OSDN Git Service

b/2412594 Added an implicit intent filter to the Calendar Launcher.
authorErik <roboerik@android.com>
Wed, 24 Feb 2010 22:46:03 +0000 (14:46 -0800)
committerErik <roboerik@android.com>
Fri, 26 Feb 2010 18:47:05 +0000 (10:47 -0800)
Added an implicent intent filter to the Calendar launcher so it will no longer be tied
to the package name. And added functionality to allow a data uri to be passed giving a
time to start the calendar at as well as allowing "VIEW" as an extra with "DAY" to go
to the day view directly.

AndroidManifest.xml
src/com/android/calendar/LaunchActivity.java
src/com/android/calendar/Utils.java

index 365e6ea..49860ff 100644 (file)
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data android:mimeType="time/epoch" />
+                <data android:host="com.android.calendar" />
+                <data android:scheme="content"/>
+            </intent-filter>
         </activity>
 
         <activity android:name="MonthActivity" android:label="@string/month_view"
index 92aec0f..662c66e 100644 (file)
@@ -23,7 +23,6 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.net.Uri;
 import android.os.Bundle;
-import android.preference.PreferenceManager;
 import android.provider.Calendar;
 import android.provider.Settings;
 
@@ -31,6 +30,8 @@ public class LaunchActivity extends Activity {
     private static final String TAG = "LaunchActivity";
 
     static final String KEY_DETAIL_VIEW = "DETAIL_VIEW";
+    static final String KEY_VIEW_TYPE = "VIEW";
+    static final String VIEW_TYPE_DAY = "DAY";
 
     private Bundle mExtras;
 
@@ -86,13 +87,20 @@ public class LaunchActivity extends Activity {
             intent.putExtras(mExtras);
             if (mExtras.getBoolean(KEY_DETAIL_VIEW, false)) {
                 defaultViewKey = CalendarPreferenceActivity.KEY_DETAILED_VIEW;
+            } else if (VIEW_TYPE_DAY.equals(mExtras.getString(KEY_VIEW_TYPE))) {
+                defaultViewKey = VIEW_TYPE_DAY;
             }
         }
         intent.putExtras(myIntent);
 
         SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this);
-        String startActivity = prefs.getString(defaultViewKey,
+        String startActivity;
+        if (defaultViewKey.equals(VIEW_TYPE_DAY)) {
+            startActivity = CalendarApplication.ACTIVITY_NAMES[CalendarApplication.DAY_VIEW_ID];
+        } else {
+            startActivity = prefs.getString(defaultViewKey,
                 CalendarPreferenceActivity.DEFAULT_START_VIEW);
+        }
 
         intent.setClassName(this, startActivity);
         intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
index 7dd3da2..7294714 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) {
@@ -79,7 +82,19 @@ 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 && 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 == -1) {
             millis = System.currentTimeMillis();
         }