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

Commit a119231e authored by Danesh M's avatar Danesh M
Browse files

QSBooleanSettingsRow : Add default value attribute

Without this, settings might throw NotFoundException
and set incorrect defaults

Change-Id: Ia7e193d7c8f935cd5e371e3377af7b64ddcb37cc
parent db9cc40c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
            style="@style/SettingRow"
            android:key="status_bar_show_weather"
            android:title="@string/quick_settings_title_show_weather"
            systemui:defaultValue="1"
            systemui:table="cm_system"
    />

@@ -53,6 +54,7 @@
            style="@style/SettingRow"
            android:title="@string/quick_settings_title_enlarge_first_row"
            android:key="sysui_qs_main_tiles"
            systemui:defaultValue="1"
            systemui:table="cm_secure" />

    <LinearLayout
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

        <attr name="android:key"/>
        <attr name="android:title" />
        <attr name="defaultValue" format="integer"/>
    </declare-styleable>
</resources>
+21 −25
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class QSBooleanSettingRow extends LinearLayout implements View.OnClickLis
    String mKey;
    private TextView mText;
    private Switch mSwitch;
    private int mDefaultValue;

    public QSBooleanSettingRow(Context context) {
        this(context, null);
@@ -79,6 +80,7 @@ public class QSBooleanSettingRow extends LinearLayout implements View.OnClickLis

        mTitle = a.getString(R.styleable.QuickSettingsRow_android_title);
        mKey = a.getString(R.styleable.QuickSettingsRow_android_key);
        mDefaultValue = a.getInt(R.styleable.QuickSettingsRow_defaultValue, 0);

        if (mText != null) {
            mText.setText(mTitle);
@@ -131,32 +133,26 @@ public class QSBooleanSettingRow extends LinearLayout implements View.OnClickLis
    private boolean getCurrent() {
        ContentResolver cr = getContext().getContentResolver();
        int ret = 0;
        try {
        switch (mWhichTable) {
            case TABLE_GLOBAL:
                    ret = Settings.Global.getInt(cr, mKey);
                ret = Settings.Global.getInt(cr, mKey, mDefaultValue);
                break;
            case TABLE_SECURE:
                    ret = Settings.Secure.getInt(cr, mKey);
                ret = Settings.Secure.getInt(cr, mKey, mDefaultValue);
                break;
            case TABLE_SYSTEM:
                    ret = Settings.System.getInt(cr, mKey);
                ret = Settings.System.getInt(cr, mKey, mDefaultValue);
                break;
            case TABLE_CM_GLOBAL:
                    ret = CMSettings.Global.getInt(cr, mKey);
                ret = CMSettings.Global.getInt(cr, mKey, mDefaultValue);
                break;
            case TABLE_CM_SECURE:
                    ret = CMSettings.Secure.getInt(cr, mKey);
                ret = CMSettings.Secure.getInt(cr, mKey, mDefaultValue);
                break;
            case TABLE_CM_SYSTEM:
                    ret = CMSettings.System.getInt(cr, mKey);
                ret = CMSettings.System.getInt(cr, mKey, mDefaultValue);
                break;
        }
        } catch (Settings.SettingNotFoundException|CMSettings.CMSettingNotFoundException e) {
            Log.e(TAG, "need to add a default setting for key: " + mKey
                    + " in table: " + mWhichTable);
            e.printStackTrace();
        }
        return ret == 1;
    }