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