If you think the Android project gnucash-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (c) 2012 Ngewi Fet <ngewif@gmail.com>
*/*fromwww.java2s.com*/
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package org.gnucash.android.receivers;
import org.gnucash.android.ui.UxArgument;
import org.gnucash.android.ui.widget.WidgetConfigurationActivity;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
/**
* {@link AppWidgetProvider} which is responsible for managing widgets on the homescreen
* It receives broadcasts related to updating and deleting widgets
* Widgets can also be updated manually by calling {@link WidgetConfigurationActivity#updateAllWidgets(Context)}
* @author Ngewi Fet <ngewif@gmail.com>
*
*/publicclass TransactionAppWidgetProvider extends AppWidgetProvider {
@Override
publicvoid onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
finalint N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
String accountUID = PreferenceManager
.getDefaultSharedPreferences(context)
.getString(UxArgument.SELECTED_ACCOUNT_UID + appWidgetId, null);
if (accountUID == null)
return;
WidgetConfigurationActivity.updateWidget(context, appWidgetId, accountUID);
}
}
@Override
publicvoid onEnabled(Context context) {
super.onEnabled(context);
WidgetConfigurationActivity.updateAllWidgets(context);
}
@Override
publicvoid onDeleted(Context context, int[] appWidgetIds) {
super.onDeleted(context, appWidgetIds);
Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
for (int appWidgetId : appWidgetIds) {
editor.remove(UxArgument.SELECTED_ACCOUNT_UID + appWidgetId);
}
editor.commit();
}
}