Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

Commit

Permalink
Fixed AlarmManager minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mudar committed Jan 13, 2014
1 parent 60131ac commit 9f06c87
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void updateDuration(Intent intent) {
final long currentTimeRounded = TimeHelper.getRoundedCurrentTimeMillis();

mCurrentStats.mCurrentRun.mDuration = newDuration;
mCurrentStats.mCurrentRun.mTargetTime = currentTimeRounded + newDuration;
mCurrentStats.mCurrentRun.mTargetTime = mCurrentStats.mCurrentRun.mStartTime + newDuration;

PeaceOfMindPrefs.saveToSharedPreferences(mCurrentStats, mSharedPreferences);

Expand All @@ -159,7 +159,7 @@ private void updateDuration(Intent intent) {

mContext.sendBroadcast(updateIntent);

AlarmManagerHelper.updateAlarm(mContext, currentTimeRounded + mCurrentStats.mCurrentRun.mDuration);
AlarmManagerHelper.updateAlarm(mContext, mCurrentStats.mCurrentRun.mTargetTime);
} else {
endPeaceOfMind(false);
}
Expand Down Expand Up @@ -243,8 +243,6 @@ private void endPeaceOfMind(boolean wasInterrupted) {

setPeaceOfMindIconInNotificationBar(false, wasInterrupted);

if (wasInterrupted) {
AlarmManagerHelper.disableAlarm(mContext.getApplicationContext());
}
AlarmManagerHelper.disableAlarm(mContext.getApplicationContext(), wasInterrupted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void run() {
long currentTime = TimeHelper.getRoundedCurrentTimeMillis();

peaceOfMindTick(currentTime - currentStats.mCurrentRun.mStartTime, currentStats.mCurrentRun.mDuration);
if (currentStats.mCurrentRun.mTargetTime - currentTime > DateUtils.MINUTE_IN_MILLIS + Const.ALARM_INACCURACY) {
if (currentStats.mCurrentRun.mTargetTime - currentTime + Const.ALARM_INACCURACY > DateUtils.MINUTE_IN_MILLIS) {
startTimer();
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ private void loadAvailableData() {
final long currentTime = TimeHelper.getRoundedCurrentTimeMillis();
final float targetTimePercent = (float) currentStats.mCurrentRun.mDuration / (float) mMaxTime;

mVerticalSeekBar.setInvertedProgress((int) (targetTimePercent * mVerticalSeekBar.getHeight()));
mVerticalSeekBar.setInvertedProgress(targetTimePercent);

updateTextForNewTime(currentTime - currentStats.mCurrentRun.mStartTime, currentStats.mCurrentRun.mDuration);
updateTimeTextLabel(targetTimePercent * 100);
Expand Down Expand Up @@ -458,7 +458,7 @@ public synchronized void peaceOfMindStarted(long duration) {

updateTextForNewTime(0, duration);
updateScreenBackgrounds();
mVerticalSeekBar.setInvertedProgress((int) (targetTimePercent * mVerticalSeekBar.getHeight()));
mVerticalSeekBar.setInvertedProgress(targetTimePercent);

startPeaceOfMindVideo();
startTimer();
Expand Down Expand Up @@ -520,7 +520,7 @@ public void run() {
updateScreenBackgrounds();
mVerticalSeekBar.setThumb(mResources.getDrawable(R.drawable.seekbar_thumb_off));
mVerticalSeekBar.setThumbOffset(0);
mVerticalSeekBar.setInvertedProgress(0);
mVerticalSeekBar.setInvertedProgress(0f);
updateTextForNewTime(0, 0);
updateTimeTextLabel(0);

Expand Down Expand Up @@ -589,7 +589,7 @@ private void displayHintOnFirstRun(SharedPreferences prefs) {

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// Some devices cannot play MPEG-4, fallback using a lo-res H.264
// Some devices cannot play MPEG-4, fallback using a lo-res H.264
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.fp_start_pom_h264_video);
mVideo.setVideoURI(uri);
mVideo.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,87 +23,87 @@

public class VerticalSeekBar extends SeekBar {

private VerticalScrollListener _listener;

public VerticalSeekBar(Context context) {
super(context);
}

public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}

public void setPeaceListener(VerticalScrollListener listener) {
_listener = listener;
}

public void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}

@Override
protected synchronized void onMeasure(int widthMeasureSpec,
int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}

protected void onDraw(Canvas c) {
c.rotate(90);
c.translate(0, -getWidth());

super.onDraw(c);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
updateScroll(event);
break;
case MotionEvent.ACTION_MOVE:
updateScroll(event);
break;
case MotionEvent.ACTION_UP:
updateScroll(event);
performScrollEnded();
break;

case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
public void setInvertedProgress(int y){
final int i = getMax() - (getMax() * y / getHeight());
setProgress(100 - i);
onSizeChanged(getWidth(), getHeight(), 0, 0);
}

private void updateScroll(MotionEvent event) {
private VerticalScrollListener _listener;

public VerticalSeekBar(Context context) {
super(context);
}

public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}

public void setPeaceListener(VerticalScrollListener listener) {
_listener = listener;
}

public void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}

@Override
protected synchronized void onMeasure(int widthMeasureSpec,
int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}

protected void onDraw(Canvas c) {
c.rotate(90);
c.translate(0, -getWidth());

super.onDraw(c);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
updateScroll(event);
break;
case MotionEvent.ACTION_MOVE:
updateScroll(event);
break;
case MotionEvent.ACTION_UP:
updateScroll(event);
performScrollEnded();
break;

case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}

public void setInvertedProgress(float y) {
final int progress = (int) Math.ceil(getMax() * y);
setProgress(progress);
onSizeChanged(getWidth(), getHeight(), 0, 0);
}

private void updateScroll(MotionEvent event) {
final int i = getMax() - (int) (getMax() * event.getY() / getHeight());
setProgress(100 - i);
onSizeChanged(getWidth(), getHeight(), 0, 0);
if (_listener != null) {
_listener.updateBarScroll(getProgress());
}
}

private void performScrollEnded() {
float progress = getProgress() / 100.0f;

if (_listener != null) {
_listener.scrollEnded(progress);
}
}
setProgress(100 - i);
onSizeChanged(getWidth(), getHeight(), 0, 0);

if (_listener != null) {
_listener.updateBarScroll(getProgress());
}
}

private void performScrollEnded() {
float progress = getProgress() / 100.0f;

if (_listener != null) {
_listener.scrollEnded(progress);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public static void enableAlarm(Context context, long target) {
toggleWidgetRepeatingAlarm(context, target);
}

public static void disableAlarm(Context context) {
toggleWakeupAlarm(context, -1l);
public static void disableAlarm(Context context, boolean wasInterrupted) {
if (wasInterrupted) {
toggleWakeupAlarm(context, -1l);
}
toggleWidgetRepeatingAlarm(context, -1l);
}

Expand Down

0 comments on commit 9f06c87

Please sign in to comment.