mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-16 23:12:51 +00:00
Added preferences activity
This commit is contained in:
parent
fa7e5941f1
commit
1182df481b
4 changed files with 59 additions and 1 deletions
|
@ -31,6 +31,9 @@
|
||||||
android:label="@string/title_activity_intro"
|
android:label="@string/title_activity_intro"
|
||||||
android:theme="@style/Theme.Intro">
|
android:theme="@style/Theme.Intro">
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity android:name=".PreferencesActivity"
|
||||||
|
>
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -54,7 +54,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
//AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
|
||||||
|
|
||||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -163,6 +162,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
//noinspection SimplifiableIfStatement
|
//noinspection SimplifiableIfStatement
|
||||||
if (id == R.id.action_settings) {
|
if (id == R.id.action_settings) {
|
||||||
|
|
||||||
|
Intent preferencesActivity = new Intent(this, PreferencesActivity.class);
|
||||||
|
startActivity(preferencesActivity);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
50
app/src/main/java/me/impy/aegis/PreferencesActivity.java
Normal file
50
app/src/main/java/me/impy/aegis/PreferencesActivity.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package me.impy.aegis;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.app.AppCompatDelegate;
|
||||||
|
|
||||||
|
public class PreferencesActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
SharedPreferences mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
if(mySharedPreferences.getBoolean("pref_night_mode", false))
|
||||||
|
{
|
||||||
|
setTheme(R.style.AppTheme_Dark);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
setTheme(R.style.AppTheme_Default);
|
||||||
|
}
|
||||||
|
getFragmentManager().beginTransaction().replace(android.R.id.content, new PreferencesFragment()).commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
public static class PreferencesFragment extends PreferenceFragment {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
|
Preference nightModePreference = findPreference("pref_night_mode");
|
||||||
|
nightModePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
//AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||||
|
Intent i = new Intent(getActivity(), MainActivity.class);
|
||||||
|
//startActivity(i);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,4 +2,6 @@
|
||||||
<string name="app_name">Aegis</string>
|
<string name="app_name">Aegis</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="title_activity_intro">IntroActivity</string>
|
<string name="title_activity_intro">IntroActivity</string>
|
||||||
|
<string name="settings">Preferences</string>
|
||||||
|
<string name="pref_night_mode">Night mode</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue