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.accounts.AccountManagerCallback;
22 import android.accounts.AccountManagerFuture;
23 import android.accounts.AuthenticatorException;
24 import android.accounts.OperationCanceledException;
25 import android.app.Activity;
26 import android.content.Intent;
27 import android.content.SharedPreferences;
28 import android.net.Uri;
29 import android.os.Bundle;
30 import android.preference.PreferenceManager;
32 import com.google.android.gsf.GoogleLoginServiceConstants;
34 import java.io.IOException;
37 public class LaunchActivity extends Activity {
38 static final String KEY_DETAIL_VIEW = "DETAIL_VIEW";
39 static final String GMAIL_AUTH_SERVICE = "mail";
41 private Bundle mExtras;
44 protected void onCreate(Bundle icicle) {
45 super.onCreate(icicle);
46 mExtras = getIntent().getExtras();
48 // Our UI is not something intended for the user to see. We just
49 // stick around until we can figure out what to do next based on
50 // the current state of the system.
51 // TODO: Removed until framework is fixed in b/2008662
54 // Only try looking for an account if this is the first launch.
56 // This will request a Gmail account and if none are present, it will
57 // invoke SetupWizard to login or create one. The result is returned
58 // via the Future2Callback.
59 Bundle bundle = new Bundle();
60 bundle.putCharSequence("optional_message", getText(R.string.calendar_plug));
61 AccountManager.get(this).getAuthTokenByFeatures(
62 GoogleLoginServiceConstants.ACCOUNT_TYPE, GMAIL_AUTH_SERVICE,
63 new String[]{GoogleLoginServiceConstants.FEATURE_LEGACY_HOSTED_OR_GOOGLE}, this,
64 bundle, null /* loginOptions */, new AccountManagerCallback<Bundle>() {
65 public void run(AccountManagerFuture<Bundle> future) {
67 Bundle result = future.getResult();
68 onAccountsLoaded(new Account(
69 result.getString(GoogleLoginServiceConstants.AUTH_ACCOUNT_KEY),
70 result.getString(AccountManager.KEY_ACCOUNT_TYPE)));
71 } catch (OperationCanceledException e) {
73 } catch (IOException e) {
75 } catch (AuthenticatorException e) {
79 }, null /* handler */);
83 private void onAccountsLoaded(Account account) {
84 // Get the data for from this intent, if any
85 Intent myIntent = getIntent();
86 Uri myData = myIntent.getData();
88 // Set up the intent for the start activity
89 Intent intent = new Intent();
91 intent.setData(myData);
94 String defaultViewKey = CalendarPreferenceActivity.KEY_START_VIEW;
95 if (mExtras != null) {
96 intent.putExtras(mExtras);
97 if (mExtras.getBoolean(KEY_DETAIL_VIEW, false)) {
98 defaultViewKey = CalendarPreferenceActivity.KEY_DETAILED_VIEW;
101 intent.putExtras(myIntent);
103 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
104 String startActivity = prefs.getString(defaultViewKey,
105 CalendarPreferenceActivity.DEFAULT_START_VIEW);
107 intent.setClassName(this, startActivity);
108 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
109 startActivity(intent);