[SuwLib] Implement GlifListLayout
Bug: 25726515 Change-Id: I192f33635e9919c02adfdb2c9afa1652dd84aab2
This commit is contained in:
parent
fce4cf6161
commit
e15b8a2489
36
library/main/res/layout/suw_glif_header.xml
Normal file
36
library/main/res/layout/suw_glif_header.xml
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 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:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/suw_layout_icon"
|
||||
style="@style/SuwGlifIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@null" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/suw_layout_title"
|
||||
style="@style/SuwGlifHeaderTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
24
library/main/res/layout/suw_glif_list_template.xml
Normal file
24
library/main/res/layout/suw_glif_list_template.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 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.
|
||||
-->
|
||||
|
||||
<com.android.setupwizardlib.view.StickyHeaderListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:suwHeader="@layout/suw_glif_header" />
|
|
@ -27,18 +27,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/suw_layout_icon"
|
||||
style="@style/SuwGlifIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@null" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/suw_layout_title"
|
||||
style="@style/SuwGlifHeaderTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<include layout="@layout/suw_glif_header" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/suw_layout_content"
|
||||
|
|
|
@ -44,6 +44,10 @@
|
|||
<attr name="suwHeaderText" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="SuwGlifListLayout">
|
||||
<attr name="android:entries" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="SuwSetupWizardLayout">
|
||||
<attr name="suwBackground" format="color|reference" />
|
||||
<attr name="suwBackgroundTile" format="color|reference" />
|
||||
|
|
110
library/main/src/com/android/setupwizardlib/GlifListLayout.java
Normal file
110
library/main/src/com/android/setupwizardlib/GlifListLayout.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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.
|
||||
*/
|
||||
|
||||
package com.android.setupwizardlib;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.android.setupwizardlib.items.ItemAdapter;
|
||||
import com.android.setupwizardlib.items.ItemGroup;
|
||||
import com.android.setupwizardlib.items.ItemInflater;
|
||||
|
||||
/**
|
||||
* A GLIF themed layout with a ListView. {@code android:entries} can also be used to specify an
|
||||
* {@link com.android.setupwizardlib.items.ItemHierarchy} to be used with this layout in XML.
|
||||
*/
|
||||
public class GlifListLayout extends GlifLayout {
|
||||
|
||||
private static final String TAG = "GlifListLayout";
|
||||
private ListView mListView;
|
||||
|
||||
public GlifListLayout(Context context) {
|
||||
this(context, 0, 0);
|
||||
}
|
||||
|
||||
public GlifListLayout(Context context, int template) {
|
||||
this(context, template, 0);
|
||||
}
|
||||
|
||||
public GlifListLayout(Context context, int template, int containerId) {
|
||||
super(context, template, containerId);
|
||||
init(context, null, 0);
|
||||
}
|
||||
|
||||
public GlifListLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
public GlifListLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuwGlifListLayout,
|
||||
defStyleAttr, 0);
|
||||
final int xml = a.getResourceId(R.styleable.SuwGlifListLayout_android_entries, 0);
|
||||
if (xml != 0) {
|
||||
final ItemGroup inflated = (ItemGroup) new ItemInflater(context).inflate(xml);
|
||||
setAdapter(new ItemAdapter(inflated));
|
||||
}
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onInflateTemplate(LayoutInflater inflater, int template) {
|
||||
if (template == 0) {
|
||||
template = R.layout.suw_glif_list_template;
|
||||
}
|
||||
return super.onInflateTemplate(inflater, template);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewGroup findContainer(int containerId) {
|
||||
if (containerId == 0) {
|
||||
containerId = android.R.id.list;
|
||||
}
|
||||
return super.findContainer(containerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTemplateInflated() {
|
||||
mListView = (ListView) findViewById(android.R.id.list);
|
||||
}
|
||||
|
||||
public ListView getListView() {
|
||||
return mListView;
|
||||
}
|
||||
|
||||
public void setAdapter(ListAdapter adapter) {
|
||||
getListView().setAdapter(adapter);
|
||||
}
|
||||
|
||||
public ListAdapter getAdapter() {
|
||||
return getListView().getAdapter();
|
||||
}
|
||||
}
|
20
library/test/res/layout/test_glif_list_layout.xml
Normal file
20
library/test/res/layout/test_glif_list_layout.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!--
|
||||
Copyright (C) 2015 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.
|
||||
-->
|
||||
|
||||
<com.android.setupwizardlib.GlifListLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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.
|
||||
*/
|
||||
|
||||
package com.android.setupwizardlib.test;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.HeaderViewListAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.setupwizardlib.GlifListLayout;
|
||||
|
||||
public class GlifListLayoutTest extends InstrumentationTestCase {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mContext = new ContextThemeWrapper(getInstrumentation().getContext(),
|
||||
R.style.SuwThemeGlif_Light);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testDefaultTemplate() {
|
||||
GlifListLayout layout = new GlifListLayout(mContext);
|
||||
assertListTemplateInflated(layout);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAddView() {
|
||||
GlifListLayout layout = new GlifListLayout(mContext);
|
||||
TextView tv = new TextView(mContext);
|
||||
try {
|
||||
layout.addView(tv);
|
||||
fail("Adding view to ListLayout should throw");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// Expected exception
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testInflateFromXml() {
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
GlifListLayout layout = (GlifListLayout)
|
||||
inflater.inflate(R.layout.test_glif_list_layout, null);
|
||||
assertListTemplateInflated(layout);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetListView() {
|
||||
GlifListLayout layout = new GlifListLayout(mContext);
|
||||
assertListTemplateInflated(layout);
|
||||
assertNotNull("getListView should not be null", layout.getListView());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAdapter() {
|
||||
GlifListLayout layout = new GlifListLayout(mContext);
|
||||
assertListTemplateInflated(layout);
|
||||
|
||||
final ArrayAdapter<String> adapter =
|
||||
new ArrayAdapter<>(mContext, android.R.layout.simple_list_item_1);
|
||||
adapter.add("Abracadabra");
|
||||
layout.setAdapter(adapter);
|
||||
|
||||
final ListAdapter gotAdapter = layout.getAdapter();
|
||||
if (gotAdapter instanceof HeaderViewListAdapter) {
|
||||
assertSame("Adapter got from GlifListLayout should be same as set",
|
||||
adapter, ((HeaderViewListAdapter) gotAdapter).getWrappedAdapter());
|
||||
} else {
|
||||
assertSame("Adapter got from GlifListLayout should be same as set",
|
||||
adapter, gotAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertListTemplateInflated(GlifListLayout layout) {
|
||||
View title = layout.findViewById(R.id.suw_layout_title);
|
||||
assertNotNull("@id/suw_layout_title should not be null", title);
|
||||
|
||||
View icon = layout.findViewById(R.id.suw_layout_icon);
|
||||
assertNotNull("@id/suw_layout_icon should not be null", icon);
|
||||
|
||||
View listView = layout.findViewById(android.R.id.list);
|
||||
assertTrue("@android:id/list should be a ListView", listView instanceof ListView);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue