Loading src/com/android/deskclock/AlarmClockFragment.java +20 −8 Original line number Diff line number Diff line Loading @@ -269,6 +269,12 @@ public class AlarmClockFragment extends DeskClockFragment implements public void onResume() { super.onResume(); final DeskClock activity = (DeskClock) getActivity(); if (activity.getSelectedTab() == DeskClock.ALARM_TAB_INDEX) { setFabAppearance(); setLeftRightButtonAppearance(); } if (mAdapter != null) { mAdapter.notifyDataSetChanged(); } Loading Loading @@ -1442,18 +1448,24 @@ public class AlarmClockFragment extends DeskClockFragment implements } @Override public void setFabAppearance(ImageButton fab) { if (!isAdded()) { public void setFabAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mFab == null || activity.getSelectedTab() != DeskClock.ALARM_TAB_INDEX) { return; } fab.setVisibility(View.VISIBLE); fab.setImageResource(R.drawable.ic_fab_plus); fab.setContentDescription(getString(R.string.button_alarms)); mFab.setVisibility(View.VISIBLE); mFab.setImageResource(R.drawable.ic_fab_plus); mFab.setContentDescription(getString(R.string.button_alarms)); } @Override public void setLeftRightButtonAppearance(ImageButton left, ImageButton right) { left.setVisibility(View.INVISIBLE); right.setVisibility(View.INVISIBLE); public void setLeftRightButtonAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mLeftButton == null || mRightButton == null || activity.getSelectedTab() != DeskClock.ALARM_TAB_INDEX) { return; } mLeftButton.setVisibility(View.INVISIBLE); mRightButton.setVisibility(View.INVISIBLE); } } src/com/android/deskclock/ClockFragment.java +21 −9 Original line number Diff line number Diff line Loading @@ -209,11 +209,17 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen @Override public void onResume() { super.onResume(); final DeskClock activity = (DeskClock) getActivity(); if (activity.getSelectedTab() == DeskClock.CLOCK_TAB_INDEX) { setFabAppearance(); setLeftRightButtonAppearance(); } mPrefs.registerOnSharedPreferenceChangeListener(this); mDateFormat = getString(R.string.abbrev_wday_month_day_no_year); mDateFormatForAccessibility = getString(R.string.full_wday_month_day_no_year); Activity activity = getActivity(); Utils.setQuarterHourUpdater(mHandler, mQuarterHourUpdater); // Besides monitoring when quarter-hour changes, monitor other actions that // effect clock time Loading Loading @@ -277,18 +283,24 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen } @Override public void setFabAppearance(ImageButton fab) { if (!isAdded()) { public void setFabAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mFab == null || activity.getSelectedTab() != DeskClock.CLOCK_TAB_INDEX) { return; } fab.setVisibility(View.VISIBLE); fab.setImageResource(R.drawable.ic_globe); fab.setContentDescription(getString(R.string.button_cities)); mFab.setVisibility(View.VISIBLE); mFab.setImageResource(R.drawable.ic_globe); mFab.setContentDescription(getString(R.string.button_cities)); } @Override public void setLeftRightButtonAppearance(ImageButton left, ImageButton right) { left.setVisibility(View.INVISIBLE); right.setVisibility(View.INVISIBLE); public void setLeftRightButtonAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mLeftButton == null || mRightButton == null || activity.getSelectedTab() != DeskClock.CLOCK_TAB_INDEX) { return; } mLeftButton.setVisibility(View.INVISIBLE); mRightButton.setVisibility(View.INVISIBLE); } } src/com/android/deskclock/DeskClock.java +28 −10 Original line number Diff line number Diff line Loading @@ -477,9 +477,8 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe TabInfo info = mTabs.get(getRtlPosition(position)); fragment = Fragment.instantiate(mContext, info.clss.getName(), info.args); if (fragment instanceof TimerFragment) { ((TimerFragment) fragment).setFabAppearance(mFab); ((TimerFragment) fragment).setLeftRightButtonAppearance(mLeftButton, mRightButton); ((TimerFragment) fragment).setFabAppearance(); ((TimerFragment) fragment).setLeftRightButtonAppearance(); } } return fragment; Loading Loading @@ -543,10 +542,12 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { TabInfo info = (TabInfo) tab.getTag(); int position = info.getPosition(); final TabInfo info = (TabInfo) tab.getTag(); final int position = info.getPosition(); final int rtlSafePosition = getRtlPosition(position); mSelectedTab = position; if (mIsFirstLaunch && getRtlPosition(position) == CLOCK_TAB_INDEX) { if (mIsFirstLaunch && isClockTab(rtlSafePosition)) { mLeftButton.setVisibility(View.INVISIBLE); mRightButton.setVisibility(View.INVISIBLE); mFab.setVisibility(View.VISIBLE); Loading @@ -554,11 +555,11 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe mFab.setContentDescription(getString(R.string.button_cities)); mIsFirstLaunch = false; } else { DeskClockFragment f = (DeskClockFragment) getItem(getRtlPosition(position)); f.setFabAppearance(mFab); f.setLeftRightButtonAppearance(mLeftButton, mRightButton); DeskClockFragment f = (DeskClockFragment) getItem(rtlSafePosition); f.setFabAppearance(); f.setLeftRightButtonAppearance(); } mPager.setCurrentItem(getRtlPosition(position)); mPager.setCurrentItem(rtlSafePosition); } @Override Loading @@ -566,6 +567,11 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe // Do nothing } private boolean isClockTab(int rtlSafePosition) { final int clockTabIndex = isRtl() ? RTL_CLOCK_TAB_INDEX : CLOCK_TAB_INDEX; return rtlSafePosition == clockTabIndex; } public void notifySelectedPage(int page) { notifyPageChanged(page); } Loading Loading @@ -712,4 +718,16 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe } return position; } public ImageButton getFab() { return mFab; } public ImageButton getLeftButton() { return mLeftButton; } public ImageButton getRightButton() { return mRightButton; } } src/com/android/deskclock/DeskClockFragment.java +19 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.deskclock; import android.app.Activity; import android.app.Fragment; import android.os.Bundle; import android.support.v4.widget.PopupMenuCompat; Loading @@ -26,6 +27,10 @@ import android.widget.PopupMenu; public class DeskClockFragment extends Fragment { protected ImageButton mFab; protected ImageButton mLeftButton; protected ImageButton mRightButton; public void onPageChanged(int page) { // Do nothing here , only in derived classes } Loading @@ -34,11 +39,23 @@ public class DeskClockFragment extends Fragment { // Do nothing here , only in derived classes } public void setFabAppearance(ImageButton fab) { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final Activity activity = getActivity(); if (activity instanceof DeskClock) { final DeskClock deskClockActivity = (DeskClock) activity; mFab = deskClockActivity.getFab(); mLeftButton = deskClockActivity.getLeftButton(); mRightButton = deskClockActivity.getRightButton(); } } public void setFabAppearance() { // Do nothing here , only in derived classes } public void setLeftRightButtonAppearance(ImageButton left, ImageButton right) { public void setLeftRightButtonAppearance() { // Do nothing here , only in derived classes } Loading src/com/android/deskclock/stopwatch/StopwatchFragment.java +41 −107 Original line number Diff line number Diff line Loading @@ -43,9 +43,6 @@ public class StopwatchFragment extends DeskClockFragment int mState = Stopwatches.STOPWATCH_RESET; // Stopwatch views that are accessed by the activity private ImageButton mFab; private ImageButton mLeftButton; private ImageButton mRightButton; private CircleTimerView mTime; private CountingTimerView mTimeText; private ListView mLapsList; Loading Loading @@ -399,7 +396,8 @@ public class StopwatchFragment extends DeskClockFragment mTime.readFromSharedPref(prefs, "sw"); mTime.postInvalidate(); setButtons(mState); setFabAppearance(); setLeftRightButtonAppearance(); mTimeText.setTime(mAccumulatedTime, true, true); if (mState == Stopwatches.STOPWATCH_RUNNING) { acquireWakeLock(); Loading Loading @@ -458,8 +456,9 @@ public class StopwatchFragment extends DeskClockFragment mTimeText.setTime(mAccumulatedTime, true, true); mTimeText.blinkTimeStr(true); updateCurrentLap(mAccumulatedTime); setButtons(Stopwatches.STOPWATCH_STOPPED); mState = Stopwatches.STOPWATCH_STOPPED; setFabAppearance(); setLeftRightButtonAppearance(); } private void doStart(long time) { Loading @@ -470,14 +469,16 @@ public class StopwatchFragment extends DeskClockFragment if (mTime.isAnimating()) { mTime.startIntervalAnimation(); } setButtons(Stopwatches.STOPWATCH_RUNNING); mState = Stopwatches.STOPWATCH_RUNNING; setFabAppearance(); setLeftRightButtonAppearance(); } private void doLap() { if (DEBUG) LogUtils.v("StopwatchFragment.doLap"); showLaps(); setButtons(Stopwatches.STOPWATCH_RUNNING); setFabAppearance(); setLeftRightButtonAppearance(); } private void doReset() { Loading @@ -493,15 +494,9 @@ public class StopwatchFragment extends DeskClockFragment mTime.reset(); mTimeText.setTime(mAccumulatedTime, true, true); mTimeText.blinkTimeStr(false); setButtons(Stopwatches.STOPWATCH_RESET); mState = Stopwatches.STOPWATCH_RESET; } private void showShareButton(boolean show) { if (mRightButton != null) { mRightButton.setVisibility(show ? View.VISIBLE : View.INVISIBLE); mRightButton.setEnabled(show); } setFabAppearance(); setLeftRightButtonAppearance(); } private void shareResults() { Loading Loading @@ -542,80 +537,10 @@ public class StopwatchFragment extends DeskClockFragment return output; } /*** * Update the buttons on the stopwatch according to the watch's state */ private void setButtons(int state) { final Activity activity = getActivity(); if (!(activity instanceof DeskClock)) { return; } final DeskClock deskClockActivity = (DeskClock) activity; if (mFab == null || deskClockActivity.getSelectedTab() != DeskClock .STOPWATCH_TAB_INDEX) { return; } switch (state) { case Stopwatches.STOPWATCH_RESET: setButton(mLeftButton, R.string.sw_lap_button, R.drawable.ic_lap, false, View.INVISIBLE); changeFab(R.drawable.ic_fab_play); showShareButton(false); break; case Stopwatches.STOPWATCH_RUNNING: setButton(mLeftButton, R.string.sw_lap_button, R.drawable.ic_lap, !reachedMaxLaps(), View.VISIBLE); changeFab(R.drawable.ic_fab_pause); showShareButton(false); break; case Stopwatches.STOPWATCH_STOPPED: setButton(mLeftButton, R.string.sw_reset_button, R.drawable.ic_reset, true, View.VISIBLE); changeFab(R.drawable.ic_fab_play); showShareButton(true); break; default: break; } } private void changeFab(int id) { if (getActivity() instanceof DeskClock) { if (mFab != null && ((DeskClock) getActivity()).getSelectedTab() == DeskClock.STOPWATCH_TAB_INDEX) { if (id == R.drawable.ic_fab_play) { mFab.setContentDescription(getString(R.string.sw_start_button)); } else if (id == R.drawable.ic_fab_pause){ mFab.setContentDescription(getString(R.string.sw_stop_button)); } mFab.setImageResource(id); mFab.setVisibility(View.VISIBLE); } } } private boolean reachedMaxLaps() { return mLapsAdapter.getCount() >= Stopwatches.MAX_LAPS; } /*** * Set a single button with the string and states provided. * @param b - Button view to update * @param text - Text in button * @param enabled - enable/disables the button * @param visibility - Show/hide the button */ private void setButton( ImageButton b, int text, int drawableId, boolean enabled, int visibility) { if (b == null) { return; } b.setContentDescription(getActivity().getResources().getString(text)); b.setImageResource(drawableId); b.setVisibility(visibility); b.setEnabled(enabled); } /*** * Handle action when user presses the lap button * @param time - in hundredth of a second Loading Loading @@ -873,12 +798,11 @@ public class StopwatchFragment extends DeskClockFragment } @Override public void setFabAppearance(ImageButton fab) { if (!isAdded()) { public void setFabAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mFab == null || activity.getSelectedTab() != DeskClock.STOPWATCH_TAB_INDEX) { return; } mFab = fab; if (mState == Stopwatches.STOPWATCH_RUNNING) { mFab.setImageResource(R.drawable.ic_fab_pause); mFab.setContentDescription(getString(R.string.sw_stop_button)); Loading @@ -890,27 +814,37 @@ public class StopwatchFragment extends DeskClockFragment } @Override public void setLeftRightButtonAppearance(ImageButton left, ImageButton right) { if (!isAdded()) { public void setLeftRightButtonAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mLeftButton == null || mRightButton == null || activity.getSelectedTab() != DeskClock.STOPWATCH_TAB_INDEX) { return; } mRightButton.setImageResource(R.drawable.ic_share); mRightButton.setContentDescription(getString(R.string.sw_share_button)); mLeftButton = left; mRightButton = right; mLeftButton.setVisibility(mState == Stopwatches.STOPWATCH_RESET ? View.INVISIBLE : View.VISIBLE); mRightButton.setVisibility(mState == Stopwatches.STOPWATCH_RESET || mState == Stopwatches.STOPWATCH_RUNNING ? View.INVISIBLE : View.VISIBLE); if (mState == Stopwatches.STOPWATCH_RUNNING) { switch (mState) { case Stopwatches.STOPWATCH_RESET: mLeftButton.setImageResource(R.drawable.ic_lap); mLeftButton.setContentDescription(getString(R.string.sw_lap_button)); } else { mLeftButton.setEnabled(false); mLeftButton.setVisibility(View.INVISIBLE); mRightButton.setVisibility(View.INVISIBLE); break; case Stopwatches.STOPWATCH_RUNNING: mLeftButton.setImageResource(R.drawable.ic_lap); mLeftButton.setContentDescription(getString(R.string.sw_lap_button)); mLeftButton.setEnabled(!reachedMaxLaps()); mLeftButton.setVisibility(View.VISIBLE); mRightButton.setVisibility(View.INVISIBLE); break; case Stopwatches.STOPWATCH_STOPPED: mLeftButton.setImageResource(R.drawable.ic_reset); mLeftButton.setContentDescription(getString(R.string.sw_reset_button)); mLeftButton.setEnabled(true); mLeftButton.setVisibility(View.VISIBLE); mRightButton.setVisibility(View.VISIBLE); break; } mRightButton.setImageResource(R.drawable.ic_share); mRightButton.setContentDescription(getString(R.string.sw_share_button)); } } Loading
src/com/android/deskclock/AlarmClockFragment.java +20 −8 Original line number Diff line number Diff line Loading @@ -269,6 +269,12 @@ public class AlarmClockFragment extends DeskClockFragment implements public void onResume() { super.onResume(); final DeskClock activity = (DeskClock) getActivity(); if (activity.getSelectedTab() == DeskClock.ALARM_TAB_INDEX) { setFabAppearance(); setLeftRightButtonAppearance(); } if (mAdapter != null) { mAdapter.notifyDataSetChanged(); } Loading Loading @@ -1442,18 +1448,24 @@ public class AlarmClockFragment extends DeskClockFragment implements } @Override public void setFabAppearance(ImageButton fab) { if (!isAdded()) { public void setFabAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mFab == null || activity.getSelectedTab() != DeskClock.ALARM_TAB_INDEX) { return; } fab.setVisibility(View.VISIBLE); fab.setImageResource(R.drawable.ic_fab_plus); fab.setContentDescription(getString(R.string.button_alarms)); mFab.setVisibility(View.VISIBLE); mFab.setImageResource(R.drawable.ic_fab_plus); mFab.setContentDescription(getString(R.string.button_alarms)); } @Override public void setLeftRightButtonAppearance(ImageButton left, ImageButton right) { left.setVisibility(View.INVISIBLE); right.setVisibility(View.INVISIBLE); public void setLeftRightButtonAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mLeftButton == null || mRightButton == null || activity.getSelectedTab() != DeskClock.ALARM_TAB_INDEX) { return; } mLeftButton.setVisibility(View.INVISIBLE); mRightButton.setVisibility(View.INVISIBLE); } }
src/com/android/deskclock/ClockFragment.java +21 −9 Original line number Diff line number Diff line Loading @@ -209,11 +209,17 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen @Override public void onResume() { super.onResume(); final DeskClock activity = (DeskClock) getActivity(); if (activity.getSelectedTab() == DeskClock.CLOCK_TAB_INDEX) { setFabAppearance(); setLeftRightButtonAppearance(); } mPrefs.registerOnSharedPreferenceChangeListener(this); mDateFormat = getString(R.string.abbrev_wday_month_day_no_year); mDateFormatForAccessibility = getString(R.string.full_wday_month_day_no_year); Activity activity = getActivity(); Utils.setQuarterHourUpdater(mHandler, mQuarterHourUpdater); // Besides monitoring when quarter-hour changes, monitor other actions that // effect clock time Loading Loading @@ -277,18 +283,24 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen } @Override public void setFabAppearance(ImageButton fab) { if (!isAdded()) { public void setFabAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mFab == null || activity.getSelectedTab() != DeskClock.CLOCK_TAB_INDEX) { return; } fab.setVisibility(View.VISIBLE); fab.setImageResource(R.drawable.ic_globe); fab.setContentDescription(getString(R.string.button_cities)); mFab.setVisibility(View.VISIBLE); mFab.setImageResource(R.drawable.ic_globe); mFab.setContentDescription(getString(R.string.button_cities)); } @Override public void setLeftRightButtonAppearance(ImageButton left, ImageButton right) { left.setVisibility(View.INVISIBLE); right.setVisibility(View.INVISIBLE); public void setLeftRightButtonAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mLeftButton == null || mRightButton == null || activity.getSelectedTab() != DeskClock.CLOCK_TAB_INDEX) { return; } mLeftButton.setVisibility(View.INVISIBLE); mRightButton.setVisibility(View.INVISIBLE); } }
src/com/android/deskclock/DeskClock.java +28 −10 Original line number Diff line number Diff line Loading @@ -477,9 +477,8 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe TabInfo info = mTabs.get(getRtlPosition(position)); fragment = Fragment.instantiate(mContext, info.clss.getName(), info.args); if (fragment instanceof TimerFragment) { ((TimerFragment) fragment).setFabAppearance(mFab); ((TimerFragment) fragment).setLeftRightButtonAppearance(mLeftButton, mRightButton); ((TimerFragment) fragment).setFabAppearance(); ((TimerFragment) fragment).setLeftRightButtonAppearance(); } } return fragment; Loading Loading @@ -543,10 +542,12 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { TabInfo info = (TabInfo) tab.getTag(); int position = info.getPosition(); final TabInfo info = (TabInfo) tab.getTag(); final int position = info.getPosition(); final int rtlSafePosition = getRtlPosition(position); mSelectedTab = position; if (mIsFirstLaunch && getRtlPosition(position) == CLOCK_TAB_INDEX) { if (mIsFirstLaunch && isClockTab(rtlSafePosition)) { mLeftButton.setVisibility(View.INVISIBLE); mRightButton.setVisibility(View.INVISIBLE); mFab.setVisibility(View.VISIBLE); Loading @@ -554,11 +555,11 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe mFab.setContentDescription(getString(R.string.button_cities)); mIsFirstLaunch = false; } else { DeskClockFragment f = (DeskClockFragment) getItem(getRtlPosition(position)); f.setFabAppearance(mFab); f.setLeftRightButtonAppearance(mLeftButton, mRightButton); DeskClockFragment f = (DeskClockFragment) getItem(rtlSafePosition); f.setFabAppearance(); f.setLeftRightButtonAppearance(); } mPager.setCurrentItem(getRtlPosition(position)); mPager.setCurrentItem(rtlSafePosition); } @Override Loading @@ -566,6 +567,11 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe // Do nothing } private boolean isClockTab(int rtlSafePosition) { final int clockTabIndex = isRtl() ? RTL_CLOCK_TAB_INDEX : CLOCK_TAB_INDEX; return rtlSafePosition == clockTabIndex; } public void notifySelectedPage(int page) { notifyPageChanged(page); } Loading Loading @@ -712,4 +718,16 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe } return position; } public ImageButton getFab() { return mFab; } public ImageButton getLeftButton() { return mLeftButton; } public ImageButton getRightButton() { return mRightButton; } }
src/com/android/deskclock/DeskClockFragment.java +19 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.deskclock; import android.app.Activity; import android.app.Fragment; import android.os.Bundle; import android.support.v4.widget.PopupMenuCompat; Loading @@ -26,6 +27,10 @@ import android.widget.PopupMenu; public class DeskClockFragment extends Fragment { protected ImageButton mFab; protected ImageButton mLeftButton; protected ImageButton mRightButton; public void onPageChanged(int page) { // Do nothing here , only in derived classes } Loading @@ -34,11 +39,23 @@ public class DeskClockFragment extends Fragment { // Do nothing here , only in derived classes } public void setFabAppearance(ImageButton fab) { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final Activity activity = getActivity(); if (activity instanceof DeskClock) { final DeskClock deskClockActivity = (DeskClock) activity; mFab = deskClockActivity.getFab(); mLeftButton = deskClockActivity.getLeftButton(); mRightButton = deskClockActivity.getRightButton(); } } public void setFabAppearance() { // Do nothing here , only in derived classes } public void setLeftRightButtonAppearance(ImageButton left, ImageButton right) { public void setLeftRightButtonAppearance() { // Do nothing here , only in derived classes } Loading
src/com/android/deskclock/stopwatch/StopwatchFragment.java +41 −107 Original line number Diff line number Diff line Loading @@ -43,9 +43,6 @@ public class StopwatchFragment extends DeskClockFragment int mState = Stopwatches.STOPWATCH_RESET; // Stopwatch views that are accessed by the activity private ImageButton mFab; private ImageButton mLeftButton; private ImageButton mRightButton; private CircleTimerView mTime; private CountingTimerView mTimeText; private ListView mLapsList; Loading Loading @@ -399,7 +396,8 @@ public class StopwatchFragment extends DeskClockFragment mTime.readFromSharedPref(prefs, "sw"); mTime.postInvalidate(); setButtons(mState); setFabAppearance(); setLeftRightButtonAppearance(); mTimeText.setTime(mAccumulatedTime, true, true); if (mState == Stopwatches.STOPWATCH_RUNNING) { acquireWakeLock(); Loading Loading @@ -458,8 +456,9 @@ public class StopwatchFragment extends DeskClockFragment mTimeText.setTime(mAccumulatedTime, true, true); mTimeText.blinkTimeStr(true); updateCurrentLap(mAccumulatedTime); setButtons(Stopwatches.STOPWATCH_STOPPED); mState = Stopwatches.STOPWATCH_STOPPED; setFabAppearance(); setLeftRightButtonAppearance(); } private void doStart(long time) { Loading @@ -470,14 +469,16 @@ public class StopwatchFragment extends DeskClockFragment if (mTime.isAnimating()) { mTime.startIntervalAnimation(); } setButtons(Stopwatches.STOPWATCH_RUNNING); mState = Stopwatches.STOPWATCH_RUNNING; setFabAppearance(); setLeftRightButtonAppearance(); } private void doLap() { if (DEBUG) LogUtils.v("StopwatchFragment.doLap"); showLaps(); setButtons(Stopwatches.STOPWATCH_RUNNING); setFabAppearance(); setLeftRightButtonAppearance(); } private void doReset() { Loading @@ -493,15 +494,9 @@ public class StopwatchFragment extends DeskClockFragment mTime.reset(); mTimeText.setTime(mAccumulatedTime, true, true); mTimeText.blinkTimeStr(false); setButtons(Stopwatches.STOPWATCH_RESET); mState = Stopwatches.STOPWATCH_RESET; } private void showShareButton(boolean show) { if (mRightButton != null) { mRightButton.setVisibility(show ? View.VISIBLE : View.INVISIBLE); mRightButton.setEnabled(show); } setFabAppearance(); setLeftRightButtonAppearance(); } private void shareResults() { Loading Loading @@ -542,80 +537,10 @@ public class StopwatchFragment extends DeskClockFragment return output; } /*** * Update the buttons on the stopwatch according to the watch's state */ private void setButtons(int state) { final Activity activity = getActivity(); if (!(activity instanceof DeskClock)) { return; } final DeskClock deskClockActivity = (DeskClock) activity; if (mFab == null || deskClockActivity.getSelectedTab() != DeskClock .STOPWATCH_TAB_INDEX) { return; } switch (state) { case Stopwatches.STOPWATCH_RESET: setButton(mLeftButton, R.string.sw_lap_button, R.drawable.ic_lap, false, View.INVISIBLE); changeFab(R.drawable.ic_fab_play); showShareButton(false); break; case Stopwatches.STOPWATCH_RUNNING: setButton(mLeftButton, R.string.sw_lap_button, R.drawable.ic_lap, !reachedMaxLaps(), View.VISIBLE); changeFab(R.drawable.ic_fab_pause); showShareButton(false); break; case Stopwatches.STOPWATCH_STOPPED: setButton(mLeftButton, R.string.sw_reset_button, R.drawable.ic_reset, true, View.VISIBLE); changeFab(R.drawable.ic_fab_play); showShareButton(true); break; default: break; } } private void changeFab(int id) { if (getActivity() instanceof DeskClock) { if (mFab != null && ((DeskClock) getActivity()).getSelectedTab() == DeskClock.STOPWATCH_TAB_INDEX) { if (id == R.drawable.ic_fab_play) { mFab.setContentDescription(getString(R.string.sw_start_button)); } else if (id == R.drawable.ic_fab_pause){ mFab.setContentDescription(getString(R.string.sw_stop_button)); } mFab.setImageResource(id); mFab.setVisibility(View.VISIBLE); } } } private boolean reachedMaxLaps() { return mLapsAdapter.getCount() >= Stopwatches.MAX_LAPS; } /*** * Set a single button with the string and states provided. * @param b - Button view to update * @param text - Text in button * @param enabled - enable/disables the button * @param visibility - Show/hide the button */ private void setButton( ImageButton b, int text, int drawableId, boolean enabled, int visibility) { if (b == null) { return; } b.setContentDescription(getActivity().getResources().getString(text)); b.setImageResource(drawableId); b.setVisibility(visibility); b.setEnabled(enabled); } /*** * Handle action when user presses the lap button * @param time - in hundredth of a second Loading Loading @@ -873,12 +798,11 @@ public class StopwatchFragment extends DeskClockFragment } @Override public void setFabAppearance(ImageButton fab) { if (!isAdded()) { public void setFabAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mFab == null || activity.getSelectedTab() != DeskClock.STOPWATCH_TAB_INDEX) { return; } mFab = fab; if (mState == Stopwatches.STOPWATCH_RUNNING) { mFab.setImageResource(R.drawable.ic_fab_pause); mFab.setContentDescription(getString(R.string.sw_stop_button)); Loading @@ -890,27 +814,37 @@ public class StopwatchFragment extends DeskClockFragment } @Override public void setLeftRightButtonAppearance(ImageButton left, ImageButton right) { if (!isAdded()) { public void setLeftRightButtonAppearance() { final DeskClock activity = (DeskClock) getActivity(); if (mLeftButton == null || mRightButton == null || activity.getSelectedTab() != DeskClock.STOPWATCH_TAB_INDEX) { return; } mRightButton.setImageResource(R.drawable.ic_share); mRightButton.setContentDescription(getString(R.string.sw_share_button)); mLeftButton = left; mRightButton = right; mLeftButton.setVisibility(mState == Stopwatches.STOPWATCH_RESET ? View.INVISIBLE : View.VISIBLE); mRightButton.setVisibility(mState == Stopwatches.STOPWATCH_RESET || mState == Stopwatches.STOPWATCH_RUNNING ? View.INVISIBLE : View.VISIBLE); if (mState == Stopwatches.STOPWATCH_RUNNING) { switch (mState) { case Stopwatches.STOPWATCH_RESET: mLeftButton.setImageResource(R.drawable.ic_lap); mLeftButton.setContentDescription(getString(R.string.sw_lap_button)); } else { mLeftButton.setEnabled(false); mLeftButton.setVisibility(View.INVISIBLE); mRightButton.setVisibility(View.INVISIBLE); break; case Stopwatches.STOPWATCH_RUNNING: mLeftButton.setImageResource(R.drawable.ic_lap); mLeftButton.setContentDescription(getString(R.string.sw_lap_button)); mLeftButton.setEnabled(!reachedMaxLaps()); mLeftButton.setVisibility(View.VISIBLE); mRightButton.setVisibility(View.INVISIBLE); break; case Stopwatches.STOPWATCH_STOPPED: mLeftButton.setImageResource(R.drawable.ic_reset); mLeftButton.setContentDescription(getString(R.string.sw_reset_button)); mLeftButton.setEnabled(true); mLeftButton.setVisibility(View.VISIBLE); mRightButton.setVisibility(View.VISIBLE); break; } mRightButton.setImageResource(R.drawable.ic_share); mRightButton.setContentDescription(getString(R.string.sw_share_button)); } }