[WifiSetup] Tablet landscape layout

Created setup_preference for sw600dp-land, modeled after
template_with_header in Setup Wizard. Copied over wide illustration,
which is again a placeholder and needs real graphics from UX.
Renamed SetupWizardHeader to SetupWizardIllustration. Added
aspectRatio attribute to SetupWizardIllustration that, will set the
aspect ratio of the top padding. If 0 or not specified, padding will
not be set.

Bug: 16349429
Change-Id: Ic2623ee0c0ee8864383d22da006b418b8c371bf0
This commit is contained in:
Maurice Lam
2014-07-17 20:35:15 -07:00
parent 1f53937469
commit 068354a1bb
8 changed files with 171 additions and 49 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2014 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.android.settings.widget.SetupWizardIllustration
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:foreground="@drawable/illustration_wifi_wide"
android:background="@drawable/grass">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start|top"
android:weightSum="16">
<TextView
android:id="@+id/title"
style="@style/SetupCardTitle"
android:text="@string/wifi_setup_wizard_title"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/setup_wizard_card_margin_top"
android:layout_weight="8"
android:background="?android:attr/colorBackground"
android:elevation="@dimen/setup_wizard_card_elevation"
android:orientation="vertical">
<TextView
android:id="@+id/wifi_required_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:text="@string/wifi_required_info_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:cacheColorHint="@android:color/transparent"
android:clipToPadding="false"
android:drawSelectorOnTop="false"
android:headerDividersEnabled="false"
android:scrollbarAlwaysDrawVerticalTrack="true" />
</LinearLayout>
</LinearLayout>
</com.android.settings.widget.SetupWizardIllustration>
<fragment android:name="com.android.setupwizard.navigationbar.SetupWizardNavBar"
android:id="@+id/navigation_bar"
style="@style/setup_wizard_navbar_style" />
</LinearLayout>

View File

@@ -15,14 +15,16 @@
limitations under the License. limitations under the License.
--> -->
<com.android.settings.widget.SetupWizardHeader <com.android.settings.widget.SetupWizardIllustration
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:id="@+id/title_area" android:id="@+id/title_area"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/grass" android:background="@drawable/grass"
android:foreground="@drawable/illustration_wifi" android:foreground="@drawable/illustration_wifi"
android:tag="stickyContainer"> android:tag="stickyContainer"
settings:aspectRatio="2.0">
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
@@ -32,4 +34,4 @@
android:tag="sticky" android:tag="sticky"
android:text="@string/wifi_setup_wizard_title"/> android:text="@string/wifi_setup_wizard_title"/>
</com.android.settings.widget.SetupWizardHeader> </com.android.settings.widget.SetupWizardIllustration>

View File

@@ -21,7 +21,11 @@
<declare-styleable name="IconPreferenceScreen"> <declare-styleable name="IconPreferenceScreen">
<attr name="icon" format="reference" /> <attr name="icon" format="reference" />
</declare-styleable> </declare-styleable>
<declare-styleable name="SetupWizardIllustration">
<attr name="aspectRatio" format="float" />
</declare-styleable>
<declare-styleable name="BatteryHistoryChart"> <declare-styleable name="BatteryHistoryChart">
<!-- Base text color, typeface, size, and style. --> <!-- Base text color, typeface, size, and style. -->
<attr name="android:textAppearance" /> <attr name="android:textAppearance" />

View File

@@ -48,6 +48,12 @@
<!-- Size of padding to give in the wifi list when there is no icon --> <!-- Size of padding to give in the wifi list when there is no icon -->
<dimen name="setup_list_no_icon_padding">56dp</dimen> <dimen name="setup_list_no_icon_padding">56dp</dimen>
<dimen name="setup_add_network_item_height">56dp</dimen> <dimen name="setup_add_network_item_height">56dp</dimen>
<dimen name="setup_wizard_card_elevation">5dp</dimen>
<dimen name="setup_wizard_card_margin_top">128dp</dimen>
<dimen name="setup_wizard_card_title_margin_top">256dp</dimen>
<dimen name="setup_wizard_card_title_padding_end">32dp</dimen>
<dimen name="setup_wizard_card_title_padding_start">56dp</dimen>
<dimen name="setup_wizard_card_title_padding_top">24dp</dimen>
<dimen name="setup_wizard_margin_sides">40dp</dimen> <dimen name="setup_wizard_margin_sides">40dp</dimen>
<dimen name="divider_height">3dip</dimen> <dimen name="divider_height">3dip</dimen>

View File

@@ -174,6 +174,18 @@
<item name="android:paddingTop">@dimen/setup_title_padding_top</item> <item name="android:paddingTop">@dimen/setup_title_padding_top</item>
</style> </style>
<!-- Alternate title style used for some tablet-landscape layouts -->
<style name="SetupCardTitle" parent="@android:style/TextAppearance.Material.Display1">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">@dimen/setup_wizard_card_title_margin_top</item>
<item name="android:layout_weight">6</item>
<item name="android:paddingStart">@dimen/setup_wizard_card_title_padding_start</item>
<item name="android:paddingEnd">@dimen/setup_wizard_card_title_padding_end</item>
<item name="android:paddingTop">@dimen/setup_wizard_card_title_padding_top</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="SetupAddWifiNetwork"> <style name="SetupAddWifiNetwork">
<item name="android:fontFamily">sans-serif-medium</item> <item name="android:fontFamily">sans-serif-medium</item>
<item name="android:gravity">start|center_vertical</item> <item name="android:gravity">start|center_vertical</item>

View File

@@ -22,49 +22,51 @@ import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.widget.FrameLayout; import android.widget.FrameLayout;
/* import com.android.settings.R;
* Copied from com.google.android.setupwizard.util.SetupWizardHeader
*/
public class SetupWizardHeader extends FrameLayout {
// Size the baseline grid in pixels /**
* Class to draw the illustration of setup wizard. The aspectRatio attribute determines the aspect
* ratio of the top padding, which is leaving space for the illustration. Draws an illustration
* (foreground) to fit the width of the view and fills the rest with the background.
*
* Copied from com.google.android.setupwizard.util.SetupWizardIllustration
*/
public class SetupWizardIllustration extends FrameLayout {
private static final String TAG = "SetupWizardIllustration";
// Size of the baseline grid in pixels
private float mBaselineGridSize; private float mBaselineGridSize;
private Drawable mBackground; private Drawable mBackground;
private Drawable mForeground; private Drawable mForeground;
private int mForegroundHeight; private int mForegroundHeight = 0;
private float mScale = 1.0f; private float mScale = 1.0f;
private float mAspectRatio = 0.0f;
public SetupWizardHeader(Context context) { public SetupWizardIllustration(Context context) {
super(context); this(context, null);
init();
} }
public SetupWizardHeader(Context context, AttributeSet attrs) { public SetupWizardIllustration(Context context, AttributeSet attrs) {
super(context, attrs); this(context, attrs, 0);
initFromAttributes(context, attrs);
} }
public SetupWizardHeader(Context context, AttributeSet attrs, int defStyleAttr) { public SetupWizardIllustration(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); this(context, attrs, defStyleAttr, 0);
initFromAttributes(context, attrs);
} }
public SetupWizardHeader(Context context, AttributeSet attrs, int defStyleAttr, public SetupWizardIllustration(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) { int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
initFromAttributes(context, attrs); if (attrs != null) {
} TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.SetupWizardIllustration, 0, 0);
private void initFromAttributes(Context context, AttributeSet attrs) { mAspectRatio = a.getFloat(R.styleable.SetupWizardIllustration_aspectRatio, 0.0f);
TypedArray a = context.obtainStyledAttributes(attrs, a.recycle();
new int[] { android.R.attr.foreground }); }
setForeground(a.getDrawable(0));
init();
}
protected void init() {
// Number of pixels of the 8dp baseline grid as defined in material design specs // Number of pixels of the 8dp baseline grid as defined in material design specs
mBaselineGridSize = getResources().getDisplayMetrics().density * 8; mBaselineGridSize = getResources().getDisplayMetrics().density * 8;
setWillNotDraw(false); setWillNotDraw(false);
@@ -83,15 +85,19 @@ public class SetupWizardHeader extends FrameLayout {
* Sets the drawable used as the illustration. THe drawable is expected to have intrinsic * Sets the drawable used as the illustration. THe drawable is expected to have intrinsic
* width and height defined and will be scaled to fit the width of the view. * width and height defined and will be scaled to fit the width of the view.
*/ */
@Override
public void setForeground(Drawable foreground) { public void setForeground(Drawable foreground) {
mForeground = foreground; mForeground = foreground;
} }
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int illustrationHeight = MeasureSpec.getSize(widthMeasureSpec) / 2; if (mAspectRatio != 0.0f) {
illustrationHeight -= illustrationHeight % mBaselineGridSize; int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
setPadding(0, illustrationHeight, 0, 0); int illustrationHeight = (int) (parentWidth / mAspectRatio);
illustrationHeight -= illustrationHeight % mBaselineGridSize;
setPaddingRelative(0, illustrationHeight, 0, 0);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} }
@@ -100,16 +106,25 @@ public class SetupWizardHeader extends FrameLayout {
final int layoutWidth = right - left; final int layoutWidth = right - left;
final int layoutHeight = bottom - top; final int layoutHeight = bottom - top;
if (mForeground != null) { if (mForeground != null) {
// Scale the foreground to fill the width of the view final float intrinsicWidth = mForeground.getIntrinsicWidth();
mScale = layoutWidth / (float) mForeground.getIntrinsicWidth(); final float intrinsicHeight = mForeground.getIntrinsicHeight();
mForegroundHeight = (int) (mForeground.getIntrinsicHeight() * mScale); if (intrinsicWidth <= 0 || intrinsicHeight <= 0) {
mForeground.setBounds(0, 0, layoutWidth, mForegroundHeight); Log.e(TAG, "Foreground drawable intrinsic size must be defined and positive");
mForeground = null;
mForegroundHeight = 0;
mScale = 1.0f;
} else {
// Scale the foreground to fill the width of the view
mScale = layoutWidth / intrinsicWidth;
mForegroundHeight = (int) (intrinsicHeight * mScale);
mForeground.setBounds(0, 0, layoutWidth, mForegroundHeight);
}
} }
if (mBackground != null) { if (mBackground != null) {
// Scale the bounds by mScale to compensate for the scale done to the canvas before // Scale the bounds by mScale to compensate for the scale done to the canvas before
// drawing. // drawing.
mBackground.setBounds(0, 0, (int) (layoutWidth / mScale), mBackground.setBounds(0, 0, (int) Math.ceil(layoutWidth / mScale),
(int) ((layoutHeight - mForegroundHeight) / mScale)); (int) Math.ceil((layoutHeight - mForegroundHeight) / mScale));
} }
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
} }
@@ -117,19 +132,20 @@ public class SetupWizardHeader extends FrameLayout {
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
if (mBackground != null) { if (mBackground != null) {
canvas.save();
// Draw the background filling parts not covered by the illustration // Draw the background filling parts not covered by the illustration
int saveCount = canvas.save();
canvas.translate(0, mForegroundHeight); canvas.translate(0, mForegroundHeight);
// Scale the background so its size matches the foreground // Scale the background so its size matches the foreground
canvas.scale(mScale, mScale, 0, 0); canvas.scale(mScale, mScale, 0, 0);
mBackground.draw(canvas); mBackground.draw(canvas);
canvas.restoreToCount(saveCount); canvas.restore();
} }
if (mForeground != null) { if (mForeground != null) {
canvas.save();
// Draw the illustration // Draw the illustration
mForeground.draw(canvas); mForeground.draw(canvas);
canvas.restore();
} }
super.onDraw(canvas); super.onDraw(canvas);
} }
} }

View File

@@ -28,10 +28,10 @@ import android.view.WindowInsets;
import android.widget.ListView; import android.widget.ListView;
/** /**
* This class provides sticky header functionality in a list view, to use with SetupWizardHeader. * This class provides sticky header functionality in a list view, to use with
* To use this, add a header tagged with "sticky", or a header tagged with "stickyContainer" and * SetupWizardIllustration. To use this, add a header tagged with "sticky", or a header tagged with
* one of its child tagged as "sticky". The sticky container will be draw when the sticky element * "stickyContainer" and one of its child tagged as "sticky". The sticky container will be drawn
* hits the top of the view. * when the sticky element hits the top of the view.
* *
* There are a few things to note: * There are a few things to note:
* 1. The two supported scenarios are StickyHeaderListView -> Header (stickyContainer) -> sticky, * 1. The two supported scenarios are StickyHeaderListView -> Header (stickyContainer) -> sticky,
@@ -41,7 +41,7 @@ import android.widget.ListView;
* 3. If fitsSystemWindows is true, then this will offset the sticking position by the height of * 3. If fitsSystemWindows is true, then this will offset the sticking position by the height of
* the system decorations at the top of the screen. * the system decorations at the top of the screen.
* *
* @see com.google.android.setupwizard.util.SetupWizardHeader * @see SetupWizardIllustration
* @see com.google.android.setupwizard.util.StickyHeaderScrollView * @see com.google.android.setupwizard.util.StickyHeaderScrollView
* *
* Copied from com.google.android.setupwizard.util.StickyHeaderListView * Copied from com.google.android.setupwizard.util.StickyHeaderListView