summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/widget
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2015-05-06 11:42:25 -0700
committerAdam Cohen <adamcohen@google.com>2015-05-21 16:16:40 -0700
commit2e6da1539bc7286336b3c24d96ab76434939ce4d (patch)
tree38c7387dc9a5f6f084c4998aac88495189423d3b /src/com/android/launcher3/widget
parenta9d012c6e67b644498e07c63f36617c1b8915e02 (diff)
downloadandroid_packages_apps_Trebuchet-2e6da1539bc7286336b3c24d96ab76434939ce4d.tar.gz
android_packages_apps_Trebuchet-2e6da1539bc7286336b3c24d96ab76434939ce4d.tar.bz2
android_packages_apps_Trebuchet-2e6da1539bc7286336b3c24d96ab76434939ce4d.zip
Refactoring DeviceProfile
-> Pulling out the parts of device profile which can (and need to be) initialized and accessed without access to an Activity context, ie. the invariant bits. -> The invariant bits are stored in InvariantDeviceProfile which is initialized statically from LauncherAppState. -> The DeviceProfile contains the Activity context-dependent bits, and we will create one of these for each Activity instance, and this instance is accessed through the Launcher activity. -> It's possible that we can continue to refactor this such that all appropriate dimensions can be computed without an Activity context (by only specifying orientation). This would be an extension of this CL and allow us to know exactly how launcher will look in both orientations from any context. Sets the stage for some improvements around b/19514688 Change-Id: Ia7daccf14d8ca2b9cb340b8780b684769e9f1892
Diffstat (limited to 'src/com/android/launcher3/widget')
-rw-r--r--src/com/android/launcher3/widget/PendingAddWidgetInfo.java11
-rw-r--r--src/com/android/launcher3/widget/WidgetCell.java22
-rw-r--r--src/com/android/launcher3/widget/WidgetsContainerView.java6
-rw-r--r--src/com/android/launcher3/widget/WidgetsListAdapter.java13
4 files changed, 28 insertions, 24 deletions
diff --git a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
index db1699818..36cc2b111 100644
--- a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
+++ b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
@@ -19,6 +19,7 @@ import android.appwidget.AppWidgetHostView;
import android.os.Bundle;
import android.os.Parcelable;
+import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.PendingAddItemInfo;
@@ -39,7 +40,7 @@ public class PendingAddWidgetInfo extends PendingAddItemInfo {
public AppWidgetHostView boundWidget;
public Bundle bindOptions = null;
- public PendingAddWidgetInfo(LauncherAppWidgetProviderInfo i, Parcelable data) {
+ public PendingAddWidgetInfo(Launcher launcher, LauncherAppWidgetProviderInfo i, Parcelable data) {
if (i.isCustomWidget) {
itemType = LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
} else {
@@ -54,10 +55,10 @@ public class PendingAddWidgetInfo extends PendingAddItemInfo {
previewImage = i.previewImage;
icon = i.icon;
- spanX = i.spanX;
- spanY = i.spanY;
- minSpanX = i.minSpanX;
- minSpanY = i.minSpanY;
+ spanX = i.getSpanX(launcher);
+ spanY = i.getSpanY(launcher);
+ minSpanX = i.getMinSpanX(launcher);
+ minSpanY = i.getMinSpanY(launcher);
}
public boolean isCustomWidget() {
diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java
index dcaf1f211..3ec164506 100644
--- a/src/com/android/launcher3/widget/WidgetCell.java
+++ b/src/com/android/launcher3/widget/WidgetCell.java
@@ -29,7 +29,9 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
+import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.R;
@@ -72,6 +74,8 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
private WidgetPreviewLoader mWidgetPreviewLoader;
private PreviewLoadRequest mActiveRequest;
+ private Launcher mLauncher;
+
public WidgetCell(Context context) {
this(context, null);
}
@@ -84,8 +88,9 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
super(context, attrs, defStyle);
final Resources r = context.getResources();
- mDimensionsFormatString = r.getString(R.string.widget_dims_format);
+ mLauncher = (Launcher) context;
+ mDimensionsFormatString = r.getString(R.string.widget_dims_format);
setContainerWidth();
setWillNotDraw(false);
setClipToPadding(false);
@@ -93,9 +98,9 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
}
private void setContainerWidth() {
- DeviceProfile profile = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile();
+ DeviceProfile profile = mLauncher.getDeviceProfile();
cellSize = (int) (profile.cellWidthPx * WIDTH_SCALE);
- mPresetPreviewSize = (int) (profile.cellWidthPx * WIDTH_SCALE * PREVIEW_SCALE);
+ mPresetPreviewSize = (int) (cellSize * PREVIEW_SCALE);
}
@Override
@@ -130,14 +135,14 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
*/
public void applyFromAppWidgetProviderInfo(LauncherAppWidgetProviderInfo info,
WidgetPreviewLoader loader) {
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
+ InvariantDeviceProfile profile =
+ LauncherAppState.getInstance().getInvariantDeviceProfile();
mInfo = info;
// TODO(hyunyoungs): setup a cache for these labels.
mWidgetName.setText(AppWidgetManagerCompat.getInstance(getContext()).loadLabel(info));
- int hSpan = Math.min(info.spanX, grid.numColumns);
- int vSpan = Math.min(info.spanY, grid.numRows);
+ int hSpan = Math.min(info.getSpanX(mLauncher), profile.numColumns);
+ int vSpan = Math.min(info.getSpanY(mLauncher), profile.numRows);
mWidgetDims.setText(String.format(mDimensionsFormatString, hSpan, vSpan));
mWidgetPreviewLoader = loader;
}
@@ -192,8 +197,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
public int getActualItemWidth() {
ItemInfo info = (ItemInfo) getTag();
int[] size = getPreviewSize();
- int cellWidth = LauncherAppState.getInstance()
- .getDynamicGrid().getDeviceProfile().cellWidthPx;
+ int cellWidth = mLauncher.getDeviceProfile().cellWidthPx;
return Math.min(size[0], info.spanX * cellWidth);
}
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index 5a879faa0..05e842e71 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -109,7 +109,7 @@ public class WidgetsContainerView extends BaseContainerView
mView.setLayoutManager(new LinearLayoutManager(getContext()) {
@Override
protected int getExtraLayoutSpace(State state) {
- DeviceProfile grid = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile();
+ DeviceProfile grid = mLauncher.getDeviceProfile();
return super.getExtraLayoutSpace(state)
+ grid.availableHeightPx * PRELOAD_SCREEN_HEIGHT_MULTIPLE;
}
@@ -230,8 +230,8 @@ public class WidgetsContainerView extends BaseContainerView
int maxWidth = Math.min((int) (icon.getWidth() * minScale), size[0]);
int[] previewSizeBeforeScale = new int[1];
- preview = getWidgetPreviewLoader().generateWidgetPreview(createWidgetInfo.info,
- maxWidth, null, previewSizeBeforeScale);
+ preview = getWidgetPreviewLoader().generateWidgetPreview(mLauncher,
+ createWidgetInfo.info, maxWidth, null, previewSizeBeforeScale);
if (previewSizeBeforeScale[0] < icon.getWidth()) {
// The icon has extra padding around it.
diff --git a/src/com/android/launcher3/widget/WidgetsListAdapter.java b/src/com/android/launcher3/widget/WidgetsListAdapter.java
index 918ec1bda..7439a44f8 100644
--- a/src/com/android/launcher3/widget/WidgetsListAdapter.java
+++ b/src/com/android/launcher3/widget/WidgetsListAdapter.java
@@ -32,11 +32,12 @@ import android.widget.LinearLayout;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.DeviceProfile;
-import com.android.launcher3.DynamicGrid;
+import com.android.launcher3.IconCache;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
import com.android.launcher3.WidgetPreviewLoader;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.model.WidgetsModel;
@@ -56,7 +57,6 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
private static final String TAG = "WidgetsListAdapter";
private static final boolean DEBUG = true;
- private Context mContext;
private Launcher mLauncher;
private LayoutInflater mLayoutInflater;
@@ -74,7 +74,6 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
View.OnLongClickListener iconLongClickListener,
Launcher launcher) {
mLayoutInflater = LayoutInflater.from(context);
- mContext = context;
mIconClickListener = iconClickListener;
mIconLongClickListener = iconLongClickListener;
@@ -141,7 +140,7 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
WidgetCell widget = (WidgetCell) row.getChildAt(i);
if (infoList.get(i) instanceof LauncherAppWidgetProviderInfo) {
LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) infoList.get(i);
- PendingAddWidgetInfo pawi = new PendingAddWidgetInfo(info, null);
+ PendingAddWidgetInfo pawi = new PendingAddWidgetInfo(mLauncher, info, null);
widget.setTag(pawi);
widget.applyFromAppWidgetProviderInfo(info, mWidgetPreviewLoader);
} else if (infoList.get(i) instanceof ResolveInfo) {
@@ -206,10 +205,10 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
}
private void setContainerHeight() {
- Resources r = mContext.getResources();
- DeviceProfile profile = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile();
+ Resources r = mLauncher.getResources();
+ DeviceProfile profile = mLauncher.getDeviceProfile();
if (profile.isLargeTablet || profile.isTablet) {
- mIndent = DynamicGrid.pxFromDp(PRESET_INDENT_SIZE_TABLET, r.getDisplayMetrics());
+ mIndent = Utilities.pxFromDp(PRESET_INDENT_SIZE_TABLET, r.getDisplayMetrics());
}
}
}