Search in sources :

Example 1 with ColorUsage

use of com.amaze.filemanager.utils.color.ColorUsage in project AmazeFileManager by TeamAmaze.

the class ColorPref method onPreferenceClick.

@Override
public boolean onPreferenceClick(final Preference preference) {
    switch(preference.getKey()) {
        case KEY_COLOREDNAV:
            activity.invalidateNavBar();
            break;
        case PreferencesConstants.PREFERENCE_SKIN:
        case PreferencesConstants.PREFERENCE_SKIN_TWO:
        case PreferencesConstants.PREFERENCE_ACCENT:
        case PreferencesConstants.PREFERENCE_ICON_SKIN:
            final ColorUsage usage = ColorUsage.fromString(preference.getKey());
            if (usage != null) {
                ColorAdapter adapter = new ColorAdapter(getActivity(), ColorPreference.getUniqueAvailableColors(getActivity()), usage, activity.getColorPreference().getColor(usage), (selectedColorRes) -> {
                    activity.getColorPreference().setRes(usage, selectedColorRes).saveToPreferences(sharedPref);
                    if (dialog != null)
                        dialog.dismiss();
                    invalidateEverything();
                });
                GridView v = (GridView) getActivity().getLayoutInflater().inflate(R.layout.dialog_grid, null);
                v.setAdapter(adapter);
                v.setOnItemClickListener(adapter);
                int fab_skin = activity.getColorPreference().getColor(ColorUsage.ACCENT);
                dialog = new MaterialDialog.Builder(getActivity()).positiveText(R.string.cancel).title(R.string.choose_color).theme(activity.getAppTheme().getMaterialDialogTheme()).autoDismiss(true).positiveColor(fab_skin).neutralColor(fab_skin).neutralText(R.string.defualt).callback(new MaterialDialog.ButtonCallback() {

                    @Override
                    public void onNeutral(MaterialDialog dialog) {
                        super.onNeutral(dialog);
                        if (activity != null)
                            activity.setRestartActivity();
                        activity.getColorPreference().setRes(usage, usage.getDefaultColor()).saveToPreferences(sharedPref);
                        invalidateEverything();
                    }
                }).customView(v, false).show();
            }
            return false;
        case "selectcolorconfig":
            switchSections();
            return true;
    }
    return false;
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorAdapter(com.amaze.filemanager.adapters.ColorAdapter) GridView(android.widget.GridView) ColorUsage(com.amaze.filemanager.utils.color.ColorUsage)

Aggregations

GridView (android.widget.GridView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 ColorAdapter (com.amaze.filemanager.adapters.ColorAdapter)1 ColorUsage (com.amaze.filemanager.utils.color.ColorUsage)1