Merge "Provide up to 3 folder name suggestions to active IME Bug: 144973594" into ub-launcher3-master

This commit is contained in:
Hyunyoung Song
2019-11-23 00:48:08 +00:00
committed by Android (Google) Code Review
4 changed files with 61 additions and 24 deletions
@@ -21,14 +21,19 @@ import android.util.AttributeSet;
import android.view.DragEvent;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.android.launcher3.folder.FolderNameProvider;
import com.android.launcher3.util.UiThreadHelper;
import java.util.List;
/**
* The edit text that reports back when the back key has been pressed.
* Note: AppCompatEditText doesn't fully support #displayCompletions and #onCommitCompletion
*/
public class ExtendedEditText extends EditText {
@@ -85,12 +90,9 @@ public class ExtendedEditText extends EditText {
super.onLayout(changed, left, top, right, bottom);
if (mShowImeAfterFirstLayout) {
// soft input only shows one frame after the layout of the EditText happens,
post(new Runnable() {
@Override
public void run() {
showSoftInput();
mShowImeAfterFirstLayout = false;
}
post(() -> {
showSoftInput();
mShowImeAfterFirstLayout = false;
});
}
}
@@ -103,9 +105,27 @@ public class ExtendedEditText extends EditText {
UiThreadHelper.hideKeyboardAsync(getContext(), getWindowToken());
}
@Override
public void onCommitCompletion(CompletionInfo text) {
setText(text.getText());
}
/**
* Currently only used for folder name suggestion.
*/
public void displayCompletions(List<String> suggestList) {
int cnt = Math.min(suggestList.size(), FolderNameProvider.SUGGEST_MAX);
CompletionInfo[] cInfo = new CompletionInfo[cnt];
for (int i = 0; i < cnt; i++) {
cInfo[i] = new CompletionInfo(i, i, suggestList.get(i));
}
post(() -> getContext().getSystemService(InputMethodManager.class)
.displayCompletions(this, cInfo));
}
private boolean showSoftInput() {
return requestFocus() &&
((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
getContext().getSystemService(InputMethodManager.class)
.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
}
+10 -8
View File
@@ -84,6 +84,7 @@ import com.android.launcher3.views.ClipPathView;
import com.android.launcher3.widget.PendingAddShortcutInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -217,7 +218,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
& ~InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
& ~InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
| InputType.TYPE_TEXT_FLAG_CAP_WORDS);
mFolderName.forceDisableSuggestions(true);
mFolderName.forceDisableSuggestions(!FeatureFlags.FOLDER_NAME_SUGGEST.get());
mFooter = findViewById(R.id.folder_footer);
@@ -412,19 +413,20 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
});
}
/**
* Show suggested folder title.
*/
public void showSuggestedTitle(CharSequence suggestName) {
public void showSuggestedTitle(String[] suggestName) {
if (FeatureFlags.FOLDER_NAME_SUGGEST.get() && mInfo.contents.size() == 2) {
if (!TextUtils.isEmpty(suggestName)) {
mFolderName.setHint(suggestName);
mFolderName.setText(suggestName);
if (suggestName.length > 0 && !TextUtils.isEmpty(suggestName[0])) {
mFolderName.setHint(suggestName[0]);
mFolderName.setText(suggestName[0]);
mInfo.title = suggestName[0];
animateOpen();
mFolderName.showKeyboard();
mInfo.title = suggestName;
mFolderName.displayCompletions(
Arrays.asList(suggestName).subList(1, suggestName.length));
}
animateOpen();
}
}
@@ -371,22 +371,31 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
if (!itemAdded) mPreviewItemManager.hidePreviewItem(index, true);
final int finalIndex = index;
String[] suggestedNameOut = new String[1];
String[] suggestedNameOut = new String[FolderNameProvider.SUGGEST_MAX];
if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
Executors.UI_HELPER_EXECUTOR.post(() -> mLauncher.getFolderNameProvider()
.getSuggestedFolderName(getContext(), mInfo.contents, suggestedNameOut));
Executors.UI_HELPER_EXECUTOR.post(() -> {
mLauncher.getFolderNameProvider().getSuggestedFolderName(
getContext(), mInfo.contents, suggestedNameOut);
showFinalView(finalIndex, item, suggestedNameOut);
});
} else {
showFinalView(finalIndex, item, suggestedNameOut);
}
postDelayed(() -> {
mPreviewItemManager.hidePreviewItem(finalIndex, false);
mFolder.showItem(item);
invalidate();
mFolder.showSuggestedTitle(suggestedNameOut[0]);
}, DROP_IN_ANIMATION_DURATION);
} else {
addItem(item);
}
}
private void showFinalView(int finalIndex, final WorkspaceItemInfo item,
String[] suggestedNameOut) {
postDelayed(() -> {
mPreviewItemManager.hidePreviewItem(finalIndex, false);
mFolder.showItem(item);
invalidate();
mFolder.showSuggestedTitle(suggestedNameOut);
}, DROP_IN_ANIMATION_DURATION);
}
public void onDrop(DragObject d, boolean itemReturnedOnFailedDrop) {
WorkspaceItemInfo item;
if (d.dragInfo instanceof AppInfo) {
@@ -28,6 +28,12 @@ import java.util.ArrayList;
*/
public class FolderNameProvider {
/**
* IME usually has up to 3 suggest slots. Adding one as in Launcher, there are folder
* name edit box that we can also provide suggestion.
*/
public static final int SUGGEST_MAX = 4;
/**
* Returns suggested folder name.
*/