diff options
-rw-r--r-- | res/layout/app_drawer_item.xml | 2 | ||||
-rw-r--r-- | res/values/dimens.xml | 1 | ||||
-rw-r--r-- | src/com/android/launcher3/AppDrawerListAdapter.java | 55 |
3 files changed, 40 insertions, 18 deletions
diff --git a/res/layout/app_drawer_item.xml b/res/layout/app_drawer_item.xml index 46a965226..b80ad6756 100644 --- a/res/layout/app_drawer_item.xml +++ b/res/layout/app_drawer_item.xml @@ -49,7 +49,7 @@ <com.android.launcher3.AutoFitTextView android:id="@+id/drawer_item_title" - android:layout_width="27dp" + android:layout_width="@dimen/app_drawer_char_width" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginLeft="6dp" diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 124bcb7db..2992cef1b 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -128,6 +128,7 @@ <dimen name="app_drawer_scrubber_padding">20dp</dimen> <!-- App Drawer Item --> + <dimen name="app_drawer_char_width">27dp</dimen> <dimen name="container_paddingStart">6dp</dimen> <dimen name="container_paddingEnd">6dp</dimen> <dimen name="aftv_width">32dp</dimen> 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); } |