我在世界模擬時鐘工作我使用了android模擬時鐘,它的工作在活動,但我不能使用它在小部件,我累了用google搜索它有任何人有想法?定製安卓模擬時鐘在小工具
0
A
回答
0
您可以在主屏幕小部件使用下面的窗口小部件類:
* AnalogClock
* Button
* Chronometer
* ImageButton
* ImageView
* ProgressBar
* TextView
這些類的後代不支持
看到我們如何使用主屏幕小部件here的AnalogClock部件的例子
0
您必須基於ImageView創建自己的窗口小部件,並創建後臺服務來創建位圖並定期將其推送到窗口小部件。
0
/**
* *此插件用兩隻手幾個小時, * *分鐘顯示類比時鐘。 */
@RemoteView 公共類AnalogClock2擴展視圖{
public AnalogClock2(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
private Time mCalendar;
private Drawable mHourHand;
private Drawable mMinuteHand;
private Drawable mSecondHand;
private Drawable mDial;
private int mDialWidth;
private int mDialHeight;
private boolean mAttached;
private final Handler mHandler = new Handler();
private float mMinutes;
private float mHour;
private boolean mChanged;
Context mContext;
public static String mtimezone="Asia/Calcutta";
public AnalogClock2(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public AnalogClock2(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
Resources r = context.getResources();
// TypedArray a =
// context.obtainStyledAttributes(
// attrs, R.styleable.AnalogClock, defStyle, 0);
mContext = context;
// mDial =
// a.getDrawable(com.android.internal.R.styleable.AnalogClock_dial);
// if (mDial == null) {
mDial = r.getDrawable(R.drawable.widgetdial);
// }
// mHourHand =
// a.getDrawable(com.android.internal.R.styleable.AnalogClock_hand_hour);
// if (mHourHand == null) {
mHourHand = r.getDrawable(R.drawable.widgethour);
// }
// mMinuteHand =
// a.getDrawable(com.android.internal.R.styleable.AnalogClock_hand_minute);
// if (mMinuteHand == null) {
mMinuteHand = r.getDrawable(R.drawable.widgetminute);
mSecondHand = r.getDrawable(R.drawable.widgetminute);
// }
mCalendar = new Time();
mDialWidth = mDial.getIntrinsicWidth();
mDialHeight = mDial.getIntrinsicHeight();
}
public static void timezone(String timezone){
mtimezone=timezone;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (!mAttached) {
mAttached = true;
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
getContext().registerReceiver(mIntentReceiver, filter, null, mHandler);
}
// NOTE: It's safe to do these after registering the receiver since the
// receiver always runs
// in the main thread, therefore the receiver can't run before this
// method returns.
// The time zone may have changed while the receiver wasn't registered,
// so update the Time
//mCalendar = new Time();
mCalendar = new Time(mtimezone);
// Make sure we update to the current time
onTimeChanged();
counter.start();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mAttached) {
counter.cancel();
getContext().unregisterReceiver(mIntentReceiver);
mAttached = false;
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
float hScale = 1.0f;
float vScale = 1.0f;
if (widthMode != MeasureSpec.UNSPECIFIED && widthSize < mDialWidth) {
hScale = (float) widthSize/(float) mDialWidth;
}
if (heightMode != MeasureSpec.UNSPECIFIED && heightSize < mDialHeight) {
vScale = (float) heightSize/(float) mDialHeight;
}
System.out.println("***********************HAI****************");
float scale = Math.min(hScale, vScale);
setMeasuredDimension(resolveSize((int) (mDialWidth * scale), widthMeasureSpec),
resolveSize((int) (mDialHeight * scale), heightMeasureSpec));
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mChanged = true;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// // here changes on every tick//////
///////
/////
// //////
// // ///
// //
boolean changed = mChanged;
if (changed) {
mChanged = false;
}
boolean seconds = mSeconds;
if (seconds) {
mSeconds = false;
}
int availableWidth = 100;
int availableHeight = 200;
int x = availableWidth/2;
int y = availableHeight/2;
final Drawable dial = mDial;
int w = dial.getIntrinsicWidth();
int h = dial.getIntrinsicHeight();
boolean scaled = false;
if (availableWidth < w || availableHeight < h) {
scaled = true;
float scale = Math.min((float) availableWidth/(float) w,
(float) availableHeight/(float) h);
canvas.save();
canvas.scale(scale, scale, x, y);
}
if (changed) {
dial.setBounds(x - (w/2), y - (h/2), x + (w/2), y + (h/2));
}
dial.draw(canvas);
canvas.save();
canvas.rotate(mHour/12.0f * 360.0f, x, y);
final Drawable hourHand = mHourHand;
if (changed) {
w = hourHand.getIntrinsicWidth();
h = hourHand.getIntrinsicHeight();
hourHand.setBounds(x - (w/2), y - (h/3), x + (w/2), y + (h/3));
}
hourHand.draw(canvas);
canvas.restore();
canvas.save();
canvas.rotate(mMinutes/60.0f * 360.0f, x, y);
// canvas.rotate(mSecond, x, y);
final Drawable minuteHand = mMinuteHand;
if (changed) {
w = minuteHand.getIntrinsicWidth();
h = minuteHand.getIntrinsicHeight();
minuteHand.setBounds(x - (w/2), y - (h/3), x + (w/2), y + (h/3));
}
minuteHand.draw(canvas);
canvas.restore();
canvas.save();
canvas.rotate(mSecond, x, y);
// minuteHand = mMinuteHand;
if (seconds) {
w = mSecondHand.getIntrinsicWidth();
h = mSecondHand.getIntrinsicHeight();
mSecondHand.setBounds(x - (w/2), y - (h/3), x + (w/2), y + (h/3));
}
mSecondHand.draw(canvas);
canvas.restore();
if (scaled) {
canvas.restore();
}
}
MyCount counter = new MyCount(10000, 1000);
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
counter.start();
}
@Override
public void onTick(long millisUntilFinished) {
mCalendar.setToNow();
int hour = mCalendar.hour;
int minute = mCalendar.minute;
int second = mCalendar.second;
mSecond = 6.0f * second;
mSeconds = true;
// mChanged = true;
AnalogClock2.this.invalidate();
// Toast.makeText(mContext, "text", Toast.LENGTH_LONG).show();
}
}
boolean mSeconds = false;
float mSecond = 0;
private void onTimeChanged() {
mCalendar.setToNow();
int hour = mCalendar.hour+4;
int minute = mCalendar.minute+15;
int second = mCalendar.second;
mMinutes = minute + second/60.0f;
mHour = hour + mMinutes/60.0f;
mChanged = true;
}
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) {
String tz = intent.getStringExtra("time-zone");
mCalendar = new Time(TimeZone.getTimeZone(tz).getID());
}
mCalendar = new Time(mtimezone);
onTimeChanged();
invalidate();
}
};
}
+0
我有這樣的自定義模擬時鐘..以及如何從這個時鐘準備小部件? – 2013-04-12 05:09:51
相關問題
- 1. 如何定製模擬時鐘
- 2. 時鐘小工具殺死
- 3. 安卓:在模擬器
- 4. 安卓視頻錄製與模擬器
- 5. 模擬時鐘 - 在標籤上繪製時鐘手臂
- 6. Controling XML中的製表符小工具(安卓)
- 7. 安卓倒計時計時器的小時/分鐘選擇器
- 8. JSF模擬時鐘
- 9. 安卓小工具集中時的背景色
- 10. 安卓鬧鐘UI
- 11. 模擬時鐘工作,但秒重繪
- 12. 爲黑莓製作模擬時鐘
- 13. 安卓工具測試:IllegalAccessError
- 14. 安卓tabwidget定製
- 15. 安卓顯示/隱藏小工具調整大小填寫父
- 16. 生成特定時鐘減慢模擬
- 17. 模擬一個小宇宙的工具
- 18. 安卓鬧鐘管理器設置重複在特定時間
- 19. 安卓小工具不能正常工作
- 20. 定製時鐘小部件不工作在android 4.1.2
- 21. 推圖標遠在安卓工具欄
- 22. 安卓工作室模塊
- 23. 安卓:24小時格式
- 24. 模擬時鐘java作業
- 25. 模擬時鐘的setInterval()
- 26. 安卓工具欄不再工作
- 27. 安卓鬧鐘調整鬧鐘音量
- 28. 安卓模擬器Arch Linux在焦點不齊時落後
- 29. 安卓模擬器屏幕顛倒
- 30. Firemonkey安卓平臺塊模擬器
但AnalogClock也widegt可以在主屏幕小部件使用?具有u嘗試,如果再發布您的代碼 – 2012-04-11 08:16:46