blob: b8a9ba3fd54c846d02e68e7ccdaef596daa7551f [file] [log] [blame]
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.calendar.selectcalendars;
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.database.ContentObserver;
import android.os.Bundle;
import android.os.Handler;
import android.provider.CalendarContract;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.android.calendar.AbstractCalendarActivity;
import com.android.calendar.CalendarController;
import com.android.calendar.CalendarController.EventType;
import com.android.calendar.CalendarController.ViewType;
import com.android.calendar.R;
import com.android.calendar.Utils;
public class SelectVisibleCalendarsActivity extends AbstractCalendarActivity {
private SelectVisibleCalendarsFragment mFragment;
private CalendarController mController;
// Create an observer so that we can update the views whenever a
// Calendar event changes.
private final ContentObserver mObserver = new ContentObserver(new Handler()) {
@Override
public boolean deliverSelfNotifications() {
return true;
}
@Override
public void onChange(boolean selfChange) {
mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
}
};
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.simple_frame_layout);
mController = CalendarController.getInstance(this);
mFragment = (SelectVisibleCalendarsFragment) getFragmentManager().findFragmentById(
R.id.main_frame);
if (mFragment == null) {
mFragment = new SelectVisibleCalendarsFragment(R.layout.calendar_sync_item);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.main_frame, mFragment);
ft.show(mFragment);
ft.commit();
}
}
@Override
public void onResume() {
super.onResume();
getContentResolver().registerContentObserver(CalendarContract.Events.CONTENT_URI,
true, mObserver);
}
@Override
public void onPause() {
super.onPause();
getContentResolver().unregisterContentObserver(mObserver);
}
// Needs to be in proguard whitelist
// Specified as listener via android:onClick in a layout xml
public void handleSelectSyncedCalendarsClicked(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, SelectSyncedCalendarsMultiAccountActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getActionBar()
.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Utils.returnToCalendarHome(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}