mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
Replaces settings activity with correct Preference fragment and xml
This commit is contained in:
@@ -1,50 +1,30 @@
|
||||
package com.wismna.geoffroy.donext;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Spinner;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
populateSpinner();
|
||||
|
||||
// Display the preferences fragment as the main content.
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||
}
|
||||
|
||||
private void populateSpinner() {
|
||||
Spinner spinner = (Spinner) findViewById(R.id.max_lists_spinner);
|
||||
spinner.setSelection(getPreference(R.id.max_lists_spinner));
|
||||
//ArrayAdapter<String> adapter = (ArrayAdapter<String>) spinner.getAdapter();
|
||||
//int position = adapter.getPosition()
|
||||
/*ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
|
||||
R.array.settings_max_lists_number, R.layout.support_simple_spinner_dropdown_item);
|
||||
adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
|
||||
spinner.setAdapter(adapter);*/
|
||||
}
|
||||
public static class SettingsFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
protected int getPreference(int setting) {
|
||||
SharedPreferences sharedPreferences = this.getPreferences(Context.MODE_PRIVATE);
|
||||
return sharedPreferences.getInt(getString(setting), 2);
|
||||
}
|
||||
protected void setPreference(int setting, int value) {
|
||||
SharedPreferences sharedPreferences = this.getPreferences(Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putInt(getString(setting), value);
|
||||
editor.apply();
|
||||
}
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||
// Item was selected, do something
|
||||
//setPreference(R.id.max_lists_spinner, Integer.parseInt((String) parent.getItemAtPosition(pos)));
|
||||
setPreference(R.id.max_lists_spinner, pos);
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// Another interface callback
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:orientation="vertical"
|
||||
tools:context="com.wismna.geoffroy.donext.SettingsActivity">
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:saveEnabled="true"
|
||||
android:checked="true"
|
||||
android:clickable="true"
|
||||
android:text="@string/settings_confirm_donext" />
|
||||
<CheckBox
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:clickable="true"
|
||||
android:saveEnabled="true"
|
||||
android:text="@string/settings_confirm_markdone" />
|
||||
<CheckBox
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:clickable="true"
|
||||
android:saveEnabled="true"
|
||||
android:text="@string/settings_confirm_delete" />
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_max_lists_label"/>
|
||||
<Spinner
|
||||
android:id="@+id/max_lists_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:entries="@array/settings_max_lists_number"/>
|
||||
</LinearLayout>
|
23
DoNExt/app/src/main/res/xml/preferences.xml
Normal file
23
DoNExt/app/src/main/res/xml/preferences.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<CheckBoxPreference
|
||||
android:key="pref_conf_next"
|
||||
android:title="@string/settings_confirm_donext"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:key="pref_conf_done"
|
||||
android:title="@string/settings_confirm_markdone"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:key="pref_conf_del"
|
||||
android:title="@string/settings_confirm_delete"
|
||||
android:defaultValue="true" />
|
||||
<ListPreference
|
||||
android:key="pref_conf_max_lists"
|
||||
android:title="@string/settings_max_lists_label"
|
||||
android:dialogTitle="@string/settings_max_lists_label"
|
||||
android:entries="@array/settings_max_lists_number"
|
||||
android:entryValues="@array/settings_max_lists_number"
|
||||
android:summary="%s"
|
||||
android:defaultValue="3" />
|
||||
</PreferenceScreen>
|
Reference in New Issue
Block a user