Improve Settings

This commit is contained in:
seven332 committed 2016-03-16 19:28:13 +08:00
1 parent 37bec12843
commit 896d731069
10 files changed
+145 -14

No files matched your search

@@ -33,6 +33,7 @@ public class AppConfig {
private static final String IMAGE = "image";
private static final String CRASH = "crash";
private static final String PARSE_ERROR = "parse_error";
private static final String LOGCAT = "logcat";
private static Context sContext;
@@ -97,6 +98,11 @@ public class AppConfig {
return getDirInExternalAppDir(PARSE_ERROR);
}
@Nullable
public static File getExternalLogcatDir() {
return getDirInExternalAppDir(LOGCAT);
}
@Nullable
public static File createExternalTempFile() {
return FileUtils.createTempFile(getExternalTempDir(), null);
@@ -57,6 +57,7 @@ public class AboutFragment extends PreferenceFragment
Preference checkForUpdate = findPreference(KEY_CHECK_FOR_UPDATES);
author.setSummary(getString(R.string.settings_about_author_summary).replace('$', '@'));
donate.setSummary(getString(R.string.settings_about_donate_summary).replace('$', '@'));
author.setOnPreferenceClickListener(this);
googlePlus.setOnPreferenceClickListener(this);
@@ -16,16 +16,52 @@
package com.hippo.ehviewer.ui.fragment;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.widget.Toast;
import com.hippo.ehviewer.AppConfig;
import com.hippo.ehviewer.R;
import com.hippo.util.LogCat;
import com.hippo.util.ReadableTime;
public class AdvancedFragment extends PreferenceFragment {
import java.io.File;
public class AdvancedFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {
private static final String KEY_DUMP_LOGCAT = "dump_logcat";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.advanced_settings);
Preference dumpLogcat = findPreference(KEY_DUMP_LOGCAT);
dumpLogcat.setOnPreferenceClickListener(this);
}
@Override
public boolean onPreferenceClick(Preference preference) {
String key = preference.getKey();
if (KEY_DUMP_LOGCAT.equals(key)) {
boolean ok;
File file = null;
File dir = AppConfig.getExternalLogcatDir();
if (dir != null) {
file = new File(dir, "logcat-" + ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt");
ok = LogCat.save(file);
} else {
ok = false;
}
Resources resources = getResources();
Toast.makeText(getActivity(),
ok ? resources.getString(R.string.settings_about_dump_logcat_to, file.getPath()) :
resources.getString(R.string.settings_about_dump_logcat_failed), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
}
@@ -0,0 +1,45 @@
/*
* Copyright 2015 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.util;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public final class LogCat {
private LogCat() {
}
public static boolean save(File file) {
if (!FileUtils.ensureFile(file)) {
return false;
}
try {
Process p = Runtime.getRuntime().exec("logcat -d");
IOUtils.copy(p.getInputStream(), new FileOutputStream(file));
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}