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

Commit bcd2b572 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Adnan Begovic
Browse files

Settings: add "advanced" menu to Display/TapToWake

          Forward TapToWake from CM11

          Contains Commits:

          Author: Ricardo Cerqueira<cyanogenmod@cerqueira.org>
          DisplaySettings: Add hardware-framework support for tap-to-wake

          Since we have tap-to-sleep globally, might as well support the
          wake gesture as a standalone thing through the HAF. Place it in
          "Display".
          Change-Id: I6facc2334ff9e80077581c54c428476594e91528

          Author: Roman Birg <roman@cyngn.com>
          Settings: set proper default value for tap to wake

          The first time the display_settings.xml file gets inflated, the
          PreferenceManager takes the defaultValue and persists it in the default
          shared preferences file.
          When we read the double tap to wake preference,
          we assume it has a default value of true, which it uses until the user
          enters Display Settings for the first time. At that point, the default
          value is persisted, and every boot after will use the default value in
          display_settings.xml.
          Remove the default defined in the XML file.
          Change-Id: I0989dd73b6b3c42ff8649bc17eebf4e191293ee4

Change-Id: I271390aa7bfc56811dcf6fff7e1d05c76c4bfa48
parent 5719bbe7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ include frameworks/opt/setupwizard/navigationbar/common.mk
include frameworks/opt/setupwizard/library/common.mk
include frameworks/base/packages/SettingsLib/common.mk

LOCAL_JAVA_LIBRARIES += org.cyanogenmod.hardware

include $(BUILD_PACKAGE)

# Use the following include to make our test apk.
+8 −0
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@
            android:usesCleartextTraffic="false">

        <!-- Settings -->
        <uses-library android:name="org.cyanogenmod.hardware"
                android:required="false" />

        <activity android:name="Settings"
                android:taskAffinity="com.android.settings"
@@ -2509,6 +2511,12 @@
            </intent-filter>
        </receiver>

        <receiver android:name=".cyanogenmod.BootReceiver" android:enabled="true">$
            <intent-filter android:priority="2147483647">$
                <action android:name="android.intent.action.BOOT_COMPLETED" />$
            </intent-filter>$
        </receiver>

        <!-- Watch for ContactsContract.Profile changes and update the user's photo.  -->
        <receiver android:name=".users.ProfileUpdateReceiver">
            <intent-filter>
+7 −0
Original line number Diff line number Diff line
@@ -398,4 +398,11 @@

    <string name="navigation_ring_title">Navigation ring targets</string>
    <string name="navigation_ring_message">Tap the edit icon to open the navigation ring for editing.\n\nSelect a target to configure its behavior.\n\nTap the check mark icon to save your changes, or restore to reset the settings to defaults.</string>

    <!--- Advanced Settings -->
    <string name="advanced_settings">Advanced settings</string>
    <string name="advanced_settings_summary">Enable more settings options</string>

    <!--- Tap To Wake -->
    <string name="double_tap_to_wake_title">Double-tap to wake</string>
</resources>
+7 −0
Original line number Diff line number Diff line
@@ -97,5 +97,12 @@
                android:title="@string/wifi_display_settings_title"
                settings:keywords="@string/keywords_display_cast_screen"
                android:fragment="com.android.settings.wfd.WifiDisplaySettings" />
        <PreferenceScreen
                android:key="advanced_display_prefs"
                android:title="@string/advanced_settings">

                <SwitchPreference
                    android:key="double_tap_wake_gesture"
                    android:title="@string/double_tap_to_wake_title" />
        </PreferenceScreen>
</PreferenceScreen>
+49 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Build;
@@ -48,6 +49,7 @@ import android.os.SystemProperties;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.provider.SearchIndexableResource;
@@ -59,6 +61,7 @@ import java.util.ArrayList;
import java.util.List;

import com.android.settings.Utils;
import org.cyanogenmod.hardware.TapToWake;

public class DisplaySettings extends SettingsPreferenceFragment implements
        Preference.OnPreferenceChangeListener, OnPreferenceClickListener, Indexable {
@@ -76,6 +79,9 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
    private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness";
    private static final String KEY_AUTO_ROTATE = "auto_rotate";
    private static final String KEY_NIGHT_MODE = "night_mode";
    private static final String KEY_TAP_TO_WAKE = "double_tap_wake_gesture";

    private static final String CATEGORY_ADVANCED = "advanced_display_prefs";

    private static final int DLG_GLOBAL_CHANGE_WARNING = 1;

@@ -90,6 +96,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
    private SwitchPreference mDozePreference;
    private SwitchPreference mTapToWakePreference;
    private SwitchPreference mAutoBrightnessPreference;
    private SwitchPreference mTapToWake;

    @Override
    protected int getMetricsCategory() {
@@ -197,6 +204,13 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
            mNightModePreference.setValue(String.valueOf(currentNightMode));
            mNightModePreference.setOnPreferenceChangeListener(this);
        }
        PreferenceScreen advancedPrefs = (PreferenceScreen) findPreference(CATEGORY_ADVANCED);

        mTapToWake = (SwitchPreference) findPreference(KEY_TAP_TO_WAKE);
        if (!isTapToWakeSupported()) {
            advancedPrefs.removePreference(mTapToWake);
            mTapToWake = null;
        }
    }

    private static boolean allowAllRotations(Context context) {
@@ -318,6 +332,11 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
    @Override
    public void onResume() {
        super.onResume();

        if (mTapToWake != null) {
            mTapToWake.setChecked(TapToWake.isEnabled());
        }

        updateState();
    }

@@ -372,6 +391,15 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
        }
    }

    private static boolean isTapToWakeSupported() {
        try {
            return TapToWake.isSupported();
        } catch (NoClassDefFoundError e) {
            // Hardware abstraction framework not installed
            return false;
        }
    }

    public void writeFontSizePreference(Object objValue) {
        try {
            mCurConfig.fontScale = Float.parseFloat(objValue.toString());
@@ -383,6 +411,10 @@ public class DisplaySettings extends SettingsPreferenceFragment implements

    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
        if (preference == mTapToWake) {
            return TapToWake.setEnabled(mTapToWake.isChecked());
        }

        return super.onPreferenceTreeClick(preferenceScreen, preference);
    }

@@ -449,6 +481,23 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
        return R.string.help_uri_display;
    }

    /**
     * Restore the properties associated with this preference on boot
       @param ctx A valid context
     */
    public static void restore(Context ctx) {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
        if (isTapToWakeSupported()) {
            final boolean enabled = prefs.getBoolean(KEY_TAP_TO_WAKE,
                TapToWake.isEnabled());
            if (!TapToWake.setEnabled(enabled)) {
                Log.e(TAG, "Failed to restore tap-to-wake settings.");
            } else {
                Log.d(TAG, "Tap-to-wake settings restored.");
            }
        }
    }

    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider() {
                @Override
Loading