added overriding status/location list when manual entry added
This commit is contained in:
parent
b87f859d75
commit
c765ac0782
@ -3,6 +3,7 @@ package com.uam.wmi.findmytutor.activity;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@ -14,16 +15,17 @@ import android.preference.PreferenceManager;
|
||||
import android.view.MenuItem;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class SharingActivity extends AppCompatPreferenceActivity {
|
||||
//rivate static final String TAG = SettingsActivity.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// load settings fragment
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit();
|
||||
}
|
||||
|
||||
@ -32,30 +34,48 @@ public class SharingActivity extends AppCompatPreferenceActivity {
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.pref_sharing);
|
||||
//setListPreferenceData("key_description",getActivity());
|
||||
// feedback preference click listener
|
||||
/* Preference myPref = findPreference(getString(R.string.key_send_feedback));
|
||||
myPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
sendFeedback(getActivity());
|
||||
Preference manualStatus = findPreference("key_manual_status");
|
||||
manualStatus.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ListPreference lp = (ListPreference) findPreference("key_status_value");
|
||||
updateListPreference(lp ,newValue,"manual_statuses");
|
||||
return true;
|
||||
}
|
||||
});*/
|
||||
}
|
||||
protected ListPreference setListPreferenceData(String lp_name, Activity mActivity) {
|
||||
ListPreference lp = (ListPreference) findPreference(lp_name);
|
||||
});
|
||||
Preference manualLoction = findPreference("key_manual_location_custom");
|
||||
manualLoction.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ListPreference lp = (ListPreference) findPreference("manual_location_list_title");
|
||||
updateListPreference(lp ,newValue,"manual_locations");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
CharSequence[] entries = { "One", "Two", "Three" };
|
||||
CharSequence[] entryValues = { "1", "2", "3" };
|
||||
if(lp == null)
|
||||
lp = new ListPreference(mActivity);
|
||||
}
|
||||
protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){
|
||||
CharSequence [] entries = lp.getEntries();
|
||||
Set <String> defaultEntries = new HashSet(Arrays.asList(entries));
|
||||
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
|
||||
Set <String> manualStatusSet = sharedPref.getStringSet(storageKey,defaultEntries);
|
||||
manualStatusSet.add((String) newValue);
|
||||
String [] manualStatusArr = manualStatusSet.toArray(new String[0]);
|
||||
Arrays.sort(manualStatusArr);
|
||||
setListPreferenceData(lp.getKey(),manualStatusArr);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putStringSet(storageKey,manualStatusSet);
|
||||
editor.commit();
|
||||
}
|
||||
protected ListPreference setListPreferenceData(String lp_name, String [] entries) {
|
||||
ListPreference lp = (ListPreference) findPreference(lp_name);
|
||||
lp.setEntries(entries);
|
||||
CharSequence[] entryValues = new CharSequence [entries.length];
|
||||
for (int i = 0; i < entries.length; i++){
|
||||
entryValues[i] = Integer.toString(i+1);
|
||||
}
|
||||
lp.setDefaultValue("1");
|
||||
lp.setEntryValues(entryValues);
|
||||
lp.setTitle("Number Of blahs");
|
||||
lp.setSummary(lp.getEntry());
|
||||
lp.setDialogTitle("Number of Blah objects");
|
||||
lp.setKey(lp_name);
|
||||
return lp;
|
||||
}
|
||||
}
|
||||
@ -68,54 +88,12 @@ public class SharingActivity extends AppCompatPreferenceActivity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private static void bindPreferenceSummaryToValue(Preference preference) {
|
||||
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
|
||||
|
||||
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
|
||||
PreferenceManager
|
||||
.getDefaultSharedPreferences(preference.getContext())
|
||||
.getString(preference.getKey(), ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* A preference value change listener that updates the preference's summary
|
||||
* to reflect its new value.
|
||||
*/
|
||||
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String stringValue = newValue.toString();
|
||||
|
||||
if (preference instanceof ListPreference) {
|
||||
// For list preferences, look up the correct display value in
|
||||
// the preference's 'entries' list.
|
||||
ListPreference listPreference = (ListPreference) preference;
|
||||
int index = listPreference.findIndexOfValue(stringValue);
|
||||
|
||||
// Set the summary to reflect the new value.
|
||||
preference.setSummary(
|
||||
index >= 0
|
||||
? listPreference.getEntries()[index]
|
||||
: null);
|
||||
|
||||
} else if (preference instanceof EditTextPreference) {
|
||||
if (preference.getKey().equals("key_gallery_name")) {
|
||||
// update the changed gallery name to summary filed
|
||||
preference.setSummary(stringValue);
|
||||
}
|
||||
} else {
|
||||
preference.setSummary(stringValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Email client intent to send support mail
|
||||
* Appends the necessary device information to email body
|
||||
* useful when providing support
|
||||
*/
|
||||
public static void sendFeedback(Context context) {
|
||||
/* public static void sendFeedback(Context context) {
|
||||
String body = null;
|
||||
try {
|
||||
body = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
||||
@ -130,5 +108,5 @@ public class SharingActivity extends AppCompatPreferenceActivity {
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "Query from android app");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, body);
|
||||
context.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_email_client)));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -61,9 +61,9 @@
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
<string-array name="manual_location_entries">
|
||||
<item>@string/description_available</item>
|
||||
<item>@string/description_busy</item>
|
||||
<item>@string/description_consultation</item>
|
||||
<item>@string/assembly_c</item>
|
||||
<item>@string/assembly_a</item>
|
||||
<item>@string/passage_d</item>
|
||||
</string-array>
|
||||
<string-array name="manual_location_values">
|
||||
<item>0</item>
|
||||
|
@ -73,8 +73,11 @@
|
||||
|
||||
<string name="manual_location">Manual location</string>
|
||||
<string name="title_list_manual_location">Choose manual location</string>
|
||||
|
||||
<string name="title_manual_location">Add custom location</string>
|
||||
<string name="assembly_a">Assembly Hall A</string>
|
||||
<string name="assembly_c">Assembly Hall C</string>
|
||||
<string name="passage_d">Passage D</string>
|
||||
|
||||
|
||||
<string name="settings_category_general">General</string>
|
||||
<string name="key_notifications_enabled">key_notifications_enabled</string>
|
||||
|
@ -43,6 +43,8 @@
|
||||
<ListPreference
|
||||
android:defaultValue="1"
|
||||
android:key="manual_location_list_title"
|
||||
android:entries="@array/manual_location_entries"
|
||||
android:entryValues="@array/manual_location_values"
|
||||
android:summary="%s"
|
||||
android:title="@string/title_list_manual_location" />
|
||||
<EditTextPreference
|
||||
|
Loading…
Reference in New Issue
Block a user