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

Commit 983e4065 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Starting the default activity when an app widget's

default/fallback view is clicked

Bug: 119142325
Test: Verfied on device
Change-Id: I5ac39b77cdd0a46f8c66dcec289cec78746e67cf
parent 45ac8e40
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Color;
@@ -622,6 +624,7 @@ public class AppWidgetHostView extends FrameLayout {
                    }
                }
                defaultView = inflater.inflate(layoutId, this, false);
                defaultView.setOnClickListener(this::onDefaultViewClicked);
            } else {
                Log.w(TAG, "can't inflate defaultView because mInfo is missing");
            }
@@ -641,6 +644,19 @@ public class AppWidgetHostView extends FrameLayout {
        return defaultView;
    }

    private void onDefaultViewClicked(View view) {
        if (mInfo != null) {
            LauncherApps launcherApps = getContext().getSystemService(LauncherApps.class);
            List<LauncherActivityInfo> activities = launcherApps.getActivityList(
                    mInfo.provider.getPackageName(), mInfo.getProfile());
            if (!activities.isEmpty()) {
                LauncherActivityInfo ai = activities.get(0);
                launcherApps.startMainActivity(ai.getComponentName(), ai.getUser(),
                        RemoteViews.getSourceBounds(view), null);
            }
        }
    }

    /**
     * Inflate and return a view that represents an error state.
     */