Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90d0b580 authored by Anna Zappone's avatar Anna Zappone Committed by Android (Google) Code Review
Browse files

Merge "Launch conversation when widget card is clicked."

parents 09d28247 b1c5289c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -586,6 +586,8 @@
            </intent-filter>
        </activity>

        <activity android:name=".people.widget.LaunchConversationActivity" />

        <!-- People Space Widget -->
        <receiver
            android:name=".people.widget.PeopleSpaceWidgetProvider"
+1 −1
Original line number Diff line number Diff line
@@ -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"
+21 −8
Original line number Diff line number Diff line
@@ -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();
            }
        // 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);
        }

        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);
+59 −0
Original line number Diff line number Diff line
/*
 * 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 −0
Original line number Diff line number Diff line
@@ -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);
Loading