/[projects]/android/Side9/src/dk/thoerup/side9/Side9Config.java
ViewVC logotype

Annotation of /android/Side9/src/dk/thoerup/side9/Side9Config.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 857 - (hide annotations) (download)
Wed Jun 16 07:51:40 2010 UTC (13 years, 11 months ago) by torben
File size: 3425 byte(s)
Use string constants for preference labels
1 torben 771 package dk.thoerup.side9;
2    
3     import android.app.Activity;
4     import android.appwidget.AppWidgetManager;
5     import android.content.Context;
6     import android.content.Intent;
7     import android.content.SharedPreferences;
8     import android.content.SharedPreferences.Editor;
9     import android.os.Bundle;
10     import android.view.View;
11     import android.view.View.OnClickListener;
12     import android.widget.ArrayAdapter;
13     import android.widget.Button;
14     import android.widget.CheckBox;
15     import android.widget.Spinner;
16    
17    
18     public class Side9Config extends Activity {
19     int mAppWidgetId;
20    
21 torben 857 public final static String PREFS_SAVEIMAGE = "saveimage";
22     public final static String PREFS_SHOWCAPTION = "showcaption";
23     public final static String PREFS_ONTOUCH = "ontouch";
24    
25    
26    
27 torben 771 @Override
28     public void onCreate(Bundle savedInstanceState) {
29     super.onCreate(savedInstanceState);
30     setContentView(R.layout.config);
31    
32     Intent intent = getIntent();
33     Bundle extras = intent.getExtras();
34     if (extras != null) {
35     mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
36     }
37    
38     ////////////////////////////////////////////////////////////
39    
40    
41    
42     SharedPreferences prefs = getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE);
43    
44     Button okBtn = (Button) findViewById(R.id.ok);
45     okBtn.setOnClickListener( okListener );
46    
47     CheckBox savetosd = (CheckBox) findViewById(R.id.savetosd);
48 torben 857 boolean save = prefs.getBoolean(PREFS_SAVEIMAGE, false);
49 torben 854 savetosd.setChecked(save);
50 torben 771
51 torben 854 CheckBox showcaption = (CheckBox) findViewById(R.id.showcaption);
52 torben 857 boolean show = prefs.getBoolean(PREFS_SHOWCAPTION, false);
53 torben 854 showcaption.setChecked(show);
54    
55    
56 torben 771 Spinner ontouch = (Spinner) findViewById(R.id.ontouch);
57     ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(this, R.array.ontouchtargets, android.R.layout.simple_spinner_item);
58     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
59    
60     ontouch.setAdapter(adapter);
61    
62 torben 857 int ontouchsel = prefs.getInt(PREFS_ONTOUCH, 0);
63 torben 771 ontouch.setSelection(ontouchsel);
64    
65     }
66    
67     private void updateWidget() {
68     AppWidgetManager mgr = AppWidgetManager.getInstance(Side9Config.this);
69    
70     Side9WidgetProvider prov = new Side9WidgetProvider();
71     int widgets[] = new int[] { mAppWidgetId };
72    
73 torben 778 prov.resetStatics(); //force reload
74 torben 771 prov.onUpdate(this, mgr, widgets );
75    
76     }
77    
78    
79     OnClickListener okListener = new OnClickListener() {
80     @Override
81     public void onClick(View v) {
82    
83     CheckBox savetosd = (CheckBox) findViewById(R.id.savetosd);
84     boolean save = savetosd.isChecked();
85 torben 854
86     CheckBox showcaption = (CheckBox) findViewById(R.id.showcaption);
87     boolean show = showcaption.isChecked();
88 torben 771
89     Spinner ontouch = (Spinner) findViewById(R.id.ontouch);
90     int ontouchsel = ontouch.getSelectedItemPosition();
91    
92     SharedPreferences prefs = getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE);
93    
94     Editor edit = prefs.edit();
95 torben 857 edit.putBoolean(PREFS_SAVEIMAGE, save);
96     edit.putBoolean(PREFS_SHOWCAPTION, show);
97     edit.putInt(PREFS_ONTOUCH, ontouchsel);
98 torben 771 edit.commit();
99    
100     Intent resultValue = new Intent();
101     resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); //you MUST return this intent
102     setResult(RESULT_OK, resultValue);
103     finish();
104    
105     updateWidget();
106     }
107     };
108     }

  ViewVC Help
Powered by ViewVC 1.1.20