/*
* Copyright (C) 2009 The Undried 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.superdeskclock;
import static android.os.BatteryManager.BATTERY_STATUS_CHARGING;
import static android.os.BatteryManager.BATTERY_STATUS_FULL;
import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.AbsoluteLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
/**
* DeskClock clock view for desk docks.
*/
@SuppressWarnings("deprecation")
public class DeskClock extends Activity {
private static final boolean DEBUG = false;
private static final String LOG_TAG = "DeskClock";
// Alarm action for midnight (so we can update the date display).
private static final String ACTION_MIDNIGHT = "com.android.superdeskclock.MIDNIGHT";
// Interval between forced polls of the weather widget.
private final long QUERY_WEATHER_DELAY = 60 * 60 * 1000; // 1 hr
// Intent to broadcast for dock settings.
private static final String DOCK_SETTINGS_ACTION = "com.android.settings.DOCK_SETTINGS";
// Delay before engaging the burn-in protection mode (green-on-black).
private final long SCREEN_SAVER_TIMEOUT = 5 * 60 * 1000; // 5 min
// Repositioning delay in screen saver.
private final long SCREEN_SAVER_MOVE_DELAY = 60 * 1000; // 1 min
// Color to use for text & graphics in screen saver mode.
private final int SCREEN_SAVER_COLOR = 0xFF308030;
private final int SCREEN_SAVER_COLOR_DIM = 0xFF183018;
// Opacity of black layer between clock display and wallpaper.
private final float DIM_BEHIND_AMOUNT_NORMAL = 0.4f;
private final float DIM_BEHIND_AMOUNT_DIMMED = 0.8f; // higher contrast when display dimmed
// Internal message IDs.
private final int QUERY_WEATHER_DATA_MSG = 0x1000;
private final int UPDATE_WEATHER_DISPLAY_MSG = 0x1001;
private final int SCREEN_SAVER_TIMEOUT_MSG = 0x2000;
private final int SCREEN_SAVER_MOVE_MSG = 0x2001;
// Weather widget query information.
private static final String GENIE_PACKAGE_ID = "com.google.android.apps.genie.geniewidget";
private static final String WEATHER_CONTENT_AUTHORITY = GENIE_PACKAGE_ID + ".weather";
private static final String WEATHER_CONTENT_PATH = "/weather/current";
private static final String[] WEATHER_CONTENT_COLUMNS = new String[] {
"location",
"timestamp",
"temperature",
"highTemperature",
"lowTemperature",
"iconUrl",
"iconResId",
"description",
};
private static final String ACTION_GENIE_REFRESH = "com.google.android.apps.genie.REFRESH";
// State variables follow.
private DigitalClock mTime;
private TextView mDate;
private TextView mNextAlarm = null;
private TextView mBatteryDisplay;
private TextView mWeatherCurrentTemperature;
private TextView mWeatherHighTemperature;
private TextView mWeatherLowTemperature;
private TextView mWeatherLocation;
private ImageView mWeatherIcon;
private String mWeatherCurrentTemperatureString;
private String mWeatherHighTemperatureString;
private String mWeatherLowTemperatureString;
private String mWeatherLocationString;
private Drawable mWeatherIconDrawable;
private Resources mGenieResources = null;
private boolean mDimmed = false;
private boolean mScreenSaverMode = false;
private String mDateFormat;
private int mBatteryLevel = -1;
private boolean mPluggedIn = false;
private boolean mLaunchedFromDock = false;
private Random mRNG;
private PendingIntent mMidnightIntent;
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (DEBUG) Log.d(LOG_TAG, "mIntentReceiver.onReceive: action=" + action + ", intent=" + intent);
if (Intent.ACTION_DATE_CHANGED.equals(action) || ACTION_MIDNIGHT.equals(action)) {
refreshDate();
} else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
handleBatteryUpdate(
intent.getIntExtra("status", BATTERY_STATUS_UNKNOWN),
intent.getIntExtra("level", 0));
}
// else if (UiModeManager.ACTION_EXIT_DESK_MODE.equals(action)) {
// if (mLaunchedFromDock) {
// // moveTaskToBack(false);
// finish();
// }
// mLaunchedFromDock = false;
// }
}
};
private final Handler mHandy = new Handler() {
@Override
public void handleMessage(Message m) {
if (m.what == QUERY_WEATHER_DATA_MSG) {
new Thread() { public void run() { queryWeatherData(); } }.start();
scheduleWeatherQueryDelayed(QUERY_WEATHER_DELAY);
} else if (m.what == UPDATE_WEATHER_DISPLAY_MSG) {
updateWeatherDisplay();
} else if (m.what == SCREEN_SAVER_TIMEOUT_MSG) {
saveScreen();
} else if (m.what == SCREEN_SAVER_MOVE_MSG) {
moveScreenSaver();
}
}
};
private final ContentObserver mContentObserver = new ContentObserver(mHandy) {
@Override
public void onChange(boolean selfChange) {
if (DEBUG) Log.d(LOG_TAG, "content observer notified that weather changed");
refreshWeather();
}
};
private void moveScreenSaver() {
moveScreenSaverTo(-1,-1);
}
private void moveScreenSaverTo(int x, int y) {
if (!mScreenSaverMode) return;
final View saver_view = findViewById(R.id.saver_view);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
if (x < 0 ||
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android个性化闹钟实现源码 (394个子文件)
resources.ap_ 351KB
DeskClock.apk 410KB
AndroidManifest.xml.bak 6KB
DeskClock.class 21KB
Alarms.class 14KB
SetAlarm.class 13KB
AlarmClock.class 9KB
CalcScreen.class 8KB
AlarmAlertFullScreen.class 8KB
AlarmKlaxon.class 8KB
AlarmReceiver.class 6KB
AlarmProvider.class 6KB
ChooseBellActivity.class 5KB
DigitalClock.class 5KB
AlarmClock$AlarmTimeAdapter.class 4KB
SetBellPreference.class 4KB
Alarm.class 4KB
CalcScreen$4.class 3KB
SettingsActivity.class 3KB
RepeatPreference.class 3KB
AlarmAlert.class 3KB
Alarm$DaysOfWeek.class 3KB
R$drawable.class 3KB
R$string.class 3KB
R$id.class 3KB
AlarmClock$AlarmTimeAdapter$1.class 3KB
Compute.class 3KB
CalcScreen$2.class 2KB
AlarmProvider$DatabaseHelper.class 2KB
SetBellPreference$1.class 2KB
AnalogAppWidgetProvider.class 2KB
Alarm$Columns.class 2KB
SetAlarm$3.class 2KB
DeskClock$6.class 2KB
DigitalClock$1.class 2KB
CalcScreen$3.class 2KB
DeskClock$5.class 2KB
DeskClock$11.class 2KB
AlarmPreference.class 2KB
AlarmAlertFullScreen$1.class 2KB
AlarmClock$AlarmTimeAdapter$1$1.class 2KB
SetAlarm$5.class 2KB
AlarmInitReceiver.class 1KB
SetAlarm$2.class 1KB
SetAlarm$1.class 1KB
DeskClock$10.class 1KB
DeskClock$1.class 1KB
RepeatPreference$1.class 1KB
DigitalClock$AmPm.class 1KB
CalcScreen$1.class 1KB
AlarmAlertWakeLock.class 1KB
DeskClock$2.class 1KB
AlarmKlaxon$3.class 1KB
DeskClock$12.class 1KB
Alarm$1.class 1KB
DeskClock$7.class 1KB
SetAlarm$7.class 1KB
AlarmAlert$2.class 1KB
AlarmKlaxon$2.class 1KB
AlarmClock$1.class 1KB
SetAlarm$8.class 1KB
R$layout.class 1014B
AlarmKlaxon$1.class 1009B
DeskClock$8.class 1003B
AlarmClock$4.class 984B
DeskClock$4.class 976B
R.class 967B
DigitalClock$1$1.class 966B
Log.class 966B
AlarmAlertFullScreen$3.class 925B
SetAlarm$4.class 891B
AlarmAlert$1.class 885B
DeskClock$2$1.class 881B
AlarmAlertFullScreen$2.class 868B
AlarmClock$3.class 860B
DigitalClock$FormatChangeObserver.class 836B
SetAlarm$6.class 818B
DeskClock$3.class 814B
DeskClock$9.class 812B
AlarmClock$2.class 808B
DontPressWithParentLayout.class 793B
ToastMaster.class 730B
AlarmKlaxon$LocalBinder.class 666B
R$style.class 657B
R$array.class 653B
R$color.class 534B
R$anim.class 512B
R$menu.class 498B
R$xml.class 488B
R$raw.class 454B
R$attr.class 364B
BuildConfig.class 361B
.classpath 475B
classes.dex 103KB
undim.html 255B
DeskClock.java 32KB
Alarms.java 24KB
R.java 21KB
SetAlarm.java 15KB
AlarmClock.java 12KB
共 394 条
- 1
- 2
- 3
- 4
资源评论
Zyken
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功