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

Commit ea695cb0 authored by Yorke Lee's avatar Yorke Lee
Browse files

Handle dialpad animations better

This change prevents the dialpad from animating in when
the dialer is launched directly with a dial intent.

Change-Id: I6d7378de0484dcdadecbbc0e9c25d4c8ed1e3800
parent 15ef3e1d
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -422,15 +422,19 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
    }

    private void showDialpadFragment(boolean animate) {
        mDialpadFragment.setAdjustTranslationForAnimation(animate);
        final FragmentTransaction ft = getFragmentManager().beginTransaction();
        if (animate) {
            ft.setCustomAnimations(R.anim.slide_in, 0);
        } else {
            mDialpadFragment.setYFraction(0);
        }
        ft.show(mDialpadFragment);
        ft.commit();
    }

    private void hideDialpadFragment(boolean animate) {
        mDialpadFragment.setAdjustTranslationForAnimation(animate);
        final FragmentTransaction ft = getFragmentManager().beginTransaction();
        if (animate) {
            ft.setCustomAnimations(0, R.anim.slide_out);
@@ -619,9 +623,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O

        if (mDialpadFragment != null && (phoneIsInUse() || isDialIntent(intent))) {
            mDialpadFragment.setStartedFromNewIntent(true);
            // TODO krelease: This should use showDialpadFragment(false) to avoid animating
            // the dialpad in. Need to fix the onPreDrawListener in NewDialpadFragment first.
            showDialpadFragment(true);
            showDialpadFragment(false);
        }
    }

+14 −3
Original line number Diff line number Diff line
@@ -262,6 +262,7 @@ public class DialpadFragment extends Fragment

    private boolean mStartedFromNewIntent = false;
    private boolean mFirstLaunch = false;
    private boolean mAdjustTranslationForAnimation = false;

    private static final String PREF_DIGITS_FILLED_BY_INTENT = "pref_digits_filled_by_intent";

@@ -350,15 +351,17 @@ public class DialpadFragment extends Fragment
                false);
        fragmentView.buildLayer();

        // TODO krelease: Get rid of this ugly hack which is to prevent the first frame of the
        // animation from drawing the fragment at translationY = 0
        final ViewTreeObserver vto = fragmentView.getViewTreeObserver();
        // Adjust the translation of the DialpadFragment in a preDrawListener instead of in
        // DialtactsActivity, because at the point in time when the DialpadFragment is added,
        // its views have not been laid out yet.
        final OnPreDrawListener preDrawListener = new OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {

                if (isHidden()) return true;
                if (fragmentView.getTranslationY() == 0) {
                if (mAdjustTranslationForAnimation && fragmentView.getTranslationY() == 0) {
                    ((DialpadSlidingLinearLayout) fragmentView).setYFraction(
                            DIALPAD_SLIDE_FRACTION);
                }
@@ -1691,4 +1694,12 @@ public class DialpadFragment extends Fragment
            activity.hideSearchBar();
        }
    }

    public void setAdjustTranslationForAnimation(boolean value) {
        mAdjustTranslationForAnimation = value;
    }

    public void setYFraction(float yFraction) {
        ((DialpadSlidingLinearLayout) getView()).setYFraction(yFraction);
    }
}