Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from TheAndroidMaster/develop
Browse files Browse the repository at this point in the history
Version 0.5
  • Loading branch information
fennifith authored Oct 2, 2018
2 parents 3b2431c + 9e40aba commit 807876f
Show file tree
Hide file tree
Showing 15 changed files with 492 additions and 186 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "james.alarmio"
minSdkVersion 16
targetSdkVersion 28
versionCode 5
versionName "0.4"
versionCode 6
versionName "0.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".Alarmio"
Expand Down
184 changes: 65 additions & 119 deletions app/src/main/java/james/alarmio/activities/AlarmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.aesthetic.Aesthetic;
import com.afollestad.aesthetic.AestheticActivity;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.Date;
import java.util.concurrent.TimeUnit;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import james.alarmio.Alarmio;
Expand All @@ -39,26 +37,21 @@
import james.alarmio.services.SleepReminderService;
import james.alarmio.utils.FormatUtils;
import james.alarmio.utils.ImageUtils;
import james.alarmio.views.SlideActionView;

public class AlarmActivity extends AestheticActivity implements View.OnTouchListener {
public class AlarmActivity extends AestheticActivity implements SlideActionView.SlideActionListener {

public static final String EXTRA_ALARM = "james.alarmio.AlarmActivity.EXTRA_ALARM";
public static final String EXTRA_TIMER = "james.alarmio.AlarmActivity.EXTRA_TIMER";

private View overlay;
private TextView date;
private TextView time;
private ImageView snooze;
private ImageView dismiss;
private FloatingActionButton fab;
private SlideActionView actionView;

private Alarmio alarmio;
private Vibrator vibrator;

private boolean snoozeSelected;
private boolean dismissSelected;
private float firstX;

private boolean isAlarm;
private long triggerMillis;
private AlarmData alarm;
Expand All @@ -74,7 +67,6 @@ public class AlarmActivity extends AestheticActivity implements View.OnTouchList
private boolean isWoken;
private PowerManager.WakeLock wakeLock;

private Disposable textColorPrimarySubscription;
private Disposable textColorPrimaryInverseSubscription;
private Disposable isDarkSubscription;

Expand All @@ -89,19 +81,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
overlay = findViewById(R.id.overlay);
date = findViewById(R.id.date);
time = findViewById(R.id.time);
snooze = findViewById(R.id.snooze);
dismiss = findViewById(R.id.dismiss);
fab = findViewById(R.id.fab);

textColorPrimarySubscription = Aesthetic.Companion.get()
.textColorPrimary()
.subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
snooze.setColorFilter(integer);
dismiss.setColorFilter(integer);
}
});
actionView = findViewById(R.id.slideView);

textColorPrimaryInverseSubscription = Aesthetic.Companion.get()
.textColorPrimaryInverse()
Expand All @@ -121,14 +101,9 @@ public void accept(Boolean aBoolean) throws Exception {
}
});

fab.setOnTouchListener(this);
fab.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
firstX = fab.getX();
fab.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
actionView.setLeftImage(VectorDrawableCompat.create(getResources(), R.drawable.ic_snooze, getTheme()));
actionView.setRightImage(VectorDrawableCompat.create(getResources(), R.drawable.ic_close, getTheme()));
actionView.setListener(this);

isSlowWake = PreferenceData.SLOW_WAKE_UP.getValue(this);
slowWakeMillis = TimeUnit.MINUTES.toMillis((int) PreferenceData.SLOW_WAKE_UP_TIME.getValue(this));
Expand Down Expand Up @@ -202,8 +177,7 @@ public void onAttachedToWindow() {
@Override
protected void onDestroy() {
super.onDestroy();
if (textColorPrimarySubscription != null && textColorPrimaryInverseSubscription != null && isDarkSubscription != null) {
textColorPrimarySubscription.dispose();
if (textColorPrimaryInverseSubscription != null && isDarkSubscription != null) {
textColorPrimaryInverseSubscription.dispose();
isDarkSubscription.dispose();
}
Expand All @@ -226,93 +200,65 @@ protected void onNewIntent(Intent intent) {
}

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
snooze.setVisibility(View.VISIBLE);
dismiss.setVisibility(View.VISIBLE);
return true;
case MotionEvent.ACTION_MOVE:
float x = motionEvent.getRawX() - (view.getWidth() / 2);
view.setX(x);
boolean snoozeSelected = x <= snooze.getX() + snooze.getWidth();
boolean dismissSelected = x >= dismiss.getX() - dismiss.getWidth();
if (snoozeSelected != this.snoozeSelected || dismissSelected != this.dismissSelected) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
this.snoozeSelected = snoozeSelected;
this.dismissSelected = dismissSelected;
snooze.setPressed(snoozeSelected);
dismiss.setPressed(dismissSelected);
}
break;
case MotionEvent.ACTION_UP:
view.animate().x(firstX).start();
snooze.setVisibility(View.INVISIBLE);
dismiss.setVisibility(View.INVISIBLE);
if (this.snoozeSelected) {
snooze.setPressed(false);

final int[] minutes = new int[]{2, 5, 10, 20, 30, 60};
CharSequence[] names = new CharSequence[minutes.length + 1];
for (int i = 0; i < minutes.length; i++) {
names[i] = FormatUtils.formatUnit(AlarmActivity.this, minutes[i]);
}
public void onSlideLeft() {
final int[] minutes = new int[]{2, 5, 10, 20, 30, 60};
CharSequence[] names = new CharSequence[minutes.length + 1];
for (int i = 0; i < minutes.length; i++) {
names[i] = FormatUtils.formatUnit(AlarmActivity.this, minutes[i]);
}

names[minutes.length] = getString(R.string.title_snooze_custom);
names[minutes.length] = getString(R.string.title_snooze_custom);

stopAnnoyingness();
new AlertDialog.Builder(AlarmActivity.this, isDark ? R.style.Theme_AppCompat_Dialog_Alert : R.style.Theme_AppCompat_Light_Dialog_Alert)
.setItems(names, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which < minutes.length) {
TimerData timer = alarmio.newTimer();
timer.setDuration(TimeUnit.MINUTES.toMillis(minutes[which]), alarmio);
timer.setVibrate(AlarmActivity.this, isVibrate);
timer.setSound(AlarmActivity.this, sound);
timer.set(alarmio, ((AlarmManager) AlarmActivity.this.getSystemService(Context.ALARM_SERVICE)));
alarmio.onTimerStarted();

finish();
} else {
TimeChooserDialog timerDialog = new TimeChooserDialog(AlarmActivity.this);
timerDialog.setListener(new TimeChooserDialog.OnTimeChosenListener() {
@Override
public void onTimeChosen(int hours, int minutes, int seconds) {
TimerData timer = alarmio.newTimer();
timer.setVibrate(AlarmActivity.this, isVibrate);
timer.setSound(AlarmActivity.this, sound);
timer.setDuration(TimeUnit.HOURS.toMillis(hours)
+ TimeUnit.MINUTES.toMillis(minutes)
+ TimeUnit.SECONDS.toMillis(seconds),
alarmio);

timer.set(alarmio, ((AlarmManager) getSystemService(Context.ALARM_SERVICE)));
alarmio.onTimerStarted();
finish();
}
});
timerDialog.show();
}
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
stopAnnoyingness();
new AlertDialog.Builder(AlarmActivity.this, isDark ? R.style.Theme_AppCompat_Dialog_Alert : R.style.Theme_AppCompat_Light_Dialog_Alert)
.setItems(names, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which < minutes.length) {
TimerData timer = alarmio.newTimer();
timer.setDuration(TimeUnit.MINUTES.toMillis(minutes[which]), alarmio);
timer.setVibrate(AlarmActivity.this, isVibrate);
timer.setSound(AlarmActivity.this, sound);
timer.set(alarmio, ((AlarmManager) AlarmActivity.this.getSystemService(Context.ALARM_SERVICE)));
alarmio.onTimerStarted();

finish();
} else {
TimeChooserDialog timerDialog = new TimeChooserDialog(AlarmActivity.this);
timerDialog.setListener(new TimeChooserDialog.OnTimeChosenListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
public void onTimeChosen(int hours, int minutes, int seconds) {
TimerData timer = alarmio.newTimer();
timer.setVibrate(AlarmActivity.this, isVibrate);
timer.setSound(AlarmActivity.this, sound);
timer.setDuration(TimeUnit.HOURS.toMillis(hours)
+ TimeUnit.MINUTES.toMillis(minutes)
+ TimeUnit.SECONDS.toMillis(seconds),
alarmio);

timer.set(alarmio, ((AlarmManager) getSystemService(Context.ALARM_SERVICE)));
alarmio.onTimerStarted();
finish();
}
})
.show();

view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
} else if (this.dismissSelected) {
dismiss.setPressed(false);
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
finish();
}
break;
}
return false;
});
timerDialog.show();
}
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();

overlay.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}

@Override
public void onSlideRight() {
overlay.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,4 @@ public ViewHolder(View v) {
}
}

public interface OnClickListener {
void onClick(String timeZone);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -73,4 +75,11 @@ public void onClick(View v) {
});
}

@Override
public void show() {
super.show();
Window window = getWindow();
if (window != null)
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
}
}
17 changes: 14 additions & 3 deletions app/src/main/java/james/alarmio/fragments/HomeFragment.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package james.alarmio.fragments;

import android.Manifest;
import android.app.AlarmManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
Expand All @@ -27,6 +29,7 @@
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import jahirfiquitiva.libs.fabsmenu.FABsMenu;
import jahirfiquitiva.libs.fabsmenu.FABsMenuListener;
import jahirfiquitiva.libs.fabsmenu.TitleFAB;
import james.alarmio.Alarmio;
import james.alarmio.R;
Expand Down Expand Up @@ -217,8 +220,6 @@ public void onClick(View view) {
timerFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewPager.setCurrentItem(0, false);

new TimerDialog(getContext(), getFragmentManager()).show();
menu.collapse();
}
Expand All @@ -227,7 +228,6 @@ public void onClick(View view) {
alarmFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewPager.setCurrentItem(0, false);
new AestheticTimeSheetPickerDialog(view.getContext())
.setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {
@Override
Expand All @@ -251,6 +251,17 @@ public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
}
});

menu.setMenuListener(new FABsMenuListener() {
@Override
public void onMenuExpanded(FABsMenu fabsMenu) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.FOREGROUND_SERVICE) != PackageManager.PERMISSION_GRANTED)
requestPermissions(new String[]{Manifest.permission.FOREGROUND_SERVICE}, 0);
else fabsMenu.collapseImmediately();
}
}
});

return view;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package james.alarmio.services;

import android.Manifest;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.IBinder;
import android.os.PowerManager;
Expand All @@ -18,6 +20,7 @@

import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import james.alarmio.Alarmio;
import james.alarmio.R;
import james.alarmio.data.AlarmData;
Expand Down Expand Up @@ -136,6 +139,9 @@ public IBinder onBind(Intent intent) {
* unexpectedly leaped forwards.
*/
public static void refreshSleepTime(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ContextCompat.checkSelfPermission(context, Manifest.permission.FOREGROUND_SERVICE) != PackageManager.PERMISSION_GRANTED)
return;

Alarmio alarmio;
if (context instanceof Alarmio)
alarmio = (Alarmio) context;
Expand Down
Loading

0 comments on commit 807876f

Please sign in to comment.