Before trying bug fix
This commit is contained in:
parent
53d5eed670
commit
f67c5e5bb5
@ -23,6 +23,7 @@
|
||||
android:name=".ringtone.RingtoneActivity"
|
||||
android:label="@string/title_activity_ringtone"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:launchMode="singleTask"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity="com.philliphsu.clock2.RingtoneActivity">
|
||||
</activity>
|
||||
|
||||
@ -4,6 +4,7 @@ import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.philliphsu.clock2.Alarm;
|
||||
import com.philliphsu.clock2.UpcomingAlarmReceiver;
|
||||
@ -24,10 +25,12 @@ import static com.philliphsu.clock2.util.Preconditions.checkNotNull;
|
||||
* TODO: Adapt this to Timers too...
|
||||
*/
|
||||
public final class AlarmUtils {
|
||||
private static final String TAG = "AlarmUtils";
|
||||
|
||||
private AlarmUtils() {}
|
||||
|
||||
public static void scheduleAlarm(Context context, Alarm alarm) {
|
||||
Log.d(TAG, "Scheduling alarm " + alarm);
|
||||
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
// If there is already an alarm for this Intent scheduled (with the equality of two
|
||||
// intents being defined by filterEquals(Intent)), then it will be removed and replaced
|
||||
|
||||
@ -7,7 +7,9 @@ import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.philliphsu.clock2.Alarm;
|
||||
@ -36,11 +38,18 @@ public class RingtoneActivity extends AppCompatActivity implements RingtoneServi
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_ringtone);
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||
|
||||
long id = getIntent().getLongExtra(EXTRA_ITEM_ID, -1);
|
||||
if (id < 0) {
|
||||
throw new IllegalStateException("Cannot start RingtoneActivity without item's id");
|
||||
}
|
||||
mAlarm = checkNotNull(AlarmsRepository.getInstance(this).getItem(id));
|
||||
Log.d(TAG, "Ringing alarm " + mAlarm);
|
||||
|
||||
// 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.
|
||||
@ -68,6 +77,20 @@ public class RingtoneActivity extends AppCompatActivity implements RingtoneServi
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
//super.onNewIntent(intent); // Not needed since no fragments hosted?
|
||||
// Calling recreate() would recreate this with its current intent, not the new intent passed in here.
|
||||
mBoundService.onNewActivity(); // notify alarm missed
|
||||
finish(); // destroy this, unbind from service, and stop service
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
@ -101,13 +124,16 @@ public class RingtoneActivity extends AppCompatActivity implements RingtoneServi
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// According to the lifecycle diagram, you unbind from the service first and then stop the service.
|
||||
unbindService(mConnection);
|
||||
// TODO: Use appropriate subclass
|
||||
// If service is not running, nothing happens.
|
||||
stopService(new Intent(this, RingtoneService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutoSilence() {
|
||||
// Service should have stopped itself by this point
|
||||
finish();
|
||||
dismiss();
|
||||
}
|
||||
|
||||
private void snooze() {
|
||||
@ -118,13 +144,11 @@ public class RingtoneActivity extends AppCompatActivity implements RingtoneServi
|
||||
}
|
||||
|
||||
private void dismiss() {
|
||||
// TODO: Use appropriate subclass
|
||||
stopService(new Intent(this, RingtoneService.class));
|
||||
// TODO: Do we need to cancel the PendingIntent and the alarm in AlarmManager?
|
||||
finish();
|
||||
}
|
||||
|
||||
private RingtoneService mBoundService; // TODO: Don't need? Only used locally in ServiceConnection.
|
||||
private RingtoneService mBoundService;
|
||||
|
||||
private ServiceConnection mConnection = new ServiceConnection() {
|
||||
@Override
|
||||
|
||||
@ -64,7 +64,6 @@ public class RingtoneService extends Service { // TODO: abstract this, make subc
|
||||
// Figure 1 regarding the lifecycle of started and bound services.
|
||||
mRingtoneCallback.onAutoSilence();
|
||||
}
|
||||
stopSelf();
|
||||
}
|
||||
};
|
||||
private final IBinder mBinder = new RingtoneBinder();
|
||||
@ -78,6 +77,7 @@ public class RingtoneService extends Service { // TODO: abstract this, make subc
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (mAudioManager == null && mRingtone == null) {
|
||||
Log.d(TAG, "RingtoneService starting");
|
||||
long id = intent.getLongExtra(RingtoneActivity.EXTRA_ITEM_ID, -1);
|
||||
mAlarm = checkNotNull(AlarmsRepository.getInstance(this).getItem(id));
|
||||
// TODO: The below call requires a notification, and there is no way to provide one suitable
|
||||
@ -145,10 +145,19 @@ public class RingtoneService extends Service { // TODO: abstract this, make subc
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
public void playRingtone() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public void setRingtoneCallback(RingtoneCallback callback) {
|
||||
mRingtoneCallback = callback;
|
||||
}
|
||||
|
||||
public void onNewActivity() {
|
||||
mAutoSilenced = true;
|
||||
//stopSelf();
|
||||
}
|
||||
|
||||
// Needed so clients can get the Service instance and e.g. call setRingtoneCallback().
|
||||
public class RingtoneBinder extends Binder {
|
||||
RingtoneService getService() {
|
||||
@ -166,6 +175,6 @@ public class RingtoneService extends Service { // TODO: abstract this, make subc
|
||||
/*int minutes = Integer.parseInt(pref.getString(
|
||||
getString(R.string.key_silence_after),
|
||||
"15"));*/
|
||||
mSilenceHandler.postDelayed(mSilenceRunnable, 20000);
|
||||
//mSilenceHandler.postDelayed(mSilenceRunnable, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user