Snooze and dismiss buttons added to RingtoneActivity
This commit is contained in:
parent
f7c788cf46
commit
666b3a2a6e
@ -20,9 +20,8 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".ringtone.RingtoneActivity"
|
android:name=".ringtone.RingtoneActivity"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
|
||||||
android:label="@string/title_activity_ringtone"
|
android:label="@string/title_activity_ringtone"
|
||||||
android:theme="@style/FullscreenTheme">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
|
|||||||
@ -10,12 +10,22 @@ import android.support.v4.app.NotificationCompat;
|
|||||||
public class UpcomingAlarmReceiver extends BroadcastReceiver {
|
public class UpcomingAlarmReceiver extends BroadcastReceiver {
|
||||||
public static final String ACTION_CANCEL_NOTIFICATION
|
public static final String ACTION_CANCEL_NOTIFICATION
|
||||||
= "com.philliphsu.clock2.action.CANCEL_NOTIFICATION";
|
= "com.philliphsu.clock2.action.CANCEL_NOTIFICATION";
|
||||||
|
public static final String ACTION_SHOW_SNOOZING
|
||||||
|
= "com.philliphsu.clock2.action.CANCEL_NOTIFICATION";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) {
|
if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) {
|
||||||
nm.cancel("tag", 0);
|
nm.cancel("tag", 0);
|
||||||
|
} else if (ACTION_SHOW_SNOOZING.equals(intent.getAction())) {
|
||||||
|
Notification note = new NotificationCompat.Builder(context)
|
||||||
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
|
.setContentTitle("Snoozing")
|
||||||
|
.setContentText("New ring time here")
|
||||||
|
.build();
|
||||||
|
// todo actions
|
||||||
|
nm.notify("tag", 0, note);
|
||||||
} else {
|
} else {
|
||||||
Notification note = new NotificationCompat.Builder(context)
|
Notification note = new NotificationCompat.Builder(context)
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
package com.philliphsu.clock2.ringtone;
|
package com.philliphsu.clock2.ringtone;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.support.v7.app.ActionBar;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
import com.philliphsu.clock2.R;
|
import com.philliphsu.clock2.R;
|
||||||
import com.philliphsu.clock2.UpcomingAlarmReceiver;
|
import com.philliphsu.clock2.UpcomingAlarmReceiver;
|
||||||
@ -23,75 +23,6 @@ import static com.philliphsu.clock2.util.Preconditions.checkNotNull;
|
|||||||
* TODO: Implement dismiss and extend logic here.
|
* TODO: Implement dismiss and extend logic here.
|
||||||
*/
|
*/
|
||||||
public class RingtoneActivity extends AppCompatActivity {
|
public class RingtoneActivity extends AppCompatActivity {
|
||||||
/**
|
|
||||||
* Whether or not the system UI should be auto-hidden after
|
|
||||||
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
|
|
||||||
*/
|
|
||||||
private static final boolean AUTO_HIDE = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
|
|
||||||
* user interaction before hiding the system UI.
|
|
||||||
*/
|
|
||||||
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Some older devices needs a small delay between UI widget updates
|
|
||||||
* and a change of the status and navigation bar.
|
|
||||||
*/
|
|
||||||
private static final int UI_ANIMATION_DELAY = 300;
|
|
||||||
private final Handler mHideHandler = new Handler();
|
|
||||||
private View mContentView;
|
|
||||||
private final Runnable mHidePart2Runnable = new Runnable() {
|
|
||||||
@SuppressLint("InlinedApi")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Delayed removal of status and navigation bar
|
|
||||||
|
|
||||||
// Note that some of these constants are new as of API 16 (Jelly Bean)
|
|
||||||
// and API 19 (KitKat). It is safe to use them, as they are inlined
|
|
||||||
// at compile-time and do nothing on earlier devices.
|
|
||||||
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
|
|
||||||
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
||||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
||||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private View mControlsView;
|
|
||||||
private final Runnable mShowPart2Runnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Delayed display of UI elements
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
|
||||||
if (actionBar != null) {
|
|
||||||
actionBar.show();
|
|
||||||
}
|
|
||||||
mControlsView.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private boolean mVisible;
|
|
||||||
private final Runnable mHideRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* Touch listener to use for in-layout UI controls to delay hiding the
|
|
||||||
* system UI. This is to prevent the jarring behavior of controls going away
|
|
||||||
* while interacting with activity UI.
|
|
||||||
*/
|
|
||||||
private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
||||||
if (AUTO_HIDE) {
|
|
||||||
delayedHide(AUTO_HIDE_DELAY_MILLIS);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -107,75 +38,64 @@ public class RingtoneActivity extends AppCompatActivity {
|
|||||||
.setAction(UpcomingAlarmReceiver.ACTION_CANCEL_NOTIFICATION);
|
.setAction(UpcomingAlarmReceiver.ACTION_CANCEL_NOTIFICATION);
|
||||||
sendBroadcast(intent2);
|
sendBroadcast(intent2);
|
||||||
|
|
||||||
mVisible = true;
|
Button snooze = (Button) findViewById(R.id.btn_snooze);
|
||||||
mControlsView = findViewById(R.id.fullscreen_content_controls);
|
snooze.setOnClickListener(new View.OnClickListener() {
|
||||||
mContentView = findViewById(R.id.fullscreen_content);
|
|
||||||
|
|
||||||
|
|
||||||
// Set up the user interaction to manually show or hide the system UI.
|
|
||||||
mContentView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View v) {
|
||||||
toggle();
|
snooze();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Button dismiss = (Button) findViewById(R.id.btn_dismiss);
|
||||||
|
dismiss.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Upon interacting with UI controls, delay any scheduled hide()
|
|
||||||
// operations to prevent the jarring behavior of controls going away
|
|
||||||
// while interacting with the UI.
|
|
||||||
findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostCreate(Bundle savedInstanceState) {
|
public void onWindowFocusChanged(boolean hasFocus) {
|
||||||
super.onPostCreate(savedInstanceState);
|
super.onWindowFocusChanged(hasFocus);
|
||||||
|
if (hasFocus) {
|
||||||
|
// Set the content to appear under the system bars so that the
|
||||||
|
// content doesn't resize when the system bars hide and show.
|
||||||
|
// The system bars will remain hidden on user interaction;
|
||||||
|
// however, they can be revealed using swipe gestures along
|
||||||
|
// the region where they normally appear.
|
||||||
|
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
|
||||||
|
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
|
||||||
|
| View.SYSTEM_UI_FLAG_IMMERSIVE;
|
||||||
|
|
||||||
// Trigger the initial hide() shortly after the activity has been
|
// Make status bar translucent, which automatically adds
|
||||||
// created, to briefly hint to the user that UI controls
|
// SYSTEM_UI_FLAG_LAYOUT_STABLE and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
// are available.
|
// Looks too light on the current background..
|
||||||
delayedHide(100);
|
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||||
}
|
getWindow().getDecorView().setSystemUiVisibility(uiOptions);
|
||||||
|
|
||||||
private void toggle() {
|
|
||||||
if (mVisible) {
|
|
||||||
hide();
|
|
||||||
} else {
|
|
||||||
show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hide() {
|
private void snooze() {
|
||||||
// Hide UI first
|
// Schedule another launch
|
||||||
ActionBar actionBar = getSupportActionBar();
|
Intent intent = new Intent(this, RingtoneActivity.class)
|
||||||
if (actionBar != null) {
|
.setData(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
|
||||||
actionBar.hide();
|
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
}
|
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
|
||||||
mControlsView.setVisibility(View.GONE);
|
am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pi);
|
||||||
mVisible = false;
|
// Post snoozing notif right away
|
||||||
|
Intent intent2 = new Intent(this, UpcomingAlarmReceiver.class)
|
||||||
// Schedule a runnable to remove the status and navigation bar after a delay
|
.setAction(UpcomingAlarmReceiver.ACTION_SHOW_SNOOZING);
|
||||||
mHideHandler.removeCallbacks(mShowPart2Runnable);
|
sendBroadcast(intent2);
|
||||||
mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
private void dismiss() {
|
||||||
private void show() {
|
// TODO: Use appropriate subclass
|
||||||
// Show the system bar
|
stopService(new Intent(this, RingtoneService.class));
|
||||||
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
// TODO: Do we need to cancel the PendingIntent and the alarm in AlarmManager?
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
finish();
|
||||||
mVisible = true;
|
|
||||||
|
|
||||||
// Schedule a runnable to display UI elements after a delay
|
|
||||||
mHideHandler.removeCallbacks(mHidePart2Runnable);
|
|
||||||
mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Schedules a call to hide() in [delay] milliseconds, canceling any
|
|
||||||
* previously scheduled calls.
|
|
||||||
*/
|
|
||||||
private void delayedHide(int delayMillis) {
|
|
||||||
mHideHandler.removeCallbacks(mHideRunnable);
|
|
||||||
mHideHandler.postDelayed(mHideRunnable, delayMillis);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@
|
|||||||
is needed to present your content, e.g. VideoView, SurfaceView,
|
is needed to present your content, e.g. VideoView, SurfaceView,
|
||||||
TextureView, etc. -->
|
TextureView, etc. -->
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/fullscreen_content"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
@ -19,32 +18,27 @@
|
|||||||
android:textSize="50sp"
|
android:textSize="50sp"
|
||||||
android:textStyle="bold"/>
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
<!-- This FrameLayout insets its children based on system windows using
|
<LinearLayout
|
||||||
android:fitsSystemWindows. -->
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:fitsSystemWindows="true">
|
android:orientation="horizontal"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:padding="4dp">
|
||||||
|
|
||||||
<LinearLayout
|
<Button
|
||||||
android:id="@+id/fullscreen_content_controls"
|
android:id="@+id/btn_snooze"
|
||||||
style="?metaButtonBarStyle"
|
android:layout_width="0dp"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|center_horizontal"
|
android:layout_weight="1"
|
||||||
android:background="@color/black_overlay"
|
android:text="Snooze"/>
|
||||||
android:orientation="horizontal"
|
|
||||||
tools:ignore="UselessParent">
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/dummy_button"
|
android:id="@+id/btn_dismiss"
|
||||||
style="?metaButtonBarButtonStyle"
|
android:layout_width="0dp"
|
||||||
android:layout_width="0dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_weight="1"
|
||||||
android:layout_weight="1"
|
android:text="Dismiss"/>
|
||||||
android:text="@string/dummy_button"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|||||||
@ -17,16 +17,4 @@
|
|||||||
|
|
||||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
||||||
|
|
||||||
<style name="FullscreenTheme" parent="AppTheme">
|
|
||||||
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
|
|
||||||
<item name="android:windowActionBarOverlay">true</item>
|
|
||||||
<item name="android:windowBackground">@null</item>
|
|
||||||
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
|
|
||||||
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
|
|
||||||
<item name="android:background">@color/black_overlay</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user