Skip to content

Commit

Permalink
Merge pull request #86 from BlythMeister/NotificationSetting
Browse files Browse the repository at this point in the history
Fix for Issue #84 - Custom Notification Timings
  • Loading branch information
Fammy committed Jun 1, 2013
2 parents 15b561a + cc77d29 commit 73c048d
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 37 deletions.
5 changes: 3 additions & 2 deletions android/client/.classpath
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="libs/crittercism_v2_0_1.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="lib" path="libs/android-support-v13.jar"/>
<classpathentry kind="lib" path="libs/android-support-v4.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
24 changes: 24 additions & 0 deletions android/client/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,28 @@
<item>name_username</item>
</string-array>

<string-array name="notificationtime_list_preference">
<item>Never (Manual)</item>
<item>1 Minute</item>
<item>3 Minutes</item>
<item>5 Minutes</item>
<item>15 Minutes</item>
<item>30 Minutes</item>
<item>1 Hour</item>
<item>4 Hours</item>
<item>12 Hours</item>
</string-array>

<string-array name="notificationtimevalues_list_preference">
<item>0m</item>
<item>1m</item>
<item>3m</item>
<item>5m</item>
<item>15m</item>
<item>30m</item>
<item>1h</item>
<item>4h</item>
<item>12h</item>
</string-array>

</resources>
6 changes: 3 additions & 3 deletions android/client/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@

<string name="notification_preferences">Notifications</string>

<string name="show_notifications_preference">Enable Notifications</string>
<string name="summary_show_notifications_preference">Display notifications when you get new mentions</string>

<string name="notification_time_preference">Refresh Interval</string>
<string name="dialog_title_notificationtime_preference">Refresh Interval</string>
<string name="ringtone_preference">Ringtone</string>

<string name="settings_never">Never</string>
Expand Down
14 changes: 9 additions & 5 deletions android/client/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@

<PreferenceCategory
android:title="@string/notification_preferences">

<CheckBoxPreference
android:key="shownotifications_preference"
android:title="@string/show_notifications_preference"
android:summary="@string/summary_show_notifications_preference" />

<ListPreference
android:key="notificationtime_preference"
android:title="@string/notification_time_preference"
android:entries="@array/notificationtime_list_preference"
android:entryValues="@array/notificationtimevalues_list_preference"
android:dialogTitle="@string/dialog_title_notificationtime_preference"
android:defaultValue="0m"
/>

<RingtonePreference android:showDefault="true"
android:key="ringtone_preference"
Expand Down
59 changes: 56 additions & 3 deletions android/client/src/com/tweetlanes/android/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class AppSettings {
public static final boolean DEFAULT_VOLSCROLL = true;
public static final boolean DEFAULT_SHOW_TABLET_MARGIN = true;
public static final boolean DEFAULT_SHOW_TWEET_SOURCE = false;
public static final boolean DEFAULT_SHOW_NOTIFICATIONS = false;

private static final String STATUS_SIZE_EXTRA_SMALL = "Extra Small";
private static final String STATUS_SIZE_SMALL = "Small";
Expand All @@ -50,6 +49,17 @@ public class AppSettings {
public static final String NAME_DISPLAY_NAME = "name";
public static final String NAME_DISPLAY_USERNAME_NAME = "username_name";
public static final String NAME_DISPLAY_NAME_USERNAME = "name_username";

public static final String NOTIFICATION_TIME_0M = "0m";
public static final String NOTIFICATION_TIME_1M = "1m";
public static final String NOTIFICATION_TIME_3M = "3m";
public static final String NOTIFICATION_TIME_5M = "5m";
public static final String NOTIFICATION_TIME_15M = "15m";
public static final String NOTIFICATION_TIME_30M = "30m";
public static final String NOTIFICATION_TIME_1H = "1h";
public static final String NOTIFICATION_TIME_4H = "4h";
public static final String NOTIFICATION_TIME_12H = "12h";
public static final String NOTIFICATION_TIME_DEFAULT = NOTIFICATION_TIME_0M;

/*
*
Expand Down Expand Up @@ -197,8 +207,8 @@ public boolean isVolScrollEnabled() {
}

public boolean isShowNotificationsEnabled() {
return mSharedPreferences.getBoolean(
SettingsActivity.KEY_SHOW_NOTIFICATIONS_PREFERENCE, DEFAULT_SHOW_NOTIFICATIONS);
String notificationTime = mSharedPreferences.getString(SettingsActivity.KEY_NOTIFICATION_TIME_PREFERENCE, NOTIFICATION_TIME_DEFAULT);
return notificationTime.equals(NOTIFICATION_TIME_0M);
}

/*
Expand All @@ -215,6 +225,49 @@ public Uri getRingtoneUri() {
}
return Uri.parse(uri);
}

public long getNotificationTime() {
String notificationTime = mSharedPreferences.getString(SettingsActivity.KEY_NOTIFICATION_TIME_PREFERENCE, NOTIFICATION_TIME_DEFAULT);

//NOTE: This function returns time in Milliseconds.
if (notificationTime.equals(NOTIFICATION_TIME_1M))
{
return 60000;
}
else if (notificationTime.equals(NOTIFICATION_TIME_3M))
{
return 180000;
}
else if (notificationTime.equals(NOTIFICATION_TIME_5M))
{
return 300000;
}
else if (notificationTime.equals(NOTIFICATION_TIME_15M))
{
return 900000;
}
else if (notificationTime.equals(NOTIFICATION_TIME_30M))
{
return 1800000;
}
else if (notificationTime.equals(NOTIFICATION_TIME_1H))
{
return 3600000;
}
else if (notificationTime.equals(NOTIFICATION_TIME_4H))
{
return 14400000;
}
else if (notificationTime.equals(NOTIFICATION_TIME_12H))
{
return 43200000;
}
else
{
return 0;
}

}

/*
*
Expand Down
4 changes: 2 additions & 2 deletions android/client/src/com/tweetlanes/android/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public static void setupNotificationAlarm(Context context) {
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 12345, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager)context.getSystemService(Activity.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, AlarmManager.INTERVAL_FIFTEEN_MINUTES,
AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, AppSettings.get().getNotificationTime(),
AppSettings.get().getNotificationTime(), pendingIntent);
}

public static void cancelNotificationAlarm(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public class SettingsActivity extends PreferenceActivity implements
public static final String KEY_SOURCE_CODE_PREFERENCE = "preference_source";
public static final String KEY_DONATE_PREFERENCE = "preference_donate";
public static final String KEY_VERSION_PREFERENCE = "version_preference";
public static final String KEY_SHOW_NOTIFICATIONS_PREFERENCE = "shownotifications_preference";
public static final String KEY_RINGTONE_PREFERENCE = "ringtone_preference";
public static final String KEY_NOTIFICATION_TIME_PREFERENCE = "notificationtime_preference";

private ListPreference mThemePreference;
private Preference mCustomizeLanesPreference;
Expand All @@ -75,7 +75,7 @@ public class SettingsActivity extends PreferenceActivity implements
private Preference mSourceCodePreference;
private Preference mDonatePreference;
private Preference mVersionPreference;
private CheckBoxPreference mShowNotificationsPreference;
private ListPreference mNotificationTimePreference;

/*
*
Expand Down Expand Up @@ -225,9 +225,9 @@ public void onClick(
mDonatePreference = getPreferenceScreen().findPreference(
KEY_DONATE_PREFERENCE);
mVersionPreference = getPreferenceScreen().findPreference(
KEY_VERSION_PREFERENCE);
mShowNotificationsPreference = (CheckBoxPreference) getPreferenceScreen()
.findPreference(KEY_SHOW_NOTIFICATIONS_PREFERENCE);
KEY_VERSION_PREFERENCE);
mNotificationTimePreference = (ListPreference) getPreferenceScreen()
.findPreference(KEY_NOTIFICATION_TIME_PREFERENCE);
}

/*
Expand Down Expand Up @@ -342,10 +342,11 @@ public boolean onPreferenceClick(Preference preference) {
});

mVersionPreference.setSummary(App.getAppVersionName());

boolean showNotifications = sharedPreferences.getBoolean(
KEY_SHOW_NOTIFICATIONS_PREFERENCE, AppSettings.DEFAULT_SHOW_NOTIFICATIONS);
mShowNotificationsPreference.setChecked(showNotifications);

if (mNotificationTimePreference.getEntry() == null) {
mNotificationTimePreference.setValueIndex(1);
}
mNotificationTimePreference.setSummary(mNotificationTimePreference.getEntry());

getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
Expand Down Expand Up @@ -387,19 +388,13 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
getIntent().addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
overridePendingTransition(0, 0);
startActivity(getIntent());
}else if (listPref == mNotificationTimePreference) {
//Stop and start notifications (with new time)
Notifier.cancelNotificationAlarm(this);
Notifier.setupNotificationAlarm(this);
}
}
if (pref instanceof CheckBoxPreference) {
CheckBoxPreference cbPref = (CheckBoxPreference) pref;
if (cbPref == mShowNotificationsPreference) {
if (cbPref.isChecked()) {
Notifier.setupNotificationAlarm(this);
}
else {
Notifier.cancelNotificationAlarm(this);
}
}
}

}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion android/libraries/SocialNetLib/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="libs/twitter4j-core-3.0.3.jar"/>
<classpathentry kind="lib" path="libs/twitter4j-media-support-3.0.3.jar"/>
<classpathentry kind="src" path="src"/>
Expand Down

0 comments on commit 73c048d

Please sign in to comment.