Search in sources :

Example 1 with IconAdapter

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();
}
Also used : ColorPickerPalette(com.moez.QKSMS.ui.view.colorpicker.ColorPickerPalette) GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) QKTextView(com.moez.QKSMS.ui.view.QKTextView) ImageView(android.widget.ImageView) Animator(android.animation.Animator) WidgetProvider(com.moez.QKSMS.ui.widget.WidgetProvider) Drawable(android.graphics.drawable.Drawable) LiveViewManager(com.moez.QKSMS.common.LiveViewManager) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) Bind(butterknife.Bind) PreferenceManager(android.preference.PreferenceManager) TargetApi(android.annotation.TargetApi) Log(android.util.Log) ContextCompat(android.support.v4.content.ContextCompat) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) AnalyticsManager(com.moez.QKSMS.common.AnalyticsManager) ColorUtils(com.moez.QKSMS.common.utils.ColorUtils) IconColorReceiver(com.moez.QKSMS.receiver.IconColorReceiver) Units(com.moez.QKSMS.common.utils.Units) SettingsFragment(com.moez.QKSMS.ui.settings.SettingsFragment) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Context(android.content.Context) QKPreference(com.moez.QKSMS.enums.QKPreference) ButterKnife(butterknife.ButterKnife) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) QKActivity(com.moez.QKSMS.ui.base.QKActivity) KeyboardUtils(com.moez.QKSMS.common.utils.KeyboardUtils) R(com.moez.QKSMS.R) SeekBar(android.widget.SeekBar) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) ColorPickerPagerAdapter(com.moez.QKSMS.ui.dialog.ColorPickerPagerAdapter) Build(android.os.Build) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) QKEditText(com.moez.QKSMS.ui.view.QKEditText) CIELChEvaluator(com.moez.QKSMS.common.CIELChEvaluator) Color(android.graphics.Color) ColorInt(android.support.annotation.ColorInt) IconAdapter(com.moez.QKSMS.theme.IconAdapter) RecyclerView(android.support.v7.widget.RecyclerView) DrawableRes(android.support.annotation.DrawableRes) SharedPreferences(android.content.SharedPreferences) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper) ValueAnimator(android.animation.ValueAnimator) Resources(android.content.res.Resources) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) GridLayoutManager(android.support.v7.widget.GridLayoutManager) PackageManager(android.content.pm.PackageManager) IconAdapter(com.moez.QKSMS.theme.IconAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ComponentName(android.content.ComponentName) Intent(android.content.Intent) LinearLayout(android.widget.LinearLayout)

Aggregations

Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 TargetApi (android.annotation.TargetApi)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 Color (android.graphics.Color)1 PorterDuff (android.graphics.PorterDuff)1 Drawable (android.graphics.drawable.Drawable)1 Build (android.os.Build)1 PreferenceManager (android.preference.PreferenceManager)1 ColorInt (android.support.annotation.ColorInt)1 DrawableRes (android.support.annotation.DrawableRes)1 ContextCompat (android.support.v4.content.ContextCompat)1 ViewPager (android.support.v4.view.ViewPager)1