Merge "Show Autofill Service icon on Save UI." into oc-mr1-dev

am: 0f6599887c

Change-Id: Ic2b8972f6089346ae4b721414213809c4d3ae6bc
This commit is contained in:
Felipe Leme
2017-09-14 17:15:42 +00:00
committed by android-build-merger
7 changed files with 67 additions and 18 deletions

View File

@@ -44,8 +44,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView
android:id="@+id/autofill_save_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView <TextView
android:id="@+id/autofill_save_title" android:id="@+id/autofill_save_title"
android:paddingLeft="8dp"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/autofill_save_title" android:text="@string/autofill_save_title"

View File

@@ -604,4 +604,7 @@
<!-- Max height of the the autofill save custom subtitle as a fraction of the screen width/height --> <!-- Max height of the the autofill save custom subtitle as a fraction of the screen width/height -->
<dimen name="autofill_save_custom_subtitle_max_height">20%</dimen> <dimen name="autofill_save_custom_subtitle_max_height">20%</dimen>
<!-- Max (absolute) dimensions (both width and height) of autofill service icon on autofill save affordance -->
<dimen name="autofill_save_icon_max_size">100dp</dimen>
</resources> </resources>

View File

@@ -2901,8 +2901,9 @@
<java-symbol type="id" name="autofill_dataset_list"/> <java-symbol type="id" name="autofill_dataset_list"/>
<java-symbol type="id" name="autofill" /> <java-symbol type="id" name="autofill" />
<java-symbol type="id" name="autofill_save_custom_subtitle" /> <java-symbol type="id" name="autofill_save_custom_subtitle" />
<java-symbol type="id" name="autofill_save_title" /> <java-symbol type="id" name="autofill_save_icon" />
<java-symbol type="id" name="autofill_save_no" /> <java-symbol type="id" name="autofill_save_no" />
<java-symbol type="id" name="autofill_save_title" />
<java-symbol type="id" name="autofill_save_yes" /> <java-symbol type="id" name="autofill_save_yes" />
<java-symbol type="string" name="autofill_error_cannot_autofill" /> <java-symbol type="string" name="autofill_error_cannot_autofill" />
<java-symbol type="string" name="autofill_picker_no_suggestions" /> <java-symbol type="string" name="autofill_picker_no_suggestions" />
@@ -2926,6 +2927,7 @@
<java-symbol type="style" name="AutofillSaveAnimation" /> <java-symbol type="style" name="AutofillSaveAnimation" />
<java-symbol type="dimen" name="autofill_dataset_picker_max_size"/> <java-symbol type="dimen" name="autofill_dataset_picker_max_size"/>
<java-symbol type="dimen" name="autofill_save_custom_subtitle_max_height"/> <java-symbol type="dimen" name="autofill_save_custom_subtitle_max_height"/>
<java-symbol type="dimen" name="autofill_save_icon_max_size"/>
<java-symbol type="dimen" name="notification_big_picture_max_height"/> <java-symbol type="dimen" name="notification_big_picture_max_height"/>
<java-symbol type="dimen" name="notification_big_picture_max_width"/> <java-symbol type="dimen" name="notification_big_picture_max_width"/>

View File

@@ -34,6 +34,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Binder; import android.os.Binder;
import android.os.Bundle; import android.os.Bundle;
@@ -481,10 +482,16 @@ final class AutofillManagerServiceImpl {
sendStateToClients(true); sendStateToClients(true);
} }
@NonNull
CharSequence getServiceLabel() { CharSequence getServiceLabel() {
return mInfo.getServiceInfo().loadLabel(mContext.getPackageManager()); return mInfo.getServiceInfo().loadLabel(mContext.getPackageManager());
} }
@NonNull
Drawable getServiceIcon() {
return mInfo.getServiceInfo().loadIcon(mContext.getPackageManager());
}
/** /**
* Initializes the last fill selection after an autofill service returned a new * Initializes the last fill selection after an autofill service returned a new
* {@link FillResponse}. * {@link FillResponse}.

View File

@@ -970,8 +970,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
mService.logSaveShown(id); mService.logSaveShown(id);
final IAutoFillManagerClient client = getClient(); final IAutoFillManagerClient client = getClient();
mPendingSaveUi = new PendingUi(mActivityToken, id, client); mPendingSaveUi = new PendingUi(mActivityToken, id, client);
getUiForShowing().showSaveUi(mService.getServiceLabel(), saveInfo, getUiForShowing().showSaveUi(mService.getServiceLabel(), mService.getServiceIcon(),
valueFinder, mPackageName, this, mPendingSaveUi); saveInfo, valueFinder, mPackageName, this, mPendingSaveUi);
if (client != null) { if (client != null) {
try { try {
client.setSaveUiState(id, true); client.setSaveUiState(id, true);
@@ -1774,7 +1774,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
/** /**
* Checks whether this session is hiding the Save UI to handle a custom description link for * Checks whether this session is hiding the Save UI to handle a custom description link for
* a specific {@code token} created by {@link PendingUi#PendingUi(IBinder)}. * a specific {@code token} created by
* {@link PendingUi#PendingUi(IBinder, int, IAutoFillManagerClient)}.
*/ */
boolean isSaveUiPendingForToken(@NonNull IBinder token) { boolean isSaveUiPendingForToken(@NonNull IBinder token) {
return isSaveUiPending() && token.equals(mPendingSaveUi.getToken()); return isSaveUiPending() && token.equals(mPendingSaveUi.getToken());

View File

@@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
import android.content.IntentSender; import android.content.IntentSender;
import android.graphics.drawable.Drawable;
import android.metrics.LogMaker; import android.metrics.LogMaker;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@@ -244,8 +245,8 @@ public final class AutoFillUI {
/** /**
* Shows the UI asking the user to save for autofill. * Shows the UI asking the user to save for autofill.
*/ */
public void showSaveUi(@NonNull CharSequence providerLabel, @NonNull SaveInfo info, public void showSaveUi(@NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
@NonNull ValueFinder valueFinder, @NonNull String packageName, @NonNull SaveInfo info,@NonNull ValueFinder valueFinder, @NonNull String packageName,
@NonNull AutoFillUiCallback callback, @NonNull PendingUi pendingSaveUi) { @NonNull AutoFillUiCallback callback, @NonNull PendingUi pendingSaveUi) {
if (sVerbose) Slog.v(TAG, "showSaveUi() for " + packageName + ": " + info); if (sVerbose) Slog.v(TAG, "showSaveUi() for " + packageName + ": " + info);
int numIds = 0; int numIds = 0;
@@ -261,8 +262,8 @@ public final class AutoFillUI {
return; return;
} }
hideAllUiThread(callback); hideAllUiThread(callback);
mSaveUi = new SaveUi(mContext, pendingSaveUi, providerLabel, info, valueFinder, mSaveUi = new SaveUi(mContext, pendingSaveUi, serviceLabel, serviceIcon, info,
mOverlayControl, new SaveUi.OnSaveListener() { valueFinder, mOverlayControl, new SaveUi.OnSaveListener() {
@Override @Override
public void onSave() { public void onSave() {
log.setType(MetricsProto.MetricsEvent.TYPE_ACTION); log.setType(MetricsProto.MetricsEvent.TYPE_ACTION);

View File

@@ -22,10 +22,14 @@ import static com.android.server.autofill.Helper.sVerbose;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.app.Dialog; import android.app.Dialog;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentSender; import android.content.IntentSender;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
@@ -43,7 +47,7 @@ import android.view.ViewGroup.LayoutParams;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.autofill.AutofillManager; import android.view.autofill.AutofillManager;
import android.view.autofill.IAutoFillManagerClient; import android.widget.ImageView;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
@@ -121,9 +125,9 @@ final class SaveUi {
private boolean mDestroyed; private boolean mDestroyed;
SaveUi(@NonNull Context context, @NonNull PendingUi pendingUi, SaveUi(@NonNull Context context, @NonNull PendingUi pendingUi,
@NonNull CharSequence providerLabel, @NonNull SaveInfo info, @NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
@NonNull ValueFinder valueFinder, @NonNull OverlayControl overlayControl, @NonNull SaveInfo info, @NonNull ValueFinder valueFinder,
@NonNull OnSaveListener listener) { @NonNull OverlayControl overlayControl, @NonNull OnSaveListener listener) {
mPendingUi= pendingUi; mPendingUi= pendingUi;
mListener = new OneTimeListener(listener); mListener = new OneTimeListener(listener);
mOverlayControl = overlayControl; mOverlayControl = overlayControl;
@@ -155,24 +159,25 @@ final class SaveUi {
switch (types.size()) { switch (types.size()) {
case 1: case 1:
mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_type, mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_type,
types.valueAt(0), providerLabel), 0); types.valueAt(0), serviceLabel), 0);
break; break;
case 2: case 2:
mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_2types, mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_2types,
types.valueAt(0), types.valueAt(1), providerLabel), 0); types.valueAt(0), types.valueAt(1), serviceLabel), 0);
break; break;
case 3: case 3:
mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_3types, mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_3types,
types.valueAt(0), types.valueAt(1), types.valueAt(2), providerLabel), 0); types.valueAt(0), types.valueAt(1), types.valueAt(2), serviceLabel), 0);
break; break;
default: default:
// Use generic if more than 3 or invalid type (size 0). // Use generic if more than 3 or invalid type (size 0).
mTitle = Html.fromHtml( mTitle = Html.fromHtml(
context.getString(R.string.autofill_save_title, providerLabel), 0); context.getString(R.string.autofill_save_title, serviceLabel), 0);
} }
titleView.setText(mTitle); titleView.setText(mTitle);
setServiceIcon(context, view, serviceIcon);
ScrollView subtitleContainer = null; ScrollView subtitleContainer = null;
final CustomDescription customDescription = info.getCustomDescription(); final CustomDescription customDescription = info.getCustomDescription();
if (customDescription != null) { if (customDescription != null) {
@@ -284,6 +289,30 @@ final class SaveUi {
show(); show();
} }
private void setServiceIcon(Context context, View view, Drawable serviceIcon) {
final ImageView iconView = view.findViewById(R.id.autofill_save_icon);
final Resources res = context.getResources();
final int maxWidth = res.getDimensionPixelSize(R.dimen.autofill_save_icon_max_size);
final int maxHeight = maxWidth;
final int actualWidth = serviceIcon.getMinimumWidth();
final int actualHeight = serviceIcon.getMinimumHeight();
if (actualWidth <= maxWidth && actualHeight <= maxHeight) {
if (sDebug) {
Slog.d(TAG, "Addingservice icon "
+ "(" + actualWidth + "x" + actualHeight + ") as it's less than maximum "
+ "(" + maxWidth + "x" + maxHeight + ").");
}
iconView.setImageDrawable(serviceIcon);
} else {
Slog.w(TAG, "Not adding service icon of size "
+ "(" + actualWidth + "x" + actualHeight + ") because maximum is "
+ "(" + maxWidth + "x" + maxHeight + ").");
iconView.setVisibility(View.INVISIBLE);
}
}
/** /**
* Update the pending UI, if any. * Update the pending UI, if any.
* *