From 0b9de66e352ec4cf2906ee7f18487531929a55a7 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Fri, 2 Dec 2011 15:53:29 +1300 Subject: [PATCH] Reduce logging in UpcomingWidget --- src/com/morphoss/acal/Constants.java | 1 + .../acal/desktop/ShowUpcomingWidgetProvider.java | 49 ++++++++++++++-------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/com/morphoss/acal/Constants.java b/src/com/morphoss/acal/Constants.java index 4912669..f99a238 100755 --- a/src/com/morphoss/acal/Constants.java +++ b/src/com/morphoss/acal/Constants.java @@ -81,6 +81,7 @@ public class Constants { public static final boolean debugHeap = false && DEBUG_MODE; public static final boolean debugCheckServerDialog = false && DEBUG_MODE; public static final boolean debugTheming = false && DEBUG_MODE; + public static final boolean debugWidget = false && DEBUG_MODE; public static final long DEFAULT_MAX_AGE_WIFI = 1000*60*30; // The default to use when initialising a new collection public static final long DEFAULT_MAX_AGE_3G = 1000*60*60*2; // The default to use when initialising a new collection diff --git a/src/com/morphoss/acal/desktop/ShowUpcomingWidgetProvider.java b/src/com/morphoss/acal/desktop/ShowUpcomingWidgetProvider.java index e21bf4b..7faafb8 100644 --- a/src/com/morphoss/acal/desktop/ShowUpcomingWidgetProvider.java +++ b/src/com/morphoss/acal/desktop/ShowUpcomingWidgetProvider.java @@ -64,7 +64,8 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "onUpdate Called..."); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "onUpdate Called..."); for (int widgetId : appWidgetIds) { Intent updateIntent = new Intent(); @@ -73,7 +74,8 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT); - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Processing for widget id: "+widgetId); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Processing for widget id: "+widgetId); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean prefer24Hour = prefs.getBoolean(context.getString(R.string.prefTwelveTwentyfour),false); @@ -147,7 +149,7 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { //set on click //views.setOnClickPendingIntent(R.id.upcoming_container, pendingIntent); - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, "Processing widget "+widgetId+" completed."); appWidgetManager.updateAppWidget(widgetId, views); @@ -160,16 +162,16 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { long timeTillNextAlarm = end; if (start > 0 && start 0) aCalService.databaseDispatcher.dispatchEvent(new DatabaseChangedEvent(DatabaseChangedEvent.DATABASE_SHOW_UPCOMING_WIDGET_UPDATE,null,null)); - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Deleted "+res+" event(s) that have ended."); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Deleted "+res+" event(s) that have ended."); } /** @@ -208,7 +211,8 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { for (int i=0; !cursor.isAfterLast() && i currentEvents) { - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Checking to see if widget update is required..."); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Checking to see if widget update is required..."); //Turn events into content vals for easier processing ContentValues[] cvs = new ContentValues[currentEvents.size()]; @@ -229,9 +234,11 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { } if (hasDataChanged(context, cvs)){ - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Data change detected, Updating DB"); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Data change detected, Updating DB"); updateData(context, cvs); - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Sending update broadcast"); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Sending update broadcast"); StaticHelpers.updateWidgets(context, ShowUpcomingWidgetProvider.class); } } @@ -244,7 +251,8 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { */ public synchronized static boolean hasDataChanged(Context context, ContentValues[] newData) { ContentValues[] oldData = getCurrentData(context); - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Comparing current data to db"); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Comparing current data to db"); if (oldData.length != newData.length) return true; @@ -265,7 +273,8 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { long now = new AcalDateTime().getMillis(); if (oldData[i].getAsLong(FIELD_DTEND) <= now) return true; } - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Data does not appear to have changed."); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Data does not appear to have changed."); return false; } @@ -275,7 +284,8 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { * @param currentEvents */ public static synchronized void updateData(Context context, ContentValues[] cvs) { - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Writing new values to DB"); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Writing new values to DB"); AcalDBHelper dbhelper = new AcalDBHelper(context); SQLiteDatabase db = dbhelper.getWritableDatabase(); db.beginTransaction(); @@ -318,21 +328,24 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { public synchronized static String getEtag(Context context, int resource_id) { - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Getting Etag for resource "+resource_id); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Getting Etag for resource "+resource_id); ContentResolver cr = context.getContentResolver(); String ret = null; Cursor c = null; try { c = cr.query(DavResources.CONTENT_URI, new String[]{DavResources.ETAG}, DavResources._ID+" = ?", new String[]{resource_id+""}, null); if (c.getCount() < 1) { - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Could not find value in DB"); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Could not find value in DB"); c.close(); return null; } c.moveToFirst(); ret = c.getString(0); } catch (Exception e) { - if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Exception occured: "+e); + if (Constants.LOG_DEBUG && Constants.debugWidget) Log.println(Constants.LOGD, TAG, + "Exception occured: "+e); } if (c != null) c.close(); return ret; @@ -360,7 +373,7 @@ public class ShowUpcomingWidgetProvider extends AppWidgetProvider { return context.getString(R.string.endsAt, time); ///Event is occuring now } else if ( start.getEpochDay() == now.getEpochDay() ) { - return time; + return time; // Leave day of week off to identify it as 'today' } else { StringBuilder result = new StringBuilder(time); -- 2.11.4.GIT