If you think the Android project android-class listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2011 The Android Open Source Project
*/*www.java2s.com*/
* 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.content.res.Configuration;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.service.dreams.DreamService;
import android.util.Log;
import android.view.View;
import com.android.deskclock.Utils.ScreensaverMoveSaverRunnable;
publicclass Screensaver extends DreamService {
staticfinalboolean DEBUG = false;
staticfinal String TAG = "DeskClock/Screensaver";
private View mContentView, mSaverView;
private View mAnalogClock, mDigitalClock;
privatefinal Handler mHandler = new Handler();
privatefinal ScreensaverMoveSaverRunnable mMoveSaverRunnable;
public Screensaver() {
if (DEBUG) Log.d(TAG, "Screensaver allocated");
mMoveSaverRunnable = new ScreensaverMoveSaverRunnable(mHandler);
}
@Override
publicvoid onCreate() {
if (DEBUG) Log.d(TAG, "Screensaver created");
super.onCreate();
}
@Override
publicvoid onConfigurationChanged(Configuration newConfig) {
if (DEBUG) Log.d(TAG, "Screensaver configuration changed");
super.onConfigurationChanged(newConfig);
mHandler.removeCallbacks(mMoveSaverRunnable);
layoutClockSaver();
mHandler.post(mMoveSaverRunnable);
}
@Override
publicvoid 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
publicvoid onDetachedFromWindow() {
if (DEBUG) Log.d(TAG, "Screensaver detached from window");
super.onDetachedFromWindow();
mHandler.removeCallbacks(mMoveSaverRunnable);
}
privatevoid 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);
}
privatevoid 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);
}
}