blob: cf24d50d5c3a664f6b71e1e026d9e83e4a8bd6c7 [file] [log] [blame]
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.deskclock;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.service.dreams.DreamService;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import com.android.deskclock.Utils.ScreensaverMoveSaverRunnable;
public class Screensaver extends DreamService {
static final boolean DEBUG = false;
static final String TAG = "DeskClock/Screensaver";
private View mContentView, mSaverView;
private View mAnalogClock, mDigitalClock;
private final Handler mHandler = new Handler();
private final ScreensaverMoveSaverRunnable mMoveSaverRunnable;
public Screensaver() {
if (DEBUG) Log.d(TAG, "Screensaver allocated");
mMoveSaverRunnable = new ScreensaverMoveSaverRunnable(mHandler);
}
@Override
public void onCreate() {
if (DEBUG) Log.d(TAG, "Screensaver created");
super.onCreate();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (DEBUG) Log.d(TAG, "Screensaver configuration changed");
super.onConfigurationChanged(newConfig);
mHandler.removeCallbacks(mMoveSaverRunnable);
layoutClockSaver();
mHandler.post(mMoveSaverRunnable);
}
@Override
public void onAttachedToWindow() {
if (DEBUG) Log.d(TAG, "Screensaver attached to window");
super.onAttachedToWindow();
// We want the screen saver to exit upon user interaction.
setInteractive(false);
setFullscreen(true);
layoutClockSaver();
mHandler.post(mMoveSaverRunnable);
}
@Override
public void onDetachedFromWindow() {
if (DEBUG) Log.d(TAG, "Screensaver detached from window");
super.onDetachedFromWindow();
mHandler.removeCallbacks(mMoveSaverRunnable);
}
private void setClockStyle() {
Utils.setClockStyle(this, mDigitalClock, mAnalogClock,
ScreensaverSettingsActivity.KEY_CLOCK_STYLE);
mSaverView = findViewById(R.id.main_clock);
boolean dimNightMode = PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(ScreensaverSettingsActivity.KEY_NIGHT_MODE, false);
Utils.dimClockView(dimNightMode, mSaverView);
setScreenBright(!dimNightMode);
}
private void layoutClockSaver() {
setContentView(R.layout.desk_clock_saver);
mDigitalClock = findViewById(R.id.digital_clock);
mAnalogClock =findViewById(R.id.analog_clock);
setClockStyle();
mContentView = (View) mSaverView.getParent();
mSaverView.setAlpha(0);
mMoveSaverRunnable.registerViews(mContentView, mSaverView);
}
}