mirror of
https://github.com/nerzhul/nrz-androidlib.git
synced 2025-06-07 16:06:21 +00:00
Update nrz android lib and add gitignore
This commit is contained in:
parent
5cb1169312
commit
42a36f7c97
@ -28,8 +28,6 @@ package fr.nrz.androidlib.activities;
|
|||||||
* either expressed or implied, of the FreeBSD Project.
|
* either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@ -41,18 +39,21 @@ import android.preference.Preference;
|
|||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
public class NrzSettingsActivity extends PreferenceActivity {
|
public class NrzSettingsActivity extends PreferenceActivity {
|
||||||
private static final boolean ALWAYS_SIMPLE_PREFS = false;
|
private static String TAG = NrzSettingsActivity.class.getSimpleName();
|
||||||
protected static Context _context;
|
protected static Context _context;
|
||||||
protected static int _prefsRessourceFile;
|
protected static int _prefsRessourceFile;
|
||||||
protected static Vector<BindObjectPref> _boolPrefs = new Vector<BindObjectPref>();
|
protected static Vector<BindObjectPref> _boolPrefs = new Vector<>();
|
||||||
protected static Vector<BindObjectPref> _stringPrefs = new Vector<BindObjectPref>();
|
protected static Vector<BindObjectPref> _stringPrefs = new Vector<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostCreate(final Bundle savedInstanceState) {
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
super.onPostCreate(savedInstanceState);
|
super.onPostCreate(savedInstanceState);
|
||||||
_context = getBaseContext();
|
NrzSettingsActivity._context = getBaseContext();
|
||||||
setupSimplePreferencesScreen();
|
setupSimplePreferencesScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,41 +64,40 @@ public class NrzSettingsActivity extends PreferenceActivity {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void setupSimplePreferencesScreen() {
|
private void setupSimplePreferencesScreen() {
|
||||||
if (!isSimplePreferences(this)) {
|
if (!NrzSettingsActivity.isSimplePreferences(this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In the simplified UI, fragments are not used at all and we instead
|
// In the simplified UI, fragments are not used at all and we instead
|
||||||
// use the older PreferenceActivity APIs.
|
// use the older PreferenceActivity APIs.
|
||||||
addPreferencesFromResource(_prefsRessourceFile);
|
addPreferencesFromResource(NrzSettingsActivity._prefsRessourceFile);
|
||||||
bindPreferences();
|
bindPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public boolean onIsMultiPane() {
|
public boolean onIsMultiPane() {
|
||||||
return isXLargeTablet(this) && !isSimplePreferences(this);
|
return NrzSettingsActivity.isXLargeTablet(this) && !NrzSettingsActivity.isSimplePreferences(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to determine if the device has an extra-large screen. For
|
* Helper method to determine if the device has an extra-large screen. For
|
||||||
* example, 10" tablets are extra-large.
|
* example, 10" tablets are extra-large.
|
||||||
*/
|
*/
|
||||||
private static boolean isXLargeTablet(final Context context) {
|
private static boolean isXLargeTablet(Context context) {
|
||||||
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the simplified settings UI should be shown. This is
|
* Determines whether the simplified settings UI should be shown. This is
|
||||||
* true if this is forced via {@link #ALWAYS_SIMPLE_PREFS}, or the device
|
* true if this is forced via the device
|
||||||
* doesn't have newer APIs like {@link PreferenceFragment}, 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
|
* doesn't have an extra-large screen. In these cases, a single-pane
|
||||||
* "simplified" settings UI should be shown.
|
* "simplified" settings UI should be shown.
|
||||||
*/
|
*/
|
||||||
protected static boolean isSimplePreferences(final Context context) {
|
protected static boolean isSimplePreferences(Context context) {
|
||||||
return ALWAYS_SIMPLE_PREFS
|
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
|
||||||
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
|
|| !NrzSettingsActivity.isXLargeTablet(context);
|
||||||
|| !isXLargeTablet(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,40 +107,40 @@ public class NrzSettingsActivity extends PreferenceActivity {
|
|||||||
* immediately updated upon calling this method. The exact display format is
|
* immediately updated upon calling this method. The exact display format is
|
||||||
* dependent on the type of preference.
|
* dependent on the type of preference.
|
||||||
*
|
*
|
||||||
* @see #sBindPreferenceSummaryToValueListener
|
* @see #bindPreferenceBooleanToValue
|
||||||
*/
|
*/
|
||||||
public static void bindPreferenceBooleanToValue(final Preference preference, final Boolean defValue) {
|
public void bindPreferenceBooleanToValue(Preference preference, Boolean defValue) {
|
||||||
// Set the listener to watch for value changes.
|
// Set the listener to watch for value changes.
|
||||||
preference
|
preference
|
||||||
.setOnPreferenceChangeListener(_bindPreferenceListener);
|
.setOnPreferenceChangeListener(_bindPreferenceListener);
|
||||||
|
|
||||||
// Trigger the listener immediately with the preference's
|
// Trigger the listener immediately with the preference's
|
||||||
// current value.
|
// current value.
|
||||||
_bindPreferenceListener.onPreferenceChange(
|
_bindPreferenceListener.onPreferenceChange(
|
||||||
preference,
|
preference,
|
||||||
PreferenceManager.getDefaultSharedPreferences(
|
PreferenceManager.getDefaultSharedPreferences(
|
||||||
preference.getContext()).getBoolean(
|
preference.getContext()).getBoolean(
|
||||||
preference.getKey(),
|
preference.getKey(),
|
||||||
defValue
|
defValue
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void bindPreferenceStringToValue(final Preference preference, final String defValue) {
|
public void bindPreferenceStringToValue(Preference preference, String defValue) {
|
||||||
// Set the listener to watch for value changes.
|
// Set the listener to watch for value changes.
|
||||||
preference
|
preference
|
||||||
.setOnPreferenceChangeListener(_bindPreferenceListener);
|
.setOnPreferenceChangeListener(_bindPreferenceListener);
|
||||||
|
|
||||||
// Trigger the listener immediately with the preference's
|
// Trigger the listener immediately with the preference's
|
||||||
// current value.
|
// current value.
|
||||||
_bindPreferenceListener.onPreferenceChange(
|
_bindPreferenceListener.onPreferenceChange(
|
||||||
preference,
|
preference,
|
||||||
PreferenceManager.getDefaultSharedPreferences(
|
PreferenceManager.getDefaultSharedPreferences(
|
||||||
preference.getContext()).getString(
|
preference.getContext()).getString(
|
||||||
preference.getKey(),
|
preference.getKey(),
|
||||||
defValue
|
defValue
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,24 +148,13 @@ public class NrzSettingsActivity extends PreferenceActivity {
|
|||||||
* activity is showing a two-pane settings UI.
|
* activity is showing a two-pane settings UI.
|
||||||
*/
|
*/
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
public static class DataSyncPreferenceFragment extends PreferenceFragment {
|
public class DataSyncPreferenceFragment extends PreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(_prefsRessourceFile);
|
addPreferencesFromResource(NrzSettingsActivity._prefsRessourceFile);
|
||||||
|
|
||||||
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
|
bindPreferences();
|
||||||
// to their values. When their values change, their summaries are
|
|
||||||
// updated to reflect the new value, per the Android Design
|
|
||||||
// guidelines.
|
|
||||||
for (int i=0; i < _stringPrefs.size(); i++) {
|
|
||||||
bindPreferenceStringToValue(findPreference(_stringPrefs.get(i).name),
|
|
||||||
(String) _stringPrefs.get(i).value);
|
|
||||||
}
|
|
||||||
for (int i=0; i < _boolPrefs.size(); i++) {
|
|
||||||
bindPreferenceBooleanToValue(findPreference(_boolPrefs.get(i).name),
|
|
||||||
(Boolean) _boolPrefs.get(i).value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,22 +162,22 @@ public class NrzSettingsActivity extends PreferenceActivity {
|
|||||||
// Bind the summaries of EditText/List/Dialog/Ringtone preferences to
|
// Bind the summaries of EditText/List/Dialog/Ringtone preferences to
|
||||||
// their values. When their values change, their summaries are updated
|
// their values. When their values change, their summaries are updated
|
||||||
// to reflect the new value, per the Android Design guidelines.
|
// to reflect the new value, per the Android Design guidelines.
|
||||||
for (int i=0; i < _stringPrefs.size(); i++) {
|
for (BindObjectPref pref: NrzSettingsActivity._stringPrefs) {
|
||||||
bindPreferenceStringToValue(findPreference(_stringPrefs.get(i).name),
|
bindPreferenceStringToValue(findPreference(pref.name),
|
||||||
(String) _stringPrefs.get(i).value);
|
(String) pref.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i < _boolPrefs.size(); i++) {
|
for (BindObjectPref pref: NrzSettingsActivity._boolPrefs) {
|
||||||
bindPreferenceBooleanToValue(findPreference(_boolPrefs.get(i).name),
|
bindPreferenceBooleanToValue(findPreference(pref.name),
|
||||||
(Boolean) _boolPrefs.get(i).value);
|
(Boolean) pref.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The preference object, it's only a key value pair
|
// The preference object, it's only a key value pair
|
||||||
protected class BindObjectPref {
|
protected class BindObjectPref {
|
||||||
public String name;
|
public String name;
|
||||||
public Object value;
|
public Object value;
|
||||||
public BindObjectPref(final String prefName, final Object prefVal) {
|
public BindObjectPref(String prefName, Object prefVal) {
|
||||||
name = prefName;
|
name = prefName;
|
||||||
value = prefVal;
|
value = prefVal;
|
||||||
}
|
}
|
||||||
@ -198,14 +187,16 @@ public class NrzSettingsActivity extends PreferenceActivity {
|
|||||||
* A preference value change listener that updates the preference's summary
|
* A preference value change listener that updates the preference's summary
|
||||||
* to reflect its new value.
|
* to reflect its new value.
|
||||||
*/
|
*/
|
||||||
private static Preference.OnPreferenceChangeListener _bindPreferenceListener = new Preference.OnPreferenceChangeListener() {
|
private final Preference.OnPreferenceChangeListener _bindPreferenceListener = new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(final Preference preference, final Object value) {
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
if (preference instanceof ListPreference) {
|
if (preference instanceof ListPreference) {
|
||||||
handleListPreference(preference.getKey(), value.toString(), (ListPreference) preference);
|
Log.d(TAG, "Changed list preference " + preference.toString() + " value " + value.toString());
|
||||||
|
handleListPreference(preference.getKey(), value.toString(), (ListPreference) preference);
|
||||||
|
|
||||||
} else if (preference instanceof CheckBoxPreference) {
|
} else if (preference instanceof CheckBoxPreference) {
|
||||||
handleCheckboxPreference(preference.getKey(), (Boolean)value);
|
Log.d(TAG, "Changed checkbox preference " + preference.toString() + " value " + value.toString());
|
||||||
|
handleCheckboxPreference(preference.getKey(), (Boolean) value);
|
||||||
} else {
|
} else {
|
||||||
// For all other preferences, set the summary to the value's
|
// For all other preferences, set the summary to the value's
|
||||||
// simple string representation.
|
// simple string representation.
|
||||||
@ -215,7 +206,7 @@ public class NrzSettingsActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected static void handleCheckboxPreference(final String key, final Boolean value) {}
|
protected void handleCheckboxPreference(String key, Boolean value) {}
|
||||||
protected static void handleListPreference(final String key, final String value,
|
protected void handleListPreference(String key, String value,
|
||||||
final ListPreference preference) {}
|
ListPreference preference) {}
|
||||||
}
|
}
|
||||||
|
@ -21,34 +21,35 @@ public class AndroidAccountAdapter extends ArrayAdapter<Account> {
|
|||||||
private final Activity _activity;
|
private final Activity _activity;
|
||||||
Class<?> _newActivityClass;
|
Class<?> _newActivityClass;
|
||||||
|
|
||||||
public AndroidAccountAdapter(final Activity activity, final int resource,
|
public AndroidAccountAdapter(Activity activity, int resource,
|
||||||
final ArrayList<Account> objects, final int itemLayout, final int accountFieldId, final Class<?> newActivityClass) {
|
ArrayList<Account> objects, int itemLayout,
|
||||||
|
int accountFieldId, Class<?> newActivityClass) {
|
||||||
super(activity.getBaseContext(), resource, objects);
|
super(activity.getBaseContext(), resource, objects);
|
||||||
_accounts = objects;
|
_accounts = objects;
|
||||||
_itemLayout = itemLayout;
|
AndroidAccountAdapter._itemLayout = itemLayout;
|
||||||
_accountFieldId = accountFieldId;
|
AndroidAccountAdapter._accountFieldId = accountFieldId;
|
||||||
_activity = activity;
|
_activity = activity;
|
||||||
_newActivityClass = newActivityClass;
|
_newActivityClass = newActivityClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, final View convertView, final ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View v = convertView;
|
View v = convertView;
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
v = inflater.inflate(_itemLayout, null);
|
v = inflater.inflate(AndroidAccountAdapter._itemLayout, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Account account = _accounts.get(position);
|
final Account account = _accounts.get(position);
|
||||||
|
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
final TextView label = (TextView) v.findViewById(_accountFieldId);
|
TextView label = (TextView) v.findViewById(AndroidAccountAdapter._accountFieldId);
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
label.setText(account.name + " >");
|
label.setText(account.name + " >");
|
||||||
label.setOnClickListener(new OnClickListener() {
|
label.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(View v) {
|
||||||
final Intent i = new Intent(_activity, _newActivityClass);
|
Intent i = new Intent(_activity, _newActivityClass);
|
||||||
i.putExtra("account", account.name);
|
i.putExtra("account", account.name);
|
||||||
_activity.startActivity(i);
|
_activity.startActivity(i);
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,27 @@ public class SharedPrefs {
|
|||||||
protected final SharedPreferences _sPrefs;
|
protected final SharedPreferences _sPrefs;
|
||||||
protected final Context _context;
|
protected final Context _context;
|
||||||
|
|
||||||
public SharedPrefs(final Context context, final int prefFile) {
|
public SharedPrefs(Context context, int prefFile) {
|
||||||
_context = context;
|
_context = context;
|
||||||
|
|
||||||
_sPrefs = _context.getSharedPreferences(_context.getString(prefFile), Context.MODE_PRIVATE);
|
_sPrefs = _context.getSharedPreferences(_context.getString(prefFile), Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putBoolean(final String prefKey, final Boolean boolValue) {
|
public void putBoolean(String prefKey, Boolean boolValue) {
|
||||||
final Editor edit = _sPrefs.edit();
|
Editor edit = _sPrefs.edit();
|
||||||
edit.putBoolean(prefKey, boolValue);
|
edit.putBoolean(prefKey, boolValue);
|
||||||
edit.commit();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,19 +36,19 @@ import android.content.Context;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
public class NrzNotification {
|
public class NrzNotification {
|
||||||
public NrzNotification(final Context ct, final int iconId) {
|
public NrzNotification(Context ct, int iconId) {
|
||||||
_iconId = iconId;
|
_iconId = iconId;
|
||||||
_ct = ct;
|
_ct = ct;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
public boolean createNotify(final int nType, final String nTitle, final String nText) {
|
public boolean createNotify(int nType, String nTitle, String nText) {
|
||||||
if (_ct == null) {
|
if (_ct == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final NotificationManager notificationManager = (NotificationManager)_ct.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager)_ct.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
final Builder mBuilder = new Notification.Builder(_ct)
|
Builder mBuilder = new Notification.Builder(_ct)
|
||||||
.setContentText(nText)
|
.setContentText(nText)
|
||||||
.setContentTitle(nTitle)
|
.setContentTitle(nTitle)
|
||||||
.setSmallIcon(_iconId);
|
.setSmallIcon(_iconId);
|
||||||
@ -58,8 +58,8 @@ public class NrzNotification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
public void cancelNotify(final int nType) {
|
public void cancelNotify(int nType) {
|
||||||
final NotificationManager notificationManager = (NotificationManager)_ct.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager)_ct.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
notificationManager.cancel(nType);
|
notificationManager.cancel(nType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user