Merge "speech: On-device recognition settings profile selector" into udc-dev am: b5b15a6689
am: c449423483
am: e2d8e56c61
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23517421 Change-Id: Ic78a3af95c49680efc5bad6e3d13e7d6abb048f2 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
committed by
Automerger Merge Worker
commit
94b8257176
@@ -16,9 +16,14 @@
|
|||||||
|
|
||||||
package com.android.settings.language;
|
package com.android.settings.language;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -26,8 +31,12 @@ import androidx.preference.Preference;
|
|||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
|
||||||
|
import com.android.settings.dashboard.profileselector.UserAdapter;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/** Controller of the On-device recognition preference. */
|
/** Controller of the On-device recognition preference. */
|
||||||
@@ -37,6 +46,8 @@ public class OnDeviceRecognitionPreferenceController extends BasePreferenceContr
|
|||||||
|
|
||||||
private Optional<Intent> mIntent;
|
private Optional<Intent> mIntent;
|
||||||
|
|
||||||
|
private WeakReference<Dialog> mProfileSelectDialog = new WeakReference<>(null);
|
||||||
|
|
||||||
public OnDeviceRecognitionPreferenceController(Context context, String preferenceKey) {
|
public OnDeviceRecognitionPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
}
|
}
|
||||||
@@ -59,6 +70,48 @@ public class OnDeviceRecognitionPreferenceController extends BasePreferenceContr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
|
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
|
return super.handlePreferenceTreeClick(preference);
|
||||||
|
}
|
||||||
|
show(preference);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void show(Preference preference) {
|
||||||
|
final List<UserHandle> userHandles = new ArrayList<>();
|
||||||
|
for (UserInfo userInfo : UserManager.get(mContext).getUsers()) {
|
||||||
|
userHandles.add(userInfo.getUserHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only a single profile is installed. Proceed with its settings.
|
||||||
|
if (userHandles.size() == 1) {
|
||||||
|
mContext.startActivityAsUser(preference.getIntent(), userHandles.get(0));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple profiles are installed. Show a dialog to the user to pick one to proceed with.
|
||||||
|
createAndShowProfileSelectDialog(preference.getIntent(), userHandles);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserAdapter.OnClickListener createProfileDialogClickCallback(
|
||||||
|
Intent intent, List<UserHandle> userHandles) {
|
||||||
|
return (int position) -> {
|
||||||
|
mContext.startActivityAsUser(intent, userHandles.get(position));
|
||||||
|
if (mProfileSelectDialog.get() != null) {
|
||||||
|
mProfileSelectDialog.get().dismiss();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAndShowProfileSelectDialog(Intent intent, List<UserHandle> userHandles) {
|
||||||
|
Dialog profileSelectDialog = ProfileSelectDialog.createDialog(
|
||||||
|
mContext, userHandles, createProfileDialogClickCallback(intent, userHandles));
|
||||||
|
mProfileSelectDialog = new WeakReference<>(profileSelectDialog);
|
||||||
|
profileSelectDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an {@link Intent} for the activity in the default on-device recognizer service if
|
* Create an {@link Intent} for the activity in the default on-device recognizer service if
|
||||||
* there is a properly defined speech recognition xml meta-data for that service.
|
* there is a properly defined speech recognition xml meta-data for that service.
|
||||||
|
Reference in New Issue
Block a user