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

Commit d4726d06 authored by Winson Chung's avatar Winson Chung
Browse files

Adding rotation lock tile to quick settings (on tablets).

Change-Id: Ia68c07051acc1f0f42dde0b1322db034b5d54506
parent ad92ce85
Loading
Loading
Loading
Loading
+25 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 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.
-->
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/TextAppearance.QuickSettings.TileView"
    android:id="@+id/rotation_lock_textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:text="@string/quick_settings_rotation_unlocked_label"
    />
 No newline at end of file
+3 −0
Original line number Original line Diff line number Diff line
@@ -25,4 +25,7 @@


    <!-- The number of columns that the top level tiles span in the QuickSettings -->
    <!-- The number of columns that the top level tiles span in the QuickSettings -->
    <integer name="quick_settings_user_time_settings_tile_span">1</integer>
    <integer name="quick_settings_user_time_settings_tile_span">1</integer>

    <!-- Whether rotation lock shows up in quick settings or not -->
    <bool name="quick_settings_show_rotation_lock">true</bool>
</resources>
</resources>
+3 −0
Original line number Original line Diff line number Diff line
@@ -87,5 +87,8 @@


    <!-- The number of columns that the top level tiles span in the QuickSettings -->
    <!-- The number of columns that the top level tiles span in the QuickSettings -->
    <integer name="quick_settings_user_time_settings_tile_span">1</integer>
    <integer name="quick_settings_user_time_settings_tile_span">1</integer>

    <!-- Whether rotation lock shows up in quick settings or not -->
    <bool name="quick_settings_show_rotation_lock">false</bool>
</resources>
</resources>
+4 −0
Original line number Original line Diff line number Diff line
@@ -411,6 +411,10 @@
    <string name="quick_settings_bluetooth_label">Bluetooth</string>
    <string name="quick_settings_bluetooth_label">Bluetooth</string>
    <!-- QuickSettings: Brightness [CHAR LIMIT=NONE] -->
    <!-- QuickSettings: Brightness [CHAR LIMIT=NONE] -->
    <string name="quick_settings_brightness_label">Brightness</string>
    <string name="quick_settings_brightness_label">Brightness</string>
    <!-- QuickSettings: Rotation Unlocked [CHAR LIMIT=NONE] -->
    <string name="quick_settings_rotation_unlocked_label">Auto Rotate</string>
    <!-- QuickSettings: Rotation Locked [CHAR LIMIT=NONE] -->
    <string name="quick_settings_rotation_locked_label">Rotation Locked</string>
    <!-- QuickSettings: IME [CHAR LIMIT=NONE] -->
    <!-- QuickSettings: IME [CHAR LIMIT=NONE] -->
    <string name="quick_settings_ime_label">Input Method</string>
    <string name="quick_settings_ime_label">Input Method</string>
    <!-- QuickSettings: Location [CHAR LIMIT=NONE] -->
    <!-- QuickSettings: Location [CHAR LIMIT=NONE] -->
+33 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.TextView;


import com.android.internal.view.RotationPolicy;
import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.statusbar.phone.QuickSettingsModel.State;
import com.android.systemui.statusbar.phone.QuickSettingsModel.State;
import com.android.systemui.statusbar.phone.QuickSettingsModel.UserState;
import com.android.systemui.statusbar.phone.QuickSettingsModel.UserState;
@@ -89,6 +90,14 @@ class QuickSettings {
    private final ArrayList<QuickSettingsTileView> mDynamicSpannedTiles =
    private final ArrayList<QuickSettingsTileView> mDynamicSpannedTiles =
            new ArrayList<QuickSettingsTileView>();
            new ArrayList<QuickSettingsTileView>();


    private final RotationPolicy.RotationPolicyListener mRotationPolicyListener =
            new RotationPolicy.RotationPolicyListener() {
        @Override
        public void onChange() {
            mModel.onRotationLockChanged();
        }
    };

    public QuickSettings(Context context, QuickSettingsContainerView container) {
    public QuickSettings(Context context, QuickSettingsContainerView container) {
        mDisplayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        mDisplayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        mContext = context;
        mContext = context;
@@ -125,6 +134,7 @@ class QuickSettings {
        bluetoothController.addStateChangedCallback(mModel);
        bluetoothController.addStateChangedCallback(mModel);
        batteryController.addStateChangedCallback(mModel);
        batteryController.addStateChangedCallback(mModel);
        locationController.addStateChangedCallback(mModel);
        locationController.addStateChangedCallback(mModel);
        RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener);
    }
    }


    private void queryForUserInformation() {
    private void queryForUserInformation() {
@@ -293,6 +303,29 @@ class QuickSettings {
            parent.addView(rssiTile);
            parent.addView(rssiTile);
        }
        }


        // Rotation Lock
        if (mContext.getResources().getBoolean(R.bool.quick_settings_show_rotation_lock)) {
            QuickSettingsTileView rotationLockTile = (QuickSettingsTileView)
                    inflater.inflate(R.layout.quick_settings_tile, parent, false);
            rotationLockTile.setContent(R.layout.quick_settings_tile_rotation_lock, inflater);
            rotationLockTile.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    boolean locked = RotationPolicy.isRotationLocked(mContext);
                    RotationPolicy.setRotationLock(mContext, !locked);
                }
            });
            mModel.addRotationLockTile(rotationLockTile, new QuickSettingsModel.RefreshCallback() {
                @Override
                public void refreshView(QuickSettingsTileView view, State state) {
                    TextView tv = (TextView) view.findViewById(R.id.rotation_lock_textview);
                    tv.setCompoundDrawablesRelativeWithIntrinsicBounds(0, state.iconId, 0, 0);
                    tv.setText(state.label);
                }
            });
            parent.addView(rotationLockTile);
        }

        // Battery
        // Battery
        QuickSettingsTileView batteryTile = (QuickSettingsTileView)
        QuickSettingsTileView batteryTile = (QuickSettingsTileView)
                inflater.inflate(R.layout.quick_settings_tile, parent, false);
                inflater.inflate(R.layout.quick_settings_tile, parent, false);
Loading