Search in sources :

Example 1 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project android by cSploit.

the class Sniffer method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
    Boolean isDark = themePrefs.getBoolean("isDark", false);
    if (isDark)
        setTheme(R.style.DarkTheme);
    else
        setTheme(R.style.AppTheme);
    setTitle(System.getCurrentTarget() + " > MITM > Sniffer");
    setContentView(R.layout.plugin_mitm_sniffer);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mSniffToggleButton = (ToggleButton) findViewById(R.id.sniffToggleButton);
    mSniffProgress = (ProgressBar) findViewById(R.id.sniffActivity);
    mSortSpinner = (Spinner) findViewById(R.id.sortSpinner);
    mListView = (ListView) findViewById(R.id.listView);
    mAdapter = new StatListAdapter(R.layout.plugin_mitm_sniffer_list_item);
    mSampleTime = (int) (Double.parseDouble(System.getSettings().getString("PREF_SNIFFER_SAMPLE_TIME", "1.0")) * 1000);
    mSpoofSession = new SpoofSession(false, false, null, null);
    mSortSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, SORT));
    mSortSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
            mSortType = position;
        }

        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(this);
    mSniffToggleButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mRunning) {
                setStoppedState();
            } else {
                setStartedState();
            }
        }
    });
    new ConfirmDialog(getString(R.string.file_output), getString(R.string.question_save_to_pcap), this, new ConfirmDialog.ConfirmDialogListener() {

        @Override
        public void onConfirm() {
            mDumpToFile = true;
            mPcapFileName = (new File(Sniffer.this.getCacheDir(), "csploit-sniff-" + java.lang.System.currentTimeMillis() + ".pcap")).getAbsolutePath();
        }

        @Override
        public void onCancel() {
            mDumpToFile = false;
            mPcapFileName = null;
        }
    }).show();
}
Also used : SharedPreferences(android.content.SharedPreferences) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) ConfirmDialog(org.csploit.android.gui.dialogs.ConfirmDialog)

Example 2 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project XPrivacy by M66B.

the class WhitelistTask method onPostExecute.

@Override
@SuppressLint({ "DefaultLocale", "InflateParams" })
protected void onPostExecute(Object result) {
    if (!mContext.isFinishing()) {
        // Build dialog
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
        alertDialogBuilder.setTitle(R.string.menu_whitelists);
        alertDialogBuilder.setIcon(mContext.getThemed(R.attr.icon_launcher));
        if (mListWhitelist.keySet().size() > 0) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View llWhitelists = inflater.inflate(R.layout.whitelists, null);
            int index = 0;
            int selected = -1;
            final List<String> localizedType = new ArrayList<String>();
            for (String type : mListWhitelist.keySet()) {
                String name = "whitelist_" + type.toLowerCase().replace("/", "");
                int id = mContext.getResources().getIdentifier(name, "string", mContext.getPackageName());
                if (id == 0)
                    localizedType.add(name);
                else
                    localizedType.add(mContext.getResources().getString(id));
                if (type.equals(mType))
                    selected = index;
                index++;
            }
            Spinner spWhitelistType = (Spinner) llWhitelists.findViewById(R.id.spWhitelistType);
            ArrayAdapter<String> whitelistTypeAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_dropdown_item, localizedType);
            spWhitelistType.setAdapter(whitelistTypeAdapter);
            spWhitelistType.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    mWhitelistAdapter.setType(mListWhitelist.keySet().toArray(new String[0])[position]);
                }

                @Override
                public void onNothingSelected(AdapterView<?> view) {
                }
            });
            if (selected >= 0)
                spWhitelistType.setSelection(selected);
            ListView lvWhitelist = (ListView) llWhitelists.findViewById(R.id.lvWhitelist);
            lvWhitelist.setAdapter(mWhitelistAdapter);
            int position = spWhitelistType.getSelectedItemPosition();
            if (position != AdapterView.INVALID_POSITION)
                mWhitelistAdapter.setType(mListWhitelist.keySet().toArray(new String[0])[position]);
            alertDialogBuilder.setView(llWhitelists);
        }
        alertDialogBuilder.setPositiveButton(mContext.getString(R.string.msg_done), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
            // Do nothing
            }
        });
        // Show dialog
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }
    super.onPostExecute(result);
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) ListView(android.widget.ListView) LayoutInflater(android.view.LayoutInflater) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) ArrayAdapter(android.widget.ArrayAdapter) SuppressLint(android.annotation.SuppressLint)

Example 3 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project k-9 by k9mail.

the class AccountSetupIncoming method validateFields.

/**
     * This is invoked only when the user makes changes to a widget, not when
     * widgets are changed programmatically.  (The logic is simpler when you know
     * that this is the last thing called after an input change.)
     */
private void validateFields() {
    AuthType authType = getSelectedAuthType();
    boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
    ConnectionSecurity connectionSecurity = getSelectedSecurity();
    boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
    if (isAuthTypeExternal && !hasConnectionSecurity) {
        // Notify user of an invalid combination of AuthType.EXTERNAL & ConnectionSecurity.NONE
        String toastText = getString(R.string.account_setup_incoming_invalid_setting_combo_notice, getString(R.string.account_setup_incoming_auth_type_label), AuthType.EXTERNAL.toString(), getString(R.string.account_setup_incoming_security_label), ConnectionSecurity.NONE.toString());
        Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();
        // Reset the views back to their previous settings without recursing through here again
        OnItemSelectedListener onItemSelectedListener = mAuthTypeView.getOnItemSelectedListener();
        mAuthTypeView.setOnItemSelectedListener(null);
        mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
        mAuthTypeView.setOnItemSelectedListener(onItemSelectedListener);
        updateViewFromAuthType();
        onItemSelectedListener = mSecurityTypeView.getOnItemSelectedListener();
        mSecurityTypeView.setOnItemSelectedListener(null);
        mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);
        mSecurityTypeView.setOnItemSelectedListener(onItemSelectedListener);
        updateAuthPlainTextFromSecurityType(getSelectedSecurity());
        mPortView.removeTextChangedListener(validationTextWatcher);
        mPortView.setText(mCurrentPortViewSetting);
        mPortView.addTextChangedListener(validationTextWatcher);
        authType = getSelectedAuthType();
        isAuthTypeExternal = (AuthType.EXTERNAL == authType);
        connectionSecurity = getSelectedSecurity();
        hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
    } else {
        mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition();
        mCurrentSecurityTypeViewPosition = mSecurityTypeView.getSelectedItemPosition();
        mCurrentPortViewSetting = mPortView.getText().toString();
    }
    boolean hasValidCertificateAlias = mClientCertificateSpinner.getAlias() != null;
    boolean hasValidUserName = Utility.requiredFieldValid(mUsernameView);
    boolean hasValidPasswordSettings = hasValidUserName && !isAuthTypeExternal && Utility.requiredFieldValid(mPasswordView);
    boolean hasValidExternalAuthSettings = hasValidUserName && isAuthTypeExternal && hasConnectionSecurity && hasValidCertificateAlias;
    mNextButton.setEnabled(Utility.domainFieldValid(mServerView) && Utility.requiredFieldValid(mPortView) && (hasValidPasswordSettings || hasValidExternalAuthSettings));
    Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
}
Also used : ConnectionSecurity(com.fsck.k9.mail.ConnectionSecurity) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AuthType(com.fsck.k9.mail.AuthType)

Example 4 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project k-9 by k9mail.

the class AccountSetupOutgoing method initializeViewListeners.

/**
     * Called at the end of either {@code onCreate()} or
     * {@code onRestoreInstanceState()}, after the views have been initialized,
     * so that the listeners are not triggered during the view initialization.
     * This avoids needless calls to {@code validateFields()} which is called
     * immediately after this is called.
     */
private void initializeViewListeners() {
    /*
         * Updates the port when the user changes the security type. This allows
         * us to show a reasonable default which the user can change.
         */
    mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            /*
                 * We keep our own record of the spinner state so we
                 * know for sure that onItemSelected() was called
                 * because of user input, not because of spinner
                 * state initialization. This assures that the port
                 * will not be replaced with a default value except
                 * on user input.
                 */
            if (mCurrentSecurityTypeViewPosition != position) {
                updatePortFromSecurityType();
                boolean isInsecure = (ConnectionSecurity.NONE == getSelectedSecurity());
                boolean isAuthExternal = (AuthType.EXTERNAL == getSelectedAuthType());
                boolean loginNotRequired = !mRequireLoginView.isChecked();
                /*
                     * If the user selects ConnectionSecurity.NONE, a
                     * warning would normally pop up if the authentication
                     * is AuthType.EXTERNAL (i.e., using client
                     * certificates). But such a warning is irrelevant if
                     * login is not required. So to avoid such a warning
                     * (generated in validateFields()) under those
                     * conditions, we change the (irrelevant) authentication
                     * method to PLAIN.
                     */
                if (isInsecure && isAuthExternal && loginNotRequired) {
                    OnItemSelectedListener onItemSelectedListener = mAuthTypeView.getOnItemSelectedListener();
                    mAuthTypeView.setOnItemSelectedListener(null);
                    mCurrentAuthTypeViewPosition = mAuthTypeAdapter.getAuthPosition(AuthType.PLAIN);
                    mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
                    mAuthTypeView.setOnItemSelectedListener(onItemSelectedListener);
                    updateViewFromAuthType();
                }
                validateFields();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        /* unused */
        }
    });
    mAuthTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (mCurrentAuthTypeViewPosition == position) {
                return;
            }
            updateViewFromAuthType();
            validateFields();
            AuthType selection = getSelectedAuthType();
            // Have the user select (or confirm) the client certificate
            if (AuthType.EXTERNAL == selection) {
                // This may again invoke validateFields()
                mClientCertificateSpinner.chooseCertificate();
            } else {
                mPasswordView.requestFocus();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        /* unused */
        }
    });
    mRequireLoginView.setOnCheckedChangeListener(this);
    mClientCertificateSpinner.setOnClientCertificateChangedListener(clientCertificateChangedListener);
    mUsernameView.addTextChangedListener(validationTextWatcher);
    mPasswordView.addTextChangedListener(validationTextWatcher);
    mServerView.addTextChangedListener(validationTextWatcher);
    mPortView.addTextChangedListener(validationTextWatcher);
}
Also used : OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AuthType(com.fsck.k9.mail.AuthType) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) View(android.view.View)

Example 5 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project platform_frameworks_base by android.

the class PrintActivity method bindUi.

private void bindUi() {
    // Summary
    mSummaryContainer = findViewById(R.id.summary_content);
    mSummaryCopies = (TextView) findViewById(R.id.copies_count_summary);
    mSummaryPaperSize = (TextView) findViewById(R.id.paper_size_summary);
    // Options container
    mOptionsContent = (PrintContentView) findViewById(R.id.options_content);
    mOptionsContent.setOptionsStateChangeListener(this);
    mOptionsContent.setOpenOptionsController(this);
    OnItemSelectedListener itemSelectedListener = new MyOnItemSelectedListener();
    OnClickListener clickListener = new MyClickListener();
    // Copies
    mCopiesEditText = (EditText) findViewById(R.id.copies_edittext);
    mCopiesEditText.setOnFocusChangeListener(mSelectAllOnFocusListener);
    mCopiesEditText.setText(MIN_COPIES_STRING);
    mCopiesEditText.setSelection(mCopiesEditText.getText().length());
    mCopiesEditText.addTextChangedListener(new EditTextWatcher());
    // Destination.
    mPrintersObserver = new PrintersObserver();
    mDestinationSpinnerAdapter.registerDataSetObserver(mPrintersObserver);
    mDestinationSpinner = (Spinner) findViewById(R.id.destination_spinner);
    mDestinationSpinner.setAdapter(mDestinationSpinnerAdapter);
    mDestinationSpinner.setOnItemSelectedListener(itemSelectedListener);
    // Media size.
    mMediaSizeSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, android.R.id.text1);
    mMediaSizeSpinner = (Spinner) findViewById(R.id.paper_size_spinner);
    mMediaSizeSpinner.setAdapter(mMediaSizeSpinnerAdapter);
    mMediaSizeSpinner.setOnItemSelectedListener(itemSelectedListener);
    // Color mode.
    mColorModeSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, android.R.id.text1);
    mColorModeSpinner = (Spinner) findViewById(R.id.color_spinner);
    mColorModeSpinner.setAdapter(mColorModeSpinnerAdapter);
    mColorModeSpinner.setOnItemSelectedListener(itemSelectedListener);
    // Duplex mode.
    mDuplexModeSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, android.R.id.text1);
    mDuplexModeSpinner = (Spinner) findViewById(R.id.duplex_spinner);
    mDuplexModeSpinner.setAdapter(mDuplexModeSpinnerAdapter);
    mDuplexModeSpinner.setOnItemSelectedListener(itemSelectedListener);
    // Orientation
    mOrientationSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, android.R.id.text1);
    String[] orientationLabels = getResources().getStringArray(R.array.orientation_labels);
    mOrientationSpinnerAdapter.add(new SpinnerItem<>(ORIENTATION_PORTRAIT, orientationLabels[0]));
    mOrientationSpinnerAdapter.add(new SpinnerItem<>(ORIENTATION_LANDSCAPE, orientationLabels[1]));
    mOrientationSpinner = (Spinner) findViewById(R.id.orientation_spinner);
    mOrientationSpinner.setAdapter(mOrientationSpinnerAdapter);
    mOrientationSpinner.setOnItemSelectedListener(itemSelectedListener);
    // Range options
    ArrayAdapter<SpinnerItem<Integer>> rangeOptionsSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, android.R.id.text1);
    mRangeOptionsSpinner = (Spinner) findViewById(R.id.range_options_spinner);
    mRangeOptionsSpinner.setAdapter(rangeOptionsSpinnerAdapter);
    mRangeOptionsSpinner.setOnItemSelectedListener(itemSelectedListener);
    updatePageRangeOptions(PrintDocumentInfo.PAGE_COUNT_UNKNOWN);
    // Page range
    mPageRangeTitle = (TextView) findViewById(R.id.page_range_title);
    mPageRangeEditText = (EditText) findViewById(R.id.page_range_edittext);
    mPageRangeEditText.setVisibility(View.INVISIBLE);
    mPageRangeTitle.setVisibility(View.INVISIBLE);
    mPageRangeEditText.setOnFocusChangeListener(mSelectAllOnFocusListener);
    mPageRangeEditText.addTextChangedListener(new RangeTextWatcher());
    // Advanced options button.
    mMoreOptionsButton = (Button) findViewById(R.id.more_options_button);
    mMoreOptionsButton.setOnClickListener(clickListener);
    // Print button
    mPrintButton = (ImageView) findViewById(R.id.print_button);
    mPrintButton.setOnClickListener(clickListener);
    // The UI is now initialized
    mIsOptionsUiBound = true;
    // Special prompt instead of destination spinner for the first time the user printed
    if (!hasUserEverPrinted()) {
        mShowDestinationPrompt = true;
        mSummaryCopies.setEnabled(false);
        mSummaryPaperSize.setEnabled(false);
        mDestinationSpinner.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                mShowDestinationPrompt = false;
                mSummaryCopies.setEnabled(true);
                mSummaryPaperSize.setEnabled(true);
                updateOptionsUi();
                mDestinationSpinner.setOnTouchListener(null);
                mDestinationSpinnerAdapter.notifyDataSetChanged();
                return false;
            }
        });
    }
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) PrintContentView(com.android.printspooler.widget.PrintContentView) MotionEvent(android.view.MotionEvent) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) OnClickListener(android.view.View.OnClickListener) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)25 View (android.view.View)23 AdapterView (android.widget.AdapterView)21 TextView (android.widget.TextView)14 ArrayAdapter (android.widget.ArrayAdapter)11 OnClickListener (android.view.View.OnClickListener)10 ImageView (android.widget.ImageView)9 ListView (android.widget.ListView)6 Spinner (android.widget.Spinner)6 MotionEvent (android.view.MotionEvent)5 PrintContentView (com.android.printspooler.widget.PrintContentView)5 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 Editable (android.text.Editable)3 CompoundButton (android.widget.CompoundButton)3 EditText (android.widget.EditText)3 SuppressLint (android.annotation.SuppressLint)2 AlertDialog (android.app.AlertDialog)2 Bundle (android.os.Bundle)2