OSDN Git Service

Settings : Add back navigation bar customization.
authorDanny Baumann <dannybaumann@web.de>
Fri, 22 Nov 2013 10:21:21 +0000 (11:21 +0100)
committerAdnan Begovic <adnan@cyngn.com>
Fri, 30 Oct 2015 00:36:28 +0000 (17:36 -0700)
Change-Id: I6431a611f3107fd1022df11362d1d2aa27b2f436

24 files changed:
res/drawable-hdpi/ic_navbar_edit.png [new file with mode: 0644]
res/drawable-hdpi/ic_navbar_restore.png [new file with mode: 0644]
res/drawable-hdpi/ic_navbar_save.png [new file with mode: 0644]
res/drawable-hdpi/stat_navbar_edit_off.png [new file with mode: 0644]
res/drawable-hdpi/stat_navbar_edit_on.png [new file with mode: 0644]
res/drawable-mdpi/ic_navbar_edit.png [new file with mode: 0644]
res/drawable-mdpi/ic_navbar_restore.png [new file with mode: 0644]
res/drawable-mdpi/ic_navbar_save.png [new file with mode: 0644]
res/drawable-mdpi/stat_navbar_edit_off.png [new file with mode: 0644]
res/drawable-mdpi/stat_navbar_edit_on.png [new file with mode: 0644]
res/drawable-xhdpi/ic_navbar_edit.png [new file with mode: 0644]
res/drawable-xhdpi/ic_navbar_restore.png [new file with mode: 0644]
res/drawable-xhdpi/ic_navbar_save.png [new file with mode: 0644]
res/drawable-xhdpi/stat_navbar_edit_off.png [new file with mode: 0644]
res/drawable-xhdpi/stat_navbar_edit_on.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_navbar_edit.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_navbar_restore.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_navbar_save.png [new file with mode: 0644]
res/drawable/navbar_tut.png [new file with mode: 0644]
res/layout/nav_bar.xml [new file with mode: 0644]
res/values/cm_strings.xml
res/xml/button_settings.xml
src/com/android/settings/Utils.java
src/com/android/settings/cyanogenmod/NavBar.java [new file with mode: 0644]

diff --git a/res/drawable-hdpi/ic_navbar_edit.png b/res/drawable-hdpi/ic_navbar_edit.png
new file mode 100644 (file)
index 0000000..5448804
Binary files /dev/null and b/res/drawable-hdpi/ic_navbar_edit.png differ
diff --git a/res/drawable-hdpi/ic_navbar_restore.png b/res/drawable-hdpi/ic_navbar_restore.png
new file mode 100644 (file)
index 0000000..04d1aa0
Binary files /dev/null and b/res/drawable-hdpi/ic_navbar_restore.png differ
diff --git a/res/drawable-hdpi/ic_navbar_save.png b/res/drawable-hdpi/ic_navbar_save.png
new file mode 100644 (file)
index 0000000..fdfb1f3
Binary files /dev/null and b/res/drawable-hdpi/ic_navbar_save.png differ
diff --git a/res/drawable-hdpi/stat_navbar_edit_off.png b/res/drawable-hdpi/stat_navbar_edit_off.png
new file mode 100644 (file)
index 0000000..d796bde
Binary files /dev/null and b/res/drawable-hdpi/stat_navbar_edit_off.png differ
diff --git a/res/drawable-hdpi/stat_navbar_edit_on.png b/res/drawable-hdpi/stat_navbar_edit_on.png
new file mode 100644 (file)
index 0000000..263c0ed
Binary files /dev/null and b/res/drawable-hdpi/stat_navbar_edit_on.png differ
diff --git a/res/drawable-mdpi/ic_navbar_edit.png b/res/drawable-mdpi/ic_navbar_edit.png
new file mode 100644 (file)
index 0000000..78f3704
Binary files /dev/null and b/res/drawable-mdpi/ic_navbar_edit.png differ
diff --git a/res/drawable-mdpi/ic_navbar_restore.png b/res/drawable-mdpi/ic_navbar_restore.png
new file mode 100644 (file)
index 0000000..8bfe6c3
Binary files /dev/null and b/res/drawable-mdpi/ic_navbar_restore.png differ
diff --git a/res/drawable-mdpi/ic_navbar_save.png b/res/drawable-mdpi/ic_navbar_save.png
new file mode 100644 (file)
index 0000000..45f6258
Binary files /dev/null and b/res/drawable-mdpi/ic_navbar_save.png differ
diff --git a/res/drawable-mdpi/stat_navbar_edit_off.png b/res/drawable-mdpi/stat_navbar_edit_off.png
new file mode 100644 (file)
index 0000000..0520768
Binary files /dev/null and b/res/drawable-mdpi/stat_navbar_edit_off.png differ
diff --git a/res/drawable-mdpi/stat_navbar_edit_on.png b/res/drawable-mdpi/stat_navbar_edit_on.png
new file mode 100644 (file)
index 0000000..8c93091
Binary files /dev/null and b/res/drawable-mdpi/stat_navbar_edit_on.png differ
diff --git a/res/drawable-xhdpi/ic_navbar_edit.png b/res/drawable-xhdpi/ic_navbar_edit.png
new file mode 100644 (file)
index 0000000..abe6a24
Binary files /dev/null and b/res/drawable-xhdpi/ic_navbar_edit.png differ
diff --git a/res/drawable-xhdpi/ic_navbar_restore.png b/res/drawable-xhdpi/ic_navbar_restore.png
new file mode 100644 (file)
index 0000000..faba694
Binary files /dev/null and b/res/drawable-xhdpi/ic_navbar_restore.png differ
diff --git a/res/drawable-xhdpi/ic_navbar_save.png b/res/drawable-xhdpi/ic_navbar_save.png
new file mode 100644 (file)
index 0000000..e39ebe9
Binary files /dev/null and b/res/drawable-xhdpi/ic_navbar_save.png differ
diff --git a/res/drawable-xhdpi/stat_navbar_edit_off.png b/res/drawable-xhdpi/stat_navbar_edit_off.png
new file mode 100644 (file)
index 0000000..d0c63a0
Binary files /dev/null and b/res/drawable-xhdpi/stat_navbar_edit_off.png differ
diff --git a/res/drawable-xhdpi/stat_navbar_edit_on.png b/res/drawable-xhdpi/stat_navbar_edit_on.png
new file mode 100644 (file)
index 0000000..1bfee82
Binary files /dev/null and b/res/drawable-xhdpi/stat_navbar_edit_on.png differ
diff --git a/res/drawable-xxhdpi/ic_navbar_edit.png b/res/drawable-xxhdpi/ic_navbar_edit.png
new file mode 100644 (file)
index 0000000..7327ed7
Binary files /dev/null and b/res/drawable-xxhdpi/ic_navbar_edit.png differ
diff --git a/res/drawable-xxhdpi/ic_navbar_restore.png b/res/drawable-xxhdpi/ic_navbar_restore.png
new file mode 100644 (file)
index 0000000..e98aad8
Binary files /dev/null and b/res/drawable-xxhdpi/ic_navbar_restore.png differ
diff --git a/res/drawable-xxhdpi/ic_navbar_save.png b/res/drawable-xxhdpi/ic_navbar_save.png
new file mode 100644 (file)
index 0000000..f09cc00
Binary files /dev/null and b/res/drawable-xxhdpi/ic_navbar_save.png differ
diff --git a/res/drawable/navbar_tut.png b/res/drawable/navbar_tut.png
new file mode 100644 (file)
index 0000000..44578f5
Binary files /dev/null and b/res/drawable/navbar_tut.png differ
diff --git a/res/layout/nav_bar.xml b/res/layout/nav_bar.xml
new file mode 100644 (file)
index 0000000..71de6f6
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:padding="25dp"
+    android:orientation="vertical">
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_margin="8dip"
+        android:layout_gravity="center"
+        android:layout_weight="0.2"
+        android:text="@string/navigation_bar_help_text"
+        android:textSize="14sp" />
+    <LinearLayout
+        android:layout_weight="0.8"
+        android:layout_width="match_parent"
+        android:gravity="center_horizontal"
+        android:layout_height="0dp">
+        <LinearLayout
+            android:id="@+id/navbar_restore"
+            android:layout_marginRight="25dp"
+            style="?android:attr/borderlessButtonStyle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:orientation="vertical"
+            android:gravity="center">
+            <ImageView
+                android:paddingBottom="15dp"
+                android:layout_width="60dp"
+                android:layout_height="60dp"
+                android:src="@drawable/ic_navbar_restore" />
+            <TextView
+                android:gravity="center_horizontal"
+                android:textAllCaps="true"
+                android:text="@string/navigation_restore_button_text"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textSize="14sp" />
+        </LinearLayout>
+        <LinearLayout
+            android:visibility="gone"
+            android:id="@+id/navbar_save"
+            style="?android:attr/borderlessButtonStyle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:orientation="vertical"
+            android:gravity="center">
+            <ImageView
+                android:paddingBottom="15dp"
+                android:layout_width="60dp"
+                android:layout_height="60dp"
+                android:src="@drawable/ic_navbar_save" />
+            <TextView
+                android:textAllCaps="true"
+                android:text="@string/navigation_save_button_text"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textSize="14sp" />
+        </LinearLayout>
+        <LinearLayout
+            android:id="@+id/navbar_edit"
+            style="?android:attr/borderlessButtonStyle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:orientation="vertical"
+            android:gravity="center">
+            <ImageView
+                android:paddingBottom="15dp"
+                android:layout_width="60dp"
+                android:layout_height="60dp"
+                android:src="@drawable/ic_navbar_edit" />
+            <TextView
+                android:textAllCaps="true"
+                android:text="@string/navigation_edit_button_text"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textSize="14sp" />
+        </LinearLayout>
+    </LinearLayout>
+</LinearLayout>
\ No newline at end of file
index 0dde3ab..51cff4e 100644 (file)
     <string name="navigation_bar_category">Navigation bar</string>
     <string name="navigation_bar_left_title">Left-handed mode</string>
     <string name="navigation_bar_left_summary">Place the navigation bar on the left side of the screen in landscape mode</string>
+    <string name="navigation_bar_title">Buttons and layout</string>
+    <string name="navigation_bar_help_text">To get started tap the edit icon to unlock the navigation bar for editing.\n\nYou can tap an icon to change its shortcut, or long press an icon to re-arrange the layout.\n\nTap save to commit your changes, or restore to reset the layout to default settings.</string>
+    <string name="navigation_restore_button_text">Restore\ndefaults</string>
+    <string name="navigation_edit_button_text">Edit</string>
+    <string name="navigation_save_button_text">Save</string>
+    <string name="navigation_bar_reset_message">Delete current settings and restore the default layout?</string>
 
     <!-- Notification light dialogs -->
     <string name="edit_light_settings">Edit light settings</string>
index c36d0e1..b5151cf 100644 (file)
             android:summary="@string/navigation_bar_left_summary"
             android:defaultValue="false" />
 
+        <PreferenceScreen
+            android:key="navigation_bar"
+            android:fragment="com.android.settings.cyanogenmod.NavBar"
+            android:title="@string/navigation_bar_title" />
+
     </PreferenceCategory>
 
     <PreferenceCategory
index b1170c8..0834c8d 100644 (file)
@@ -17,6 +17,7 @@
 package com.android.settings;
 
 import android.annotation.Nullable;
+import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.ActivityManagerNative;
 import android.app.AlertDialog;
@@ -31,6 +32,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.IPackageManager;
 import android.content.pm.IntentFilterVerificationInfo;
@@ -40,6 +42,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.content.pm.Signature;
 import android.content.pm.UserInfo;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.content.res.Resources.NotFoundException;
 import android.content.res.TypedArray;
@@ -81,6 +84,8 @@ import android.util.ArraySet;
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.LayoutInflater;
+import android.view.DisplayInfo;
+import android.view.Surface;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.animation.Animation;
@@ -1422,4 +1427,36 @@ public final class Utils {
         }
     }
 
+    /**
+     * Locks the activity orientation to the current device orientation
+     * @param activity
+     */
+    public static void lockCurrentOrientation(Activity activity) {
+        int currentRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
+        int orientation = activity.getResources().getConfiguration().orientation;
+        int frozenRotation = 0;
+        switch (currentRotation) {
+            case Surface.ROTATION_0:
+                frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
+                        ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+                        : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+                break;
+            case Surface.ROTATION_90:
+                frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
+                        ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
+                        : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+                break;
+            case Surface.ROTATION_180:
+                frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
+                        ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
+                        : ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+                break;
+            case Surface.ROTATION_270:
+                frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
+                        ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+                        : ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+                break;
+        }
+        activity.setRequestedOrientation(frozenRotation);
+    }
 }
diff --git a/src/com/android/settings/cyanogenmod/NavBar.java b/src/com/android/settings/cyanogenmod/NavBar.java
new file mode 100644 (file)
index 0000000..6ce028d
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * 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.cyanogenmod;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Fragment;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import com.android.settings.R;
+import com.android.settings.Utils;
+
+public class NavBar extends Fragment implements View.OnClickListener {
+
+    private LinearLayout mRestore, mSave, mEdit;
+    private boolean mEditMode;
+    private Activity mActivity;
+    private final static Intent mIntent = new Intent("android.intent.action.NAVBAR_EDIT");
+
+    @Override
+    public void onAttach(Activity activity) {
+        super.onAttach(activity);
+        mActivity = activity;
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.nav_bar, container, false);
+    }
+
+    @Override
+    public void onViewCreated(View view, Bundle savedInstanceState) {
+        mEdit = (LinearLayout) view.findViewById(R.id.navbar_edit);
+        mEdit.setOnClickListener(this);
+        mSave = (LinearLayout) view.findViewById(R.id.navbar_save);
+        mSave.setOnClickListener(this);
+        mRestore = (LinearLayout) view.findViewById(R.id.navbar_restore);
+        mRestore.setOnClickListener(this);
+    }
+
+    @Override
+    public void onDetach() {
+        mActivity = null;
+        super.onDetach();
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+        toggleEditMode(false, false);
+    }
+
+    @Override
+    public void onClick(View v) {
+        if (v == mEdit) {
+            mEditMode = !mEditMode;
+            toggleEditMode(mEditMode, false);
+        } else if (v == mSave) {
+            mEditMode = !mEditMode;
+            toggleEditMode(mEditMode, true);
+        } else if (v == mRestore) {
+            new AlertDialog.Builder(mActivity)
+                    .setTitle(R.string.profile_reset_title)
+                    .setIcon(R.drawable.ic_navbar_restore)
+                    .setMessage(R.string.navigation_bar_reset_message)
+                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int id) {
+                            if (mEditMode) {
+                                toggleEditMode(false, false);
+                            }
+                            Settings.System.putString(getActivity().getContentResolver(),
+                                    Settings.System.NAV_BUTTONS, null);
+                            toggleEditMode(true, false);
+                            toggleEditMode(false, false);
+                            mEditMode = false;
+                        }
+                    }).setNegativeButton(R.string.cancel, null)
+                    .create().show();
+        }
+    }
+
+    /**
+     * Toggles navbar edit mode
+     * @param on True to enter edit mode / false to exit
+     * @param save True to save changes / false to discard them
+     */
+    private void toggleEditMode(boolean on, boolean save) {
+        mIntent.putExtra("edit", on);
+        mIntent.putExtra("save", save);
+        mActivity.sendBroadcast(mIntent);
+        if (on) {
+            Utils.lockCurrentOrientation(mActivity);
+        } else {
+            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
+        }
+        toggleEditSaveViews(on);
+    }
+
+    private void toggleEditSaveViews(boolean on) {
+        mEdit.setVisibility(!on ? View.VISIBLE : View.GONE);
+        mSave.setVisibility(on
+                ? View.VISIBLE : View.GONE);
+    }
+}