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

Commit 739e1ed7 authored by James Lemieux's avatar James Lemieux
Browse files

Fix fab disappearing on rotation when no timers exist

Bug: 25779786

The issue here is that TimerSetupView actually customizes the fab.
These customizations include setting it invisible. It was a poor design
to share the fab with this view. So, the fix is that the view now holds
its own fab-like button that it is free to manipulate without fear of
altering the app-wide fab state unintentionally.

Change-Id: Ie83b03c98db4f77e0be912b122b6f74c2c7e6c8a
parent ad9d3e6d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:baselineAligned="false"
        android:orientation="horizontal">

        <!-- This nested ltr layout cannot be combined with the parent because
@@ -32,8 +33,7 @@
            android:layout_marginBottom="@dimen/footer_button_size"
            android:layoutDirection="ltr"
            android:gravity="center"
            android:orientation="vertical"
            >
            android:orientation="vertical">

            <com.android.deskclock.timer.TimerView
                android:id="@+id/timer_time_text"
@@ -88,6 +88,6 @@

    </LinearLayout>

    <include layout="@layout/timer_cancel_button" />
    <include layout="@layout/timer_setup_buttons" />

</FrameLayout>
 No newline at end of file
+8 −9
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:baselineAligned="false"
        android:orientation="horizontal"
        app:layout_behavior="com.android.deskclock.widget.toast.LinearLayoutWithSnackbarBehavior">

@@ -68,9 +69,9 @@

            <ImageButton
                android:id="@+id/left_button"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal"
                android:layout_width="@dimen/design_fab_size_normal"
                android:layout_height="@dimen/design_fab_size_normal"
                android:layout_gravity="center"
                android:contentDescription="@null"
                android:scaleType="center" />

@@ -100,14 +101,12 @@

            <ImageButton
                android:id="@+id/right_button"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal"
                android:layout_width="@dimen/design_fab_size_normal"
                android:layout_height="@dimen/design_fab_size_normal"
                android:layout_gravity="center"
                android:contentDescription="@null"
                android:scaleType="center" />

        </FrameLayout>

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -66,6 +66,6 @@
        android:id="@+id/fourth"
        layout="@layout/three_keys_view" />

    <include layout="@layout/timer_cancel_button" />
    <include layout="@layout/timer_setup_buttons" />

</LinearLayout>
+67 −0
Original line number Diff line number Diff line
@@ -16,25 +16,52 @@

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="@dimen/footer_button_size"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/timer_cancel"
    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_gravity="start|center_vertical"
        android:layout_weight="1">

        <ImageButton
            android:id="@+id/timer_cancel"
            android:layout_width="@dimen/design_fab_size_normal"
            android:layout_height="@dimen/design_fab_size_normal"
            android:layout_gravity="center"
            android:contentDescription="@string/timer_cancel"
        android:paddingEnd="20dp"
            android:scaleType="center"
        android:src="@drawable/ic_cancel"
        android:textSize="@dimen/button_font_size" />
            android:src="@drawable/ic_cancel" />

    </FrameLayout>

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="start|center_vertical"
        android:layout_weight="1">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/timer_create"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="@dimen/fab_margin"
            android:contentDescription="@string/timer_start"
            android:src="@drawable/ic_start_white_24dp"
            android:visibility="invisible"
            app:borderWidth="0dp"
            app:elevation="@dimen/fab_elevation" />

    </FrameLayout>

    <Space
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" />
        android:layout_weight="1" />

</LinearLayout>
+53 −47
Original line number Diff line number Diff line
@@ -119,6 +119,8 @@ public class TimerFragment extends DeskClockFragment {
        mCancelCreateButton = (ImageButton) view.findViewById(R.id.timer_cancel);
        mCancelCreateButton.setOnClickListener(new CancelCreateListener());

        view.findViewById(R.id.timer_create).setOnClickListener(new CreateListener());

        final Resources resources = getResources();
        mShortAnimationDuration = resources.getInteger(android.R.integer.config_shortAnimTime);
        mMediumAnimationDuration = resources.getInteger(android.R.integer.config_mediumAnimTime);
@@ -217,7 +219,8 @@ public class TimerFragment extends DeskClockFragment {

        // If the timer creation view is visible, store the input for later restoration.
        if (mCurrentView == mCreateTimerView) {
            outState.putSerializable(KEY_TIMER_SETUP_STATE, mCreateTimerView.getState());
            mTimerSetupState = mCreateTimerView.getState();
            outState.putSerializable(KEY_TIMER_SETUP_STATE, mTimerSetupState);
        }
    }

@@ -252,33 +255,15 @@ public class TimerFragment extends DeskClockFragment {
            }

        } else if (mCurrentView == mCreateTimerView) {
            mFab.setVisibility(VISIBLE);
            mCreateTimerView.registerStartButton(mFab);
            mCreateTimerView.initializeStartButtonVisibility();
            mFab.setImageResource(R.drawable.ic_start_white_24dp);
            mFab.setContentDescription(getString(R.string.timer_start));
            mFab.setVisibility(INVISIBLE);
        }
    }

    @Override
    public void onFabClick(View view) {
        if (mCurrentView == mCreateTimerView) {
            // Create the new timer.
            final long length = mCreateTimerView.getTimeInMillis();
            final Timer timer = DataModel.getDataModel().addTimer(length, "", false);
            Events.sendTimerEvent(R.string.action_create, R.string.label_deskclock);

            // Start the new timer.
            DataModel.getDataModel().startTimer(timer);
            Events.sendTimerEvent(R.string.action_start, R.string.label_deskclock);

            // Display the freshly created timer view.
            mViewPager.setCurrentItem(0);

            // Return to the list of timers.
            animateToView(mTimersView, null);
        } else {
        final Timer timer = getTimer();

        // If no timer is currently showing a fab action is meaningless.
        if (timer == null) {
            return;
        }
@@ -298,7 +283,6 @@ public class TimerFragment extends DeskClockFragment {
                break;
        }
    }
    }

    @Override
    public void setLeftRightButtonAppearance() {
@@ -432,14 +416,6 @@ public class TimerFragment extends DeskClockFragment {
        mTimersView.setVisibility(GONE);
        mCreateTimerView.setVisibility(VISIBLE);

        // Prepare the state of the create view.
        mCreateTimerView.reset();
        mCreateTimerView.updateDeleteButtonAndDivider();
        mCreateTimerView.registerStartButton(mFab);
        if (getSelectedTab() == DeskClock.TIMER_TAB_INDEX) {
            mCreateTimerView.initializeStartButtonVisibility();
        }

        // Record the fact that the create view is visible.
        mCurrentView = mCreateTimerView;

@@ -678,12 +654,42 @@ public class TimerFragment extends DeskClockFragment {
        }
    }

    /**
     * Clicking the play icon on the timer creation page creates a new timer and returns to the
     * timers list.
     */
    private class CreateListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            // Create the new timer.
            final long length = mCreateTimerView.getTimeInMillis();
            final Timer timer = DataModel.getDataModel().addTimer(length, "", false);
            Events.sendTimerEvent(R.string.action_create, R.string.label_deskclock);

            // Start the new timer.
            DataModel.getDataModel().startTimer(timer);
            Events.sendTimerEvent(R.string.action_start, R.string.label_deskclock);

            // Reset the state of the create view.
            mCreateTimerView.reset();

            // Display the freshly created timer view.
            mViewPager.setCurrentItem(0);

            // Return to the list of timers.
            animateToView(mTimersView, null);
        }
    }

    /**
     * Clicking the X icon on the timer creation page returns to the timers list.
     */
    private class CancelCreateListener implements OnClickListener {
        @Override
        public void onClick(View view) {
            // Reset the state of the create view.
            mCreateTimerView.reset();

            if (hasTimers()) {
                animateToView(mTimersView, null);
            }
Loading