OSDN Git Service

b/2492707 If all guests have no response will be called 'Guests' not 'Maybe'
[android-x86/packages-apps-Calendar.git] / src / com / android / calendar / LaunchActivity.java
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
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                 // 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[] {
66                     Calendar.AUTHORITY
67                 });
68                 startActivity(intent);
69                 finish();
70             }
71         }
72     }
73
74     private void launchCalendarView() {
75         // Get the data for from this intent, if any
76         Intent myIntent = getIntent();
77         Uri myData = myIntent.getData();
78
79         // Set up the intent for the start activity
80         Intent intent = new Intent();
81         if (myData != null) {
82             intent.setData(myData);
83         }
84
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;
92             }
93         }
94         intent.putExtras(myIntent);
95
96         SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this);
97         String startActivity;
98         if (defaultViewKey.equals(VIEW_TYPE_DAY)) {
99             startActivity = CalendarApplication.ACTIVITY_NAMES[CalendarApplication.DAY_VIEW_ID];
100         } else {
101             startActivity = prefs.getString(defaultViewKey,
102                 CalendarPreferenceActivity.DEFAULT_START_VIEW);
103         }
104
105         intent.setClassName(this, startActivity);
106         intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
107         startActivity(intent);
108         finish();
109     }
110 }