2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.calendar;
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;
29 public class LaunchActivity extends Activity {
30 private static final String TAG = "LaunchActivity";
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";
36 private Bundle mExtras;
39 protected void onCreate(Bundle icicle) {
40 super.onCreate(icicle);
41 mExtras = getIntent().getExtras();
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
50 // Only try looking for an account if this is the first launch.
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
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 // TODO bounce them to the add account screen if accessible from the public api
63 final Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
64 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
65 intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] {
68 startActivity(intent);
74 private void launchCalendarView() {
75 // Get the data for from this intent, if any
76 Intent myIntent = getIntent();
77 Uri myData = myIntent.getData();
79 // Set up the intent for the start activity
80 Intent intent = new Intent();
82 intent.setData(myData);
85 String defaultViewKey = CalendarPreferenceActivity.KEY_START_VIEW;
86 if (mExtras != null) {
87 intent.putExtras(mExtras);
88 if (mExtras.getBoolean(KEY_DETAIL_VIEW, false)) {
89 defaultViewKey = CalendarPreferenceActivity.KEY_DETAILED_VIEW;
90 } else if (VIEW_TYPE_DAY.equals(mExtras.getString(KEY_VIEW_TYPE))) {
91 defaultViewKey = VIEW_TYPE_DAY;
94 intent.putExtras(myIntent);
96 SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this);
98 if (defaultViewKey.equals(VIEW_TYPE_DAY)) {
99 startActivity = CalendarApplication.ACTIVITY_NAMES[CalendarApplication.DAY_VIEW_ID];
101 startActivity = prefs.getString(defaultViewKey,
102 CalendarPreferenceActivity.DEFAULT_START_VIEW);
105 intent.setClassName(this, startActivity);
106 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
107 startActivity(intent);