If you think the Android project bitfynd-wallet-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2014 the original author or authors.
*//www.java2s.com
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package de.schildbach.wallet.ui.preference;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.support.annotation.NonNull;
import de.schildbach.wallet.Constants;
import de.schildbach.wallet.WalletApplication;
import de.schildbach.wallet.ui.DialogBuilder;
import de.schildbach.wallet.ui.ReportIssueDialogBuilder;
import de.schildbach.wallet.util.CrashReporter;
import de.schildbach.wallet.R;
/**
* @author Andreas Schildbach
*/publicfinalclass DiagnosticsFragment extends PreferenceFragment
{
private Activity activity;
private WalletApplication application;
privatestaticfinal String PREFS_KEY_REPORT_ISSUE = "report_issue";
privatestaticfinal String PREFS_KEY_INITIATE_RESET = "initiate_reset";
privatestaticfinal Logger log = LoggerFactory.getLogger(DiagnosticsFragment.class);
@Override
publicvoid onAttach(final Activity activity)
{
super.onAttach(activity);
this.activity = activity;
this.application = (WalletApplication) activity.getApplication();
}
@Override
publicvoid onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_diagnostics);
}
@Override
publicboolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, @NonNull final Preference preference)
{
final String key = preference.getKey();
if (PREFS_KEY_REPORT_ISSUE.equals(key))
{
handleReportIssue();
return true;
}
elseif (PREFS_KEY_INITIATE_RESET.equals(key))
{
handleInitiateReset();
return true;
}
return false;
}
publicvoid handleReportIssue()
{
final ReportIssueDialogBuilder dialog = new ReportIssueDialogBuilder(activity, R.string.report_issue_dialog_title_issue,
R.string.report_issue_dialog_message_issue)
{
@Override
protected CharSequence subject()
{
return Constants.REPORT_SUBJECT_ISSUE + " " + application.packageInfo().versionName;
}
@Override
protected CharSequence collectApplicationInfo() throws IOException
{
final StringBuilder applicationInfo = new StringBuilder();
CrashReporter.appendApplicationInfo(applicationInfo, application);
return applicationInfo;
}
@Override
protected CharSequence collectStackTrace()
{
return null;
}
@Override
protected CharSequence collectDeviceInfo() throws IOException
{
final StringBuilder deviceInfo = new StringBuilder();
CrashReporter.appendDeviceInfo(deviceInfo, activity);
return deviceInfo;
}
@Override
protected CharSequence collectWalletDump()
{
return application.getWallet().toString(false, true, true, null);
}
};
dialog.show();
}
publicvoid handleInitiateReset()
{
final DialogBuilder dialog = new DialogBuilder(activity);
dialog.setTitle(R.string.preferences_initiate_reset_title);
dialog.setMessage(R.string.preferences_initiate_reset_dialog_message);
dialog.setPositiveButton(R.string.preferences_initiate_reset_dialog_positive, new OnClickListener()
{
@Override
publicvoid onClick(final DialogInterface dialog, finalint which)
{
log.info("manually initiated blockchain reset");
application.resetBlockchain();
activity.finish(); // TODO doesn't fully finish prefs on single pane layouts
}
});
dialog.setNegativeButton(R.string.button_dismiss, null);
dialog.show();
}
}