Merge "UI updates for Done Bar sample" into jb-mr2-dev
diff --git a/ui/actionbar/DoneBar/AndroidManifest.xml b/ui/actionbar/DoneBar/AndroidManifest.xml
index 5536a9b..cce4d5e 100755
--- a/ui/actionbar/DoneBar/AndroidManifest.xml
+++ b/ui/actionbar/DoneBar/AndroidManifest.xml
@@ -26,7 +26,7 @@
android:theme="@style/Theme.Sample"
android:allowBackup="true">
- <activity android:name=".MainActivity"
+ <activity android:name=".SampleDashboardActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/ui/actionbar/DoneBar/res/drawable-xhdpi/sample_dashboard_item_background.9.png b/ui/actionbar/DoneBar/res/drawable-xhdpi/sample_dashboard_item_background.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/ui/actionbar/DoneBar/res/drawable-xhdpi/sample_dashboard_item_background.9.png
Binary files differ
diff --git a/ui/actionbar/DoneBar/res/layout/activity_main.xml b/ui/actionbar/DoneBar/res/layout/activity_main.xml
deleted file mode 100755
index e342ca3..0000000
--- a/ui/actionbar/DoneBar/res/layout/activity_main.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<!--
- Copyright 2013 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.
- -->
-
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <LinearLayout style="@style/Widget.SampleContentContainer"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
-
- <TextView style="@style/Widget.SampleMessage"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/intro_message" />
-
- <Button style="@style/Widget.SampleButton"
- android:id="@+id/done_bar_link"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/margin_large"
- android:layout_marginBottom="@dimen/margin_small"
- android:text="@string/done_bar_title" />
-
- <TextView style="@style/Widget.SampleMessage"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/done_bar_description" />
-
- <Button style="@style/Widget.SampleButton"
- android:id="@+id/done_button_link"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/margin_large"
- android:layout_marginBottom="@dimen/margin_small"
- android:text="@string/done_button_title" />
-
- <TextView style="@style/Widget.SampleMessage"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/done_button_description" />
-
- </LinearLayout>
-</ScrollView>
diff --git a/ui/actionbar/DoneBar/res/layout/activity_sample_dashboard.xml b/ui/actionbar/DoneBar/res/layout/activity_sample_dashboard.xml
new file mode 100755
index 0000000..88cdb80
--- /dev/null
+++ b/ui/actionbar/DoneBar/res/layout/activity_sample_dashboard.xml
@@ -0,0 +1,41 @@
+<!--
+ Copyright 2013 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="match_parent"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+
+ <GridView android:id="@android:id/list"
+ style="@style/Widget.SampleDashboard.Grid"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:paddingLeft="@dimen/horizontal_page_margin"
+ android:paddingRight="@dimen/horizontal_page_margin"
+ android:paddingBottom="@dimen/vertical_page_margin"
+ android:scrollbarStyle="outsideOverlay" />
+
+</LinearLayout>
diff --git a/ui/actionbar/DoneBar/res/layout/sample_dashboard_item.xml b/ui/actionbar/DoneBar/res/layout/sample_dashboard_item.xml
new file mode 100644
index 0000000..38987ee
--- /dev/null
+++ b/ui/actionbar/DoneBar/res/layout/sample_dashboard_item.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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"
+ style="@style/Widget.SampleDashboard.Item"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <TextView android:id="@android:id/text1"
+ style="@style/Widget.SampleDashboard.Item.Title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ <TextView android:id="@android:id/text2"
+ style="@style/Widget.SampleDashboard.Item.Description"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+</LinearLayout>
diff --git a/ui/actionbar/DoneBar/res/values-sw600dp/dimens.xml b/ui/actionbar/DoneBar/res/values-sw600dp/dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/ui/actionbar/DoneBar/res/values-sw600dp/dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/ui/actionbar/DoneBar/res/values-sw600dp/styles.xml b/ui/actionbar/DoneBar/res/values-sw600dp/styles.xml
index 8b7fa45..401e7aa 100644
--- a/ui/actionbar/DoneBar/res/values-sw600dp/styles.xml
+++ b/ui/actionbar/DoneBar/res/values-sw600dp/styles.xml
@@ -16,24 +16,9 @@
<resources>
- <style name="Widget.SampleContentContainer">
- <item name="android:paddingTop">@dimen/margin_medium</item>
- <item name="android:paddingBottom">@dimen/margin_medium</item>
- <item name="android:paddingLeft">@dimen/margin_huge</item>
- <item name="android:paddingRight">@dimen/margin_huge</item>
- </style>
-
<style name="Widget.SampleMessage">
<item name="android:textAppearance">?android:textAppearanceLarge</item>
<item name="android:lineSpacingMultiplier">1.2</item>
</style>
- <style name="Widget.SampleButton" parent="android:Widget.Holo.Light.Button">
- <item name="android:textAppearance">?android:textAppearanceLarge</item>
- <item name="android:paddingTop">@dimen/margin_medium</item>
- <item name="android:paddingBottom">@dimen/margin_medium</item>
- <item name="android:paddingLeft">@dimen/margin_large</item>
- <item name="android:paddingRight">@dimen/margin_large</item>
- </style>
-
</resources>
diff --git a/ui/actionbar/DoneBar/res/values/dimens.xml b/ui/actionbar/DoneBar/res/values/dimens.xml
index 952c220..39e710b 100644
--- a/ui/actionbar/DoneBar/res/values/dimens.xml
+++ b/ui/actionbar/DoneBar/res/values/dimens.xml
@@ -24,4 +24,9 @@
<dimen name="margin_large">32dp</dimen>
<dimen name="margin_huge">64dp</dimen>
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
</resources>
diff --git a/ui/actionbar/DoneBar/res/values/styles.xml b/ui/actionbar/DoneBar/res/values/styles.xml
index 80895ef..f3841bd 100644
--- a/ui/actionbar/DoneBar/res/values/styles.xml
+++ b/ui/actionbar/DoneBar/res/values/styles.xml
@@ -27,7 +27,10 @@
<style name="Widget" />
<style name="Widget.SampleContentContainer">
- <item name="android:padding">@dimen/margin_medium</item>
+ <item name="android:paddingTop">@dimen/vertical_page_margin</item>
+ <item name="android:paddingBottom">@dimen/vertical_page_margin</item>
+ <item name="android:paddingLeft">@dimen/horizontal_page_margin</item>
+ <item name="android:paddingRight">@dimen/horizontal_page_margin</item>
</style>
<style name="Widget.SampleMessage">
@@ -35,8 +38,34 @@
<item name="android:lineSpacingMultiplier">1.1</item>
</style>
- <style name="Widget.SampleButton" parent="android:Widget.Holo.Light.Button">
- <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <style name="Widget.SampleDashboard.Grid" parent="Widget">
+ <item name="android:stretchMode">columnWidth</item>
+ <item name="android:columnWidth">200dp</item>
+ <item name="android:numColumns">auto_fit</item>
+ <item name="android:drawSelectorOnTop">true</item>
+ <item name="android:horizontalSpacing">@dimen/margin_medium</item>
+ <item name="android:verticalSpacing">@dimen/margin_medium</item>
+ </style>
+
+ <style name="Widget.SampleDashboard.Item" parent="Widget">
+ <item name="android:background">@drawable/sample_dashboard_item_background</item>
+ <item name="android:paddingTop">@dimen/margin_small</item>
+ <item name="android:paddingLeft">@dimen/margin_medium</item>
+ <item name="android:paddingRight">@dimen/margin_medium</item>
+ <item name="android:paddingBottom">@dimen/margin_medium</item>
+ </style>
+
+ <style name="Widget.SampleDashboard.Item.Title" parent="Widget">
+ <item name="android:layout_marginBottom">@dimen/margin_tiny</item>
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:textColor">#09c</item>
+ <item name="android:textStyle">bold</item>
+ <item name="android:textSize">24sp</item>
+ </style>
+
+ <style name="Widget.SampleDashboard.Item.Description" parent="Widget">
+ <item name="android:textAppearance">?android:textAppearanceSmall</item>
+ <item name="android:fontFamily">sans-serif-light</item>
</style>
</resources>
diff --git a/ui/actionbar/DoneBar/src/com/example/android/donebar/DoneBarActivity.java b/ui/actionbar/DoneBar/src/com/example/android/donebar/DoneBarActivity.java
old mode 100644
new mode 100755
diff --git a/ui/actionbar/DoneBar/src/com/example/android/donebar/DoneButtonActivity.java b/ui/actionbar/DoneBar/src/com/example/android/donebar/DoneButtonActivity.java
old mode 100644
new mode 100755
diff --git a/ui/actionbar/DoneBar/src/com/example/android/donebar/MainActivity.java b/ui/actionbar/DoneBar/src/com/example/android/donebar/MainActivity.java
deleted file mode 100755
index ff188df..0000000
--- a/ui/actionbar/DoneBar/src/com/example/android/donebar/MainActivity.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2013 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.example.android.donebar;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-
-/**
- * A simple launcher activity describing the alternative action bar presentations and allowing the
- * user to navigate to a demo of each.
- */
-public class MainActivity extends Activity {
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- findViewById(R.id.done_bar_link).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(MainActivity.this, DoneBarActivity.class));
- }
- });
-
- findViewById(R.id.done_button_link).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(MainActivity.this, DoneButtonActivity.class));
- }
- });
- }
-}
diff --git a/ui/actionbar/DoneBar/src/com/example/android/donebar/SampleDashboardActivity.java b/ui/actionbar/DoneBar/src/com/example/android/donebar/SampleDashboardActivity.java
new file mode 100755
index 0000000..e86e6fc
--- /dev/null
+++ b/ui/actionbar/DoneBar/src/com/example/android/donebar/SampleDashboardActivity.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2013 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.example.android.donebar;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.GridView;
+import android.widget.TextView;
+
+/**
+ * A simple launcher activity offering access to the individual samples in this project.
+ */
+public class SampleDashboardActivity extends Activity implements AdapterView.OnItemClickListener {
+ /**
+ * The collection of samples that will be used to populate the 'dashboard' grid.
+ */
+ private Sample[] mSamples;
+
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_sample_dashboard);
+
+ // Prepare list of samples in this dashboard.
+ mSamples = new Sample[]{
+ new Sample(R.string.done_bar_title, R.string.done_bar_description,
+ DoneBarActivity.class),
+ new Sample(R.string.done_button_title, R.string.done_button_description,
+ DoneButtonActivity.class),
+ };
+
+ // Use the custom adapter in the GridView and hook up a click listener to handle
+ // selection of individual samples.
+ GridView gridView = (GridView) findViewById(android.R.id.list);
+ gridView.setAdapter(new SampleAdapter());
+ gridView.setOnItemClickListener(this);
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> container, View view, int position, long id) {
+ // A sample was selected in the dashboard; open it.
+ startActivity(mSamples[position].intent);
+ }
+
+ /**
+ * A custom array-based adapter, designed for use with a {@link GridView}.
+ */
+ private class SampleAdapter extends BaseAdapter {
+ @Override
+ public int getCount() {
+ return mSamples.length;
+ }
+
+ @Override
+ public Sample getItem(int position) {
+ return mSamples[position];
+ }
+
+ @Override
+ public long getItemId(int position) {
+ // The title string ID should be unique per sample, so use it as an ID.
+ return mSamples[position].titleResId;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup container) {
+ if (convertView == null) {
+ // If there was no re-usable view that can be simply repopulated, create
+ // a new root view for this grid item.
+ convertView = getLayoutInflater().inflate(
+ R.layout.sample_dashboard_item, container, false);
+ }
+
+ // Populate the view's children with real data about this sample.
+ ((TextView) convertView.findViewById(android.R.id.text1)).setText(
+ mSamples[position].titleResId);
+ ((TextView) convertView.findViewById(android.R.id.text2)).setText(
+ mSamples[position].descriptionResId);
+ return convertView;
+ }
+ }
+
+ /**
+ * A simple class that stores information about a sample: a title, description, and
+ * the intent to call
+ * {@link android.content.Context#startActivity(android.content.Intent) startActivity}
+ * with in order to open the sample.
+ */
+ private class Sample {
+ int titleResId;
+ int descriptionResId;
+ Intent intent;
+
+ /**
+ * Instantiate a new sample object with a title, description, and intent.
+ */
+ private Sample(int titleResId, int descriptionResId, Intent intent) {
+ this.intent = intent;
+ this.titleResId = titleResId;
+ this.descriptionResId = descriptionResId;
+ }
+
+ /**
+ * Instantiate a new sample object with a title, description, and {@link Activity}
+ * subclass. An intent will automatically be created for the given activity.
+ */
+ private Sample(int titleResId, int descriptionResId,
+ Class<? extends Activity> activityClass) {
+ this(titleResId, descriptionResId,
+ new Intent(SampleDashboardActivity.this, activityClass));
+ }
+ }
+}