mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Reimplemented custom launcher icons
This commit is contained in:
@@ -94,7 +94,6 @@ public class QKSMSAppBase extends MultiDexApplication {
|
||||
registerActivityLifecycleCallbacks(new LifecycleHandler());
|
||||
|
||||
ThemeManager.init(this);
|
||||
ThemeManager.migrateIcon(this); // TODO a few versions after 2.7, we can phase this out along with the old alias
|
||||
MmsConfig.init(this);
|
||||
Contact.init(this);
|
||||
DraftCache.init(this);
|
||||
|
||||
@@ -100,8 +100,7 @@ public enum QKPreference {
|
||||
|
||||
// Storage
|
||||
COMPOSE_DRAFT("compose_draft", ""),
|
||||
LAST_AUTO_DELETE_CHECK("last_auto_delete_check", 0),
|
||||
MIGRATED_ICON("migrated_icon", false);
|
||||
LAST_AUTO_DELETE_CHECK("last_auto_delete_check", 0);
|
||||
|
||||
private String mKey;
|
||||
private Object mDefaultValue;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.moez.QKSMS.theme;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.internal.widget.AdapterViewCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.moez.QKSMS.R;
|
||||
|
||||
public class IconAdapter extends RecyclerView.Adapter<IconViewHolder> {
|
||||
|
||||
private Context mContext;
|
||||
private AdapterViewCompat.OnItemClickListener mOnItemClickListener;
|
||||
private int[] mIconIds = new int[]{
|
||||
R.mipmap.ic_launcher, R.mipmap.ic_launcher_dark, R.mipmap.ic_launcher_red, R.mipmap.ic_launcher_pink,
|
||||
R.mipmap.ic_launcher_purple, R.mipmap.ic_launcher_deep_purple, R.mipmap.ic_launcher_indigo,
|
||||
R.mipmap.ic_launcher_blue, R.mipmap.ic_launcher_light_blue, R.mipmap.ic_launcher_cyan,
|
||||
R.mipmap.ic_launcher_teal, R.mipmap.ic_launcher_green, R.mipmap.ic_launcher_light_green,
|
||||
R.mipmap.ic_launcher_lime, R.mipmap.ic_launcher_yellow, R.mipmap.ic_launcher_amber,
|
||||
R.mipmap.ic_launcher_orange, R.mipmap.ic_launcher_deep_orange, R.mipmap.ic_launcher_brown,
|
||||
R.mipmap.ic_launcher_grey, R.mipmap.ic_launcher_blue_grey
|
||||
};
|
||||
|
||||
public IconAdapter(Context context, AdapterViewCompat.OnItemClickListener onItemClickListener) {
|
||||
mContext = context;
|
||||
mOnItemClickListener = onItemClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IconViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.list_item_icon, parent, false);
|
||||
return new IconViewHolder(this, view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(IconViewHolder holder, int position) {
|
||||
holder.bind(position);
|
||||
holder.itemView.setOnClickListener(v -> mOnItemClickListener.onItemClick(null, holder.itemView, position, 0));
|
||||
}
|
||||
|
||||
public Integer getItem(int position) {
|
||||
return mIconIds[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mIconIds.length;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.moez.QKSMS.theme;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import com.moez.QKSMS.R;
|
||||
|
||||
public class IconViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@Bind(R.id.icon) protected ImageView mIcon;
|
||||
|
||||
protected IconAdapter mIconAdapter;
|
||||
|
||||
public IconViewHolder(IconAdapter iconAdapter, View view) {
|
||||
super(view);
|
||||
mIconAdapter = iconAdapter;
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public void bind(int position) {
|
||||
int iconRes = mIconAdapter.getItem(position);
|
||||
mIcon.setImageResource(iconRes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,8 @@ import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -37,8 +39,10 @@ import com.moez.QKSMS.common.ConversationPrefsHelper;
|
||||
import com.moez.QKSMS.common.LiveViewManager;
|
||||
import com.moez.QKSMS.common.utils.ColorUtils;
|
||||
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
||||
import com.moez.QKSMS.common.utils.Units;
|
||||
import com.moez.QKSMS.enums.QKPreference;
|
||||
import com.moez.QKSMS.receiver.IconColorReceiver;
|
||||
import com.moez.QKSMS.theme.IconAdapter;
|
||||
import com.moez.QKSMS.ui.base.QKActivity;
|
||||
import com.moez.QKSMS.ui.dialog.ColorPickerPagerAdapter;
|
||||
import com.moez.QKSMS.ui.dialog.QKDialog;
|
||||
@@ -326,20 +330,34 @@ public class ThemeManager {
|
||||
LiveViewManager.refreshViews(QKPreference.BACKGROUND);
|
||||
}
|
||||
|
||||
public static void setIcon(final QKActivity context, boolean dark) {
|
||||
new QKDialog()
|
||||
.setContext(context)
|
||||
.setTitle(R.string.update_icon_title)
|
||||
.setMessage(R.string.update_icon_message)
|
||||
.setButtonBarOrientation(LinearLayout.VERTICAL)
|
||||
.setPositiveButton(R.string.okay, v -> {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
public static void setIcon(final QKActivity context) {
|
||||
|
||||
String defaultComponent = "com.moez.QKSMS.ui.MainActivity-Default";
|
||||
String darkComponent = "com.moez.QKSMS.ui.MainActivity-Dark";
|
||||
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]);
|
||||
|
||||
// Save the enabled component so we can kill the app with this one when
|
||||
// it's all done.
|
||||
if (i == position) {
|
||||
enabledComponent = componentClassName;
|
||||
} else {
|
||||
packageManager.setComponentEnabledSetting(
|
||||
new ComponentName(context, dark ? defaultComponent : darkComponent),
|
||||
new ComponentName(context, componentClassName),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
// Don't kill the app while we're in the loop! This will
|
||||
// prevent the other component enabled settings from
|
||||
@@ -347,53 +365,26 @@ public class ThemeManager {
|
||||
// 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, dark ? darkComponent : defaultComponent);
|
||||
context.sendBroadcast(intent);
|
||||
})
|
||||
.setCancelOnTouchOutside(false)
|
||||
// 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();
|
||||
}
|
||||
|
||||
public static void migrateIcon(Context context) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
|
||||
// If we've already migrated to use the MainActivity-Default component, we don't need to do anything
|
||||
if (mPrefs.getBoolean(QKPreference.MIGRATED_ICON.getKey(), (Boolean) QKPreference.MIGRATED_ICON.getDefaultValue())) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPrefs.edit().putBoolean(QKPreference.MIGRATED_ICON.getKey(), true).apply();
|
||||
|
||||
String[] colors = {
|
||||
"Red", "Pink", "Purple", "DeepPurple", "Indigo", "Blue",
|
||||
"LightBlue", "Cyan", "Teal", "Green", "LightGreen", "Lime",
|
||||
"Yellow", "Amber", "Orange", "DeepOrange", "Brown", "Grey",
|
||||
"BlueGrey"
|
||||
};
|
||||
|
||||
// Disable all of the old components
|
||||
for (String color : colors) {
|
||||
String componentClassName = String.format("com.moez.QKSMS.ui.MainActivity-%s", color);
|
||||
packageManager.setComponentEnabledSetting(
|
||||
new ComponentName(context, componentClassName),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP
|
||||
);
|
||||
}
|
||||
|
||||
// Enable the new component
|
||||
ComponentName componentName = new ComponentName(context, "com.moez.QKSMS.ui.MainActivity-Default");
|
||||
packageManager.setComponentEnabledSetting(componentName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||
PackageManager.DONT_KILL_APP
|
||||
);
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getBackgroundColor() {
|
||||
return mBackgroundColor;
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -113,7 +114,7 @@ public class QKDialog extends DialogFragment {
|
||||
mCustomPanel = (LinearLayout) view.findViewById(R.id.customPanel);
|
||||
mCustomPanel.setVisibility(View.VISIBLE);
|
||||
|
||||
if (mCustomView instanceof ListView) {
|
||||
if (mCustomView instanceof ListView || mCustomView instanceof RecyclerView) {
|
||||
mCustomPanel.addView(mCustomView);
|
||||
} else {
|
||||
ScrollView scrollView = new ScrollView(mContext);
|
||||
|
||||
@@ -82,7 +82,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
public static final String CATEGORY_APPEARANCE_SYSTEM_BARS = "pref_key_category_appearance_system_bars";
|
||||
|
||||
public static final String THEME = "pref_key_theme";
|
||||
public static final String ICON = "pref_key_icon_dark";
|
||||
public static final String ICON = "pref_key_icon";
|
||||
public static final String STATUS_TINT = "pref_key_status_tint";
|
||||
public static final String NAVIGATION_TINT = "pref_key_navigation_tint";
|
||||
public static final String BACKGROUND = "pref_key_background";
|
||||
@@ -425,9 +425,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
case BACKGROUND:
|
||||
ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue));
|
||||
break;
|
||||
case ICON:
|
||||
ThemeManager.setIcon(mContext, (Boolean) newValue);
|
||||
break;
|
||||
case STATUS_TINT:
|
||||
ThemeManager.setStatusBarTintEnabled(mContext, (Boolean) newValue);
|
||||
break;
|
||||
@@ -579,6 +576,9 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
case THEME:
|
||||
ThemeManager.showColorPickerDialog(mContext);
|
||||
break;
|
||||
case ICON:
|
||||
ThemeManager.setIcon(mContext);
|
||||
break;
|
||||
case BUBBLES:
|
||||
new BubblePreferenceDialog().setContext(mContext).show();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user