1 /* 2 * Copyright (C) 2006 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 17 package com.android.calendar; 18 19 import android.content.Intent; 20 import android.content.SharedPreferences; 21 import android.os.Bundle; 22 import android.preference.PreferenceManager; 23 import android.text.format.Time; 24 import android.view.View; 25 import android.view.ViewGroup.LayoutParams; 26 import android.widget.ProgressBar; 27 import android.widget.ViewSwitcher; 28 29 public class WeekActivity extends CalendarActivity implements ViewSwitcher.ViewFactory { 30 /** 31 * The view id used for all the views we create. It's OK to have all child 32 * views have the same ID. This ID is used to pick which view receives 33 * focus when a view hierarchy is saved / restore 34 */ 35 private static final int VIEW_ID = 1; 36 37 @Override onCreate(Bundle icicle)38 protected void onCreate(Bundle icicle) { 39 super.onCreate(icicle); 40 41 setContentView(R.layout.week_activity); 42 43 mSelectedDay = Utils.timeFromIntent(getIntent()); 44 mViewSwitcher = (ViewSwitcher) findViewById(R.id.switcher); 45 mViewSwitcher.setFactory(this); 46 mViewSwitcher.getCurrentView().requestFocus(); 47 mProgressBar = (ProgressBar) findViewById(R.id.progress_circular); 48 } 49 makeView()50 public View makeView() { 51 WeekView wv = new WeekView(this); 52 wv.setId(VIEW_ID); 53 wv.setLayoutParams(new ViewSwitcher.LayoutParams( 54 LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 55 wv.setSelectedDay(mSelectedDay); 56 return wv; 57 } 58 59 @Override onNewIntent(Intent intent)60 protected void onNewIntent(Intent intent) { 61 long timeMillis = Utils.timeFromIntentInMillis(intent); 62 if (timeMillis > 0) { 63 Time time = new Time(); 64 time.set(timeMillis); 65 goTo(time, false); 66 } 67 } 68 69 @Override onResume()70 protected void onResume() { 71 super.onResume(); 72 73 CalendarView view1 = (CalendarView) mViewSwitcher.getCurrentView(); 74 CalendarView view2 = (CalendarView) mViewSwitcher.getNextView(); 75 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 76 77 String str = prefs.getString(CalendarPreferenceActivity.KEY_DETAILED_VIEW, 78 CalendarPreferenceActivity.DEFAULT_DETAILED_VIEW); 79 view1.setDetailedView(str); 80 view2.setDetailedView(str); 81 } 82 83 @Override onPause()84 protected void onPause() { 85 super.onPause(); 86 CalendarView view = (CalendarView) mViewSwitcher.getCurrentView(); 87 mSelectedDay = view.getSelectedDay(); 88 89 // Record Week View as the (new) start view 90 Utils.setDefaultView(this, CalendarApplication.WEEK_VIEW_ID); 91 } 92 } 93