Fix various UX bugs.

* In the drag & drop list align numbers with the + in
  the "+ Add a language" button
* Keep the "+ Add a language" button under the list
* Shadow cell while drag & drop
* Updated various strings for dialog titles and messages

Bug: 26557242
Bug: 26710677
Bug: 26712004
Bug: 27070104
Change-Id: I10d26eac9581c955328e667d7309b5f0ac649110
This commit is contained in:
Mihai Nita
2016-02-22 15:44:40 -08:00
parent 60df76b169
commit a475fb1e06
5 changed files with 106 additions and 54 deletions

View File

@@ -40,12 +40,11 @@
<TextView <TextView
android:id="@+id/miniLabel" android:id="@+id/miniLabel"
style="@style/LanguageCheckboxAndLabel"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
tools:text="22" tools:text="22"
android:textColor="?android:attr/colorAccent" android:textColor="?android:attr/colorAccent"
android:minWidth="32sp" android:minWidth="24sp"
android:gravity="center_vertical|center_horizontal" android:gravity="center_vertical|center_horizontal"
android:layout_alignTop="@id/checkbox" android:layout_alignTop="@id/checkbox"
android:layout_alignBottom="@id/checkbox"/> android:layout_alignBottom="@id/checkbox"/>

View File

@@ -14,20 +14,23 @@
limitations under the License. limitations under the License.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:orientation="vertical"
android:layoutDirection="locale" android:layoutDirection="locale"
android:textDirection="locale"> android:textDirection="locale">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<com.android.settings.localepicker.LocaleRecyclerView <com.android.settings.localepicker.LocaleRecyclerView
android:id="@+id/dragList" android:id="@+id/dragList"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical"/> android:scrollbars="vertical"/>
<Button <Button
@@ -43,4 +46,6 @@
style="@style/Base.Widget.AppCompat.Button.Borderless" style="@style/Base.Widget.AppCompat.Button.Borderless"
android:textAppearance="?android:attr/textAppearanceListItem"/> android:textAppearance="?android:attr/textAppearanceListItem"/>
</LinearLayout> </LinearLayout>
</ScrollView>

View File

@@ -525,20 +525,22 @@
<!-- "Button" that opens a language picker. The selected language gets added to the language list. [CHAR LIMIT=30] --> <!-- "Button" that opens a language picker. The selected language gets added to the language list. [CHAR LIMIT=30] -->
<string name="add_a_language">Add a language</string> <string name="add_a_language">Add a language</string>
<!-- The title of the confirmation dialog shown when the user selected several languages and tries to remove them [CHAR LIMIT=60] --> <!-- The title of the confirmation dialog shown when the user selects one / several languages and tries to remove them [CHAR LIMIT=60] -->
<string name="dlg_remove_locales_title">Remove from your language preference?</string> <plurals name="dlg_remove_locales_title">
<!-- TODO: come up with a good string --> <item quantity="one">Remove selected language?</item>
<!-- The text of the confirmation dialog shown when the user selected several languages and tries to remove them [CHAR LIMIT=NONE] --> <item quantity="other">Remove selected languages?</item>
<string name="dlg_remove_locales_message" translatable="false">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla egestas porta aliquet. Ut laoreet orci tellus, id cursus enim volutpat in.</string> </plurals>
<!-- The title of the error dialog shown when the user selected all the languages and tries to remove them [CHAR LIMIT=60] --> <!-- The text of the confirmation dialog shown when the user selects several languages and tries to remove them [CHAR LIMIT=NONE] -->
<string name="dlg_remove_locales_error_title">Language removal error</string> <string name="dlg_remove_locales_message">Text will be displayed in another language</string>
<!-- The text of the error dialog shown when the user selected all the languages and tries to remove them [CHAR LIMIT=NONE] -->
<string name="dlg_remove_locales_error_message">Cant remove all the languages, you should leave at least one.</string>
<!-- TODO: Marked non-translatable for now, as it is not final. Waiting on b/27070104 --> <!-- The title of the error dialog shown when the user selects all the languages and tries to remove them [CHAR LIMIT=60] -->
<!-- This text shows in the language picker when the system is not translated into that languages [CHAR LIMIT=130] --> <string name="dlg_remove_locales_error_title">Cant remove all languages</string>
<string name="locale_not_translated" translatable="false">Not all applications are translated into this language; you might experience a mixture.</string> <!-- The text of the error dialog shown when the user selects all the languages and tries to remove them [CHAR LIMIT=NONE] -->
<string name="dlg_remove_locales_error_message">Keep at least one preferred language</string>
<!-- 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>
<!-- 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 :) ). --> <!-- 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> <string name="activity_picker_label">Choose activity</string>

View File

@@ -17,22 +17,24 @@
package com.android.settings.localepicker; package com.android.settings.localepicker;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas;
import android.support.v4.view.MotionEventCompat; import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper; import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.LocaleList; import android.util.LocaleList;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import com.android.settings.R;
import com.android.internal.app.LocalePicker; import com.android.internal.app.LocalePicker;
import com.android.internal.app.LocaleStore; import com.android.internal.app.LocaleStore;
import com.android.settings.R;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -79,6 +81,10 @@ class LocaleDragAndDropAdapter
this.mFeedItemList = feedItemList; this.mFeedItemList = feedItemList;
this.mContext = context; this.mContext = context;
final float dragElevation = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
context.getResources().getDisplayMetrics());
this.mItemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback( this.mItemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(
ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0 /* no swipe */) { ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0 /* no swipe */) {
@@ -93,6 +99,35 @@ class LocaleDragAndDropAdapter
public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) { public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
// Swipe is disabled, this is intentionally empty. // Swipe is disabled, this is intentionally empty.
} }
private static final int SELECTION_GAINED = 1;
private static final int SELECTION_LOST = 0;
private static final int SELECTION_UNCHANGED = -1;
private int mSelectionStatus = SELECTION_UNCHANGED;
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder, float dX, float dY,
int actionState, boolean isCurrentlyActive) {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY,
actionState, isCurrentlyActive);
// We change the elevation if selection changed
if (mSelectionStatus != SELECTION_UNCHANGED) {
viewHolder.itemView.setElevation(
mSelectionStatus == SELECTION_GAINED ? dragElevation : 0);
mSelectionStatus = SELECTION_UNCHANGED;
}
}
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
super.onSelectedChanged(viewHolder, actionState);
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
mSelectionStatus = SELECTION_GAINED;
} else if (actionState == ItemTouchHelper.ACTION_STATE_IDLE) {
mSelectionStatus = SELECTION_LOST;
}
}
}); });
} }
@@ -187,6 +222,15 @@ class LocaleDragAndDropAdapter
return result; return result;
} }
LocaleStore.LocaleInfo getFirstChecked() {
for (LocaleStore.LocaleInfo li : mFeedItemList) {
if (li.getChecked()) {
return li;
}
}
return null;
}
void addLocale(LocaleStore.LocaleInfo li) { void addLocale(LocaleStore.LocaleInfo li) {
mFeedItemList.add(li); mFeedItemList.add(li);
notifyItemInserted(mFeedItemList.size() - 1); notifyItemInserted(mFeedItemList.size() - 1);

View File

@@ -21,7 +21,6 @@ import android.app.FragmentTransaction;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.LocaleList; import android.util.LocaleList;
@@ -33,12 +32,11 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import com.android.settings.R;
import com.android.internal.app.LocalePicker; import com.android.internal.app.LocalePicker;
import com.android.internal.app.LocalePickerWithRegion; import com.android.internal.app.LocalePickerWithRegion;
import com.android.internal.app.LocaleStore; import com.android.internal.app.LocaleStore;
import com.android.settings.InstrumentedFragment; import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import java.util.ArrayList; import java.util.ArrayList;
@@ -107,16 +105,16 @@ public class LocaleListEditor extends SettingsPreferenceFragment
} }
private void removeLocaleWarningDialog() { private void removeLocaleWarningDialog() {
int checked = mAdapter.getCheckedCount(); int checkedCount = mAdapter.getCheckedCount();
// Nothing checked, just exit remove mode without a warning dialog // Nothing checked, just exit remove mode without a warning dialog
if (checked == 0) { if (checkedCount == 0) {
setRemoveMode(!mRemoveMode); setRemoveMode(!mRemoveMode);
return; return;
} }
// All locales selected, warning dialog, can't remove them all // All locales selected, warning dialog, can't remove them all
if (checked == mAdapter.getItemCount()) { if (checkedCount == mAdapter.getItemCount()) {
new AlertDialog.Builder(getActivity()) new AlertDialog.Builder(getActivity())
.setTitle(R.string.dlg_remove_locales_error_title) .setTitle(R.string.dlg_remove_locales_error_title)
.setMessage(R.string.dlg_remove_locales_error_message) .setMessage(R.string.dlg_remove_locales_error_message)
@@ -130,8 +128,10 @@ public class LocaleListEditor extends SettingsPreferenceFragment
return; return;
} }
final String title = getResources().getQuantityString(R.plurals.dlg_remove_locales_title,
checkedCount);
new AlertDialog.Builder(getActivity()) new AlertDialog.Builder(getActivity())
.setTitle(R.string.dlg_remove_locales_title) .setTitle(title)
.setMessage(R.string.dlg_remove_locales_message) .setMessage(R.string.dlg_remove_locales_message)
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override @Override
@@ -161,9 +161,9 @@ public class LocaleListEditor extends SettingsPreferenceFragment
} }
private static List<LocaleStore.LocaleInfo> getUserLocaleList(Context context) { private static List<LocaleStore.LocaleInfo> getUserLocaleList(Context context) {
List<LocaleStore.LocaleInfo> result = new ArrayList<>(); final List<LocaleStore.LocaleInfo> result = new ArrayList<>();
LocaleList localeList = LocalePicker.getLocales(); final LocaleList localeList = LocalePicker.getLocales();
for (int i = 0; i < localeList.size(); i++) { for (int i = 0; i < localeList.size(); i++) {
Locale locale = localeList.get(i); Locale locale = localeList.get(i);
result.add(LocaleStore.getLocaleInfo(locale)); result.add(LocaleStore.getLocaleInfo(locale));
@@ -173,8 +173,10 @@ public class LocaleListEditor extends SettingsPreferenceFragment
} }
private void configureDragAndDrop(View view) { private void configureDragAndDrop(View view) {
RecyclerView list = (RecyclerView) view.findViewById(R.id.dragList); final RecyclerView list = (RecyclerView) view.findViewById(R.id.dragList);
list.setLayoutManager(new LinearLayoutManager(this.getContext())); final LinearLayoutManager llm = new LinearLayoutManager(this.getContext());
llm.setAutoMeasureEnabled(true);
list.setLayoutManager(llm);
list.setHasFixedSize(true); list.setHasFixedSize(true);
mAdapter.setRecyclerView(list); mAdapter.setRecyclerView(list);