DeskClock.java revision 357497c341662c56945e22e458852f52a977efdf
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.deskclock;
18
19import android.app.ActionBar;
20import android.app.ActionBar.Tab;
21import android.app.Activity;
22import android.app.Fragment;
23import android.app.FragmentTransaction;
24import android.content.ActivityNotFoundException;
25import android.content.Context;
26import android.content.Intent;
27import android.content.SharedPreferences;
28import android.graphics.drawable.TransitionDrawable;
29import android.os.Bundle;
30import android.os.Handler;
31import android.os.Message;
32import android.preference.PreferenceManager;
33import android.support.v13.app.FragmentPagerAdapter;
34import android.support.v4.view.ViewPager;
35import android.util.Log;
36import android.view.Menu;
37import android.view.MenuItem;
38import android.view.MotionEvent;
39import android.view.View;
40import android.view.View.OnTouchListener;
41import android.view.animation.AlphaAnimation;
42import android.view.animation.Animation;
43import android.view.animation.Animation.AnimationListener;
44import android.view.animation.AnimationUtils;
45import android.view.animation.ScaleAnimation;
46import android.view.animation.Transformation;
47import android.view.animation.TranslateAnimation;
48import android.widget.LinearLayout.LayoutParams;
49import android.widget.PopupMenu;
50import android.widget.Toast;
51
52import com.android.deskclock.stopwatch.StopwatchFragment;
53import com.android.deskclock.stopwatch.StopwatchService;
54import com.android.deskclock.stopwatch.Stopwatches;
55import com.android.deskclock.timer.TimerFragment;
56import com.android.deskclock.timer.Timers;
57import com.android.deskclock.worldclock.CitiesActivity;
58
59import java.util.ArrayList;
60import java.util.TimeZone;
61
62/**
63 * DeskClock clock view for desk docks.
64 */
65public class DeskClock extends Activity {
66    private static final boolean DEBUG = false;
67
68    private static final String LOG_TAG = "DeskClock";
69
70    // Alarm action for midnight (so we can update the date display).
71    private static final String KEY_SELECTED_TAB = "selected_tab";
72    private static final String KEY_CLOCK_STATE = "clock_state";
73
74    public static final String SELECT_TAB_INTENT_EXTRA = "deskclock.select.tab";
75
76    private ActionBar mActionBar;
77    private Tab mTimerTab;
78    private Tab mClockTab;
79    private Tab mStopwatchTab;
80
81    private ViewPager mViewPager;
82    private TabsAdapter mTabsAdapter;
83
84    public static final int TIMER_TAB_INDEX = 0;
85    public static final int CLOCK_TAB_INDEX = 1;
86    public static final int STOPWATCH_TAB_INDEX = 2;
87
88    private int mSelectedTab;
89    private final boolean mDimmed = false;
90    private boolean mAddingTimer;
91    private int[] mClockButtonIds;
92    private int[] mTimerButtonId;
93    private int mFooterHeight;
94    private int mDimAnimationDuration;
95    private View mClockBackground;
96    private View mClockForeground;
97    private boolean mIsBlackBackground;
98
99    private int mClockState = CLOCK_NORMAL;
100    private static final int CLOCK_NORMAL = 0;
101    private static final int CLOCK_LIGHTS_OUT = 1;
102    private static final int CLOCK_DIMMED = 2;
103
104
105
106    // Delay before hiding the action bar and buttons
107    private static final long CLOCK_LIGHTSOUT_TIMEOUT = 10 * 1000; // 10 seconds
108    private static final long TIMER_SW_LIGHTSOUT_TIMEOUT = 3 * 1000; // 10 seconds
109    // Delay before dimming the screen
110    private static final long DIM_TIMEOUT = 10 * 1000; // 10 seconds
111
112    // Opacity of black layer between clock display and wallpaper.
113    private final float DIM_BEHIND_AMOUNT_NORMAL = 0.4f;
114    private final float DIM_BEHIND_AMOUNT_DIMMED = 0.8f; // higher contrast when display dimmed
115
116    private final int SCREEN_SAVER_TIMEOUT_MSG   = 0x2000;
117    private final int SCREEN_SAVER_MOVE_MSG      = 0x2001;
118    private final int DIM_TIMEOUT_MSG            = 0x2002;
119    private final int LIGHTSOUT_TIMEOUT_MSG      = 0x2003;
120    private final int BACK_TO_NORMAL_MSG         = 0x2004;
121
122
123
124    private final Handler mHandy = new Handler() {
125        @Override
126        public void handleMessage(Message m) {
127            switch(m.what) {
128                case LIGHTSOUT_TIMEOUT_MSG:
129                    if (mViewPager.getCurrentItem() == TIMER_TAB_INDEX && mAddingTimer) {
130                        break;
131                    }
132                    mClockState = CLOCK_LIGHTS_OUT;
133                    setClockState(true);
134                    break;
135                case DIM_TIMEOUT_MSG:
136                    mClockState = CLOCK_DIMMED;
137                    doDim(true);
138                    break;
139            }
140        }
141    };
142
143    @Override
144    public void onNewIntent(Intent newIntent) {
145        super.onNewIntent(newIntent);
146        if (DEBUG) Log.d(LOG_TAG, "onNewIntent with intent: " + newIntent);
147
148        // update our intent so that we can consult it to determine whether or
149        // not the most recent launch was via a dock event
150        setIntent(newIntent);
151
152        // Timer receiver may ask to go to the timers fragment if a timer expired.
153        int tab = newIntent.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
154        if (tab != -1) {
155            if (mActionBar != null) {
156                mActionBar.setSelectedNavigationItem(tab);
157            }
158        }
159    }
160
161    private void initViews() {
162
163        if (mTabsAdapter == null) {
164            mViewPager = new ViewPager(this);
165            mViewPager.setId(R.id.desk_clock_pager);
166            mTabsAdapter = new TabsAdapter(this, mViewPager);
167            createTabs(mSelectedTab);
168        }
169        setContentView(mViewPager);
170        mActionBar.setSelectedNavigationItem(mSelectedTab);
171    }
172
173    private void createTabs(int selectedIndex) {
174        mActionBar = getActionBar();
175
176        mActionBar.setDisplayOptions(0);
177        if (mActionBar != null) {
178            mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
179            mTimerTab = mActionBar.newTab();
180            mTimerTab.setIcon(R.drawable.timer_tab);
181            mTimerTab.setContentDescription(R.string.menu_timer);
182            mTabsAdapter.addTab(mTimerTab, TimerFragment.class,TIMER_TAB_INDEX);
183
184            mClockTab = mActionBar.newTab();
185            mClockTab.setIcon(R.drawable.clock_tab);
186            mClockTab.setContentDescription(R.string.menu_clock);
187            mTabsAdapter.addTab(mClockTab, ClockFragment.class,CLOCK_TAB_INDEX);
188            mStopwatchTab = mActionBar.newTab();
189            mStopwatchTab.setIcon(R.drawable.stopwatch_tab);
190            mStopwatchTab.setContentDescription(R.string.menu_stopwatch);
191            mTabsAdapter.addTab(mStopwatchTab, StopwatchFragment.class,STOPWATCH_TAB_INDEX);
192            mActionBar.setSelectedNavigationItem(selectedIndex);
193        }
194    }
195
196    @Override
197    protected void onCreate(Bundle icicle) {
198        super.onCreate(icicle);
199
200        mSelectedTab = CLOCK_TAB_INDEX;
201        if (icicle != null) {
202            mSelectedTab = icicle.getInt(KEY_SELECTED_TAB, CLOCK_TAB_INDEX);
203            mClockState = icicle.getInt(KEY_CLOCK_STATE, CLOCK_NORMAL);
204        }
205
206        // Timer receiver may ask the app to go to the timer fragment if a timer expired
207        Intent i = getIntent();
208        if (i != null) {
209            int tab = i.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
210            if (tab != -1) {
211                mSelectedTab = tab;
212            }
213        }
214        initViews();
215        setHomeTimeZone();
216
217        int[] buttonIds = {R.id.alarms_button, R.id.cities_button, R.id.menu_button};
218        mClockButtonIds = buttonIds;
219        int[] button = {R.id.timer_add_timer};
220        mTimerButtonId = button;
221        mFooterHeight = (int) getResources().getDimension(R.dimen.button_footer_height);
222        mDimAnimationDuration = getResources().getInteger(R.integer.dim_animation_duration);
223        mClockBackground = findViewById(R.id.clock_background);
224        mClockForeground = findViewById(R.id.clock_foreground);
225        mIsBlackBackground = false;
226    }
227
228    @Override
229    protected void onResume() {
230        super.onResume();
231        mAddingTimer = true;
232        setClockState(false);
233
234        Intent stopwatchIntent = new Intent(getApplicationContext(), StopwatchService.class);
235        stopwatchIntent.setAction(Stopwatches.KILL_NOTIF);
236        startService(stopwatchIntent);
237
238        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
239        SharedPreferences.Editor editor = prefs.edit();
240        editor.putBoolean(Timers.NOTIF_APP_OPEN, true);
241        editor.apply();
242        Intent timerIntent = new Intent();
243        timerIntent.setAction(Timers.NOTIF_IN_USE_CANCEL);
244        sendBroadcast(timerIntent);
245    }
246
247    @Override
248    public void onPause() {
249        removeLightsMessages();
250
251        Intent intent = new Intent(getApplicationContext(), StopwatchService.class);
252        intent.setAction(Stopwatches.SHOW_NOTIF);
253        startService(intent);
254
255        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
256        SharedPreferences.Editor editor = prefs.edit();
257        editor.putBoolean(Timers.NOTIF_APP_OPEN, false);
258        editor.apply();
259        Intent timerIntent = new Intent();
260        timerIntent.setAction(Timers.NOTIF_IN_USE_SHOW);
261        sendBroadcast(timerIntent);
262
263        super.onPause();
264    }
265
266    @Override
267    protected void onSaveInstanceState(Bundle outState) {
268        super.onSaveInstanceState(outState);
269        outState.putInt(KEY_SELECTED_TAB, mActionBar.getSelectedNavigationIndex());
270        outState.putInt(KEY_CLOCK_STATE, mClockState);
271    }
272
273    public void clockButtonsOnClick(View v) {
274        if (!isClockStateNormal()) {
275            bringLightsUp(true);
276            return;
277        }
278        if (v == null)
279            return;
280        switch (v.getId()) {
281            case R.id.alarms_button:
282                startActivity(new Intent(this, AlarmClock.class));
283                break;
284            case R.id.cities_button:
285                startActivity(new Intent(this, CitiesActivity.class));
286                break;
287            case R.id.menu_button:
288                showMenu(v);
289                break;
290            default:
291                break;
292        }
293    }
294
295    private void showMenu(View v) {
296        PopupMenu popupMenu = new PopupMenu(this, v);
297        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener () {
298            @Override
299            public boolean onMenuItemClick(MenuItem item) {
300                switch (item.getItemId()) {
301                    case R.id.menu_item_settings:
302                        startActivity(new Intent(DeskClock.this, SettingsActivity.class));
303                        return true;
304                    case R.id.menu_item_help:
305                        Intent i = item.getIntent();
306                        if (i != null) {
307                            try {
308                                startActivity(i);
309                            } catch (ActivityNotFoundException e) {
310                                // No activity found to match the intent - ignore
311                            }
312                        }
313                        return true;
314                    default:
315                        break;
316                }
317                return true;
318            }
319        });
320        popupMenu.inflate(R.menu.desk_clock_menu);
321
322        Menu menu = popupMenu.getMenu();
323        MenuItem help = menu.findItem(R.id.menu_item_help);
324        if (help != null) {
325            Utils.prepareHelpMenuItem(this, help);
326        }
327        popupMenu.show();
328    }
329
330    /***
331     * Insert the local time zone as the Home Time Zone if one is not set
332     */
333    private void setHomeTimeZone() {
334        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
335        String homeTimeZone = prefs.getString(SettingsActivity.KEY_HOME_TZ, "");
336        if (!homeTimeZone.isEmpty()) {
337        return;
338        }
339        homeTimeZone = TimeZone.getDefault().getID();
340        SharedPreferences.Editor editor = prefs.edit();
341        editor.putString(SettingsActivity.KEY_HOME_TZ, homeTimeZone);
342        editor.apply();
343        Log.v(LOG_TAG, "Setting home time zone to " + homeTimeZone);
344    }
345
346    public boolean isClockStateNormal() {
347        return mClockState == CLOCK_NORMAL;
348    }
349
350    private boolean isClockStateDimmed() {
351        return mClockState == CLOCK_DIMMED;
352    }
353
354    public void clockOnViewClick(View view) {
355        // Toggle lights
356        switch(mClockState) {
357            case CLOCK_NORMAL:
358                mClockState = CLOCK_LIGHTS_OUT;
359                break;
360            case CLOCK_LIGHTS_OUT:
361            case CLOCK_DIMMED:
362                mClockState = CLOCK_NORMAL;
363                break;
364            default:
365                Log.v(LOG_TAG, "in a bad state. setting to normal.");
366                mClockState = CLOCK_NORMAL;
367                break;
368        }
369        setClockState(true);
370    }
371
372    private void setClockState(boolean fade) {
373        doDim(fade);
374        switch(mClockState) {
375            case CLOCK_NORMAL:
376                doLightsOut(false, fade);
377                break;
378            case CLOCK_LIGHTS_OUT:
379                doLightsOut(true, fade);
380                if (mViewPager.getCurrentItem() == CLOCK_TAB_INDEX) {
381                    scheduleDim();
382                }
383                break;
384            case CLOCK_DIMMED:
385                doLightsOut(true, fade);
386                break;
387            default:
388                break;
389        }
390    }
391
392    private void doDim(boolean fade) {
393        if (mClockBackground == null) {
394            mClockBackground = findViewById(R.id.clock_background);
395            mClockForeground = findViewById(R.id.clock_foreground);
396            if (mClockBackground == null || mClockForeground == null) {
397                return;
398            }
399        }
400        if (mClockState == CLOCK_DIMMED) {
401            mClockForeground.startAnimation(
402                    AnimationUtils.loadAnimation(this, fade ? R.anim.dim : R.anim.dim_instant));
403            TransitionDrawable backgroundFade =
404                    (TransitionDrawable) mClockBackground.getBackground();
405            TransitionDrawable foregroundFade =
406                    (TransitionDrawable) mClockForeground.getBackground();
407            backgroundFade.startTransition(fade ? mDimAnimationDuration : 0);
408            foregroundFade.startTransition(fade ? mDimAnimationDuration : 0);
409            mIsBlackBackground = true;
410        } else {
411            if (mIsBlackBackground) {
412                mClockForeground.startAnimation(
413                        AnimationUtils.loadAnimation(this, R.anim.undim));
414                TransitionDrawable backgroundFade =
415                        (TransitionDrawable) mClockBackground.getBackground();
416                TransitionDrawable foregroundFade =
417                        (TransitionDrawable) mClockForeground.getBackground();
418                backgroundFade.reverseTransition(0);
419                foregroundFade.reverseTransition(0);
420                mIsBlackBackground = false;
421            }
422        }
423    }
424
425    public void doLightsOut(boolean lightsOut, boolean fade) {
426        if (lightsOut) {
427            mActionBar.hide();
428            mViewPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
429            hideAnimated(fade, R.id.clock_footer, mFooterHeight, mClockButtonIds);
430            if (mViewPager.getCurrentItem() != STOPWATCH_TAB_INDEX) {
431                hideAnimated(fade, R.id.timer_footer, mFooterHeight, mTimerButtonId);
432            }
433        } else {
434            mActionBar.show();
435            mViewPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
436            unhideAnimated(fade, R.id.clock_footer, mFooterHeight, mClockButtonIds);
437            if (mViewPager.getCurrentItem() != STOPWATCH_TAB_INDEX) {
438                unhideAnimated(fade, R.id.timer_footer, mFooterHeight, mTimerButtonId);
439            }
440            // Make sure dim will not start before lights out
441            removeLightsMessages();
442            scheduleLightsOut();
443        }
444    }
445
446    private void hideAnimated(boolean fade, int viewId, int toYDelta, final int[] buttonIds) {
447        View view = findViewById(viewId);
448        if (view != null) {
449            Animation hideAnimation = new TranslateAnimation(0, 0, 0, toYDelta);
450            hideAnimation.setDuration(fade ? 350 : 0);
451            hideAnimation.setFillAfter(true);
452            hideAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,
453                    android.R.interpolator.decelerate_cubic));
454            hideAnimation.setAnimationListener(new AnimationListener() {
455                @Override
456                public void onAnimationEnd(Animation animation) {
457                    if (buttonIds != null) {
458                        for (int buttonId : buttonIds) {
459                            View button = findViewById(buttonId);
460                            if (button != null) {
461                                button.setVisibility(View.GONE);
462                            }
463                        }
464                    }
465                }
466                @Override
467                public void onAnimationRepeat(Animation animation) {
468                }
469                @Override
470                public void onAnimationStart(Animation animation) {
471                }
472            });
473            view.startAnimation(hideAnimation);
474        }
475    }
476
477    private void unhideAnimated(boolean fade, int viewId, int fromYDelta, final int[] buttonIds) {
478        View view = findViewById(viewId);
479        if (view != null) {
480            Animation unhideAnimation = new TranslateAnimation(0, 0, fromYDelta, 0);
481            unhideAnimation.setDuration(fade ? 350 : 0);
482            unhideAnimation.setFillAfter(true);
483            unhideAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,
484                    android.R.interpolator.decelerate_cubic));
485            if (buttonIds != null) {
486                for (int buttonId : buttonIds) {
487                    View button = findViewById(buttonId);
488                    if (button != null) {
489                        button.setVisibility(View.VISIBLE);
490                    }
491                }
492            }
493            view.startAnimation(unhideAnimation);
494        }
495    }
496
497    public void removeLightsMessages() {
498        mHandy.removeMessages(BACK_TO_NORMAL_MSG);
499        mHandy.removeMessages(LIGHTSOUT_TIMEOUT_MSG);
500        mHandy.removeMessages(DIM_TIMEOUT_MSG);
501    }
502
503    public void scheduleLightsOut() {
504        removeLightsMessages();
505        long timeout;
506        if (mViewPager.getCurrentItem() == CLOCK_TAB_INDEX) {
507            timeout = CLOCK_LIGHTSOUT_TIMEOUT;
508        } else {
509            timeout = TIMER_SW_LIGHTSOUT_TIMEOUT;
510        }
511        mHandy.sendMessageDelayed(Message.obtain(mHandy, LIGHTSOUT_TIMEOUT_MSG), timeout);
512    }
513
514    public void bringLightsUp(boolean fade) {
515        removeLightsMessages();
516        if (mClockState != CLOCK_NORMAL) {
517            mClockState = CLOCK_NORMAL;
518            setClockState(fade);
519        } else {
520            scheduleLightsOut();
521        }
522    }
523
524    private void scheduleDim() {
525        removeLightsMessages();
526        mHandy.sendMessageDelayed(Message.obtain(mHandy, DIM_TIMEOUT_MSG), DIM_TIMEOUT);
527    }
528
529    public void setTimerAddingTimerState(boolean addingTimer) {
530        mAddingTimer = addingTimer;
531        if (addingTimer && mViewPager.getCurrentItem() == TIMER_TAB_INDEX) {
532            removeLightsMessages();
533        }
534    }
535
536    /***
537     * Adapter for wrapping together the ActionBar's tab with the ViewPager
538     */
539
540    private class TabsAdapter extends FragmentPagerAdapter
541            implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
542
543        private static final String KEY_TAB_POSITION = "tab_position";
544
545        final class TabInfo {
546            private final Class<?> clss;
547            private final Bundle args;
548
549            TabInfo(Class<?> _class, int position) {
550                clss = _class;
551                args = new Bundle();
552                args.putInt(KEY_TAB_POSITION, position);
553            }
554
555            public int getPosition() {
556                return args.getInt(KEY_TAB_POSITION, 0);
557            }
558        }
559
560        private final ArrayList<TabInfo> mTabs = new ArrayList <TabInfo>();
561        ActionBar mMainActionBar;
562        Context mContext;
563        ViewPager mPager;
564
565        public TabsAdapter(Activity activity, ViewPager pager) {
566            super(activity.getFragmentManager());
567            mContext = activity;
568            mMainActionBar = activity.getActionBar();
569            mPager = pager;
570            mPager.setAdapter(this);
571            mPager.setOnPageChangeListener(this);
572        }
573
574        @Override
575        public Fragment getItem(int position) {
576            TabInfo info = mTabs.get(position);
577            DeskClockFragment f = (DeskClockFragment) Fragment.instantiate(
578                    mContext, info.clss.getName(), info.args);
579            return f;
580        }
581
582        @Override
583        public int getCount() {
584            return mTabs.size();
585        }
586
587        public void addTab(ActionBar.Tab tab, Class<?> clss, int position) {
588            TabInfo info = new TabInfo(clss, position);
589            tab.setTag(info);
590            tab.setTabListener(this);
591            mTabs.add(info);
592            mMainActionBar.addTab(tab);
593            notifyDataSetChanged();
594        }
595
596        @Override
597        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
598            boolean fade = !isClockStateNormal();
599            bringLightsUp(fade);
600        }
601
602        @Override
603        public void onPageSelected(int position) {
604            mMainActionBar.setSelectedNavigationItem(position);
605            boolean fade = !isClockStateNormal();
606            bringLightsUp(fade);
607        }
608
609        @Override
610        public void onPageScrollStateChanged(int state) {
611            // Do nothing
612        }
613
614        @Override
615        public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
616            // Do nothing
617        }
618
619        @Override
620        public void onTabSelected(Tab tab, FragmentTransaction ft) {
621            TabInfo info = (TabInfo)tab.getTag();
622            mPager.setCurrentItem(info.getPosition());
623            boolean fade = !isClockStateNormal();
624            bringLightsUp(fade);
625        }
626
627        @Override
628        public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
629            // Do nothing
630
631        }
632    }
633
634    public static class OnTapListener implements OnTouchListener {
635        private DeskClock mActivity;
636        private float mLastTouchX;
637        private float mLastTouchY;
638        private long mLastTouchTime;
639        private float MAX_MOVEMENT_ALLOWED = 20;
640        private long MAX_TIME_ALLOWED = 500;
641
642        public OnTapListener(Activity activity) {
643            mActivity = (DeskClock) activity;
644        }
645
646        @Override
647        public boolean onTouch(View v, MotionEvent e) {
648            switch (e.getAction()) {
649                case (MotionEvent.ACTION_DOWN):
650                    if (mActivity.isClockStateDimmed()) {
651                        mActivity.clockOnViewClick(v);
652                        resetValues();
653                        break;
654                    }
655                    mLastTouchX = e.getX();
656                    mLastTouchY = e.getY();
657                    mLastTouchTime = Utils.getTimeNow();
658                    mActivity.removeLightsMessages();
659                    break;
660                case (MotionEvent.ACTION_UP):
661                    float xDiff = Math.abs(e.getX()-mLastTouchX);
662                    float yDiff = Math.abs(e.getY()-mLastTouchY);
663                    long timeDiff = (Utils.getTimeNow() - mLastTouchTime);
664                    if (xDiff < MAX_MOVEMENT_ALLOWED && yDiff < MAX_MOVEMENT_ALLOWED
665                            && timeDiff < MAX_TIME_ALLOWED) {
666                        mActivity.clockOnViewClick(v);
667                        return true;
668                    } else {
669                        if (mActivity.isClockStateNormal()){
670                            mActivity.scheduleLightsOut();
671                        } else if (!mActivity.isClockStateDimmed()) {
672                            mActivity.scheduleDim();
673                        }
674                    }
675                    break;
676                case (MotionEvent.ACTION_MOVE):
677                    break;
678                default:
679                    resetValues();
680            }
681            return false;
682        }
683
684        private void resetValues() {
685            mLastTouchX = -1*MAX_MOVEMENT_ALLOWED + 1;
686            mLastTouchY = -1*MAX_MOVEMENT_ALLOWED + 1;
687            mLastTouchTime = -1*MAX_TIME_ALLOWED + 1;
688        }
689    }
690
691}
692