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+ }
0 commit comments