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:
@@ -17,22 +17,24 @@
|
||||
package com.android.settings.localepicker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.util.LocaleList;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.internal.app.LocaleStore;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -79,6 +81,10 @@ class LocaleDragAndDropAdapter
|
||||
this.mFeedItemList = feedItemList;
|
||||
|
||||
this.mContext = context;
|
||||
|
||||
final float dragElevation = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
|
||||
context.getResources().getDisplayMetrics());
|
||||
|
||||
this.mItemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(
|
||||
ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0 /* no swipe */) {
|
||||
|
||||
@@ -93,6 +99,35 @@ class LocaleDragAndDropAdapter
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
LocaleStore.LocaleInfo getFirstChecked() {
|
||||
for (LocaleStore.LocaleInfo li : mFeedItemList) {
|
||||
if (li.getChecked()) {
|
||||
return li;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void addLocale(LocaleStore.LocaleInfo li) {
|
||||
mFeedItemList.add(li);
|
||||
notifyItemInserted(mFeedItemList.size() - 1);
|
||||
|
@@ -21,7 +21,6 @@ import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.LocaleList;
|
||||
@@ -33,12 +32,11 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.internal.app.LocalePickerWithRegion;
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.InstrumentedFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -107,16 +105,16 @@ public class LocaleListEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
private void removeLocaleWarningDialog() {
|
||||
int checked = mAdapter.getCheckedCount();
|
||||
int checkedCount = mAdapter.getCheckedCount();
|
||||
|
||||
// Nothing checked, just exit remove mode without a warning dialog
|
||||
if (checked == 0) {
|
||||
if (checkedCount == 0) {
|
||||
setRemoveMode(!mRemoveMode);
|
||||
return;
|
||||
}
|
||||
|
||||
// All locales selected, warning dialog, can't remove them all
|
||||
if (checked == mAdapter.getItemCount()) {
|
||||
if (checkedCount == mAdapter.getItemCount()) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.dlg_remove_locales_error_title)
|
||||
.setMessage(R.string.dlg_remove_locales_error_message)
|
||||
@@ -130,8 +128,10 @@ public class LocaleListEditor extends SettingsPreferenceFragment
|
||||
return;
|
||||
}
|
||||
|
||||
final String title = getResources().getQuantityString(R.plurals.dlg_remove_locales_title,
|
||||
checkedCount);
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.dlg_remove_locales_title)
|
||||
.setTitle(title)
|
||||
.setMessage(R.string.dlg_remove_locales_message)
|
||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@@ -161,9 +161,9 @@ public class LocaleListEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
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++) {
|
||||
Locale locale = localeList.get(i);
|
||||
result.add(LocaleStore.getLocaleInfo(locale));
|
||||
@@ -173,8 +173,10 @@ public class LocaleListEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
private void configureDragAndDrop(View view) {
|
||||
RecyclerView list = (RecyclerView) view.findViewById(R.id.dragList);
|
||||
list.setLayoutManager(new LinearLayoutManager(this.getContext()));
|
||||
final RecyclerView list = (RecyclerView) view.findViewById(R.id.dragList);
|
||||
final LinearLayoutManager llm = new LinearLayoutManager(this.getContext());
|
||||
llm.setAutoMeasureEnabled(true);
|
||||
list.setLayoutManager(llm);
|
||||
|
||||
list.setHasFixedSize(true);
|
||||
mAdapter.setRecyclerView(list);
|
||||
|
Reference in New Issue
Block a user