diff options
author | Kirill Grouchnikov <kirillg@google.com> | 2015-10-28 21:04:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-10-28 21:04:34 +0000 |
commit | d4035382f2ef4bb3a8d79c55b829d132041d4f73 (patch) | |
tree | b3ea43082ca514e85d37ff285bdb7967353cca3a | |
parent | 23ee659cba7f4375d2beb3f39289937f425b2666 (diff) | |
parent | afeff426a936f862f3fa816b4a57e0e82f304a37 (diff) | |
download | android_development-d4035382f2ef4bb3a8d79c55b829d132041d4f73.tar.gz android_development-d4035382f2ef4bb3a8d79c55b829d132041d4f73.tar.bz2 android_development-d4035382f2ef4bb3a8d79c55b829d132041d4f73.zip |
Merge "Test app for ViewPager." into mnc-ub-dev
5 files changed, 201 insertions, 0 deletions
diff --git a/samples/Support4Demos/AndroidManifest.xml b/samples/Support4Demos/AndroidManifest.xml index d3f0b8522..9d4f69d79 100644 --- a/samples/Support4Demos/AndroidManifest.xml +++ b/samples/Support4Demos/AndroidManifest.xml @@ -359,6 +359,14 @@ </intent-filter> </activity> + <activity android:name=".view.ViewPagerActivity" + android:label="@string/view_pager_support"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv4.SUPPORT4_SAMPLE_CODE" /> + </intent-filter> + </activity> + <activity android:name=".graphics.RoundedBitmapDrawableActivity" android:label="Graphics/RoundedBitmapDrawable"> <intent-filter> diff --git a/samples/Support4Demos/res/layout/view_pager_sample.xml b/samples/Support4Demos/res/layout/view_pager_sample.xml new file mode 100644 index 000000000..1c6d23829 --- /dev/null +++ b/samples/Support4Demos/res/layout/view_pager_sample.xml @@ -0,0 +1,57 @@ +<?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="match_parent" + android:orientation="vertical"> + <android.support.v4.view.ViewPager + android:id="@+id/view_pager" + android:layout_width="match_parent" + android:layout_height="0dip" + android:layout_weight="1"> + <android.support.v4.view.PagerTabStrip + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="top"/> + </android.support.v4.view.ViewPager> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:gravity="end"> + <CheckBox + android:id="@+id/view_pager_smooth_scroll" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:checked="true" + android:text="@string/view_pager_smooth_scroll"/> + <Button + android:id="@+id/view_pager_switch_tabs_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="12dip" + android:text="@string/view_pager_switch_tabs"/> + <Button + android:id="@+id/view_pager_double_switch_tabs_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="12dip" + android:text="@string/view_pager_double_switch_tabs"/> + </LinearLayout> +</LinearLayout> diff --git a/samples/Support4Demos/res/layout/view_pager_tab.xml b/samples/Support4Demos/res/layout/view_pager_tab.xml new file mode 100644 index 000000000..1d0bf31ae --- /dev/null +++ b/samples/Support4Demos/res/layout/view_pager_tab.xml @@ -0,0 +1,21 @@ +<?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. +--> + +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:textSize="32sp" + android:gravity="center"/> diff --git a/samples/Support4Demos/res/values/strings.xml b/samples/Support4Demos/res/values/strings.xml index 2157be187..8917c667d 100644 --- a/samples/Support4Demos/res/values/strings.xml +++ b/samples/Support4Demos/res/values/strings.xml @@ -195,4 +195,9 @@ <string name="drawable_compat_color_tint">Color tint</string> <string name="drawable_compat_color_list_tint">Color state list</string> + <!-- ViewPager --> + <string name="view_pager_support">View/View pager</string> + <string name="view_pager_smooth_scroll">Smooth scroll</string> + <string name="view_pager_switch_tabs">Switch tabs</string> + <string name="view_pager_double_switch_tabs">Double-switch tabs</string> </resources> diff --git a/samples/Support4Demos/src/com/example/android/supportv4/view/ViewPagerActivity.java b/samples/Support4Demos/src/com/example/android/supportv4/view/ViewPagerActivity.java new file mode 100644 index 000000000..e50cc610a --- /dev/null +++ b/samples/Support4Demos/src/com/example/android/supportv4/view/ViewPagerActivity.java @@ -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.example.android.supportv4.view; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.view.ViewPager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.TextView; +import android.widget.Toast; +import com.example.android.supportv4.R; + +import java.lang.Override; +import java.lang.Runnable; + +public class ViewPagerActivity extends FragmentActivity { + private static int[] PAGE_COLORS = { 0xFF700000, 0xFF500020, 0xFF300030, 0xFF200050, + 0xFF000070}; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.view_pager_sample); + + final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager); + viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) { + @Override + public int getCount() { + return PAGE_COLORS.length; + } + + @Override + public CharSequence getPageTitle(int position) { + return "Page " + position; + } + + @Override + public Fragment getItem(int position) { + Fragment fragment = new DemoObjectFragment(); + Bundle args = new Bundle(); + args.putInt(DemoObjectFragment.ARG_INDEX, position); + fragment.setArguments(args); + return fragment; + } + }); + + final CheckBox smoothScroll = (CheckBox) findViewById(R.id.view_pager_smooth_scroll); + + Button switchTabsButton = (Button) findViewById(R.id.view_pager_switch_tabs_button); + switchTabsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + viewPager.setCurrentItem(2, smoothScroll.isChecked()); + Toast.makeText(view.getContext(), "Current item = " + viewPager.getCurrentItem(), + Toast.LENGTH_SHORT).show(); + } + }); + + Button doubleSwitchTabsButton = + (Button) findViewById(R.id.view_pager_double_switch_tabs_button); + doubleSwitchTabsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + viewPager.setCurrentItem(0, smoothScroll.isChecked()); + viewPager.setCurrentItem(2, smoothScroll.isChecked()); + Toast.makeText(view.getContext(), "Current item = " + viewPager.getCurrentItem(), + Toast.LENGTH_SHORT).show(); + } + }); + } + + public static class DemoObjectFragment extends Fragment { + public static final String ARG_INDEX = "index"; + + @Override + public View onCreateView(LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + // The last two arguments ensure LayoutParams are inflated + // properly. + View rootView = inflater.inflate(R.layout.view_pager_tab, container, false); + Bundle args = getArguments(); + int position = args.getInt(ARG_INDEX); + rootView.setBackgroundColor(PAGE_COLORS[position]); + ((TextView) rootView).setText(Integer.toString(position)); + return rootView; + } + } +} |