31
31
import android .util .Log ;
32
32
import android .view .View ;
33
33
import android .widget .Button ;
34
+ import android .widget .CheckBox ;
34
35
import android .widget .RemoteViews ;
35
36
import android .widget .Spinner ;
36
37
import android .widget .Toast ;
@@ -58,6 +59,7 @@ public class WidgetConfigurationActivity extends Activity {
58
59
private int mAppWidgetId ;
59
60
60
61
private Spinner mAccountsSpinner ;
62
+ private CheckBox mShouldDisplayBalance ;
61
63
private Button mOkButton ;
62
64
private Button mCancelButton ;
63
65
@@ -68,6 +70,7 @@ public void onCreate(Bundle savedInstanceState) {
68
70
setResult (RESULT_CANCELED );
69
71
70
72
mAccountsSpinner = (Spinner ) findViewById (R .id .input_accounts_spinner );
73
+ mShouldDisplayBalance = (CheckBox ) findViewById (R .id .input_should_display_balance );
71
74
mOkButton = (Button ) findViewById (R .id .btn_save );
72
75
mCancelButton = (Button ) findViewById (R .id .btn_cancel );
73
76
@@ -83,7 +86,11 @@ public void onCreate(Bundle savedInstanceState) {
83
86
//without this line, the app crashes when a user tries to select an account
84
87
cursorAdapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
85
88
mAccountsSpinner .setAdapter (cursorAdapter );
86
-
89
+
90
+ boolean passcodeEnabled = PreferenceManager .getDefaultSharedPreferences (getApplicationContext ())
91
+ .getBoolean (UxArgument .ENABLED_PASSCODE , false );
92
+ mShouldDisplayBalance .setChecked (!passcodeEnabled );
93
+
87
94
bindListeners ();
88
95
}
89
96
@@ -109,13 +116,15 @@ public void onClick(View v) {
109
116
}
110
117
111
118
long accountId = mAccountsSpinner .getSelectedItemId ();
119
+ boolean shouldDisplayBalance = mShouldDisplayBalance .isChecked ();
112
120
String accountUID = mAccountsDbAdapter .getUID (accountId );
113
121
SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (WidgetConfigurationActivity .this );
114
122
Editor editor = prefs .edit ();
115
123
editor .putString (UxArgument .SELECTED_ACCOUNT_UID + mAppWidgetId , accountUID );
124
+ editor .putBoolean (UxArgument .SHOULD_DISPLAY_BALANCE + mAppWidgetId , shouldDisplayBalance );
116
125
editor .commit ();
117
126
118
- updateWidget (WidgetConfigurationActivity .this , mAppWidgetId , accountUID );
127
+ updateWidget (WidgetConfigurationActivity .this , mAppWidgetId , accountUID , shouldDisplayBalance );
119
128
120
129
Intent resultValue = new Intent ();
121
130
resultValue .putExtra (AppWidgetManager .EXTRA_APPWIDGET_ID , mAppWidgetId );
@@ -140,7 +149,7 @@ public void onClick(View v) {
140
149
* @param appWidgetId ID of the widget to be updated
141
150
* @param accountUID GUID of the account tied to the widget
142
151
*/
143
- public static void updateWidget (final Context context , int appWidgetId , String accountUID ) {
152
+ public static void updateWidget (final Context context , int appWidgetId , String accountUID , boolean shouldDisplayBalance ) {
144
153
Log .i ("WidgetConfiguration" , "Updating widget: " + appWidgetId );
145
154
AppWidgetManager appWidgetManager = AppWidgetManager .getInstance (context );
146
155
@@ -173,10 +182,14 @@ public static void updateWidget(final Context context, int appWidgetId, String a
173
182
174
183
Money accountBalance = accountsDbAdapter .getAccountBalance (accountUID , -1 , System .currentTimeMillis ());
175
184
176
- views .setTextViewText (R .id .transactions_summary ,
177
- accountBalance .formattedString (Locale .getDefault ()));
178
- int color = accountBalance .isNegative () ? R .color .debit_red : R .color .credit_green ;
179
- views .setTextColor (R .id .transactions_summary , context .getResources ().getColor (color ));
185
+ if (shouldDisplayBalance ) {
186
+ views .setTextViewText (R .id .transactions_summary ,
187
+ accountBalance .formattedString (Locale .getDefault ()));
188
+ int color = accountBalance .isNegative () ? R .color .debit_red : R .color .credit_green ;
189
+ views .setTextColor (R .id .transactions_summary , context .getResources ().getColor (color ));
190
+ } else {
191
+ views .setViewVisibility (R .id .transactions_summary , View .GONE );
192
+ }
180
193
181
194
182
195
Intent accountViewIntent = new Intent (context , TransactionsActivity .class );
@@ -219,11 +232,13 @@ public void run() {
219
232
for (final int widgetId : appWidgetIds ) {
220
233
final String accountUID = defaultSharedPrefs
221
234
.getString (UxArgument .SELECTED_ACCOUNT_UID + widgetId , null );
235
+ final boolean shouldDisplayBalance = defaultSharedPrefs
236
+ .getBoolean (UxArgument .SHOULD_DISPLAY_BALANCE + widgetId , true );
222
237
223
238
if (accountUID == null )
224
239
continue ;
225
240
226
- updateWidget (context , widgetId , accountUID );
241
+ updateWidget (context , widgetId , accountUID , shouldDisplayBalance );
227
242
}
228
243
}
229
244
}).start ();
0 commit comments