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

Commit 0d4404c0 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Fix DeskClock dream on phones.

Side effect: improve random positioning of screensaver mode
inside the Clock app as well as in the dream.

Bug: 5603598
Change-Id: I1f7cb060ef2d6e1aad6d8f8d8e864c6614f4ff8d
parent f1a1f919
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@
            android:gravity="center_vertical|right"
            >
            <include layout="@layout/desk_clock_time_date"
                android:layout_width="match_parent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/time_margin_top"
                android:layout_marginBottom="@dimen/time_margin_bottom"
+3 −10
Original line number Diff line number Diff line
@@ -18,17 +18,10 @@
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_x="0dip"
        android:layout_y="0dip"
    android:background="#FF000000"
        />
    >

    <RelativeLayout
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/saver_view">
@@ -36,6 +29,6 @@
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </RelativeLayout>
    </FrameLayout>

</AbsoluteLayout>
+2 −2
Original line number Diff line number Diff line
@@ -34,18 +34,18 @@
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="@dimen/time_margin_right"
            android:layout_alignParentRight="true"
            android:singleLine="true"
            android:ellipsize="none"
            android:textSize="@dimen/time_text_size"
            android:textColor="@color/time_text_color"
            android:gravity="left"
            />

        <com.android.deskclock.AndroidClockTextView 
            android:id="@+id/am_pm"
            android:layout_width="@dimen/time_margin_right"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignRight="@id/timeDisplay"
            android:layout_alignBaseline="@id/timeDisplay"
            android:paddingLeft="4dip"
            android:layout_marginTop="@dimen/ampm_margin_top"
+30 −28
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import java.lang.Runnable;
import android.util.Log;

public class Screensaver extends Activity {
    View mContainer;
    View mContentView, mSaverView;

    static int CLOCK_COLOR = 0xFF66AAFF;

@@ -59,42 +59,44 @@ public class Screensaver extends Activity {
        public void run() {
            long delay = MOVE_DELAY;

            View parent = (View)mContainer.getParent();
            //Log.d("DeskClock/Screensaver", String.format("parent=(%d x %d)",
//                        parent.getWidth(), parent.getHeight()));
            final float xrange = parent.getWidth() - mContainer.getWidth();
            final float yrange = parent.getHeight() - mContainer.getHeight();
//            Log.d("DeskClock/Screensaver",
//                    String.format("mContentView=(%d x %d) container=(%d x %d)",
//                        mContentView.getWidth(), mContentView.getHeight(),
//                        mSaverView.getWidth(), mSaverView.getHeight()
//                        ));
            final float xrange = mContentView.getWidth() - mSaverView.getWidth();
            final float yrange = mContentView.getHeight() - mSaverView.getHeight();

            if (xrange == 0) {
            if (xrange == 0 && yrange == 0) {
                delay = 500; // back in a split second
            } else {
                final int nextx = (int) (Math.random() * xrange);
                final int nexty = (int) (Math.random() * yrange);

                if (mContainer.getAlpha() == 0f) {
                if (mSaverView.getAlpha() == 0f) {
                    // jump right there
                    mContainer.setX(nextx);
                    mContainer.setY(nexty);
                    ObjectAnimator.ofFloat(mContainer, "alpha", 0f, 1f)
                    mSaverView.setX(nextx);
                    mSaverView.setY(nexty);
                    ObjectAnimator.ofFloat(mSaverView, "alpha", 0f, 1f)
                        .setDuration(FADE_TIME)
                        .start();
                } else {
                    AnimatorSet s = new AnimatorSet();
                    Animator xMove   = ObjectAnimator.ofFloat(mContainer,
                                         "x", mContainer.getX(), nextx);
                    Animator yMove   = ObjectAnimator.ofFloat(mContainer,
                                         "y", mContainer.getY(), nexty);
                    Animator xMove   = ObjectAnimator.ofFloat(mSaverView,
                                         "x", mSaverView.getX(), nextx);
                    Animator yMove   = ObjectAnimator.ofFloat(mSaverView,
                                         "y", mSaverView.getY(), nexty);

                    Animator xShrink = ObjectAnimator.ofFloat(mContainer, "scaleX", 1f, 0.75f);
                    Animator xGrow   = ObjectAnimator.ofFloat(mContainer, "scaleX", 0.75f, 1f);
                    Animator xShrink = ObjectAnimator.ofFloat(mSaverView, "scaleX", 1f, 0.75f);
                    Animator xGrow   = ObjectAnimator.ofFloat(mSaverView, "scaleX", 0.75f, 1f);

                    Animator yShrink = ObjectAnimator.ofFloat(mContainer, "scaleY", 1f, 0.75f);
                    Animator yGrow   = ObjectAnimator.ofFloat(mContainer, "scaleY", 0.75f, 1f);
                    Animator yShrink = ObjectAnimator.ofFloat(mSaverView, "scaleY", 1f, 0.75f);
                    Animator yGrow   = ObjectAnimator.ofFloat(mSaverView, "scaleY", 0.75f, 1f);
                    AnimatorSet shrink = new AnimatorSet(); shrink.play(xShrink).with(yShrink);
                    AnimatorSet grow = new AnimatorSet(); grow.play(xGrow).with(yGrow);

                    Animator fadeout = ObjectAnimator.ofFloat(mContainer, "alpha", 1f, 0f);
                    Animator fadein = ObjectAnimator.ofFloat(mContainer, "alpha", 0f, 1f);
                    Animator fadeout = ObjectAnimator.ofFloat(mSaverView, "alpha", 1f, 0f);
                    Animator fadein = ObjectAnimator.ofFloat(mSaverView, "alpha", 0f, 1f);


                    if (SLIDE) {
@@ -141,10 +143,10 @@ public class Screensaver extends Activity {
        super.onStart();
        CLOCK_COLOR = getResources().getColor(R.color.screen_saver_color);
        setContentView(R.layout.desk_clock_saver);
        mContainer = findViewById(R.id.saver_view);
        mContainer.setAlpha(0);
        mContainer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        mContainer.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        mSaverView = findViewById(R.id.saver_view);
        mContentView = (View) mSaverView.getParent();
        mSaverView.setAlpha(0);
        mSaverView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

        AndroidClockTextView timeDisplay = (AndroidClockTextView) findViewById(R.id.timeDisplay);
        if (timeDisplay != null) {
@@ -163,8 +165,8 @@ public class Screensaver extends Activity {
    @Override
    public void onResume() {
        super.onResume();

        mMoveSaverRunnable.run();
//        Log.d("DeskClock/Screensaver", "resume");
        mHandler.post(mMoveSaverRunnable);
    }

    @Override