More improvements to pager.
Also another size step for the resource screen size sample.
Change-Id: I9e8b63d2fc9a0ceab7b003f7bd75218b78311ed6
diff --git a/samples/ApiDemos/res/layout-h974dp/resources_height.xml b/samples/ApiDemos/res/layout-h974dp/resources_height.xml
new file mode 100644
index 0000000..5eb120d
--- /dev/null
+++ b/samples/ApiDemos/res/layout-h974dp/resources_height.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+
+<!-- Part of resources_width_and_height that varies based on height. -->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+ <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"
+ android:orientation="vertical">
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#8000ff00">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#80ff0000">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#8000ff00">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#80ff0000">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#8000ff00">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#80ff0000">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#8000ff00">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#80ff0000">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#8000ff00">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#80ff0000">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#8000ff00">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ <FrameLayout android:layout_width="match_parent" android:layout_height="0px"
+ android:layout_weight="1" android:padding="4dp"
+ android:background="#80ff0000">
+ <include layout="@layout/resources_width" />
+ </FrameLayout>
+ </LinearLayout>
+</merge>
diff --git a/samples/ApiDemos/res/layout-w1024dp/resources_width.xml b/samples/ApiDemos/res/layout-w1024dp/resources_width.xml
new file mode 100644
index 0000000..05ea7ba
--- /dev/null
+++ b/samples/ApiDemos/res/layout-w1024dp/resources_width.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+
+<!-- Part of resources_width_and_height that varies based on width. -->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+ <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"
+ android:orientation="horizontal">
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#1">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#2">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#3">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#4">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#5">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#6">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#7">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#8">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#9">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#10">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#11">
+ </TextView>
+ <TextView android:layout_width="0px" android:layout_height="match_parent"
+ android:layout_weight="1" android:gravity="center"
+ android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
+ android:background="#800000ff" android:text="w1024dp Width\n#12">
+ </TextView>
+ </LinearLayout>
+</merge>
diff --git a/samples/ApiDemos/res/layout/fragment_pager.xml b/samples/ApiDemos/res/layout/fragment_pager_support.xml
similarity index 65%
rename from samples/ApiDemos/res/layout/fragment_pager.xml
rename to samples/ApiDemos/res/layout/fragment_pager_support.xml
index 3867f46..a082e2e 100644
--- a/samples/ApiDemos/res/layout/fragment_pager.xml
+++ b/samples/ApiDemos/res/layout/fragment_pager_support.xml
@@ -28,10 +28,17 @@
android:layout_weight="1">
</android.support.v4.app.FragmentPager>
- <Button android:id="@+id/new_fragment"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_weight="0"
- android:text="@string/new_fragment">
- <requestFocus />
- </Button>
+ <LinearLayout android:orientation="horizontal"
+ android:gravity="center" android:measureWithLargestChild="true"
+ android:layout_width="match_parent" android:layout_height="wrap_content"
+ android:layout_weight="0">
+ <Button android:id="@+id/goto_first"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/first">
+ </Button>
+ <Button android:id="@+id/goto_last"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/last">
+ </Button>
+ </LinearLayout>
</LinearLayout>
diff --git a/samples/ApiDemos/res/layout/fragment_pager_list.xml b/samples/ApiDemos/res/layout/fragment_pager_support_list.xml
similarity index 100%
rename from samples/ApiDemos/res/layout/fragment_pager_list.xml
rename to samples/ApiDemos/res/layout/fragment_pager_support_list.xml
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index d7858f0..024975a 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -175,6 +175,8 @@
<string name="fragment_stack_support">Support/App/Fragment/Stack</string>
<string name="fragment_pager_support">Support/App/Fragment/Pager</string>
+ <string name="first">First</string>
+ <string name="last">Last</string>
<string name="loader_cursor">App/Loader/Cursor</string>
diff --git a/samples/ApiDemos/src/com/example/android/apis/support/app/FragmentPagerSupport.java b/samples/ApiDemos/src/com/example/android/apis/support/app/FragmentPagerSupport.java
index 46d29ac..c78c6d3 100644
--- a/samples/ApiDemos/src/com/example/android/apis/support/app/FragmentPagerSupport.java
+++ b/samples/ApiDemos/src/com/example/android/apis/support/app/FragmentPagerSupport.java
@@ -40,26 +40,28 @@
static final int NUM_ITEMS = 10;
FragmentPager mPager;
- int mCurPos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.fragment_pager);
+ setContentView(R.layout.fragment_pager_support);
mPager = (FragmentPager)findViewById(R.id.pager);
mPager.setAdapter(this);
+ Button button;
+
// Watch for button clicks.
- Button button = (Button)findViewById(R.id.new_fragment);
+ button = (Button)findViewById(R.id.goto_first);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- mCurPos++;
- if (mCurPos < NUM_ITEMS) {
- mPager.setCurrentItem(mCurPos);
- } else {
- mCurPos--;
- }
+ mPager.setCurrentItem(0);
+ }
+ });
+ button = (Button)findViewById(R.id.goto_last);
+ button.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ mPager.setCurrentItem(NUM_ITEMS-1);
}
});
}
@@ -108,7 +110,7 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
+ View v = inflater.inflate(R.layout.fragment_pager_support_list, container, false);
View tv = v.findViewById(R.id.text);
((TextView)tv).setText("Fragment #" + mNum);
return v;