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

Commit 4da3535c authored by sssemil's avatar sssemil Committed by Gerrit Code Review
Browse files

Customisable location tile(1/2)

Change-Id: I2287dc4566d2f7b5b6b92f834d80d6efa559f278
parent 8f4197d4
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -356,6 +356,20 @@
        <item>3</item>
    </string-array>

    <string-array name="entries_location_widget" translatable="false">
        <!-- Off is always preset -->
        <item>@string/cm_location_mode_battery_saving</item>
        <item>@string/cm_location_mode_device_only</item>
        <item>@string/cm_location_mode_high_accuracy</item>
    </string-array>

    <string-array name="values_location_widget" translatable="false">
        <!-- Off is always preset -->
        <item>1</item>
        <item>2</item>
        <item>3</item>
    </string-array>

    <!-- Quick pulldown -->
    <string-array name="quick_pulldown_entries" translatable="false">
        <item>@string/quick_pulldown_off</item>
+4 −0
Original line number Diff line number Diff line
@@ -401,6 +401,10 @@
    <string name="cm_sound_mode_vibrate">Vibrate</string>
    <string name="cm_sound_mode_sound">Sound</string>
    <string name="cm_sound_mode_soundVibrate">Sound &amp; Vibrate</string>
    <string name="pref_location_mode_title">Location modes</string>
    <string name="cm_location_mode_battery_saving">Battery saving</string>
    <string name="cm_location_mode_device_only">Device only</string>
    <string name="cm_location_mode_high_accuracy">High accuracy</string>

    <!-- Reset tiles -->
    <string name="tiles_reset_title">Reset</string>
+7 −0
Original line number Diff line number Diff line
@@ -74,6 +74,13 @@
            android:entries="@array/entries_screentimeout_widget"
            android:entryValues="@array/values_screentimeout_widget" />

        <MultiSelectListPreference
            android:key="pref_location_mode"
            android:dialogTitle="@string/pref_location_mode_title"
            android:title="@string/pref_location_mode_title"
            android:entries="@array/entries_location_widget"
            android:entryValues="@array/values_location_widget" />

        </PreferenceCategory>

    <PreferenceCategory
+33 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The CyanogenMod Project
 * Copyright (C) 2011-2014 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.Vibrator;
import android.preference.ListPreference;
import android.preference.MultiSelectListPreference;
@@ -48,6 +49,7 @@ public class QuickSettings extends SettingsPreferenceFragment implements

    private static final String SEPARATOR = "OV=I=XseparatorX=I=VO";
    private static final String EXP_RING_MODE = "pref_ring_mode";
    private static final String EXP_LOCATION_MODE = "pref_location_mode";
    private static final String EXP_NETWORK_MODE = "pref_network_mode";
    private static final String EXP_SCREENTIMEOUT_MODE = "pref_screentimeout_mode";
    private static final String QUICK_PULLDOWN = "quick_pulldown";
@@ -57,6 +59,7 @@ public class QuickSettings extends SettingsPreferenceFragment implements
    private static final String QS_SMALL_ICONS = "qs_small_icons";

    private MultiSelectListPreference mRingMode;
    private MultiSelectListPreference mLocationMode;
    private ListPreference mNetworkMode;
    private ListPreference mScreenTimeoutMode;
    private ListPreference mQuickPulldown;
@@ -112,6 +115,23 @@ public class QuickSettings extends SettingsPreferenceFragment implements
            }
        }

        mLocationMode = (MultiSelectListPreference) prefSet.findPreference(EXP_LOCATION_MODE);
        if (mLocationMode != null) {
                int currentLocatorMode = Settings.System.getIntForUser(resolver,
                        Settings.System.EXPANDED_LOCATION_MODE, 0, UserHandle.USER_CURRENT);
                Set<String> currentModes = new HashSet<String>();
                String[] modes = getResources().getStringArray(R.array.values_location_widget);
                int count = modes.length;
                for (int i = 0; i < count; i++) {
                    int mask = (int) Math.pow(2, i + 1); // Off is always preset
                    if ((currentLocatorMode & mask) == mask) {
                        currentModes.add(modes[i]);
                    }
                }
                mLocationMode.setValues(currentModes);
                mLocationMode.setOnPreferenceChangeListener(this);
        }

        // Add the network mode preference
        mNetworkMode = (ListPreference) prefSet.findPreference(EXP_NETWORK_MODE);
        if (mNetworkMode != null) {
@@ -179,6 +199,7 @@ public class QuickSettings extends SettingsPreferenceFragment implements
        }
    }

    @SuppressWarnings("unchecked")
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        ContentResolver resolver = getContentResolver();
        if (preference == mRingMode) {
@@ -188,6 +209,17 @@ public class QuickSettings extends SettingsPreferenceFragment implements
            Settings.System.putString(resolver, Settings.System.EXPANDED_RING_MODE, value);
            updateSummary(value, mRingMode, R.string.pref_ring_mode_summary);
            return true;
        } else if (preference == mLocationMode) {
            int currentLocatorMode = 1; // Off is always preset
            String[] currentModes = ((Set<String>) newValue).toArray(new String[]{});
            int count = currentModes.length;
            for (int i = 0; i < count; i++) {
                int index = mLocationMode.findIndexOfValue(currentModes[i]);
                currentLocatorMode |= (int) Math.pow(2, index + 1); // Off is always preset
            }
            Settings.System.putIntForUser(resolver, Settings.System.EXPANDED_LOCATION_MODE,
                    currentLocatorMode, UserHandle.USER_CURRENT);
            return true;
        } else if (preference == mNetworkMode) {
            int value = Integer.valueOf((String) newValue);
            int index = mNetworkMode.findIndexOfValue((String) newValue);