Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Notificações completamente funcionais
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Ponces committed Jul 6, 2015
1 parent b351cbd commit aaff347
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

18 changes: 1 addition & 17 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions CalendarioCoco2.iml → CalendarioCoco.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="CalendarioCoco2" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id="CalendarioCoco" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
Expand All @@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
10 changes: 5 additions & 5 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="CalendarioCoco2" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="CalendarioCoco" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -92,12 +92,12 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="design-22.2.0" level="project" />
<orderEntry type="library" exported="" name="material-calendarview-0.4.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="design-22.2.0" level="project" />
<orderEntry type="library" exported="" name="material-calendarview-0.4.0" level="project" />
</component>
</module>
5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -32,9 +31,7 @@
android:name=".CalendarViewActivity"
android:label="@string/title_activity_calendar_view" >
</activity>
<receiver android:name=".AlarmReceiver"
android:enabled="true"
android:exported="false" >
<receiver android:name=".AlarmReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,27 @@ public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = sharedPreferences.getBoolean("switch_notifications", true);
if(enabled) {
showNotification();
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
c.set(java.util.Calendar.HOUR_OF_DAY, 8);
c.set(java.util.Calendar.MINUTE, 0);
c.set(java.util.Calendar.SECOND, 0);
long timeChosen = PreferenceManager.getDefaultSharedPreferences(context)
.getLong("notification_hour", c.getTimeInMillis());c.setTimeInMillis(timeChosen);
.getLong("notification_hour", c.getTimeInMillis());
c.setTimeInMillis(timeChosen);
if(java.util.Calendar.getInstance().get(java.util.Calendar.HOUR_OF_DAY) > c.get(java.util.Calendar.HOUR_OF_DAY)) {
timeChosen += 24 * 60 * 60 * 1000;
} else {
if(java.util.Calendar.getInstance().get(java.util.Calendar.MINUTE) > c.get(java.util.Calendar.MINUTE)) {
timeChosen += 24 * 60 * 60 * 1000;
}
}
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, timeChosen, 24 * 60 * 60 * 1000,
PendingIntent.getBroadcast(context, 0, new Intent(context, AlarmReceiver.class), 0));
} else {
showNotification();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@
*/
public class TimePreference extends DialogPreference {

private Context context;
private java.util.Calendar calendar;
private TimePicker picker = null;

public TimePreference(Context ctxt) {
this(ctxt, null);
this.context = ctxt;
}

public TimePreference(Context ctxt, AttributeSet attrs) {
this(ctxt, attrs, android.R.attr.dialogPreferenceStyle);
this.context = ctxt;
}

public TimePreference(Context ctxt, AttributeSet attrs, int defStyle) {
super(ctxt, attrs, defStyle);
this.context = ctxt;
setPositiveButtonText(R.string.ok);
setNegativeButtonText(R.string.cancel);
calendar = new GregorianCalendar();
Expand Down Expand Up @@ -114,19 +110,23 @@ public void createNotification() {
c.set(java.util.Calendar.HOUR_OF_DAY, 8);
c.set(java.util.Calendar.MINUTE, 0);
c.set(java.util.Calendar.SECOND, 0);
long timeChosen = PreferenceManager.getDefaultSharedPreferences(context)
long timeChosen = PreferenceManager.getDefaultSharedPreferences(getContext())
.getLong("notification_hour", c.getTimeInMillis());
c.setTimeInMillis(timeChosen);
if(java.util.Calendar.getInstance().get(java.util.Calendar.HOUR_OF_DAY) > c.get(java.util.Calendar.HOUR_OF_DAY)) {
timeChosen += 24 * 60 * 60 * 1000;
} else {
if(java.util.Calendar.getInstance().get(java.util.Calendar.MINUTE) > c.get(java.util.Calendar.MINUTE)) {
timeChosen += 24 * 60 * 60 * 1000;
}
}
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, timeChosen, 24 * 60 * 60 * 1000,
PendingIntent.getBroadcast(context, 0, new Intent(context, AlarmReceiver.class), 0));
PendingIntent.getBroadcast(getContext(), 0, new Intent(getContext(), AlarmReceiver.class), 0));
}

public void cancelNotification() {
AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
am.cancel(PendingIntent.getBroadcast(context, 0, new Intent(context, AlarmReceiver.class), 0));
AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
am.cancel(PendingIntent.getBroadcast(getContext(), 0, new Intent(getContext(), AlarmReceiver.class), 0));
}
}

0 comments on commit aaff347

Please sign in to comment.