Skip to content

Instantly share code, notes, and snippets.

@rafaeltoledo
Created November 5, 2019 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaeltoledo/991ec5327b0aa82e8750be7deb8d5081 to your computer and use it in GitHub Desktop.
Save rafaeltoledo/991ec5327b0aa82e8750be7deb8d5081 to your computer and use it in GitHub Desktop.
Android 21
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="listagem"
android:title="Modo de Listagem"
android:summary="Escolha o modo de listagem a ser utilizado"
android:entries="@array/nomes_ordenacao"
android:entryValues="@array/opcoes_ordenacao"
android:dialogTitle="Escolha o modo de listagem" />
<CheckBoxPreference
android:key="alarme"
android:title="Tocar Alarme no Almoço"
android:summary="Marque se deseja ser informado sobre a hora do almoço" />
<net.rafaeltoledo.restaurante.PreferenciaHorario
android:key="horario_alarme"
android:title="Horário do Alarme do Almoço"
android:defaultValue="12:00"
android:summary="Configure seu horário desejado para o alarme"
android:dependency="alarme" />
<CheckBoxPreference
android:key="usar_notificacao"
android:title="Ativar Notifocação"
android:defaultValue="true"
android:summary="Marque caso deseje um ícone na barra de status, ou desmarque para a notificação em tela cheia"
android:dependency="alarme" />
</PreferenceScreen>
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences preferencias = PreferenceManager.getDefaultSharedPreferences(context);
boolean usarNotificacao = preferencias.getBoolean("usar_notificacao", true);
if (usarNotificacao) {
NotificationManager gerenciador = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification nota = new Notification(R.drawable.notificacao, "Hora do Almoço!", System.currentTimeMillis());
PendingIntent i = PendingIntent.getActivity(context, 0, new Intent(context, AlarmeActivity.class), 0);
nota.setLatestEventInfo(context, "Lista de Restaurantes", "Hora do Almoço! Está com fome?", i);
nota.flags |= Notification.FLAG_AUTO_CANCEL;
gerenciador.notify(ID_NOTIFICACAO, nota);
} else {
Intent i = new Intent(context, AlarmeActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment