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

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

Add onClick action to notification clock and date

In expanded StatusBar
- clicking clock opens alarms
- clicking date opens calendar - today selected

http://www.youtube.com/watch?v=MLom5e3nQoA

PS3: added turn-blue-on-click
PS4++: nitpicking cleanups

Change-Id: I850732dcca0e65af59ce009aaf9f7ba18bcaf915
parent 8322f1ea
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@
            android:singleLine="true"
            android:paddingLeft="6dip"
            android:gravity="center_vertical|left"
            android:clickable="false"
            />
    </LinearLayout>
        
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
        android:layout_marginLeft="8dp"
        android:singleLine="true"
        android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Clock"
        android:clickable="true"
        />

    <com.android.systemui.statusbar.policy.DateView android:id="@+id/date"
+1 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@
            android:paddingLeft="6dip"
            android:layout_marginRight="8dip"
            android:gravity="center_vertical|left"
            android:clickable="false"
            />

        <TextView
+1 −0
Original line number Diff line number Diff line
@@ -235,6 +235,7 @@
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Clock"
            android:clickable="true"
            />
    
        <com.android.systemui.statusbar.policy.DateView
+48 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar.policy;

import android.app.ActivityManagerNative;
import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -28,6 +30,7 @@ import android.graphics.Canvas;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.provider.AlarmClock;
import android.provider.Settings;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
@@ -38,7 +41,10 @@ import android.text.style.RelativeSizeSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.TextView;

import java.text.SimpleDateFormat;
@@ -51,11 +57,12 @@ import com.android.internal.R;
 * This widget display an analogic clock with two hands for hours and
 * minutes.
 */
public class Clock extends TextView {
public class Clock extends TextView implements OnClickListener, OnTouchListener {
    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;
@@ -100,6 +107,11 @@ public class Clock extends TextView {
        mHandler = new Handler();
        SettingsObserver settingsObserver = new SettingsObserver(mHandler);
        settingsObserver.observe();
        if(isClickable()){
            setOnClickListener(this);
            setOnTouchListener(this);
        }
        mDefaultColor = getCurrentTextColor();
        updateSettings();
    }

@@ -260,5 +272,39 @@ public class Clock extends TextView {
        else
            setVisibility(View.GONE);
    }

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

        // collapse status bar
        StatusBarManager statusBarManager = (StatusBarManager) getContext().getSystemService(
                Context.STATUS_BAR_SERVICE);
        statusBarManager.collapse();

        // dismiss keyguard in case it was active and no passcode set
        try {
            ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
        } catch (Exception ex) {
            // no action needed here
        }

        // start alarm clock intent
        Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(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;
    }
}
Loading