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

Commit

Permalink
actually implement some icon reusing stuff - #113
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed May 20, 2018
1 parent 6f32dfe commit 67ffca0
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

app.putSpecificPreference(context, AppData.PreferenceIdentifier.NOTIFICATIONS, isChecked);

StaticUtils.updateStatusService(context);
StaticUtils.updateStatusService(context, true);
}
});

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/james/status/adapters/IconAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
holder.checkBox.setOnCheckedChangeListener(this);
} else {
PreferenceData.ICON_VISIBILITY.setValue(activity, isChecked, icon.getIdentifierArgs());
StaticUtils.updateStatusService(activity);
StaticUtils.updateStatusService(activity, false);

notifyItemChanged(holder.getAdapterPosition());
}
Expand All @@ -86,7 +86,7 @@ public void onClick(View v) {

setIcons(icons);
notifyDataSetChanged();
StaticUtils.updateStatusService(activity);
StaticUtils.updateStatusService(activity, true);
}
});

Expand All @@ -104,7 +104,7 @@ public void onClick(View v) {

setIcons(icons);
notifyDataSetChanged();
StaticUtils.updateStatusService(activity);
StaticUtils.updateStatusService(activity, true);
}
});

Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/com/james/status/data/icon/IconData.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public List<BasePreferenceData> getPreferences() {
new BasePreferenceData.OnPreferenceChangeListener<Boolean>() {
@Override
public void onPreferenceChange(Boolean preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
));
Expand All @@ -450,7 +450,7 @@ public void onPreferenceChange(Boolean preference) {
new BasePreferenceData.OnPreferenceChangeListener<Boolean>() {
@Override
public void onPreferenceChange(Boolean preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
));
Expand All @@ -468,7 +468,7 @@ public void onPreferenceChange(Boolean preference) {
new BasePreferenceData.OnPreferenceChangeListener<Integer>() {
@Override
public void onPreferenceChange(Integer preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
},
new ListPreferenceData.ListPreference(
Expand Down Expand Up @@ -497,7 +497,7 @@ public void onPreferenceChange(Integer preference) {
new BasePreferenceData.OnPreferenceChangeListener<Integer>() {
@Override
public void onPreferenceChange(Integer preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
)
Expand All @@ -517,7 +517,7 @@ public void onPreferenceChange(Integer preference) {
new BasePreferenceData.OnPreferenceChangeListener<Integer>() {
@Override
public void onPreferenceChange(Integer preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
));
Expand All @@ -536,7 +536,7 @@ public void onPreferenceChange(Integer preference) {
new BasePreferenceData.OnPreferenceChangeListener<Integer>() {
@Override
public void onPreferenceChange(Integer preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
));
Expand All @@ -551,7 +551,7 @@ public void onPreferenceChange(Integer preference) {
new BasePreferenceData.OnPreferenceChangeListener<Integer>() {
@Override
public void onPreferenceChange(Integer preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
));
Expand All @@ -566,7 +566,7 @@ public void onPreferenceChange(Integer preference) {
new BasePreferenceData.OnPreferenceChangeListener<String>() {
@Override
public void onPreferenceChange(String preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
},
"Audiowide.ttf",
Expand Down Expand Up @@ -597,7 +597,7 @@ public void onPreferenceChange(String preference) {
new BasePreferenceData.OnPreferenceChangeListener<Integer>() {
@Override
public void onPreferenceChange(Integer preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
},
new ListPreferenceData.ListPreference(getContext().getString(R.string.text_effect_none), Typeface.NORMAL),
Expand All @@ -620,7 +620,7 @@ public void onPreferenceChange(Integer preference) {
@Override
public void onPreferenceChange(IconStyleData preference) {
style = preference;
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public List<BasePreferenceData> getPreferences() {
new BasePreferenceData.OnPreferenceChangeListener<Integer>() {
@Override
public void onPreferenceChange(Integer preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public List<BasePreferenceData> getPreferences() {
@Override
public void onPreferenceChange(String preference) {
format = preference;
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
}
}
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void onFileChanged(boolean isSettingsChanged) {
recyclerView.getAdapter().notifyDataSetChanged();

if (isSettingsChanged) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), false);
this.isSettingsChanged = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
app.clearPreferences(getContext());
}

StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
adapter.notifyDataSetChanged();
dialogInterface.dismiss();
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public void setNotifications(boolean isNotifications) {
app.putSpecificPreference(getContext(), AppData.PreferenceIdentifier.NOTIFICATIONS, isNotifications);
}

StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), true);
adapter.notifyDataSetChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,6 @@ public String getTitle(Context context) {

@Override
public void onPreferenceChange(Object preference) {
StaticUtils.updateStatusService(getContext());
StaticUtils.updateStatusService(getContext(), false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void onReceive(Context context, Intent intent) {
if (intent.hasExtra(EXTRA_ACTIVITY) && intent.hasExtra(EXTRA_VISIBILITY)) {
AppData.ActivityData activity = intent.getParcelableExtra(EXTRA_ACTIVITY);
activity.putPreference(context, AppData.PreferenceIdentifier.FULLSCREEN, !intent.getBooleanExtra(EXTRA_VISIBILITY, true));
StaticUtils.updateStatusService(context);
StaticUtils.updateStatusService(context, true);
}
}
}
52 changes: 31 additions & 21 deletions app/src/main/java/com/james/status/services/StatusService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class StatusService extends Service {
public static final String ACTION_START = "com.james.status.ACTION_START";
public static final String ACTION_STOP = "com.james.status.ACTION_STOP";
public static final String ACTION_UPDATE = "com.james.status.ACTION_UPDATE";
public static final String EXTRA_KEEP_OLD = "com.james.status.EXTRA_KEEP_OLD";
public static final String EXTRA_COLOR = "com.james.status.EXTRA_COLOR";
public static final String EXTRA_IS_SYSTEM_FULLSCREEN = "com.james.status.EXTRA_IS_SYSTEM_FULLSCREEN";
public static final String EXTRA_IS_FULLSCREEN = "com.james.status.EXTRA_IS_FULLSCREEN";
Expand Down Expand Up @@ -141,7 +142,7 @@ public void run() {
};

if (PreferenceData.STATUS_ENABLED.getValue(this))
setUp();
setUp(false);

headsUpDuration = (int) PreferenceData.STATUS_HEADS_UP_DURATION.getValue(this) * 1000;
}
Expand Down Expand Up @@ -169,7 +170,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
if (action == null) return START_STICKY;
switch (action) {
case ACTION_START:
setUp();
setUp(intent.getBooleanExtra(EXTRA_KEEP_OLD, false));
break;
case ACTION_STOP:
windowManager.removeView(statusView);
Expand Down Expand Up @@ -293,7 +294,13 @@ public void onTaskRemoved(Intent rootIntent) {
} else super.onTaskRemoved(rootIntent);
}

public void setUp() {
/**
* Initializes the StatusView if it doesn't exist yet, sets listeners,
* applies any changes to preferences/icons
*
* @param shouldKeepOld whether to reuse the old IconData instances
*/
public void setUp(boolean shouldKeepOld) {
if (statusView == null || statusView.getParent() == null) {
if (statusView != null) {
windowManager.removeView(statusView);
Expand All @@ -306,31 +313,34 @@ public void setUp() {
params.gravity = Gravity.TOP;

windowManager.addView(statusView, params);
} else statusView.unregister();
} else if (!shouldKeepOld)
statusView.unregister();

statusView.init();

if (fullscreenView == null || fullscreenView.getParent() == null) {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(1, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSPARENT);
params.gravity = Gravity.START | Gravity.TOP;
fullscreenView = new View(this);
if (!shouldKeepOld) {
if (fullscreenView == null || fullscreenView.getParent() == null) {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(1, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSPARENT);
params.gravity = Gravity.START | Gravity.TOP;
fullscreenView = new View(this);

windowManager.addView(fullscreenView, params);
windowManager.addView(fullscreenView, params);

fullscreenView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (statusView != null && fullscreenView != null) {
Point size = new Point();
windowManager.getDefaultDisplay().getSize(size);
statusView.setFullscreen(fullscreenView.getMeasuredHeight() == size.y);
fullscreenView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (statusView != null && fullscreenView != null) {
Point size = new Point();
windowManager.getDefaultDisplay().getSize(size);
statusView.setFullscreen(fullscreenView.getMeasuredHeight() == size.y);
}
}
}
});
}
});
}

statusView.setIcons(getIcons(this));
statusView.register();
statusView.setIcons(getIcons(this));
statusView.register();
}

IntentFilter notificationFilter = new IntentFilter();
notificationFilter.addAction(NotificationsIconData.ACTION_NOTIFICATION_ADDED);
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/james/status/utils/StaticUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,17 @@ public static boolean isStatusServiceRunning(Context context) {
return false;
}

public static void updateStatusService(Context context) {
/**
* Sends an intent to apply preference changes to the StatusService
*
* @param context current context to send intent from
* @param shouldKeepIcons whether to reuse existing instances of IconDatas
*/
public static void updateStatusService(Context context, boolean shouldKeepIcons) {
if (isStatusServiceRunning(context)) {
Intent intent = new Intent(StatusService.ACTION_START);
intent.setClass(context, StatusService.class);
intent.putExtra(StatusService.EXTRA_KEEP_OLD, shouldKeepIcons);
context.startService(intent);
}

Expand Down

0 comments on commit 67ffca0

Please sign in to comment.