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

Commit 7fb3323b authored by Abel Tesfaye's avatar Abel Tesfaye Committed by Android (Google) Code Review
Browse files

Merge "Implemented new preference setting screen for face based auto-rotation" into sc-dev

parents 16dfec5d a96775c5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -954,7 +954,7 @@
                <category android:name="com.android.settings.SHORTCUT" />
            </intent-filter>
            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                android:value="com.android.settings.DisplaySettings" />
                android:value="@string/rotate_settings_class" />
            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                android:value="true" />
        </activity>
+19 −0
Original line number Diff line number Diff line
@@ -97,6 +97,15 @@
    <!-- Description for the button that makes interface elements larger. [CHAR_LIMIT=NONE] -->
    <string name="font_size_make_larger_desc">Make larger</string>
    <!-- Auto rotate switchbar title. [CHAR_LIMIT=NONE] -->
    <string name="auto_rotate_settings_primary_switch_title">Use Auto-Rotate</string>
    <!-- Disclaimer for camera based rotate [CHAR_LIMIT=NONE] -->
    <string name="smart_rotate_text_headline">
        Face based Autorotate uses the front camera to see if and how someone is looking at the screen. It allows
        for reading while lying down and images are never stored or sent to Google.&lt;br>&lt;br>
       &lt;a href="<xliff:g example="http://www.google.com" id="url">http://support.google.com/mobile?p=telephony_rtt</xliff:g>">Learn more&lt;/a>
    </string>
    <string name="font_size_preview_text_headline">Sample text</string>
    <string name="font_size_preview_text_title"
            translation_description="Title text in sample text used to illustrate how the currently selected font size will appear to the user. NOTE: Translate manually. No not adopt any copyrighted material for translation.">
@@ -2704,8 +2713,18 @@
    <!-- Display settings --><skip/>
    <!-- Sound & display settings screen, section header for settings related to display -->
    <string name="display_settings">Display</string>
    <!-- Sound & display settings screen, section header for settings related to display -->
    <string name="rotate_settings_class" translatable="false">com.android.settings.DisplaySettings</string>
    <!-- Sound & display settings screen, accelerometer-based rotation check box label -->
    <string name="accelerometer_title">Auto-rotate screen</string>
    <!-- Sound & display settings screen, locked rotation check box label [CHAR LIMIT=30] -->
    <string name="auto_rotate_option_off">Off</string>
    <!-- Sound & display settings screen, accelerometer-based rotation check box label [CHAR LIMIT=30] -->
    <string name="auto_rotate_option_on">On</string>
    <!-- Sound & display settings screen, face-based rotation check box label [CHAR LIMIT=30] -->
    <string name="auto_rotate_option_face_based">On - Face-based</string>
    <!-- SmartAutoRotatePreferenceFragment settings screen, face-based rotation switch label [CHAR LIMIT=30] -->
    <string name="auto_rotate_switch_face_based">Enable Face Detection</string>
    <!-- Display settings screen, Color mode settings title [CHAR LIMIT=30] -->
    <string name="color_mode_title">Colors</string>
    <!-- Display settings screen, Color mode option for "natural(sRGB) color"  [CHAR LIMIT=45] -->
+33 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2021 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:title="@string/accelerometer_title" >

    <SwitchPreference
        android:key="face_based_rotate"
        android:title="@string/auto_rotate_switch_face_based"
        settings:controller="com.android.settings.display.SmartAutoRotateController" />

    <com.android.settingslib.widget.FooterPreference
        android:icon="@drawable/ic_privacy_shield_24dp"
        android:selectable="false"
        settings:searchable="false" />

</PreferenceScreen>
+2 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings;
import com.android.settings.deviceinfo.legal.ModuleLicensesDashboard;
import com.android.settings.display.NightDisplaySettings;
import com.android.settings.display.SmartAutoRotatePreferenceFragment;
import com.android.settings.display.darkmode.DarkModeSettingsFragment;
import com.android.settings.dream.DreamSettings;
import com.android.settings.enterprise.EnterprisePrivacySettings;
@@ -176,6 +177,7 @@ public class SettingsGateway {
            SavedAccessPointsWifiSettings2.class.getName(),
            AllInOneTetherSettings.class.getName(),
            TetherSettings.class.getName(),
            SmartAutoRotatePreferenceFragment.class.getName(),
            WifiP2pSettings.class.getName(),
            WifiTetherSettings.class.getName(),
            BackgroundCheckSummary.class.getName(),
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.display;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.widget.Switch;

import com.android.internal.view.RotationPolicy;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.OnMainSwitchChangeListener;

/**
 * The switch controller for the location.
 */
public class AutoRotateSwitchBarController implements OnMainSwitchChangeListener,
        LifecycleObserver, OnStart, OnStop {

    private final SettingsMainSwitchBar mSwitchBar;
    private final Context mContext;
    private boolean mValidListener;
    private final MetricsFeatureProvider mMetricsFeatureProvider;

    public AutoRotateSwitchBarController(Context context, SettingsMainSwitchBar switchBar,
            Lifecycle lifecycle) {
        mSwitchBar = switchBar;
        mContext = context;
        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
        if (lifecycle != null) {
            lifecycle.addObserver(this);
        }
    }

    @Override
    public void onStart() {
        if (!mValidListener) {
            mSwitchBar.addOnSwitchChangeListener(this);
            mValidListener = true;
        }
        onChange();
    }

    @Override
    public void onStop() {
        if (mValidListener) {
            mSwitchBar.removeOnSwitchChangeListener(this);
            mValidListener = false;
        }
    }

    /**
     * Listens to the state change of the rotation primary switch.
     */
    @Override
    public void onSwitchChanged(Switch switchView, boolean isChecked) {
        setRotationLock(isChecked);
    }


    protected void onChange() {
        final boolean isEnabled = !RotationPolicy.isRotationLocked(mContext);
        if (isEnabled != mSwitchBar.isChecked()) {
            // set listener to null so that that code below doesn't trigger onCheckedChanged()
            if (mValidListener) {
                mSwitchBar.removeOnSwitchChangeListener(this);
            }
            mSwitchBar.setChecked(isEnabled);
            if (mValidListener) {
                mSwitchBar.addOnSwitchChangeListener(this);
            }
        }
    }

    private boolean setRotationLock(boolean isChecked) {
        final boolean isLocked = !isChecked;
        mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATION_LOCK, isLocked);
        RotationPolicy.setRotationLock(mContext, isLocked);
        return true;
    }

}
Loading