From b7e9f63e1079981ddcd967a2ccb253ae2e116025 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sun, 29 Mar 2015 20:56:00 +0200 Subject: [PATCH] Use nrz-androidlib for common code. Use NrzSettingsActivity from nrz-androidlib as a parent of SettingsActivity Remove OcSMSNotification and use NrzNotification instead --- AndroidManifest.xml | 4 +- project.properties | 2 +- .../activities/GeneralSettingsActivity.java | 164 ++---------------- .../enums/OCSMSNotificationType.java | 2 +- .../notifications/OCSMSNotification.java | 57 ------ .../OCSMSNotificationManager.java | 61 +++---- 6 files changed, 53 insertions(+), 237 deletions(-) delete mode 100644 src/fr/unix_experience/owncloud_sms/notifications/OCSMSNotification.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index dd21ef1..ce1efa5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="26" + android:versionName="0.18.2"> = Configuration.SCREENLAYOUT_SIZE_XLARGE; - } - - /** - * Determines whether the simplified settings UI should be shown. This is - * true if this is forced via {@link #ALWAYS_SIMPLE_PREFS}, or the device - * doesn't have newer APIs like {@link PreferenceFragment}, or the device - * doesn't have an extra-large screen. In these cases, a single-pane - * "simplified" settings UI should be shown. - */ - private static boolean isSimplePreferences(final Context context) { - return ALWAYS_SIMPLE_PREFS - || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB - || !isXLargeTablet(context); } /** @@ -123,7 +70,7 @@ public class GeneralSettingsActivity extends PreferenceActivity { .setSummary(index >= 0 ? listPreference.getEntries()[index] : null); - final Account[] myAccountList = mAccountMgr.getAccountsByType(mAccountType); + final Account[] myAccountList = _accountMgr.getAccountsByType(_accountType); // Handle sync frequency change if (prefKey.equals("sync_frequency")) { @@ -132,7 +79,7 @@ public class GeneralSettingsActivity extends PreferenceActivity { // Get ownCloud SMS account list for (int i = 0; i < myAccountList.length; i++) { // And get all authorities for this account - final List syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], mAccountAuthority); + final List syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], _accountAuthority); boolean foundSameSyncCycle = false; for (int j = 0; j < syncList.size(); j++) { @@ -148,42 +95,12 @@ public class GeneralSettingsActivity extends PreferenceActivity { b.putInt("synctype", 1); ContentResolver.removePeriodicSync(myAccountList[i], - mAccountAuthority, b); + _accountAuthority, b); ContentResolver.addPeriodicSync(myAccountList[i], - mAccountAuthority, b, syncFreq * 60); + _accountAuthority, b, syncFreq * 60); } } } - // Slow Sync frequency - /*else if (prefKey.equals(new String("slow_sync_frequency"))) { - long syncFreq = Long.parseLong((String)value); - - // Get ownCloud SMS account list - Account[] myAccountList = mAccountMgr.getAccountsByType(mAccountType); - for (int i = 0; i < myAccountList.length; i++) { - // And get all authorities for this account - List syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], mSlowSyncAccountAuthority); - - boolean foundSameSyncCycle = false; - for (int j = 0; j < syncList.size(); j++) { - PeriodicSync ps = syncList.get(i); - - if (ps.period == syncFreq && ps.extras.getInt("synctype") == 2) { - foundSameSyncCycle = true; - } - } - - if (foundSameSyncCycle == false) { - Bundle b = new Bundle(); - b.putInt("synctype", 2); - - ContentResolver.removePeriodicSync(myAccountList[i], - mSlowSyncAccountAuthority, b); - ContentResolver.addPeriodicSync(myAccountList[i], - mSlowSyncAccountAuthority, b, syncFreq * 60); - } - } - }*/ } else if (preference instanceof CheckBoxPreference) { final String prefKey = preference.getKey(); final Boolean boolValue = (Boolean)value; @@ -192,7 +109,7 @@ public class GeneralSettingsActivity extends PreferenceActivity { prefKey.equals(new String("sync_3g")) || prefKey.equals("sync_gprs") || prefKey.equals("sync_4g") || prefKey.equals("sync_others")) { - final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(mContext); + final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context); prefs.putBoolean(prefKey, boolValue); } } else { @@ -204,49 +121,6 @@ public class GeneralSettingsActivity extends PreferenceActivity { } }; - /** - * Binds a preference's summary to its value. More specifically, when the - * preference's value is changed, its summary (line of text below the - * preference title) is updated to reflect the value. The summary is also - * immediately updated upon calling this method. The exact display format is - * dependent on the type of preference. - * - * @see #sBindPreferenceSummaryToValueListener - */ - private static void bindPreferenceBooleanToValue(final Preference preference, final Boolean defValue) { - // Set the listener to watch for value changes. - preference - .setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); - - // Trigger the listener immediately with the preference's - // current value. - sBindPreferenceSummaryToValueListener.onPreferenceChange( - preference, - PreferenceManager.getDefaultSharedPreferences( - preference.getContext()).getBoolean( - preference.getKey(), - defValue - ) - ); - } - - private static void bindPreferenceStringToValue(final Preference preference) { - // Set the listener to watch for value changes. - preference - .setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); - - // Trigger the listener immediately with the preference's - // current value. - sBindPreferenceSummaryToValueListener.onPreferenceChange( - preference, - PreferenceManager.getDefaultSharedPreferences( - preference.getContext()).getString( - preference.getKey(), - "" - ) - ); - } - /** * This fragment shows data and sync preferences only. It is used when the * activity is showing a two-pane settings UI. @@ -256,7 +130,7 @@ public class GeneralSettingsActivity extends PreferenceActivity { @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_data_sync); + addPreferencesFromResource(_prefsRessourceFile); // Bind the summaries of EditText/List/Dialog/Ringtone preferences // to their values. When their values change, their summaries are @@ -269,13 +143,11 @@ public class GeneralSettingsActivity extends PreferenceActivity { bindPreferenceBooleanToValue(findPreference("sync_gprs"), DefaultPrefs.syncGPRS); bindPreferenceBooleanToValue(findPreference("sync_2g"), DefaultPrefs.sync2G); bindPreferenceBooleanToValue(findPreference("sync_others"), DefaultPrefs.syncOthers); - //bindPreferenceSummaryToValue(findPreference("slow_sync_frequency")); } } - private void bindPreferences() { - mContext = getBaseContext(); - + @Override + protected void bindPreferences() { // Bind the summaries of EditText/List/Dialog/Ringtone preferences to // their values. When their values change, their summaries are updated // to reflect the new value, per the Android Design guidelines. diff --git a/src/fr/unix_experience/owncloud_sms/enums/OCSMSNotificationType.java b/src/fr/unix_experience/owncloud_sms/enums/OCSMSNotificationType.java index 67e86e6..bf9be53 100644 --- a/src/fr/unix_experience/owncloud_sms/enums/OCSMSNotificationType.java +++ b/src/fr/unix_experience/owncloud_sms/enums/OCSMSNotificationType.java @@ -12,7 +12,7 @@ package fr.unix_experience.owncloud_sms.enums; * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ diff --git a/src/fr/unix_experience/owncloud_sms/notifications/OCSMSNotification.java b/src/fr/unix_experience/owncloud_sms/notifications/OCSMSNotification.java deleted file mode 100644 index 2af5bff..0000000 --- a/src/fr/unix_experience/owncloud_sms/notifications/OCSMSNotification.java +++ /dev/null @@ -1,57 +0,0 @@ -package fr.unix_experience.owncloud_sms.notifications; - -/* - * Copyright (c) 2014-2015, Loic Blot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import fr.unix_experience.owncloud_sms.R; -import fr.unix_experience.owncloud_sms.enums.OCSMSNotificationType; -import android.annotation.TargetApi; -import android.app.Notification; -import android.app.Notification.Builder; -import android.app.NotificationManager; -import android.content.Context; -import android.os.Build; - -public class OCSMSNotification { - public OCSMSNotification(Context ct) { - _ct = ct; - } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - public boolean createNotify(OCSMSNotificationType nType, String nTitle, String nText) { - if (_ct == null) { - return false; - } - NotificationManager notificationManager = (NotificationManager)_ct.getSystemService(Context.NOTIFICATION_SERVICE); - - Builder mBuilder = new Notification.Builder(_ct) - .setContentText(nText) - .setContentTitle(nTitle) - .setSmallIcon(R.drawable.ic_launcher); - - notificationManager.notify(nType.ordinal(), mBuilder.build()); - return true; - } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - public void cancelNotify(OCSMSNotificationType nType) { - NotificationManager notificationManager = (NotificationManager)_ct.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.cancel(nType.ordinal()); - } - - private Context _ct; -} diff --git a/src/fr/unix_experience/owncloud_sms/notifications/OCSMSNotificationManager.java b/src/fr/unix_experience/owncloud_sms/notifications/OCSMSNotificationManager.java index ea7fb33..aad25ab 100644 --- a/src/fr/unix_experience/owncloud_sms/notifications/OCSMSNotificationManager.java +++ b/src/fr/unix_experience/owncloud_sms/notifications/OCSMSNotificationManager.java @@ -12,55 +12,56 @@ package fr.unix_experience.owncloud_sms.notifications; * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +import android.content.Context; +import fr.nrz.androidlib.notifications.NrzNotification; import fr.unix_experience.owncloud_sms.R; import fr.unix_experience.owncloud_sms.enums.OCSMSNotificationType; -import android.content.Context; public class OCSMSNotificationManager { - public OCSMSNotificationManager(Context context) { + public OCSMSNotificationManager(final Context context) { _context = context; - _notification = new OCSMSNotification(_context); + _notification = new NrzNotification(_context, R.drawable.ic_launcher); } public void setSyncProcessMsg() { - createNotificationIfPossible(OCSMSNotificationType.SYNC, - _context.getString(R.string.sync_title), - _context.getString(R.string.sync_inprogress) - ); + createNotificationIfPossible(OCSMSNotificationType.SYNC, + _context.getString(R.string.sync_title), + _context.getString(R.string.sync_inprogress) + ); } - + public void dropSyncProcessMsg() { - _notification.cancelNotify(OCSMSNotificationType.SYNC); + _notification.cancelNotify(OCSMSNotificationType.SYNC.ordinal()); } - - public void setSyncErrorMsg(String errMsg) { - createNotificationIfPossible(OCSMSNotificationType.SYNC_FAILED, - _context.getString(R.string.sync_title), - _context.getString(R.string.fatal_error) + "\n" + errMsg - ); + + public void setSyncErrorMsg(final String errMsg) { + createNotificationIfPossible(OCSMSNotificationType.SYNC_FAILED, + _context.getString(R.string.sync_title), + _context.getString(R.string.fatal_error) + "\n" + errMsg + ); } - + public void dropSyncErrorMsg() { - _notification.cancelNotify(OCSMSNotificationType.SYNC_FAILED); + _notification.cancelNotify(OCSMSNotificationType.SYNC_FAILED.ordinal()); } - - public void setDebugMsg(String errMsg) { - createNotificationIfPossible(OCSMSNotificationType.DEBUG, - "DEBUG", errMsg - ); + + public void setDebugMsg(final String errMsg) { + createNotificationIfPossible(OCSMSNotificationType.DEBUG, + "DEBUG", errMsg + ); } - - private void createNotificationIfPossible(OCSMSNotificationType nType, String nTitle, String nMsg) { - _notification.createNotify(nType, nTitle, nMsg); + + private void createNotificationIfPossible(final OCSMSNotificationType nType, final String nTitle, final String nMsg) { + _notification.createNotify(nType.ordinal(), nTitle, nMsg); } - - private Context _context; - private OCSMSNotification _notification; - + + private final Context _context; + private final NrzNotification _notification; + }