Automatically show IME when showing the fingerprint delete/rename dialog.
Also a bit of code clean up.
Change-Id: I541a9c9ec031b7075f2812ef938adb9e591757c5
(cherry picked from commit 86ccad0bfd
)
This commit is contained in:
@@ -39,6 +39,7 @@ import android.hardware.fingerprint.FingerprintManager.AuthenticationResult;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -90,7 +91,9 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
|
|
||||||
public static class FingerprintSettingsFragment extends SettingsPreferenceFragment
|
public static class FingerprintSettingsFragment extends SettingsPreferenceFragment
|
||||||
implements OnPreferenceChangeListener, Indexable {
|
implements OnPreferenceChangeListener, Indexable {
|
||||||
private static final int MAX_RETRY_ATTEMPTS = 5;
|
private static final int MAX_RETRY_ATTEMPTS = 20;
|
||||||
|
private static final int RESET_HIGHLIGHT_DELAY_MS = 500;
|
||||||
|
|
||||||
private static final String TAG = "FingerprintSettings";
|
private static final String TAG = "FingerprintSettings";
|
||||||
private static final String KEY_FINGERPRINT_ITEM_PREFIX = "key_fingerprint_item";
|
private static final String KEY_FINGERPRINT_ITEM_PREFIX = "key_fingerprint_item";
|
||||||
private static final String KEY_USAGE_CATEGORY = "fingerprint_usage_category";
|
private static final String KEY_USAGE_CATEGORY = "fingerprint_usage_category";
|
||||||
@@ -101,7 +104,8 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
private static final String KEY_LAUNCHED_CONFIRM = "launched_confirm";
|
private static final String KEY_LAUNCHED_CONFIRM = "launched_confirm";
|
||||||
|
|
||||||
private static final int MSG_REFRESH_FINGERPRINT_TEMPLATES = 1000;
|
private static final int MSG_REFRESH_FINGERPRINT_TEMPLATES = 1000;
|
||||||
private static final int MSG_HIGHLIGHT_FINGERPRINT_ITEM = 1001;
|
private static final int MSG_FINGER_AUTH_SUCCESS = 1001;
|
||||||
|
private static final int MSG_FINGER_AUTH_FAIL = 1002;
|
||||||
|
|
||||||
private static final int CONFIRM_REQUEST = 101;
|
private static final int CONFIRM_REQUEST = 101;
|
||||||
private static final int CHOOSE_LOCK_GENERIC_REQUEST = 102;
|
private static final int CHOOSE_LOCK_GENERIC_REQUEST = 102;
|
||||||
@@ -118,29 +122,30 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
private int mMaxFingerprintAttempts;
|
private int mMaxFingerprintAttempts;
|
||||||
private byte[] mToken;
|
private byte[] mToken;
|
||||||
private boolean mLaunchedConfirm;
|
private boolean mLaunchedConfirm;
|
||||||
|
private Drawable mHighlightDrawable;
|
||||||
|
|
||||||
private AuthenticationCallback mAuthCallback = new AuthenticationCallback() {
|
private AuthenticationCallback mAuthCallback = new AuthenticationCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationSucceeded(AuthenticationResult result) {
|
public void onAuthenticationSucceeded(AuthenticationResult result) {
|
||||||
mHandler.obtainMessage(MSG_HIGHLIGHT_FINGERPRINT_ITEM,
|
int fingerId = result.getFingerprint().getFingerId();
|
||||||
result.getFingerprint().getFingerId(), 0).sendToTarget();
|
mHandler.obtainMessage(MSG_FINGER_AUTH_SUCCESS, fingerId, 0).sendToTarget();
|
||||||
retryFingerprint(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAuthenticationFailed() {
|
public void onAuthenticationFailed() {
|
||||||
retryFingerprint(true);
|
mHandler.obtainMessage(MSG_FINGER_AUTH_FAIL).sendToTarget();
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationError(int errMsgId, CharSequence errString) {
|
public void onAuthenticationError(int errMsgId, CharSequence errString) {
|
||||||
// get activity will be null on a screen rotation
|
// get activity will be null on a screen rotation
|
||||||
if (getActivity() != null) {
|
Activity activity = getActivity();
|
||||||
Toast.makeText(getActivity(), errString, Toast.LENGTH_SHORT);
|
if (activity != null) {
|
||||||
|
Toast.makeText(activity, errString, Toast.LENGTH_SHORT);
|
||||||
|
}
|
||||||
if (errMsgId != FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
|
if (errMsgId != FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
|
||||||
retryFingerprint(false);
|
retryFingerprint(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
|
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
|
||||||
@@ -166,8 +171,12 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
case MSG_REFRESH_FINGERPRINT_TEMPLATES:
|
case MSG_REFRESH_FINGERPRINT_TEMPLATES:
|
||||||
removeFingerprintPreference(msg.arg1);
|
removeFingerprintPreference(msg.arg1);
|
||||||
break;
|
break;
|
||||||
case MSG_HIGHLIGHT_FINGERPRINT_ITEM:
|
case MSG_FINGER_AUTH_SUCCESS:
|
||||||
highlightFingerprintItem(msg.arg1);
|
highlightFingerprintItem(msg.arg1);
|
||||||
|
retryFingerprint(true);
|
||||||
|
break;
|
||||||
|
case MSG_FINGER_AUTH_FAIL:
|
||||||
|
retryFingerprint(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -206,7 +215,8 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
KEY_LAUNCHED_CONFIRM, false);
|
KEY_LAUNCHED_CONFIRM, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mFingerprintManager = (FingerprintManager) getActivity().getSystemService(
|
Activity activity = getActivity();
|
||||||
|
mFingerprintManager = (FingerprintManager) activity.getSystemService(
|
||||||
Context.FINGERPRINT_SERVICE);
|
Context.FINGERPRINT_SERVICE);
|
||||||
|
|
||||||
// Need to authenticate a session token if none
|
// Need to authenticate a session token if none
|
||||||
@@ -228,17 +238,6 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void highlightFingerprintItem(int fpId) {
|
|
||||||
String prefName = genKey(fpId);
|
|
||||||
Preference pref = mManageCategory.findPreference(prefName);
|
|
||||||
if (pref instanceof FingerprintPreference) {
|
|
||||||
final FingerprintPreference fpref = (FingerprintPreference) pref;
|
|
||||||
fpref.highlight();
|
|
||||||
} else {
|
|
||||||
Log.w(TAG, "Wrong pref " + (pref != null ? pref.getKey() : "null"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Important!
|
* Important!
|
||||||
*
|
*
|
||||||
@@ -306,8 +305,11 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
// Make sure we reload the preference hierarchy since fingerprints may be added,
|
// Make sure we reload the preference hierarchy since fingerprints may be added,
|
||||||
// deleted or renamed.
|
// deleted or renamed.
|
||||||
createPreferenceHierarchy();
|
updatePreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePreferences() {
|
||||||
|
createPreferenceHierarchy();
|
||||||
retryFingerprint(true);
|
retryFingerprint(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +347,7 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
|
|
||||||
private void showRenameDeleteDialog(Preference pref, final Fingerprint fp) {
|
private void showRenameDeleteDialog(Preference pref, final Fingerprint fp) {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
AlertDialog dialog = new AlertDialog.Builder(activity)
|
final AlertDialog dialog = new AlertDialog.Builder(activity)
|
||||||
.setView(R.layout.fingerprint_rename_dialog)
|
.setView(R.layout.fingerprint_rename_dialog)
|
||||||
.setPositiveButton(R.string.security_settings_fingerprint_enroll_dialog_ok,
|
.setPositiveButton(R.string.security_settings_fingerprint_enroll_dialog_ok,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@@ -356,6 +358,7 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
if (!newName.equals(name)) {
|
if (!newName.equals(name)) {
|
||||||
if (DEBUG) Log.v(TAG, "rename " + name + " to " + newName);
|
if (DEBUG) Log.v(TAG, "rename " + name + " to " + newName);
|
||||||
mFingerprintManager.rename(fp.getFingerId(), newName);
|
mFingerprintManager.rename(fp.getFingerId(), newName);
|
||||||
|
updatePreferences();
|
||||||
}
|
}
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
@@ -374,6 +377,16 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
mDialogTextField = (EditText) dialog.findViewById(R.id.fingerprint_rename_field);
|
mDialogTextField = (EditText) dialog.findViewById(R.id.fingerprint_rename_field);
|
||||||
mDialogTextField.setText(fp.getName());
|
mDialogTextField.setText(fp.getName());
|
||||||
mDialogTextField.selectAll();
|
mDialogTextField.selectAll();
|
||||||
|
// show the IME
|
||||||
|
mDialogTextField.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onFocusChange(View v, boolean hasFocus) {
|
||||||
|
if (hasFocus) {
|
||||||
|
dialog.getWindow().setSoftInputMode(
|
||||||
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -413,6 +426,33 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Drawable getHighlightDrawable() {
|
||||||
|
if (mHighlightDrawable == null) {
|
||||||
|
mHighlightDrawable = getActivity().getDrawable(R.drawable.preference_highlight);
|
||||||
|
}
|
||||||
|
return mHighlightDrawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void highlightFingerprintItem(int fpId) {
|
||||||
|
String prefName = genKey(fpId);
|
||||||
|
FingerprintPreference fpref =
|
||||||
|
(FingerprintPreference) mManageCategory.findPreference(prefName);
|
||||||
|
final Drawable highlight = getHighlightDrawable();
|
||||||
|
final View view = fpref.getView();
|
||||||
|
final int centerX = view.getWidth() / 2;
|
||||||
|
final int centerY = view.getHeight() / 2;
|
||||||
|
highlight.setHotspot(centerX, centerY);
|
||||||
|
view.setBackground(highlight);
|
||||||
|
view.setPressed(true);
|
||||||
|
mHandler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
view.setPressed(false);
|
||||||
|
view.setBackground(null);
|
||||||
|
}
|
||||||
|
}, RESET_HIGHLIGHT_DELAY_MS);
|
||||||
|
}
|
||||||
|
|
||||||
private void launchChooseOrConfirmLock() {
|
private void launchChooseOrConfirmLock() {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
long challenge = mFingerprintManager.preEnroll();
|
long challenge = mFingerprintManager.preEnroll();
|
||||||
@@ -423,7 +463,8 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
intent.setClassName("com.android.settings", ChooseLockGeneric.class.getName());
|
intent.setClassName("com.android.settings", ChooseLockGeneric.class.getName());
|
||||||
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
|
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
|
||||||
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||||
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS, true);
|
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS,
|
||||||
|
true);
|
||||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
|
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
|
||||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
|
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
|
||||||
startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
|
startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
|
||||||
@@ -432,16 +473,12 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class FingerprintPreference extends Preference {
|
public static class FingerprintPreference extends Preference {
|
||||||
private static final int RESET_HIGHLIGHT_DELAY_MS = 500;
|
|
||||||
private Fingerprint mFingerprint;
|
private Fingerprint mFingerprint;
|
||||||
private View mView;
|
private View mView;
|
||||||
private Drawable mHighlightDrawable;
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
public FingerprintPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
public FingerprintPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
int defStyleRes) {
|
int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
mContext = context;
|
|
||||||
}
|
}
|
||||||
public FingerprintPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
public FingerprintPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
this(context, attrs, defStyleAttr, 0);
|
this(context, attrs, defStyleAttr, 0);
|
||||||
@@ -455,6 +492,8 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public View getView() { return mView; }
|
||||||
|
|
||||||
public void setFingerprint(Fingerprint item) {
|
public void setFingerprint(Fingerprint item) {
|
||||||
mFingerprint = item;
|
mFingerprint = item;
|
||||||
}
|
}
|
||||||
@@ -463,30 +502,6 @@ public class FingerprintSettings extends SettingsActivity {
|
|||||||
return mFingerprint;
|
return mFingerprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getHighlightDrawable() {
|
|
||||||
if (mHighlightDrawable == null) {
|
|
||||||
mHighlightDrawable = mContext.getDrawable(R.drawable.preference_highlight);
|
|
||||||
}
|
|
||||||
return mHighlightDrawable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void highlight() {
|
|
||||||
Drawable highlight = getHighlightDrawable();
|
|
||||||
final View view = mView;
|
|
||||||
view.setBackground(highlight);
|
|
||||||
final int centerX = view.getWidth() / 2;
|
|
||||||
final int centerY = view.getHeight() / 2;
|
|
||||||
highlight.setHotspot(centerX, centerY);
|
|
||||||
view.setPressed(true);
|
|
||||||
view.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
view.setPressed(false);
|
|
||||||
view.setBackground(null);
|
|
||||||
}
|
|
||||||
}, RESET_HIGHLIGHT_DELAY_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBindView(View view) {
|
protected void onBindView(View view) {
|
||||||
super.onBindView(view);
|
super.onBindView(view);
|
||||||
|
Reference in New Issue
Block a user