Blame |
Last modification |
View Log
| RSS feed
package com.gebauz.Uhr;
import java.util.Timer;
import android.app.Activity;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.RemoteViews;
import android.widget.Toast;
import android.widget.ImageView;
import java.util.Date;
import java.util.TimerTask;
public class PopupActivity
extends Activity
{
private RefreshHandler redrawHandler =
new RefreshHandler
();
class RefreshHandler
extends Handler
{
@
Override
public void handleMessage
(Message msg
)
{
PopupActivity.
this.
update();
}
public void sleep
()
{
this.
removeMessages(0);
sendMessageDelayed
(obtainMessage
(0),
1000);
}
};
@
Override
protected void onCreate
(Bundle savedInstanceState
)
{
super.
onCreate(savedInstanceState
);
setContentView
(R.
layout.
popup);
//Toast.makeText(getApplicationContext(), "We are in PopupActivity", Toast.LENGTH_SHORT).show();
//Timer timer = new Timer();
//timer.scheduleAtFixedRate(new MyTime(getApplicationContext(), this), 0, 1000);
imageHours0 =
(ImageView)findViewById
(R.
id.
popup_hour0);
imageHours1 =
(ImageView)findViewById
(R.
id.
popup_hour1);
imageMins0 =
(ImageView)findViewById
(R.
id.
popup_min0);
imageMins1 =
(ImageView)findViewById
(R.
id.
popup_min1);
imageSecs0 =
(ImageView)findViewById
(R.
id.
popup_sek0);
imageSecs1 =
(ImageView)findViewById
(R.
id.
popup_sek1);
update
();
}
// private class MyTime extends TimerTask
// {
// PopupActivity popupActivity;
ImageView imageHours0
;
ImageView imageHours1
;
ImageView imageMins0
;
ImageView imageMins1
;
ImageView imageSecs0
;
ImageView imageSecs1
;
int hours0
[] =
{
R.
drawable.
hour0_0,
R.
drawable.
hour0_1,
R.
drawable.
hour0_2,
};
int hours1
[] =
{
R.
drawable.
hour1_0,
R.
drawable.
hour1_1,
R.
drawable.
hour1_2,
R.
drawable.
hour1_3,
R.
drawable.
hour1_4,
R.
drawable.
hour1_5,
R.
drawable.
hour1_6,
R.
drawable.
hour1_7,
R.
drawable.
hour1_8,
R.
drawable.
hour1_9,
};
int mins0
[] =
{
R.
drawable.
min0_0,
R.
drawable.
min0_1,
R.
drawable.
min0_2,
R.
drawable.
min0_3,
R.
drawable.
min0_4,
R.
drawable.
min0_5,
};
int mins1
[] =
{
R.
drawable.
min1_0,
R.
drawable.
min1_1,
R.
drawable.
min1_2,
R.
drawable.
min1_3,
R.
drawable.
min1_4,
R.
drawable.
min1_5,
R.
drawable.
min1_6,
R.
drawable.
min1_7,
R.
drawable.
min1_8,
R.
drawable.
min1_9,
};
int seks0
[] =
{
R.
drawable.
sek0_0,
R.
drawable.
sek0_1,
R.
drawable.
sek0_2,
R.
drawable.
sek0_3,
R.
drawable.
sek0_4,
R.
drawable.
sek0_5,
};
int seks1
[] =
{
R.
drawable.
sek1_0,
R.
drawable.
sek1_1,
R.
drawable.
sek1_2,
R.
drawable.
sek1_3,
R.
drawable.
sek1_4,
R.
drawable.
sek1_5,
R.
drawable.
sek1_6,
R.
drawable.
sek1_7,
R.
drawable.
sek1_8,
R.
drawable.
sek1_9,
};
/*
public MyTime(Context context, PopupActivity _popupActivity)
{
popupActivity = _popupActivity;
imageHours0 = (ImageView)popupActivity.findViewById(R.id.popup_hour0);
imageHours1 = (ImageView)popupActivity.findViewById(R.id.popup_hour1);
imageMins0 = (ImageView)popupActivity.findViewById(R.id.popup_min0);
imageMins1 = (ImageView)popupActivity.findViewById(R.id.popup_min1);
imageSecs0 = (ImageView)popupActivity.findViewById(R.id.popup_sek0);
imageSecs1 = (ImageView)popupActivity.findViewById(R.id.popup_sek1);
run();
}*/
// @Override
public void update
()
{
Date now =
new Date();
int hours = now.
getHours();
int hour0 = hours /
10;
int hour1 = hours
% 10;
if (hour0
>=
3)
hour0 =
3;
if (hour1
>=
10)
hour1 =
10;
int mins = now.
getMinutes();
int min0 = mins /
10;
int min1 = mins
% 10;
if (min0
>=
6)
min0 =
6;
if (min1
>=
10)
min1 =
10;
int seconds = now.
getSeconds();
int second0 = seconds /
10;
int second1 = seconds
% 10;
if (seconds
>=
6)
seconds =
6;
if (second1
>=
10)
second1 =
10;
SetImageForDigit
(imageHours0, hours0
[hour0
]);
SetImageForDigit
(imageHours1, hours1
[hour1
]);
SetImageForDigit
(imageMins0, mins0
[min0
]);
SetImageForDigit
(imageMins1, mins1
[min1
]);
SetImageForDigit
(imageSecs0, seks0
[second0
]);
SetImageForDigit
(imageSecs1, seks1
[second1
]);
//remoteViews.setImageViewResource(R.id.widget_hour0, R.drawable.hour0_2);
//remoteViews.setTextViewText(R.id.widget_textview, "Time = " + format.format(new Date()));
//appWidgetManager.updateAppWidget(thisWidget, remoteViews);
redrawHandler.
sleep();
}
public void SetImageForDigit
(ImageView img,
int resource
)
{
img.
setImageResource(resource
);
img.
postInvalidate();
//remoteViews.setImageViewResource(digit, resource);
}
// }
}