New API demo for UndoManager.
Change-Id: Ic49211c771db275f27ceefa5372b005a357fce21
This commit is contained in:
@@ -1117,6 +1117,14 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".content.TextUndoActivity" android:label="@string/activity_text_undo">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||
<category android:name="android.intent.category.EMBED" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".content.ResourcesLayoutReference"
|
||||
android:label="@string/activity_resources_layout_reference">
|
||||
<intent-filter>
|
||||
|
||||
58
samples/ApiDemos/res/layout/text_undo.xml
Normal file
58
samples/ApiDemos/res/layout/text_undo.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2013 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!-- Demonstrates saving and restoring activity state.
|
||||
See corresponding Java code com.android.sdk.app.SaveRestoreState.java. -->
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
<LinearLayout android:orientation="vertical" android:padding="4dip"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||
|
||||
<TextView android:id="@+id/msg"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0" android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:paddingBottom="8dip"
|
||||
android:text="@string/text_undo_msg" />
|
||||
|
||||
<EditText android:id="@+id/text"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:freezesText="true">
|
||||
</EditText>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="8dip">
|
||||
<Button
|
||||
android:id="@+id/undo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/undo"
|
||||
android:layout_gravity="bottom" />
|
||||
<Button
|
||||
android:id="@+id/redo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/redo"
|
||||
android:layout_gravity="bottom" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
@@ -421,6 +421,12 @@
|
||||
<string name="styled_text">Plain, <b>bold</b>, <i>italic</i>, <b><i>bold-italic</i></b></string>
|
||||
<string name="styled_text_prog">Assigned programmatically:</string>
|
||||
|
||||
<string name="activity_text_undo">Content/Undo Manager/Text</string>
|
||||
<string name="text_undo_msg">Demonstrates simple use of UndoManager with text editing
|
||||
in a TextView.</string>
|
||||
<string name="undo">Undo</string>
|
||||
<string name="redo">Redo</string>
|
||||
|
||||
<string name="activity_resources_layout_reference">Content/Resources/Layout Reference</string>
|
||||
<string name="resources_layout_reference_description">Shows how to write layout
|
||||
resource references, so that you can define multiple different configurations of
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.apis.content;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.UndoManager;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import com.example.android.apis.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Simple example of using an UndoManager for editing text in a TextView.
|
||||
*/
|
||||
public class TextUndoActivity extends Activity {
|
||||
UndoManager mUndoManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mUndoManager = new UndoManager();
|
||||
if (savedInstanceState != null) {
|
||||
Parcelable p = savedInstanceState.getParcelable("undo");
|
||||
if (p != null) {
|
||||
mUndoManager.restoreInstanceState(p);
|
||||
}
|
||||
}
|
||||
|
||||
setContentView(R.layout.text_undo);
|
||||
|
||||
((TextView)findViewById(R.id.text)).setUndoManager(mUndoManager, "text");
|
||||
((Button)findViewById(R.id.undo)).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mUndoManager.undo(null, 1);
|
||||
}
|
||||
});
|
||||
((Button)findViewById(R.id.redo)).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mUndoManager.redo(null, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable("undo", mUndoManager.saveInstanceState());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user