Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
progress on #111 and #113
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Feb 24, 2018
1 parent bb213b5 commit aeeb062
Show file tree
Hide file tree
Showing 24 changed files with 635 additions and 647 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/com/james/status/data/IconStyleData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
Expand All @@ -13,9 +14,12 @@
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.content.ContextCompat;

import com.james.status.utils.ImageUtils;
import com.james.status.utils.StaticUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class IconStyleData implements Parcelable {

Expand All @@ -27,23 +31,27 @@ public class IconStyleData implements Parcelable {
public int type;
public int[] resource = new int[0];
public String[] path = new String[0];
private Map<Integer, Bitmap> icons;

public IconStyleData(String name, int type, @DrawableRes int... resource) {
this.name = name;
this.type = type;
this.resource = resource;
icons = new HashMap<>();
}

public IconStyleData(String name, String... path) {
this.name = name;
type = TYPE_FILE;
this.path = path;
icons = new HashMap<>();
}

protected IconStyleData(Parcel in) {
name = in.readString();
resource = in.createIntArray();
path = in.createStringArray();
icons = new HashMap<>();
}

public int getSize() {
Expand Down Expand Up @@ -79,6 +87,20 @@ public Drawable getDrawable(Context context, int value) {
}
}

@Nullable
public Bitmap getBitmap(Context context, int value) {
if (icons.containsKey(value))
return icons.get(value);
else {
Drawable drawable = getDrawable(context, value);
if (drawable != null) {
Bitmap bitmap = ImageUtils.drawableToBitmap(drawable);
icons.put(value, bitmap);
return bitmap;
} else return null;
}
}

public void writeToSharedPreferences(SharedPreferences.Editor editor, String prefix) {
if (type == TYPE_FILE) {
editor.putInt(prefix + name + "-length", getSize());
Expand Down
25 changes: 19 additions & 6 deletions app/src/main/java/com/james/status/data/NotificationData.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.NotificationCompat;

import com.james.status.utils.ImageUtils;

public class NotificationData implements Parcelable {

public String category, title, subtitle, packageName, group, key, tag = "";
public int priority, id, iconRes, color = Color.BLACK;
private boolean isAlert;
private Bitmap icon;
private Bitmap largeIcon;
private Icon unloadedIcon, unloadedLargeIcon;

Expand Down Expand Up @@ -158,13 +161,23 @@ public NotificationData[] newArray(int size) {
};

@Nullable
public Drawable getIcon(Context context) {
Drawable drawable = null;
if (iconRes != 0) drawable = getDrawable(context, iconRes, packageName);
if (drawable == null && unloadedIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
drawable = unloadedIcon.loadDrawable(context);
public Bitmap getIcon(Context context) {
if (icon == null) {
Drawable drawable = null;
if (iconRes != 0) drawable = getDrawable(context, iconRes, packageName);
if (drawable == null && unloadedIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
drawable = unloadedIcon.loadDrawable(context);

if (drawable != null) {
Bitmap bitmap = ImageUtils.drawableToBitmap(drawable);
if (bitmap != null) {
icon = bitmap;
return bitmap;
}
}
}

return drawable;
return null;
}

@Nullable
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/james/status/data/PreferenceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public enum PreferenceData {
STATUS_COLOR(Color.BLACK),
STATUS_HOME_TRANSPARENT(true),
STATUS_ICON_COLOR(Color.WHITE),
STATUS_ICON_TEXT_COLOR(Color.WHITE),
STATUS_DARK_ICON_COLOR(Color.BLACK),
STATUS_DARK_ICON_TEXT_COLOR(Color.BLACK),
STATUS_DARK_ICONS(true),
STATUS_TINTED_ICONS(false),
STATUS_PREVENT_ICON_OVERLAP(false),
Expand All @@ -55,6 +58,7 @@ public enum PreferenceData {
ICON_TEXT_TYPEFACE("%1$s/TEXT_TYPEFACE", ""),
ICON_TEXT_EFFECT("%1$s/TEXT_EFFECT", Typeface.BOLD),
ICON_ICON_VISIBILITY("%1$s/ICON_VISIBILITY", true),
ICON_ICON_COLOR("%1$s/ICON_COLOR", Color.WHITE),
ICON_ICON_STYLE("%1$s/ICON_STYLE", ""),
ICON_ICON_STYLE_NAMES("%1$s/ICON_STYLE_NAMES", new String[]{}),
ICON_ICON_PADDING("%1$s/ICON_PADDING", 2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private AirplaneModeReceiver(AirplaneModeIconData iconData) {
@Override
public void onReceive(AirplaneModeIconData icon, Intent intent) {
if (intent.getBooleanExtra(TelephonyManager.EXTRA_STATE, false))
icon.onDrawableUpdate(0);
else icon.onDrawableUpdate(-1);
icon.onIconUpdate(0);
else icon.onIconUpdate(-1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void register() {
alarm = Settings.System.getString(getContext().getContentResolver(), android.provider.Settings.System.NEXT_ALARM_FORMATTED);

if (alarm != null)
onDrawableUpdate(0);
onIconUpdate(0);
}

@Override
Expand Down Expand Up @@ -122,8 +122,8 @@ public void onReceive(AlarmIconData icon, Intent intent) {
alarm = Settings.System.getString(icon.getContext().getContentResolver(), android.provider.Settings.System.NEXT_ALARM_FORMATTED);

if (alarm != null)
icon.onDrawableUpdate(0);
else icon.onDrawableUpdate(-1);
icon.onIconUpdate(0);
else icon.onIconUpdate(-1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void register() {
if (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL)
iconLevel += 7;

onDrawableUpdate(iconLevel);
onIconUpdate(iconLevel);

if (hasText())
onTextUpdate(String.valueOf((int) (((double) level / scale) * 100)) + "%");
Expand Down Expand Up @@ -254,7 +254,7 @@ public void onReceive(BatteryIconData icon, Intent intent) {
if (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL)
iconLevel += 7;

icon.onDrawableUpdate(iconLevel);
icon.onIconUpdate(iconLevel);

if (icon.hasText())
icon.onTextUpdate(String.valueOf((int) (((double) level / scale) * 100)) + "%");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void register() {
int state = StaticUtils.getBluetoothState(getContext());

if (state != BluetoothAdapter.STATE_OFF)
onDrawableUpdate(state == BluetoothAdapter.STATE_CONNECTED ? 1 : 0);
else onDrawableUpdate(-1);
onIconUpdate(state == BluetoothAdapter.STATE_CONNECTED ? 1 : 0);
else onIconUpdate(-1);
}

@Override
Expand Down Expand Up @@ -106,8 +106,8 @@ private BluetoothReceiver(BluetoothIconData iconData) {
public void onReceive(BluetoothIconData icon, Intent intent) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
if (state != BluetoothAdapter.STATE_OFF)
icon.onDrawableUpdate(state == BluetoothAdapter.STATE_CONNECTED ? 1 : 0);
else icon.onDrawableUpdate(-1);
icon.onIconUpdate(state == BluetoothAdapter.STATE_CONNECTED ? 1 : 0);
else icon.onIconUpdate(-1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public String[] getPermissions() {
}

@Override
public boolean canHazDrawable() {
public boolean canHazIcon() {
return false;
}

@Override
public boolean hasDrawable() {
public boolean hasIcon() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public String[] getPermissions() {
}

@Override
public boolean canHazDrawable() {
public boolean canHazIcon() {
return false;
}

@Override
public boolean hasDrawable() {
public boolean hasIcon() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ else if (level < 1) {
}
}

onDrawableUpdate(level);
onIconUpdate(level);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/james/status/data/icon/GpsIconData.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ private GpsReceiver(GpsIconData iconData) {
public void onReceive(GpsIconData icon, Intent intent) {
if (icon.locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
if (isLocationFixed(icon)) {
icon.onDrawableUpdate(1);
icon.onIconUpdate(1);
} else
icon.onDrawableUpdate(0);
} else icon.onDrawableUpdate(-1);
icon.onIconUpdate(0);
} else icon.onIconUpdate(-1);
}

private boolean isLocationFixed(GpsIconData icon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ private HeadphoneReceiver(HeadphoneIconData iconData) {
@Override
public void onReceive(HeadphoneIconData icon, Intent intent) {
if (intent.getIntExtra("state", 0) == 1)
icon.onDrawableUpdate(intent.getIntExtra("microphone", 0));
else icon.onDrawableUpdate(-1);
icon.onIconUpdate(intent.getIntExtra("microphone", 0));
else icon.onIconUpdate(-1);
}
}
}
Loading

0 comments on commit aeeb062

Please sign in to comment.