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

Commit 292ec906 authored by Adnan Begovic's avatar Adnan Begovic Committed by Steve Kondik
Browse files

Settings: Create default expanded desktop style fragment.

Change-Id: I01faf4985bac7a8a5054b5716af36208c39d4016
parent 4fd0a98b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
    <FrameLayout
            android:id="@+id/extra_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    <ListView
            android:id="@+id/user_list_view"
            android:layout_width="match_parent"
+12 −0
Original line number Diff line number Diff line
@@ -452,4 +452,16 @@
        <item>1004</item>
        <item>1005</item>
    </string-array>

    <string-array name="expanded_desktop_entries" translatable="false">
        <item>@string/expanded_hide_both</item>
        <item>@string/expanded_hide_status</item>
        <item>@string/expanded_hide_navigation</item>
    </string-array>

    <string-array name="expanded_desktop_values" translatable="false">
        <item>0</item>
        <item>1</item>
        <item>2</item>
    </string-array>
</resources>
+3 −1
Original line number Diff line number Diff line
@@ -1010,7 +1010,9 @@
    <string name="expanded_nothing_to_show">To add a custom per-app configuration for expanded state, set \'Enabled for all\' to the off position</string>
    <string name="expanded_desktop_state">Expanded state</string>
    <string name="expanded_enabled_for_all">Enabled for all</string>
    <string name="expanded_user_configurable">User configurable</string>
    <string name="expanded_desktop_style">Expanded desktop style</string>
    <string name="expanded_desktop_style_description">Choose a default expanded desktop style</string>
    <string name="expanded_desktop_title">Expanded desktop options</string>

    <string name="lockscreen_settings_title">Lock screen</string>
    <string name="lockscreen_targets_message">Lock screen shortcuts</string>
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 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.
     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">
    <PreferenceCategory
            android:title="@string/expanded_desktop_title" >
        <ListPreference
                android:key="expanded_desktop_style"
                android:title="@string/expanded_desktop_style"
                android:entries="@array/expanded_desktop_entries"
                android:entryValues="@array/expanded_desktop_values"/>
    </PreferenceCategory>
</PreferenceScreen>
 No newline at end of file
+149 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.
 * 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.applications;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Bundle;

import android.os.Handler;
import android.preference.ListPreference;
import android.preference.Preference;
import android.provider.Settings;
import android.view.WindowManager;
import android.view.WindowManagerPolicyControl;

import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;

public class ExpandedDesktopExtraPrefs extends SettingsPreferenceFragment
        implements Preference.OnPreferenceChangeListener{
    private static final String KEY_EXPANDED_DESKTOP_STYLE = "expanded_desktop_style";

    private ListPreference mExpandedDesktopStylePref;
    private int mExpandedDesktopStyle;
    private final Handler mHandler = new Handler();
    private final SettingsObserver mSettingsObserver = new SettingsObserver();

    public static ExpandedDesktopExtraPrefs newInstance() {
        ExpandedDesktopExtraPrefs expandedDesktopExtraPrefs = new ExpandedDesktopExtraPrefs();
        return expandedDesktopExtraPrefs;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.expanded_desktop_prefs);
        mExpandedDesktopStyle = getExpandedDesktopStyle();
        createPreferences();
    }

    @Override
    public void onResume() {
        super.onResume();
        mSettingsObserver.register(true);
    }

    @Override
    public void onPause() {
        mSettingsObserver.register(false);
        super.onPause();
    }

    public void createPreferences() {
        mExpandedDesktopStylePref = (ListPreference) findPreference(KEY_EXPANDED_DESKTOP_STYLE);
        mExpandedDesktopStylePref.setOnPreferenceChangeListener(this);
        updateExpandedDesktopStyle();
    }

    private void updateExpandedDesktopStyle() {
        if (mExpandedDesktopStylePref == null) {
            return;
        }
        mExpandedDesktopStyle = getExpandedDesktopStyle();
        mExpandedDesktopStylePref.setValueIndex(mExpandedDesktopStyle);
        mExpandedDesktopStylePref.setSummary(getDesktopSummary(mExpandedDesktopStyle));
        // We need to visually show the change
        // TODO: This is hacky, but it works
        writeValue("");
        writeValue("immersive.full=*");
    }

    private int getDesktopSummary(int state) {
        switch (state) {
            case WindowManagerPolicyControl.ImmersiveDefaultStyles.IMMERSIVE_STATUS:
                return R.string.expanded_hide_status;
            case WindowManagerPolicyControl.ImmersiveDefaultStyles.IMMERSIVE_NAVIGATION:
                return R.string.expanded_hide_navigation;
            case WindowManagerPolicyControl.ImmersiveDefaultStyles.IMMERSIVE_FULL:
            default:
                return R.string.expanded_hide_both;
        }
    }

    private int getExpandedDesktopStyle() {
        return Settings.Global.getInt(getContentResolver(),
                Settings.Global.POLICY_CONTROL_STYLE,
                WindowManagerPolicyControl.ImmersiveDefaultStyles.IMMERSIVE_FULL);
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object value) {
        final int val = Integer.valueOf((String) value);
        WindowManagerPolicyControl.saveStyleToSettings(getActivity(), val);
        return false;
    }

    private void writeValue(String value) {
        Settings.Global.putString(getContentResolver(), Settings.Global.POLICY_CONTROL, value);
    }

    // === Window Policy Style Callbacks ===

    private final class SettingsObserver extends ContentObserver {
        private final Uri DEFAULT_WINDOW_POLICY_STYLE =
                Settings.Global.getUriFor(Settings.Global.POLICY_CONTROL_STYLE);

        public SettingsObserver() {
            super(mHandler);
        }

        public void register(boolean register) {
            final ContentResolver cr = getContentResolver();
            if (register) {
                cr.registerContentObserver(DEFAULT_WINDOW_POLICY_STYLE, false, this);
            } else {
                cr.unregisterContentObserver(this);
            }
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            super.onChange(selfChange, uri);
            if (DEFAULT_WINDOW_POLICY_STYLE.equals(uri)) {
                updateExpandedDesktopStyle();
            }
        }
    }
}
Loading