Add analytics settings

This commit is contained in:
seven332 committed 2016-03-07 17:38:03 +08:00
1 parent 5b6b6f63b2
commit 1851ce0ab7
9 files changed
+120 -5

No files matched your search

@@ -392,7 +392,7 @@ public class Settings {
putBoolean(KEY_ASK_ANALYTICS, value);
}
private static final String KEY_ENABLE_ANALYTICS = "enable_analytics";
public static final String KEY_ENABLE_ANALYTICS = "enable_analytics";
private static final boolean DEFAULT_ENABLE_ANALYTICS = false;
public static boolean getEnableAnalytics() {
@@ -17,15 +17,32 @@
package com.hippo.ehviewer.ui.fragment;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import com.hippo.ehviewer.Analytics;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
public class AboutFragment extends PreferenceFragment {
public class AboutFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.about_settings);
Preference enableAnalytics = findPreference(Settings.KEY_ENABLE_ANALYTICS);
enableAnalytics.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (Settings.KEY_ENABLE_ANALYTICS.equals(key)) {
if (newValue instanceof Boolean && (Boolean) newValue) {
Analytics.start(getActivity());
}
}
return true;
}
}
@@ -0,0 +1,75 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.preference;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import com.hippo.ehviewer.R;
import com.hippo.text.Html;
// TODO Add html attr
// TODO Add url clickable
public class SimpleDialogPreference extends DialogPreference {
private CharSequence mMessage;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SimpleDialogPreference(Context context) {
super(context);
init(context, null, 0, 0);
}
public SimpleDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0, 0);
}
public SimpleDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr, 0);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SimpleDialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs, defStyleAttr, defStyleRes);
}
public void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SimpleDialogPreference, defStyleAttr, defStyleRes);
setMessage(a.getString(R.styleable.SimpleDialogPreference_message));
a.recycle();
}
public void setMessage(String message) {
mMessage = Html.fromHtml(message);
}
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
builder.setMessage(mMessage);
builder.setPositiveButton(android.R.string.ok, null);
builder.setNegativeButton(null, null);
}
}