1 /* 2 * Copyright (C) 2007 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.accounts.Account; 20 import android.accounts.AccountManager; 21 import android.app.Activity; 22 import android.content.Intent; 23 import android.content.SharedPreferences; 24 import android.net.Uri; 25 import android.os.Bundle; 26 import android.provider.Calendar; 27 import android.provider.Settings; 28 29 public class LaunchActivity extends Activity { 30 private static final String TAG = "LaunchActivity"; 31 32 static final String KEY_DETAIL_VIEW = "DETAIL_VIEW"; 33 static final String KEY_VIEW_TYPE = "VIEW"; 34 static final String VIEW_TYPE_DAY = "DAY"; 35 36 private Bundle mExtras; 37 38 @Override onCreate(Bundle icicle)39 protected void onCreate(Bundle icicle) { 40 super.onCreate(icicle); 41 mExtras = getIntent().getExtras(); 42 43 // Our UI is not something intended for the user to see. We just 44 // stick around until we can figure out what to do next based on 45 // the current state of the system. 46 // Removed because it causes draw problems when entering in landscape orientation 47 // TODO: Figure out draw problem. Original reason for removal due to b/2008662 48 // setVisible(false); 49 50 // Only try looking for an account if this is the first launch. 51 if (icicle == null) { 52 Account[] accounts = AccountManager.get(this).getAccounts(); 53 if(accounts.length > 0) { 54 // If the only account is an account that can't use Calendar we let the user into 55 // Calendar, but they can't create any events until they add an account with a 56 // Calendar. 57 launchCalendarView(); 58 } else { 59 // If we failed to find a valid Calendar, bounce the user to the account settings 60 // screen. Using the Calendar authority has the added benefit of only showing 61 // account types that use Calendar when you enter the add account screen from here. 62 final Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT); 63 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 64 intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] { 65 Calendar.AUTHORITY 66 }); 67 startActivityForResult(intent, 0); 68 } 69 } 70 } 71 72 @Override onActivityResult(int requestCode, int resultCode, Intent data)73 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 74 Account[] accounts = AccountManager.get(this).getAccounts(); 75 if(accounts.length > 0) { 76 // If the only account is an account that can't use Calendar we let the user into 77 // Calendar, but they can't create any events until they add an account with a 78 // Calendar. 79 launchCalendarView(); 80 } else { 81 finish(); 82 } 83 } 84 launchCalendarView()85 private void launchCalendarView() { 86 // Get the data for from this intent, if any 87 Intent myIntent = getIntent(); 88 Uri myData = myIntent.getData(); 89 90 // Set up the intent for the start activity 91 Intent intent = new Intent(); 92 if (myData != null) { 93 intent.setData(myData); 94 } 95 96 String defaultViewKey = CalendarPreferenceActivity.KEY_START_VIEW; 97 if (mExtras != null) { 98 intent.putExtras(mExtras); 99 if (mExtras.getBoolean(KEY_DETAIL_VIEW, false)) { 100 defaultViewKey = CalendarPreferenceActivity.KEY_DETAILED_VIEW; 101 } else if (VIEW_TYPE_DAY.equals(mExtras.getString(KEY_VIEW_TYPE))) { 102 defaultViewKey = VIEW_TYPE_DAY; 103 } 104 } 105 intent.putExtras(myIntent); 106 107 SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this); 108 String startActivity; 109 if (defaultViewKey.equals(VIEW_TYPE_DAY)) { 110 startActivity = CalendarApplication.ACTIVITY_NAMES[CalendarApplication.DAY_VIEW_ID]; 111 } else if (defaultViewKey.equals(CalendarPreferenceActivity.KEY_DETAILED_VIEW)) { 112 startActivity = prefs.getString(defaultViewKey, 113 CalendarPreferenceActivity.DEFAULT_DETAILED_VIEW); 114 } else { 115 startActivity = prefs.getString(defaultViewKey, 116 CalendarPreferenceActivity.DEFAULT_START_VIEW); 117 } 118 119 intent.setClassName(this, startActivity); 120 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); 121 startActivity(intent); 122 finish(); 123 } 124 } 125