Android Open Source - wordpress-stats-widget Widget Provider






From Project

Back to project page wordpress-stats-widget.

License

The source code is released under:

GNU General Public License

If you think the Android project wordpress-stats-widget 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

package org.lucasr.wordpress;
// w  w w  .  jav a 2  s. c o  m
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

public class WidgetProvider extends AppWidgetProvider {
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        Log.v("WordpressWidget", "onUpdate");

        SharedPreferences prefs =
            context.getSharedPreferences(WidgetConfigure.PREFS_NAME, 0);

        for (int i = 0; i < appWidgetIds.length; i++) {
            Log.v("WordpressWidget", "starting update task for "
                    + appWidgetIds[i]);

            String apiKey = prefs.getString(WidgetConfigure.PREFS_KEY_APP_KEY
                    + appWidgetIds[i], null);
            String blogId = prefs.getString(WidgetConfigure.PREFS_KEY_BLOG_ID
                    + appWidgetIds[i], null);
            String blogHost = prefs.getString(WidgetConfigure.PREFS_KEY_BLOG_HOST
                    + appWidgetIds[i], null);

            // Run task to get stats from wp server
            new StatsTask(context, appWidgetIds[i], apiKey, blogId, blogHost).execute();
        }
    }

    @Override
    public void onDeleted(Context context, int[] appWidgetIds) {
        Log.v("WordpressWidget", "onDeleted");

        SharedPreferences.Editor prefs =
            context.getSharedPreferences(WidgetConfigure.PREFS_NAME, 0).edit();

        for (int i = 0; i < appWidgetIds.length; i++) {
            Log.v("WordpressWidget", "removing prefs for " + appWidgetIds[i]);

            prefs.remove(WidgetConfigure.PREFS_KEY_APP_KEY + appWidgetIds[i]);
            prefs.remove(WidgetConfigure.PREFS_KEY_BLOG_ID + appWidgetIds[i]);
            prefs.remove(WidgetConfigure.PREFS_KEY_BLOG_HOST + appWidgetIds[i]);
            prefs.remove(WidgetConfigure.PREFS_KEY_VIEW_COUNTS + appWidgetIds[i]);
            prefs.remove(WidgetConfigure.PREFS_KEY_LAST_UPDATE + appWidgetIds[i]);
        }

        prefs.commit();
    }
}




Java Source Code List

org.lucasr.wordpress.BarChart.java
org.lucasr.wordpress.BlogInfo.java
org.lucasr.wordpress.NetworkException.java
org.lucasr.wordpress.NoAuthException.java
org.lucasr.wordpress.StatsTask.java
org.lucasr.wordpress.Stats.java
org.lucasr.wordpress.TrustAllManager.java
org.lucasr.wordpress.TrustAllSSLSocketFactory.java
org.lucasr.wordpress.WidgetConfigure.java
org.lucasr.wordpress.WidgetProvider.java