Download Seminar Slides

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
COMP 5047 Pervasive Computing
Week 6: Smartphones & the Android OS
Dr.-Ing. Rainer Wasinger
School of Information Technologies
Class Readings
•
•
International Telecommunication Union (2010). Measuring the Information Society
2010 (URL: http://www.itu.int/ITU-D/ict/publications/idi/2010/Material/
MIS_2010_Summary_E.pdf)
– Question 1: What is the IDI? and the ICT Price Basket? and why is the ICT Price
Basket important?
– Question 2: From Table 2, what general conclusions can one draw about the top 25
and bottom 10 economies, with regard to GNI per capita, and ICT Price Basket as %
of GNI per capita (for fixed telephone; mobile cellular; fixed broadband)?
– Question 3: Page 9 states: "The report finds that ICTs can have important
economic and socio-economic benefits, … women into economic activity. " Is the
reasoning sound? Discuss.
Nielsen, J. (2011). Defer Secondary Content When Writing for Mobile Users (URL:
http://www.useit.com/alertbox/mobile-content.html)
– Question 4: Nielsen speaks of most mobile tasks being goal-directed. He also
introduces the notion of progressive disclosure. How does the Android framework
support goal-directed tasks and progressive disclosure?
– Question 5: Nielsen writes that “mobile devices require a tight ous in content
presentation, with the first screen limited to only the most essential information”.
Describe how this applies to your project.
2
Class Readings - Measuring the Information Society 2010, ITU
3
Class Readings - Measuring the Information Society 2010, ITU
• Spider charts illustrating the use of the 11 IDI indicators.
4
Class Readings - Measuring the Information Society 2010, ITU
5
Economy and Internet Trends, Morgan Stanley Slides
6
So what do all the sub-directories mean?
7
Part 1: Android Widgets and more on GUI Design
8
GUI Design for Android Applications
• Two ways to create user interfaces:
– Using Java code and classes.
– Using XML.
• This is the standard method of GUI creation. It is inspired by the web
development model, wherein you can separate the presentation of your
application (its UI) from the application logic used to fetch and fill in data.
• XML layout files should start with an XML declaration, i.e.:
<?xml version=“1.0” encoding=“utf-8”?>
• The first ViewGroup element (e.g. ScrollView, LinearLayout) must also include the
android XML namespace, e.g.:
<ScrollView xmlns:android=“http://schemas.android.com/apk/res/android”
• XML layout files are linked to the code via the method setContentView,
e.g., for a layout page called propertylisting.xml, we would call the
following from within the respective Activity class:
setContentView(R.layout.propertylisting);
Note: Layout filenames must contain the .xml suffix, and only the characters:
“a-z”, “0-9”, and “_.”.
9
Android GUI Widgets (ViewGroups and Views)
10
ViewGroup Widgets (android.view.ViewGroup)
Let’s have a look
at the following:
• LinearLayout
• AbsoluteLayout
(deprecated)
• RelativeLayout
• TableLayout
11
Creating an XML GUI Layout File
1. Open the Android XML file wizard:
2. Fill in the details, as shown
on the right
12
LinearLayout (android.widget.LinearLayout)
•
In LinearLayouts, child widgets are presented either horizontally or
vertically.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=“fill_parent"
android:layout_height=“fill_parent“
android:orientation="horizontal">
<Button android:text="Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:text="Button02“
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:text="Button03“
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
13
LinearLayout (cont.)
•
In LinearLayouts, child widgets are presented either horizontally or
vertically.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=“fill_parent"
android:layout_height="fill_parent“
android:orientation=“vertical">
<Button android:text="Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:text="Button02“
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:text="Button03“
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
14
LinearLayout (cont.)
•
•
android:layout_width="wrap_content“
– “fill_parent”: This means the widget should fill up all available space
in its enclosing container, after all other widgets are taken care of. If
there is no parent, it will fill the entire screen.
– “wrap_content”: This means that the widget should fill up its natural
space, unless that is too big, in which case Android can use word<?xml version="1.0" encoding="utf-8"?>
wrap as needed to make it
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
fit.
android:layout_width=“fill_parent"
android:layout_height=“fill_parent“
– “Xpx”: The width of the
android:orientation=“vertical">
<Button android:text="Button01"
widget in pixels, where X is
android:id="@+id/Button01"
android:layout_width="wrap_content"
a number.
android:layout_height="wrap_content"></Button>
<Button android:text="Button02“
The same values apply for the
android:id="@+id/Button02"
android:layout_width="wrap_content"
attribute android:layout_height.
android:layout_height="wrap_content"></Button>
<Button android:text="Button03“
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
15
RelativeLayout (android.widget.RelativeLayout)
•
In RelativeLayouts, child widgets are placed relative to one other. The
“android:id” parameter is important when using this type of.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:text="Button02"
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/Button01"></Button>
<Button android:text="Button03"
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Button01"></Button>
</RelativeLayout>
16
TableLayout (android.widget.TableLayout)
•
•
In TableLayouts, child widgets are placed into rows and columns. A
TableLayout consists of TableRow widgets, and each row can
effectively have one or more columns.
Other common layout parameters:
– android:layout_gravity={“top”,
“bottom”, “center”, “right”, “left”}
– android:background=“#FFFFFF”
– android:visibility={“visible”,
“invisible”, “gone”}
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow android:id="@+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:text="Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button android:text="Button02"
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</TableRow>
<TableRow android:id="@+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:text="Button03"
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>
17
View Widgets (android.view.View)
Let’s have a look
at the following:
• TextView
• EditText
• Button
• RadioGroup /
RadioButton
• Spinner
18
View Widgets (android.view.View)
19
View Widgets (android.view.View)
•
Text Fields (i.e. EditText’s) and Onscreen Input Methods
Email (top). Password (bottom).
Plain text (top). Time (bottom).
20
TextView, EditText, and View
<TextView android:text="TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textStyle="bold|italic“
android:typeface="sans">
</TextView>
<EditText android:text="EditText01"
android:id="@+id/editText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
Retrieving text from an EditText:
EditText editTextStr = (EditText)findViewById(R.id.editText01);
String fetchedStr = editTextStr.getText().toString();
21
TextView, EditText, and View (cont.)
<TextView android:text="TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textStyle="bold|italic“
android:typeface="sans">
</TextView>
<EditText android:text="EditText01"
android:id="@+id/editText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
<View android:background="#FFFFFF"
android:layout_width="wrap_content"
android:layout_height="1dip"/>
22
View IDs and the R.java File
•
<EditText
Any View object may have an
android:text=“@string/edit_text01"
integer ID associated to it, to
android:id="@+id/editText01"
android:layout_width="wrap_content"
uniquely identify the View within
android:layout_height="wrap_content">
the tree. The ID is typically
</EditText>
assigned in the layout XML file as
a string, though after compilation, it is referenced as an integer in the
R.java file.
•
The @ symbol: This indicates that the XML parser should parse and
expand the rest of the ID string and identify it as an ID resource.
• The @ symbol is used when referencing an existing XML resource.
•
The + symbol: This means that this is a new resource name that must
be created and added to our resources (i.e. in the R.java file).
– The + symbol is used when declaring an XML resource.
23
View IDs and the R.java File (cont.)
R.java
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int textView01=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
public static final int my_string1=0x7f040002;
public static final int my_string2=0x7f040003;
}
main.xml
}
...<TextView android:id="@+id/textView01"
android:text="@string/my_string1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>...
temp.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_string1">A test string resource</string>
<string name="my_string2">Another test string</string>
</resources>
24
Button, RadioGroup/RadioButton, and Spinner
<Button android:id="@+id/button01“
android:text="Button01"
android:layout_width="wrap_content“
android:layout_height="wrap_content">
</Button>
<RadioGroup android:id="@+id/myRadioGroup"
android:layout_width="wrap_content“ android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/radioButton01“
android:text="RadioButton01"
android:layout_width="wrap_content” android:layout_height="wrap_content">
</RadioButton>
<RadioButton android:id="@+id/radioButton02“
android:text="RadioButton02"
android:layout_width="wrap_content“ android:layout_height="wrap_content">
</RadioButton>
</RadioGroup>
<Spinner android:id="@+id/spinner01"
android:layout_width="fill_parent"
android:layout_height="45dp"/>
25
Using android.widget.Button
To capture button clicks, we set up an event listener using the setOnClickListener
method. E.g., we might use an (anonymous) inner class to capture button
clicks, as is defined below:
Button button01=(Button)findViewById(R.id.button01);
button01.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d("PropertyApp", "button01 has just been pressed");
}
});
26
Using android.widget.RadioButton
To get the ID of a currently-checked radio button we use the
getCheckedRadioButtonID method. E.g.:
RadioGroup myRadioGroup;
myRadioGroup=(RadioGroup)findViewById(R.id.myRadioGroup);
int checkedID = myRadioGroup.getCheckedRadioButtonId();
if (checkedID == -1) {
Log.d(TAG, "No radio button was selected.");
} else if (checkedID == R.id.radioButton01) {
Log.d(TAG, "'radioButton01' was selected.");
populatePropertyCatalog(false); //creates the property catalog
//using 'buy' data.
} else if (checkedID == R.id.radioButton02) {
Log.d(TAG, "'radioButton02' was selected.");
populatePropertyCatalog(true); //creates the property catalog
//using 'rent' data.
}
27
Using android.widget.Spinner
public class PropertyApp extends Activity implements OnItemSelectedListener {
String[] spinner01Items = {"---", "Apartment", "House", "Land"};
...
public void initialiseSearchPageGUI() {
Spinner spinner01=(Spinner)findViewById(R.id.spinner01);
spinner01.setOnItemSelectedListener(this);
ArrayAdapter<String> spinner01AA = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
spinner01Items);
spinner01AA.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spinner01.setAdapter(spinner01AA);
...
}
...
//Callback method to be invoked when an item in this view has been selected.
public void onItemSelected(AdapterView<?> parent, View v, int position, long id){
} //onItemSelected
//Callback method to be invoked when the selection disappears from this view.
public void onNothingSelected(AdapterView<?> parent) {
} //onNothingSelected
...
28
Using android.widget.Spinner (cont.)
public class PropertyApp extends Activity implements OnItemSelectedListener {
String[] spinner01Items = {"---", "Apartment", "House", "Land"};
...
public void initialiseSearchPageGUI() {
Spinner spinner01=(Spinner)findViewById(R.id.spinner01);
spinner01.setOnItemSelectedListener(this);
ArrayAdapter<String> spinner01AA = new ArrayAdapter<String>(
this,
We use the Activity itself as
android.R.layout.simple_list_item_1,
the listener, which is possible
spinner01Items);
because the Activity
spinner01AA.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item); implements the
OnItemSelectedListener
spinner01.setAdapter(spinner01AA);
interface.
...
}
...above event handling could also be implemented as an anonymous inner class:
The
//Callback method to be invoked when an item OnItemSelectedListener(){
in this view has been selected.
spinner01.setOnItemSelectedListener(new
public
void onItemSelected(AdapterView<?> parent, View v, int position, long id){
@Override
} //onItemSelected
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long
arg3) { /*Do something*/ }
@Override
//Callback
method to be invoked when the selection disappears from this view.
public
onNothingSelected(AdapterView<?>
public
voidvoid
onNothingSelected(AdapterView<?>
parent) { arg0) { /*Do something*/ }
});
} //onNothingSelected
...
29
Using android.widget.Spinner (cont.)
public class PropertyApp extends Activity implements OnItemSelectedListener {
String[] spinner01Items = {"---", "Apartment", "House", "Land"};
...
public void initialiseSearchPageGUI() {
Spinner spinner01=(Spinner)findViewById(R.id.spinner01);
spinner01.setOnItemSelectedListener(this);
ArrayAdapter<String> spinner01AA = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
spinner01Items);
spinner01AA.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
•Adapters
provide
a common interface to the data model behind a selection-style widget.
spinner01.setAdapter(spinner01AA);
...
•ArrayAdapter
is one of the easiest to use adapters. It takes three parameters:
}
• Context context: The context to use, typically the Activity instance.
...
//Callback
to beThe
invoked
when ID
anofitem
in this
view
hasas
been
selected.
• intmethod
resource:
resource
a view
to use,
such
a built-in
system
public void
onItemSelected(AdapterView<?>
parent,
View v, int position, long id){
resource
ID as shown in the example
above.
} //onItemSelected
•
int textViewResourceId: The actual list of items to show.
//Callback method to be invoked when theisselection
disappears
from
this
view.
•android.R.layout.simple_list_item_1:
used to format
your list
with
one
TextView in
public
void
onNothingSelected(AdapterView<?>
{
each
row.
This
text is large, white, and centredparent)
vertically.
} //onNothingSelected
...
30
Using android.widget.Spinner
public class PropertyApp extends Activity implements OnItemSelectedListener {
String[] spinner01Items = {"---", "Apartment", "House", "Land"};
...
public void initialiseSearchPageGUI() {
Spinner spinner01=(Spinner)findViewById(R.id.spinner01);
spinner01.setOnItemSelectedListener(this);
ArrayAdapter<String> spinner01AA = new ArrayAdapter<String>(
this,
setDropDownViewResource:
android.R.layout.simple_list_item_1,
Sets a specific resource to
spinner01Items);
use for the drop-down view, in
spinner01AA.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item); this case the built-in system
spinner01.setAdapter(spinner01AA);
resource:
...
“simple_spinner_dropdown_it
}
em”
...
//Callback method to be invoked when an item in this view has been selected.
public void onItemSelected(AdapterView<?> parent, View v, int position, long id){
} //onItemSelected
//Callback method to be invoked when the selection disappears from this view.
public void onNothingSelected(AdapterView<?> parent) {
} //onNothingSelected
...
31
COMP5047 PropertyApp Screenshots
•
Screenshots (as shown in last week’s lecture)
searchpage.xml
•
•
•
propertylisting.xml,
propertylistrow.xml
propertydetails.xml
searchpage.xml:
•
A vertical LinearLayout, containing a number of horizontal LinearLayouts that
themselves encompass a range of standard View widgets.
propertylisting.xml and propertylistrow.xml:
•
A LinearLayout containing a ListView.
•
Each element in the ListView is a horizontal LinearLayout, encompassing:
•
An ImageView, and a
•
Vertical LinearLayout containing a TextView and a TableLayout that holds a
number of parameters.
propertydetails.xml:
•
A ScrollView, containing a vertical LinearLayout that contains a TextView,
ImageView, TableLayout, and another TextView.
32
Part 2: More on Activities and Intents
33
COMP5047 PropertyApp Class Diagram
User interaction
between Activities
AndroidManifest.xml
propertylistrow.xml
searchpage.xml
propertylisting.xml
propertydetails.xml
PropertyApp
PropertyList
PropertyDetails
(extends Activity)
(extends Activity)
(extends Activity)
PropertyListAdapter
Write data into
database
1
1
(extends ArrayAdapter<Property>)
Retrieve data
from database
1
PropertyDB
DatabaseHelper
1…*
Property
Retrieve
data from
database
propertydata
(extends SQLiteOpenHelper)
…_buy.xml
…_rent.xml
XMLParser
XMLUnmarshaller
(extends DefaultHandler)
XMLPropertyCatalog
…
34
Activities and Intents
• Activity (android.app.Activity):
– Activities represent the building block of the user
interface.
– Activities are used to present a visual user interface for
one focused endeavour that the user can undertake.
• Intent (android.content.Intent):
– An Intent is an abstract description of an operation to be
performed.
– An Intent’s most significant use is in the launching of
activities, where it can be thought of as the glue
between activities.
– Intents are basically a passive data structure holding an
abstract description of an action to be performed.
35
Intents – Another look at the PropertyApp
AndroidManifest.xml File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="au.edu.usyd.it.PropertyApp"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".PropertyApp“ 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=".PropertyList“ android:label="@string/app_name">
</activity>
<activity android:name=".PropertyDetails“ android:label="@string/app_name">
</activity>
</application>
<uses-sdk android:minSdkVersion=“2" />
</manifest>
Note how each Activity in the PropertyApp application is defined in the AndroidManifest.xml
file. This is needed in applications that utilise explicit intents. If not in the manifest, we
would receive an ActivityNotFoundException at runtime.
36
Creating an Intent and passing it to the Android OS
• If the activity you intend to launch is part of your own
application, it is simplest to create an explicit intent that
names the component that you wish to launch (remember
that the activity also needs to be named in the
AndroidManifest.xml file). E.g.:
//Create an intent for a specific component.
//Intent(Context packageContext, Class<?> cls)
Intent i = new Intent(PropertyApp.this, PropertyList.class);
• The next step is to pass the Intent to Android and get the
child activity to launch. The simplest option is to call
startActivity(Intent i), which gets Android to find the bestmatch activity and pass the intent to it for handling. E.g.:
startActivity(i);
37
Intent Extras – Putting and Getting Extras
• Extras: Extras are key-value pairs that contain additional
information that should be delivered to the component
handling the intent. E.g.:
– Placing the Extra from inside the PropertyApp class:
i.putExtra(PropertyApp.EXTRA_TO_RENT, “false”);
– Retrieving the Extra from inside the PropertyList class:
toRentStr = extras != null ?
extras.getString(PropertyApp.EXTRA_TO_RENT) : null;
i.e. if "extras!=null", then
toRentStr=extras.getString(PropertyApp.EXTRA_TO_RENT), else
toRentStr=null.
38
Intent Extras - The Full Example
public class PropertyApp extends Activity implements OnItemSelectedListener {
public static final String
EXTRA_PROPERTY_ID="au.edu.usyd.it.PropertyApp.property_id";
public static final String
EXTRA_TO_RENT="au.edu.usyd.it.PropertyApp.to_rent";
...
public void initialiseSearchPageGUI() {
Intent i = new Intent(PropertyApp.this, PropertyList.class);
i.putExtra(PropertyApp.EXTRA_TO_RENT, “false”);
startActivity(i);
Note: The au.edu.usyd.it.PropertyApp
...
namespace is used to ensure that the
'extra' name will not collide with any
names perhaps in use by the Android
system.
public class PropertyList extends Activity {
...
protected void onCreate(Bundle savedInstanceState) {
String toRentStr = null;
boolean toRent = false;
Bundle extras = getIntent().getExtras();
toRentStr = extras != null ?
extras.getString(PropertyApp.EXTRA_TO_RENT) : null;
toRent = Boolean.parseBoolean(toRentStr);
39
COMP5047 PropertyApp SQLite Database
• SQLite Manager Add-on for Firefox
40
Security Permissions
• A quick look at defining security permissions in an Android
App.
41
Security Permissions (cont.)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apt.tutorial.two“ android:versionCode="1“
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
...
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application android:label="@string/app_name">
<activity android:name=".Patchy“ android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
See http://developer.android.com/reference/android/Manifest.permission.html for a full list of permissions.
</manifest>
There are currently over 100 that have been defined.
42
Part 3: Smartphone Design
43
Mobile Device Design
• Typical mobile device limitations:
– Processor, memory, display size (e.g. might require
extensive scrolling), modes of input (e.g. 12-key
numeric keypad; touch-screen).
• System Designer Choices
– E.g. menu placement, location of physical buttons,
button sizes, choice of hardware (e.g. capacitive /
resistive touch screens).
• Input Interaction / Output Presentation:
– Input: Speech, handwriting, stylus/finger input, sensorbased input.
– Output: Sound, graphics, video, haptic/vibration,
projection.
44
Mobile Phone Target Groups
•
•
Feature phones: These are low-end mobile phones providing basic voice
communication, as well as functionalities like playing music, taking photos, and
sometimes also simple applications (e.g. based on Java ME or BREW).
Smartphones (see week 5 lecture slides): Support in addition to voice
communication, PIM, and typically also email, Internet, and rich 3rd party
applications.
Low-end
Mid-range
High-end
Luxury
45
Part 4: PersonisJ: A Mobile Client-Side User
Modelling Framework (cont.)
46
PersonisJ: Example Application
COMP5047PersonisJExample:
47
PersonisJ: Example Application
• Two classes to look at:
– PersonisJExample activity:
• Checks if PersonisJ is installed and whether it is on the
PersonisJ whitelist. It then calls AppModel to create the model.
appModel.createUserModel();
• Creates the UI, incl. the tell and ask buttons:
– Tell:
appModel.savePersonalInformationEvidence
(evidence.toString());
– Ask:
String evidenceStr = appModel.
retrievePersonalInformationEvidence();
– AppModel:
• This is where the real work is done.
48
PersonisJ Example Application
•
AppModel:
1. Looking up the model:
Model pModel = Model.getPhoneModel(context);
2.
Passing PersonisJ this application’s model representation:
pModel.importFromJSON(readString);
(based on the definition in the R.raw.usermodel_definition file).
3.
Telling PersonisJ a new evidence:
Component c = pModel.getComponentByPath(“Applications/
PersonisJExample/Profile/PersonalInformation”);
c.tell(evidence, Personis.Component.VALUE_TYPE_STRING,
Personis.Evidence.TYPE_GIVEN);
4. Asking PersonisJ for an evidence:
String evidence = c.ask(eResolver, eFilter);
49
PersonisJ Example Application
{
"contextinfo": {
"Description": "Applications",
"Identifier": "Applications",
"resolver": ""
},
"contexts": {
"PersonisJExample": {
"contextinfo": {
"Description": "Example application that makes use of
PersonisJ",
"Identifier": "PersonisJExample",
"resolver": ""
},
"contexts": {
"Profile": {
"contextinfo": {
"Description": "User profile, containing information
about the user",
"Identifier": "Profile",
"resolver": ""
},
"contexts": {},
"components": {
"PersonalInformation": {
"valueType": "string",
"componentType": "attribute",
"Description": "The user's personal information",
"Identifier": "PersonalInformation",
"evidenceList": [],
"resolver": "",
"value": null
}
},
"views": {},
"subs": {}
}
},
"components": {},
"views": {},
"subs": {}
}
},
"components": {},
"views": {},
"subs": {}
PersonisJ Model JSON Format:
•
At the top level context, the model is encoded in
JSON as a dictionary:
{“contextinfo”:contextinfo, “contexts”:thecontexts,
“components”:thecomps, “views”:theviews,
“subs”:thesubs}
•
contextinfo: is a dictionary containing
information about the context, in particular:
“Description”, “Identifier”, and “resolver”.
•
thecontexts: is a dictionary containing an entry
for each subcontext: key is the context name,
value is the subcontext encoded as above.
•
component: An object encoded as a dictionary
containing: “Description”, “Identifier”,
“componentType”, “evidenceList”, “resolver”,
“valueType”, and “value”.
•
evidence: An object encoded as a dictionary
containing: “value”, “evidenceType”, “exp_time”,
“source”, “time”, “flags”, and “comment”.
"contextinfo": {},
"contexts": {},
"components": {},
"views": {},
"subs": {}
}
50