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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 854 - (show annotations) (download)
Wed Jun 16 07:40:59 2010 UTC (13 years, 11 months ago) by torben
File size: 3212 byte(s)
Very basic caption support
1 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 @Override
22 public void onCreate(Bundle savedInstanceState) {
23 super.onCreate(savedInstanceState);
24 setContentView(R.layout.config);
25
26 Intent intent = getIntent();
27 Bundle extras = intent.getExtras();
28 if (extras != null) {
29 mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
30 }
31
32 ////////////////////////////////////////////////////////////
33
34
35
36 SharedPreferences prefs = getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE);
37
38 Button okBtn = (Button) findViewById(R.id.ok);
39 okBtn.setOnClickListener( okListener );
40
41 CheckBox savetosd = (CheckBox) findViewById(R.id.savetosd);
42 boolean save = prefs.getBoolean("saveimage", false);
43 savetosd.setChecked(save);
44
45 CheckBox showcaption = (CheckBox) findViewById(R.id.showcaption);
46 boolean show = prefs.getBoolean("showcaption", false);
47 showcaption.setChecked(show);
48
49
50 Spinner ontouch = (Spinner) findViewById(R.id.ontouch);
51 ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(this, R.array.ontouchtargets, android.R.layout.simple_spinner_item);
52 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
53
54 ontouch.setAdapter(adapter);
55
56 int ontouchsel = prefs.getInt("ontouch", 0);
57 ontouch.setSelection(ontouchsel);
58
59 }
60
61 private void updateWidget() {
62 AppWidgetManager mgr = AppWidgetManager.getInstance(Side9Config.this);
63
64 Side9WidgetProvider prov = new Side9WidgetProvider();
65 int widgets[] = new int[] { mAppWidgetId };
66
67 prov.resetStatics(); //force reload
68 prov.onUpdate(this, mgr, widgets );
69
70 }
71
72
73 OnClickListener okListener = new OnClickListener() {
74 @Override
75 public void onClick(View v) {
76
77 CheckBox savetosd = (CheckBox) findViewById(R.id.savetosd);
78 boolean save = savetosd.isChecked();
79
80 CheckBox showcaption = (CheckBox) findViewById(R.id.showcaption);
81 boolean show = showcaption.isChecked();
82
83 Spinner ontouch = (Spinner) findViewById(R.id.ontouch);
84 int ontouchsel = ontouch.getSelectedItemPosition();
85
86 SharedPreferences prefs = getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE);
87
88 Editor edit = prefs.edit();
89 edit.putBoolean("saveimage", save);
90 edit.putBoolean("showcaption", show);
91 edit.putInt("ontouch", ontouchsel);
92 edit.commit();
93
94 Intent resultValue = new Intent();
95 resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); //you MUST return this intent
96 setResult(RESULT_OK, resultValue);
97 finish();
98
99 updateWidget();
100 }
101 };
102 }

  ViewVC Help
Powered by ViewVC 1.1.20