[Panlingual][Settings] Add top intro on the top of app list.

- show a message for app selection of user to avoid any confusion of
   searching app.

Bug: b/230689178
Test: see b/230689178
Change-Id: I597e718b81bd7a5019c69dbdfc02f26d7f3af5fd
This commit is contained in:
tom hsu
2022-05-13 17:57:14 +08:00
committed by Tom Hsu
parent 8a823a2c2c
commit 36693d8096
3 changed files with 63 additions and 13 deletions

View File

@@ -518,6 +518,9 @@
<!-- Description for the disclaimer of per app language. [CHAR LIMIT=NONE]--> <!-- Description for the disclaimer of per app language. [CHAR LIMIT=NONE]-->
<string name="desc_app_locale_disclaimer">Language may differ from languages available in the app. Some apps may not support this setting.</string> <string name="desc_app_locale_disclaimer">Language may differ from languages available in the app. Some apps may not support this setting.</string>
<!-- Description for introduction of the locale selection supported of app list [CHAR LIMIT=NONE]-->
<string name="desc_app_locale_selection_supported">Only apps that support language selection are shown here.</string>
<!-- The title of the confirmation dialog shown when the user selects one / 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] -->
<plurals name="dlg_remove_locales_title"> <plurals name="dlg_remove_locales_title">
<item quantity="one">Remove selected language?</item> <item quantity="one">Remove selected language?</item>

View File

@@ -85,6 +85,14 @@ public class ApplicationViewHolder extends RecyclerView.ViewHolder {
return view; return view;
} }
static View newHeader(ViewGroup parent, int resText) {
ViewGroup view = (ViewGroup) LayoutInflater.from(parent.getContext())
.inflate(R.layout.preference_app_header, parent, false);
TextView textView = view.findViewById(R.id.apps_top_intro_text);
textView.setText(resText);
return view;
}
void setSummary(CharSequence summary) { void setSummary(CharSequence summary) {
mSummary.setText(summary); mSummary.setText(summary);
} }

View File

@@ -824,14 +824,16 @@ public class ManageApplications extends InstrumentedFragment
if (mApplications == null) { if (mApplications == null) {
return; return;
} }
final int position = mRecyclerView.getChildAdapterPosition(view); final int applicationPosition =
ApplicationsAdapter.getApplicationPosition(
mListType, mRecyclerView.getChildAdapterPosition(view));
if (position == RecyclerView.NO_POSITION) { if (applicationPosition == RecyclerView.NO_POSITION) {
Log.w(TAG, "Cannot find position for child, skipping onClick handling"); Log.w(TAG, "Cannot find position for child, skipping onClick handling");
return; return;
} }
if (mApplications.getApplicationCount() > position) { if (mApplications.getApplicationCount() > applicationPosition) {
ApplicationsState.AppEntry entry = mApplications.getAppEntry(position); ApplicationsState.AppEntry entry = mApplications.getAppEntry(applicationPosition);
mCurrentPkgName = entry.info.packageName; mCurrentPkgName = entry.info.packageName;
mCurrentUid = entry.info.uid; mCurrentUid = entry.info.uid;
startApplicationDetailsActivity(); startApplicationDetailsActivity();
@@ -1058,6 +1060,7 @@ public class ManageApplications extends InstrumentedFragment
private static final String STATE_LAST_SCROLL_INDEX = "state_last_scroll_index"; private static final String STATE_LAST_SCROLL_INDEX = "state_last_scroll_index";
private static final int VIEW_TYPE_APP = 0; private static final int VIEW_TYPE_APP = 0;
private static final int VIEW_TYPE_EXTRA_VIEW = 1; private static final int VIEW_TYPE_EXTRA_VIEW = 1;
private static final int VIEW_TYPE_APP_HEADER = 2;
private final ApplicationsState mState; private final ApplicationsState mState;
private final ApplicationsState.Session mSession; private final ApplicationsState.Session mSession;
@@ -1229,7 +1232,11 @@ public class ManageApplications extends InstrumentedFragment
@Override @Override
public ApplicationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ApplicationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View view; final View view;
if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) { if (mManageApplications.mListType == LIST_TYPE_APPS_LOCALE
&& viewType == VIEW_TYPE_APP_HEADER) {
view = ApplicationViewHolder.newHeader(parent,
R.string.desc_app_locale_selection_supported);
} else if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) {
view = ApplicationViewHolder.newView(parent, true /* twoTarget */); view = ApplicationViewHolder.newView(parent, true /* twoTarget */);
} else { } else {
view = ApplicationViewHolder.newView(parent, false /* twoTarget */); view = ApplicationViewHolder.newView(parent, false /* twoTarget */);
@@ -1239,6 +1246,9 @@ public class ManageApplications extends InstrumentedFragment
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (position == 0 && mManageApplications.mListType == LIST_TYPE_APPS_LOCALE) {
return VIEW_TYPE_APP_HEADER;
}
return VIEW_TYPE_APP; return VIEW_TYPE_APP;
} }
@@ -1472,10 +1482,11 @@ public class ManageApplications extends InstrumentedFragment
@Override @Override
public int getItemCount() { public int getItemCount() {
if (mEntries == null) { int count = getApplicationCount();
return 0; if (count != 0 && mManageApplications.mListType == LIST_TYPE_APPS_LOCALE) {
count++;
} }
return mEntries.size(); return count;
} }
public int getApplicationCount() { public int getApplicationCount() {
@@ -1483,15 +1494,18 @@ public class ManageApplications extends InstrumentedFragment
} }
public AppEntry getAppEntry(int position) { public AppEntry getAppEntry(int position) {
return mEntries.get(position); return mEntries.get(
getApplicationPosition(mManageApplications.mListType, position));
} }
@Override @Override
public long getItemId(int position) { public long getItemId(int position) {
if (position == mEntries.size()) { int applicationPosition =
getApplicationPosition(mManageApplications.mListType, position);
if (applicationPosition == mEntries.size()) {
return -1; return -1;
} }
return mEntries.get(position).id; return mEntries.get(applicationPosition).id;
} }
public boolean isEnabled(int position) { public boolean isEnabled(int position) {
@@ -1499,7 +1513,9 @@ public class ManageApplications extends InstrumentedFragment
|| mManageApplications.mListType != LIST_TYPE_HIGH_POWER) { || mManageApplications.mListType != LIST_TYPE_HIGH_POWER) {
return true; return true;
} }
ApplicationsState.AppEntry entry = mEntries.get(position); ApplicationsState.AppEntry entry =
mEntries.get(
getApplicationPosition(mManageApplications.mListType, position));
return !mBackend.isSysAllowlisted(entry.info.packageName) return !mBackend.isSysAllowlisted(entry.info.packageName)
&& !mBackend.isDefaultActiveApp(entry.info.packageName); && !mBackend.isDefaultActiveApp(entry.info.packageName);
@@ -1507,8 +1523,15 @@ public class ManageApplications extends InstrumentedFragment
@Override @Override
public void onBindViewHolder(ApplicationViewHolder holder, int position) { public void onBindViewHolder(ApplicationViewHolder holder, int position) {
if (getItemViewType(position) == VIEW_TYPE_APP_HEADER) {
// It does not bind holder here, due to header view.
return;
}
// Bind the data efficiently with the holder // Bind the data efficiently with the holder
final ApplicationsState.AppEntry entry = mEntries.get(position); final ApplicationsState.AppEntry entry =
mEntries.get(
getApplicationPosition(mManageApplications.mListType, position));
synchronized (entry) { synchronized (entry) {
mState.ensureLabelDescription(entry); mState.ensureLabelDescription(entry);
holder.setTitle(entry.label, entry.labelDescription); holder.setTitle(entry.label, entry.labelDescription);
@@ -1608,6 +1631,22 @@ public class ManageApplications extends InstrumentedFragment
} }
} }
/**
* Adjusts position if this list adds a header.
* TODO(b/232533002) Add a header view on adapter of RecyclerView may not a good idea since
* ManageApplication is a generic purpose. In the future, here shall look for
* a better way to add a header without using recyclerView or any other ways
* to achieve the goal.
*/
public static int getApplicationPosition(int listType, int position) {
int applicationPosition = position;
// Adjust position due to header added.
if (position > 0 && listType == LIST_TYPE_APPS_LOCALE) {
applicationPosition = position - 1;
}
return applicationPosition;
}
public static class OnScrollListener extends RecyclerView.OnScrollListener { public static class OnScrollListener extends RecyclerView.OnScrollListener {
private int mScrollState = SCROLL_STATE_IDLE; private int mScrollState = SCROLL_STATE_IDLE;
private boolean mDelayNotifyDataChange; private boolean mDelayNotifyDataChange;