Merge "Add ActionMode demos to Support7Demos" into lmp-mr1-ub-dev

This commit is contained in:
Chris Banes
2015-02-20 11:56:11 +00:00
committed by Android (Google) Code Review
6 changed files with 246 additions and 0 deletions

View File

@@ -213,6 +213,15 @@
</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">
@@ -271,6 +280,15 @@
</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">

View File

@@ -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>

View File

@@ -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>

View File

@@ -57,6 +57,7 @@
<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>
@@ -129,6 +130,7 @@
<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>
@@ -173,5 +175,6 @@
<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>

View File

@@ -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) {
}
});
}
}

View File

@@ -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) {
}
});
}
}