Mm

1. ^ Android{{M IntentAlarmReceiver ^ > ^^ AlarmReceiver

public void onReceive(Context context, Intent intent) { ac01 app = ac01.geApp(); app.btEvent("from AlarmReceiver"); }

Intent intent = new Intent(ac01.this, AlarmReceiver.class); Pendinglntent p_intent =

PendingIntent.getBroadcast(ac01.this, 0, intent, 0);

Calendar calendar = Calendar.getInstanceQ; calendar. setTimeInMillis(System.currentTimeMillis()); calendar. add(Calendar.SECOND, 15);

AlarmManager am = (AlarmManager)getSystemService(AiARM_SERFICE); am.set(AlarmManager..RTC WAKEUP, calendar.getTimeInMillis(), p_intent);

ASE AlarmManager p_intent

Intent intent = new Intent(ac01.this, AlarmReceiver.class); PendingIntent p_intent = PendingIntent.getBroadcast(ac01.this, 0, intent, 0); long firstTime = SystemClock. elapsedRealtime(); firstTime += 800;

AlarmManager am = (AlarmManager)getSystemService(ALARM_SERFICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 800, p_intent);

MASE AlarmManager Intent

4. AndroidManifest.xml gjp± :

<receiver android:name=".AlarmReceiver">

</receiver>

BroadcastReceiver : ffiMMM—^M

BroadcastReceiver P^S^M^ : ^m—'ffl Service ° BroadcastReceiver M Service -Activity =

2. ®T<toall_service>®ffi ' WW 15

3. ## 15 ' Alarm Manager intent ° ^ BroadcastReceiver ^^ intent ' WM NotifyService ' ftfl^WftitW ' ac01 Title :

4. ST<Exit> ' MA^ISAT °

Step-2: MM BroadcastReceiver ftAS^ : AlarmReceiver > :

package com.misoo.kx02; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent;

public class AlarmReceiver extends BroadcastReceiver {

@Override public void onReceive(Context context, Intent intent) { context. startService(new Intent(context, NotifyService.class));

Step-3: MM Service ftAS^ : NotifyService > RMAMtUT ■ // NotifyService.java MA®

package com.misoo.kx02; import android.app.Service; import android.content.Intent; import android.os.IBinder; public class NotifyService extends Service{ @Override protected void onCreate() { ac01 app = ac01.getApp(); app.btEvent("from Notfy Service"); } @Override public IBinder onBind(Intent intent) { return null; }

package com.misoo.kx02;

import java.util.Calendar;

import android.app.Activity;

import android.app.AlarmManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.os.Bundle;

import android.widget.Button;

import android.view.View;

import android.view.View.OnClickListener;

public class acOl extends Activity implements OnClickListener{ private static acOl appRef = null; private Button btn, btn2; boolean k = false; @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle);

appRef = this; setContentView(R.layout.cs);

btn = (Button)findViewById(R.id.call_service);

btn. setOnClickListener(this);

btn2 = (Button)findViewById(R.id.exit);

btn2.setOnClickListener(this);

public static acOl getApp() { return appRef; } public void btEvent( String data ) { setTitle(data); } public void onClick(View argO) { if(arg0 == btn){ setTitle(" Waiting... Alarm=15");

Intent intent = new Intent(acO1.this, AlarmReceiver. class); PendingIntent p_intent = PendingIntentgetBroadcast(acO1.this, O, intent, O); Calendar calendar = Calendar. getlnstance(); calendar. setTimeInMilhs(System.currentT/'meM/7lis()); calendar.add(Calendar.SECOND, 15); // Schedule the alarm!

AlarmManager am = (AlarmManager)getSystemService(4JL4RM_SERF/CE); am.set(AlarmManager.RTC_^4^EFP, calendar.getTimeInMillis(), p_intent); } if (argO == btn2){

Intent intent = new Intent(acO1.this, AlarmReceiver. class); PendingIntent p_intent = PendingIntent.getBroadcast(acO1.this, O, intent, O); AlarmManager am = (AlarmManager)getSystemService(^Z^RM_SERF/CE); am.cancel(p_intent); finish();

Step-5: AndroidManifest.xml ft^W ' :

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.misoo.kx02"> <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> </actvity>

<receiver android:name=".AlarmReceiver"> </receiver>

<service android:name=".NotifyService"> </service> </application> </manifest>

1. ^ AlarmtReceiver ac01 ffAft Intent onReceive()®

public void onReceive(Context context, Intent intent) {

context. startService(new Intent(context, NotifyService. class), null);

Wg^ft startService()#A^ffl Intent NotifyService =

2. NotifyService «»T'g^M»« onCreate()M° MTfl-MMffl

10.3 #28 : MMf^ffl ProgressDialog

° OTafiMM^SXMSffi ProgressDialog fiM^^ User :

1. ftg^MffiffiMMX :

2. ^T<load map>®ffi ' WUXffi ProgressDialog f^M;

this main thread please wait-

Loading YourMap...

Second Screen

Here Is Your Map.

Step-1: MA Android ^^ : kx03 ° Step-2: MM Activity mASA : ac01 >

package com.misoo.kx03;

import android.app.Activity;

import android.app.ProgressDialog;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.LinearLayout;

public class ac01 extends Activity implements OnClickListener {

private final int WC = ViewGroup.LayoutParams. WRAP_CONTENT;

private Button btn, btn2;

private ProgressDialog progressDialog = null;

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle);

LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout. VERTICAL);

btn = new Button(this); btn.setText("load map"); btn. setOnClickListener(this);

layout.addView(btn, new LinearLayout.LayoutParams(WC, WC));

btn2 = new Button(this);

btn2.setText("Exit");

btn2.setOnClickListener(this);

layout.addView(btn2, new LinearLayout.LayoutParams(WC, WC)); setContentView (lay out);

progressDialog=ProgressDialog.sAow(this,

"please wait...","Loading YourMap... ",true); new Thread(){

sleep(8000);

Intent intent = new Intent();

intent. setClass(ac01. this, DispActivity.class);

start Activity (intent); }

catch(Exception e)

progressDialog.dismiss(); }

setTitle("this main thread");

Step-3: MM Activity ^TSB : DispActivity ' fig^fif^PT :

package com.misoo.kx03;

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

import android.widget.LinearLayout;

import android.widget.TextView;

public class DispActivity extends Activity implements OnClickListener { private final int WC = ViewGroup.LayoutParams. WRAP_CONTENT; public static final int EXITID = Menu.FIRST + 2; private TextView tx;

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setTitle("Second Screen"); tx = new TextView(this); tx.setText("Here Is Your Map.");

setContentView(tx, new LinearLayout.LayoutParams(WC, WC));

@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, EXITID, 0, "Exit"); return true;

public void onClick(View v)

{ setTitle("yes"); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case EXITID: this.finish(); return true;

return super.onOptionsItemSelected(item);

1. #ffiT<load map>g» ' ac01 ^^ onClick()®m ' WA

progressDialog = ProgressDialog.sAow(this,

"please wait... ","Loading YourMap... ",true);

sleep(8000);

Intent intent = new Intent();

intent.setClass(ac01.this, DispActivity. class);

startActivity(intent); }

catch(Exception e)

progressDialog.dismiss(); }

setTitle("this main thread");

• S1iSAf^MAIlAProgressDialogfAS^ °

progressDialog.dismiss(); AMAW ProgressDialog ' WAWM 1 WS 2 °

SiliiS^miSiAH - AAMMMfMABt ' MAAIAMM

UserSimAA ' mnm KeyEvent -

goal

- exEra_bonus thing long -I short —I middle

import android.app.Activity;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.LinearLayout;

public class ac01 extends Activity implements OnClickListener {

private final int WC = ViewGroup.LayoutParams. WRAP_CONTENT; private LinearLayout layout; private GraphicView gv;

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle);

layout = new LinearLayout(this); layout. setOrientation(LinearLay out. HORIZONTAL); setContentView(lay out); LinearLayout.LayoutParams param =

new LinearLayout.LayoutParams(200, 300); param.leftMargin = 1; gv = new GraphicView(this); layout.addView(gv,param);

Buton btn = new Button(this); btn.setText("Exit");

btn. setOnClickListener(this);

param = new LinearLayout.LayoutParams(WC, WC);

param.leftMargin = 10;

layout.addView(btn, param);

gv.build_model(); gv.requestFocus();

@Override public boolean onKeyDown(int keyCode, KeyEvent msg) {

if(keyCode == KeyEvent. KEYCODEDPADDOWN) gv.MoveDown(); if (keyCode == KeyEvent. KEYCODEDPADUP) gv.MoveUp(); if (keyCode == KeyEvent.KEYCODE_Z) gv.zip_toggle();

return true; } public void onClick(View arg0) { finish(); }

// — GraphicView.java MA® — package com.misoo.kx04; import java.util.ArrayList; import java.util.HashMap; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View;

public class GraphicView extends View { private Paint paint= new Paint(); private ObjectMap root, next_node, curr_item, pa; private MapList show_list, lv_0_coll, lv_1_coll, lv_2_coll; private int base, x, y, target_index, acc_index; private class MapList extends ArrayList<ObjectMap> {

private static final long serialVersionUID = 1L;

private class ObjectMap extends HashMap<String,Object> { private static final long serialVersionUID = 1L;

public void put_object(String key, Object value) { super.put(key, value); } public void put_string(String key, String value) { super.put(key, value); } public MapList get_sons() { return (MapList)super.get("sons"); }

GraphicView(Context context) { super(context); target_index = 0; base = 0; root = getNewNode(null, "goal");

@Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color. WHITE);

y = base + 6; acc_index = 0; show_list = new MapList(); this.drawNode_recursive(root, canvas); }

private void drawNode_recursive(ObjectMap curr_node, Canvas canvas) { String level = curr_node.get("level").toString(); int k = Integer. valueOf(level); x= k* 10 + 2; MapList son_coll = curr_node.get_sons(); int sz = son_coll.size(); String plus = "+"; // zip if(sz == 0) {

plus = "-"; show_list.add(curr_node); this.drawNode(x, y, curr_node, plus, canvas); if(pa != null) pa.put_object("last_pos", new Integer(y)); curr_node.put_object("last_pos", new Integer(y+6)); return; } else {

plus = curr_node.get("zip").toString(); if (plus == "+") {

show_list. add(curr_node); this.drawNode(x, y, curr_node, plus, canvas); pa = (ObjectMap)curr_node.get("parent"); if(pa != null) pa.put_object("last_pos", new Integer(y)); curr_node.put_object("last_pos", new Integer(y+6)); return; } show_list. add(curr_node); this.drawNode(x, y, curr_node, plus, canvas); pa = (ObjectMap)curr_node.get("parent"); if(pa != null) pa.put("last_pos", new Integer(y)); curr_node.put_object("last_pos", new Integer(y+6)); for(int i=0; i<sz; i++) {

this.drawNode_recursive(next_node, canvas); }

private void drawNode(int x, int y, ObjectMap curr_node, String plus, Canvas canvas) { String tx = curr_node.get("name").toString(); paint. setAntiAlias(true); if(x != 2) {

pant. setColor(Color.DKGRAY); canvas.drawLine(x-5,y+5, x, y+5, paint); pa = (ObjectMap)curr_node.get("parent"); Integer last_pos = (Integer)pa.get("last_pos"); int last_y = last_pos;

pant. setColor(Color.5LACK); paint. setStroke Width( 1); paint setColor(Color.LTGRAY); canvas.drawRect(x, y, x+10, y+10, paint); pant. setColor(Color.fiLUE); canvas.drawLine(x+2, y+5, x+8, y+5, paint); if(plus == "+") canvas.drawLine(x+5, y+2, x+5, y+8, paint); if(plus == "@") canvas.drawRect(x+2, y+2, x+8, y+8, paint); String level = curr_node.get("level").toString(); int k = Integer. valueOft\evel); switch(k){

case 0: paint. setColor(Color.5LACK); break; case 1: paint. setColor(Color.5LUE); break; case 2: paint. setColor(Color.5LACK); break;

case 3: paint. setColor(Color.5LUE); break; }

if( target_index == acc_index) paint. setColor(Color.RED); canvas.drawText(tx, x+13, y+8, paint);

public void build_model() {

root = getNewNode(null, "goal");

lv_0_coll = root.get_sons(); curr_item = getNewNode(root, ' "money"); lv_0_coll.add(curr_item); lv_1_coll = curr_item.get_sons(); lv_1_coll.add(getNewNode(curr_item, " "salary")); lv_1_coll.add(getNewNode(curr_item, "bonus")); lv_1_coll.add(getNewNode(curr_item, "extra_bonus")); curr_item.put_string("zip", " "@");

curr_item = getNewNode(root, " "thing");

lv_0_coll.add(curr_item); lv_1_coll = curr_item.get_sons(); next_node = getNewNode(curr_item, "few");

lv_1_coll.add(next_node); lv_2_coll = next_node.get_sons(); lv_2_coll.add(getNewNode(next_node, "little")); lv_2_coll.add(getNewNode(next_node, ' "fewer"));

lv_1_coll.add(getNewNode(curr_item, " "middle")); lv_1_coll.add(getNewNode(curr_item, "busy")); curr_item.put_string("zip", " "@"); curr_item =getNewNode(root, " "long");

lv_0_coll.add(curr_item); lv_1_coll = curr_item.get_sons(); lv_1_coll.add(getNewNode(curr_item, " "short")); lv_1_coll.add(getNewNode(curr_item, " "middle")); lv_1_coll.add(getNewNode(curr_item, " "long")); curr_item.put_string("zip", " "@"); root.put_string("zip", "@");

private ObjectMap getNewNode(ObjectMap pa, String name) { String lv = null; String level = null; if(pa == null) level = "0"; else { lv = pa.get("level").toString();

ObjectMap m_obj = new ObjectMap(); m_obj.put_object("last_pos", new Integer(18)); m_obj.put_string("level", level); m_obj.put_string("name", name); m_obj.put_object("parent", pa); m_obj.put_object("sons", new MapList()); m_obj.put_string("zip", "+"); return m_obj;

public void MoveUp() { target_index--; this.invalidate(); } public void MoveDown() { target_index++; this.invalidate(); } public void zip_toggle() {

ObjectMap curr_node = show_list.get(target_index); String zz = curr_node.get("zip").toString(); if(zz == "@"){

curr_node.put_string("zip", " "+"); this.invalidate();

curr_node.put_string("zip", " "@"); this.invalidate();

0 0

Post a comment