.XML file
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center"
android:layout_gravity="center">
<AnalogClock android:dial="@drawable/clockdialog2"
android:hand_hour="@drawable/arrow_hour1" android:layout_gravity="center"
android:layout_width="wrap_content" android:id="@+id/AnalogClock"
android:layout_height="wrap_content" android:hand_minute="@drawable/widgetminute">
</AnalogClock>
<ImageView android:src="@drawable/arrow_second1"
android:id="@+id/imgsecond" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerInParent="true" />
</RelativeLayout>
.JAVA file
final Runnable mRunnable = new Runnable() {
public void run() {
Date mDate = new Date();
int mHours = mDate.getHours();
int mMinutes = mDate.getMinutes();
int mSeconds = mDate.getSeconds();
String mCurrentTime = mHours + ":" + mMinutes + "::" + mSeconds;
Log.v(TAG, "CurrentTime: " + mCurrentTime + " Counter "
+ mCounter);
try {
img = (ImageView) findViewById(R.id.imgsecond);
RotateAnimation rotateAnimation = new RotateAnimation(
(mSeconds - 1) * 6, mSeconds * 6,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(true);
img.startAnimation(rotateAnimation);
} catch (Exception e) {
Log.e("log_tag", "Error msg is " + e.toString());
}
if (mCurrentTime.equals("17:38")) {
PlayChim();
}
if (!mStop) {
mHandler.postDelayed(this, 1000);
}
if (mCounter >= 56) {
// mStop = true;
try {
mMediaPlayer.stop();
} catch (Exception e) {
Log.v(TAG, "MediaPlayerStopException " + e.toString());
}
}
}
private void PlayChim() {
try {
mMediaPlayer = MediaPlayer.create(mContext, R.raw.bell);
mMediaPlayer.start();
} catch (Exception e) {
Log.v(TAG, "MediaPlayerException " + e.toString());
}
mCounter++;
}
};
mHandler.postDelayed(mRunnable, 1000);
}
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center"
android:layout_gravity="center">
<AnalogClock android:dial="@drawable/clockdialog2"
android:hand_hour="@drawable/arrow_hour1" android:layout_gravity="center"
android:layout_width="wrap_content" android:id="@+id/AnalogClock"
android:layout_height="wrap_content" android:hand_minute="@drawable/widgetminute">
</AnalogClock>
<ImageView android:src="@drawable/arrow_second1"
android:id="@+id/imgsecond" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerInParent="true" />
</RelativeLayout>
.JAVA file
final Runnable mRunnable = new Runnable() {
public void run() {
Date mDate = new Date();
int mHours = mDate.getHours();
int mMinutes = mDate.getMinutes();
int mSeconds = mDate.getSeconds();
String mCurrentTime = mHours + ":" + mMinutes + "::" + mSeconds;
Log.v(TAG, "CurrentTime: " + mCurrentTime + " Counter "
+ mCounter);
try {
img = (ImageView) findViewById(R.id.imgsecond);
RotateAnimation rotateAnimation = new RotateAnimation(
(mSeconds - 1) * 6, mSeconds * 6,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(true);
img.startAnimation(rotateAnimation);
} catch (Exception e) {
Log.e("log_tag", "Error msg is " + e.toString());
}
if (mCurrentTime.equals("17:38")) {
PlayChim();
}
if (!mStop) {
mHandler.postDelayed(this, 1000);
}
if (mCounter >= 56) {
// mStop = true;
try {
mMediaPlayer.stop();
} catch (Exception e) {
Log.v(TAG, "MediaPlayerStopException " + e.toString());
}
}
}
private void PlayChim() {
try {
mMediaPlayer = MediaPlayer.create(mContext, R.raw.bell);
mMediaPlayer.start();
} catch (Exception e) {
Log.v(TAG, "MediaPlayerException " + e.toString());
}
mCounter++;
}
};
mHandler.postDelayed(mRunnable, 1000);
}
hi girish great work
ReplyDeleteHi,Nice tutorial.how to make this a widget?
ReplyDeleteplease reply via email ;)
ReplyDeletenice tutorial.how to make this app widget?please reply via email
ReplyDelete