Commit da7ee0f8 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca Committed by Pietro Saccardi

Settings added - but not working widget (only backup project)

parent ec393d50
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -15,11 +15,6 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
......@@ -39,6 +34,16 @@
android:resource="@xml/mywidget"></meta-data>
</receiver>
<activity
android:name=".SettingsActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package it.giacomo.sesamo;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
public class SettingsActivity extends PreferenceActivity implements Preference.OnPreferenceChangeListener {
public static class MyPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try{
addPreferencesFromResource(R.xml.settings);
SettingsActivity m = new SettingsActivity();
this.getPreferenceManager().getSharedPreferences();
m.bindPreferenceSummaryToValue(findPreference("prefUsername"));
}catch(Exception exp){
exp.toString();
}
}
}
private void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(this);
// Trigger the listener immediately with the preference's
// current value.
onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
}
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
}
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list (since they have separate labels/values).
ListPreference listPreference = (ListPreference) preference;
int prefIndex = listPreference.findIndexOfValue(stringValue);
if (prefIndex >= 0) {
preference.setSummary(listPreference.getEntries()[prefIndex]);
}
} else {
// For other preferences, set the summary to the value's simple string representation.
preference.setSummary(stringValue);
}
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="syncFrequency">
<item name="1">Once a day</item>
<item name="7">Once a week</item>
<item name="3">Once a year</item>
<item name="0">Never (Update maually)</item>
</string-array>
<string-array name="syncFrequencyValues">
<item name="1">1</item>
<item name="7">7</item>
<item name="30">30</item>
<item name="0">0</item>
</string-array>
</resources>
......@@ -3,4 +3,21 @@
<string name="title_home">Home</string>
<string name="title_dashboard">Dashboard</string>
<string name="title_notifications">Notifications</string>
<string name="pref_send_report">Send crash reports</string>
<string name="pref_send_report_summary">Helps to fix bugs</string>
<string name="pref_sync_frequency">Sync frequency</string>
<string name="pref_sync_frequency_summary">Set the sync frequency</string>
<string name="pref_user_name">Set username</string>
<string name="pref_user_name_summary">Set your username</string>
<string name="pref_user_profile">User Profile</string>
<string name="pref_update_setting">Update Settings</string>
<string name="pref_title_social_recommendations">Enable social recommendations</string>
<string name="pref_description_social_recommendations">Recommendations for people to contact based on your message history</string>
<string name="pref_title_display_name">Display name</string>
<string name="pref_default_display_name">Bülent Siyah</string>
</resources>
......@@ -2,7 +2,8 @@
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dp"
android:updatePeriodMillis="10000"
android:configure="it.giacomo.sesamo.SettingsActivity"
android:updatePeriodMillis="10000"
android:minHeight="146dp"
android:initialLayout="@layout/activity_main">
......
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/pref_user_profile" >
<EditTextPreference
android:title="@string/pref_user_name"
android:summary="@string/pref_user_name_summary"
android:key="prefUsername"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_update_setting" >
<CheckBoxPreference
android:defaultValue="false"
android:key="prefSendReport"
android:summary="@string/pref_send_report_summary"
android:title="@string/pref_send_report" >
</CheckBoxPreference>
<ListPreference
android:key="prefSyncFrequency"
android:entries="@array/syncFrequency"
android:summary="@string/pref_sync_frequency_summary"
android:entryValues="@array/syncFrequencyValues"
android:title="@string/pref_sync_frequency" />
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment