From b4df3c325d255a872ad485cc469ea0f2acf58fe9 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Fri, 8 Jul 2011 16:37:25 -0700 Subject: [PATCH] Fix warnings --- .../localytics/android/DatapointHelper.java | 145 +++++++++--------- .../localytics/android/LocalyticsSession.java | 34 ++-- .../localytics/android/UploaderThread.java | 19 +-- .../astrid/actfm/sync/ActFmSyncService.java | 2 +- .../sync/ProducteevSyncProvider.java | 4 +- .../src/com/todoroo/astrid/dao/TaskDao.java | 2 +- 6 files changed, 104 insertions(+), 102 deletions(-) diff --git a/astrid/common-src/com/localytics/android/DatapointHelper.java b/astrid/common-src/com/localytics/android/DatapointHelper.java index 0f28806d9..22c8c0606 100644 --- a/astrid/common-src/com/localytics/android/DatapointHelper.java +++ b/astrid/common-src/com/localytics/android/DatapointHelper.java @@ -1,11 +1,11 @@ /** * DatapointHelper.java * Copyright (C) 2009 Char Software Inc., DBA Localytics - * + * * This code is provided under the Localytics Modified BSD License. * A copy of this license has been distributed in a file called LICENSE - * with this source code. - * + * with this source code. + * * Please visit www.localytics.com for more information. */ @@ -21,33 +21,34 @@ import java.util.TimeZone; import android.content.Context; import android.content.pm.PackageManager; import android.net.wifi.WifiManager; +import android.provider.Settings.System; import android.telephony.TelephonyManager; import android.util.Log; -import android.provider.Settings.System; /** * Provides a number of static functions to aid in the collection and formatting * of datapoints. * @author Localytics */ -public final class DatapointHelper +@SuppressWarnings("nls") +public final class DatapointHelper { // This class should never be instantiated - private DatapointHelper() { } - + private DatapointHelper() { /**/ } + private static final String LOG_PREFIX = "(DatapointHelper) "; private static final String DROID2_ANDROID_ID = "9774d56d682e549c"; - - // Each YAML entry either goes to the session controller, the event controller - // or the optin controller + + // Each YAML entry either goes to the session controller, the event controller + // or the optin controller public static final String CONTROLLER_SESSION = "- c: se\n"; public static final String CONTROLLER_EVENT = "- c: ev\n"; public static final String CONTROLLER_OPT = "- c: optin\n"; - - // Each entry is either a create action, or an update action + + // Each entry is either a create action, or an update action public static final String ACTION_CREATE = " a: c\n"; - public static final String ACTION_UPDATE = " a: u\n"; + public static final String ACTION_UPDATE = " a: u\n"; public static final String ACTION_OPTIN = " a: optin\n"; - + // The target object for the data being set up. public static final String OBJECT_SESSION_DP = " se:\n"; public static final String OBJECT_EVENT_DP = " ev:\n"; @@ -60,91 +61,91 @@ public final class DatapointHelper * WEBSERVICE PARAMENTER NAMES * * ***************************** */ - + // Every object has a UUID public static final String PARAM_UUID = "u"; - + // The identifier for this application, generated by the user on the webservice public static final String PARAM_APP_UUID = "au"; - + // The version of this application, taken from the application's manifest. public static final String PARAM_APP_VERSION = "av"; - + // A session's UUID as previously created. public static final String PARAM_SESSION_UUID = "su"; - + // A hashed identifier unique to this device public static final String PARAM_DEVICE_UUID = "du"; - + // android, iphone, blackberry, windowsmobile public static final String PARAM_DEVICE_PLATFORM = "dp"; - + // maker of this device (currently not supported by Android) public static final String PARAM_DEVICE_MAKE = "dma"; - + // model of the device public static final String PARAM_DEVICE_MODEL = "dmo"; - + // version of the OS on this device public static final String PARAM_OS_VERSION = "dov"; - + // country device is from (obtained by querying the SIM card) public static final String PARAM_DEVICE_COUNTRY = "dc"; - + // country the current locale is set to public static final String PARAM_LOCALE_COUNTRY = "dlc"; - + // country the language is set to public static final String PARAM_LOCALE_LANGUAGE = "dll"; - - // Locale as a language_country string. (Not collected because this info + + // Locale as a language_country string. (Not collected because this info // is already provided by LOCALE_LANGUAGE and LOCALE_COUNTRY. public static final String PARAM_LOCALE = "dl"; - + // Country the user is currently in (comes from Sim card) public static final String PARAM_NETWORK_COUNTRY = "nc"; - + // Current carrier (comes from sim card) public static final String PARAM_NETWORK_CARRIER = "nca"; - + // Current mobile network code (comes from sim card) public static final String PARAM_NETWORK_MNC = "mnc"; - + // current mobile country code (comes from sim card) public static final String PARAM_NETWORK_MCC = "mcc"; - + // type of data connection (wifi, umts, gprs, evdo, ...) public static final String PARAM_DATA_CONNECTION = "dac"; - + // the version of this Localytics client library public static final String PARAM_LIBRARY_VERSION = "lv"; - + // The source where the location came from public static final String PARAM_LOCATION_SOURCE = "ls"; - + // the latitude returned by the location provider public static final String PARAM_LOCATION_LAT = "lat"; - + // the longitude from the location provider public static final String PARAM_LOCATION_LNG = "lng"; - + // the current time on the user's device public static final String PARAM_CLIENT_TIME = "ct"; - + // sent at closing time, the current time on the users's device public static final String PARAM_CLIENT_CLOSED_TIME = "ctc"; - + // The name an event that occured - public static final String PARAM_EVENT_NAME = "n"; - - // the optin value sent in if a user opts in or out. + public static final String PARAM_EVENT_NAME = "n"; + + // the optin value sent in if a user opts in or out. public static final String PARAM_OPT_VALUE = "optin"; - + /** * Returns the given key/value pair as a YAML string. This string is intended to be * used to define values for the first level of data in the YAML file. This is - * different from the datapoints which belong another level in. - * @param paramName The name of the parameter + * different from the datapoints which belong another level in. + * @param paramName The name of the parameter * @param paramValue The value of the parameter * @param paramIndent The indent level of the parameter * @return a YAML string which can be dumped to the YAML file @@ -153,13 +154,13 @@ public final class DatapointHelper { if (paramName.length() > LocalyticsSession.MAX_NAME_LENGTH) { - Log.v(DatapointHelper.LOG_PREFIX, "Parameter name exceeds " + Log.v(DatapointHelper.LOG_PREFIX, "Parameter name exceeds " + LocalyticsSession.MAX_NAME_LENGTH + " character limit. Truncating."); paramName = paramName.substring(0, LocalyticsSession.MAX_NAME_LENGTH); } if (paramValue.length() > LocalyticsSession.MAX_NAME_LENGTH) { - Log.v(DatapointHelper.LOG_PREFIX, "Parameter value exceeds " + Log.v(DatapointHelper.LOG_PREFIX, "Parameter value exceeds " + LocalyticsSession.MAX_NAME_LENGTH + " character limit. Truncating."); paramValue = paramValue.substring(0, LocalyticsSession.MAX_NAME_LENGTH); } @@ -178,7 +179,7 @@ public final class DatapointHelper formattedString.append(escapeString(paramValue)); formattedString.append("\n"); - + return formattedString.toString(); } @@ -187,30 +188,30 @@ public final class DatapointHelper * one way hash and cannot be used to determine what device this data came from. * @param appContext The context used to access the settings resolver * @return An 1-way hashed identifier unique to this device or null if an ID, or the hashing - * algorithm is not available. + * algorithm is not available. */ public static String getGlobalDeviceId(final Context appContext) { String systemId = System.getString(appContext.getContentResolver(), System.ANDROID_ID); if(systemId == null || systemId.toLowerCase().equals(DROID2_ANDROID_ID)) - { + { return null; } - + try { MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] digest = md.digest(systemId.getBytes()); BigInteger hashedNumber = new BigInteger(1, digest); return new String(hashedNumber.toString(16)); - + } catch(NoSuchAlgorithmException e) { return null; - } + } } - + /** * Determines the type of network this device is connected to. * @param appContext the context used to access the device's WIFI @@ -219,10 +220,10 @@ public final class DatapointHelper */ public static String getNetworkType( final Context appContext, - TelephonyManager telephonyManager) - { - WifiManager wifiManager = (WifiManager)appContext.getSystemService(Context.WIFI_SERVICE); - + TelephonyManager telephonyManager) + { + WifiManager wifiManager = (WifiManager)appContext.getSystemService(Context.WIFI_SERVICE); + // this will only work for apps which already have wifi permissions. try { @@ -230,29 +231,29 @@ public final class DatapointHelper { return "wifi"; } - } - catch (Exception e) { } - + } + catch (Exception e) { /**/ } + switch (telephonyManager.getNetworkType()) - { + { case TelephonyManager.NETWORK_TYPE_EDGE : return "edge"; case TelephonyManager.NETWORK_TYPE_GPRS : return "GPRS"; case TelephonyManager.NETWORK_TYPE_UMTS : return "UMTS"; - case TelephonyManager.NETWORK_TYPE_UNKNOWN : return "unknown"; + case TelephonyManager.NETWORK_TYPE_UNKNOWN : return "unknown"; } - - return "none"; + + return "none"; } - + /** * Gets the pretty string for this application's version. * @param appContext The context used to examine packages * @return The application's version as a pretty string */ - public static String getAppVersion(final Context appContext) + public static String getAppVersion(final Context appContext) { PackageManager pm = appContext.getPackageManager(); - + try { return pm.getPackageInfo(appContext.getPackageName(), 0).versionName; @@ -262,9 +263,9 @@ public final class DatapointHelper return "unknown"; } } - + /** - * Gets the current time, along with local timezone, formatted as a DateTime for the webservice. + * Gets the current time, along with local timezone, formatted as a DateTime for the webservice. * @return a DateTime of the current local time and timezone. */ public static String getTimeAsDatetime() @@ -289,7 +290,7 @@ public final class DatapointHelper int startRead = 0; // Index to start reading at int stopRead = 0; // Index characters get read from and where the substring ends - int bufferLength = rawString.length(); + int bufferLength = rawString == null ? 0 : rawString.length(); if (rawString == null) { diff --git a/astrid/common-src/com/localytics/android/LocalyticsSession.java b/astrid/common-src/com/localytics/android/LocalyticsSession.java index 9de4abb5c..1947c9602 100644 --- a/astrid/common-src/com/localytics/android/LocalyticsSession.java +++ b/astrid/common-src/com/localytics/android/LocalyticsSession.java @@ -11,26 +11,25 @@ package com.localytics.android; -import android.content.Context; -import android.telephony.TelephonyManager; -import android.util.Log; -import android.os.Build; - import java.io.BufferedReader; import java.io.File; -import java.io.FileOutputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.io.OutputStream; - +import java.util.Arrays; import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.UUID; -import java.util.Arrays; + +import android.content.Context; +import android.os.Build; +import android.telephony.TelephonyManager; +import android.util.Log; /** * The class which manages creating, collecting, & uploading a Localytics session. @@ -70,6 +69,7 @@ import java.util.Arrays; * @author Localytics * @version 1.5 */ +@SuppressWarnings("nls") public final class LocalyticsSession { //////////////////////////////////////// @@ -217,7 +217,7 @@ public final class LocalyticsSession { fp.createNewFile(); } - catch (IOException e) { } + catch (IOException e) { /**/ } createOptEvent(false); } @@ -473,7 +473,7 @@ public final class LocalyticsSession DatapointHelper.PARAM_SESSION_UUID, this._sessionUUID, 3)); eventString.append(DatapointHelper.formatYAMLLine( DatapointHelper.PARAM_CLIENT_TIME, DatapointHelper.getTimeAsDatetime(), 3)); - + eventString.append(DatapointHelper.formatYAMLLine( DatapointHelper.PARAM_EVENT_NAME, event, 3)); @@ -508,7 +508,7 @@ public final class LocalyticsSession * divisible by step size, the method guarantees only the minimum and the * step size to be accurate to specification, with the new maximum will be * moved to the next regular step. - * + * * @param actualValue The int value to be sorted. * @param minValue The int value representing the inclusive minimum interval. * @param maxValue The int value representing the inclusive maximum interval. @@ -534,16 +534,16 @@ public final class LocalyticsSession for (int currentStep = 0; currentStep <= stepQuantity; currentStep++) { steps[currentStep] = minValue + (currentStep) * step; - } + } return createRangedAttribute(actualValue, steps); } - /** + /** * Sorts an int value into a predefined, pre-sorted set of intervals, returning a string representing the * new expected value. The array must be sorted in ascending order, with the first element representing * the inclusive lower bound and the last element representing the exclusive upper bound. For instance, * the array [0,1,3,10] will provide the following buckets: less than 0, 0, 1-2, 3-9, 10 or greater. - * + * * @param actualValue The int value to be bucketed. * @param steps The sorted int array representing the bucketing intervals. */ @@ -559,7 +559,7 @@ public final class LocalyticsSession // if greater than largest value else if (actualValue >= steps[steps.length - 1]) { - bucket = steps[steps.length - 1] + " and above"; + bucket = steps[steps.length - 1] + " and above"; } else { @@ -567,7 +567,7 @@ public final class LocalyticsSession int bucketIndex = Arrays.binarySearch(steps, actualValue); if (bucketIndex < 0) { - // if the index wasn't found, then we want the value before the insertion point as the lower end + // if the index wasn't found, then we want the value before the insertion point as the lower end // the special case where the insertion point is 0 is covered above, so we don't have to worry about it here bucketIndex = (- bucketIndex) - 2; } @@ -932,7 +932,7 @@ public final class LocalyticsSession * Runnable which gets passed to the uploader thread so it can * notify the library when uploads are complete. */ - private Runnable uploadComplete = new Runnable() + private final Runnable uploadComplete = new Runnable() { public void run() { diff --git a/astrid/common-src/com/localytics/android/UploaderThread.java b/astrid/common-src/com/localytics/android/UploaderThread.java index 815c57270..0f09a256e 100644 --- a/astrid/common-src/com/localytics/android/UploaderThread.java +++ b/astrid/common-src/com/localytics/android/UploaderThread.java @@ -16,7 +16,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.FileReader; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; @@ -37,16 +36,17 @@ import android.util.Log; * The thread which handles uploading Localytics data. * @author Localytics */ +@SuppressWarnings("nls") public class UploaderThread extends Thread { - private Runnable _completeCallback; - private File _localyticsDir; - private String _sessionFilePrefix; - private String _uploaderFilePrefix; - private String _closeFilePrefix; + private final Runnable _completeCallback; + private final File _localyticsDir; + private final String _sessionFilePrefix; + private final String _uploaderFilePrefix; + private final String _closeFilePrefix; // The Tag used in logging. - private final static String LOG_TAG = "Localytics_uploader"; + private final static String LOG_TAG = "Localytics_uploader"; // The URL to send Localytics session data to private final static String ANALYTICS_URL = "http://analytics.localytics.com/api/datapoints/bulk"; @@ -85,7 +85,8 @@ public class UploaderThread extends Thread * Renames all the session files (so that other threads can keep writing * datapoints without affecting the upload. And then uploads them. */ - public void run() + @Override + public void run() { int numFilesToUpload = 0; @@ -278,7 +279,7 @@ public class UploaderThread extends Thread { BufferedReader reader = new BufferedReader( new InputStreamReader( - new FileInputStream(inputFile), + new FileInputStream(inputFile), "UTF-8"), UploaderThread.BUFFER_SIZE); char[] buf = new char[1024]; diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index 0b5b4c0c4..c757978de 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -819,7 +819,7 @@ public final class ActFmSyncService { model.setValue(Task.TITLE, json.getString("title")); model.setValue(Task.IMPORTANCE, json.getInt("importance")); model.setValue(Task.DUE_DATE, - model.createDueDate(Task.URGENCY_SPECIFIC_DAY, readDate(json, "due"))); + Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, readDate(json, "due"))); model.setValue(Task.COMPLETION_DATE, readDate(json, "completed_at")); model.setValue(Task.CREATION_DATE, readDate(json, "created_at")); model.setValue(Task.DELETION_DATE, readDate(json, "deleted_at")); diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java index 25b34ab7e..9a66e4ef9 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java @@ -365,9 +365,9 @@ public class ProducteevSyncProvider extends SyncProvider { if(!item.containsValue(Task.DUE_DATE)) { int setting = Preferences.getIntegerFromString(R.string.p_default_urgency_key, Task.URGENCY_NONE); - item.setValue(Task.DUE_DATE, item.createDueDate(setting, 0)); + item.setValue(Task.DUE_DATE, Task.createDueDate(setting, 0)); } if(!item.containsValue(Task.HIDE_UNTIL)) { int setting = Preferences.getIntegerFromString(R.string.p_default_hideUntil_key,