|
|
This is a library of atomic Proof of Concepts apps (POCs) I'm using to produce my Android code works more elegantly. Creating POCs is fun and once I get a POC operational, it's easier to visualize how POCs can be integrated to fulfill a requirement.
In the spirit of my IsHappenDo philosophy, I've converged to naming the POCs as a cause and effect, think of poking a frog and watching it jump. My ideas for IsHappenDo came from work in Artificial Intelligence many moons ago and I use it these days to make sense of programming constructs. So my project names have a name form of cause-effect, with a dash in between. This works fine for Eclipse Android project names. The final project name form is written as nounverb_adjective_adverb-nounverb_adjective_adverb. The adjective and adverb are optional and usually vary when there are several code constructs to accomplish the same reaction. The cause verb is optional, since the cause itself can be simply the presence of a noun, as if for example simplifying UserIsPresent-ConnectionSend to User-ConnectionSend. This discipline of reducing POCs to atomic level keeps the POC code basic and reactionary.
To produce a module requirement, several POCs can be serially connected. For example, a user entered value on a UI widget can take this path,
SubmitButtonPress-EntryValidate
EntryValidate-EntryValueChange
EntryValueChange-ConnectionSend
ConnectionWait-ConnectionFinish
ConnectionFinish-ModelUpdate
ModelUpdate-ViewUpdate
To bundle POCs into a more meaningful assemblage, the server connection POCs,
EntryValueChange-ConnectionSend
ConnectionWait-ConnectionFinish
ConnectionFinish-ModelUpdate
can be expressed as,
EntryValue-ConnectionSendReceive-ModelUpdate
and the entire serial chain of POCs can be condensed to the requirement statement as,
SubmitButtonPress->ViewUpdate.
|
ButtonPress-EmailAttachmentSend Press the Send Email button to email an attached image.png file. At start of app, a directory is created on the sdcard at /mnt/sdcard/EmailAttachmentSend. The image.png file is copied from the app's resources drawable to the created directory. Upon send of the email, the To, CC, subject, message, and attached files are setup. Any number of To, CC emails can be applied as well as any number of attached files although only one file is attached. Android Intent ACTION_SEND_MULTIPLE is used to send the email. The intent pops-up a ContextMenu with options for GMail and SMS.
|
|
|
ListViewSelect-Toast_Position_ContextMenu Short press a list item to show a toast. Long press to popup a ContextMenu for making the item selected all caps or removing it. A ListView setAdapter is set to an ArrayList of a string array. The ListView object has a setOnItemClickListener onItemClick(..) event present a Toast for a short press. Registration for the ContextMenu is made by registerForContextMenu(..) on the ListView object. The registration requires both onCreateContextMenu(..) for the menu inflate and onContextItemSelected(..) for the long press response to be defined. |
|
|
ListActivitySelect_LayoutSimple-ToastPopUp_ListPosition Press a list item to show a toast. The class extends ListActivity and calls setListAdaptor(..) to assign the string array as the list content. Callback method onListItemClick(.., position, ..) handles the display of the selected item through this.getListAdapter().getItem(position). |
|
|
When EditText widget edittext, has method OnKeyListener.onKey(..) detect a carriage return, a toast is shown and hideKeyboard() is called. Method hideKeyboard() makes use of a class object for InputMethodManager. |
|
|
Press button "Toggle File" to cycle the variable state from "xml1", to "xml2", to "xml3", then back to "xml1". On all state changes, method getISFromState(..) switches the InputSource object between an xml string, resource xml file, and a URL InputStream. Classes SAXParserFactory and XMLHandler are used to parse XML files. Class XMLHandler extends DefaultHandler and has custom method characters(..) to extract the string value of tag "tagB". |
|
|
To write a file, an instance of BufferedWriter(new OutputStreamWriter(openFileOutput(filename, MODE_WORLD_WRITEABLE))) is created. To read the same file, BufferedReader(new InputStreamReader(openFileInput(filename))) is created. Only strings are used to write and read in this example. The directory path is not accessible through Eclipse DDMS navigation. As stated on http://developer.android.com/guide/topics/data/data-storage.html, "Using the Internal Storage", "You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed." |
|
|
CountDownTimer(bignum, 1000) is instanced to accept parameter bignum = Long.MAX_VALUE. bignum is decremented every second. it will take approximately 5.849x10^11 years to reach zero at which time a new Android will likely have emerged. |
|
|
Press the "Update to Google" button to have the WebView switch from website http://brainyideas.com to http://google.com . The WebView is setup with JavaScript and zooming capability. |
|
|
Press the "Take a Picture" button and Android camera tool appears. The button initiates intent MediaStore.ACTION_IMAGE_CAPTURE for variable rawImagePathFile which is fixed to File(Environment.getExternalStorageDirectory(), "image.jpg"); The image file is created at "/mnt/sdcard/image.jpg" where you can explore it using DDMS. An InputStream bitmap is for the image file is captured and assigned to the ImageView. A target directory is created to store a compressed bitmap image size in form of a jpeg. A png file is considerably larger at five times the size of a jpeg and the percent compressed scale size is ignored so a jpeg is a preferred image format for this POC. The target image file is saved with a System.currentTimeMillis() filename. |
|
|
Press the Next button to switch to the next Activity. The TextView of each Activity shows Activity 1, 2, or 3. The button onClick(..) method has an intent setup for the next ActivityX.class. Method startActivityForResult(..) switches the Activity screen. |
|
|
Short press the button to run the method onClick(..) in setOnClickListener(..). Long press the button to execute callback code in the onContextItemSelected(..) method. See a toast popup for both and a TextView message from the last action remains. The registerForContextMenu(button1) produces a call to onCreateContextMenu(..) to define the Context Menu. |
|
|
ContextMenuSelect_XMLBased-ToastPopUp Short press the button to run the method onClick(..) in setOnClickListener(..). Long press the button to execute callback code in the onContextItemSelected(..) method. See a toast popup for both and a TextView message from the last action remains. The registerForContextMenu(button1) produces a call to onCreateContextMenu(..) to define the Context Menu. The Context Menu is created from the MenuInflater method inflate on file context_menu.xml. |
|
|
Select a menu option and see a toast popup. The Options Menu is created programmatically with menu.add(..) statements in the onCreateOptions(..) callback. Callback, onOptionsItemSelected(..) executes the individuals toasts and leaves a TextView message. |
|
|
OptionsMenuSelect_XMLBased-ToastPopUp Select a menu option and see a toast popup. The Options Menu is created from the MenuInflater method inflate on file menu.xml. Callback, onOptionsItemSelected(..) executes the individuals toasts and leaves a TextView message. |
|
|
Select a tab and see the related Activity. Layout file tab.xml contains the required TabHost TabWidget and FrameLayout elements. A TabHost object is created from the tab.xml element, "@android:id/tabhost". A new TabSpec object is created from the factory method newTabSpec(..) of the TabHost object. The indicator sets the tab name and icon. Two Intents are created for a basic Activity and an Activity defined as a layout. Activity2 is from this library at ButtonPress-LabelShow. |
|
|
Apply a setAdapter(..) on a new ArrayAdapter for a constant string array. Use the android.R.layout.simple_list_item_1 layout. Create a ListView object and apply a click listener anonymous class to it that brings up a Toast. |
|
|
ListActivitySelect_ListInFile-ToastPopUp Apply a setListAdapter(..) on a new ArrayAdapter for a constant string array. Create a ListView object within a ListActivity extended class and apply a click listener anonymous class to it. |
|
|
Apply a setListAdapter(..) on a new ArrayAdapter for a constant string array. Create a ListView object within a ListActivity extended class and apply a click listener anonymous class to it. |
|
|
The Button View is given a click listener. Press of the Button calls the method to change the TextView string. |
|