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.preference.PreferenceManager;
27 import android.provider.Calendar;
28 import android.provider.Settings;
30 public class LaunchActivity extends Activity {
31 private static final String TAG = "LaunchActivity";
33 static final String KEY_DETAIL_VIEW = "DETAIL_VIEW";
34 //Part of example on opening sync settings page
35 private static final String AUTHORITIES_FILTER_KEY = "authorities";
37 private Bundle mExtras;
40 protected void onCreate(Bundle icicle) {
41 super.onCreate(icicle);
42 mExtras = getIntent().getExtras();
44 // Our UI is not something intended for the user to see. We just
45 // stick around until we can figure out what to do next based on
46 // the current state of the system.
47 // Removed because it causes draw problems when entering in landscape orientation
48 // TODO: Figure out draw problem. Original reason for removal due to b/2008662
51 // Only try looking for an account if this is the first launch.
53 Account[] accounts = AccountManager.get(this).getAccounts();
54 if(accounts.length > 0) {
55 // If the only account is an account that can't use Calendar we let the user into
56 // Calendar, but they can't create any events until they add an account with a
60 // If we failed to find a valid Calendar, bounce the user to the account settings
61 // screen. Using the Calendar authority has the added benefit of only showing
62 // account types that use Calendar when you enter the add account screen from here.
63 // TODO bounce them to the add account screen if accessible from the public api
64 final Intent intent = new Intent(Settings.ACTION_SYNC_SETTINGS);
65 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
66 intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
69 startActivity(intent);
75 private void launchCalendarView() {
76 // Get the data for from this intent, if any
77 Intent myIntent = getIntent();
78 Uri myData = myIntent.getData();
80 // Set up the intent for the start activity
81 Intent intent = new Intent();
83 intent.setData(myData);
86 String defaultViewKey = CalendarPreferenceActivity.KEY_START_VIEW;
87 if (mExtras != null) {
88 intent.putExtras(mExtras);
89 if (mExtras.getBoolean(KEY_DETAIL_VIEW, false)) {
90 defaultViewKey = CalendarPreferenceActivity.KEY_DETAILED_VIEW;
93 intent.putExtras(myIntent);
95 SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this);
96 String startActivity = prefs.getString(defaultViewKey,
97 CalendarPreferenceActivity.DEFAULT_START_VIEW);
99 intent.setClassName(this, startActivity);
100 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
101 startActivity(intent);