1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| package com.bibi.chuut;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
public class alarme_repetitive extends alarme{
protected long interval_defaut = AlarmManager.INTERVAL_DAY;
protected boolean inexact_defaut = false;
long intervale;
boolean inexact;
public long getintervale() {
return intervale;
}
public void setintervale(long _intervale) {
this.intervale = _intervale;
}
public boolean getinexact() {
return inexact;
}
public void setinexact(boolean _inexact) {
this.inexact = _inexact;
}
public alarme_repetitive(String _nom) {
super(_nom);
this.intervale = interval_defaut;
this.inexact = inexact_defaut;
}
public alarme_repetitive(String _nom, boolean _inexact, long _intervale,Context context) {
super(_nom);
this.intervale=_intervale;
this.inexact = _inexact;
this.intent = new Intent(context,alarme_action.class);
this.type = type_defaut;
this.intent.setAction(type);
}
public void activer(Context context)
{
this.active = true;
this.intent.setAction(type);
this.pending_intent = PendingIntent.getBroadcast(context, 0, this.intent, 0);
if(!this.inexact)
{
setRepeating(context);
}
else
{
setInexactRepeating(context);
}
enregistrement(context);
}
private void setRepeating(Context context)
{
this.alarme_manager.setRepeating(AlarmManager.RTC_WAKEUP, this.date.getTimeInMillis(), this.intervale, this.pending_intent);
}
private void setInexactRepeating(Context context)
{
this.alarme_manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, this.date.getTimeInMillis(), this.intervale, this.pending_intent);
}
protected void enregistrement(Context context)
{
SharedPreferences donnees = context.getSharedPreferences(this.nom, Activity.MODE_PRIVATE);
SharedPreferences.Editor ecriture = donnees.edit();
ecriture.putString("nom", this.nom);
ecriture.putString("type", this.type);
ecriture.putLong("date", this.date.getTimeInMillis());
ecriture.putBoolean("active", this.active);
ecriture.putLong("intervale", this.intervale);
ecriture.putBoolean("inexact", this.inexact);
ecriture.apply();
}
public void recupereration(Context context)
{
SharedPreferences donnees = context.getSharedPreferences(this.nom, Activity.MODE_PRIVATE);
this.nom = donnees.getString("nom", "faux nom");
this.type = donnees.getString("type", this.type_defaut);
this.date.setTimeInMillis(donnees.getLong("date", 0));
this.active = donnees.getBoolean("active", this.active_defaut);
this.intervale = donnees.getLong("intervale", this.interval_defaut);
this.inexact = donnees.getBoolean("inexact", this.inexact_defaut);
}
} |
Partager