Merge "Launch conversation when widget card is clicked."
This commit is contained in:
@@ -586,6 +586,8 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".people.widget.LaunchConversationActivity" />
|
||||
|
||||
<!-- People Space Widget -->
|
||||
<receiver
|
||||
android:name=".people.widget.PeopleSpaceWidgetProvider"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -69,16 +69,29 @@ public class PeopleSpaceUtils {
|
||||
|
||||
/** Converts {@code drawable} to a {@link Bitmap}. */
|
||||
public static Bitmap convertDrawableToBitmap(Drawable drawable) {
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
return ((BitmapDrawable) drawable).getBitmap();
|
||||
if (drawable == null) {
|
||||
return null;
|
||||
}
|
||||
// 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);
|
||||
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
drawable.draw(canvas);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user