CalendarSettingsActivity.java revision 34bb002c19ed9488fc466909f9d729600232d305
1/* 2 * Copyright (C) 2010 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 17package com.android.calendar; 18 19import android.accounts.Account; 20import android.accounts.AccountManager; 21import android.app.ActionBar; 22import android.content.ContentResolver; 23import android.content.Intent; 24import android.net.Uri; 25import android.os.Bundle; 26import android.preference.PreferenceActivity; 27import android.provider.Calendar; 28import android.provider.Calendar.Calendars; 29import android.provider.Settings; 30import android.view.Menu; 31import android.view.MenuInflater; 32import android.view.MenuItem; 33 34import java.util.List; 35 36public class CalendarSettingsActivity extends PreferenceActivity { 37 @Override 38 public void onBuildHeaders(List<Header> target) { 39 loadHeadersFromResource(R.xml.calendar_settings_headers, target); 40 getActionBar().setDisplayOptions( 41 ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); 42 Account[] accounts = AccountManager.get(this).getAccounts(); 43 if (accounts != null) { 44 int length = accounts.length; 45 for (int i = 0; i < length; i++) { 46 Account acct = accounts[i]; 47 if (ContentResolver.getIsSyncable(acct, Calendar.AUTHORITY) > 0) { 48 Header accountHeader = new Header(); 49 accountHeader.title = acct.name; 50 accountHeader.fragment = 51 "com.android.calendar.selectcalendars.SelectCalendarsSyncFragment"; 52 Bundle args = new Bundle(); 53 args.putString(Calendars.ACCOUNT_NAME, acct.name); 54 args.putString(Calendars.ACCOUNT_TYPE, acct.type); 55 accountHeader.fragmentArguments = args; 56 target.add(1, accountHeader); 57 } 58 } 59 } 60 } 61 62 @Override 63 public boolean onOptionsItemSelected(MenuItem item) { 64 switch (item.getItemId()) { 65 case android.R.id.home: 66 Intent launchIntent = new Intent(); 67 launchIntent.setAction(Intent.ACTION_VIEW); 68 launchIntent.setData(Uri.parse("content://com.android.calendar/time")); 69 launchIntent.setFlags( 70 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); 71 startActivity(launchIntent); 72 return true; 73 case R.id.action_add_account: 74 Intent nextIntent = new Intent(Settings.ACTION_ADD_ACCOUNT); 75 final String[] array = { "com.android.calendar" }; 76 nextIntent.putExtra(Settings.EXTRA_AUTHORITIES, array); 77 nextIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 78 startActivity(nextIntent); 79 return true; 80 } 81 return super.onOptionsItemSelected(item); 82 } 83 84 @Override 85 public boolean onCreateOptionsMenu(Menu menu) { 86 MenuInflater inflater = getMenuInflater(); 87 inflater.inflate(R.menu.settings_title_bar, menu); 88 return true; 89 } 90} 91