From e28930e94f45c8ba70aa31e86044693512ac85b8 Mon Sep 17 00:00:00 2001 From: Braden Farmer Date: Sun, 25 Dec 2016 16:19:36 -0700 Subject: [PATCH] Use existing layout params when defining widget sizes --- .../farmerbb/taskbar/service/DashboardService.java | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/farmerbb/taskbar/service/DashboardService.java b/app/src/main/java/com/farmerbb/taskbar/service/DashboardService.java index 469b24eb..bf018e48 100644 --- a/app/src/main/java/com/farmerbb/taskbar/service/DashboardService.java +++ b/app/src/main/java/com/farmerbb/taskbar/service/DashboardService.java @@ -372,11 +372,13 @@ public class DashboardService extends Service { if(hostView != null) { try { getPackageManager().getApplicationInfo(hostView.getAppWidgetInfo().provider.getPackageName(), 0); - hostView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - hostView.post(new Runnable() { @Override public void run() { + 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()); } }); @@ -510,11 +512,9 @@ public class DashboardService extends Service { private void addWidget(int appWidgetId, int cellId, boolean shouldSave) { AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); - DashboardCell cellLayout = cells.get(cellId); - AppWidgetHostView hostView = mAppWidgetHost.createView(DashboardService.this, appWidgetId, appWidgetInfo); + final DashboardCell cellLayout = cells.get(cellId); + final AppWidgetHostView hostView = mAppWidgetHost.createView(DashboardService.this, appWidgetId, appWidgetInfo); hostView.setAppWidget(appWidgetId, appWidgetInfo); - hostView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - hostView.updateAppWidgetSize(null, cellLayout.getWidth(), cellLayout.getHeight(), cellLayout.getWidth(), cellLayout.getHeight()); Bundle bundle = new Bundle(); bundle.putInt("cellId", cellId); @@ -538,6 +538,17 @@ public class DashboardService extends Service { SharedPreferences pref = U.getSharedPreferences(this); pref.edit().putInt("dashboard_widget_" + Integer.toString(cellId), appWidgetId).apply(); } + + new Handler().post(new Runnable() { + @Override + public void run() { + 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()); + } + }); } private void removeWidget(int cellId) { -- 2.11.0