Android Open Source - neoscoin-wallet Preferences Activity






From Project

Back to project page neoscoin-wallet.

License

The source code is released under:

GNU General Public License

If you think the Android project neoscoin-wallet 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 2011-2014 the original author or authors.
 *//  www  .j a va  2  s .c  o  m
 * 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;

import java.io.IOException;

import javax.annotation.Nonnull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
import com.actionbarsherlock.view.MenuItem;

import de.schildbach.wallet.Configuration;
import de.schildbach.wallet.Constants;
import de.schildbach.wallet.WalletApplication;
import de.schildbach.wallet.util.CrashReporter;
import katastrophos.neoscoin.wallet.R;

/**
 * @author Andreas Schildbach
 */
public final class PreferencesActivity extends SherlockPreferenceActivity implements OnPreferenceChangeListener
{
  private WalletApplication application;
  private Preference trustedPeerPreference;
  private Preference trustedPeerOnlyPreference;

  private static final String PREFS_KEY_REPORT_ISSUE = "report_issue";
  private static final String PREFS_KEY_INITIATE_RESET = "initiate_reset";
  private static final String PREFS_KEY_DATA_USAGE = "data_usage";

  private static final Intent dataUsageIntent = new Intent();
  static
  {
    dataUsageIntent.setComponent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH ? new ComponentName("com.android.settings",
        "com.android.settings.Settings$DataUsageSummaryActivity") : new ComponentName("com.android.phone", "com.android.phone.Settings"));
  }

  private static final Logger log = LoggerFactory.getLogger(PreferencesActivity.class);

  @Override
  protected void onCreate(final Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);

    application = (WalletApplication) getApplication();
    addPreferencesFromResource(R.xml.preferences);

    trustedPeerPreference = findPreference(Configuration.PREFS_KEY_TRUSTED_PEER);
    trustedPeerPreference.setOnPreferenceChangeListener(this);

    trustedPeerOnlyPreference = findPreference(Configuration.PREFS_KEY_TRUSTED_PEER_ONLY);
    trustedPeerOnlyPreference.setOnPreferenceChangeListener(this);

    final Preference dataUsagePreference = findPreference(PREFS_KEY_DATA_USAGE);
    dataUsagePreference.setEnabled(getPackageManager().resolveActivity(dataUsageIntent, 0) != null);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
    final String trustedPeer = prefs.getString(Configuration.PREFS_KEY_TRUSTED_PEER, "").trim();
    updateTrustedPeer(trustedPeer);
  }

  @Override
  protected void onDestroy()
  {
    trustedPeerPreference.setOnPreferenceChangeListener(null);

    super.onDestroy();
  }

  @Override
  public boolean onOptionsItemSelected(final MenuItem item)
  {
    switch (item.getItemId())
    {
      case android.R.id.home:
        finish();
        return true;
    }

    return super.onOptionsItemSelected(item);
  }

  @Override
  public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, final Preference preference)
  {
    final String key = preference.getKey();

    if (PREFS_KEY_DATA_USAGE.equals(key))
    {
      startActivity(dataUsageIntent);
      finish();
    }
    else if (PREFS_KEY_REPORT_ISSUE.equals(key))
    {
      final ReportIssueDialogBuilder dialog = new ReportIssueDialogBuilder(this, 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, PreferencesActivity.this);
          return deviceInfo;
        }

        @Override
        protected CharSequence collectWalletDump()
        {
          return application.getWallet().toString(false, true, true, null);
        }
      };

      dialog.show();

      return true;
    }
    else if (PREFS_KEY_INITIATE_RESET.equals(key))
    {
      final DialogBuilder dialog = new DialogBuilder(this);
      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
        public void onClick(final DialogInterface dialog, final int which)
        {
          log.info("manually initiated blockchain reset");

          application.resetBlockchain();
          finish();
        }
      });
      dialog.setNegativeButton(R.string.button_dismiss, null);
      dialog.show();

      return true;
    }

    return false;
  }

  @Override
  public boolean onPreferenceChange(final Preference preference, final Object newValue)
  {
    if (preference.equals(trustedPeerPreference))
    {
      application.stopBlockchainService();
      updateTrustedPeer((String) newValue);
    }
    else if (preference.equals(trustedPeerOnlyPreference))
    {
      application.stopBlockchainService();
    }

    return true;
  }

  private void updateTrustedPeer(@Nonnull final String trustedPeer)
  {
    if (trustedPeer.isEmpty())
    {
      trustedPeerPreference.setSummary(R.string.preferences_trusted_peer_summary);
      trustedPeerOnlyPreference.setEnabled(false);
    }
    else
    {
      trustedPeerPreference.setSummary(trustedPeer);
      trustedPeerOnlyPreference.setEnabled(true);
    }
  }
}




Java Source Code List

de.schildbach.wallet.AddressBookProvider.java
de.schildbach.wallet.Configuration.java
de.schildbach.wallet.Constants.java
de.schildbach.wallet.ExchangeRatesProvider.java
de.schildbach.wallet.PaymentIntent.java
de.schildbach.wallet.WalletApplication.java
de.schildbach.wallet.WalletBalanceWidgetProvider.java
de.schildbach.wallet.camera.CameraManager.java
de.schildbach.wallet.integration.android.BitcoinIntegration.java
de.schildbach.wallet.integration.sample.SampleActivity.java
de.schildbach.wallet.offline.AcceptBluetoothService.java
de.schildbach.wallet.offline.AcceptBluetoothThread.java
de.schildbach.wallet.offline.DirectPaymentTask.java
de.schildbach.wallet.service.AutosyncReceiver.java
de.schildbach.wallet.service.BlockchainServiceImpl.java
de.schildbach.wallet.service.BlockchainService.java
de.schildbach.wallet.ui.AboutActivity.java
de.schildbach.wallet.ui.AbstractBindServiceActivity.java
de.schildbach.wallet.ui.AbstractOnDemandServiceActivity.java
de.schildbach.wallet.ui.AbstractWalletActivity.java
de.schildbach.wallet.ui.AddressAndLabel.java
de.schildbach.wallet.ui.AddressBookActivity.java
de.schildbach.wallet.ui.BlockListFragment.java
de.schildbach.wallet.ui.CurrencyAmountView.java
de.schildbach.wallet.ui.CurrencyCalculatorLink.java
de.schildbach.wallet.ui.CurrencySymbolDrawable.java
de.schildbach.wallet.ui.CurrencyTextView.java
de.schildbach.wallet.ui.DialogBuilder.java
de.schildbach.wallet.ui.EditAddressBookEntryFragment.java
de.schildbach.wallet.ui.ExchangeRateLoader.java
de.schildbach.wallet.ui.ExchangeRatesActivity.java
de.schildbach.wallet.ui.ExchangeRatesFragment.java
de.schildbach.wallet.ui.FileAdapter.java
de.schildbach.wallet.ui.HelpDialogFragment.java
de.schildbach.wallet.ui.ImportDialogButtonEnablerListener.java
de.schildbach.wallet.ui.ImportKeysActivity.java
de.schildbach.wallet.ui.InputParser.java
de.schildbach.wallet.ui.NetworkMonitorActivity.java
de.schildbach.wallet.ui.PeerListFragment.java
de.schildbach.wallet.ui.PreferencesActivity.java
de.schildbach.wallet.ui.ProgressDialogFragment.java
de.schildbach.wallet.ui.ReportIssueDialogBuilder.java
de.schildbach.wallet.ui.RequestCoinsActivity.java
de.schildbach.wallet.ui.RequestCoinsFragment.java
de.schildbach.wallet.ui.RequestPaymentRequestTask.java
de.schildbach.wallet.ui.ScanActivity.java
de.schildbach.wallet.ui.ScannerView.java
de.schildbach.wallet.ui.SendCoinsActivity.java
de.schildbach.wallet.ui.SendCoinsFragment.java
de.schildbach.wallet.ui.SendCoinsOfflineTask.java
de.schildbach.wallet.ui.SendCoinsQrActivity.java
de.schildbach.wallet.ui.SendingAddressesFragment.java
de.schildbach.wallet.ui.ShowPasswordCheckListener.java
de.schildbach.wallet.ui.TransactionActivity.java
de.schildbach.wallet.ui.TransactionFragment.java
de.schildbach.wallet.ui.TransactionsListAdapter.java
de.schildbach.wallet.ui.TransactionsListFragment.java
de.schildbach.wallet.ui.WalletActionsFragment.java
de.schildbach.wallet.ui.WalletActivity.java
de.schildbach.wallet.ui.WalletAddressFragment.java
de.schildbach.wallet.ui.WalletAddressesAdapter.java
de.schildbach.wallet.ui.WalletAddressesFragment.java
de.schildbach.wallet.ui.WalletBalanceFragment.java
de.schildbach.wallet.ui.WalletBalanceLoader.java
de.schildbach.wallet.ui.WalletDisclaimerFragment.java
de.schildbach.wallet.ui.WalletTransactionsFragment.java
de.schildbach.wallet.util.AbstractClipboardManager.java
de.schildbach.wallet.util.Base43.java
de.schildbach.wallet.util.BitmapFragment.java
de.schildbach.wallet.util.Bluetooth.java
de.schildbach.wallet.util.CircularProgressView.java
de.schildbach.wallet.util.CrashReporter.java
de.schildbach.wallet.util.Crypto.java
de.schildbach.wallet.util.GenericUtils.java
de.schildbach.wallet.util.HttpGetThread.java
de.schildbach.wallet.util.Io.java
de.schildbach.wallet.util.Iso8601Format.java
de.schildbach.wallet.util.LinuxSecureRandom.java
de.schildbach.wallet.util.Nfc.java
de.schildbach.wallet.util.PaymentProtocol.java
de.schildbach.wallet.util.Qr.java
de.schildbach.wallet.util.ThrottlingWalletChangeListener.java
de.schildbach.wallet.util.ViewPagerTabs.java
de.schildbach.wallet.util.WalletUtils.java