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

Commit ec04d651 authored by Erik's avatar Erik
Browse files

b/5245457 Make background toggle day/night/screensaver modes

Change-Id: I95a5589c302bdb9d0da0fa181ac378aa3e4adbb5
parent 68acd51c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -23,6 +23,15 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <View android:id="@+id/window_touch"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#00000000"
        android:visibility="visible"
        android:clickable="false"
        />

    <!-- the top padding accounts for the status bar area -->
    <RelativeLayout
        android:id="@+id/desk_clock"
+0 −1
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="@dimen/time_margin_right"
                android:layout_below="@id/nightmode_button"
                android:textSize="@dimen/time_text_size"
                android:textColor="@color/time_text_color"
                android:gravity="left"
+0 −12
Original line number Diff line number Diff line
@@ -32,23 +32,11 @@
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="@dimen/time_margin_right"
            android:layout_below="@id/nightmode_button"
            android:textSize="@dimen/time_text_size"
            android:textColor="@color/time_text_color"
            android:gravity="left"
            />

        <ImageButton android:id="@+id/nightmode_button"
            style="@style/RoundTouchButton"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/ic_clock_brightness"
            android:layout_alignRight="@id/timeDisplay"
            android:layout_marginRight="@dimen/font_margin_adjust"
            android:contentDescription="@string/nightmode_button_description"
            android:nextFocusDown="@+id/alarm_button"
            />

        <com.android.deskclock.AndroidClockTextView
            android:id="@+id/am_pm"
            android:layout_width="wrap_content"
+9 −11
Original line number Diff line number Diff line
@@ -23,6 +23,15 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <View android:id="@+id/window_touch"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#00000000"
        android:visibility="visible"
        android:clickable="false"
        />

    <!-- the top padding accounts for the status bar area -->
    <LinearLayout
        android:id="@+id/desk_clock"
@@ -40,17 +49,6 @@
            android:layout_weight="1"
            android:gravity="center_vertical|right"
            >
            <ImageButton android:id="@+id/nightmode_button"
                style="@style/RoundTouchButton"
                android:layout_weight="0"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:src="@drawable/ic_clock_brightness"
                android:layout_marginRight="@dimen/time_margin_right"
                android:paddingRight="@dimen/font_margin_adjust"
                android:contentDescription="@string/nightmode_button_description"
                android:nextFocusDown="@+id/alarm_button"
                />
            <include layout="@layout/desk_clock_time_date"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
+13 −45
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -183,7 +184,6 @@ public class DeskClock extends Activity {

    private View mAlarmButton;


    private void moveScreenSaver() {
        moveScreenSaverTo(-1,-1);
    }
@@ -526,16 +526,19 @@ public class DeskClock extends Activity {
        View alarmControl = mAlarmButton != null ? mAlarmButton : findViewById(R.id.nextAlarm);
        alarmControl.setOnClickListener(alarmClickListener);

        final ImageButton nightmodeButton = (ImageButton) findViewById(R.id.nightmode_button);
        if (nightmodeButton != null) {
            nightmodeButton.setOnClickListener(new View.OnClickListener() {
        View touchView = findViewById(R.id.window_touch);
        touchView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // If the screen saver is on let onUserInteraction handle it
                if (!mScreenSaverMode) {
                    mDimmed = !mDimmed;
                    doDim(true);
                }
            }
        });

            nightmodeButton.setOnLongClickListener(new View.OnLongClickListener() {
        touchView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                saveScreen();
                return true;
@@ -543,41 +546,6 @@ public class DeskClock extends Activity {
        });
    }

        final View tintView = findViewById(R.id.window_tint);
        tintView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                if (mDimmed && event.getAction() == MotionEvent.ACTION_DOWN) {
                    // We want to un-dim the whole screen on tap.
                    // ...Unless the user is specifically tapping on the dim
                    // widget, in which case let it do the work.
                    Rect r = new Rect();
                    nightmodeButton.getHitRect(r);
                    int[] gloc = new int[2];
                    nightmodeButton.getLocationInWindow(gloc);
                    r.offsetTo(gloc[0], gloc[1]); // convert to window coords

                    if (!r.contains((int) event.getX(), (int) event.getY())) {
                        mDimmed = false;
                        doDim(true);
                    }
                }
                return false; // always pass the click through
            }
        });

        // Tidy up awkward focus behavior: the first view to be focused in
        // trackball mode should be the alarms button
        final ViewTreeObserver vto = alarmControl.getViewTreeObserver();
        final View alarmView = alarmControl;
        vto.addOnGlobalFocusChangeListener(new ViewTreeObserver.OnGlobalFocusChangeListener() {
            public void onGlobalFocusChanged(View oldFocus, View newFocus) {
                if (oldFocus == null && newFocus == nightmodeButton) {
                    alarmView.requestFocus();
                }
            }
        });
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);