New ringtone activity layout

This commit is contained in:
Phillip Hsu
2016-08-06 00:06:15 -07:00
parent 6ae9c3511c
commit d845f241e9
9 changed files with 246 additions and 66 deletions
@@ -8,6 +8,7 @@ import android.content.Intent;
import com.philliphsu.clock2.alarms.ScrollHandler;
import com.philliphsu.clock2.model.TimersTableManager;
import com.philliphsu.clock2.timers.TimerNotificationService;
import com.philliphsu.clock2.timers.TimerRingtoneService;
import com.philliphsu.clock2.timers.TimesUpActivity;
/**
@@ -77,5 +78,8 @@ public final class AsyncTimersTableUpdateHandler extends AsyncDatabaseTableUpdat
if (removeNotification) {
TimerNotificationService.cancelNotification(getContext(), timer.getId());
}
// Won't do anything if not actually started
getContext().stopService(new Intent(getContext(), TimerRingtoneService.class));
// TODO: Do we need to finish TimesUpActivity?
}
}
@@ -1,8 +1,7 @@
package com.philliphsu.clock2.alarms;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.ViewGroup;
import com.philliphsu.clock2.Alarm;
import com.philliphsu.clock2.R;
@@ -21,26 +20,6 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
// TODO: If the upcoming alarm notification isn't present, verify other notifications aren't affected.
// This could be the case if we're starting a new instance of this activity after leaving the first launch.
mAlarmController.removeUpcomingAlarmNotification(getRingingObject());
// TODO: Butterknife binding
Button snooze = (Button) findViewById(R.id.btn_snooze);
snooze.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
snooze();
}
});
Button dismiss = (Button) findViewById(R.id.btn_dismiss);
dismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
@Override
public int layoutResource() {
return R.layout.activity_ringtone;
}
@Override
@@ -48,14 +27,50 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
return AlarmRingtoneService.class;
}
private void snooze() {
@Override
protected CharSequence getHeaderTitle() {
return getRingingObject().label();
}
@Override
protected void getHeaderContent(ViewGroup parent) {
// TODO: Consider applying size span on the am/pm label
getLayoutInflater().inflate(R.layout.content_header_alarm_activity, parent, true);
}
@Override
protected int getAutoSilencedDrawable() {
// TODO: correct icon
return R.drawable.ic_half_day_1_black_24dp;
}
@Override
protected int getAutoSilencedText() {
return R.string.alarm_auto_silenced_text;
}
@Override
protected int getLeftButtonDrawable() {
// TODO: correct icon
return R.drawable.ic_half_day_1_black_24dp;
}
@Override
protected int getRightButtonDrawable() {
// TODO: correct icon
return R.drawable.ic_half_day_1_black_24dp;
}
@Override
protected void onLeftButtonClick() {
mAlarmController.snoozeAlarm(getRingingObject());
// Can't call dismiss() because we don't want to also call cancelAlarm()! Why? For example,
// we don't want the alarm, if it has no recurrence, to be turned off right now.
stopAndFinish();
}
private void dismiss() {
@Override
protected void onRightButtonClick() {
// TODO do we really need to cancel the intent and alarm?
mAlarmController.cancelAlarm(getRingingObject(), false);
stopAndFinish();
@@ -5,13 +5,24 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.LayoutRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.philliphsu.clock2.R;
import com.philliphsu.clock2.util.LocalBroadcastHelper;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
@@ -26,16 +37,48 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
private static boolean sIsAlive = false;
private T mRingingObject;
// TODO: Should we extend from BaseActivity instead?
@LayoutRes
public abstract int layoutResource();
@Bind(R.id.title) TextView mHeaderTitle;
@Bind(R.id.auto_silenced_text) TextView mAutoSilencedText;
@Bind(R.id.ok) Button mOkButton;
@Bind(R.id.btn_left) FloatingActionButton mLeftButton;
@Bind(R.id.btn_right) FloatingActionButton mRightButton;
protected abstract Class<? extends RingtoneService> getRingtoneServiceClass();
protected abstract CharSequence getHeaderTitle();
/**
* Subclasses are responsible for adding their content view
* to the provided parent container.
*/
protected abstract void getHeaderContent(ViewGroup parent);
@DrawableRes
protected abstract int getAutoSilencedDrawable();
@StringRes
protected abstract int getAutoSilencedText();
@DrawableRes
protected abstract int getLeftButtonDrawable();
@DrawableRes
protected abstract int getRightButtonDrawable();
@OnClick(R.id.btn_left)
protected abstract void onLeftButtonClick();
@OnClick(R.id.btn_right)
protected abstract void onRightButtonClick();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layoutResource());
setContentView(R.layout.activity_ringtone);
ButterKnife.bind(this);
if ((mRingingObject = getIntent().getParcelableExtra(EXTRA_RINGING_OBJECT)) == null)
throw new IllegalStateException("Cannot start RingtoneActivity without a ringing object");
sIsAlive = true;
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
@@ -43,9 +86,13 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if ((mRingingObject = getIntent().getParcelableExtra(EXTRA_RINGING_OBJECT)) == null) {
throw new IllegalStateException("Cannot start RingtoneActivity without a ringing object");
}
mHeaderTitle.setText(getHeaderTitle()); // TOneverDO: call before assigning mRingingObject
getHeaderContent((LinearLayout) findViewById(R.id.header));
mAutoSilencedText.setCompoundDrawablesWithIntrinsicBounds(0, getAutoSilencedDrawable(), 0, 0);
mAutoSilencedText.setText(getAutoSilencedText());
mLeftButton.setImageResource(getLeftButtonDrawable());
mRightButton.setImageResource(getRightButtonDrawable());
Intent intent = new Intent(this, getRingtoneServiceClass())
.putExtra(EXTRA_RINGING_OBJECT, mRingingObject);
startService(intent);
@@ -2,6 +2,8 @@ package com.philliphsu.clock2.timers;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.ViewGroup;
import com.philliphsu.clock2.R;
import com.philliphsu.clock2.Timer;
@@ -17,13 +19,60 @@ public class TimesUpActivity extends RingtoneActivity<Timer> {
TimerNotificationService.cancelNotification(this, getRingingObject().getId());
}
@Override
public int layoutResource() {
return R.layout.activity_ringtone;
}
@Override
protected Class<? extends RingtoneService> getRingtoneServiceClass() {
return TimerRingtoneService.class;
}
@Override
protected CharSequence getHeaderTitle() {
return getRingingObject().label();
}
@Override
protected void getHeaderContent(ViewGroup parent) {
// Inflate the content and apply the parent's layout params, but don't
// attach it to the parent yet. This is so the return value can be
// the root of the inflated content, and not the parent. Alternatively,
// we could set an id on the root of the content's layout and find it
// from the returned parent.
CountdownChronometer countdown = (CountdownChronometer) getLayoutInflater()
.inflate(R.layout.content_header_timesup_activity, parent, false);
countdown.setBase(SystemClock.elapsedRealtime());
countdown.start();
parent.addView(countdown);
}
@Override
protected int getAutoSilencedDrawable() {
// TODO: correct icon
return R.drawable.ic_half_day_1_black_24dp;
}
@Override
protected int getAutoSilencedText() {
return R.string.timer_auto_silenced_text;
}
@Override
protected int getLeftButtonDrawable() {
// TODO: correct icon
return R.drawable.ic_half_day_1_black_24dp;
}
@Override
protected int getRightButtonDrawable() {
// TODO: correct icon
return R.drawable.ic_half_day_1_black_24dp;
}
@Override
protected void onLeftButtonClick() {
}
@Override
protected void onRightButtonClick() {
}
}