summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3
diff options
context:
space:
mode:
authorRaj Yengisetty <rajesh@cyngn.com>2015-04-29 18:03:32 -0700
committerRaj Yengisetty <rajesh@cyngn.com>2015-04-30 10:52:24 -0700
commit9887c0bb82cd67611b0d89be0ba09680894317af (patch)
tree7ae346a1386b3fd3b06f6253625b459f36b7b083 /src/com/android/launcher3
parentf6eb35b79a7b9d52e72993c9b3d1e61a95813b7d (diff)
downloadandroid_packages_apps_Trebuchet-9887c0bb82cd67611b0d89be0ba09680894317af.tar.gz
android_packages_apps_Trebuchet-9887c0bb82cd67611b0d89be0ba09680894317af.tar.bz2
android_packages_apps_Trebuchet-9887c0bb82cd67611b0d89be0ba09680894317af.zip
AppDrawer: Calculate numColumns by using available screen space
Using the allAppsNumColumns calculated by DeviceProfile isn't accurate for the vertical app drawer because of the leading char. So calculate our own. Additionally, set the appropriate padding for the drawer icon. Finally, distribute the extra pixel space available for app drawer rows between the app icons. This way apps are evenly spread across the screen. Change-Id: I921c5044d6a490150bf1300762698c2773627ff6
Diffstat (limited to 'src/com/android/launcher3')
-rw-r--r--src/com/android/launcher3/AppDrawerListAdapter.java55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/com/android/launcher3/AppDrawerListAdapter.java b/src/com/android/launcher3/AppDrawerListAdapter.java
index 25c6bb793..20beb0664 100644
--- a/src/com/android/launcher3/AppDrawerListAdapter.java
+++ b/src/com/android/launcher3/AppDrawerListAdapter.java
@@ -79,6 +79,8 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter<AppDrawerListAdap
private LinkedHashMap<String, SectionIndices> mSectionHeaders;
private LinearLayout.LayoutParams mIconParams;
private Rect mIconRect;
+ private int mNumColumns = 0;
+ private int mExtraPadding = 0;
private LocaleSetManager mLocaleSetManager;
private ArrayList<ComponentName> mProtectedApps;
@@ -375,21 +377,21 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter<AppDrawerListAdap
private void initParams() {
mDeviceProfile = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile();
- int width = mDeviceProfile.allAppsIconSizePx + 2 * mDeviceProfile.edgeMarginPx;
- int drawnWidth = (mDeviceProfile.allAppsCellWidthPx * mDeviceProfile.numColumnsBase) +
- ((mDeviceProfile.edgeMarginPx * 2) * mDeviceProfile.numColumnsBase);
+ int iconWidth = mDeviceProfile.allAppsIconSizePx + 2 * mDeviceProfile.edgeMarginPx;
- mIconParams = new
- LinearLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT);
+ // set aside the space needed for the container character
+ int neededWidth = mLauncher.getResources()
+ .getDimensionPixelSize(R.dimen.app_drawer_char_width);
+ int availableWidth = mDeviceProfile.availableWidthPx - neededWidth;
+ mNumColumns = (int) Math.floor(availableWidth / iconWidth);
+ int leftOverPx = availableWidth % iconWidth;
+ // The leftOverPx need to be divided into parts that can be applied as margins to the app
+ // icons. Since we cannot add to the far left or far right margin, break up the leftOverPx
+ // into (numColumns - 1) parts. Divide this value by 2 so that we divide the value equally
+ // between each appIcon in the row.
+ mExtraPadding = (leftOverPx / (mNumColumns - 1)) / 2;
- boolean isLarge = SettingsProvider.getBoolean(mLauncher,
- SettingsProvider.SETTINGS_UI_GENERAL_ICONS_LARGE,
- R.bool.preferences_interface_general_icons_large_default);
-
- if (!isLarge) {
- mIconParams.setMarginStart(mDeviceProfile.edgeMarginPx);
- mIconParams.setMarginEnd(mDeviceProfile.edgeMarginPx);
- }
+ mIconParams = new LinearLayout.LayoutParams(iconWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
mIconParams.topMargin = mDeviceProfile.edgeMarginPx;
mIconParams.bottomMargin = mDeviceProfile.edgeMarginPx;
@@ -448,8 +450,8 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter<AppDrawerListAdap
Collections.sort(appInfos, LauncherModel.getAppNameComparator());
- for (int i = 0; i < appInfos.size(); i += mDeviceProfile.numColumnsBase) {
- int endIndex = (int) Math.min(i + mDeviceProfile.numColumnsBase, appInfos.size());
+ for (int i = 0; i < appInfos.size(); i += mNumColumns) {
+ int endIndex = (int) Math.min(i + mNumColumns, appInfos.size());
ArrayList<AppInfo> subList = new ArrayList<AppInfo>(appInfos.subList(i, endIndex));
AppItemIndexedInfo indexInfo;
indexInfo = new AppItemIndexedInfo(startString, bucketIndex, subList, i != 0);
@@ -638,7 +640,7 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter<AppDrawerListAdap
holder.mTextView.setLayoutParams(marginParams);
}
- for (int i = 0; i < mDeviceProfile.numColumnsBase; i++) {
+ for (int i = 0; i < mNumColumns; i++) {
AppDrawerIconView icon = (AppDrawerIconView) mLayoutInflater.inflate(
R.layout.drawer_icon, holder.mLayout, false);
icon.setOnClickListener(mLauncher);
@@ -690,9 +692,24 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter<AppDrawerListAdap
final int size = indexedInfo.mInfo.size();
- for (int i = 0; i < holder.mLayout.getChildCount(); i++) {
+ int childSize = holder.mLayout.getChildCount();
+ for (int i = 0; i < childSize; i++) {
AppDrawerIconView icon = (AppDrawerIconView) holder.mLayout.getChildAt(i);
icon.setLayoutParams(mIconParams);
+ int extraStart = mExtraPadding;
+ int extraEnd = mExtraPadding;
+ // Do not amend the starting and ending padding, only the padding between icons
+ if (i == 0) {
+ extraStart = 0;
+ } else if (i == childSize - 1) {
+ extraEnd = 0;
+ }
+
+ LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) icon.getLayoutParams();
+ lp.leftMargin = extraStart;
+ lp.rightMargin = extraEnd;
+ icon.setLayoutParams(lp);
+
if (i >= size) {
icon.setVisibility(View.INVISIBLE);
} else {
@@ -702,6 +719,10 @@ public class AppDrawerListAdapter extends RecyclerView.Adapter<AppDrawerListAdap
Drawable d = Utilities.createIconDrawable(info.iconBitmap);
d.setBounds(mIconRect);
icon.mIcon.setImageDrawable(d);
+ icon.mIcon.setPadding(mDeviceProfile.iconDrawablePaddingPx,
+ mDeviceProfile.iconDrawablePaddingPx,
+ mDeviceProfile.iconDrawablePaddingPx,
+ mDeviceProfile.iconDrawablePaddingPx);
icon.mLabel.setText(info.title);
icon.mLabel.setVisibility(mHideIconLabels ? View.INVISIBLE : View.VISIBLE);
}