1 package com.example.android.apis.content; 2 3 //Need the following import to get access to the app resources, since this 4 //class is in a sub-package. 5 import com.example.android.apis.R; 6 7 import android.app.Activity; 8 import android.content.Intent; 9 import android.os.Bundle; 10 import android.view.Menu; 11 import android.view.View; 12 import android.view.View.OnClickListener; 13 import android.widget.Button; 14 import android.widget.EditText; 15 16 public class ProcessText extends Activity { 17 18 @Override onCreate(Bundle savedInstanceState)19 protected void onCreate(Bundle savedInstanceState) { 20 super.onCreate(savedInstanceState); 21 setContentView(R.layout.process_text_main); 22 23 CharSequence text = getIntent().getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT); 24 boolean readonly = 25 getIntent().getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false); 26 27 EditText edit = (EditText) findViewById(R.id.process_text_received_text_editable); 28 edit.setText(text); 29 edit.setSelection(edit.getText().length()); 30 31 Button finishButton = (Button) findViewById(R.id.process_text_finish_button); 32 finishButton.setText(readonly 33 ? R.string.process_text_finish_readonly : R.string.process_text_finish); 34 finishButton.setOnClickListener( 35 new OnClickListener() { 36 @Override 37 public void onClick(View arg0) { 38 finish(); 39 } 40 }); 41 } 42 43 @Override finish()44 public void finish() { 45 EditText edit = (EditText) findViewById(R.id.process_text_received_text_editable); 46 Intent intent = getIntent(); 47 intent.putExtra(Intent.EXTRA_PROCESS_TEXT, edit.getText()); 48 setResult(RESULT_OK, intent); 49 super.finish(); 50 } 51 52 @Override onCreateOptionsMenu(Menu menu)53 public boolean onCreateOptionsMenu(Menu menu) { 54 return false; 55 } 56 57 } 58