Search in sources :

Example 1 with ColorPickerDialog

use of com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog in project qksms by moezbhatti.

the class ConversationSettingsDialog method onPreferenceClick.

public boolean onPreferenceClick(Preference preference) {
    switch(preference.getKey()) {
        case SettingsFragment.THEME:
            ThemeManager.showColorPickerDialogForConversation(mContext, mConversationPrefs);
            break;
        case SettingsFragment.NOTIFICATION_LED_COLOR:
            ColorPickerDialog ledColorPickerDialog = new ColorPickerDialog();
            ledColorPickerDialog.initialize(R.string.pref_theme_led, mLedColors, Integer.parseInt(mConversationPrefs.getNotificationLedColor()), 3, 2);
            ledColorPickerDialog.setOnColorSelectedListener(color -> mConversationPrefs.putString(SettingsFragment.NOTIFICATION_LED_COLOR, "" + color));
            ledColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker");
            break;
        case SettingsFragment.NOTIFICATION_TONE:
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, getRingtoneUri());
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.pref_ringtone));
            intent.putExtra(ARG_THREAD_ID, mThreadId);
            ((MessageListActivity) getActivity()).getResultForThreadId(mThreadId);
            getActivity().startActivityForResult(intent, RINGTONE_REQUEST_CODE);
            break;
    }
    return true;
}
Also used : MessageListActivity(com.moez.QKSMS.ui.messagelist.MessageListActivity) Intent(android.content.Intent) ColorPickerDialog(com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog)

Example 2 with ColorPickerDialog

use of com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog in project qksms by moezbhatti.

the class SettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    setHasOptionsMenu(true);
    mContext = (QKActivity) getActivity();
    mPrefs = mContext.getPrefs();
    mRes = mContext.getResources();
    mContext.setTitle(R.string.title_settings);
    mResource = args.getInt("category", R.xml.settings);
    addPreferencesFromResource(mResource);
    // Set `this` to be the preferences click/change listener for all the preferences.
    PreferenceScreen screen = getPreferenceScreen();
    for (int i = 0; i < screen.getPreferenceCount(); i++) {
        Preference pref = screen.getPreference(i);
        pref.setOnPreferenceClickListener(this);
        pref.setOnPreferenceChangeListener(this);
        // well.
        if (pref instanceof PreferenceCategory) {
            Stack<PreferenceCategory> stack = new Stack<>();
            stack.push((PreferenceCategory) pref);
            do {
                PreferenceCategory category = stack.pop();
                for (int j = 0; j < category.getPreferenceCount(); j++) {
                    Preference subPref = category.getPreference(j);
                    subPref.setOnPreferenceClickListener(this);
                    subPref.setOnPreferenceChangeListener(this);
                    if (subPref instanceof PreferenceCategory) {
                        stack.push((PreferenceCategory) subPref);
                    }
                }
            } while (!stack.isEmpty());
        }
    }
    Preference icon = findPreference(ICON);
    if (icon != null) {
        icon.setOnPreferenceClickListener(this);
    }
    mThemeLed = findPreference(NOTIFICATION_LED_COLOR);
    if (mThemeLed != null) {
        mLedColors = new int[] { mRes.getColor(R.color.blue_light), mRes.getColor(R.color.purple_light), mRes.getColor(R.color.green_light), mRes.getColor(R.color.yellow_light), mRes.getColor(R.color.red_light), mRes.getColor(R.color.white_pure) };
        mLedColorPickerDialog = new ColorPickerDialog();
        mLedColorPickerDialog.initialize(R.string.pref_theme_led, mLedColors, Integer.parseInt(mPrefs.getString(NOTIFICATION_LED_COLOR, "-48060")), 3, 2);
        mLedColorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {

            @Override
            public void onColorSelected(int color) {
                mPrefs.edit().putString(mThemeLed.getKey(), "" + color).apply();
                onPreferenceChange(findPreference(mThemeLed.getKey()), color);
            }
        });
    }
    ListPreference font_family = (ListPreference) findPreference(FONT_FAMILY);
    if (font_family != null) {
        mFontFamilies = mRes.getStringArray(R.array.font_families);
        font_family.setSummary(mFontFamilies[Integer.parseInt(font_family.getValue())]);
    }
    ListPreference font_size = (ListPreference) findPreference(FONT_SIZE);
    if (font_size != null) {
        mFontSizes = mRes.getStringArray(R.array.font_sizes);
        font_size.setSummary(mFontSizes[Integer.parseInt(font_size.getValue())]);
    }
    ListPreference font_weight = (ListPreference) findPreference(FONT_WEIGHT);
    if (font_weight != null) {
        mFontWeights = mRes.getStringArray(R.array.font_weights);
        int i = Integer.parseInt(font_weight.getValue());
        font_weight.setSummary(mFontWeights[i == 2 ? 0 : 1]);
    }
    EditTextPreference deleteUnread = (EditTextPreference) findPreference(DELETE_UNREAD_MESSAGES);
    if (deleteUnread != null) {
        deleteUnread.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD)));
    }
    EditTextPreference deleteRead = (EditTextPreference) findPreference(DELETE_READ_MESSAGES);
    if (deleteRead != null) {
        deleteRead.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, QKPreferences.getString(QKPreference.AUTO_DELETE_READ)));
    }
    Preference day_start = findPreference(DAY_START);
    if (day_start != null) {
        day_start.setSummary(DateFormatter.getSummaryTimestamp(mContext, mPrefs.getString(DAY_START, "6:00")));
    }
    Preference night_start = findPreference(NIGHT_START);
    if (night_start != null) {
        night_start.setSummary(DateFormatter.getSummaryTimestamp(mContext, mPrefs.getString(NIGHT_START, "21:00")));
    }
    mMmscUrl = (EditTextPreference) findPreference(MMSC_URL);
    if (mMmscUrl != null) {
        mMmscUrl.setSummary(mMmscUrl.getText());
    }
    mMmsProxy = (EditTextPreference) findPreference(MMS_PROXY);
    if (mMmsProxy != null) {
        mMmsProxy.setSummary(mMmsProxy.getText());
    }
    mMmsPort = (EditTextPreference) findPreference(MMS_PORT);
    if (mMmsPort != null) {
        mMmsPort.setSummary(mMmsPort.getText());
    }
    mMaxMmsAttachmentSize = (ListPreference) findPreference(MAX_MMS_ATTACHMENT_SIZE);
    if (mMaxMmsAttachmentSize != null) {
        mMaxMmsAttachmentSizes = mRes.getStringArray(R.array.max_mms_attachment_sizes);
        String value = mMaxMmsAttachmentSize.getValue();
        String summary = mMaxMmsAttachmentSizes[mMaxMmsAttachmentSize.findIndexOfValue(value)];
        mMaxMmsAttachmentSize.setSummary(summary);
    }
    Preference version = findPreference(VERSION);
    if (version != null) {
        String v = "unknown";
        try {
            PackageInfo info = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
            v = info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        version.setSummary(v);
    }
    // Status and nav bar tinting are only supported on kit kat or above.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        removePreference(CATEGORY_APPEARANCE_SYSTEM_BARS);
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) Bundle(android.os.Bundle) PackageInfo(android.content.pm.PackageInfo) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference) Stack(java.util.Stack) ColorPickerDialog(com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog) PackageManager(android.content.pm.PackageManager) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) QKPreference(com.moez.QKSMS.enums.QKPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) ColorPickerSwatch(com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch)

Aggregations

ColorPickerDialog (com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog)2 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Bundle (android.os.Bundle)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 EditTextPreference (android.preference.EditTextPreference)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 PreferenceCategory (android.preference.PreferenceCategory)1 PreferenceScreen (android.preference.PreferenceScreen)1 QKPreference (com.moez.QKSMS.enums.QKPreference)1 MessageListActivity (com.moez.QKSMS.ui.messagelist.MessageListActivity)1 ColorPickerSwatch (com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch)1 Stack (java.util.Stack)1