Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b91473e5 authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Created custom RGB picker

parent 84a96126
Loading
Loading
Loading
Loading
+79 −39
Original line number Diff line number Diff line
@@ -11,26 +11,32 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import butterknife.Bind;
import butterknife.ButterKnife;
import com.moez.QKSMS.R;
import com.moez.QKSMS.common.AnalyticsManager;
import com.moez.QKSMS.common.CIELChEvaluator;
import com.moez.QKSMS.common.ConversationPrefsHelper;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.enums.QKPreference;
import com.moez.QKSMS.common.utils.ColorUtils;
import com.moez.QKSMS.enums.QKPreference;
import com.moez.QKSMS.receiver.IconColorReceiver;
import com.moez.QKSMS.ui.base.QKActivity;
import com.moez.QKSMS.ui.dialog.QKDialog;
import com.moez.QKSMS.ui.settings.SettingsFragment;
import com.moez.QKSMS.ui.view.QKTextView;
import com.moez.QKSMS.ui.view.colorpicker.ColorPickerPalette;
import com.moez.QKSMS.ui.widget.WidgetProvider;

public class ThemeManager {
@@ -461,53 +467,72 @@ public class ThemeManager {
    }

    public static void showColorPickerDialog(final QKActivity context) {
        final QKDialog dialog = new QKDialog();
        showColorPicker(context, v -> setColor(context, getColor()));
    }

        ColorPickerPalette palette = new ColorPickerPalette(context);
        palette.setGravity(Gravity.CENTER);
        palette.init(19, 4, color -> {
            palette.init(getSwatch(color).length, 4, color2 -> {
                setColor(context, color2);
                dialog.dismiss();
    public static void showColorPickerDialogForConversation(final QKActivity context, ConversationPrefsHelper prefs) {
        showColorPicker(context, v -> {
            prefs.putString(QKPreference.THEME.getKey(), "" + getColor());
            LiveViewManager.refreshViews(QKPreference.CONVERSATION_THEME);
        });
    }

            palette.drawPalette(getSwatch(color), mColor);
        });
    private static void showColorPicker(QKActivity context, View.OnClickListener saveListener) {
        final QKDialog dialog = new QKDialog();

        palette.drawPalette(PALETTE, getSwatchColor(mColor));
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_color_picker_rgb, null, false);
        ColorPickerViewHolder holder = new ColorPickerViewHolder(view);

        dialog.setContext(context)
                .setTitle(R.string.pref_theme)
                .setCustomView(palette)
                .setNegativeButton(R.string.cancel, null);
        SeekBar.OnSeekBarChangeListener seekListener = new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                int color = ThemeManager.getColor();
                color = Color.rgb(seekBar == holder.mRed ? progress : Color.red(color),
                        seekBar == holder.mGreen ? progress : Color.green(color),
                        seekBar == holder.mBlue ? progress : Color.blue(color));

                if (seekBar == holder.mRed) holder.mRedValue.setText(String.valueOf(progress));
                if (seekBar == holder.mGreen) holder.mGreenValue.setText(String.valueOf(progress));
                if (seekBar == holder.mBlue) holder.mBlueValue.setText(String.valueOf(progress));

        dialog.show();
                ThemeManager.setActiveColor(color);
            }

    public static void showColorPickerDialogForConversation(final QKActivity context, ConversationPrefsHelper prefs) {
        final QKDialog dialog = new QKDialog();
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

        ColorPickerPalette palette = new ColorPickerPalette(context);
        palette.setGravity(Gravity.CENTER);
        palette.init(19, 4, color -> {
            palette.init(getSwatch(color).length, 4, color2 -> {
                prefs.putString(QKPreference.THEME.getKey(), "" + color2);
                setActiveColor(color2);
                LiveViewManager.refreshViews(QKPreference.CONVERSATION_THEME);
                dialog.dismiss();
            });
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        };

            palette.drawPalette(getSwatch(color), prefs.getColor());
        Drawable thumbRed = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
        Drawable thumbGreen = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
        Drawable thumbBlue = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
        LiveViewManager.registerView(QKPreference.THEME, holder.mPreview, key -> {
            holder.mPreview.setBackgroundColor(ThemeManager.getColor());
            holder.mRed.getProgressDrawable().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
            holder.mGreen.getProgressDrawable().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
            holder.mBlue.getProgressDrawable().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
        });

        palette.drawPalette(PALETTE, getSwatchColor(prefs.getColor()));
        holder.mRed.setThumb(thumbRed);
        holder.mRed.setOnSeekBarChangeListener(seekListener);
        holder.mGreen.setThumb(thumbGreen);
        holder.mGreen.setOnSeekBarChangeListener(seekListener);
        holder.mBlue.setThumb(thumbBlue);
        holder.mBlue.setOnSeekBarChangeListener(seekListener);

        dialog.setContext(context)
                .setTitle(R.string.pref_theme)
                .setCustomView(palette)
                .setNegativeButton(R.string.cancel, null);
        holder.mRed.setProgress(Color.red(ThemeManager.getColor()));
        holder.mGreen.setProgress(Color.green(ThemeManager.getColor()));
        holder.mBlue.setProgress(Color.blue(ThemeManager.getColor()));

        dialog.show();
        dialog.setContext(context)
                .setCustomView(view)
                .setNegativeButton(R.string.cancel, v -> ThemeManager.setActiveColor(ThemeManager.getThemeColor()))
                .setPositiveButton(R.string.save, saveListener)
                .show();
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
@@ -548,7 +573,7 @@ public class ThemeManager {
                getColorString(color)
        );

        int colorFrom = mColor;
        int colorFrom = mActiveColor;
        mColor = color;
        mActiveColor = color;

@@ -635,4 +660,19 @@ public class ThemeManager {

        return PALETTE;
    }

    static class ColorPickerViewHolder {
        @Bind(R.id.preview) View mPreview;
        @Bind(R.id.red) SeekBar mRed;
        @Bind(R.id.red_value) QKTextView mRedValue;
        @Bind(R.id.green) SeekBar mGreen;
        @Bind(R.id.green_value) QKTextView mGreenValue;
        @Bind(R.id.blue) SeekBar mBlue;
        @Bind(R.id.blue_value) QKTextView mBlueValue;

        public ColorPickerViewHolder(View view) {
            ButterKnife.bind(this, view);
        }

    }
}
+5 −1
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import com.moez.QKSMS.R;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.utils.Units;
import com.moez.QKSMS.enums.QKPreference;
import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.base.QKActivity;
import com.moez.QKSMS.ui.view.QKTextView;
@@ -130,8 +132,10 @@ public class QKDialog extends DialogFragment {
            mPositiveButtonView = (QKTextView) view.findViewById(R.id.buttonPositive);
            mPositiveButtonView.setVisibility(View.VISIBLE);
            mPositiveButtonView.setText(mPositiveButtonText);
            mPositiveButtonView.setTextColor(ThemeManager.getColor());
            mPositiveButtonView.setOnClickListener(mPositiveButtonClickListener);
            LiveViewManager.registerView(QKPreference.THEME, mPositiveButtonView, key -> {
                mPositiveButtonView.setTextColor(ThemeManager.getColor());
            });
        }

        if (mNeutralButtonEnabled) {
+12 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <solid android:color="@color/grey_light_ultra" />
            <size
                android:width="16dp"
                android:height="16dp" />
        </shape>
    </item>

</layer-list>
 No newline at end of file
+119 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="128dp"
        android:background="#e2e28e" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:layout_marginTop="16dp"
        android:gravity="center_vertical">

        <com.moez.QKSMS.ui.view.QKTextView
            android:layout_width="24dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:gravity="center"
            android:lines="1"
            android:text="R"
            app:type="secondary"
            tools:ignore="HardcodedText" />

        <SeekBar
            android:id="@+id/red"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:max="255" />

        <com.moez.QKSMS.ui.view.QKTextView
            android:id="@+id/red_value"
            android:layout_width="36dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="16dp"
            android:gravity="center"
            android:lines="1"
            app:type="primary"
            tools:text="41" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:gravity="center_vertical">

        <com.moez.QKSMS.ui.view.QKTextView
            android:layout_width="24dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:gravity="center"
            android:lines="1"
            android:text="G"
            app:type="secondary"
            tools:ignore="HardcodedText" />

        <SeekBar
            android:id="@+id/green"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:max="255" />

        <com.moez.QKSMS.ui.view.QKTextView
            android:id="@+id/green_value"
            android:layout_width="36dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="16dp"
            android:gravity="center"
            android:lines="1"
            app:type="primary"
            tools:text="22" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:layout_marginBottom="16dp"
        android:gravity="center_vertical">

        <com.moez.QKSMS.ui.view.QKTextView
            android:layout_width="24dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:gravity="center"
            android:lines="1"
            android:text="B"
            app:type="secondary"
            tools:ignore="HardcodedText" />

        <SeekBar
            android:id="@+id/blue"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:max="255" />

        <com.moez.QKSMS.ui.view.QKTextView
            android:id="@+id/blue_value"
            android:layout_width="36dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="16dp"
            android:gravity="center"
            android:lines="1"
            app:type="primary"
            tools:text="231" />

    </LinearLayout>

</LinearLayout>
 No newline at end of file