Search in sources :

Example 86 with InputFilter

use of android.text.InputFilter in project samourai-wallet-android by Samourai-Wallet.

the class SendActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_send);
    setSupportActionBar(findViewById(R.id.toolbar_send));
    Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
    setTitle("");
    // CustomView for showing and hiding body of th UI
    sendTransactionDetailsView = findViewById(R.id.sendTransactionDetailsView);
    // ViewSwitcher Element for toolbar section of the UI.
    // we can switch between Form and review screen with this element
    amountViewSwitcher = findViewById(R.id.toolbar_view_switcher);
    // Input elements from toolbar section of the UI
    toAddressEditText = findViewById(R.id.edt_send_to);
    btcEditText = findViewById(R.id.amountBTC);
    satEditText = findViewById(R.id.amountSat);
    tvToAddress = findViewById(R.id.to_address_review);
    tvReviewSpendAmount = findViewById(R.id.send_review_amount);
    tvReviewSpendAmountInSats = findViewById(R.id.send_review_amount_in_sats);
    tvMaxAmount = findViewById(R.id.totalBTC);
    // view elements from review segment and transaction segment can be access through respective
    // methods which returns root viewGroup
    btnReview = sendTransactionDetailsView.getTransactionView().findViewById(R.id.review_button);
    cahootsSwitch = sendTransactionDetailsView.getTransactionView().findViewById(R.id.cahoots_switch);
    ricochetHopsSwitch = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_hops_switch);
    ricochetTitle = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_desc);
    ricochetDesc = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_title);
    ricochetStaggeredDelivery = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_staggered_option);
    ricochetStaggeredOptionGroup = sendTransactionDetailsView.getTransactionView().findViewById(R.id.ricochet_staggered_option_group);
    tvSelectedFeeRate = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.selected_fee_rate);
    tvSelectedFeeRateLayman = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.selected_fee_rate_in_layman);
    tvTotalFee = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.total_fee);
    btnSend = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.send_btn);
    feeSeekBar = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.fee_seekbar);
    tvEstimatedBlockWait = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.est_block_time);
    feeSeekBar = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.fee_seekbar);
    cahootsGroup = sendTransactionDetailsView.findViewById(R.id.cohoots_options);
    cahootsStatusText = sendTransactionDetailsView.findViewById(R.id.cahoot_status_text);
    totalMinerFeeLayout = sendTransactionDetailsView.getTransactionReview().findViewById(R.id.total_miner_fee_group);
    cahootsNotice = sendTransactionDetailsView.findViewById(R.id.cahoots_not_enabled_notice);
    btcEditText.addTextChangedListener(BTCWatcher);
    btcEditText.setFilters(new InputFilter[] { new DecimalDigitsInputFilter(8, 8) });
    satEditText.addTextChangedListener(satWatcher);
    toAddressEditText.addTextChangedListener(AddressWatcher);
    btnReview.setOnClickListener(v -> review());
    btnSend.setOnClickListener(v -> initiateSpend());
    View.OnClickListener clipboardCopy = view -> {
        ClipboardManager cm = (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = android.content.ClipData.newPlainText("Miner fee", tvTotalFee.getText());
        if (cm != null) {
            cm.setPrimaryClip(clipData);
            Toast.makeText(this, getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
        }
    };
    tvTotalFee.setOnClickListener(clipboardCopy);
    tvSelectedFeeRate.setOnClickListener(clipboardCopy);
    SPEND_TYPE = SPEND_BOLTZMANN;
    saveChangeIndexes();
    setUpRicochet();
    setUpCahoots();
    setUpFee();
    setBalance();
    enableReviewButton(false);
    setUpBoltzman();
    validateSpend();
    checkDeepLinks();
    if (getIntent().getExtras().containsKey("preselected")) {
        preselectedUTXOs = PreSelectUtil.getInstance().getPreSelected(getIntent().getExtras().getString("preselected"));
        setBalance();
        if (preselectedUTXOs != null && preselectedUTXOs.size() > 0) {
            cahootsGroup.setVisibility(View.GONE);
            ricochetHopsSwitch.setVisibility(View.GONE);
            ricochetTitle.setVisibility(View.GONE);
            ricochetDesc.setVisibility(View.GONE);
        }
    } else {
        Disposable disposable = APIFactory.getInstance(getApplicationContext()).walletBalanceObserver.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(aLong -> {
            if (balance == aLong) {
                return;
            }
            setBalance();
        }, Throwable::printStackTrace);
        compositeDisposables.add(disposable);
        // Update fee
        Disposable feeDisposable = Observable.fromCallable(() -> APIFactory.getInstance(getApplicationContext()).getDynamicFees()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(t -> {
            Log.i(TAG, "Fees : ".concat(t.toString()));
            setUpFee();
        }, Throwable::printStackTrace);
        compositeDisposables.add(feeDisposable);
        if (getIntent().getExtras() != null) {
            if (!getIntent().getExtras().containsKey("balance")) {
                return;
            }
            balance = getIntent().getExtras().getLong("balance");
        }
    }
}
Also used : MonetaryUtil(com.samourai.wallet.util.MonetaryUtil) BIP47Util(com.samourai.wallet.bip47.BIP47Util) Bundle(android.os.Bundle) Completable(io.reactivex.Completable) Uri(android.net.Uri) Group(android.support.constraint.Group) WhirlpoolMeta(com.samourai.wallet.whirlpool.WhirlpoolMeta) Cahoots(com.samourai.wallet.cahoots.Cahoots) JSONException(org.json.JSONException) Vector(java.util.Vector) UTXOSActivity(com.samourai.wallet.utxos.UTXOSActivity) Handler(android.os.Handler) Looper(android.os.Looper) Map(java.util.Map) ClipboardManager(android.content.ClipboardManager) BigInteger(java.math.BigInteger) Triple(org.apache.commons.lang3.tuple.Triple) Log(android.util.Log) ContextCompat(android.support.v4.content.ContextCompat) TxosLinkerOptionEnum(com.samourai.boltzmann.linker.TxosLinkerOptionEnum) AppUtil(com.samourai.wallet.util.AppUtil) TorManager(com.samourai.wallet.tor.TorManager) TransactionOutput(org.bitcoinj.core.TransactionOutput) BIP47Meta(com.samourai.wallet.bip47.BIP47Meta) Snackbar(android.support.design.widget.Snackbar) InputFilter(android.text.InputFilter) TextWatcher(android.text.TextWatcher) FormatsUtil(com.samourai.wallet.util.FormatsUtil) DecimalDigitsInputFilter(com.samourai.wallet.util.DecimalDigitsInputFilter) AddressFactory(com.samourai.wallet.util.AddressFactory) Editable(android.text.Editable) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) TxAnimUIActivity(com.samourai.wallet.TxAnimUIActivity) SeekBar(android.widget.SeekBar) SamouraiWallet(com.samourai.wallet.SamouraiWallet) Toast(android.widget.Toast) Menu(android.view.Menu) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress) Observable(io.reactivex.Observable) RicochetMeta(com.samourai.wallet.ricochet.RicochetMeta) CharSequenceX(com.samourai.wallet.util.CharSequenceX) BoltzmannSettings(com.samourai.boltzmann.beans.BoltzmannSettings) Bech32Util(com.samourai.wallet.segwit.bech32.Bech32Util) IOException(java.io.IOException) TypedValue(android.util.TypedValue) Observer(io.reactivex.Observer) PaynymSelectModalFragment(com.samourai.wallet.fragments.PaynymSelectModalFragment) ConstraintLayout(android.support.constraint.ConstraintLayout) APIFactory(com.samourai.wallet.api.APIFactory) EditText(android.widget.EditText) HD_WalletFactory(com.samourai.wallet.hd.HD_WalletFactory) PrefsUtil(com.samourai.wallet.util.PrefsUtil) LinearLayout(android.widget.LinearLayout) Switch(android.widget.Switch) Transaction(org.bitcoinj.core.Transaction) URLDecoder(java.net.URLDecoder) Coin(org.bitcoinj.core.Coin) DecimalFormatSymbols(java.text.DecimalFormatSymbols) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) JSONObject(org.json.JSONObject) CheckBox(android.widget.CheckBox) TxProcessor(com.samourai.boltzmann.processor.TxProcessor) Locale(java.util.Locale) SamouraiActivity(com.samourai.wallet.SamouraiActivity) View(android.view.View) Button(android.widget.Button) ManualCahootsActivity(com.samourai.wallet.send.cahoots.ManualCahootsActivity) Schedulers(io.reactivex.schedulers.Schedulers) ParseException(java.text.ParseException) Splitter(com.google.common.base.Splitter) AccessFactory(com.samourai.wallet.access.AccessFactory) WebUtil(com.samourai.wallet.util.WebUtil) ViewSwitcher(android.widget.ViewSwitcher) PreSelectUtil(com.samourai.wallet.utxos.PreSelectUtil) SendAddressUtil(com.samourai.wallet.util.SendAddressUtil) ViewGroup(android.view.ViewGroup) BIP84Util(com.samourai.wallet.segwit.BIP84Util) AlertDialog(android.app.AlertDialog) Objects(java.util.Objects) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Script(org.bitcoinj.script.Script) Address(org.bitcoinj.core.Address) Txos(com.samourai.boltzmann.beans.Txos) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Typeface(android.graphics.Typeface) Context(android.content.Context) Intent(android.content.Intent) HashMap(java.util.HashMap) PayloadUtil(com.samourai.wallet.payload.PayloadUtil) BIP49Util(com.samourai.wallet.segwit.BIP49Util) MnemonicException(org.bitcoinj.crypto.MnemonicException) CahootsUtil(com.samourai.wallet.cahoots.CahootsUtil) SendTransactionDetailsView(com.samourai.wallet.widgets.SendTransactionDetailsView) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) Hex(org.bouncycastle.util.encoders.Hex) ClipData(android.content.ClipData) SelectCahootsType(com.samourai.wallet.send.cahoots.SelectCahootsType) RicochetActivity(com.samourai.wallet.ricochet.RicochetActivity) DialogInterface(android.content.DialogInterface) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress) CompoundButton(android.widget.CompoundButton) PayNymDetailsActivity(com.samourai.wallet.paynym.paynymDetails.PayNymDetailsActivity) DecimalFormat(java.text.DecimalFormat) R(com.samourai.wallet.R) PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) TxProcessorResult(com.samourai.boltzmann.processor.TxProcessorResult) BatchSendActivity(com.samourai.wallet.BatchSendActivity) TimeUnit(java.util.concurrent.TimeUnit) CameraFragmentBottomSheet(com.samourai.wallet.fragments.CameraFragmentBottomSheet) Activity(android.app.Activity) Collections(java.util.Collections) JSONArray(org.json.JSONArray) ClipboardManager(android.content.ClipboardManager) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) DecimalDigitsInputFilter(com.samourai.wallet.util.DecimalDigitsInputFilter) View(android.view.View) TextView(android.widget.TextView) SendTransactionDetailsView(com.samourai.wallet.widgets.SendTransactionDetailsView) ClipData(android.content.ClipData)

Example 87 with InputFilter

use of android.text.InputFilter in project android-client by GenesisVision.

the class ChangePasswordActivity method setInputFilters.

private void setInputFilters() {
    InputFilter filter = (source, start, end, dest, dstart, dend) -> {
        for (int i = start; i < end; i++) {
            if (Character.isWhitespace(source.charAt(i))) {
                return "";
            }
        }
        return null;
    };
    oldPassword.setFilters(new InputFilter[] { filter });
    newPassword.setFilters(new InputFilter[] { filter });
    repeatPassword.setFilters(new InputFilter[] { filter });
}
Also used : InjectPresenter(com.arellomobile.mvp.presenter.InjectPresenter) PrimaryButton(vision.genesis.clientapp.ui.PrimaryButton) TypefaceUtil(vision.genesis.clientapp.utils.TypefaceUtil) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) ButterKnife(butterknife.ButterKnife) TextInputLayout(com.google.android.material.textfield.TextInputLayout) BaseSwipeBackActivity(vision.genesis.clientapp.feature.BaseSwipeBackActivity) R(vision.genesis.clientapp.R) Intent(android.content.Intent) MessageBottomSheetDialog(vision.genesis.clientapp.feature.main.message.MessageBottomSheetDialog) ThemeUtil(vision.genesis.clientapp.utils.ThemeUtil) OnClick(butterknife.OnClick) BindView(butterknife.BindView) TextView(android.widget.TextView) OnEditorAction(butterknife.OnEditorAction) View(android.view.View) InputFilter(android.text.InputFilter) Activity(android.app.Activity) EditorInfo(android.view.inputmethod.EditorInfo) EditText(android.widget.EditText) InputFilter(android.text.InputFilter)

Example 88 with InputFilter

use of android.text.InputFilter in project android-client by GenesisVision.

the class SetupAccountTfaActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(ThemeUtil.getCurrentThemeResource());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup_account_two_factor);
    ButterKnife.bind(this);
    Bundle extras = getIntent().getExtras();
    if (extras != null && !extras.isEmpty()) {
        UUID id = (UUID) extras.getSerializable(EXTRA_ID);
        if (id != null) {
            presenter.setData(id);
            InputFilter[] filters = new InputFilter[1];
            filters[0] = new InputFilter.LengthFilter(Constants.TWO_FACTOR_CODE_LENGTH);
            code.setFilters(filters);
            return;
        }
    }
    Timber.e("Passed empty data to %s", getClass().getSimpleName());
    onBackPressed();
}
Also used : InputFilter(android.text.InputFilter) Bundle(android.os.Bundle) UUID(java.util.UUID)

Example 89 with InputFilter

use of android.text.InputFilter in project android_packages_apps_Settings by omnirom.

the class Utf8ByteLengthFilterTest method testFilter.

@SmallTest
public void testFilter() {
    // Define the variables
    CharSequence source;
    SpannableStringBuilder dest;
    // Constructor to create a LengthFilter
    InputFilter lengthFilter = new Utf8ByteLengthFilter(10);
    InputFilter[] filters = { lengthFilter };
    // filter() implicitly invoked. If the total length > filter length, the filter will
    // cut off the source CharSequence from beginning to fit the filter length.
    source = "abc";
    dest = new SpannableStringBuilder("abcdefgh");
    dest.setFilters(filters);
    dest.insert(1, source);
    String expectedString1 = "aabbcdefgh";
    assertEquals(expectedString1, dest.toString());
    dest.replace(5, 8, source);
    String expectedString2 = "aabbcabcgh";
    assertEquals(expectedString2, dest.toString());
    dest.insert(2, source);
    assertEquals(expectedString2, dest.toString());
    dest.delete(1, 3);
    String expectedString3 = "abcabcgh";
    assertEquals(expectedString3, dest.toString());
    dest.append("12345");
    String expectedString4 = "abcabcgh12";
    assertEquals(expectedString4, dest.toString());
    // 2 Chinese chars == 6 bytes in UTF-8
    source = "\u60a8\u597d";
    dest.replace(8, 10, source);
    assertEquals(expectedString3, dest.toString());
    dest.replace(0, 1, source);
    String expectedString5 = "\u60a8bcabcgh";
    assertEquals(expectedString5, dest.toString());
    dest.replace(0, 4, source);
    String expectedString6 = "\u60a8\u597dbcgh";
    assertEquals(expectedString6, dest.toString());
    // 2 Latin-1 chars == 4 bytes in UTF-8
    source = "\u00a3\u00a5";
    dest.delete(2, 6);
    dest.insert(0, source);
    String expectedString7 = "\u00a3\u00a5\u60a8\u597d";
    assertEquals(expectedString7, dest.toString());
    dest.replace(2, 3, source);
    String expectedString8 = "\u00a3\u00a5\u00a3\u597d";
    assertEquals(expectedString8, dest.toString());
    dest.replace(3, 4, source);
    String expectedString9 = "\u00a3\u00a5\u00a3\u00a3\u00a5";
    assertEquals(expectedString9, dest.toString());
    // filter() explicitly invoked
    dest = new SpannableStringBuilder("abcdefgh");
    CharSequence beforeFilterSource = "TestLengthFilter";
    String expectedAfterFilter = "TestLength";
    CharSequence actualAfterFilter = lengthFilter.filter(beforeFilterSource, 0, beforeFilterSource.length(), dest, 0, dest.length());
    assertEquals(expectedAfterFilter, actualAfterFilter);
}
Also used : InputFilter(android.text.InputFilter) SpannableStringBuilder(android.text.SpannableStringBuilder) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 90 with InputFilter

use of android.text.InputFilter in project smoke by textbrowser.

the class Settings method prepareListeners.

private void prepareListeners() {
    Button button1 = null;
    Spinner spinner1 = (Spinner) findViewById(R.id.neighbors_transport);
    Switch switch1 = null;
    TextView textView1 = (TextView) findViewById(R.id.participant_name);
    button1 = (Button) findViewById(R.id.add_neighbor);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            addNeighbor();
        }
    });
    button1 = (Button) findViewById(R.id.add_participant);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            addParticipant();
        }
    });
    button1 = (Button) findViewById(R.id.clear_log);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            m_databaseHelper.clearTable("log");
        }
    });
    button1 = (Button) findViewById(R.id.echo_help);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            PopupWindow popupWindow = new PopupWindow(Settings.this);
            TextView textView1 = new TextView(Settings.this);
            float density = Settings.this.getResources().getDisplayMetrics().density;
            textView1.setBackgroundColor(Color.rgb(232, 234, 246));
            textView1.setPaddingRelative((int) (10 * density), (int) (10 * density), (int) (10 * density), (int) (10 * density));
            textView1.setText("Echo queues allow Smoke to echo internal data from " + "local neighbor to local neighbor. Each Echo queue may " + "contain at most " + Neighbor.MAXIMUM_QUEUED_ECHO_PACKETS + " messages. Please note that the " + "Echo mechanism may burden a device. A neighbor will " + "echo data if it discovers that the data are not " + "intended for it.");
            textView1.setTextSize(16);
            popupWindow.setContentView(textView1);
            popupWindow.setOutsideTouchable(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                popupWindow.setHeight(450);
                popupWindow.setWidth(700);
            }
            popupWindow.showAsDropDown(view);
        }
    });
    button1 = (Button) findViewById(R.id.epks);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            epks("");
        }
    });
    button1 = (Button) findViewById(R.id.generate_pki);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            preparePKI();
        }
    });
    button1 = (Button) findViewById(R.id.initialize_ozone_help);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            PopupWindow popupWindow = new PopupWindow(Settings.this);
            TextView textView1 = new TextView(Settings.this);
            float density = Settings.this.getResources().getDisplayMetrics().density;
            textView1.setBackgroundColor(Color.rgb(232, 234, 246));
            textView1.setPaddingRelative((int) (10 * density), (int) (10 * density), (int) (10 * density), (int) (10 * density));
            textView1.setText("Set the Ozone to IP Address:Port:Type.");
            textView1.setTextSize(16);
            popupWindow.setContentView(textView1);
            popupWindow.setOutsideTouchable(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                popupWindow.setHeight(450);
                popupWindow.setWidth(700);
            }
            popupWindow.showAsDropDown(view);
        }
    });
    button1 = (Button) findViewById(R.id.ozone_help);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            PopupWindow popupWindow = new PopupWindow(Settings.this);
            TextView textView1 = new TextView(Settings.this);
            float density = Settings.this.getResources().getDisplayMetrics().density;
            textView1.setBackgroundColor(Color.rgb(232, 234, 246));
            textView1.setPaddingRelative((int) (10 * density), (int) (10 * density), (int) (10 * density), (int) (10 * density));
            textView1.setText("An Ozone Address defines a virtual location, " + "a separate device where messages are to be stored for " + "later retrieval. A virtual post office. " + "Please remember to share your Ozone Address with your " + "friends as well as at least one SmokeStack.");
            textView1.setTextSize(16);
            popupWindow.setContentView(textView1);
            popupWindow.setOutsideTouchable(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                popupWindow.setHeight(450);
                popupWindow.setWidth(700);
            }
            popupWindow.showAsDropDown(view);
        }
    });
    button1 = (Button) findViewById(R.id.passthrough_help);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            PopupWindow popupWindow = new PopupWindow(Settings.this);
            TextView textView1 = new TextView(Settings.this);
            float density = Settings.this.getResources().getDisplayMetrics().density;
            textView1.setBackgroundColor(Color.rgb(232, 234, 246));
            textView1.setPaddingRelative((int) (10 * density), (int) (10 * density), (int) (10 * density), (int) (10 * density));
            textView1.setText("Passthrough neighbors are special full-duplex " + "connections which Smoke utilizes for distributing " + "data to non-Smoke destinations. Data which is " + "received on passthrough connections is echoed " + "directly to other non-passthrough neighbors if " + "echoing is enabled.");
            textView1.setTextSize(16);
            popupWindow.setContentView(textView1);
            popupWindow.setOutsideTouchable(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                popupWindow.setHeight(450);
                popupWindow.setWidth(700);
            }
            popupWindow.showAsDropDown(view);
        }
    });
    button1 = (Button) findViewById(R.id.refresh_neighbors);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            populateNeighbors(null);
        }
    });
    button1 = (Button) findViewById(R.id.refresh_participants);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            populateParticipants();
        }
    });
    final DialogInterface.OnCancelListener listener1 = new DialogInterface.OnCancelListener() {

        public void onCancel(DialogInterface dialog) {
            if (State.getInstance().getString("dialog_accepted").equals("true")) {
                State.getInstance().reset();
                m_databaseHelper.resetAndDrop();
                s_cryptography.reset();
                Intent intent = getIntent();
                startActivity(intent);
                finish();
            }
        }
    };
    button1 = (Button) findViewById(R.id.reset);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Miscellaneous.showPromptDialog(Settings.this, listener1, "Are you sure that you " + "wish to reset Smoke? All " + "of the data will be removed.");
        }
    });
    button1 = (Button) findViewById(R.id.reset_neighbor_fields);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            RadioButton radioButton1 = (RadioButton) findViewById(R.id.neighbors_ipv4);
            Spinner spinner1 = (Spinner) findViewById(R.id.neighbors_transport);
            Spinner spinner2 = (Spinner) findViewById(R.id.proxy_type);
            Switch switch1 = (Switch) findViewById(R.id.initialize_ozone);
            Switch switch2 = (Switch) findViewById(R.id.non_tls);
            Switch switch3 = (Switch) findViewById(R.id.passthrough);
            TextView proxyIpAddress = (TextView) findViewById(R.id.proxy_ip_address);
            TextView proxyPort = (TextView) findViewById(R.id.proxy_port);
            TextView textView1 = (TextView) findViewById(R.id.neighbors_ip_address);
            TextView textView2 = (TextView) findViewById(R.id.neighbors_port);
            TextView textView3 = (TextView) findViewById(R.id.neighbors_scope_id);
            switch1.setChecked(false);
            switch2.setChecked(false);
            switch3.setChecked(false);
            proxyIpAddress.setText("");
            proxyPort.setText("");
            radioButton1.setChecked(true);
            spinner1.setSelection(0);
            spinner2.setSelection(0);
            textView1.setText("");
            textView2.setText("4710");
            textView3.setText("");
            textView1.requestFocus();
        }
    });
    button1 = (Button) findViewById(R.id.reset_participants_fields);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            Switch switch1 = (Switch) findViewById(R.id.as_alias);
            TextView textView1 = (TextView) findViewById(R.id.participant_name);
            TextView textView2 = (TextView) findViewById(R.id.participant_siphash_id);
            switch1.setChecked(true);
            textView1.setText("");
            textView2.setText("");
            textView1.requestFocus();
        }
    });
    final DialogInterface.OnCancelListener listener2 = new DialogInterface.OnCancelListener() {

        public void onCancel(DialogInterface dialog) {
            if (State.getInstance().getString("dialog_accepted").equals("true")) {
                TextView textView1 = (TextView) findViewById(R.id.ozone);
                textView1.setText("");
                m_databaseHelper.reset();
                populateFancyKeyData();
                populateNeighbors(null);
                populateParticipants();
                prepareCredentials();
            }
        }
    };
    button1 = (Button) findViewById(R.id.save_alias);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            String alias = ((TextView) findViewById(R.id.alias)).getText().toString().trim();
            if (!alias.isEmpty() && alias.length() < 8)
                Miscellaneous.showErrorDialog(Settings.this, "A Smoke Alias must include at " + "least eight characters. ");
            else if (alias.isEmpty()) {
                m_databaseHelper.writeSetting(s_cryptography, "alias", "");
                s_cryptography.prepareSipHashIds(null);
                s_cryptography.prepareSipHashKeys();
            } else {
                if (m_databaseHelper.readSetting(s_cryptography, "fire_user_name").trim().isEmpty())
                    m_databaseHelper.writeSetting(s_cryptography, "fire_user_name", alias);
                m_databaseHelper.writeSetting(s_cryptography, "alias", alias);
                s_cryptography.prepareSipHashIds(alias);
                s_cryptography.prepareSipHashKeys();
            }
            StringBuilder stringBuilder = new StringBuilder();
            TextView textView1 = (TextView) findViewById(R.id.siphash_identity);
            stringBuilder.append(Miscellaneous.prepareSipHashId(s_cryptography.sipHashId()));
            textView1.setText(stringBuilder);
            textView1.setTextIsSelectable(true);
            textView1.setVisibility(View.VISIBLE);
        }
    });
    button1 = (Button) findViewById(R.id.save_ozone);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            TextView textView1 = (TextView) findViewById(R.id.ozone);
            if (!generateOzone(textView1.getText().toString())) {
                Miscellaneous.showErrorDialog(Settings.this, "An error occurred while processing the Ozone data.");
                textView1.requestFocus();
            }
        }
    });
    button1 = (Button) findViewById(R.id.set_password);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            Spinner spinner1 = null;
            TextView textView1 = (TextView) findViewById(R.id.password1);
            TextView textView2 = (TextView) findViewById(R.id.password2);
            textView1.setSelectAllOnFocus(true);
            textView2.setSelectAllOnFocus(true);
            if (textView1.getText().length() < 1 || !textView1.getText().toString().equals(textView2.getText().toString())) {
                String error = "";
                if (textView1.getText().length() < 1)
                    error = "Each password must contain " + "at least one character.";
                else
                    error = "The provided passwords are not identical.";
                Miscellaneous.showErrorDialog(Settings.this, error);
                textView1.requestFocus();
                return;
            }
            int iterationCount = 1000;
            int iterationCountLimit = 7500;
            try {
                spinner1 = (Spinner) findViewById(R.id.iteration_count);
                iterationCount = Integer.parseInt(spinner1.getSelectedItem().toString());
            } catch (Exception exception) {
                iterationCount = 1000;
            }
            spinner1 = (Spinner) findViewById(R.id.key_derivation_function);
            if (spinner1.getSelectedItem().toString().equals("Argon2id"))
                iterationCountLimit = 10;
            else
                iterationCountLimit = 7500;
            if (iterationCount > iterationCountLimit)
                Miscellaneous.showPromptDialog(Settings.this, listener2, "You have selected an elevated iteration count. " + "If you proceed, the initialization process may " + "require a significant amount of time to complete. " + "Continue?");
            else
                prepareCredentials();
        }
    });
    button1 = (Button) findViewById(R.id.share_via_ozone);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            shareSipHashId(-1);
        }
    });
    button1 = (Button) findViewById(R.id.silent_help);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            PopupWindow popupWindow = new PopupWindow(Settings.this);
            TextView textView1 = new TextView(Settings.this);
            float density = Settings.this.getResources().getDisplayMetrics().density;
            textView1.setBackgroundColor(Color.rgb(232, 234, 246));
            textView1.setPaddingRelative((int) (10 * density), (int) (10 * density), (int) (10 * density), (int) (10 * density));
            textView1.setText("Disable all status broadcasts. Please note that " + "remote servers may terminate silent connections.");
            textView1.setTextSize(16);
            popupWindow.setContentView(textView1);
            popupWindow.setOutsideTouchable(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                popupWindow.setHeight(450);
                popupWindow.setWidth(700);
            }
            popupWindow.showAsDropDown(view);
        }
    });
    button1 = (Button) findViewById(R.id.siphash_help);
    button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            if (Settings.this.isFinishing())
                return;
            PopupWindow popupWindow = new PopupWindow(Settings.this);
            TextView textView1 = new TextView(Settings.this);
            float density = Settings.this.getResources().getDisplayMetrics().density;
            textView1.setBackgroundColor(Color.rgb(232, 234, 246));
            textView1.setPaddingRelative((int) (10 * density), (int) (10 * density), (int) (10 * density), (int) (10 * density));
            if (((Switch) findViewById(R.id.as_alias)).isChecked())
                textView1.setText("A Smoke Alias is an arrangement of digits and " + "letters assigned to a specific subscriber " + "(public key pair). " + "The tokens allow participants to exchange public " + "key pairs via the Echo Public Key Sharing (EPKS) " + "protocol. " + "An example Smoke Alias is account@e-mail.org.");
            else
                textView1.setText("A Smoke ID is an arrangement of hexadecimal " + "characters assigned to a specific subscriber " + "(public key pair). " + "The tokens allow participants to exchange public " + "key pairs via the Echo Public Key Sharing (EPKS) " + "protocol.");
            textView1.setTextSize(16);
            popupWindow.setContentView(textView1);
            popupWindow.setOutsideTouchable(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                popupWindow.setHeight(450);
                popupWindow.setWidth(700);
            }
            popupWindow.showAsDropDown(view);
        }
    });
    switch1 = (Switch) findViewById(R.id.as_alias);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            TextView textView1 = (TextView) findViewById(R.id.at_sign);
            TextView textView2 = (TextView) findViewById(R.id.participant_name);
            TextView textView3 = (TextView) findViewById(R.id.participant_siphash_id);
            if (isChecked) {
                textView1.setText("|");
                textView3.setFilters(new InputFilter[] {});
                textView3.setHint("Smoke Alias");
                textView3.setText(textView2.getText());
            } else {
                textView1.setText("@");
                textView3.setFilters(new InputFilter[] { new InputFilter.AllCaps(), s_sipHashInputFilter });
                textView3.setHint("Smoke ID");
                textView3.setText("");
            }
        }
    });
    switch1 = (Switch) findViewById(R.id.automatic_refresh);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                m_databaseHelper.writeSetting(null, "automatic_neighbors_refresh", "true");
                startTimers();
            } else {
                m_databaseHelper.writeSetting(null, "automatic_neighbors_refresh", "false");
                stopTimers();
            }
        }
    });
    switch1 = (Switch) findViewById(R.id.echo);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                m_databaseHelper.writeSetting(null, "neighbors_echo", "true");
                State.getInstance().setNeighborsEcho(true);
            } else {
                m_databaseHelper.writeSetting(null, "neighbors_echo", "false");
                Kernel.getInstance().clearNeighborQueues();
                State.getInstance().setNeighborsEcho(false);
            }
        }
    });
    switch1 = (Switch) findViewById(R.id.foreground_service);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                SmokeService.startForegroundTask(Settings.this);
                m_databaseHelper.writeSetting(null, "foreground_service", "true");
            } else {
                SmokeService.stopForegroundTask(Settings.this);
                m_databaseHelper.writeSetting(null, "foreground_service", "false");
            }
        }
    });
    switch1 = (Switch) findViewById(R.id.neighbor_details);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked)
                m_databaseHelper.writeSetting(null, "neighbors_details", "true");
            else
                m_databaseHelper.writeSetting(null, "neighbors_details", "false");
            Switch switch1 = (Switch) findViewById(R.id.automatic_refresh);
            if (!switch1.isChecked())
                populateNeighbors(null);
        }
    });
    switch1 = (Switch) findViewById(R.id.overwrite);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Button button1 = null;
            button1 = (Button) findViewById(R.id.generate_pki);
            button1.setEnabled(isChecked);
            button1 = (Button) findViewById(R.id.set_password);
            button1.setEnabled(isChecked);
        }
    });
    switch1 = (Switch) findViewById(R.id.query_time_server);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            State.getInstance().setQueryTimerServer(isChecked);
            m_databaseHelper.writeSetting(null, "query_time_server", isChecked ? "true" : "false");
        }
    });
    switch1 = (Switch) findViewById(R.id.silent);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            State.getInstance().setSilent(isChecked);
            m_databaseHelper.writeSetting(null, "silent", isChecked ? "true" : "false");
        }
    });
    switch1 = (Switch) findViewById(R.id.sleepless);
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Kernel.getInstance().setWakeLock(isChecked);
            m_databaseHelper.writeSetting(null, "always_awake", isChecked ? "true" : "false");
            TextView textView1 = (TextView) findViewById(R.id.about);
            textView1.setText(About.about());
            textView1.append("\n");
            textView1.append("WakeLock Locked: " + Miscellaneous.niceBoolean(Kernel.getInstance().wakeLocked()));
            textView1.append("\n");
            textView1.append("WiFiLock Locked: " + Miscellaneous.niceBoolean(Kernel.getInstance().wifiLocked()));
        }
    });
    spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Spinner proxyType = (Spinner) findViewById(R.id.proxy_type);
            Switch nonTls = (Switch) findViewById(R.id.non_tls);
            TextView proxyIpAddress = (TextView) findViewById(R.id.proxy_ip_address);
            TextView proxyPort = (TextView) findViewById(R.id.proxy_port);
            if (position == 0) {
                /*
			** Events may occur prematurely.
			*/
                boolean isAuthenticated = State.getInstance().isAuthenticated();
                nonTls.setEnabled(isAuthenticated);
                proxyIpAddress.setEnabled(isAuthenticated);
                proxyPort.setEnabled(isAuthenticated);
                proxyType.setEnabled(isAuthenticated);
            } else {
                nonTls.setChecked(false);
                nonTls.setEnabled(false);
                proxyIpAddress.setEnabled(false);
                proxyIpAddress.setText("");
                proxyPort.setEnabled(false);
                proxyPort.setText("");
                proxyType.setEnabled(false);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    textView1.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (s != null) {
                Switch switch1 = (Switch) findViewById(R.id.as_alias);
                if (switch1.isChecked()) {
                    TextView textView1 = (TextView) findViewById(R.id.participant_siphash_id);
                    textView1.setText(s);
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) PopupWindow(android.widget.PopupWindow) RadioButton(android.widget.RadioButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) InputFilter(android.text.InputFilter) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Switch(android.widget.Switch) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) CompoundButton(android.widget.CompoundButton)

Aggregations

InputFilter (android.text.InputFilter)93 EditText (android.widget.EditText)33 View (android.view.View)31 TextView (android.widget.TextView)31 DialogInterface (android.content.DialogInterface)19 AlertDialog (android.app.AlertDialog)17 Editable (android.text.Editable)14 Paint (android.graphics.Paint)12 Bundle (android.os.Bundle)11 TextWatcher (android.text.TextWatcher)11 LinearLayout (android.widget.LinearLayout)11 Spanned (android.text.Spanned)10 TextPaint (android.text.TextPaint)10 ImageView (android.widget.ImageView)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 Intent (android.content.Intent)7 Nullable (android.support.annotation.Nullable)7 SmallTest (android.test.suitebuilder.annotation.SmallTest)7 Button (android.widget.Button)7 Context (android.content.Context)6