diff options
author | Rohit Yengisetty <rohit@cyngn.com> | 2015-01-06 10:20:21 -0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-18 13:52:42 -0700 |
commit | 4251408f2eb71b250035b711ee195c7c2b68a26b (patch) | |
tree | ff40af78071680a54d09230f65ce9f175d077e5a | |
parent | 36d9e578bdad4a59604a7a5abe8b04316ca89b7d (diff) | |
download | android_packages_apps_Calendar-4251408f2eb71b250035b711ee195c7c2b68a26b.tar.gz android_packages_apps_Calendar-4251408f2eb71b250035b711ee195c7c2b68a26b.tar.bz2 android_packages_apps_Calendar-4251408f2eb71b250035b711ee195c7c2b68a26b.zip |
Calendar - Added provisions to show/hide Floating Action Button.
YearView actively shows/hides FAB when the user scrolls to keep all
the content accessible.
Change-Id: I8005861cb6ecf98758782c034adcc19e30951df8
-rw-r--r-- | res/values/integers.xml | 2 | ||||
-rw-r--r-- | src/com/android/calendar/AllInOneActivity.java | 44 | ||||
-rw-r--r-- | src/com/android/calendar/CalendarController.java | 5 | ||||
-rw-r--r-- | src/com/android/calendar/year/YearViewAdapter.java | 6 | ||||
-rw-r--r-- | src/com/android/calendar/year/YearViewPagerFragment.java | 88 |
5 files changed, 138 insertions, 7 deletions
diff --git a/res/values/integers.xml b/res/values/integers.xml index 1ca466fb..1d71eda1 100644 --- a/res/values/integers.xml +++ b/res/values/integers.xml @@ -34,5 +34,7 @@ <integer name="work_end_minutes">1200</integer> <!-- The time (in milliseconds) to scroll in or out the mini month and calendar controls --> <integer name="calendar_controls_animation_time">400</integer> + <!-- Default duration for fast zippy animations (in ms) --> + <integer name="animation_duration_fast">200</integer> </resources> diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java index b43a1262..4fd59dd4 100644 --- a/src/com/android/calendar/AllInOneActivity.java +++ b/src/com/android/calendar/AllInOneActivity.java @@ -65,7 +65,10 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.accessibility.AccessibilityEvent; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.OvershootInterpolator; import android.widget.DatePicker; +import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.RelativeLayout.LayoutParams; @@ -138,6 +141,11 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH private View mCalendarsList; private View mMiniMonthContainer; private View mSecondaryPane; + private View mFab; + private int mFabHeight; + private int mFabYOffset; + private boolean mFabShowing = true; + private int mFabAnimDuration; private String mTimeZone; private boolean mShowCalendarControls; private boolean mShowEventInfoFullScreenAgenda; @@ -435,6 +443,12 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH mMiniMonthContainer = findViewById(R.id.mini_month_container); mSecondaryPane = findViewById(R.id.secondary_pane); + mFab = (ImageButton) findViewById(R.id.floating_action_button); + mFabHeight = res.getDimensionPixelSize(R.dimen.floating_action_button_height); + mFabYOffset = res.getDimensionPixelSize( + R.dimen.floating_action_button_margin_bottom); + mFabAnimDuration = res.getInteger(R.integer.animation_duration_fast); + // Must register as the first activity because this activity can modify // the list of event handlers in it's handle method. This affects who // the rest of the handlers the controller dispatches to are. @@ -1088,6 +1102,7 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing()); } ft.commit(); + showFab(); // reset FAB after every transaction ; on every refresh of main_pane } } @@ -1177,7 +1192,8 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH @Override public long getSupportedEventTypes() { - return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE; + return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE | + EventType.HIDE_FAB | EventType.SHOW_FAB; } @Override @@ -1311,10 +1327,36 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH if (!mIsTabletConfig) { mActionBarMenuSpinnerAdapter.setTime(mController.getTime()); } + } else if (event.eventType == EventType.SHOW_FAB) { + showFab(); + } else if (event.eventType == EventType.HIDE_FAB) { + hideFab(); } updateSecondaryTitleFields(displayTime); } + private void showFab() { + if (!mFabShowing) { + mFab.animate() + .translationY(0) // move FAB to the originally specified location in layout + .setDuration(mFabAnimDuration) + .setInterpolator(new OvershootInterpolator()); + + mFabShowing = true; + } + } + + private void hideFab() { + if (mFabShowing) { + mFab.animate() + .translationY(mFabHeight + mFabYOffset) // FAB disappears off container bounds + .setDuration(mFabAnimDuration) + .setInterpolator(new AccelerateInterpolator()); + + mFabShowing = false; + } + } + // Needs to be in proguard whitelist // Specified as listener via android:onClick in a layout xml public void handleSelectSyncedCalendarsClicked(View v) { diff --git a/src/com/android/calendar/CalendarController.java b/src/com/android/calendar/CalendarController.java index fd5392f1..0406cd54 100644 --- a/src/com/android/calendar/CalendarController.java +++ b/src/com/android/calendar/CalendarController.java @@ -127,6 +127,11 @@ public class CalendarController { // select which calendars to display final long LAUNCH_SELECT_VISIBLE_CALENDARS = 1L << 11; + + // events for showing and hiding the floating action button (FAB) + final long SHOW_FAB = 1L << 12; + + final long HIDE_FAB = 1L << 13; } /** diff --git a/src/com/android/calendar/year/YearViewAdapter.java b/src/com/android/calendar/year/YearViewAdapter.java index f4bd4964..f08deadd 100644 --- a/src/com/android/calendar/year/YearViewAdapter.java +++ b/src/com/android/calendar/year/YearViewAdapter.java @@ -26,7 +26,7 @@ public class YearViewAdapter extends BaseAdapter implements View.OnTouchListener /* Define configuration parameters for a month view */ // fraction of the view occupied by the header - private static final double MONTH_HEADER_HEIGHT = 0.30; + private static final double MONTH_HEADER_HEIGHT = 0.25; // fraction of the header to use for the month title text private static final double MONTH_LABEL_FONT_SIZE = MONTH_HEADER_HEIGHT * 0.30; @@ -35,7 +35,7 @@ public class YearViewAdapter extends BaseAdapter implements View.OnTouchListener private static final double PADDING = 0.05; // fraction of the view to use for text - private static final double MONTH_DAY_TEXT_SIZE = (1 - (2 * PADDING)) * (0.7) / 7; + private static final double MONTH_DAY_TEXT_SIZE = (1 - (2 * PADDING)) * (0.5) / 7; // The padding b/w the week rows. The container height sans that taken up by the header // is equally distributed among six rows @@ -92,7 +92,7 @@ public class YearViewAdapter extends BaseAdapter implements View.OnTouchListener mHeight = height; // calculate the dimensions of each of the months mMonthWidth = mWidth / mColumns; - mMonthHeight = mHeight / (NUMBER_OF_MONTHS / mColumns); + mMonthHeight = mMonthWidth; } @Override diff --git a/src/com/android/calendar/year/YearViewPagerFragment.java b/src/com/android/calendar/year/YearViewPagerFragment.java index 494aac69..7b0e17d4 100644 --- a/src/com/android/calendar/year/YearViewPagerFragment.java +++ b/src/com/android/calendar/year/YearViewPagerFragment.java @@ -20,6 +20,7 @@ package com.android.calendar.year; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; +import android.content.Context; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -30,7 +31,9 @@ import android.text.format.DateUtils; import android.text.format.Time; import android.util.Log; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.GridView; @@ -38,6 +41,7 @@ import com.android.calendar.CalendarController; import com.android.calendar.CalendarController.EventType; import com.android.calendar.CalendarController.EventInfo; import com.android.calendar.R; +import com.android.calendar.Utils; import com.android.datetimepicker.date.MonthView; import com.android.datetimepicker.date.SimpleMonthView; @@ -199,9 +203,9 @@ public class YearViewPagerFragment extends Fragment implements CalendarControlle super.onAttach(activity); int orientation = getActivity().getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_PORTRAIT) { - mColumns = 3; // the year view will be in a 4x3 configuration + mColumns = 2; // the year view will be in a 6x2 configuration } else { - mColumns = 4; // the year view will be in a 3x4 configuration + mColumns = 3; // the year view will be in a 4x3 configuration } } @@ -217,7 +221,7 @@ public class YearViewPagerFragment extends Fragment implements CalendarControlle @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mGridView = new GridView(getActivity()); + mGridView = new CustomGridView(getActivity()); // set layout params ? mGridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH); mGridView.setNumColumns(mColumns); @@ -249,5 +253,83 @@ public class YearViewPagerFragment extends Fragment implements CalendarControlle return mGridView; } + + /** + * A GridView with a custom scroll listener that is tied to the display status of FAB + */ + public static class CustomGridView extends GridView { + private float mClickY; + private float mTouchSlop; + private CalendarController mController; + + public CustomGridView(Context context) { + super(context); + mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); + mController = CalendarController.getInstance(context); + } + + /* + Overiding method to implement a scroll gesture listener which is interested in + vertical movements to show or hide FAB + */ + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + int action = ev.getAction(); + + switch(action) { + case MotionEvent.ACTION_DOWN: + mClickY = ev.getY(); + break; + case MotionEvent.ACTION_MOVE: + processNewMoveEvent(ev); + break; + } + + return super.onInterceptTouchEvent(ev); + } + + /* + Overiding method to implement a scroll gesture listener which is interested in + vertical movements to show or hide FAB + */ + @Override + public boolean onTouchEvent(MotionEvent ev) { + int action = ev.getAction(); + + switch(action) { + case MotionEvent.ACTION_MOVE: + processNewMoveEvent(ev); + break; + } + + return super.onTouchEvent(ev); + } + + /** + * Expects the input MotionEvent to be a move event. This function determines if there + * is enough vertical movement beyond the defined threshold. If there is sufficient + * movement along the vertical, the FAB is shown or hidden based on the direction of + * movement (up or down) + * + * @param ev event to parse + */ + private void processNewMoveEvent(MotionEvent ev) { + float distanceMoved = mClickY - ev.getY(); + if (Math.abs(distanceMoved) > mTouchSlop ) { + if (distanceMoved < 0) { + // scrolled down so show FAB + mController.sendEvent(this, EventType.SHOW_FAB, null, null, null, + 0, 0, 0, null, null); + } else { + // scrolle up so hide FAB + mController.sendEvent(this, EventType.HIDE_FAB, null, null, null, + 0, 0, 0, null, null); + + } + // set Y to the current place in the gesture + mClickY = ev.getY(); + } + } + } } } |