/[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 771 - (show annotations) (download)
Mon May 31 14:14:59 2010 UTC (13 years, 11 months ago) by torben
File size: 2846 byte(s)
Partial commit - first iteration of saving images to /sdcard/
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 Spinner ontouch = (Spinner) findViewById(R.id.ontouch);
46 ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(this, R.array.ontouchtargets, android.R.layout.simple_spinner_item);
47 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
48
49 ontouch.setAdapter(adapter);
50
51 int ontouchsel = prefs.getInt("ontouch", 0);
52 ontouch.setSelection(ontouchsel);
53
54 }
55
56 private void updateWidget() {
57 AppWidgetManager mgr = AppWidgetManager.getInstance(Side9Config.this);
58
59 Side9WidgetProvider prov = new Side9WidgetProvider();
60 int widgets[] = new int[] { mAppWidgetId };
61
62 prov.onUpdate(this, mgr, widgets );
63
64 }
65
66
67 OnClickListener okListener = new OnClickListener() {
68 @Override
69 public void onClick(View v) {
70
71 CheckBox savetosd = (CheckBox) findViewById(R.id.savetosd);
72 boolean save = savetosd.isChecked();
73
74 Spinner ontouch = (Spinner) findViewById(R.id.ontouch);
75 int ontouchsel = ontouch.getSelectedItemPosition();
76
77 SharedPreferences prefs = getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE);
78
79 Editor edit = prefs.edit();
80 edit.putBoolean("saveimage", save);
81 edit.putInt("ontouch", ontouchsel);
82 edit.commit();
83
84 Intent resultValue = new Intent();
85 resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); //you MUST return this intent
86 setResult(RESULT_OK, resultValue);
87 finish();
88
89 updateWidget();
90 }
91 };
92 }

  ViewVC Help
Powered by ViewVC 1.1.20