1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-07 16:06:18 +00:00

Re-import nrzAndroidLib, this lib will be deprecated

This commit is contained in:
Loic Blot 2016-03-18 11:39:50 +01:00
parent 42e12a2081
commit 1cced8b2e4
10 changed files with 367 additions and 31 deletions

View File

@ -27,7 +27,6 @@ repositories {
dependencies {
compile project(':owncloudAndroidLibrary')
compile project(':nrzandroidlib')
compile 'com.android.support:support-v13:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'

View File

@ -4,7 +4,7 @@
android:versionCode="34"
android:versionName="0.20.1"> <!-- From Android 4.0 to 6.0 -->
<uses-sdk
android:maxSdkVersion="23"
android:maxSdkVersion="24"
android:minSdkVersion="14"
android:targetSdkVersion="23"/>
@ -95,7 +95,7 @@
android:label="@string/title_activity_select_account">
</activity>
<activity
android:name=".activities.GeneralSettingsActivity"
android:name=".activities.OCSMSSettingsActivity"
android:label="@string/title_activity_general_settings">
</activity>
<activity

View File

@ -100,7 +100,7 @@ public class MainActivity extends AppCompatActivity
}
private boolean openAppSettings () {
startActivity(new Intent(this, GeneralSettingsActivity.class));
startActivity(new Intent(this, OCSMSSettingsActivity.class));
return true;
}

View File

@ -27,13 +27,13 @@ import android.util.Log;
import java.util.List;
import fr.nrz.androidlib.activities.NrzSettingsActivity;
import fr.unix_experience.owncloud_sms.activities.virtual.VirtualSettingsActivity;
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
public class GeneralSettingsActivity extends NrzSettingsActivity {
private static final String TAG = GeneralSettingsActivity.class.getSimpleName();
public class OCSMSSettingsActivity extends VirtualSettingsActivity {
private static final String TAG = OCSMSSettingsActivity.class.getSimpleName();
private static AccountManager _accountMgr;
private static String _accountAuthority;
@ -41,23 +41,23 @@ public class GeneralSettingsActivity extends NrzSettingsActivity {
@Override
protected void onPostCreate(Bundle savedInstanceState) {
GeneralSettingsActivity._accountMgr = AccountManager.get(getBaseContext());
GeneralSettingsActivity._accountAuthority = getString(R.string.account_authority);
GeneralSettingsActivity._accountType = getString(R.string.account_type);
NrzSettingsActivity._prefsRessourceFile = R.xml.pref_data_sync;
_accountMgr = AccountManager.get(getBaseContext());
_accountAuthority = getString(R.string.account_authority);
_accountType = getString(R.string.account_type);
_prefsRessourceFile = R.xml.pref_data_sync;
// Bind our boolean preferences
NrzSettingsActivity._boolPrefs.add(new BindObjectPref("push_on_receive", DefaultPrefs.pushOnReceive));
NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_wifi", DefaultPrefs.syncWifi));
NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_4g", DefaultPrefs.sync4G));
NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_3g", DefaultPrefs.sync3G));
NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_gprs", DefaultPrefs.syncGPRS));
NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_2g", DefaultPrefs.sync2G));
NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_others", DefaultPrefs.syncOthers));
_boolPrefs.add(new BindObjectPref("push_on_receive", DefaultPrefs.pushOnReceive));
_boolPrefs.add(new BindObjectPref("sync_wifi", DefaultPrefs.syncWifi));
_boolPrefs.add(new BindObjectPref("sync_4g", DefaultPrefs.sync4G));
_boolPrefs.add(new BindObjectPref("sync_3g", DefaultPrefs.sync3G));
_boolPrefs.add(new BindObjectPref("sync_gprs", DefaultPrefs.syncGPRS));
_boolPrefs.add(new BindObjectPref("sync_2g", DefaultPrefs.sync2G));
_boolPrefs.add(new BindObjectPref("sync_others", DefaultPrefs.syncOthers));
// Bind our string preferences
NrzSettingsActivity._stringPrefs.add(new BindObjectPref("sync_frequency", "15"));
NrzSettingsActivity._stringPrefs.add(new BindObjectPref("sync_bulk_messages", "-1"));
_stringPrefs.add(new BindObjectPref("sync_frequency", "15"));
_stringPrefs.add(new BindObjectPref("sync_bulk_messages", "-1"));
// Must be at the end, after preference bind
super.onPostCreate(savedInstanceState);
@ -69,8 +69,8 @@ public class GeneralSettingsActivity extends NrzSettingsActivity {
"sync_wifi".equals(key) || "sync_2g".equals(key) ||
"sync_3g".equals(key) || "sync_gprs".equals(key) ||
"sync_4g".equals(key) || "sync_others".equals(key)) {
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(NrzSettingsActivity._context);
Log.d(GeneralSettingsActivity.TAG,"GeneralSettingsActivity.handleCheckboxPreference: set " + key + " to "
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
Log.d(TAG,"OCSMSSettingsActivity.handleCheckboxPreference: set " + key + " to "
+ value.toString());
prefs.putBoolean(key, value);
}
@ -89,17 +89,17 @@ public class GeneralSettingsActivity extends NrzSettingsActivity {
Log.d(TAG, "Modifying listPreference " + key);
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(NrzSettingsActivity._context);
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
// Handle sync frequency change
if ("sync_frequency".equals(key)) {
Account[] myAccountList = GeneralSettingsActivity._accountMgr.getAccountsByType(GeneralSettingsActivity._accountType);
Account[] myAccountList = _accountMgr.getAccountsByType(_accountType);
long syncFreq = Long.parseLong(value);
// Get ownCloud SMS account list
for (Account acct: myAccountList) {
// And get all authorities for this account
List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(acct, GeneralSettingsActivity._accountAuthority);
List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(acct, _accountAuthority);
boolean foundSameSyncCycle = false;
for (PeriodicSync ps: syncList) {
@ -112,9 +112,9 @@ public class GeneralSettingsActivity extends NrzSettingsActivity {
Bundle b = new Bundle();
b.putInt("synctype", 1);
ContentResolver.removePeriodicSync(acct, GeneralSettingsActivity._accountAuthority, b);
ContentResolver.removePeriodicSync(acct, _accountAuthority, b);
if (syncFreq > 0) {
ContentResolver.addPeriodicSync(acct, GeneralSettingsActivity._accountAuthority, b, syncFreq * 60);
ContentResolver.addPeriodicSync(acct, _accountAuthority, b, syncFreq * 60);
}
}

View File

@ -7,7 +7,7 @@ import android.os.Bundle;
import java.util.ArrayList;
import java.util.Collections;
import fr.nrz.androidlib.adapters.AndroidAccountAdapter;
import fr.unix_experience.owncloud_sms.adapters.AndroidAccountAdapter;
import fr.unix_experience.android_lib.AppCompatListActivity;
import fr.unix_experience.owncloud_sms.R;

View File

@ -0,0 +1,212 @@
package fr.unix_experience.owncloud_sms.activities.virtual;
/**
* Copyright (c) 2013-2015, Loic Blot <loic.blot@unix-experience.fr>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
*/
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.Log;
import java.util.Vector;
public class VirtualSettingsActivity extends PreferenceActivity {
private static String TAG = VirtualSettingsActivity.class.getSimpleName();
protected static Context _context;
protected static int _prefsRessourceFile;
protected static Vector<BindObjectPref> _boolPrefs = new Vector<>();
protected static Vector<BindObjectPref> _stringPrefs = new Vector<>();
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
VirtualSettingsActivity._context = getBaseContext();
setupSimplePreferencesScreen();
}
/**
* Shows the simplified settings UI if the device configuration if the
* device configuration dictates that a simplified, single-pane UI should be
* shown.
*/
@SuppressWarnings("deprecation")
private void setupSimplePreferencesScreen() {
if (!VirtualSettingsActivity.isSimplePreferences(this)) {
return;
}
// In the simplified UI, fragments are not used at all and we instead
// use the older PreferenceActivity APIs.
addPreferencesFromResource(VirtualSettingsActivity._prefsRessourceFile);
bindPreferences();
}
/** {@inheritDoc} */
@Override
public boolean onIsMultiPane() {
return VirtualSettingsActivity.isXLargeTablet(this) && !VirtualSettingsActivity.isSimplePreferences(this);
}
/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
/**
* Determines whether the simplified settings UI should be shown. This is
* true if this is forced via 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.
*/
protected static boolean isSimplePreferences(Context context) {
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
|| !VirtualSettingsActivity.isXLargeTablet(context);
}
/**
* 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 #bindPreferenceBooleanToValue
*/
public void bindPreferenceBooleanToValue(Preference preference, Boolean defValue) {
// Set the listener to watch for value changes.
preference
.setOnPreferenceChangeListener(_bindPreferenceListener);
// Trigger the listener immediately with the preference's
// current value.
_bindPreferenceListener.onPreferenceChange(
preference,
PreferenceManager.getDefaultSharedPreferences(
preference.getContext()).getBoolean(
preference.getKey(),
defValue
)
);
}
public void bindPreferenceStringToValue(Preference preference, String defValue) {
// Set the listener to watch for value changes.
preference
.setOnPreferenceChangeListener(_bindPreferenceListener);
// Trigger the listener immediately with the preference's
// current value.
_bindPreferenceListener.onPreferenceChange(
preference,
PreferenceManager.getDefaultSharedPreferences(
preference.getContext()).getString(
preference.getKey(),
defValue
)
);
}
/**
* This fragment shows data and sync preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class DataSyncPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(VirtualSettingsActivity._prefsRessourceFile);
bindPreferences();
}
}
private 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.
for (BindObjectPref pref: VirtualSettingsActivity._stringPrefs) {
bindPreferenceStringToValue(findPreference(pref.name),
(String) pref.value);
}
for (BindObjectPref pref: VirtualSettingsActivity._boolPrefs) {
bindPreferenceBooleanToValue(findPreference(pref.name),
(Boolean) pref.value);
}
}
// The preference object, it's only a key value pair
protected class BindObjectPref {
public String name;
public Object value;
public BindObjectPref(String prefName, Object prefVal) {
name = prefName;
value = prefVal;
}
}
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
*/
private final Preference.OnPreferenceChangeListener _bindPreferenceListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
if (preference instanceof ListPreference) {
Log.d(TAG, "Changed list preference " + preference.toString() + " value " + value.toString());
handleListPreference(preference.getKey(), value.toString(), (ListPreference) preference);
} else if (preference instanceof CheckBoxPreference) {
Log.d(TAG, "Changed checkbox preference " + preference.toString() + " value " + value.toString());
handleCheckboxPreference(preference.getKey(), (Boolean) value);
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
//preference.setSummary(boolValue);
}
return true;
}
};
protected void handleCheckboxPreference(String key, Boolean value) {}
protected void handleListPreference(String key, String value,
ListPreference preference) {}
}

View File

@ -0,0 +1,63 @@
package fr.unix_experience.owncloud_sms.adapters;
import android.accounts.Account;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
public class AndroidAccountAdapter extends ArrayAdapter<Account> {
private final ArrayList<Account> _accounts;
private static int _itemLayout;
private static int _accountFieldId;
private final Activity _activity;
Class<?> _newActivityClass;
public AndroidAccountAdapter(Activity activity, int resource,
ArrayList<Account> objects, int itemLayout,
int accountFieldId, Class<?> newActivityClass) {
super(activity.getBaseContext(), resource, objects);
_accounts = objects;
AndroidAccountAdapter._itemLayout = itemLayout;
AndroidAccountAdapter._accountFieldId = accountFieldId;
_activity = activity;
_newActivityClass = newActivityClass;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(AndroidAccountAdapter._itemLayout, null);
}
final Account account = _accounts.get(position);
if (account != null) {
TextView label = (TextView) v.findViewById(AndroidAccountAdapter._accountFieldId);
if (label != null) {
label.setText(account.name + " >");
v.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(_activity, _newActivityClass);
i.putExtra("account", account.name);
_activity.startActivity(i);
}
});
}
}
return v;
}
}

View File

@ -19,7 +19,7 @@ package fr.unix_experience.owncloud_sms.prefs;
import android.content.Context;
import android.content.SharedPreferences;
import fr.nrz.androidlib.common.SharedPrefs;
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;

View File

@ -0,0 +1,63 @@
package fr.unix_experience.owncloud_sms.prefs;
/**
* Copyright (c) 2013-2015, Loic Blot <loic.blot@unix-experience.fr>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
*/
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class SharedPrefs {
protected final SharedPreferences _sPrefs;
protected final Context _context;
public SharedPrefs(Context context, int prefFile) {
_context = context;
_sPrefs = _context.getSharedPreferences(_context.getString(prefFile), Context.MODE_PRIVATE);
}
public void putBoolean(String prefKey, Boolean boolValue) {
Editor edit = _sPrefs.edit();
edit.putBoolean(prefKey, boolValue);
edit.apply();
}
public void putInteger(String prefKey, Integer intValue) {
Editor edit = _sPrefs.edit();
edit.putInt(prefKey, intValue);
edit.apply();
}
public void putLong(String prefKey, long longValue) {
Editor edit = _sPrefs.edit();
edit.putLong(prefKey, longValue);
edit.apply();
}
}

View File

@ -27,9 +27,8 @@ import android.support.annotation.NonNull;
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
public class SmsDataProvider extends ContentProvider {
public SmsDataProvider () {}
public SmsDataProvider (Context ct) {
public SmsDataProvider (Context ct) {
super();
_context = ct;
}