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

Commit f4a0d188 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Enabling async inflation for AppWidgets" into ub-launcher3-master

parents 9117e94e dcc0ba29
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context;
import android.graphics.Rect;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -36,13 +37,17 @@ import android.widget.RemoteViews;

import com.android.launcher3.dragndrop.DragLayer.TouchCompleteListener;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.concurrent.Executor;

/**
 * {@inheritDoc}
 */
public class LauncherAppWidgetHostView extends AppWidgetHostView implements TouchCompleteListener {

    private static final String TAG = "LauncherWidgetHostView";

    // Related to the auto-advancing of widgets
    private static final long ADVANCE_INTERVAL = 20000;
    private static final long ADVANCE_STAGGER = 250;
@@ -75,6 +80,16 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView implements Touc
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        setAccessibilityDelegate(Launcher.getLauncher(context).getAccessibilityDelegate());
        setBackgroundResource(R.drawable.widget_internal_focus_bg);

        if (Utilities.isAtLeastO()) {
            try {
                Method asyncMethod = AppWidgetHostView.class
                        .getMethod("setAsyncExecutor", Executor.class);
                asyncMethod.invoke(this, Utilities.THREAD_POOL_EXECUTOR);
            } catch (Exception e) {
                Log.e(TAG, "Unable to set async executor", e);
            }
        }
    }

    @Override
+6 −0
Original line number Diff line number Diff line
@@ -85,6 +85,12 @@ public final class Utilities {
    private static final Matrix sMatrix = new Matrix();
    private static final Matrix sInverseMatrix = new Matrix();

    public static boolean isAtLeastO() {
        // TODO: Clean this up: b/32610406
        return !"REL".equals(Build.VERSION.CODENAME)
                && "O".compareTo(Build.VERSION.CODENAME) <= 0;
    }

    public static final boolean ATLEAST_NOUGAT_MR1 =
        Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1;