diff options
| author | 2020-10-26 13:36:19 +0000 | |
|---|---|---|
| committer | 2020-10-26 13:36:19 +0000 | |
| commit | 90d0b580026ac40fe75eb0da0784c6603321180b (patch) | |
| tree | 7059a703b1ca61e985ce1b205a1ef51331e005c5 | |
| parent | 09d28247c5864a15f16cb8184f0fede6f50ffd9c (diff) | |
| parent | b1c5289c1cd413f87d27190e699b86d293ba158a (diff) | |
Merge "Launch conversation when widget card is clicked."
6 files changed, 103 insertions, 9 deletions
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 407104504132..ddd0dac0e9db 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -586,6 +586,8 @@ </intent-filter> </activity> + <activity android:name=".people.widget.LaunchConversationActivity" /> + <!-- People Space Widget --> <receiver android:name=".people.widget.PeopleSpaceWidgetProvider" diff --git a/packages/SystemUI/res/layout/people_space_widget_item.xml b/packages/SystemUI/res/layout/people_space_widget_item.xml index a40bfffaabd7..e4de6f91769c 100644 --- a/packages/SystemUI/res/layout/people_space_widget_item.xml +++ b/packages/SystemUI/res/layout/people_space_widget_item.xml @@ -15,12 +15,12 @@ ~ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/item" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:background="@drawable/people_space_tile_view_card" + android:id="@+id/item" android:orientation="vertical" android:padding="6dp" android:layout_marginBottom="6dp" diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java index 2ddcc5aa77fe..1a9dd712bd0e 100644 --- a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +++ b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java @@ -69,16 +69,29 @@ public class PeopleSpaceUtils { /** Converts {@code drawable} to a {@link Bitmap}. */ public static Bitmap convertDrawableToBitmap(Drawable drawable) { + if (drawable == null) { + return null; + } + if (drawable instanceof BitmapDrawable) { - return ((BitmapDrawable) drawable).getBitmap(); + BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; + if (bitmapDrawable.getBitmap() != null) { + return bitmapDrawable.getBitmap(); + } + } + + Bitmap bitmap; + if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { + bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); + // Single color bitmap will be created of 1x1 pixel + } else { + bitmap = Bitmap.createBitmap( + drawable.getIntrinsicWidth(), + drawable.getIntrinsicHeight(), + Bitmap.Config.ARGB_8888 + ); } - // We use max below because the drawable might have no intrinsic width/height (e.g. if the - // drawable is a solid color). - Bitmap bitmap = - Bitmap.createBitmap( - Math.max(drawable.getIntrinsicWidth(), 1), - Math.max(drawable.getIntrinsicHeight(), 1), - Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/LaunchConversationActivity.java b/packages/SystemUI/src/com/android/systemui/people/widget/LaunchConversationActivity.java new file mode 100644 index 000000000000..44f173bc5175 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/people/widget/LaunchConversationActivity.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.people.widget; + +import android.app.Activity; +import android.content.Intent; +import android.content.pm.LauncherApps; +import android.content.pm.ShortcutInfo; +import android.os.Bundle; +import android.util.Log; + +import com.android.systemui.people.PeopleSpaceUtils; + +/** Proxy activity to launch ShortcutInfo's conversation. */ +public class LaunchConversationActivity extends Activity { + private static final String TAG = "PeopleSpaceLaunchConv"; + private static final boolean DEBUG = PeopleSpaceUtils.DEBUG; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (DEBUG) Log.d(TAG, "onCreate called"); + + Intent intent = getIntent(); + ShortcutInfo shortcutInfo = (ShortcutInfo) intent.getParcelableExtra( + PeopleSpaceWidgetProvider.EXTRA_SHORTCUT_INFO + ); + if (shortcutInfo != null) { + if (DEBUG) { + Log.d(TAG, "Launching conversation with shortcutInfo id " + shortcutInfo.getId()); + } + try { + LauncherApps launcherApps = + getApplicationContext().getSystemService(LauncherApps.class); + launcherApps.startShortcut( + shortcutInfo, null, null); + } catch (Exception e) { + Log.e(TAG, "Exception starting shortcut:" + e); + } + } else { + if (DEBUG) Log.d(TAG, "Trying to launch conversation with null shortcutInfo."); + } + finish(); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java index 85801f9e7206..aa98b61ff947 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetProvider.java @@ -16,6 +16,7 @@ package com.android.systemui.people.widget; +import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; @@ -31,6 +32,8 @@ public class PeopleSpaceWidgetProvider extends AppWidgetProvider { private static final String TAG = "PeopleSpaceWidgetPvd"; private static final boolean DEBUG = PeopleSpaceUtils.DEBUG; + public static final String EXTRA_SHORTCUT_INFO = "extra_shortcut_info"; + /** Called when widget updates. */ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); @@ -45,6 +48,19 @@ public class PeopleSpaceWidgetProvider extends AppWidgetProvider { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); views.setRemoteAdapter(R.id.widget_list_view, intent); + Intent activityIntent = new Intent(context, LaunchConversationActivity.class); + activityIntent.addFlags( + Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_CLEAR_TASK + | Intent.FLAG_ACTIVITY_NO_HISTORY + | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + PendingIntent pendingIntent = PendingIntent.getActivity( + context, + appWidgetId, + activityIntent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + views.setPendingIntentTemplate(R.id.widget_list_view, pendingIntent); + // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_list_view); appWidgetManager.updateAppWidget(appWidgetId, views); diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetRemoteViewsFactory.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetRemoteViewsFactory.java index 093925a2664a..c68c30632b6c 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetRemoteViewsFactory.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetRemoteViewsFactory.java @@ -130,6 +130,10 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R mLauncherApps.getShortcutIconDrawable(shortcutInfo, 0) ) ); + + Intent fillInIntent = new Intent(); + fillInIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_SHORTCUT_INFO, shortcutInfo); + personView.setOnClickFillInIntent(R.id.item, fillInIntent); } catch (Exception e) { Log.e(TAG, "Couldn't retrieve shortcut information", e); } |