Skip to content

Commit 09b4fd2

Browse files
committed
updated UI for context accuracy
1 parent bcb4077 commit 09b4fd2

File tree

15 files changed

+511
-407
lines changed

15 files changed

+511
-407
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/***
2+
Copyright (c) 2008-2011 CommonsWare, LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
not use this file except in compliance with the License. You may obtain
6+
a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
package edu.fsu.cs.contextprovider;
16+
17+
import android.app.Activity;
18+
19+
import android.os.Bundle;
20+
import android.os.PowerManager;
21+
import android.app.ListActivity;
22+
import android.content.Context;
23+
import android.content.Intent;
24+
import android.view.View;
25+
import android.view.ViewGroup;
26+
import android.view.LayoutInflater;
27+
import android.view.Window;
28+
import android.view.WindowManager;
29+
import android.widget.AdapterView;
30+
import android.widget.ArrayAdapter;
31+
import android.widget.RadioButton;
32+
import android.widget.RatingBar;
33+
import android.widget.LinearLayout;
34+
import android.widget.ListView;
35+
import android.widget.TextView;
36+
import android.widget.Toast;
37+
38+
import java.util.ArrayList;
39+
import java.util.Timer;
40+
import java.util.TimerTask;
41+
42+
import edu.fsu.cs.contextprovider.data.ContextConstants;
43+
import edu.fsu.cs.contextprovider.dialog.*;
44+
import edu.fsu.cs.contextprovider.monitor.DerivedMonitor;
45+
import edu.fsu.cs.contextprovider.monitor.LocationMonitor;
46+
import edu.fsu.cs.contextprovider.monitor.MovementMonitor;
47+
import edu.fsu.cs.contextprovider.monitor.SocialMonitor;
48+
import edu.fsu.cs.contextprovider.monitor.SystemMonitor;
49+
import edu.fsu.cs.contextprovider.monitor.WeatherMonitor;
50+
51+
public class ContextAccuracyActivity extends ListActivity {
52+
// private static final String[] items = { "Location", "Movement", "Weather", "Social", "System", "Derived" };
53+
54+
private PowerManager.WakeLock wakelock;
55+
private static Timer timer = new Timer();
56+
private long DISMISS_TIMEOUT = 30;
57+
58+
@Override
59+
public void onCreate(Bundle icicle) {
60+
super.onCreate(icicle);
61+
62+
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
63+
wakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "ContextAccuracyActivity");
64+
65+
ArrayList<ContextRowModel> list = new ArrayList<ContextRowModel>();
66+
67+
// for (String string : items) { list.add(new ContextRowModel(string)); }
68+
ContextRowModel locationModel = new ContextRowModel("Location", LocationMonitor.getAddress());
69+
list.add(locationModel);
70+
ContextRowModel movementModel = new ContextRowModel("Movement", MovementMonitor.getMovementState());
71+
list.add(movementModel);
72+
ContextRowModel weatherModel = new ContextRowModel("Weather", WeatherMonitor.getWeatherCond());
73+
list.add(weatherModel);
74+
ContextRowModel socialModel = new ContextRowModel("Social", SocialMonitor.getContact());
75+
list.add(socialModel);
76+
ContextRowModel systemModel = new ContextRowModel("System", String.valueOf(SystemMonitor.isBatteryPlugged()));
77+
list.add(systemModel);
78+
ContextRowModel derivedModel = new ContextRowModel("Derived", DerivedMonitor.getActivity());
79+
list.add(derivedModel);
80+
81+
setListAdapter(new ContextAdapter(list));
82+
83+
timer.schedule(new ContextDismissTask(), (DISMISS_TIMEOUT*1000));
84+
}
85+
86+
@Override
87+
protected void onPause() {
88+
super.onPause();
89+
wakelock.release();
90+
}
91+
92+
@Override
93+
protected void onResume() {
94+
super.onResume();
95+
wakelock.acquire();
96+
}
97+
98+
private ContextRowModel getModel(int position) {
99+
return (((ContextAdapter) getListAdapter()).getItem(position));
100+
}
101+
102+
class ContextAdapter extends ArrayAdapter<ContextRowModel> {
103+
ContextAdapter(ArrayList<ContextRowModel> list) {
104+
super(ContextAccuracyActivity.this, R.layout.accuracyrow, R.id.label, list);
105+
}
106+
107+
public View getView(int position, View convertView, ViewGroup parent) {
108+
View row = super.getView(position, convertView, parent);
109+
// ContextViewHolder holder = (ContextViewHolder) row.getTag();
110+
// if (holder == null) {
111+
// holder = new ContextViewHolder(row);
112+
// row.setTag(holder);
113+
// RadioButton.OnClickListener myOptionOnClickListener = new RadioButton.OnClickListener() {
114+
// public void onClick(View v) {
115+
// Integer myPosition = (Integer) v.getTag();
116+
// ContextRowModel model = getModel(myPosition);
117+
// Toast.makeText(ContextAccuracyActivity.this, "Option 1 : " + "\n", Toast.LENGTH_LONG).show();
118+
// }
119+
// };
120+
// }
121+
// ContextRowModel model = getModel(position);
122+
return (row);
123+
}
124+
}
125+
126+
class ContextRowModel {
127+
String label;
128+
String context;
129+
Boolean accurate = true;
130+
RadioButton rb1;
131+
RadioButton rb2;
132+
TextView contextText;
133+
134+
ContextRowModel(String label, String context) {
135+
this.label = label;
136+
this.context = context;
137+
}
138+
139+
// public ContextRowModel(View base) {
140+
// this.rb1 = (RadioButton) base.findViewById(R.id.radioYes);
141+
// this.rb2 = (RadioButton) base.findViewById(R.id.radioNo);
142+
// this.contextText = (TextView) base.findViewById(R.id.currentContext);
143+
// if(rb1.isChecked() == true) {
144+
// accurate = true;
145+
// } else if(rb2.isChecked() == true) {
146+
// accurate = false;
147+
// }
148+
// }
149+
}
150+
151+
152+
private class ContextDismissTask extends TimerTask
153+
{
154+
public void run()
155+
{
156+
Intent intent = new Intent(ContextConstants.CONTEXT_STORE_INTENT);
157+
intent.putExtra(ContextConstants.LOCATION_ACCURATE, true);
158+
intent.putExtra(ContextConstants.MOVEMENT_ACCURATE, true);
159+
intent.putExtra(ContextConstants.WEATHER_ACCURATE, true);
160+
intent.putExtra(ContextConstants.SOCIAL_ACCURATE, true);
161+
intent.putExtra(ContextConstants.SYSTEM_ACCURATE, true);
162+
intent.putExtra(ContextConstants.DERIVED_ACCURATE, true);
163+
sendBroadcast(intent);
164+
165+
finish();
166+
}
167+
}
168+
}

res/drawable/derived.png

4.17 KB
Loading

res/drawable/location.png

4.57 KB
Loading

res/drawable/movement.png

4.26 KB
Loading

res/drawable/social.png

4.07 KB
Loading

res/drawable/system.png

2.5 KB
Loading

res/drawable/weather.png

4.21 KB
Loading

res/layout/accuracy.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="fill_parent"
5+
android:layout_height="fill_parent">
6+
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
7+
<TextView android:layout_height="wrap_content" android:id="@+id/accuracyDescription" android:layout_width="fill_parent" android:paddingBottom="15px" android:text="@string/accuracy_message"></TextView>
8+
<TextView android:layout_height="wrap_content" android:id="@+id/locationHeader" android:text="@string/locationTitle" android:layout_width="wrap_content"></TextView>
9+
<LinearLayout android:id="@+id/linearLayout8" android:layout_width="fill_parent" android:layout_height="wrap_content">
10+
<ImageView android:id="@+id/imageView1" android:src="@drawable/location" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
11+
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:editable="false" android:text="@string/locationTitle" android:id="@+id/editLocation"></EditText>
12+
</LinearLayout>
13+
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:paddingBottom="10px" android:layout_height="wrap_content">
14+
<TextView android:layout_height="wrap_content" android:id="@+id/textView1" android:text="@string/accuracy" android:layout_width="wrap_content"></TextView>
15+
<SeekBar android:layout_width="fill_parent" android:id="@+id/location" android:layout_height="wrap_content" android:paddingLeft="20px" android:paddingRight="30px"></SeekBar>
16+
</LinearLayout>
17+
<TextView android:layout_height="wrap_content" android:id="@+id/movementHeader" android:text="@string/movementTitle" android:layout_width="wrap_content"></TextView>
18+
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content">
19+
<ImageView android:id="@+id/imageView2" android:src="@drawable/movement" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
20+
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/movementTitle" android:editable="false" android:id="@+id/editMovement"></EditText>
21+
</LinearLayout>
22+
<LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:paddingBottom="10px" android:layout_height="wrap_content">
23+
<TextView android:layout_height="wrap_content" android:id="@+id/textView2" android:text="@string/accuracy" android:layout_width="wrap_content"></TextView>
24+
<SeekBar android:layout_width="fill_parent" android:id="@+id/movement" android:layout_height="wrap_content" android:paddingRight="30px" android:paddingLeft="20px"></SeekBar>
25+
</LinearLayout>
26+
<TextView android:layout_height="wrap_content" android:id="@+id/weatherHeader" android:text="@string/weatherTitle" android:layout_width="wrap_content"></TextView>
27+
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content">
28+
<ImageView android:id="@+id/ImageView01" android:src="@drawable/weather" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
29+
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/weatherTitle" android:id="@+id/editWeather" android:editable="false"></EditText>
30+
</LinearLayout>
31+
<LinearLayout android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:paddingBottom="10px" android:layout_height="wrap_content">
32+
<TextView android:layout_height="wrap_content" android:id="@+id/textView3" android:text="@string/accuracy" android:layout_width="wrap_content"></TextView>
33+
<SeekBar android:layout_width="fill_parent" android:id="@+id/weather" android:layout_height="wrap_content" android:paddingLeft="20px" android:paddingRight="30px"></SeekBar>
34+
</LinearLayout>
35+
<TextView android:layout_height="wrap_content" android:id="@+id/socialHeader" android:text="@string/socialTitle" android:layout_width="wrap_content"></TextView>
36+
<LinearLayout android:id="@+id/LinearLayout03" android:layout_width="fill_parent" android:layout_height="wrap_content">
37+
<ImageView android:id="@+id/ImageView02" android:src="@drawable/social" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
38+
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/socialTitle" android:id="@+id/editSocial" android:editable="false"></EditText>
39+
</LinearLayout>
40+
<LinearLayout android:id="@+id/linearLayout4" android:layout_width="fill_parent" android:paddingBottom="10px" android:layout_height="wrap_content">
41+
<TextView android:layout_height="wrap_content" android:id="@+id/textView4" android:text="@string/accuracy" android:layout_width="wrap_content"></TextView>
42+
<SeekBar android:layout_width="fill_parent" android:id="@+id/social" android:layout_height="wrap_content" android:paddingLeft="20px" android:paddingRight="30px"></SeekBar>
43+
</LinearLayout>
44+
<TextView android:layout_height="wrap_content" android:id="@+id/systemHeader" android:text="@string/systemTitle" android:layout_width="wrap_content"></TextView>
45+
<LinearLayout android:id="@+id/LinearLayout05" android:layout_width="fill_parent" android:layout_height="wrap_content">
46+
<ImageView android:id="@+id/ImageView04" android:src="@drawable/system" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
47+
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/editSystem" android:text="@string/systemTitle" android:editable="false"></EditText>
48+
</LinearLayout>
49+
<LinearLayout android:id="@+id/linearLayout5" android:layout_width="fill_parent" android:paddingBottom="10px" android:layout_height="wrap_content">
50+
<TextView android:layout_height="wrap_content" android:id="@+id/textView5" android:text="@string/accuracy" android:layout_width="wrap_content"></TextView>
51+
<SeekBar android:layout_width="fill_parent" android:id="@+id/system" android:layout_height="wrap_content" android:paddingLeft="20px" android:paddingRight="30px"></SeekBar>
52+
</LinearLayout>
53+
<TextView android:layout_height="wrap_content" android:id="@+id/derivedHeader" android:text="@string/derivedTitle" android:layout_width="wrap_content"></TextView>
54+
<LinearLayout android:id="@+id/LinearLayout04" android:layout_width="fill_parent" android:layout_height="wrap_content">
55+
<ImageView android:id="@+id/ImageView03" android:src="@drawable/derived" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
56+
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/editDerived" android:text="@string/derivedTitle" android:editable="false"></EditText>
57+
</LinearLayout>
58+
<LinearLayout android:id="@+id/linearLayout6" android:layout_width="fill_parent" android:paddingBottom="10px" android:layout_height="wrap_content">
59+
<TextView android:layout_height="wrap_content" android:id="@+id/textView6" android:text="@string/accuracy" android:layout_width="wrap_content"></TextView>
60+
<SeekBar android:layout_width="fill_parent" android:id="@+id/derived" android:layout_height="wrap_content" android:paddingLeft="20px" android:paddingRight="30px"></SeekBar>
61+
</LinearLayout>
62+
<LinearLayout android:id="@+id/linearLayout7" android:layout_width="wrap_content" android:layout_height="fill_parent" android:paddingTop="10px">
63+
<Button android:id="@+id/SubmitButton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/submit"></Button>
64+
<Button android:id="@+id/ResetButton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/reset"></Button>
65+
</LinearLayout>
66+
</LinearLayout>
67+
</ScrollView>

res/raw/changelog

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<small>*** Notice ***
2-
Welcome to Event Power Log!
32

4-
<b>Version 0.0.1</b>
5-
- Were almost working!
3+
<b>Version 0.45</b>
4+
Context persistence; prefs expanded; corrupt file fix
5+
<b>Version 0.44</b>
6+
added orm store functions for each monitor
7+
<b>Version 0.43</b>
8+
Implemented ui for context accuracy popup
9+
<b>Version 0.42</b>
10+
Expanded prefs; context accuracy popup test service
11+
<b>Version 0.41</b>
12+
Corrected conflict merge errors
613

714
</small>

0 commit comments

Comments
 (0)