Home | History | Annotate | Download | only in activity
      1 /**
      2  * Copyright (c) 2012, Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.email.activity;
     18 
     19 import android.app.Activity;
     20 import android.content.ContentUris;
     21 import android.content.Intent;
     22 import android.database.Cursor;
     23 import android.net.Uri;
     24 import android.os.Bundle;
     25 import android.provider.CalendarContract;
     26 
     27 import com.android.emailcommon.mail.MeetingInfo;
     28 import com.android.emailcommon.mail.PackedString;
     29 import com.android.emailcommon.provider.EmailContent.Message;
     30 import com.android.emailcommon.utility.Utility;
     31 
     32 public class EventViewer extends Activity {
     33     @Override
     34     public void onCreate(Bundle savedInstanceState) {
     35         super.onCreate(savedInstanceState);
     36         Uri uri = getIntent().getData();
     37         long messageId = Long.parseLong(uri.getLastPathSegment());
     38         Message msg = Message.restoreMessageWithId(this, messageId);
     39         if (msg == null) {
     40             finish();
     41         } else {
     42             PackedString info = new PackedString(msg.mMeetingInfo);
     43             String uid = info.get(MeetingInfo.MEETING_UID);
     44             long eventId = -1;
     45             if (uid != null) {
     46                 Cursor c = getContentResolver().query(CalendarContract.Events.CONTENT_URI,
     47                         new String[] {CalendarContract.Events._ID},
     48                         CalendarContract.Events.SYNC_DATA2 + "=?",
     49                         new String[] {uid}, null);
     50                 if (c != null) {
     51                     try {
     52                         if (c.getCount() == 1) {
     53                             c.moveToFirst();
     54                             eventId = c.getLong(0);
     55                         }
     56                     } finally {
     57                         c.close();
     58                     }
     59                 }
     60             }
     61             Intent intent = new Intent(Intent.ACTION_VIEW);
     62             if (eventId != -1) {
     63                 uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId);
     64             } else {
     65                 long time =
     66                         Utility.parseEmailDateTimeToMillis(info.get(MeetingInfo.MEETING_DTSTART));
     67                 uri = Uri.parse("content://com.android.calendar/time/" + time);
     68                 intent.putExtra("VIEW", "DAY");
     69             }
     70             intent.setData(uri);
     71             intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
     72             startActivity(intent);
     73             finish();
     74         }
     75     }
     76 }
     77