--- /dev/null
+<?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
<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>
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
package com.android.settings;
import android.annotation.Nullable;
+import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.AlertDialog;
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;
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;
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;
}
}
+ /**
+ * 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);
+ }
}
--- /dev/null
+/*
+ * 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);
+ }
+}