Listing 1217 Close JobjavaGUI setup

package com.msi.manning.UnlockingAndroid;

// multiple imports omitted for brevity, see full source public class CloseJob extends Activity { ProgressDialog myprogress; Handler progresshandler; Message msg; JobEntry je = null; private closejobView sc = null; @Override public void onCreate(Bundle icicle) {

super.onCreate(icicle) ;

Intent startingIntent = getIntent();

Bundle b = startingIntent.getExtras() if (b != null) { je = JobEntry.fromBundle(b);

sc = new closej obview (this) ; O Instantiate instance setContentview (sc) ; of closejobView if (je == null) { finish();

@Override Q Define available public boolean onCreateOptionsMenu (Menu menu) { <1-' menus super.onCreateOptionsMenu(menu); menu.add(0,0,"Sign & Close"); menu.add(0,1,"Cancel") ;

return true; © Handle selected

} I menu public boolean onOptionsItemSelected (Menu. Item item) { <1-'

Prefs myprefs = new Prefs(CloseJob.this.getApplicationContext()); switch (item.getId()) { case 0: try {

myprogress =, "Closing Job ", ^ "Saving Signature to Network",true,false); progresshandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case 0:

myprogress.setMessage("" + (String) msg.obj); break; case 1:




Thread workthread = new Thread(new DoCloseJob (myprefs) ) ; <-1 to CloseJob workthread.start(); } catch (Exception e) {

Log.d("closej ob",e.getMessage()); msg = new Message () ; msg. what = 1 ;


return true; case 1:

finish(); return true;

return false;

Unlike previous activities in this chapter, the UI does not come from a design time-defined layout, but rather an instance of a closejobView O is the primary UI. The closejobView is defined in listing 12.18.

The onCreateOptionsMenu method © is an override of the base View's method, allowing a convenient way to add menus to this screen. Note that two menus are added, one for Sign & Close and one for Cancel. The onOptionsItemSelected method © is invoked when the user selects a menu item. A ProgressDialog and accompanying Handler are instantiated when the menu to close a job is selected. Once the progress-reporting mechanism is in place, a new Thread is created and started in order to process the steps required to actually close the job ©. Note that an instance of Prefs is passed in as an argument to the constructor, as that will be needed to store a signature, as we'll show in listing 12.19.

The UI at this point is only partially set up; we need a means to capture a signature on the screen of our Android device. Listing 12.18 implements the class closejobView, which is an extension of the View class.

0 0

Post a comment