Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 305692f8 authored by Budi Kusmiantoro's avatar Budi Kusmiantoro
Browse files

resolved conflicts for merge of 104bdcc2 to lmp-mr1-dev

Change-Id: If6c2f3cbb6be237799c64c95fa46266c06522329
parents 090a567f 104bdcc2
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -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();
        }
@@ -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);
    }
}
+21 −9
Original line number Diff line number Diff line
@@ -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
@@ -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);
    }
}
+16 −5
Original line number Diff line number Diff line
@@ -476,9 +476,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;
@@ -556,8 +555,8 @@ public class DeskClock extends Activity implements LabelDialogFragment.TimerLabe
                mIsFirstLaunch = false;
            } else {
                DeskClockFragment f = (DeskClockFragment) getItem(rtlSafePosition);
                f.setFabAppearance(mFab);
                f.setLeftRightButtonAppearance(mLeftButton, mRightButton);
                f.setFabAppearance();
                f.setLeftRightButtonAppearance();
            }
            mPager.setCurrentItem(rtlSafePosition);
        }
@@ -718,4 +717,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;
    }
}
+19 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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
    }
@@ -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
    }

+41 −107
Original line number Diff line number Diff line
@@ -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;
@@ -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();
@@ -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) {
@@ -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() {
@@ -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() {
@@ -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
@@ -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));
@@ -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