use of com.moez.QKSMS.theme.IconAdapter in project qksms by moezbhatti.
the class ThemeManager method setIcon.
public static void setIcon(final QKActivity context) {
String[] colors = { "Default", "Dark", "Red", "Pink", "Purple", "DeepPurple", "Indigo", "Blue", "LightBlue", "Cyan", "Teal", "Green", "LightGreen", "Lime", "Yellow", "Amber", "Orange", "DeepOrange", "Brown", "Grey", "BlueGrey" };
RecyclerView recyclerView = new RecyclerView(context);
recyclerView.setLayoutParams(new LinearLayout.LayoutParams(-1, Units.dpToPx(context, 200)));
recyclerView.setLayoutManager(new GridLayoutManager(context, 4));
recyclerView.setAdapter(new IconAdapter(context, (parent, view, position, id) -> {
PackageManager packageManager = context.getPackageManager();
// Disable all of the color aliases, except for the alias with the current
// color.
String enabledComponent = null;
for (int i = 0; i < colors.length; i++) {
String componentClassName = String.format("com.moez.QKSMS.ui.MainActivity-%s", colors[i]);
// it's all done.
if (i == position) {
enabledComponent = componentClassName;
} else {
packageManager.setComponentEnabledSetting(new ComponentName(context, componentClassName), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, // won't show up to the user.
PackageManager.DONT_KILL_APP);
}
}
// Broadcast an intent to a receiver that will:
// 1) enable the last component; and
// 2) relaunch QKSMS with the new component name.
Intent intent = new Intent(IconColorReceiver.ACTION_ICON_COLOR_CHANGED);
intent.putExtra(IconColorReceiver.EXTRA_COMPONENT_NAME, enabledComponent);
context.sendBroadcast(intent);
}));
new QKDialog().setContext(context).setTitle(R.string.update_icon_title).setMessage(R.string.update_icon_message).setCustomView(recyclerView).setNegativeButton(R.string.cancel, null).show();
}
Aggregations