ApiDemos: Add a sample for Text Processing intents.

Change-Id: Ic2b333a6c83d24e73216daa69e68f473e33d103f
This commit is contained in:
Clara Bayarri
2015-04-08 18:30:50 +01:00
parent 64d5a34e12
commit 9326316443
6 changed files with 152 additions and 0 deletions

View File

@@ -1272,6 +1272,21 @@
android:exported="false"
android:enabled="@bool/atLeastHoneycombMR2" />
<activity android:name=".content.ProcessTextLauncher"
android:label="@string/process_text_title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".content.ProcessText" >
<intent-filter >
<action android:name="android.intent.action.PROCESS_TEXT"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<!-- ************************************* -->
<!-- HARDWARE PACKAGE SAMPLES -->
<!-- ************************************* -->

View File

@@ -0,0 +1,26 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/process_text_received_text_title"
android:textAppearance="@android:style/TextAppearance.Material.Title" />
<EditText
android:id="@+id/process_text_received_text_editable"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/process_text_finish_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/process_text_finish" />
</LinearLayout>

View File

@@ -0,0 +1,21 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:padding="10dip"
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/process_text_send_title"
android:textAppearance="@android:style/TextAppearance.Material.Title" />
<EditText
android:id="@+id/process_text_send_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/process_text_send_description" />
</LinearLayout>

View File

@@ -1564,4 +1564,13 @@
<string name="mms_status_downloading">Downloading</string>
<string name="mms_enable_receiver">Enable MMS broadcast receiver</string>
<string name="process_text_title">Content/Process Text Intent</string>
<string name="process_text_received_text_title">Received text selection</string>
<string name="process_text_finish_readonly">Finish</string>
<string name="process_text_finish">Replace</string>
<string name="process_text_no_text_received">No text received.</string>
<string name="process_text_no_text_process_intent_received">Try selecting some text in another app and find this app\'s name in the list of options for its selection menu.</string>
<string name="process_text_send_title">Select text to process</string>
<string name="process_text_send_description">Select a piece of text from this box to trigger the text selection action mode. In there, you will find \"Content/Process Text\". That is because this app declares it can handle text processing intents. Try selecting that action to send the selected text to that activity and retrieve processed text back.</string>
</resources>

View File

@@ -0,0 +1,57 @@
package com.example.android.apis.content;
//Need the following import to get access to the app resources, since this
//class is in a sub-package.
import com.example.android.apis.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class ProcessText extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.process_text_main);
CharSequence text = getIntent().getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
boolean readonly =
getIntent().getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false);
EditText edit = (EditText) findViewById(R.id.process_text_received_text_editable);
edit.setText(text);
edit.setSelection(edit.getText().length());
Button finishButton = (Button) findViewById(R.id.process_text_finish_button);
finishButton.setText(readonly
? R.string.process_text_finish_readonly : R.string.process_text_finish);
finishButton.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
@Override
public void finish() {
EditText edit = (EditText) findViewById(R.id.process_text_received_text_editable);
Intent intent = getIntent();
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, edit.getText());
setResult(RESULT_OK, intent);
super.finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return false;
}
}

View File

@@ -0,0 +1,24 @@
package com.example.android.apis.content;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
//Need the following import to get access to the app resources, since this
//class is in a sub-package.
import com.example.android.apis.R;
public class ProcessTextLauncher extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.process_text_send);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return false;
}
}