OSDN Git Service

Quick fix to add safer time checking for time from intents.
[android-x86/packages-apps-Calendar.git] / src / com / android / calendar / Utils.java
index 55cbfba..aa48fe0 100644 (file)
@@ -21,12 +21,15 @@ import static android.provider.Calendar.EVENT_BEGIN_TIME;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.net.Uri;
 import android.preference.PreferenceManager;
 import android.text.format.Time;
+import android.util.Log;
 import android.view.animation.AlphaAnimation;
 import android.widget.ViewFlipper;
 
 import java.util.Calendar;
+import java.util.List;
 
 public class Utils {
     public static void startActivity(Context context, String className, long time) {
@@ -40,12 +43,12 @@ public class Utils {
     }
 
     static String getSharedPreference(Context context, String key, String defaultValue) {
-        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+        SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(context);
         return prefs.getString(key, defaultValue);
     }
 
     static void setSharedPreference(Context context, String key, String value) {
-        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+        SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(context);
         SharedPreferences.Editor editor = prefs.edit();
         editor.putString(key, value);
         editor.commit();
@@ -54,7 +57,7 @@ public class Utils {
     static void setDefaultView(Context context, int viewId) {
         String activityString = CalendarApplication.ACTIVITY_NAMES[viewId];
 
-        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+        SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(context);
         SharedPreferences.Editor editor = prefs.edit();
         if (viewId == CalendarApplication.AGENDA_VIEW_ID ||
                 viewId == CalendarApplication.DAY_VIEW_ID) {
@@ -79,8 +82,20 @@ public class Utils {
      */
     public static final long timeFromIntentInMillis(Intent intent) {
         // If the time was specified, then use that.  Otherwise, use the current time.
+        Uri data = intent.getData();
         long millis = intent.getLongExtra(EVENT_BEGIN_TIME, -1);
-        if (millis == -1) {
+        if (millis == -1 && data != null && data.isHierarchical()) {
+            List<String> path = data.getPathSegments();
+            if(path.size() == 3 && path.get(1).equals("time")) {
+                try {
+                    millis = Long.valueOf(data.getLastPathSegment());
+                } catch (NumberFormatException e) {
+                    Log.i("Calendar", "timeFromIntentInMillis: Data existed but no valid time " +
+                            "found. Using current time.");
+                }
+            }
+        }
+        if (millis <= 0) {
             millis = System.currentTimeMillis();
         }
         return millis;