/[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 778 - (hide annotations) (download)
Tue Jun 1 09:14:19 2010 UTC (14 years ago) by torben
File size: 2885 byte(s)
Some more force reload when creating or removing the widget
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     @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 torben 778 prov.resetStatics(); //force reload
63 torben 771 prov.onUpdate(this, mgr, widgets );
64    
65     }
66    
67    
68     OnClickListener okListener = new OnClickListener() {
69     @Override
70     public void onClick(View v) {
71    
72     CheckBox savetosd = (CheckBox) findViewById(R.id.savetosd);
73     boolean save = savetosd.isChecked();
74    
75     Spinner ontouch = (Spinner) findViewById(R.id.ontouch);
76     int ontouchsel = ontouch.getSelectedItemPosition();
77    
78     SharedPreferences prefs = getSharedPreferences(Side9WidgetProvider.TAG, Context.MODE_PRIVATE);
79    
80     Editor edit = prefs.edit();
81     edit.putBoolean("saveimage", save);
82     edit.putInt("ontouch", ontouchsel);
83     edit.commit();
84    
85     Intent resultValue = new Intent();
86     resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); //you MUST return this intent
87     setResult(RESULT_OK, resultValue);
88     finish();
89    
90     updateWidget();
91     }
92     };
93     }

  ViewVC Help
Powered by ViewVC 1.1.20