Home | History | Annotate | Download | only in calendar
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      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 package com.android.calendar;
     17 
     18 import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
     19 import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
     20 import static com.android.calendar.CalendarController.ATTENDEE_NO_RESPONSE;
     21 import static com.android.calendar.CalendarController.EVENT_ATTENDEE_RESPONSE;
     22 
     23 import android.app.ActionBar;
     24 import android.app.Activity;
     25 import android.app.FragmentManager;
     26 import android.app.FragmentTransaction;
     27 import android.content.Intent;
     28 import android.net.Uri;
     29 import android.os.Bundle;
     30 import android.util.Log;
     31 
     32 public class EventInfoActivity extends Activity {
     33 //        implements CalendarController.EventHandler, SearchView.OnQueryTextListener,
     34 //        SearchView.OnCloseListener {
     35 
     36     private static final String TAG = "EventInfoActivity";
     37     private EventInfoFragment mInfoFragment;
     38     private long mStartMillis, mEndMillis;
     39     private long mEventId;
     40 
     41     @Override
     42     protected void onCreate(Bundle icicle) {
     43         super.onCreate(icicle);
     44 
     45         setContentView(R.layout.simple_frame_layout);
     46 
     47         // Get the fragment if exists
     48         mInfoFragment = (EventInfoFragment)
     49                 getFragmentManager().findFragmentById(R.id.main_frame);
     50 
     51 
     52         // Get the info needed for the fragment
     53         Intent intent = getIntent();
     54         int attendeeResponse = 0;
     55         mEventId = 0;
     56         boolean isDialog = false;
     57 
     58         if (icicle != null) {
     59             mEventId = icicle.getLong(EventInfoFragment.BUNDLE_KEY_EVENT_ID);
     60             mStartMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_START_MILLIS);
     61             mEndMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_END_MILLIS);
     62             attendeeResponse = icicle.getInt(EventInfoFragment.BUNDLE_KEY_ATTENDEE_RESPONSE);
     63             isDialog = icicle.getBoolean(EventInfoFragment.BUNDLE_KEY_IS_DIALOG);
     64         } else if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
     65             mStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
     66             mEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
     67             attendeeResponse = intent.getIntExtra(EVENT_ATTENDEE_RESPONSE, ATTENDEE_NO_RESPONSE);
     68             Uri data = intent.getData();
     69             if (data != null) {
     70                 try {
     71                     mEventId = Long.parseLong(data.getLastPathSegment());
     72                 } catch (NumberFormatException e) {
     73                     Log.wtf(TAG,"No event id");
     74                 }
     75             }
     76         }
     77 
     78         // Remove the application title
     79         ActionBar bar = getActionBar();
     80         if (bar != null) {
     81             bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
     82         }
     83 
     84         // Create a new fragment if none exists
     85         if (mInfoFragment == null) {
     86             FragmentManager fragmentManager = getFragmentManager();
     87             FragmentTransaction ft = fragmentManager.beginTransaction();
     88             mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis,
     89                     attendeeResponse, isDialog, isDialog ?
     90                             EventInfoFragment.DIALOG_WINDOW_STYLE :
     91                                 EventInfoFragment.FULL_WINDOW_STYLE);
     92             ft.replace(R.id.main_frame, mInfoFragment);
     93             ft.commit();
     94         }
     95     }
     96 
     97 //    @Override
     98 //    public boolean onOptionsItemSelected(MenuItem item) {
     99 //
    100 //        // Handles option menu selections:
    101 //        // Home button - close event info activity and start the main calendar one
    102 //        // Edit button - start the event edit activity and close the info activity
    103 //        // Delete button - start a delete query that calls a runnable that close the info activity
    104 //
    105 //        switch (item.getItemId()) {
    106 //            case android.R.id.home:
    107 //                Intent launchIntent = new Intent();
    108 //                launchIntent.setAction(Intent.ACTION_VIEW);
    109 //                launchIntent.setData(Uri.parse(CalendarContract.CONTENT_URI + "/time"));
    110 //                launchIntent.setFlags(
    111 //                        Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    112 //                startActivity(launchIntent);
    113 //                finish();
    114 //                return true;
    115 //            case R.id.info_action_edit:
    116 //                Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId);
    117 //                Intent intent = new Intent(Intent.ACTION_EDIT, uri);
    118 //                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis);
    119 //                intent.putExtra(EXTRA_EVENT_END_TIME, mEndMillis);
    120 //                intent.setClass(this, EditEventActivity.class);
    121 //                intent.putExtra(EVENT_EDIT_ON_LAUNCH, true);
    122 //                startActivity(intent);
    123 //                finish ();
    124 //                break;
    125 //            case R.id.info_action_delete:
    126 //                DeleteEventHelper deleteHelper = new DeleteEventHelper(
    127 //                        this, this, true /* exitWhenDone */);
    128 //                deleteHelper.delete(mStartMillis, mEndMillis, mEventId, -1, onDeleteRunnable);
    129 //                break;
    130 //            default:
    131 //                break;
    132 //        }
    133 //        return super.onOptionsItemSelected(item);
    134 //    }
    135 
    136     // runs at the end of a delete action and closes the activity
    137 //    private Runnable onDeleteRunnable = new Runnable() {
    138 //        @Override
    139 //        public void run() {
    140 //            finish ();
    141 //        }
    142 //    };
    143 
    144     @Override
    145     protected void onNewIntent(Intent intent) {
    146         // From the Android Dev Guide: "It's important to note that when
    147         // onNewIntent(Intent) is called, the Activity has not been restarted,
    148         // so the getIntent() method will still return the Intent that was first
    149         // received with onCreate(). This is why setIntent(Intent) is called
    150         // inside onNewIntent(Intent) (just in case you call getIntent() at a
    151         // later time)."
    152         setIntent(intent);
    153     }
    154 
    155 
    156     @Override
    157     public void onSaveInstanceState(Bundle outState) {
    158         super.onSaveInstanceState(outState);
    159     }
    160 
    161     @Override
    162     protected void onResume() {
    163         super.onResume();
    164     }
    165 
    166     @Override
    167     protected void onPause() {
    168         super.onPause();
    169     }
    170 
    171     @Override
    172     protected void onDestroy() {
    173         super.onDestroy();
    174     }
    175 }
    176