Commit 2c7c851a authored by Michael Chan's avatar Michael Chan
Browse files

b/3189042 Handle ACTION_VIEW in AllInOne. Removed EventInfoActivity.

Change-Id: Ic00300e5d48d264ade7d400d703cba8f5a2b8626
parent 7a30aa9f
......@@ -65,6 +65,11 @@
<data android:host="com.android.calendar" />
<data android:scheme="content"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/event" />
</intent-filter>
</activity-alias>
<activity android:name=".event.EditEventActivity"
......@@ -85,17 +90,6 @@
</intent-filter>
</activity-alias>
<activity android:name="EventInfoActivity" android:label="@string/event_info_title"
android:theme="@style/CalendarTheme.WithActionBar"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/event" />
</intent-filter>
</activity>
<activity android:name="GoogleCalendarUriIntentFilter" android:label="@string/app_label"
android:theme="@android:style/Theme.Light"
android:configChanges="orientation|keyboardHidden">
......
......@@ -18,12 +18,14 @@ package com.android.calendar;
import static android.provider.Calendar.EVENT_BEGIN_TIME;
import static android.provider.Calendar.EVENT_END_TIME;
import static android.provider.Calendar.AttendeesColumns.ATTENDEE_STATUS;
import com.android.calendar.CalendarController.EventHandler;
import com.android.calendar.CalendarController.EventInfo;
import com.android.calendar.CalendarController.EventType;
import com.android.calendar.CalendarController.ViewType;
import com.android.calendar.agenda.AgendaFragment;
import com.android.calendar.event.EditEventHelper;
import com.android.calendar.month.MonthByWeekFragment;
import com.android.calendar.selectcalendars.SelectCalendarsFragment;
......@@ -53,6 +55,7 @@ import android.view.View;
import android.widget.SearchView;
import android.widget.TextView;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
......@@ -77,6 +80,11 @@ public class AllInOneActivity extends Activity implements EventHandler,
private TextView mHomeTime;
private String mTimeZone;
private long mViewEventId = -1;
private long mIntentEventStartMillis = -1;
private long mIntentEventEndMillis = -1;
private int mIntentAttendeeResponse = EditEventHelper.ATTENDEE_NO_RESPONSE;
// Action bar and Navigation bar (left side of Action bar)
private ActionBar mActionBar;
private ActionBar.Tab mDayTab;
......@@ -112,28 +120,37 @@ public class AllInOneActivity extends Activity implements EventHandler,
// This needs to be created before setContentView
mController = CalendarController.getInstance(this);
// Get time from intent or icicle
long timeMillis;
long timeMillis = -1;
int viewType = -1;
boolean restoreEdit = false;
final Intent intent = getIntent();
if (icicle != null) {
timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
} else {
timeMillis = Utils.timeFromIntentInMillis(getIntent());
}
boolean restoreEdit = icicle != null ? icicle.getBoolean(BUNDLE_KEY_RESTORE_EDIT, false)
: false;
int viewType;
if (restoreEdit) {
restoreEdit = icicle.getBoolean(BUNDLE_KEY_RESTORE_EDIT, false);
viewType = ViewType.EDIT;
} else {
String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action)) {
// Open EventInfo later
timeMillis = parseViewAction(intent);
}
if (timeMillis == -1) {
timeMillis = Utils.timeFromIntentInMillis(intent);
}
}
if (!restoreEdit) {
viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
}
mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
Time t = new Time(mTimeZone);
t.set(timeMillis);
if (icicle != null && getIntent() != null) {
Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + getIntent().toString());
if (icicle != null && intent != null) {
Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
} else {
Log.d(TAG, "not both, icicle:" + icicle + " intent:" + getIntent());
Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
}
mIsMultipane = (getResources().getConfiguration().screenLayout
......@@ -163,6 +180,29 @@ public class AllInOneActivity extends Activity implements EventHandler,
mContentResolver = getContentResolver();
}
private long parseViewAction(final Intent intent) {
long timeMillis = -1;
Uri data = intent.getData();
if (data != null && data.isHierarchical()) {
List<String> path = data.getPathSegments();
if (path.size() == 2 && path.get(0).equals("events")) {
try {
mViewEventId = Long.valueOf(data.getLastPathSegment());
if(mViewEventId != -1) {
mIntentEventStartMillis = intent.getLongExtra(EVENT_BEGIN_TIME, 0);
mIntentEventEndMillis = intent.getLongExtra(EVENT_END_TIME, 0);
mIntentAttendeeResponse = intent.getIntExtra(
ATTENDEE_STATUS, EditEventHelper.ATTENDEE_NO_RESPONSE);
timeMillis = mIntentEventStartMillis;
}
} catch (NumberFormatException e) {
// Ignore if mViewEventId can't be parsed
}
}
}
return timeMillis;
}
private void configureActionBar() {
mActionBar = getActionBar();
mActionBar.setTabNavigationMode();
......@@ -195,6 +235,14 @@ public class AllInOneActivity extends Activity implements EventHandler,
updateHomeClock();
mPaused = false;
mOnSaveInstanceStateCalled = false;
if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
mController.sendEventRelatedEvent(this, EventType.VIEW_EVENT, mViewEventId,
mIntentEventStartMillis, mIntentEventEndMillis, -1, -1);
mViewEventId = -1;
mIntentEventStartMillis = -1;
mIntentEventEndMillis = -1;
}
}
@Override
......
......@@ -454,7 +454,7 @@ public class CalendarController {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId);
intent.setData(eventUri);
intent.setClassName(mContext, EventInfoActivity.class.getName());
// intent.setClassName(mContext, EventInfoActivity.class.getName());
intent.putExtra(EVENT_BEGIN_TIME, startMillis);
intent.putExtra(EVENT_END_TIME, endMillis);
mContext.startActivity(intent);
......
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.calendar;
import static android.provider.Calendar.EVENT_BEGIN_TIME;
import static android.provider.Calendar.EVENT_END_TIME;
import static android.provider.Calendar.AttendeesColumns.ATTENDEE_STATUS;
import com.android.calendar.CalendarController.EventInfo;
import com.android.calendar.CalendarController.EventType;
import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.Time;
public class EventInfoActivity extends AbstractCalendarActivity
implements CalendarController.EventHandler {
private static final int HANDLER_KEY = 0;
static final int ATTENDEE_NO_RESPONSE = -1;
private DeleteEventHelper mDeleteEventHelper;
private CalendarController mController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This needs to be created before setContentView
mController = CalendarController.getInstance(this);
Intent intent = getIntent();
Uri uri = intent.getData();
long startMillis = intent.getLongExtra(EVENT_BEGIN_TIME, 0);
long endMillis = intent.getLongExtra(EVENT_END_TIME, 0);
int attendeeResponseFromIntent = intent.getIntExtra(
ATTENDEE_STATUS, ATTENDEE_NO_RESPONSE);
Fragment f = new EventInfoFragment(
uri, startMillis, endMillis, attendeeResponseFromIntent);
getFragmentManager().openTransaction().add(android.R.id.content, f).commit();
mDeleteEventHelper = new DeleteEventHelper(this, this, true /* exit when done */);
mController.registerEventHandler(HANDLER_KEY, this);
}
@Override
protected void onDestroy() {
super.onDestroy();
CalendarController.removeInstance(this);
}
@Override
public void eventsChanged() {
// TODO Auto-generated method stub
}
@Override
public long getSupportedEventTypes() {
return EventType.DELETE_EVENT;
}
@Override
public void handleEvent(EventInfo event) {
if (event.eventType == EventType.DELETE_EVENT) {
long endTime = (event.endTime == null) ? -1 : event.endTime.toMillis(false);
mDeleteEventHelper.delete(
event.startTime.toMillis(false), endTime, event.id, -1);
}
}
}
......@@ -78,7 +78,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
CalendarController.EventHandler {
public static final boolean DEBUG = false;
public static final String TAG = "EventInfoActivity";
public static final String TAG = "EventInfoFragment";
private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
......@@ -311,7 +311,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
public EventInfoFragment(long eventId, long startMillis, long endMillis) {
this(ContentUris.withAppendedId(Events.CONTENT_URI, eventId),
startMillis, endMillis, EventInfoActivity.ATTENDEE_NO_RESPONSE);
startMillis, endMillis, EditEventHelper.ATTENDEE_NO_RESPONSE);
mEventId = eventId;
}
......@@ -389,7 +389,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.event_info_activity, null);
mView = inflater.inflate(R.layout.event_info, null);
if (mUri == null) {
// restore event ID from bundle
......
......@@ -170,7 +170,7 @@ public class SearchActivity extends Activity
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
intent.setData(eventUri);
intent.setClassName(this, EventInfoActivity.class.getName());
// intent.setClassName(this, EventInfoActivity.class.getName());
intent.putExtra(EVENT_BEGIN_TIME,
event.startTime != null ? event.startTime.toMillis(true) : -1);
intent.putExtra(
......
......@@ -55,7 +55,7 @@ public class EditEventActivity extends AbstractCalendarActivity {
mEditFragment = (EditEventFragment) getFragmentManager().findFragmentById(R.id.edit_event);
if (mEditFragment == null) {
mEditFragment = new EditEventFragment(mEventInfo);
mEditFragment = new EditEventFragment(mEventInfo, false);
mEditFragment.mShowModifyDialogOnLaunch = getIntent().getBooleanExtra(
CalendarController.EVENT_EDIT_ON_LAUNCH, false);
......
......@@ -350,11 +350,7 @@ public class EditEventFragment extends Fragment implements EventHandler {
}
public EditEventFragment() {
this(null);
}
public EditEventFragment(EventInfo event) {
this(event, false);
this(null, false);
}
public EditEventFragment(EventInfo event, boolean readOnly) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment