Skip to content

Commit

Permalink
Some updates
Browse files Browse the repository at this point in the history
- Update Manifest;
- Update gradle;
- Fix some lint warnings;
- Rewrite some preferences in the SettingsActivity file;
- Delete unnecessary code in the SettingsActivity file;
- Update Readme and screenshot;
- Update the main features in the “About” section and in the first launch message;
- Delete unused strings;
  • Loading branch information
BlackyHawky committed Jun 5, 2024
1 parent 0e87821 commit d3c4c09
Show file tree
Hide file tree
Showing 53 changed files with 322 additions and 302 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Clock is a privacy-conscious open-source clock, based on AOSP Clock.

## Table of Contents

- [Features](#features-)
- [Features](#features)
* [Common Issues](#common-issues)
- [Contributing](#contributing-)
* [Reporting Issues](#reporting-issues)
Expand All @@ -16,7 +16,7 @@ Clock is a privacy-conscious open-source clock, based on AOSP Clock.
- [Screenshots](#screenshots)
- [Credits](#credits)

# Features :
# Features
* Flip and shake action to dismiss/postpone alarm;
* Turn off/postpone the alarm with the power button or volume buttons;
* For Snapdragon phones only, the alarm is triggered when the phone is switched off;
Expand Down Expand Up @@ -94,6 +94,7 @@ Since the app is based on Apache 2.0 licensed AOSP Clock, an [Apache 2.0](LICENS

# Screenshots

<!--suppress CheckImageSize -->
<details>
<summary><b>Click here to see screenshots</b></summary>
<br>
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//file:noinspection GroovyConstructorNamedArguments
apply plugin: 'com.android.application'

android {
Expand Down
139 changes: 67 additions & 72 deletions app/src/main/AndroidManifest.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ public void onUpdate(Context context, AppWidgetManager wm, int[] widgetIds) {
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
private static void registerReceivers(Context context, BroadcastReceiver receiver) {
if (sReceiversRegistered) return;
IntentFilter intentFilter = new IntentFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ public void onUpdate(Context context, AppWidgetManager wm, int[] widgetIds) {
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
private static void registerReceivers(Context context, BroadcastReceiver receiver) {
if (sReceiversRegistered) return;
IntentFilter intentFilter = new IntentFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {
// reading alarms from intent
// PickSelection is started only if there are more than 1 relevant alarm
// so no need to check if alarmsFromIntent is empty
assert alarmsFromIntent != null;
for (Parcelable parcelable : alarmsFromIntent) {
final Alarm alarm = (Alarm) parcelable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import android.os.Looper;
import android.os.Message;

import androidx.annotation.NonNull;

import java.lang.reflect.Method;

/**
Expand Down Expand Up @@ -193,7 +195,7 @@ private Handler getNewHandler() {

return new Handler(thread.getLooper()) {
@Override
public void handleMessage(Message msg) {
public void handleMessage(@NonNull Message msg) {
switch (msg.what) {
case EVENT_PLAY:
final Bundle data = msg.getData();
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/best/deskclock/ClockFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ private CityListOnLongClickListener(Context context) {
}

@Override
public void onLongPress(MotionEvent e) {
public void onLongPress(@NonNull MotionEvent e) {
final View view = getView();
if (view != null) {
view.performLongClick();
}
}

@Override
public boolean onDown(MotionEvent e) {
public boolean onDown(@NonNull MotionEvent e) {
return true;
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/best/deskclock/DeskClock.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ public void run() {
}
}


/**
* As the model reports changes to the selected tab, update the user interface.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.best.deskclock.uidata.UiDataModel;

import java.io.File;
import java.util.Objects;

public class DeskClockApplication extends Application {

Expand Down Expand Up @@ -51,7 +52,7 @@ private static SharedPreferences getDefaultSharedPreferences(Context context) {
storageContext = context.createDeviceProtectedStorageContext();
final String name = context.getPackageName() + "_preferences";
final String prefsFilename = storageContext.getDataDir() + "/shared_prefs/" + name + ".xml";
final File prefs = new File(Uri.parse(prefsFilename).getPath());
final File prefs = new File(Objects.requireNonNull(Uri.parse(prefsFilename).getPath()));

if (!prefs.exists()) {
if (!storageContext.moveSharedPreferencesFrom(context, name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;

/**
* Returns a list of alarms that are specified by the intent
Expand Down Expand Up @@ -63,7 +64,7 @@ public void run() {
final int hour = mIntent.getIntExtra(AlarmClock.EXTRA_HOUR, -1);
// if minutes weren't specified default to 0
final int minutes = mIntent.getIntExtra(AlarmClock.EXTRA_MINUTES, 0);
final Boolean isPm = (Boolean) mIntent.getExtras().get(AlarmClock.EXTRA_IS_PM);
final Boolean isPm = (Boolean) Objects.requireNonNull(mIntent.getExtras()).get(AlarmClock.EXTRA_IS_PM);
boolean badInput = isPm != null && hour > 12 && isPm;
badInput |= hour < 0 || hour > 23;
badInput |= minutes < 0 || minutes > 59;
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/best/deskclock/FirstLaunch.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ public void handleOnBackPressed() {
});
}

@Override
protected void onResume() {
super.onResume();
}

/**
* Automatically sets the application title according to whether it's the debug version or not.
*/
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/best/deskclock/HandleApiCalls.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -509,7 +510,8 @@ private static void updateAlarmFromIntent(Alarm alarm, Intent intent) {
}

private static String getLabelFromIntent(Intent intent, String defaultLabel) {
final String message = intent.getExtras().getString(AlarmClock.EXTRA_MESSAGE, defaultLabel);
final String message = Objects.requireNonNull(
intent.getExtras()).getString(AlarmClock.EXTRA_MESSAGE, defaultLabel);
return message == null ? "" : message;
}

Expand Down
40 changes: 21 additions & 19 deletions app/src/main/java/com/best/deskclock/HandleShortcuts.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,28 @@ protected void onCreate(Bundle savedInstanceState) {

try {
final String action = intent.getAction();
switch (action) {
case StopwatchService.ACTION_PAUSE_STOPWATCH -> {
Events.sendStopwatchEvent(R.string.action_pause, R.string.label_shortcut);

// Open DeskClock positioned on the stopwatch tab.
UiDataModel.getUiDataModel().setSelectedTab(STOPWATCH);
startActivity(new Intent(this, DeskClock.class)
.setAction(StopwatchService.ACTION_PAUSE_STOPWATCH));
setResult(RESULT_OK);
if (action != null) {
switch (action) {
case StopwatchService.ACTION_PAUSE_STOPWATCH -> {
Events.sendStopwatchEvent(R.string.action_pause, R.string.label_shortcut);

// Open DeskClock positioned on the stopwatch tab.
UiDataModel.getUiDataModel().setSelectedTab(STOPWATCH);
startActivity(new Intent(this, DeskClock.class)
.setAction(StopwatchService.ACTION_PAUSE_STOPWATCH));
setResult(RESULT_OK);
}
case StopwatchService.ACTION_START_STOPWATCH -> {
Events.sendStopwatchEvent(R.string.action_start, R.string.label_shortcut);

// Open DeskClock positioned on the stopwatch tab.
UiDataModel.getUiDataModel().setSelectedTab(STOPWATCH);
startActivity(new Intent(this, DeskClock.class)
.setAction(StopwatchService.ACTION_START_STOPWATCH));
setResult(RESULT_OK);
}
default -> throw new IllegalArgumentException("Unsupported action: " + action);
}
case StopwatchService.ACTION_START_STOPWATCH -> {
Events.sendStopwatchEvent(R.string.action_start, R.string.label_shortcut);

// Open DeskClock positioned on the stopwatch tab.
UiDataModel.getUiDataModel().setSelectedTab(STOPWATCH);
startActivity(new Intent(this, DeskClock.class)
.setAction(StopwatchService.ACTION_START_STOPWATCH));
setResult(RESULT_OK);
}
default -> throw new IllegalArgumentException("Unsupported action: " + action);
}
} catch (Exception e) {
LOGGER.e("Error handling intent: " + intent, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.best.deskclock.events.Events;
import com.best.deskclock.uidata.UiDataModel;

import java.util.Objects;

public class ScreensaverActivity extends AppCompatActivity {

private static final LogUtils.Logger LOGGER = new LogUtils.Logger("ScreensaverActivity");
Expand All @@ -47,7 +49,7 @@ public class ScreensaverActivity extends AppCompatActivity {
public void onReceive(Context context, Intent intent) {
LOGGER.v("ScreensaverActivity onReceive, action: " + intent.getAction());

switch (intent.getAction()) {
switch (Objects.requireNonNull(intent.getAction())) {
case Intent.ACTION_POWER_CONNECTED -> updateWakeLock(true);
case Intent.ACTION_POWER_DISCONNECTED -> updateWakeLock(false);
case Intent.ACTION_USER_PRESENT -> finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void setTimeString(long remainingTime) {

String time = Utils.getTimeString(mTextView.getContext(), hours, minutes, seconds);
if (isNegative && !(hours == 0 && minutes == 0 && seconds == 0)) {
time = "\u2212" + time;
time = "" + time;
}

mTextView.setText(time);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/best/deskclock/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static float calculateRadiusOffset(float strokeSize, float dotStrokeSize,

/**
* Configure the clock that is visible to display seconds. The clock that is not visible never
* displays seconds to avoid it scheduling unnecessary ticking runnables.
* displays seconds to avoid it scheduling unnecessary ticking runnable.
*/
public static void setClockSecondsEnabled(TextClock digitalClock, AnalogClock analogClock) {
final boolean displaySeconds = DataModel.getDataModel().getDisplayClockSeconds();
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/best/deskclock/alarms/AlarmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ public void onReceive(Context context, Intent intent) {
LOGGER.v("Received broadcast: %s", action);

if (!mAlarmHandled) {
switch (action) {
case AlarmService.ALARM_SNOOZE_ACTION -> snooze();
case AlarmService.ALARM_DISMISS_ACTION -> dismiss();
case AlarmService.ALARM_DONE_ACTION -> finish();
default -> LOGGER.i("Unknown broadcast: %s", action);
if (action != null) {
switch (action) {
case AlarmService.ALARM_SNOOZE_ACTION -> snooze();
case AlarmService.ALARM_DISMISS_ACTION -> dismiss();
case AlarmService.ALARM_DONE_ACTION -> finish();
default -> LOGGER.i("Unknown broadcast: %s", action);
}
}
} else {
LOGGER.v("Ignored broadcast: %s", action);
Expand Down Expand Up @@ -284,6 +286,7 @@ protected void onCreate(Bundle savedInstanceState) {
mPulseAnimator.start();
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override
protected void onResume() {
super.onResume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static com.best.deskclock.NotificationUtils.FIRING_NOTIFICATION_CHANNEL_ID;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand Down Expand Up @@ -309,6 +310,7 @@ static synchronized void showSnoozeNotification(Context context, AlarmInstance i
updateUpcomingAlarmGroupNotification(context, -1, notification);
}

@SuppressLint("LaunchActivityFromNotification")
static synchronized void showMissedNotification(Context context, AlarmInstance instance) {
LogUtils.v("Displaying missed notification for alarm instance: " + instance.mId);

Expand Down
41 changes: 22 additions & 19 deletions app/src/main/java/com/best/deskclock/alarms/AlarmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.best.deskclock.alarms;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
Expand All @@ -28,6 +29,9 @@
import com.best.deskclock.events.Events;
import com.best.deskclock.provider.AlarmInstance;

import java.util.Arrays;
import java.util.Objects;

/**
* This service is in charge of starting/stopping the alarm. It will bring up and manage the
* {@link AlarmActivity} as well as {@link AlarmKlaxon}.
Expand Down Expand Up @@ -98,18 +102,20 @@ public void onReceive(Context context, Intent intent) {
return;
}

switch (action) {
case ALARM_SNOOZE_ACTION -> {
// Set the alarm state to snoozed.
// If this broadcast receiver is handling the snooze intent then AlarmActivity
// must not be showing, so always show snooze toast.
AlarmStateManager.setSnoozeState(context, mCurrentAlarm, true /* showToast */);
Events.sendAlarmEvent(R.string.action_snooze, R.string.label_intent);
}
case ALARM_DISMISS_ACTION -> {
// Set the alarm state to dismissed.
AlarmStateManager.deleteInstanceAndUpdateParent(context, mCurrentAlarm);
Events.sendAlarmEvent(R.string.action_dismiss, R.string.label_intent);
if (action != null) {
switch (action) {
case ALARM_SNOOZE_ACTION -> {
// Set the alarm state to snoozed.
// If this broadcast receiver is handling the snooze intent then AlarmActivity
// must not be showing, so always show snooze toast.
AlarmStateManager.setSnoozeState(context, mCurrentAlarm, true /* showToast */);
Events.sendAlarmEvent(R.string.action_snooze, R.string.label_intent);
}
case ALARM_DISMISS_ACTION -> {
// Set the alarm state to dismissed.
AlarmStateManager.deleteInstanceAndUpdateParent(context, mCurrentAlarm);
Events.sendAlarmEvent(R.string.action_dismiss, R.string.label_intent);
}
}
}
}
Expand All @@ -136,9 +142,7 @@ public void onAccuracyChanged(Sensor sensor, int acc) {
public void reset() {
mWasFaceUp = false;
mStopped = false;
for (int i = 0; i < SENSOR_SAMPLES; i++) {
mSamples[i] = false;
}
Arrays.fill(mSamples, false);
}

private boolean filterSamples() {
Expand Down Expand Up @@ -168,9 +172,7 @@ public void onSensorChanged(SensorEvent event) {
// face up
if (filterSamples()) {
mWasFaceUp = true;
for (int i = 0; i < SENSOR_SAMPLES; i++) {
mSamples[i] = false;
}
Arrays.fill(mSamples, false);
}
} else {
// Check if its face down enough.
Expand Down Expand Up @@ -285,6 +287,7 @@ private void stopCurrentAlarm() {
AlarmAlertWakeLock.releaseCpuLock();
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override
public void onCreate() {
super.onCreate();
Expand Down Expand Up @@ -314,7 +317,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
}

final long instanceId = AlarmInstance.getId(intent.getData());
switch (intent.getAction()) {
switch (Objects.requireNonNull(intent.getAction())) {
case AlarmStateManager.CHANGE_STATE_ACTION -> {
AlarmStateManager.handleIntent(this, intent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ protected void onBindItemView(final AlarmItemHolder itemHolder) {
}

private void bindEditLabel(Context context, Alarm alarm) {
if (alarm.label.length() == 0) {
if (alarm.label.isEmpty()) {
editLabel.setText(context.getString(R.string.add_label));
editLabel.setTypeface(Typeface.DEFAULT);
editLabel.setAlpha(CLOCK_DISABLED_ALPHA);
} else {
editLabel.setText(alarm.equals(Alarm.getAlarmByLabel(context.getContentResolver(), BedtimeFragment.BEDTIME_LABEL))
? context.getString(R.string.wakeup_alarm_label_visible)
: alarm.label);
editLabel.setContentDescription(alarm.label != null && alarm.label.length() > 0
editLabel.setContentDescription(alarm.label != null && !alarm.label.isEmpty()
? context.getString(R.string.label_description) + " " + alarm.label
: context.getString(R.string.no_label_specified));
editLabel.setTypeface(Typeface.DEFAULT_BOLD);
Expand Down
Loading

0 comments on commit d3c4c09

Please sign in to comment.