Commit 730a875e authored by Ricki Hirner's avatar Ricki Hirner

App settings UI

parent 17fbae2a
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
<uses-permission android:name="android.permission.WRITE_CALENDAR"/> <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
<!-- ical4android declares task access permissions --> <!-- ical4android declares task access permissions -->
<application <application
android:name=".App" android:name=".App"
android:allowBackup="true" android:allowBackup="true"
...@@ -125,6 +126,21 @@ ...@@ -125,6 +126,21 @@
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".ui.AppSettingsActivity"
android:label="@string/app_settings"
android:parentActivityName=".ui.AccountsActivity"/>
<activity
android:name=".ui.setup.LoginActivity"
android:label="@string/login_title"
android:parentActivityName=".ui.AccountsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<activity <activity
android:name=".ui.AccountActivity" android:name=".ui.AccountActivity"
android:parentActivityName=".ui.AccountsActivity"> android:parentActivityName=".ui.AccountsActivity">
...@@ -134,19 +150,12 @@ ...@@ -134,19 +150,12 @@
android:label="@string/create_addressbook"/> android:label="@string/create_addressbook"/>
<activity android:name=".ui.CreateCalendarActivity" <activity android:name=".ui.CreateCalendarActivity"
android:label="@string/create_calendar"/> android:label="@string/create_calendar"/>
<activity <activity
android:name=".ui.DebugInfoActivity" android:name=".ui.DebugInfoActivity"
android:exported="true" android:exported="true"
android:label="@string/debug_info_title"> android:label="@string/debug_info_title">
</activity> </activity>
<activity
android:name=".ui.setup.LoginActivity"
android:label="@string/login_title"
android:parentActivityName=".ui.AccountsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<!-- MemorizingTrustManager --> <!-- MemorizingTrustManager -->
<activity <activity
......
...@@ -29,11 +29,14 @@ import de.duenndns.ssl.MemorizingTrustManager; ...@@ -29,11 +29,14 @@ import de.duenndns.ssl.MemorizingTrustManager;
import lombok.Getter; import lombok.Getter;
import okhttp3.internal.tls.OkHostnameVerifier; import okhttp3.internal.tls.OkHostnameVerifier;
public class App extends Application { public class App extends Application implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String public static final String
PREF_FILE = "global", PREF_FILE = "davdroid_preferences",
PREF_LOG_TO_FILE = "log_to_file"; PREF_LOG_TO_FILE = "log_to_file";
@Getter
private static MemorizingTrustManager memorizingTrustManager;
@Getter @Getter
private static SSLSocketFactoryCompat sslSocketFactoryCompat; private static SSLSocketFactoryCompat sslSocketFactoryCompat;
...@@ -50,17 +53,32 @@ public class App extends Application { ...@@ -50,17 +53,32 @@ public class App extends Application {
super.onCreate(); super.onCreate();
preferences = getSharedPreferences(PREF_FILE, MODE_PRIVATE); preferences = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
preferences.registerOnSharedPreferenceChangeListener(this);
// initialize MemorizingTrustManager // initialize MemorizingTrustManager
MemorizingTrustManager mtm = new MemorizingTrustManager(this); memorizingTrustManager = new MemorizingTrustManager(this);
sslSocketFactoryCompat = new SSLSocketFactoryCompat(mtm); sslSocketFactoryCompat = new SSLSocketFactoryCompat(memorizingTrustManager);
hostnameVerifier = mtm.wrapHostnameVerifier(OkHostnameVerifier.INSTANCE); hostnameVerifier = memorizingTrustManager.wrapHostnameVerifier(OkHostnameVerifier.INSTANCE);
reinitLogger(); reinitLogger();
} }
// won't be called in production
@Override
public void onTerminate() {
super.onTerminate();
preferences.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (PREF_LOG_TO_FILE.equals(key)) {
log.info("Logging preferences changed, initializing logger again");
reinitLogger();
}
}
public void reinitLogger() { private void reinitLogger() {
// don't use Android default logging, we have our own handlers // don't use Android default logging, we have our own handlers
log.setUseParentHandlers(false); log.setUseParentHandlers(false);
......
...@@ -72,7 +72,8 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie ...@@ -72,7 +72,8 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
case R.id.nav_donate: case R.id.nav_donate:
startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("donate/").build())); startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("donate/").build()));
break; break;
case R.id.nav_preferences: case R.id.nav_app_settings:
startActivity(new Intent(this, AppSettingsActivity.class));
break; break;
} }
......
/*
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.ui;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.widget.Toast;
import java.security.KeyStoreException;
import java.util.Enumeration;
import java.util.logging.Level;
import at.bitfire.davdroid.App;
import at.bitfire.davdroid.R;
import de.duenndns.ssl.MemorizingTrustManager;
public class AppSettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
}
public static class SettingsFragment extends PreferenceFragmentCompat {
Preference prefResetHints,
prefResetCertificates;
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.settings_app);
prefResetHints = findPreference("reset_hints");
prefResetCertificates = findPreference("reset_certificates");
getPreferenceManager().setSharedPreferencesName(App.PREF_FILE);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference == prefResetHints)
resetHints();
else if (preference == prefResetCertificates)
resetCertificates();
else
return false;
return true;
}
private void resetHints() {
// TODO
}
private void resetCertificates() {
MemorizingTrustManager mtm = App.getMemorizingTrustManager();
int deleted = 0;
Enumeration<String> iterator = mtm.getCertificates();
while (iterator.hasMoreElements())
try {
mtm.deleteCertificate(iterator.nextElement());
deleted++;
} catch (KeyStoreException e) {
App.log.log(Level.SEVERE, "Couldn't distrust certificate", e);
}
Snackbar.make(getView(), getString(R.string.app_settings_reset_trusted_certificates_success, deleted), Snackbar.LENGTH_LONG).show();
}
}
}
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
android:icon="@drawable/ic_attach_money_dark" android:icon="@drawable/ic_attach_money_dark"
android:title="@string/navigation_drawer_donate"/> android:title="@string/navigation_drawer_donate"/>
<item <item
android:id="@+id/nav_preferences" android:id="@+id/nav_app_settings"
android:icon="@drawable/ic_settings_dark" android:icon="@drawable/ic_settings_dark"
android:title="@string/navigation_drawer_preferences"/> android:title="@string/navigation_drawer_app_settings"/>
</menu> </menu>
...@@ -17,13 +17,27 @@ ...@@ -17,13 +17,27 @@
<string name="send">Send</string> <string name="send">Send</string>
<string name="skip">Skip</string> <string name="skip">Skip</string>
<!-- AppSettingsActivity -->
<string name="app_settings">Settings</string>
<string name="app_settings_user_interface">User interface</string>
<string name="app_settings_reset_hints">Reset hints</string>
<string name="app_settings_reset_hints_summary">Re-enables hints which have been dismissed previously</string>
<string name="app_settings_security">Security</string>
<string name="app_settings_reset_trusted_certificates">Reset trusted certificates</string>
<string name="app_settings_reset_trusted_certificates_summary">Forgets all certificates which have been accepted previously</string>
<string name="app_settings_reset_trusted_certificates_success">Distrusted %d certificate(s)</string>
<string name="app_settings_debug">Debugging</string>
<string name="app_settings_log_to_file">Log to external file</string>
<string name="app_settings_log_to_file_on">Logging to external storage (if available)</string>
<string name="app_settings_log_to_file_off">External file logging is disabled</string>
<!-- AccountsActivity --> <!-- AccountsActivity -->
<string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string>
<string name="navigation_drawer_subtitle">CalDAV/CardDAV Sync Adapter</string> <string name="navigation_drawer_subtitle">CalDAV/CardDAV Sync Adapter</string>
<string name="navigation_drawer_about">About / License</string> <string name="navigation_drawer_about">About / License</string>
<string name="navigation_drawer_donate">Donate</string> <string name="navigation_drawer_donate">Donate</string>
<string name="navigation_drawer_preferences">Preferences</string> <string name="navigation_drawer_app_settings">Settings</string>
<string name="navigation_drawer_website">Web site</string> <string name="navigation_drawer_website">Web site</string>
<string name="account_list_empty">Welcome to DAVdroid!\n\nYou can add a CalDAV/CardDAV account now.</string> <string name="account_list_empty">Welcome to DAVdroid!\n\nYou can add a CalDAV/CardDAV account now.</string>
...@@ -190,7 +204,7 @@ ...@@ -190,7 +204,7 @@
<string name="create_collection_color">Set a collection color</string> <string name="create_collection_color">Set a collection color</string>
<string name="create_collection_creating">Creating collection</string> <string name="create_collection_creating">Creating collection</string>
<string name="create_collection_display_name">Display name (title) of this collection:</string> <string name="create_collection_display_name">Display name (title) of this collection:</string>
<string name="create_collection_display_name_required">A title is required</string> <string name="create_collection_display_name_required">Title is required</string>
<string name="create_collection_description">Description (optional):</string> <string name="create_collection_description">Description (optional):</string>
<string name="create_collection_home_set">Home set:</string> <string name="create_collection_home_set">Home set:</string>
<string name="delete_collection">Delete collection</string> <string name="delete_collection">Delete collection</string>
......
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/app_settings_user_interface">
<Preference
android:key="reset_hints"
android:title="@string/app_settings_reset_hints"
android:summary="@string/app_settings_reset_hints_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/app_settings_security">
<Preference
android:key="reset_certificates"
android:title="@string/app_settings_reset_trusted_certificates"
android:summary="@string/app_settings_reset_trusted_certificates_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/app_settings_debug">
<SwitchPreferenceCompat
android:key="log_to_file"
android:title="@string/app_settings_log_to_file"
android:summaryOn="@string/app_settings_log_to_file_on"
android:summaryOff="@string/app_settings_log_to_file_off"/>
</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