Browse Source

DialogAlert

pull/1/head
Samuel Vermeulen 5 months ago
parent
commit
112b2417d1
  1. 2
      .idea/misc.xml
  2. 33
      app/src/main/java/fr/svpro/radiomercure/MainActivity.java
  3. 5
      app/src/main/res/layout/activity_main.xml
  4. 11
      app/src/main/res/values/strings.xml

2
.idea/misc.xml

@ -5,7 +5,7 @@
<map>
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/drawable/ic_launcher_background.xml" value="0.2355" />
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/layout/about_dialog.xml" value="0.2" />
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/layout/activity_main.xml" value="0.5" />
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/layout/activity_main.xml" value="0.1755050505050505" />
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/menu/option.xml" value="0.33" />
</map>
</option>

33
app/src/main/java/fr/svpro/radiomercure/MainActivity.java

@ -2,10 +2,12 @@ package fr.svpro.radiomercure;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DownloadManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
@ -54,14 +56,33 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Réglage de l'app battery non optimisée par l'utilisateur
//Demande d'autorisation de désactiver l'optimisation de la batterie
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.dialog_battery_msg)
.setTitle(R.string.dialog_battery_titre);
builder.setPositiveButton(R.string.dialog_button_oui, (dialog12, id) -> {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
//intent.setData(Uri.parse("package:"+ getApplicationInfo().packageName));
startActivity(intent);
});
builder.setNegativeButton(R.string.dialog_button_non, (dialog1, id) -> {
// User cancelled the dialog
Toast.makeText(this, "Annulation par l'utilisateur", Toast.LENGTH_SHORT).show();
});
AlertDialog alertDialog = builder.create();
PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent();
if (!powerManager.isIgnoringBatteryOptimizations(getApplication().getPackageName())) {
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
//intent.setData(Uri.parse("package:"+ getApplicationInfo().packageName));
startActivity(intent);
alertDialog.show();
}
}
@ -179,6 +200,7 @@ public class MainActivity extends AppCompatActivity {
return true;
case R.id.about:
dialog.show();
return true;
@ -245,6 +267,7 @@ public class MainActivity extends AppCompatActivity {
} else {
onDestroy();
reStart();
;
}
}

5
app/src/main/res/layout/activity_main.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -13,4 +12,4 @@
</WebView>
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>

11
app/src/main/res/values/strings.xml

@ -7,4 +7,15 @@
<string name="menu_about">A Propos...</string>
<string name="dialog_close">Fermer</string>
<string name="dialog_version">RADIO MERCURE - Version </string>
<string name="dialog_battery_msg"><![CDATA[Dans le cadre d\'une utilisation optimiale de RADIO MERCURE en arrière-plan notamment pour la lecture du direct,
il est nécessaire de retirer l\'application de la liste des applications optimisées.
En cliquant sur \"Oui\", la fenêtre \"Optimiser la batterie\" apparaît puis :\n
- Selectionnez \"Tout\"\n
- Recherchez \"Radio Mercure\"\n
- Déchochez\n
- Revenez en arrière jusqu\'à afficher l\'application
]]></string>
<string name="dialog_battery_titre">Désactiver l\'optimisation de la batterie ?</string>
<string name="dialog_button_oui">Oui</string>
<string name="dialog_button_non">Non</string>
</resources>
Loading…
Cancel
Save