-
-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathTedWidgetConfigActivity.java
More file actions
120 lines (99 loc) · 2.75 KB
/
Copy pathTedWidgetConfigActivity.java
File metadata and controls
120 lines (99 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package org.qpython.qpy.texteditor;
import java.io.File;
import org.qpython.qpy.R;
import org.qpython.qpy.texteditor.common.Constants;
import org.qpython.qpy.texteditor.common.WidgetPrefs;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import org.qpython.qpy.texteditor.androidlib.data.FileUtils;
import org.qpython.qpy.texteditor.androidlib.ui.Toaster;
import org.qpython.qpy.texteditor.androidlib.ui.activity.BrowsingActivity;
@SuppressWarnings("deprecation")
public class TedWidgetConfigActivity extends BrowsingActivity implements Constants, OnClickListener {
/** the id of the widget being configured */
protected int mAppWidgetId;
/** the selected file */
protected File mSelectedFile;
/**
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_widget_config);
setResult(RESULT_CANCELED, null);
// buttons
findViewById(R.id.buttonCancel).setOnClickListener(this);
Toaster.showToast(this, R.string.toast_widget_select, false);
}
/**
* @see android.app.Activity#onResume()
*/
@Override
protected void onResume() {
super.onResume();
// get widget id
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
}
/**
* @see android.view.View.OnClickListener#onClick(android.view.View)
*/
@Override
public void onClick(View v) {
if (v.getId() == R.id.buttonCancel) {
setResult(RESULT_CANCELED);
finish();
}
}
/**
*/
@Override
protected void onFileClick(File file) {
if (file.canRead()) {
mSelectedFile = file;
setResultComplete();
}
}
/**
*/
@Override
protected boolean onFolderClick(File folder) {
mSelectedFile = null;
return true;
}
/**
*/
@Override
protected void onFolderViewFilled() {
}
/**
*
*/
protected void setResultComplete() {
AppWidgetManager appWidgetManager;
Intent resultValue;
WidgetPrefs prefs;
boolean readOnly;
readOnly = ((CheckBox) findViewById(R.id.readOnly)).isChecked();
prefs = new WidgetPrefs();
prefs.mTargetPath = FileUtils.getCanonizePath(mSelectedFile);
prefs.mReadOnly = readOnly;
prefs.store(this, mAppWidgetId);
appWidgetManager = AppWidgetManager.getInstance(this);
TedAppWidgetProvider.updateWidget(this, appWidgetManager, mAppWidgetId);
//
resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
}