Adding an upper bound to all-apps width on larger devices

Change-Id: I16a0d8fb7c5023045d0a6b9e8089e0ab6a476d6d
This commit is contained in:
Sunny Goyal
2016-04-04 16:35:22 -07:00
parent 19c5c5765d
commit 13178ac822
5 changed files with 40 additions and 7 deletions

View File

@@ -18,4 +18,7 @@
<!-- QSB -->
<dimen name="toolbar_button_vertical_padding">12dip</dimen>
<dimen name="toolbar_button_horizontal_padding">20dip</dimen>
<!-- Container -->
<dimen name="container_max_width">736dp</dimen>
</resources>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<!-- Container -->
<dimen name="container_max_width">736dp</dimen>
</resources>

View File

@@ -69,6 +69,7 @@
<item name="container_margin" format="fraction" type="fraction">0%</item>
<dimen name="container_min_margin">8dp</dimen>
<dimen name="container_max_width">0dp</dimen>
<!-- All Apps -->
<dimen name="all_apps_button_scale_down">0dp</dimen>

View File

@@ -18,16 +18,12 @@ package com.android.launcher3;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import com.android.launcher3.config.ProviderConfig;
/**
* A base container view, which supports resizing.
*/
@@ -52,9 +48,7 @@ public abstract class BaseContainerView extends FrameLayout {
super(context, attrs, defStyleAttr);
int width = ((Launcher) context).getDeviceProfile().availableWidthPx;
mHorizontalPadding = Math.max(
getResources().getDimensionPixelSize(R.dimen.container_min_margin),
(int) getResources().getFraction(R.fraction.container_margin, width, 1));
mHorizontalPadding = DeviceProfile.getMaxContainerWidth(context, width);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.BaseContainerView, defStyleAttr, 0);

View File

@@ -594,4 +594,19 @@ public class DeviceProfile {
? Math.min(widthPx, heightPx)
: Math.max(widthPx, heightPx);
}
public static final int getMaxContainerWidth(Context context, int availableWidth) {
Resources res = context.getResources();
int maxSize = res.getDimensionPixelSize(R.dimen.container_max_width);
int minMargin = res.getDimensionPixelSize(R.dimen.container_min_margin);
if (maxSize > 0) {
return Math.max(minMargin, (availableWidth - maxSize) / 2);
} else {
return Math.max(minMargin,
(int) res.getFraction(R.fraction.container_margin, availableWidth, 1));
}
}
}