Sfflf

1. ftfMAMBt ' EditText ffiSA'W AAAPA

Hello World, ac01

Hello World, ac01

Hello World, ac01

Item-1

Item-2

- tb com.misoo.ks08 + Hi acOl.java + El Input Act .java + El My Instrumentation, java + El R.java + El SelectAct.java

package com.misoo.kx08; import android.app.Activity; import android.content.ComponentName; import android.os.Bundle;

public class ac01 extends Activity {

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startInstrumentation(new ComponentName(ac01.this, MyInstrumentation.class), null, null);

Step-3: MM Instrumentation ^X^^ : MyInstrumentation ' // — MyInstrumentation.java g^® —

package com.misoo.kx08; import android.app.Instrumentation; import android.content.Intent; import android.view.KeyEvent; import android.os.Bundle;

public class MyInstrumentation extends Instrumentation { @Override public void onCreate(Bundle arguments) { super.onCreate(arguments); start(); } @Override public void onStart() { super.onStart();

Intent intent = new Intent(IntentACTIONMAIN); intent. addFlags(Intent. FLAG_ACTIVITY_NEW_TASK); intent. setClass(getTargetContext(), Input Act. class); start Activity Sync (intent);

/* begin to input for InputAct */ sendKeySync(new KeyEvent(KeyEventACTION_DOWN,

KeyEventKEYCODESHIFTLEFT)); sendCharacterSync(KeyEvent.KEYCODE_L); sendKeySync(new KeyEvent(KeyEventACTION_UP,

KeyEventKEYCODESHIFTLEFT)); sendCharacterSync(KeyEvent.KEYCODE_O); sendCharacterSync(KeyEvent.KEYCODE_V); sendCharacterSync(KeyEvent.KEYCODE_E); /* wait */

long endTime = System.currentTimeMillis() + 6*1000; while (System.currentTimeMillisQ < endTime); /* begin to input for SelectAct */ sendKeySync(new KeyEvent(KeyEventACTION_DOWN,

KeyEvent.KEYCODE_DPAD_CENTER)); sendKeySync(new KeyEvent(KeyEventACTION_DOWN,

KeyEvent.KEYCODE_DPAD_DOWN)); sendKeySync(new KeyEvent(KeyEventACTION_DOWN,

KeyEvent.KEYCODEDPADDOWN));

waitForIdleSync();

package com.misoo.kx08;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.view.View.OnKeyListener;

import android.widget.EditText; import android.widget.TextView;

public class InputAct extends Activity implements OnKeyListener { private TextView tv; private EditText et;

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); this .setContentView(R.layout. inpMt); et = (EditText)findViewById(R.id.et); tv = (TextView)findViewById(R.id.tv); et.setOnKeyListener(this); } public boolean onKey(View v, int keyCode, KeyEvent event) {

if(eventgetKeyCode()==KeyEvent.KEYCODE_DPAD_CENTER){ tv.setText(et.getText());

Intent intent = new Intent(InputAct.this, SelectAct. class); startActivityForResult(intent, 152); } if(eventgetKeyCode()==KeyEvent.KEYCODE_0 { finish(); } return false;

package com.misoo.kx08; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView;

import android.widget.AdapterView.OnItemClickListener;

public class SelectAct extends Activity implements OnItemClickListener { private String[] data = {"Item-1", "Item-2", "Item-3", "Exit"}; private TextView tv; List View lv; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R. layout. list); tv = (TextView)findViewById(R.id.tv); lv = (ListView)findViewById(R. id. list); Array Adapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simplelistiteml, data); lv.setAdapter(adapter); lv.setOnItemClickListener(this); lv.requestFocus();

public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { switch(arg2){

case 0: tv.setText(data[arg2]); break; case 1: tv.setText(data[arg2]); break; case 2: tv.setText(data[arg2]); break; case 3: finish(); break;

Step-6: MM/res/layout/input.xml ffi^^M <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation= "vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, ac01" /> <EditText android:id="@+id/et"

android:layout_width="fill_parent" android:layout_height="wrap_content" android:text=">" android:freezesText="true"> <requestFocus /> </EditText> </LinearLayout>

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.misoo.kx08"> <application android:icon="@drawable/icon">

<activity android:name=".ac01" android:label="@string/app_name"> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

<activity android:name=".InputAct" android:label="Input..."> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

<activity android:name=".SelectAct" android:label="Select..."> </activity> </application> <instrumentation android:name=".My Instrumentation" android:targetPackage="com.misoo.kx08" android:label="MyIns" />

Intent intent = new Intent(ac01.this, InputAct. class); startSubActivity(intent, INITTEXTREQUEST);

^^T Activity : InputAct ' HAA EditText ftfiA«® °

Thread t = new Thread(new Runnable() { public void run() {

sendKeySync(new KeyEvent(KeyEvent.A CTION DO WN,

KeyEvent.KEYCODE_L));

3. ' HI InputAct ft«® ' Ht! ac01 ft^ffl^ Thread ^A

fiA(Pattern)g«ffAASA ' S^tASWlfflgSH ' fflAMA

mm ' 1995 AS Erich Gamma AAAA

®A"Design Patterns: Elements of Reusable Object-Oriented Software"—' AAM

mm ' AHfAAfiitA Android jsa^a

1. ft^AMM ' SA<MENU>AlA«HAMS 4 m Menu MTOA :

2. Mi£A<View>Ml ' View... A

3. ^ASA<MUNU> ' TO<Pick>M! ' MMS Pick.Ai

4. ' $PASA<MUNU> ' Sg<Edit>MM ' t#MM Edit...®*® °

0 0

Post a comment