use of com.android.calendar.month.MonthByWeekFragment in project Etar-Calendar by Etar-Group.
the class AllInOneActivity method setMainPane.
private void setMainPane(FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
if (mOnSaveInstanceStateCalled) {
return;
}
if (!force && mCurrentView == viewType) {
return;
}
// Remove this when transition to and from month view looks fine.
boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
FragmentManager fragmentManager = getFragmentManager();
// TODO remove this if framework ever supports nested fragments
if (mCurrentView == ViewType.AGENDA) {
// If it was, we need to do some cleanup on it to prevent the
// edit/delete buttons from coming back on a rotation.
Fragment oldFrag = fragmentManager.findFragmentById(viewId);
if (oldFrag instanceof AgendaFragment) {
((AgendaFragment) oldFrag).removeFragments(fragmentManager);
}
}
if (viewType != mCurrentView) {
// controller's and are used for intercepting the back button.
if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
mPreviousView = mCurrentView;
}
mCurrentView = viewType;
}
// Create new fragment
Fragment frag = null;
Fragment secFrag = null;
switch(viewType) {
case ViewType.AGENDA:
mNavigationView.getMenu().findItem(R.id.agenda_menu_item).setChecked(true);
frag = new AgendaFragment(timeMillis, false);
if (mIsTabletConfig) {
mToolbar.setTitle(R.string.agenda_view);
}
break;
case ViewType.DAY:
mNavigationView.getMenu().findItem(R.id.day_menu_item).setChecked(true);
frag = new DayFragment(timeMillis, 1);
if (mIsTabletConfig) {
mToolbar.setTitle(R.string.day_view);
}
break;
case ViewType.MONTH:
mNavigationView.getMenu().findItem(R.id.month_menu_item).setChecked(true);
frag = new MonthByWeekFragment(timeMillis, false);
if (mShowAgendaWithMonth) {
secFrag = new AgendaFragment(timeMillis, false);
}
if (mIsTabletConfig) {
mToolbar.setTitle(R.string.month_view);
}
break;
case ViewType.WEEK:
default:
mNavigationView.getMenu().findItem(R.id.week_menu_item).setChecked(true);
frag = new DayFragment(timeMillis, Utils.getDaysPerWeek(this));
if (mIsTabletConfig) {
mToolbar.setTitle(R.string.week_view);
}
break;
}
// current view.
if (mCalendarToolbarHandler != null) {
mCalendarToolbarHandler.setCurrentMainView(viewType);
}
if (!mIsTabletConfig) {
refreshActionbarTitle(timeMillis);
}
// Show date only on tablet configurations in views different than Agenda
if (!mIsTabletConfig) {
mDateRange.setVisibility(View.GONE);
} else if (viewType != ViewType.AGENDA) {
mDateRange.setVisibility(View.VISIBLE);
} else {
mDateRange.setVisibility(View.GONE);
}
// Clear unnecessary buttons from the option menu when switching from the agenda view
if (viewType != ViewType.AGENDA) {
clearOptionsMenu();
}
boolean doCommit = false;
if (ft == null) {
doCommit = true;
ft = fragmentManager.beginTransaction();
}
if (doTransition) {
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
}
ft.replace(viewId, frag);
if (mShowAgendaWithMonth) {
if (secFrag != null) {
ft.replace(R.id.secondary_pane, secFrag);
mSecondaryPane.setVisibility(View.VISIBLE);
} else {
mSecondaryPane.setVisibility(View.GONE);
Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
if (f != null) {
ft.remove(f);
}
mController.deregisterEventHandler(R.id.secondary_pane);
}
}
if (DEBUG) {
Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
}
// If the key is already registered this will replace it
mController.registerEventHandler(viewId, (EventHandler) frag);
if (secFrag != null) {
mController.registerEventHandler(viewId, (EventHandler) secFrag);
}
if (doCommit) {
if (DEBUG) {
Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
}
ft.commit();
}
}
use of com.android.calendar.month.MonthByWeekFragment in project Etar-Calendar by Etar-Group.
the class AllInOneActivity method initFragments.
private void initFragments(long timeMillis, int viewType, Bundle icicle) {
if (DEBUG) {
Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
}
FragmentTransaction ft = getFragmentManager().beginTransaction();
if (mShowCalendarControls) {
Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
ft.replace(R.id.mini_month, miniMonthFrag);
mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
ft.replace(R.id.calendar_list, selectCalendarsFrag);
mController.registerEventHandler(R.id.calendar_list, (EventHandler) selectCalendarsFrag);
}
if (!mShowCalendarControls || viewType == ViewType.EDIT) {
mMiniMonth.setVisibility(View.GONE);
mCalendarsList.setVisibility(View.GONE);
}
EventInfo info = null;
if (viewType == ViewType.EDIT) {
mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
long eventId = -1;
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
try {
eventId = Long.parseLong(data.getLastPathSegment());
} catch (NumberFormatException e) {
if (DEBUG) {
Log.d(TAG, "Create new event");
}
}
} else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
}
long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
info = new EventInfo();
if (end != -1) {
info.endTime = new Time();
info.endTime.set(end);
}
if (begin != -1) {
info.startTime = new Time();
info.startTime.set(begin);
}
info.id = eventId;
// We set the viewtype so if the user presses back when they are
// done editing the controller knows we were in the Edit Event
// screen. Likewise for eventId
mController.setViewType(viewType);
mController.setEventId(eventId);
} else {
mPreviousView = viewType;
}
setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
// this needs to be after setMainPane()
ft.commit();
Time t = new Time(mTimeZone);
t.set(timeMillis);
if (viewType == ViewType.AGENDA && icicle != null) {
mController.sendEvent(this, EventType.GO_TO, t, null, icicle.getLong(BUNDLE_KEY_EVENT_ID, -1), viewType);
} else if (viewType != ViewType.EDIT) {
mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
}
}
Aggregations