Example usage for android.appwidget AppWidgetHostView getAppWidgetInfo

List of usage examples for android.appwidget AppWidgetHostView getAppWidgetInfo

Introduction

In this page you can find the example usage for android.appwidget AppWidgetHostView getAppWidgetInfo.

Prototype

public AppWidgetProviderInfo getAppWidgetInfo() 

Source Link

Usage

From source file:com.farmerbb.taskbar.service.DashboardService.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N)//from  w  w w  . j a  v  a  2  s. c  o  m
private void showDashboard() {
    if (layout.getVisibility() == View.GONE) {
        layout.setOnClickListener(ocl);
        fadeIn();

        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.DASHBOARD_APPEARING"));
        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

        boolean inFreeformMode = FreeformHackHelper.getInstance().isInFreeformWorkspace();

        final SharedPreferences pref = U.getSharedPreferences(this);
        Intent intent = null;

        switch (pref.getString("theme", "light")) {
        case "light":
            intent = new Intent(this, DashboardActivity.class);
            break;
        case "dark":
            intent = new Intent(this, DashboardActivityDark.class);
            break;
        }

        if (intent != null) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        }

        if (inFreeformMode) {
            if (intent != null && U.isOPreview())
                intent.putExtra("context_menu_fix", true);

            U.launchAppMaximized(this, intent);
        } else
            startActivity(intent);

        for (int i = 0; i < maxSize; i++) {
            final DashboardCell cellLayout = cells.get(i);
            final AppWidgetHostView hostView = widgets.get(i);

            if (hostView != null) {
                try {
                    getPackageManager()
                            .getApplicationInfo(hostView.getAppWidgetInfo().provider.getPackageName(), 0);
                    hostView.post(() -> {
                        ViewGroup.LayoutParams params = hostView.getLayoutParams();
                        params.width = cellLayout.getWidth();
                        params.height = cellLayout.getHeight();
                        hostView.setLayoutParams(params);
                        hostView.updateAppWidgetSize(null, cellLayout.getWidth(), cellLayout.getHeight(),
                                cellLayout.getWidth(), cellLayout.getHeight());
                    });
                } catch (PackageManager.NameNotFoundException e) {
                    removeWidget(i, false);
                } catch (NullPointerException e) {
                    removeWidget(i, true);
                }
            }
        }

        if (!pref.getBoolean("dashboard_tutorial_shown", false)) {
            U.showToastLong(this, R.string.dashboard_tutorial);
            pref.edit().putBoolean("dashboard_tutorial_shown", true).apply();
        }
    }
}