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

Commit cb81f196 authored by Sven Dawitz's avatar Sven Dawitz
Browse files

Add onLongClick action to notication clock and date

- As discussed with ciwrl on google+, LongClick opens DateTimeSettings
- Moved on-touch color change to superior xml solution, as suggested by
  Andrew Boren <preludedrew@gmail.com> here: http://review.evervolv.com/#/c/3676/"

Change-Id: I1fae71e347ffcb786227ba0b2651a66f2df35e27
parent c6df362b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:state_pressed="true"
          android:color="@android:color/holo_blue_light"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="@android:color/holo_blue_light"/> <!-- focused -->
    <item android:color="#ffffff"/>  <!--default -->

</selector>
+9 −0
Original line number Diff line number Diff line
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:state_pressed="true"
          android:color="@android:color/holo_blue_light"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="@android:color/holo_blue_light"/> <!-- focused -->
    <item android:color="#cccccc"/>  <!--default -->

</selector>
+2 −2
Original line number Diff line number Diff line
@@ -60,13 +60,13 @@
        <item name="android:textSize">32dp</item>
        <item name="android:fontFamily">sans-serif-light</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textColor">#ffffff</item>
        <item name="android:textColor">@color/clock_view_color</item>
    </style>

    <style name="TextAppearance.StatusBar.Expanded.Date">
        <item name="android:textSize">12dp</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textColor">#cccccc</item>
        <item name="android:textColor">@color/date_view_color</item>
        <item name="android:textAllCaps">true</item>
    </style>

+19 −21
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.View.OnLongClickListener;
import android.widget.TextView;

import java.text.SimpleDateFormat;
@@ -57,12 +57,11 @@ import com.android.internal.R;
 * This widget display an analogic clock with two hands for hours and
 * minutes.
 */
public class Clock extends TextView implements OnClickListener, OnTouchListener {
public class Clock extends TextView implements OnClickListener, OnLongClickListener {
    private boolean mAttached;
    private Calendar mCalendar;
    private String mClockFormatString;
    private SimpleDateFormat mClockFormat;
    private int mDefaultColor;

    private static final int AM_PM_STYLE_NORMAL  = 0;
    private static final int AM_PM_STYLE_SMALL   = 1;
@@ -109,9 +108,8 @@ public class Clock extends TextView implements OnClickListener, OnTouchListener
        settingsObserver.observe();
        if(isClickable()){
            setOnClickListener(this);
            setOnTouchListener(this);
            setOnLongClickListener(this);
        }
        mDefaultColor = getCurrentTextColor();
        updateSettings();
    }

@@ -273,10 +271,7 @@ public class Clock extends TextView implements OnClickListener, OnTouchListener
            setVisibility(View.GONE);
    }

    @Override
    public void onClick(View v) {
        setTextColor(mDefaultColor);

    private void collapseStartActivity(Intent what) {
        // collapse status bar
        StatusBarManager statusBarManager = (StatusBarManager) getContext().getSystemService(
                Context.STATUS_BAR_SERVICE);
@@ -289,22 +284,25 @@ public class Clock extends TextView implements OnClickListener, OnTouchListener
            // no action needed here
        }

        // start alarm clock intent
        // start activity
        what.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(what);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
        collapseStartActivity(intent);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int a = event.getAction();
        if (a == MotionEvent.ACTION_DOWN) {
            setTextColor(getResources().getColor(R.color.holo_blue_light));
        } else if (a == MotionEvent.ACTION_CANCEL || a == MotionEvent.ACTION_UP) {
            setTextColor(mDefaultColor);
        }
        // never consume touch event, so onClick is propperly processed
        return false;
    public boolean onLongClick(View v) {
        Intent intent = new Intent("android.settings.DATE_SETTINGS");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        collapseStartActivity(intent);

        // consume event
        return true;
    }
}
+19 −26
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import android.util.Slog;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.View.OnLongClickListener;
import android.view.ViewParent;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -41,7 +41,7 @@ import com.android.systemui.R;

import java.util.Date;

public final class DateView extends LinearLayout implements OnClickListener, OnTouchListener {
public final class DateView extends LinearLayout implements OnClickListener, OnLongClickListener {
    private static final String TAG = "DateView";

    private TextView mDoW;
@@ -50,7 +50,6 @@ public final class DateView extends LinearLayout implements OnClickListener, OnT
    private boolean mAttachedToWindow;
    private boolean mWindowVisible;
    private boolean mUpdating;
    private int mDefaultColor;

    private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
@@ -85,9 +84,7 @@ public final class DateView extends LinearLayout implements OnClickListener, OnT
        mDate.setTextAppearance(context, R.style.TextAppearance_StatusBar_Expanded_Date);
        mDate.setIncludeFontPadding(false);
        setOnClickListener(this);
        setOnTouchListener(this);

        mDefaultColor = mDate.getCurrentTextColor();
        setOnLongClickListener(this);

        // Extract how DoW and Date are distributed in the layout
        // The format is distributed as %1$s\n%2$s or %2$s\n%1$s but always in
@@ -194,11 +191,7 @@ public final class DateView extends LinearLayout implements OnClickListener, OnT
        }
    }

    @Override
    public void onClick(View v) {
        mDate.setTextColor(mDefaultColor);
        mDoW.setTextColor(mDefaultColor);

    private void collapseStartActivity(Intent what) {
        // collapse status bar
        StatusBarManager statusBarManager = (StatusBarManager) getContext().getSystemService(
                Context.STATUS_BAR_SERVICE);
@@ -211,7 +204,13 @@ public final class DateView extends LinearLayout implements OnClickListener, OnT
            // no action needed here
        }

        // start calendar - today is selected
        // start activity
        what.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(what);
    }

    @Override
    public void onClick(View v) {
        long nowMillis = System.currentTimeMillis();

        Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
@@ -219,22 +218,16 @@ public final class DateView extends LinearLayout implements OnClickListener, OnT
        ContentUris.appendId(builder, nowMillis);
        Intent intent = new Intent(Intent.ACTION_VIEW)
                .setData(builder.build());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
        collapseStartActivity(intent);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int a = event.getAction();
        if (a == MotionEvent.ACTION_DOWN) {
            int cTouch = getResources().getColor(com.android.internal.R.color.holo_blue_light);
            mDate.setTextColor(cTouch);
            mDoW.setTextColor(cTouch);
        } else if (a == MotionEvent.ACTION_CANCEL || a == MotionEvent.ACTION_UP) {
            mDate.setTextColor(mDefaultColor);
            mDoW.setTextColor(mDefaultColor);
        }
        // never consume touch event, so onClick is propperly processed
        return false;
    public boolean onLongClick(View v) {
        Intent intent = new Intent("android.settings.DATE_SETTINGS");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        collapseStartActivity(intent);

        // consume event
        return true;
    }
}