diff --git a/src/Notesmaster/app/src/main/AndroidManifest.xml b/src/Notesmaster/app/src/main/AndroidManifest.xml index 1315aab..6208b7c 100644 --- a/src/Notesmaster/app/src/main/AndroidManifest.xml +++ b/src/Notesmaster/app/src/main/AndroidManifest.xml @@ -1,29 +1,23 @@ - - - - - - - - - - - - - + + + + + + + + tools:targetApi="31"> + android:exported="true"> - @@ -60,9 +53,8 @@ android:configChanges="keyboardHidden|orientation|screenSize" android:launchMode="singleTop" android:theme="@style/NoteTheme" - android:exported="true"> + android:exported="true"> - @@ -70,7 +62,6 @@ - @@ -78,13 +69,11 @@ - - @@ -94,84 +83,76 @@ + android:multiprocess="true" /> - + + android:exported="true"> - + + - - - + + - + android:process=":remote" + android:exported="true" /> + - + android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar" + android:exported="true" /> + - + android:theme="@android:style/Theme.Holo.Light" + android:exported="true" /> + - + android:exported="false" /> - - - - - - - - - - - - - \ No newline at end of file + diff --git a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java index 85723be..e648f9d 100644 --- a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java +++ b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java @@ -1,29 +1,11 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package net.micode.notes.ui; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.content.DialogInterface.OnDismissListener; import android.content.Intent; -import android.media.AudioManager; +import android.media.AudioAttributes; import android.media.MediaPlayer; import android.media.RingtoneManager; import android.net.Uri; @@ -39,12 +21,11 @@ import net.micode.notes.tool.DataUtils; import java.io.IOException; - -public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { +public class AlarmAlertActivity extends Activity implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener { private long mNoteId; private String mSnippet; private static final int SNIPPET_PREW_MAX_LEN = 60; - MediaPlayer mPlayer; + private MediaPlayer mPlayer; @Override protected void onCreate(Bundle savedInstanceState) { @@ -85,36 +66,25 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD private boolean isScreenOn() { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); - return pm.isScreenOn(); + return pm.isInteractive(); // updated for modern Android } private void playAlarmSound() { Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM); - int silentModeStreams = Settings.System.getInt(getContentResolver(), - Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); - - if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) { - mPlayer.setAudioStreamType(silentModeStreams); - } else { - mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); - } try { + AudioAttributes attributes = new AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .build(); + + mPlayer.setAudioAttributes(attributes); mPlayer.setDataSource(this, url); mPlayer.prepare(); mPlayer.setLooping(true); mPlayer.start(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalStateException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block + } catch (IllegalArgumentException | SecurityException | + IllegalStateException | IOException e) { e.printStackTrace(); } } @@ -130,19 +100,17 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD dialog.show().setOnDismissListener(this); } + @Override public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_NEGATIVE: - Intent intent = new Intent(this, NoteEditActivity.class); - intent.setAction(Intent.ACTION_VIEW); - intent.putExtra(Intent.EXTRA_UID, mNoteId); - startActivity(intent); - break; - default: - break; + if (which == DialogInterface.BUTTON_NEGATIVE) { + Intent intent = new Intent(this, NoteEditActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.putExtra(Intent.EXTRA_UID, mNoteId); + startActivity(intent); } } + @Override public void onDismiss(DialogInterface dialog) { stopAlarmSound(); finish(); diff --git a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java index f221202..ac633e2 100644 --- a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java +++ b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java @@ -1,19 +1,3 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package net.micode.notes.ui; import android.app.AlarmManager; @@ -27,16 +11,15 @@ import android.database.Cursor; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; - public class AlarmInitReceiver extends BroadcastReceiver { - private static final String [] PROJECTION = new String [] { - NoteColumns.ID, - NoteColumns.ALERTED_DATE + private static final String[] PROJECTION = new String[]{ + NoteColumns.ID, + NoteColumns.ALERTED_DATE }; - private static final int COLUMN_ID = 0; - private static final int COLUMN_ALERTED_DATE = 1; + private static final int COLUMN_ID = 0; + private static final int COLUMN_ALERTED_DATE = 1; @Override public void onReceive(Context context, Intent intent) { @@ -44,19 +27,27 @@ public class AlarmInitReceiver extends BroadcastReceiver { Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI, PROJECTION, NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE, - new String[] { String.valueOf(currentDate) }, + new String[]{String.valueOf(currentDate)}, null); if (c != null) { if (c.moveToFirst()) { + AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); do { long alertDate = c.getLong(COLUMN_ALERTED_DATE); Intent sender = new Intent(context, AlarmReceiver.class); sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID))); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0); - AlarmManager alermManager = (AlarmManager) context - .getSystemService(Context.ALARM_SERVICE); - alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); + + PendingIntent pendingIntent = PendingIntent.getBroadcast( + context, + 0, + sender, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE // Updated flags + ); + + if (alarmManager != null) { + alarmManager.setExact(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); // Use setExact + } } while (c.moveToNext()); } c.close(); diff --git a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java index 54e503b..4d96a32 100644 --- a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java +++ b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java @@ -1,19 +1,3 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package net.micode.notes.ui; import android.content.BroadcastReceiver; @@ -24,7 +8,7 @@ public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { intent.setClass(context, AlarmAlertActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(intent); } }