Merge "Change VPN failure notification to dialog" into nyc-dev
diff --git a/res/layout/condition_card.xml b/res/layout/condition_card.xml
index c1224b5..4ddb084 100644
--- a/res/layout/condition_card.xml
+++ b/res/layout/condition_card.xml
@@ -104,7 +104,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="0dp"
- android:alpha=".7"
+ android:alpha=".8"
android:textColor="?android:attr/textColorPrimaryInverse"
style="?android:attr/buttonBarButtonStyle" />
@@ -112,7 +112,7 @@
android:id="@+id/second_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:alpha=".7"
+ android:alpha=".8"
android:textColor="?android:attr/textColorPrimaryInverse"
style="?android:attr/buttonBarButtonStyle" />
diff --git a/res/layout/locale_drag_cell.xml b/res/layout/locale_drag_cell.xml
index 522f284..db9454a 100644
--- a/res/layout/locale_drag_cell.xml
+++ b/res/layout/locale_drag_cell.xml
@@ -68,6 +68,7 @@
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:layout_gravity="center_vertical"
android:src="@drawable/drag_handle"
+ android:importantForAccessibility="no"
android:layout_alignParentEnd="true"
android:layout_alignTop="@id/checkbox"
android:layout_alignBottom="@id/checkbox"/>
diff --git a/res/values/ids.xml b/res/values/ids.xml
index f9334e4..dcf279a 100644
--- a/res/values/ids.xml
+++ b/res/values/ids.xml
@@ -24,4 +24,11 @@
<item type="id" name="lock_password" />
<item type="id" name="encrypt_dont_require_password" />
+
+ <!-- Used for custom accessibility actions in the Drag-and-Drop locale list -->
+ <item type="id" name="action_drag_move_up" />
+ <item type="id" name="action_drag_move_down" />
+ <item type="id" name="action_drag_move_top" />
+ <item type="id" name="action_drag_move_bottom" />
+ <item type="id" name="action_drag_remove" />
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e6a9801..fb18ec3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -530,6 +530,17 @@
<!-- This text shows in the language picker when the system is not translated into that languages [CHAR LIMIT=80] -->
<string name="locale_not_translated">May not be available in some apps</string>
+ <!-- Label for an accessibility action that moves a language up in the ordered language list [CHAR LIMIT=20] -->
+ <string name="action_drag_label_move_up">Move up</string>
+ <!-- Label for an accessibility action that moves a language down in the ordered language list [CHAR LIMIT=20] -->
+ <string name="action_drag_label_move_down">Move down</string>
+ <!-- Label for an accessibility action that moves a language to the top of the ordered language list [CHAR LIMIT=20] -->
+ <string name="action_drag_label_move_top">Move to top</string>
+ <!-- Label for an accessibility action that moves a language to the bottom of the ordered language list [CHAR LIMIT=20] -->
+ <string name="action_drag_label_move_bottom">Move to bottom</string>
+ <!-- Label for an accessibility action that removes the currently selected language from the the ordered language list [CHAR LIMIT=20] -->
+ <string name="action_drag_label_remove">Remove language</string>
+
<!-- The title of the dialog to pick an activity. This is shown when there are multiple activities that can do a particular action. For example, suppose you click on the "Share" menu item in the Browser. Since you can share the webpage URL via many communication methods, this dialog would come up with choices like "Email", "IM", etc. This is a generic message, and the previous example is a single possible scenario (so please don't assume it's for the browser or anything :) ). -->
<string name="activity_picker_label">Choose activity</string>
<!-- Do not translate. -->
diff --git a/src/com/android/settings/dashboard/SummaryLoader.java b/src/com/android/settings/dashboard/SummaryLoader.java
index 13f2cf4..814d1e4 100644
--- a/src/com/android/settings/dashboard/SummaryLoader.java
+++ b/src/com/android/settings/dashboard/SummaryLoader.java
@@ -94,14 +94,17 @@
});
}
+ /**
+ * Only call from the main thread.
+ */
public void setListening(boolean listening) {
- synchronized (mReceivers) {
- // Unregister listeners immediately.
- for (int i = 0; i < mReceivers.size(); i++) {
- mActivity.unregisterReceiver(mReceivers.get(i));
- }
- mReceivers.clear();
+ if (mListening == listening) return;
+ mListening = listening;
+ // Unregister listeners immediately.
+ for (int i = 0; i < mReceivers.size(); i++) {
+ mActivity.unregisterReceiver(mReceivers.get(i));
}
+ mReceivers.clear();
mWorker.obtainMessage(Worker.MSG_SET_LISTENING, listening ? 1 : 0, 0).sendToTarget();
}
@@ -147,20 +150,21 @@
* This ensures that the receivers are unregistered immediately, since most summary loader
* operations are asynchronous.
*/
- public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
- synchronized (mReceivers) {
- if (!mListening) {
- return;
+ public void registerReceiver(final BroadcastReceiver receiver, final IntentFilter filter) {
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (!mListening) {
+ return;
+ }
+ mReceivers.add(receiver);
+ mActivity.registerReceiver(receiver, filter);
}
- mReceivers.add(receiver);
- mActivity.registerReceiver(receiver, filter);
- }
+ });
}
private synchronized void setListeningW(boolean listening) {
- if (mListening == listening) return;
if (DEBUG) Log.d(TAG, "Listening " + listening);
- mListening = listening;
for (SummaryProvider p : mSummaryMap.keySet()) {
try {
p.setListening(listening);
@@ -175,10 +179,6 @@
if (provider != null) {
if (DEBUG) Log.d(TAG, "Creating " + tile);
mSummaryMap.put(provider, tile.intent.getComponent());
- if (mListening) {
- // If we are somehow already listening, put the provider in that state.
- provider.setListening(true);
- }
}
}
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index 3195641..bd6ae5c 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -25,6 +25,7 @@
import android.os.Bundle;
import android.os.RemoteException;
import android.os.SystemProperties;
+import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
@@ -116,7 +117,9 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- inflater.inflate(R.menu.data_usage, menu);
+ if (UserManager.get(getContext()).isAdminUser()) {
+ inflater.inflate(R.menu.data_usage, menu);
+ }
super.onCreateOptionsMenu(menu, inflater);
}
diff --git a/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java b/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java
index 2d22b06..bc17814 100644
--- a/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java
+++ b/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java
@@ -38,7 +38,6 @@
import java.text.NumberFormat;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Locale;
@@ -184,12 +183,14 @@
return itemCount;
}
- private void onItemMove(int fromPosition, int toPosition) {
+ void onItemMove(int fromPosition, int toPosition) {
if (fromPosition >= 0 && toPosition >= 0) {
- Collections.swap(mFeedItemList, fromPosition, toPosition);
+ final LocaleStore.LocaleInfo saved = mFeedItemList.get(fromPosition);
+ mFeedItemList.remove(fromPosition);
+ mFeedItemList.add(toPosition, saved);
} else {
// TODO: It looks like sometimes the RecycleView tries to swap item -1
- // Investigate and file a bug.
+ // I did not see it in a while, but if it happens, investigate and file a bug.
Log.e(TAG, String.format(Locale.US,
"Negative position in onItemMove %d -> %d", fromPosition, toPosition));
}
@@ -207,6 +208,23 @@
}
}
+ boolean isRemoveMode() {
+ return mRemoveMode;
+ }
+
+ void removeItem(int position) {
+ int itemCount = mFeedItemList.size();
+ if (itemCount <= 1) {
+ return;
+ }
+ if (position < 0 || position >= itemCount) {
+ return;
+ }
+ mFeedItemList.remove(position);
+ notifyDataSetChanged();
+ doTheUpdate();
+ }
+
void removeChecked() {
int itemCount = mFeedItemList.size();
for (int i = itemCount - 1; i >= 0; i--) {
diff --git a/src/com/android/settings/localepicker/LocaleLinearLayoutManager.java b/src/com/android/settings/localepicker/LocaleLinearLayoutManager.java
new file mode 100644
index 0000000..630f382
--- /dev/null
+++ b/src/com/android/settings/localepicker/LocaleLinearLayoutManager.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2016 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.localepicker;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+
+import com.android.settings.R;
+
+/**
+ * Add accessibility actions to the drag-and-drop locale list
+ *
+ * <p>Dragging is not supported neither by TalkBack or the accessibility
+ * framework at the moment. So we need custom actions to be able
+ * to change the order of the locales.</p>
+ *
+ * <p>Also, the remove functionality is difficult to discover and use
+ * with TalkBack only, so we are also adding a "remove" action.</p>
+ *
+ * <p>It only removes one locale at the time, but most users don't
+ * really add many locales "by mistake", so there is no real need
+ * to delete a lot of locales at once.</p>
+ */
+public class LocaleLinearLayoutManager extends LinearLayoutManager {
+ private final LocaleDragAndDropAdapter mAdapter;
+ private final Context mContext;
+
+ private final AccessibilityNodeInfoCompat.AccessibilityActionCompat mActionMoveUp;
+ private final AccessibilityNodeInfoCompat.AccessibilityActionCompat mActionMoveDown;
+ private final AccessibilityNodeInfoCompat.AccessibilityActionCompat mActionMoveTop;
+ private final AccessibilityNodeInfoCompat.AccessibilityActionCompat mActionMoveBottom;
+ private final AccessibilityNodeInfoCompat.AccessibilityActionCompat mActionRemove;
+
+ public LocaleLinearLayoutManager(Context context, LocaleDragAndDropAdapter adapter) {
+ super(context);
+ this.mContext = context;
+ this.mAdapter = adapter;
+
+ this.mActionMoveUp = new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
+ R.id.action_drag_move_up,
+ mContext.getString(R.string.action_drag_label_move_up));
+ this.mActionMoveDown = new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
+ R.id.action_drag_move_down,
+ mContext.getString(R.string.action_drag_label_move_down));
+ this.mActionMoveTop = new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
+ R.id.action_drag_move_top,
+ mContext.getString(R.string.action_drag_label_move_top));
+ this.mActionMoveBottom = new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
+ R.id.action_drag_move_bottom,
+ mContext.getString(R.string.action_drag_label_move_bottom));
+ this.mActionRemove = new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
+ R.id.action_drag_remove,
+ mContext.getString(R.string.action_drag_label_remove));
+ }
+
+ @Override
+ public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
+ RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
+
+ super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info);
+
+ final int itemCount = this.getItemCount();
+ final int position = this.getPosition(host);
+ final LocaleDragCell dragCell = (LocaleDragCell) host;
+
+ // We want the description to be something not localizable, so that any TTS engine for
+ // any language can handle it. And we want the position to be part of it.
+ // So we use something like "2, French (France)"
+ final String description =
+ (position + 1) + ", " + dragCell.getCheckbox().getContentDescription();
+ info.setContentDescription(description);
+
+ if (mAdapter.isRemoveMode()) { // We don't move things around in remove mode
+ return;
+ }
+
+ // The order in which we add the actions is important for the circular selection menu.
+ // With the current order the "up" action will be (more or less) up, and "down" more
+ // or less down ("more or less" because we have 5 actions)
+ if (position > 0) { // it is not the first one
+ info.addAction(mActionMoveUp);
+ info.addAction(mActionMoveTop);
+ }
+ if (position + 1 < itemCount) { // it is not the last one
+ info.addAction(mActionMoveDown);
+ info.addAction(mActionMoveBottom);
+ }
+ if (itemCount > 1) {
+ info.addAction(mActionRemove);
+ }
+ }
+
+ @Override
+ public boolean performAccessibilityActionForItem(RecyclerView.Recycler recycler,
+ RecyclerView.State state, View host, int action, Bundle args) {
+
+ final int itemCount = this.getItemCount();
+ final int position = this.getPosition(host);
+
+ switch (action) {
+ case R.id.action_drag_move_up:
+ if (position > 0) {
+ mAdapter.onItemMove(position, position - 1);
+ return true;
+ }
+ return false;
+ case R.id.action_drag_move_down:
+ if (position + 1 < itemCount) {
+ mAdapter.onItemMove(position, position + 1);
+ return true;
+ }
+ return false;
+ case R.id.action_drag_move_top:
+ if (position != 0) {
+ mAdapter.onItemMove(position, 0);
+ return true;
+ }
+ return false;
+ case R.id.action_drag_move_bottom:
+ if (position != itemCount - 1) {
+ mAdapter.onItemMove(position, itemCount - 1);
+ return true;
+ }
+ return false;
+ case R.id.action_drag_remove:
+ if (itemCount > 1) {
+ mAdapter.removeItem(position);
+ return true;
+ }
+ return false;
+ default:
+ return super.performAccessibilityActionForItem(recycler, state, host, action, args);
+ }
+ }
+}
diff --git a/src/com/android/settings/localepicker/LocaleListEditor.java b/src/com/android/settings/localepicker/LocaleListEditor.java
index 3287d39..b95a590 100644
--- a/src/com/android/settings/localepicker/LocaleListEditor.java
+++ b/src/com/android/settings/localepicker/LocaleListEditor.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
-import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.LocaleList;
import android.view.LayoutInflater;
@@ -30,7 +29,6 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.LinearLayout;
import com.android.internal.app.LocalePicker;
import com.android.internal.app.LocalePickerWithRegion;
@@ -76,9 +74,8 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstState) {
- View result = super.onCreateView(inflater, container, savedInstState);
- LinearLayout ll = (LinearLayout) result;
- View myLayout = inflater.inflate(R.layout.locale_order_list, ll);
+ final View result = super.onCreateView(inflater, container, savedInstState);
+ final View myLayout = inflater.inflate(R.layout.locale_order_list, (ViewGroup) result);
getActivity().setTitle(R.string.pref_title_lang_selection);
@@ -236,7 +233,7 @@
private void configureDragAndDrop(View view) {
final RecyclerView list = (RecyclerView) view.findViewById(R.id.dragList);
- final LinearLayoutManager llm = new LinearLayoutManager(this.getContext());
+ final LocaleLinearLayoutManager llm = new LocaleLinearLayoutManager(getContext(), mAdapter);
llm.setAutoMeasureEnabled(true);
list.setLayoutManager(llm);