diff options
Diffstat (limited to 'samples/Support7Demos')
46 files changed, 1607 insertions, 116 deletions
diff --git a/samples/Support7Demos/Android.mk b/samples/Support7Demos/Android.mk index 0d2fadb0c..e3d54d083 100644 --- a/samples/Support7Demos/Android.mk +++ b/samples/Support7Demos/Android.mk @@ -29,14 +29,20 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ android-support-v7-mediarouter \ android-support-v7-palette \ android-support-v7-recyclerview \ - android-support-v7-cardview + android-support-v7-cardview \ + android-support-design LOCAL_RESOURCE_DIR = \ $(LOCAL_PATH)/res \ frameworks/support/v7/appcompat/res \ frameworks/support/v7/gridlayout/res \ frameworks/support/v7/mediarouter/res \ - frameworks/support/v7/cardview/res + frameworks/support/v7/cardview/res \ + frameworks/support/design/res LOCAL_AAPT_FLAGS := \ --auto-add-overlay \ - --extra-packages android.support.v7.cardview:android.support.v7.appcompat:android.support.v7.gridlayout:android.support.v7.mediarouter + --extra-packages android.support.v7.appcompat \ + --extra-packages android.support.v7.cardview \ + --extra-packages android.support.v7.gridlayout \ + --extra-packages android.support.v7.mediarouter \ + --extra-packages android.support.design include $(BUILD_PACKAGE) diff --git a/samples/Support7Demos/AndroidManifest.xml b/samples/Support7Demos/AndroidManifest.xml index 1d087a470..a84dc225f 100644 --- a/samples/Support7Demos/AndroidManifest.xml +++ b/samples/Support7Demos/AndroidManifest.xml @@ -204,6 +204,51 @@ </intent-filter> </activity> + <activity android:name=".app.ActionBarPreferences" + android:label="@string/action_bar_preferences" + android:theme="@style/Theme.AppCompat"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + + <activity android:name=".app.ActionBarActionMode" + android:label="@string/action_bar_action_mode" + android:theme="@style/Theme.Custom"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + + <activity android:name=".app.AppCompatWidgetsButtons" + android:label="@string/appcompat_widgets_buttons" + android:theme="@style/Theme.AppCompat.Light.DarkActionBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + + <activity android:name=".app.AppCompatWidgetsSpinners" + android:label="@string/appcompat_widgets_spinners" + android:theme="@style/Theme.AppCompat.Light.DarkActionBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + + <activity android:name=".app.AppCompatWidgetsTextInput" + android:label="@string/appcompat_widgets_text_input" + android:theme="@style/Theme.AppCompat.Light.DarkActionBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + <activity android:name=".app.ToolbarUsage" android:label="@string/toolbar_usage" android:theme="@style/Theme.Custom.NoActionBar"> @@ -235,6 +280,33 @@ </intent-filter> </activity> + <activity android:name=".app.ToolbarActionMode" + android:label="@string/toolbar_action_mode" + android:theme="@style/Theme.AppCompat.Light.NoActionBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + + <activity android:name=".app.DialogUsage" + android:label="@string/dialog_usage" + android:theme="@style/Theme.AppCompat.Light"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + + <activity android:name=".app.AlertDialogUsage" + android:label="@string/alert_dialog_usage" + android:theme="@style/Theme.AppCompat.Light"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + <provider android:name=".app.RecentSuggestionsProvider" android:authorities="com.example.android.supportv7.RecentSuggestionsProvider" /> @@ -266,6 +338,16 @@ </intent-filter> </activity> + <activity android:name=".util.SortedListActivity" + android:label="@string/sorted_list_activity" + android:windowSoftInputMode="adjustResize" + android:theme="@style/Theme.AppCompat"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + <activity android:name=".widget.GridLayoutManagerActivity" android:label="@string/grid_layout_manager" android:theme="@style/Theme.AppCompat"> diff --git a/samples/Support7Demos/res/color/card_selector.xml b/samples/Support7Demos/res/color/card_selector.xml new file mode 100644 index 000000000..48b35ee1d --- /dev/null +++ b/samples/Support7Demos/res/color/card_selector.xml @@ -0,0 +1,20 @@ +<?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. +--> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_focused="true" android:color="@color/card_tropical"/> + <item android:state_pressed="true" android:color="@color/card_tropical"/> + <item android:color="@color/card_yellow"/> +</selector>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/action_bar_action_mode.xml b/samples/Support7Demos/res/layout/action_bar_action_mode.xml new file mode 100644 index 000000000..d498fda95 --- /dev/null +++ b/samples/Support7Demos/res/layout/action_bar_action_mode.xml @@ -0,0 +1,27 @@ +<?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. +--> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <Button + android:id="@+id/btn_start_action_mode" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="@string/start_action_mode"/> + +</FrameLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/activity_base_layout_manager.xml b/samples/Support7Demos/res/layout/activity_base_layout_manager.xml index f75018e6d..e56329e58 100644 --- a/samples/Support7Demos/res/layout/activity_base_layout_manager.xml +++ b/samples/Support7Demos/res/layout/activity_base_layout_manager.xml @@ -56,4 +56,5 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/recycler_view"/> + </LinearLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/activity_card_view.xml b/samples/Support7Demos/res/layout/activity_card_view.xml index 9b985f70e..3e1b9285e 100644 --- a/samples/Support7Demos/res/layout/activity_card_view.xml +++ b/samples/Support7Demos/res/layout/activity_card_view.xml @@ -132,46 +132,58 @@ android:text="@string/card_view_bg_color" android:layout_below="@id/alpha_label" android:layout_alignRight="@id/alpha_label"/> - <RadioGroup - android:id="@+id/select_bg_color_radio" - android:layout_toRightOf="@id/color_label" - android:layout_alignTop="@id/color_label" - android:layout_width="fill_parent" + + <ScrollView + android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" - android:layout_below="@id/alpha_seek_bar"> - <RadioButton - android:id="@+id/def" - android:layout_width="40dp" - android:layout_height="wrap_content" - android:background="@color/cardview_light_background" - android:checked="true"/> - <RadioButton - android:id="@+id/yellow" - android:layout_width="40dp" - android:layout_height="wrap_content" - android:background="@color/card_yellow"/> - <RadioButton - android:id="@+id/aquatic" - android:layout_width="40dp" - android:layout_height="wrap_content" - android:background="@color/card_aquatic"/> - <RadioButton - android:id="@+id/classic" - android:layout_width="40dp" - android:layout_height="wrap_content" - android:background="@color/card_classic"/> - <RadioButton - android:id="@+id/sunbrite" - android:layout_width="40dp" - android:layout_height="wrap_content" - android:background="@color/card_sunbrite"/> - <RadioButton - android:id="@+id/tropical" - android:layout_width="40dp" + android:layout_below="@id/alpha_seek_bar" + android:layout_toRightOf="@id/color_label" + android:layout_alignParentRight="true" + android:layout_alignTop="@id/color_label"> + + <RadioGroup + android:id="@+id/select_bg_color_radio" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@color/card_tropical"/> - </RadioGroup> + android:orientation="horizontal"> + <RadioButton + android:id="@+id/def" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@color/cardview_light_background" + android:checked="true"/> + <RadioButton + android:id="@+id/yellow" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@color/card_yellow"/> + <RadioButton + android:id="@+id/aquatic" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@color/card_aquatic"/> + <RadioButton + android:id="@+id/classic" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@color/card_classic"/> + <RadioButton + android:id="@+id/sunbrite" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@color/card_sunbrite"/> + <RadioButton + android:id="@+id/tropical" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@color/card_tropical"/> + <RadioButton + android:id="@+id/selector" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/cardview_background_selector_label"/> + </RadioGroup> + </ScrollView> <RadioGroup android:id="@+id/select_target_radio" android:layout_width="fill_parent" @@ -199,7 +211,9 @@ android:id="@+id/card_view" android:layout_width="wrap_content" android:layout_height="wrap_content" - card_view:cardElevation="10dp"> + card_view:cardElevation="10dp" + android:clickable="true" + android:layout_margin="8dp"> <TextView android:id="@+id/info_text" android:text="@string/card_view" diff --git a/samples/Support7Demos/res/layout/alert_dialog_usage.xml b/samples/Support7Demos/res/layout/alert_dialog_usage.xml new file mode 100644 index 000000000..9c6dee637 --- /dev/null +++ b/samples/Support7Demos/res/layout/alert_dialog_usage.xml @@ -0,0 +1,38 @@ +<?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:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:padding="16dp"> + + <Spinner + android:id="@+id/spinner_dialogs" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:entries="@array/alert_dialog_types" + android:layout_marginBottom="16dp"/> + + <Button + android:id="@+id/btn_show_dialog" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Show selected dialog" + android:gravity="center"/> + +</LinearLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/appcompat_widgets_buttons.xml b/samples/Support7Demos/res/layout/appcompat_widgets_buttons.xml new file mode 100644 index 000000000..aa0732893 --- /dev/null +++ b/samples/Support7Demos/res/layout/appcompat_widgets_buttons.xml @@ -0,0 +1,86 @@ +<?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. +--> + +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:padding="16dp"> + + <android.support.v7.widget.SwitchCompat + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="Switch"/> + + <CheckBox + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="CheckBox"/> + + <RadioGroup + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <RadioButton + android:id="@+id/radiobutton_1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="RadioButton"/> + + <RadioButton + android:id="@+id/radiobutton_2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="RadioButton"/> + + </RadioGroup> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button"/> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button (small)" + style="@style/Widget.AppCompat.Button.Small"/> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button (borderless)" + style="@style/Widget.AppCompat.Button.Borderless"/> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button (borderless + colored)" + style="@style/Widget.AppCompat.Button.Borderless.Colored"/> + + <RatingBar + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + + </LinearLayout> + +</ScrollView>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/appcompat_widgets_text_input.xml b/samples/Support7Demos/res/layout/appcompat_widgets_text_input.xml new file mode 100644 index 000000000..d242735e5 --- /dev/null +++ b/samples/Support7Demos/res/layout/appcompat_widgets_text_input.xml @@ -0,0 +1,51 @@ +<?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:padding="16dp"> + + <EditText + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:hint="EditText"/> + + <AutoCompleteTextView + android:id="@+id/widgets_autocompletetextview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:hint="AutoCompleteTextView"/> + + <MultiAutoCompleteTextView + android:id="@+id/widgets_multiautocompletetextview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:hint="MultiAutoCompleteTextView"/> + + <CheckedTextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="CheckedTextView" + android:checked="true" + android:checkMark="?android:listChoiceIndicatorMultiple"/> + +</LinearLayout> + + diff --git a/samples/Support7Demos/res/layout/appcompat_widgets_text_spinners.xml b/samples/Support7Demos/res/layout/appcompat_widgets_text_spinners.xml new file mode 100644 index 000000000..0a606328c --- /dev/null +++ b/samples/Support7Demos/res/layout/appcompat_widgets_text_spinners.xml @@ -0,0 +1,38 @@ +<?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:padding="16dp"> + + <Spinner + android:id="@+id/widgets_spinner" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + + <Spinner + android:id="@+id/widgets_spinner_underlined" + android:layout_width="match_parent" + android:layout_height="wrap_content" + style="@style/Widget.AppCompat.Spinner.Underlined"/> + +</LinearLayout> + + diff --git a/samples/Support7Demos/res/layout/dialog_content.xml b/samples/Support7Demos/res/layout/dialog_content.xml new file mode 100644 index 000000000..77349607d --- /dev/null +++ b/samples/Support7Demos/res/layout/dialog_content.xml @@ -0,0 +1,33 @@ +<?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:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/dialog_content"/> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/app_sample_code" /> + +</LinearLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/dialog_content_buttons.xml b/samples/Support7Demos/res/layout/dialog_content_buttons.xml new file mode 100644 index 000000000..ab697482c --- /dev/null +++ b/samples/Support7Demos/res/layout/dialog_content_buttons.xml @@ -0,0 +1,53 @@ +<?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:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/dialog_content"/> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/app_sample_code" /> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="right" + style="?attr/buttonBarStyle"> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@android:string/no" + style="?attr/buttonBarButtonStyle"/> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@android:string/ok" + style="?attr/buttonBarButtonStyle"/> + + </LinearLayout> + +</LinearLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/dialog_usage.xml b/samples/Support7Demos/res/layout/dialog_usage.xml new file mode 100644 index 000000000..4ef062668 --- /dev/null +++ b/samples/Support7Demos/res/layout/dialog_usage.xml @@ -0,0 +1,38 @@ +<?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:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:padding="16dp"> + + <Spinner + android:id="@+id/spinner_dialogs" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:entries="@array/dialog_types" + android:layout_marginBottom="16dp"/> + + <Button + android:id="@+id/btn_show_dialog" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Show selected dialog" + android:gravity="center"/> + +</LinearLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/sorted_list_activity.xml b/samples/Support7Demos/res/layout/sorted_list_activity.xml new file mode 100644 index 000000000..e20db0fb2 --- /dev/null +++ b/samples/Support7Demos/res/layout/sorted_list_activity.xml @@ -0,0 +1,33 @@ +<?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:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <EditText + android:id="@+id/new_item_text_view" + style="@style/SortedListItem" + android:imeOptions="actionDone" + android:singleLine="true" + android:hint="@string/add_new_item" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + + <android.support.v7.widget.RecyclerView android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/recycler_view"/> +</LinearLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/sorted_list_item_view.xml b/samples/Support7Demos/res/layout/sorted_list_item_view.xml new file mode 100644 index 000000000..cd476ab0e --- /dev/null +++ b/samples/Support7Demos/res/layout/sorted_list_item_view.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. +--> + +<CheckBox xmlns:android="http://schemas.android.com/apk/res/android" + style="@style/SortedListItem" + android:layout_width="match_parent" + android:layout_height="wrap_content"> +</CheckBox>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/toolbar_action_mode.xml b/samples/Support7Demos/res/layout/toolbar_action_mode.xml new file mode 100644 index 000000000..e2a1dd81e --- /dev/null +++ b/samples/Support7Demos/res/layout/toolbar_action_mode.xml @@ -0,0 +1,42 @@ +<?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.v7.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?actionBarSize" + android:background="?attr/colorPrimaryDark"/> + + <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="1"> + + <Button + android:id="@+id/btn_start_action_mode" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="@string/start_action_mode"/> + + </FrameLayout> + +</LinearLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/layout/toolbar_usage.xml b/samples/Support7Demos/res/layout/toolbar_usage.xml index b202e1f68..76944be10 100644 --- a/samples/Support7Demos/res/layout/toolbar_usage.xml +++ b/samples/Support7Demos/res/layout/toolbar_usage.xml @@ -27,7 +27,7 @@ android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimaryDark" - app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> <TextView diff --git a/samples/Support7Demos/res/values/arrays.xml b/samples/Support7Demos/res/values/arrays.xml index 8d658eb1e..c4d398725 100644 --- a/samples/Support7Demos/res/values/arrays.xml +++ b/samples/Support7Demos/res/values/arrays.xml @@ -28,4 +28,18 @@ <item>http://archive.org/download/Sintel/sintel-2048-stereo_512kb.mp4</item> <item>http://archive.org/download/Tears-of-Steel/tears_of_steel_720p.mp4</item> </string-array> + + <string-array name="dialog_types"> + <item>Simple</item> + <item>Simple with Action Bar</item> + <item>Button bar</item> + </string-array> + + <string-array name="alert_dialog_types"> + <item>Simple</item> + <item>Simple with buttons</item> + <item>List (single choice)</item> + <item>List (multi choice)</item> + </string-array> + </resources> diff --git a/samples/Support7Demos/res/values/strings.xml b/samples/Support7Demos/res/values/strings.xml index 4b3a28fd7..348014295 100644 --- a/samples/Support7Demos/res/values/strings.xml +++ b/samples/Support7Demos/res/values/strings.xml @@ -56,6 +56,11 @@ <string name="action_bar_settings_action_provider">AppCompat/Action Bar/Settings Action Provider</string> <string name="action_bar_settings_action_provider_no_handling">Handling in onOptionsItemSelected avoided</string> <string name="action_bar_with_navigation_drawer">AppCompat/Action Bar/Navigation Drawer Toggle</string> + <string name="action_bar_preferences">AppCompat/Action Bar/Preferences</string> + <string name="action_bar_action_mode">AppCompat/Action Bar/Action Mode</string> + <string name="appcompat_widgets_buttons">AppCompat/Widgets/Buttons</string> + <string name="appcompat_widgets_spinners">AppCompat/Widgets/Spinners</string> + <string name="appcompat_widgets_text_input">AppCompat/Widgets/Text Input</string> <string name="action_bar_search">Search</string> <string name="action_bar_add">Add</string> @@ -125,6 +130,12 @@ <string name="toolbar_usage">AppCompat/Toolbar/Toolbar as Action Bar</string> <string name="toolbar_display_options">AppCompat/Toolbar/Toolbar Display Options</string> <string name="toolbar_fragment_pager">AppCompat/Toolbar/Toolbar Fragment ViewPager</string> + <string name="toolbar_action_mode">AppCompat/Toolbar/Action Mode</string> + + <string name="dialog_usage">AppCompat/Dialog/Dialog Usage</string> + <string name="dialog_title">My great dialog</string> + <string name="dialog_content">My great dialog is great</string> + <string name="alert_dialog_usage">AppCompat/Dialog/AlertDialog Usage</string> <string name="sample_media_route_provider_remote">Remote Playback (Simulated)</string> <string name="sample_media_route_activity_local">Local Playback</string> @@ -158,9 +169,13 @@ <string name="card_view_sample_text">Sample text on right</string> <string name="card_view_resize_card_view">Resize CardView</string> <string name="card_view_resize_content">Resize Content</string> + <string name="cardview_background_selector_label">Selector</string> <string name="palette">Palette</string> <string name="palette_all_colors">Full color palette</string> <string name="search_hint">Search...</string> + <string name="sorted_list_activity">Sorted List</string> + <string name="add_new_item">Add New Item</string> + <string name="start_action_mode">Start Action Mode</string> </resources> diff --git a/samples/Support7Demos/res/values/styles.xml b/samples/Support7Demos/res/values/styles.xml index f085fa5f0..26a9f70de 100644 --- a/samples/Support7Demos/res/values/styles.xml +++ b/samples/Support7Demos/res/values/styles.xml @@ -29,4 +29,8 @@ <item name="colorAccent">#ffff00</item> </style> + <style name="SortedListItem" parent="@android:style/TextAppearance.Medium"> + <item name="android:minHeight">35dp</item> + </style> + </resources>
\ No newline at end of file diff --git a/samples/Support7Demos/res/xml/preferences.xml b/samples/Support7Demos/res/xml/preferences.xml new file mode 100644 index 000000000..3ec0f25ec --- /dev/null +++ b/samples/Support7Demos/res/xml/preferences.xml @@ -0,0 +1,34 @@ +<?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. +--> + +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> + + <PreferenceCategory + android:title="My category"> + + <CheckBoxPreference + android:key="check_1" + android:summary="Check or not, that is the question" + android:title="Checkbox Preference 1"/> + + <EditTextPreference + android:key="edit_1" + android:summary="Input some text here" + android:title="EditText Preference 1"/> + + </PreferenceCategory> + +</PreferenceScreen>
\ No newline at end of file diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarActionMode.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarActionMode.java new file mode 100644 index 000000000..6edf59357 --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarActionMode.java @@ -0,0 +1,79 @@ +/* + * 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.supportv7.app; + +import com.example.android.supportv7.R; + +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.v4.view.MenuItemCompat; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.view.ActionMode; +import android.support.v7.widget.SearchView; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +/** + * This demonstrates idiomatic usage of an action mode. + */ +public class ActionBarActionMode extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.action_bar_action_mode); + + findViewById(R.id.btn_start_action_mode).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActionMode(); + } + }); + } + + private void startActionMode() { + startSupportActionMode(new ActionMode.Callback() { + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + mode.getMenuInflater().inflate(R.menu.actions, menu); + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + Toast.makeText(ActionBarActionMode.this, + "Action Mode item clicked:" + item.getTitle(), Toast.LENGTH_SHORT).show(); + return true; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + } + }); + } + +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarDisplayOptions.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarDisplayOptions.java index ebda99905..d4eef84b1 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarDisplayOptions.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarDisplayOptions.java @@ -21,7 +21,7 @@ import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar.Tab; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.view.Gravity; import android.view.Menu; import android.view.View; @@ -29,10 +29,12 @@ import android.view.ViewGroup.LayoutParams; import android.widget.ArrayAdapter; import android.widget.Toast; +; + /** * This demo shows how various action bar display option flags can be combined and their effects. */ -public class ActionBarDisplayOptions extends ActionBarActivity +public class ActionBarDisplayOptions extends AppCompatActivity implements View.OnClickListener, ActionBar.TabListener { private View mCustomView; private ActionBar.LayoutParams mCustomViewLayoutParams; diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarFragmentMenu.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarFragmentMenu.java index 207631e78..e2779d020 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarFragmentMenu.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarFragmentMenu.java @@ -16,17 +16,17 @@ package com.example.android.supportv7.app; -import android.support.v4.view.MenuItemCompat; -import android.view.Menu; -import android.view.MenuItem; import com.example.android.supportv7.R; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.ActionBarActivity; +import android.support.v4.view.MenuItemCompat; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; @@ -35,7 +35,7 @@ import android.widget.Toast; /** * Demonstrates how fragments can participate in the options menu. */ -public class ActionBarFragmentMenu extends ActionBarActivity { +public class ActionBarFragmentMenu extends AppCompatActivity { MenuFragment mFragment1; Menu2Fragment mFragment2; CheckBox mCheckBox1; diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarMechanics.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarMechanics.java index ed4b97bd5..568c287e9 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarMechanics.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarMechanics.java @@ -18,7 +18,7 @@ package com.example.android.supportv7.app; import android.os.Bundle; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.WindowCompat; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; @@ -28,7 +28,7 @@ import android.widget.Toast; * standard options menu. This demo is for informative purposes only; see ActionBarUsage for * an example of using the Action Bar in a more idiomatic manner. */ -public class ActionBarMechanics extends ActionBarActivity { +public class ActionBarMechanics extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarPreferences.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarPreferences.java new file mode 100644 index 000000000..810e615bb --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarPreferences.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2010 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.supportv7.app; + +import com.example.android.supportv7.R; + +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.Toast; + +/** + * This demonstrates how to use our custom AppCompat {@link android.preference.PreferenceActivity}. + */ +public class ActionBarPreferences extends AppCompatPreferenceActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Load some preferences from resources + addPreferencesFromResource(R.xml.preferences); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.actions, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show(); + return true; + } + +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarSettingsActionProviderActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarSettingsActionProviderActivity.java index ba1ccbe28..5fb667ac1 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarSettingsActionProviderActivity.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarSettingsActionProviderActivity.java @@ -16,18 +16,19 @@ package com.example.android.supportv7.app; +import com.example.android.supportv7.R; + import android.content.Context; import android.content.Intent; import android.provider.Settings; -import android.support.v7.app.ActionBarActivity; import android.support.v4.view.ActionProvider; +import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; -import com.example.android.supportv7.R; /** * This activity demonstrates how to implement an {@link android.view.ActionProvider} @@ -35,7 +36,7 @@ import com.example.android.supportv7.R; * ActionProvider for launching the system settings and adds a menu item with that * provider. */ -public class ActionBarSettingsActionProviderActivity extends ActionBarActivity { +public class ActionBarSettingsActionProviderActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTabs.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTabs.java index 4bfea5010..a8c87f410 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTabs.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTabs.java @@ -15,24 +15,25 @@ */ package com.example.android.supportv7.app; +import com.example.android.supportv7.R; + import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar.Tab; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; -import com.example.android.supportv7.R; /** * This demonstrates the use of action bar tabs and how they interact * with other action bar features. */ -public class ActionBarTabs extends ActionBarActivity { +public class ActionBarTabs extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarUsage.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarUsage.java index f8c29caed..87726017a 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarUsage.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarUsage.java @@ -20,7 +20,7 @@ import com.example.android.supportv7.R; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.text.TextUtils; import android.view.Menu; @@ -35,7 +35,7 @@ import android.widget.Toast; * menu data itself. If you'd like to see how these things work under the hood, see * ActionBarMechanics. */ -public class ActionBarUsage extends ActionBarActivity { +public class ActionBarUsage extends AppCompatActivity { TextView mSearchText; int mSortMode = -1; diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarWithDrawerLayout.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarWithDrawerLayout.java index 3519a3854..a45edc986 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarWithDrawerLayout.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarWithDrawerLayout.java @@ -15,24 +15,24 @@ */ package com.example.android.supportv7.app; +import com.example.android.supportv7.R; import com.example.android.supportv7.Shakespeare; -import android.support.v7.app.ActionBarActivity; import android.content.res.Configuration; import android.os.Bundle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; -import com.example.android.supportv7.R; -public class ActionBarWithDrawerLayout extends ActionBarActivity { +public class ActionBarWithDrawerLayout extends AppCompatActivity { private DrawerLayout mDrawerLayout; private ListView mDrawer; private TextView mContent; diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/AlertDialogUsage.java b/samples/Support7Demos/src/com/example/android/supportv7/app/AlertDialogUsage.java new file mode 100644 index 000000000..560111b2e --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/AlertDialogUsage.java @@ -0,0 +1,101 @@ +/* + * 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.supportv7.app; + +import com.example.android.supportv7.Cheeses; +import com.example.android.supportv7.R; + +import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Spinner; + +/** + * This demonstrates idiomatic usage of AppCompat's AlertDialog. + */ +public class AlertDialogUsage extends AppCompatActivity { + + private Spinner mSpinner; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.alert_dialog_usage); + + mSpinner = (Spinner) findViewById(R.id.spinner_dialogs); + + // Add an OnClickListener to show our selected dialog + findViewById(R.id.btn_show_dialog).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showSelectedDialog(); + } + }); + } + + private void showSelectedDialog() { + switch (mSpinner.getSelectedItemPosition()) { + case 0: + showSimpleDialog(); + break; + case 1: + showSimpleButtonsDialog(); + break; + case 2: + showSingleChoiceDialog(); + break; + case 3: + showMultiChoiceDialog(); + break; + } + } + + private void showSimpleDialog() { + AlertDialog.Builder b = new AlertDialog.Builder(this); + b.setTitle(R.string.dialog_title); + b.setMessage(R.string.dialog_content); + b.show(); + } + + private void showSimpleButtonsDialog() { + AlertDialog.Builder b = new AlertDialog.Builder(this); + b.setTitle(R.string.dialog_title); + b.setMessage(R.string.dialog_content); + b.setNegativeButton("-ve", null); + b.setPositiveButton("+ve", null); + b.show(); + } + + private void showSingleChoiceDialog() { + AlertDialog.Builder b = new AlertDialog.Builder(this); + b.setTitle(R.string.dialog_title); + b.setSingleChoiceItems(Cheeses.sCheeseStrings, 0, null); + b.setPositiveButton("OK", null); + b.show(); + } + + private void showMultiChoiceDialog() { + AlertDialog.Builder b = new AlertDialog.Builder(this); + b.setTitle(R.string.dialog_title); + b.setMultiChoiceItems(Cheeses.sCheeseStrings, null, null); + b.setPositiveButton("OK", null); + b.show(); + } + + +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatPreferenceActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatPreferenceActivity.java new file mode 100644 index 000000000..e2ae88c3c --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatPreferenceActivity.java @@ -0,0 +1,128 @@ +/* + * 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. + */ + +package com.example.android.supportv7.app; + +import android.content.res.Configuration; +import android.os.Bundle; +import android.preference.PreferenceActivity; +import android.support.annotation.LayoutRes; +import android.support.annotation.Nullable; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatDelegate; +import android.support.v7.widget.Toolbar; +import android.view.MenuInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls + * to be used with AppCompat. + * + * This technique can be used with an {@link android.app.Activity} class, not just + * {@link android.preference.PreferenceActivity}. + */ +public abstract class AppCompatPreferenceActivity extends PreferenceActivity { + + private AppCompatDelegate mDelegate; + + @Override + protected void onCreate(Bundle savedInstanceState) { + getDelegate().installViewFactory(); + getDelegate().onCreate(savedInstanceState); + super.onCreate(savedInstanceState); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + getDelegate().onPostCreate(savedInstanceState); + } + + public ActionBar getSupportActionBar() { + return getDelegate().getSupportActionBar(); + } + + public void setSupportActionBar(@Nullable Toolbar toolbar) { + getDelegate().setSupportActionBar(toolbar); + } + + @Override + public MenuInflater getMenuInflater() { + return getDelegate().getMenuInflater(); + } + + @Override + public void setContentView(@LayoutRes int layoutResID) { + getDelegate().setContentView(layoutResID); + } + + @Override + public void setContentView(View view) { + getDelegate().setContentView(view); + } + + @Override + public void setContentView(View view, ViewGroup.LayoutParams params) { + getDelegate().setContentView(view, params); + } + + @Override + public void addContentView(View view, ViewGroup.LayoutParams params) { + getDelegate().addContentView(view, params); + } + + @Override + protected void onPostResume() { + super.onPostResume(); + getDelegate().onPostResume(); + } + + @Override + protected void onTitleChanged(CharSequence title, int color) { + super.onTitleChanged(title, color); + getDelegate().setTitle(title); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + getDelegate().onConfigurationChanged(newConfig); + } + + @Override + protected void onStop() { + super.onStop(); + getDelegate().onStop(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + getDelegate().onDestroy(); + } + + public void invalidateOptionsMenu() { + getDelegate().invalidateOptionsMenu(); + } + + private AppCompatDelegate getDelegate() { + if (mDelegate == null) { + mDelegate = AppCompatDelegate.create(this, null); + } + return mDelegate; + } +}
\ No newline at end of file diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsButtons.java b/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsButtons.java new file mode 100644 index 000000000..d8b2c4f18 --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsButtons.java @@ -0,0 +1,34 @@ +/* + * 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.supportv7.app; + +import com.example.android.supportv7.R; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +/** + * This demonstrates the styled {@link android.widget.Button} widgets in AppCompat. + */ +public class AppCompatWidgetsButtons extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.appcompat_widgets_buttons); + } + +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsSpinners.java b/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsSpinners.java new file mode 100644 index 000000000..2d22b9960 --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsSpinners.java @@ -0,0 +1,46 @@ +/* + * 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.supportv7.app; + +import com.example.android.supportv7.Cheeses; +import com.example.android.supportv7.R; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +/** + * This demonstrates the styled {@link android.widget.Spinner} widgets in AppCompat. + */ +public class AppCompatWidgetsSpinners extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.appcompat_widgets_text_spinners); + + // Fetch the Spinners and set an adapter + Spinner spinner = (Spinner) findViewById(R.id.widgets_spinner); + spinner.setAdapter(new ArrayAdapter<>(this, + R.layout.support_simple_spinner_dropdown_item, Cheeses.sCheeseStrings)); + + spinner = (Spinner) findViewById(R.id.widgets_spinner_underlined); + spinner.setAdapter(new ArrayAdapter<>(this, + R.layout.support_simple_spinner_dropdown_item, Cheeses.sCheeseStrings)); + } + +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsTextInput.java b/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsTextInput.java new file mode 100644 index 000000000..c94bd194a --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/AppCompatWidgetsTextInput.java @@ -0,0 +1,53 @@ +/* + * 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.supportv7.app; + +import com.example.android.supportv7.Cheeses; +import com.example.android.supportv7.R; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; +import android.widget.MultiAutoCompleteTextView; + +/** + * This demonstrates the styled text input widgets in AppCompat, such as + * {@link android.widget.EditText}, {@link android.widget.AutoCompleteTextView} and + * {@link android.widget.MultiAutoCompleteTextView}. + */ +public class AppCompatWidgetsTextInput extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.appcompat_widgets_text_input); + + // Fetch the AutoCompleteTextView and set an adapter + AutoCompleteTextView actv = (AutoCompleteTextView) findViewById( + R.id.widgets_autocompletetextview); + actv.setAdapter(new ArrayAdapter<>(this, + android.R.layout.simple_dropdown_item_1line, Cheeses.sCheeseStrings)); + + // Fetch the MultiAutoCompleteTextView and set an adapter and Tokenizer + MultiAutoCompleteTextView mactv = (MultiAutoCompleteTextView) findViewById( + R.id.widgets_multiautocompletetextview); + mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); + mactv.setAdapter(new ArrayAdapter<>(this, + android.R.layout.simple_dropdown_item_1line, Cheeses.sCheeseStrings)); + } + +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/DialogUsage.java b/samples/Support7Demos/src/com/example/android/supportv7/app/DialogUsage.java new file mode 100644 index 000000000..cf48d80bf --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/DialogUsage.java @@ -0,0 +1,116 @@ +/* + * 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. + */ +package com.example.android.supportv7.app; + +import com.example.android.supportv7.R; + +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.support.v4.view.WindowCompat; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.app.AppCompatDialog; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Spinner; +import android.widget.Toast; + +/** + * This demonstrates idiomatic usage of AppCompatDialog. + */ +public class DialogUsage extends AppCompatActivity { + + private Spinner mSpinner; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.dialog_usage); + + mSpinner = (Spinner) findViewById(R.id.spinner_dialogs); + + // Add an OnClickListener to show our selected dialog + findViewById(R.id.btn_show_dialog).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showSelectedDialog(); + } + }); + } + + private void showSelectedDialog() { + switch (mSpinner.getSelectedItemPosition()) { + case 0: + showSimpleDialog(); + break; + case 1: + showSimpleDialogWithActionBar(); + break; + case 2: + showButtonBarDialog(); + break; + } + } + + private void showSimpleDialog() { + Dialog dialog = new AppCompatDialog(this); + dialog.setTitle(R.string.dialog_title); + dialog.setContentView(R.layout.dialog_content); + dialog.show(); + } + + private void showSimpleDialogWithActionBar() { + AppCompatDialog dialog = new MenuDialog(this); + // Request the support Action Bar window feature + dialog.supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR); + dialog.setTitle(R.string.dialog_title); + dialog.setContentView(R.layout.dialog_content); + dialog.show(); + } + + private void showButtonBarDialog() { + Dialog dialog = new AppCompatDialog(this); + dialog.setTitle(R.string.dialog_title); + dialog.setContentView(R.layout.dialog_content_buttons); + dialog.show(); + } + + /** + * A simple {@link android.support.v7.app.AppCompatDialog} implementation which + * inflates some items into it's options menu, and shows a toast when one is selected. + */ + private class MenuDialog extends AppCompatDialog { + + public MenuDialog(Context context) { + super(context); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.actions, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + Toast.makeText(getOwnerActivity(), "Dialog action selected: " + item.getTitle(), + Toast.LENGTH_SHORT).show(); + return true; + } + } + +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarActionMode.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarActionMode.java new file mode 100644 index 000000000..3977048ca --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarActionMode.java @@ -0,0 +1,77 @@ +/* + * 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.supportv7.app; + +import com.example.android.supportv7.R; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.view.ActionMode; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Toast; + +/** + * This demonstrates idiomatic usage of an action mode with a Toolbar. + */ +public class ToolbarActionMode extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.toolbar_action_mode); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + findViewById(R.id.btn_start_action_mode).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActionMode(); + } + }); + } + + private void startActionMode() { + startSupportActionMode(new ActionMode.Callback() { + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + mode.getMenuInflater().inflate(R.menu.actions, menu); + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + Toast.makeText(ToolbarActionMode.this, + "Action Mode item clicked:" + item.getTitle(), Toast.LENGTH_SHORT).show(); + return true; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + } + }); + } + +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarDisplayOptions.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarDisplayOptions.java index f5c3d7587..e6d179be0 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarDisplayOptions.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarDisplayOptions.java @@ -19,23 +19,19 @@ package com.example.android.supportv7.app; import com.example.android.supportv7.R; import android.os.Bundle; -import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBar.Tab; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Gravity; import android.view.Menu; import android.view.View; import android.view.ViewGroup.LayoutParams; -import android.widget.ArrayAdapter; -import android.widget.Toast; /** * This demo shows how various action bar display option flags can be combined and their effects * when used on a Toolbar-provided Action Bar */ -public class ToolbarDisplayOptions extends ActionBarActivity +public class ToolbarDisplayOptions extends AppCompatActivity implements View.OnClickListener { private View mCustomView; diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarFragmentPagerMenu.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarFragmentPagerMenu.java index 9b579338c..575c7a18c 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarFragmentPagerMenu.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarFragmentPagerMenu.java @@ -23,10 +23,9 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.app.FragmentTransaction; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Gravity; import android.view.LayoutInflater; @@ -34,9 +33,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; @@ -46,7 +43,7 @@ import java.util.List; /** * Demonstrates how fragments can participate in the options menu from within a {@link ViewPager}. */ -public class ToolbarFragmentPagerMenu extends ActionBarActivity { +public class ToolbarFragmentPagerMenu extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarUsage.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarUsage.java index f5ac03b84..55e7f1498 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarUsage.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarUsage.java @@ -18,33 +18,20 @@ package com.example.android.supportv7.app; import com.example.android.supportv7.R; import android.app.SearchManager; -import android.content.Context; -import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.os.Handler; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBarActivity; -import android.support.v7.view.ActionMode; -import android.support.v7.widget.PopupMenu; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; -import android.text.TextUtils; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.TextView; import android.widget.Toast; /** * This demonstrates idiomatic usage of the Toolbar as the action bar. */ -public class ToolbarUsage extends ActionBarActivity { +public class ToolbarUsage extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/samples/Support7Demos/src/com/example/android/supportv7/graphics/PaletteActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/graphics/PaletteActivity.java index 9f33f2834..e82aa3acf 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/graphics/PaletteActivity.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/graphics/PaletteActivity.java @@ -30,7 +30,7 @@ import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v4.widget.ResourceCursorAdapter; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; import android.view.Menu; import android.view.MenuInflater; @@ -46,7 +46,7 @@ import android.widget.ListView; * Allows the customization of the number of colors used in the palette generation, to demonstrate * the difference in results for different types of images. */ -public class PaletteActivity extends ActionBarActivity { +public class PaletteActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/samples/Support7Demos/src/com/example/android/supportv7/graphics/PaletteDetailActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/graphics/PaletteDetailActivity.java index a91257f66..d7fd47cb1 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/graphics/PaletteDetailActivity.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/graphics/PaletteDetailActivity.java @@ -17,10 +17,11 @@ package com.example.android.supportv7.graphics; import com.example.android.supportv7.R; + import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; import android.view.Menu; import android.view.MenuItem; @@ -44,7 +45,7 @@ import java.util.List; * Also allows the customization of the number of colors used in the palette generation for * demonstration purposes. */ -public class PaletteDetailActivity extends ActionBarActivity { +public class PaletteDetailActivity extends AppCompatActivity { private ImageView mImageView; private GridView mGridView; diff --git a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteSettingsActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteSettingsActivity.java index a1d07fb56..5f1cfd60d 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteSettingsActivity.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouteSettingsActivity.java @@ -16,12 +16,12 @@ package com.example.android.supportv7.media; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; /** * This activity is a dummy settings activity for the * {@link SampleMediaRouteProvider}. */ -public class SampleMediaRouteSettingsActivity extends ActionBarActivity { +public class SampleMediaRouteSettingsActivity extends AppCompatActivity { } diff --git a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java index ba1949965..0a64c55fb 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/media/SampleMediaRouterActivity.java @@ -18,39 +18,34 @@ package com.example.android.supportv7.media; import com.example.android.supportv7.R; +import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.res.Resources; -import android.app.PendingIntent; import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; -import android.media.MediaMetadataRetriever; -import android.media.RemoteControlClient; import android.net.Uri; -import android.os.Build; +import android.os.Bundle; import android.os.Environment; import android.os.Handler; -import android.os.Bundle; import android.os.SystemClock; import android.support.v4.app.FragmentManager; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.app.MediaRouteActionProvider; -import android.support.v7.app.MediaRouteButton; import android.support.v7.app.MediaRouteControllerDialog; import android.support.v7.app.MediaRouteControllerDialogFragment; -import android.support.v7.app.MediaRouteDiscoveryFragment; import android.support.v7.app.MediaRouteDialogFactory; +import android.support.v7.app.MediaRouteDiscoveryFragment; import android.support.v7.media.MediaControlIntent; +import android.support.v7.media.MediaItemStatus; +import android.support.v7.media.MediaRouteSelector; import android.support.v7.media.MediaRouter; import android.support.v7.media.MediaRouter.Callback; -import android.support.v7.media.MediaRouter.RouteInfo; import android.support.v7.media.MediaRouter.ProviderInfo; -import android.support.v7.media.MediaRouteSelector; -import android.support.v7.media.MediaItemStatus; +import android.support.v7.media.MediaRouter.RouteInfo; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; @@ -63,12 +58,12 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageButton; import android.widget.ListView; -import android.widget.TextView; -import android.widget.TabHost; -import android.widget.TabHost.TabSpec; -import android.widget.TabHost.OnTabChangeListener; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; +import android.widget.TabHost; +import android.widget.TabHost.OnTabChangeListener; +import android.widget.TabHost.TabSpec; +import android.widget.TextView; import java.io.File; @@ -81,7 +76,7 @@ import java.io.File; * targets. * </p> */ -public class SampleMediaRouterActivity extends ActionBarActivity { +public class SampleMediaRouterActivity extends AppCompatActivity { private static final String TAG = "SampleMediaRouterActivity"; private static final String DISCOVERY_FRAGMENT_TAG = "DiscoveryFragment"; diff --git a/samples/Support7Demos/src/com/example/android/supportv7/util/SortedListActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/util/SortedListActivity.java new file mode 100644 index 000000000..8f3871dc9 --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/util/SortedListActivity.java @@ -0,0 +1,179 @@ +/* + * 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.supportv7.util; + +import com.example.android.supportv7.R; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.util.SortedList; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.util.SortedListAdapterCallback; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.EditText; +import android.widget.TextView; + +/** + * A sample activity that uses {@link SortedList} in combination with RecyclerView. + */ +public class SortedListActivity extends ActionBarActivity { + private RecyclerView mRecyclerView; + private LinearLayoutManager mLinearLayoutManager; + private SortedListAdapter mAdapter; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.sorted_list_activity); + mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view); + mRecyclerView.setHasFixedSize(true); + mLinearLayoutManager = new LinearLayoutManager(this); + mRecyclerView.setLayoutManager(mLinearLayoutManager); + mAdapter = new SortedListAdapter(getLayoutInflater(), + new Item("buy milk"), new Item("wash the car"), + new Item("wash the dishes")); + mRecyclerView.setAdapter(mAdapter); + mRecyclerView.setHasFixedSize(true); + final EditText newItemTextView = (EditText) findViewById(R.id.new_item_text_view); + newItemTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { + if (id == EditorInfo.IME_ACTION_DONE && + (keyEvent == null || keyEvent.getAction() == KeyEvent.ACTION_DOWN)) { + final String text = textView.getText().toString().trim(); + if (text.length() > 0) { + mAdapter.addItem(new Item(text)); + } + textView.setText(""); + return true; + } + return false; + } + }); + } + + private static class SortedListAdapter extends RecyclerView.Adapter<TodoViewHolder> { + SortedList<Item> mData; + final LayoutInflater mLayoutInflater; + public SortedListAdapter(LayoutInflater layoutInflater, Item... items) { + mLayoutInflater = layoutInflater; + mData = new SortedList<Item>(Item.class, new SortedListAdapterCallback<Item>(this) { + @Override + public int compare(Item t0, Item t1) { + if (t0.mIsDone != t1.mIsDone) { + return t0.mIsDone ? 1 : -1; + } + int txtComp = t0.mText.compareTo(t1.mText); + if (txtComp != 0) { + return txtComp; + } + if (t0.id < t1.id) { + return -1; + } else if (t0.id > t1.id) { + return 1; + } + return 0; + } + + @Override + public boolean areContentsTheSame(Item oldItem, + Item newItem) { + return oldItem.mText.equals(newItem.mText); + } + + @Override + public boolean areItemsTheSame(Item item1, Item item2) { + return item1.id == item2.id; + } + }); + for (Item item : items) { + mData.add(item); + } + } + + public void addItem(Item item) { + mData.add(item); + } + + @Override + public TodoViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) { + return new TodoViewHolder ( + mLayoutInflater.inflate(R.layout.sorted_list_item_view, parent, false)) { + @Override + void onDoneChanged(boolean isDone) { + int adapterPosition = getAdapterPosition(); + if (adapterPosition == RecyclerView.NO_POSITION) { + return; + } + mBoundItem.mIsDone = isDone; + mData.recalculatePositionOfItemAt(adapterPosition); + } + }; + } + + @Override + public void onBindViewHolder(TodoViewHolder holder, int position) { + holder.bindTo(mData.get(position)); + } + + @Override + public int getItemCount() { + return mData.size(); + } + } + + abstract private static class TodoViewHolder extends RecyclerView.ViewHolder { + final CheckBox mCheckBox; + Item mBoundItem; + public TodoViewHolder(View itemView) { + super(itemView); + mCheckBox = (CheckBox) itemView; + mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (mBoundItem != null && isChecked != mBoundItem.mIsDone) { + onDoneChanged(isChecked); + } + } + }); + } + + public void bindTo(Item item) { + mBoundItem = item; + mCheckBox.setText(item.mText); + mCheckBox.setChecked(item.mIsDone); + } + + abstract void onDoneChanged(boolean isChecked); + } + + private static class Item { + String mText; + boolean mIsDone = false; + final public int id; + private static int idCounter = 0; + + public Item(String text) { + id = idCounter ++; + this.mText = text; + } + } +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/view/CardViewActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/view/CardViewActivity.java index ca0c08aac..f5f8c4c0c 100644 --- a/samples/Support7Demos/src/com/example/android/supportv7/view/CardViewActivity.java +++ b/samples/Support7Demos/src/com/example/android/supportv7/view/CardViewActivity.java @@ -16,8 +16,6 @@ package com.example.android.supportv7.view; import android.app.Activity; -import android.graphics.drawable.ColorDrawable; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.view.ViewCompat; @@ -30,8 +28,6 @@ import android.widget.TextView; import com.example.android.supportv7.R; -import java.lang.reflect.Field; - public class CardViewActivity extends Activity { CardView mCardView; @@ -182,6 +178,8 @@ public class CardViewActivity extends Activity { return R.color.card_sunbrite; case R.id.tropical: return R.color.card_tropical; + case R.id.selector: + return R.color.card_selector; default: return R.color.cardview_light_background; } |