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

View File

@ -8,6 +8,7 @@ import android.content.Intent;
import com.philliphsu.clock2.alarms.ScrollHandler; import com.philliphsu.clock2.alarms.ScrollHandler;
import com.philliphsu.clock2.model.TimersTableManager; import com.philliphsu.clock2.model.TimersTableManager;
import com.philliphsu.clock2.timers.TimerNotificationService; import com.philliphsu.clock2.timers.TimerNotificationService;
import com.philliphsu.clock2.timers.TimerRingtoneService;
import com.philliphsu.clock2.timers.TimesUpActivity; import com.philliphsu.clock2.timers.TimesUpActivity;
/** /**
@ -77,5 +78,8 @@ public final class AsyncTimersTableUpdateHandler extends AsyncDatabaseTableUpdat
if (removeNotification) { if (removeNotification) {
TimerNotificationService.cancelNotification(getContext(), timer.getId()); 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?
} }
} }

View File

@ -1,8 +1,7 @@
package com.philliphsu.clock2.alarms; package com.philliphsu.clock2.alarms;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.ViewGroup;
import android.widget.Button;
import com.philliphsu.clock2.Alarm; import com.philliphsu.clock2.Alarm;
import com.philliphsu.clock2.R; 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. // 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. // This could be the case if we're starting a new instance of this activity after leaving the first launch.
mAlarmController.removeUpcomingAlarmNotification(getRingingObject()); 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 @Override
@ -48,14 +27,50 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
return AlarmRingtoneService.class; 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()); mAlarmController.snoozeAlarm(getRingingObject());
// Can't call dismiss() because we don't want to also call cancelAlarm()! Why? For example, // 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. // we don't want the alarm, if it has no recurrence, to be turned off right now.
stopAndFinish(); stopAndFinish();
} }
private void dismiss() { @Override
protected void onRightButtonClick() {
// TODO do we really need to cancel the intent and alarm? // TODO do we really need to cancel the intent and alarm?
mAlarmController.cancelAlarm(getRingingObject(), false); mAlarmController.cancelAlarm(getRingingObject(), false);
stopAndFinish(); stopAndFinish();

View File

@ -5,13 +5,24 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; 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.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager; 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 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. * An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction. * 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 static boolean sIsAlive = false;
private T mRingingObject; private T mRingingObject;
// TODO: Should we extend from BaseActivity instead? @Bind(R.id.title) TextView mHeaderTitle;
@LayoutRes @Bind(R.id.auto_silenced_text) TextView mAutoSilencedText;
public abstract int layoutResource(); @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 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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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; sIsAlive = true;
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 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_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if ((mRingingObject = getIntent().getParcelableExtra(EXTRA_RINGING_OBJECT)) == null) { mHeaderTitle.setText(getHeaderTitle()); // TOneverDO: call before assigning mRingingObject
throw new IllegalStateException("Cannot start RingtoneActivity without a ringing object"); 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()) Intent intent = new Intent(this, getRingtoneServiceClass())
.putExtra(EXTRA_RINGING_OBJECT, mRingingObject); .putExtra(EXTRA_RINGING_OBJECT, mRingingObject);
startService(intent); startService(intent);

View File

@ -2,6 +2,8 @@ package com.philliphsu.clock2.timers;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock;
import android.view.ViewGroup;
import com.philliphsu.clock2.R; import com.philliphsu.clock2.R;
import com.philliphsu.clock2.Timer; import com.philliphsu.clock2.Timer;
@ -17,13 +19,60 @@ public class TimesUpActivity extends RingtoneActivity<Timer> {
TimerNotificationService.cancelNotification(this, getRingingObject().getId()); TimerNotificationService.cancelNotification(this, getRingingObject().getId());
} }
@Override
public int layoutResource() {
return R.layout.activity_ringtone;
}
@Override @Override
protected Class<? extends RingtoneService> getRingtoneServiceClass() { protected Class<? extends RingtoneService> getRingtoneServiceClass() {
return TimerRingtoneService.class; 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() {
}
} }

View File

@ -1,44 +1,75 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#0099cc" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ringtone.RingtoneActivity"> android:background="@color/colorPrimary">
<!-- The primary full-screen view. This can be replaced with whatever view <LinearLayout
is needed to present your content, e.g. VideoView, SurfaceView, android:id="@+id/header"
TextureView, etc. -->
<TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:gravity="center" android:layout_marginTop="@dimen/activity_vertical_margin"
android:keepScreenOn="true" android:orientation="vertical"
android:text="@string/dummy_content" android:gravity="center_horizontal">
android:textColor="#33b5e5"
android:textSize="50sp" <TextView
android:textStyle="bold"/> android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Title.Inverse"
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="vertical"
android:layout_gravity="bottom" android:layout_gravity="center"
android:padding="4dp"> android:gravity="center"
android:visibility="gone">
<TextView
android:id="@+id/auto_silenced_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:keepScreenOn="true"
android:gravity="center_horizontal"
style="@style/TextAppearance.AppCompat.Large.Inverse"
android:layout_marginBottom="8dp"/>
<Button <Button
android:id="@+id/btn_snooze" android:id="@+id/ok"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:text="@android:string/ok"
android:text="Snooze"/> style="@style/Widget.AppCompat.Button.Colored"/>
<Button
android:id="@+id/btn_dismiss"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Dismiss"/>
</LinearLayout> </LinearLayout>
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="72dp"
app:columnCount="2">
<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
app:layout_gravity="center"
app:elevation="0dp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
app:layout_gravity="center"
app:elevation="0dp"/>
</android.support.v7.widget.GridLayout>
</FrameLayout> </FrameLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<TextClock xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Base.TextAppearance.AppCompat.Display2"
android:textColor="?android:attr/textColorPrimaryInverse"/>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<com.philliphsu.clock2.timers.CountdownChronometer
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Display2"
android:textColor="?android:attr/textColorPrimaryInverse"/>

View File

@ -19,7 +19,7 @@
<!-- NumpadTimePickerDialog --> <!-- NumpadTimePickerDialog -->
<dimen name="numpad_height">300dp</dimen> <dimen name="numpad_height">300dp</dimen>
<dimen name="time_input_text_size">45sp</dimen> <dimen name="time_input_text_size">45sp</dimen>
<dimen name="fab_cell_height">88dp <dimen name="viewpager_bottom_padding">88dp
</dimen> <!-- 56dp fab size + 16dp top margin + 16dp bottom margin --> </dimen> <!-- 56dp fab size + 16dp top margin + 16dp bottom margin -->
<!-- Bottom sheet specs --> <!-- Bottom sheet specs -->
@ -30,4 +30,22 @@
then the sheet will show fully expanded; the contents are not stretched to match this height. then the sheet will show fully expanded; the contents are not stretched to match this height.
This is large enough to accommodate most, if not all, of our layouts. --> This is large enough to accommodate most, if not all, of our layouts. -->
<dimen name="peek_height_upper_limit">500dp</dimen> <dimen name="peek_height_upper_limit">500dp</dimen>
<dimen name="text_size_body_1">14sp</dimen>
<dimen name="text_size_body_2">14sp</dimen>
<dimen name="text_size_button">14sp</dimen>
<dimen name="text_size_caption">12sp</dimen>
<dimen name="text_size_display_1">34sp</dimen>
<dimen name="text_size_display_2">45sp</dimen>
<dimen name="text_size_display_3">56sp</dimen>
<dimen name="text_size_display_4">112sp</dimen>
<dimen name="text_size_headline">24sp</dimen>
<dimen name="text_size_large">22sp</dimen>
<dimen name="text_size_medium">18sp</dimen>
<dimen name="text_size_menu">16sp</dimen>
<dimen name="text_size_small">14sp</dimen>
<dimen name="text_size_subhead">16sp</dimen>
<dimen name="text_size_subtitle_toolbar">16dp</dimen>
<dimen name="text_size_title">20sp</dimen>
<dimen name="text_size_title_toolbar">20dp</dimen>
</resources> </resources>

View File

@ -197,4 +197,7 @@
<string name="add_one_minute">Add 1 minute</string> <string name="add_one_minute">Add 1 minute</string>
<string name="stop">Stop</string> <string name="stop">Stop</string>
<string name="timer_expired">Timer expired</string> <string name="timer_expired">Timer expired</string>
<string name="alarm_auto_silenced_text">You missed your alarm.</string>
<string name="timer_auto_silenced_text">Your timer expired.</string>
</resources> </resources>