Search in sources :

Example 21 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project android_frameworks_base by AOSPA.

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)

Example 22 with OnItemSelectedListener

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

the class FeedInfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(UserPreferences.getTheme());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.feedinfo);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1);
    imgvCover = (ImageView) findViewById(R.id.imgvCover);
    txtvTitle = (TextView) findViewById(R.id.txtvTitle);
    txtvDescription = (TextView) findViewById(R.id.txtvDescription);
    lblLanguage = (TextView) findViewById(R.id.lblLanguage);
    txtvLanguage = (TextView) findViewById(R.id.txtvLanguage);
    lblAuthor = (TextView) findViewById(R.id.lblAuthor);
    txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
    txtvUrl = (TextView) findViewById(R.id.txtvUrl);
    cbxAutoDownload = (CheckBox) findViewById(R.id.cbxAutoDownload);
    cbxKeepUpdated = (CheckBox) findViewById(R.id.cbxKeepUpdated);
    spnAutoDelete = (Spinner) findViewById(R.id.spnAutoDelete);
    etxtUsername = (EditText) findViewById(R.id.etxtUsername);
    etxtPassword = (EditText) findViewById(R.id.etxtPassword);
    etxtFilterText = (EditText) findViewById(R.id.etxtEpisodeFilterText);
    rdoFilterInclude = (RadioButton) findViewById(R.id.radio_filter_include);
    rdoFilterInclude.setOnClickListener(v -> {
        filterInclude = true;
        filterTextChanged = true;
    });
    rdoFilterExclude = (RadioButton) findViewById(R.id.radio_filter_exclude);
    rdoFilterExclude.setOnClickListener(v -> {
        filterInclude = false;
        filterTextChanged = true;
    });
    txtvUrl.setOnClickListener(copyUrlToClipboard);
    subscription = Observable.fromCallable(() -> DBReader.getFeed(feedId)).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
        if (result == null) {
            Log.e(TAG, "Activity was started with invalid arguments");
            finish();
        }
        feed = result;
        Log.d(TAG, "Language is " + feed.getLanguage());
        Log.d(TAG, "Author is " + feed.getAuthor());
        Log.d(TAG, "URL is " + feed.getDownload_url());
        FeedPreferences prefs = feed.getPreferences();
        Glide.with(FeedInfoActivity.this).load(feed.getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(imgvCover);
        txtvTitle.setText(feed.getTitle());
        String description = feed.getDescription();
        if (description != null) {
            if (Feed.TYPE_ATOM1.equals(feed.getType())) {
                HtmlToPlainText formatter = new HtmlToPlainText();
                Document feedDescription = Jsoup.parse(feed.getDescription());
                description = StringUtils.trim(formatter.getPlainText(feedDescription));
            }
        } else {
            description = "";
        }
        txtvDescription.setText(description);
        if (!TextUtils.isEmpty(feed.getAuthor())) {
            txtvAuthor.setText(feed.getAuthor());
        } else {
            lblAuthor.setVisibility(View.GONE);
            txtvAuthor.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(feed.getLanguage())) {
            txtvLanguage.setText(LangUtils.getLanguageString(feed.getLanguage()));
        } else {
            lblLanguage.setVisibility(View.GONE);
            txtvLanguage.setVisibility(View.GONE);
        }
        txtvUrl.setText(feed.getDownload_url() + " {fa-paperclip}");
        Iconify.addIcons(txtvUrl);
        cbxAutoDownload.setEnabled(UserPreferences.isEnableAutodownload());
        cbxAutoDownload.setChecked(prefs.getAutoDownload());
        cbxAutoDownload.setOnCheckedChangeListener((compoundButton, checked) -> {
            feed.getPreferences().setAutoDownload(checked);
            feed.savePreferences(FeedInfoActivity.this);
            updateAutoDownloadSettings();
            ApplyToEpisodesDialog dialog = new ApplyToEpisodesDialog(FeedInfoActivity.this, feed, checked);
            dialog.createNewDialog().show();
        });
        cbxKeepUpdated.setChecked(prefs.getKeepUpdated());
        cbxKeepUpdated.setOnCheckedChangeListener((compoundButton, checked) -> {
            feed.getPreferences().setKeepUpdated(checked);
            feed.savePreferences(FeedInfoActivity.this);
        });
        spnAutoDelete.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                FeedPreferences.AutoDeleteAction auto_delete_action;
                switch(parent.getSelectedItemPosition()) {
                    case 0:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.GLOBAL;
                        break;
                    case 1:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.YES;
                        break;
                    case 2:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.NO;
                        break;
                    default:
                        return;
                }
                feed.getPreferences().setAutoDeleteAction(auto_delete_action);
                autoDeleteChanged = true;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        spnAutoDelete.setSelection(prefs.getAutoDeleteAction().ordinal());
        etxtUsername.setText(prefs.getUsername());
        etxtPassword.setText(prefs.getPassword());
        etxtUsername.addTextChangedListener(authTextWatcher);
        etxtPassword.addTextChangedListener(authTextWatcher);
        FeedFilter filter = prefs.getFilter();
        if (filter.includeOnly()) {
            etxtFilterText.setText(filter.getIncludeFilter());
            rdoFilterInclude.setChecked(true);
            rdoFilterExclude.setChecked(false);
            filterInclude = true;
        } else if (filter.excludeOnly()) {
            etxtFilterText.setText(filter.getExcludeFilter());
            rdoFilterInclude.setChecked(false);
            rdoFilterExclude.setChecked(true);
            filterInclude = false;
        } else {
            Log.d(TAG, "No filter set");
            rdoFilterInclude.setChecked(false);
            rdoFilterExclude.setChecked(false);
            etxtFilterText.setText("");
        }
        etxtFilterText.addTextChangedListener(filterTextWatcher);
        supportInvalidateOptionsMenu();
        updateAutoDownloadSettings();
    }, error -> {
        Log.d(TAG, Log.getStackTraceString(error));
        finish();
    });
}
Also used : FeedMenuHandler(de.danoeh.antennapod.menuhandler.FeedMenuHandler) Context(android.content.Context) Bundle(android.os.Bundle) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException) ConfirmationDialog(de.danoeh.antennapod.core.dialog.ConfirmationDialog) Uri(android.net.Uri) ImageView(android.widget.ImageView) RadioButton(android.widget.RadioButton) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) ApGlideSettings(de.danoeh.antennapod.core.glide.ApGlideSettings) StringUtils(org.apache.commons.lang3.StringUtils) Editable(android.text.Editable) DownloadRequestErrorDialogCreator(de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator) MenuItem(android.view.MenuItem) Observable(rx.Observable) ClipData(android.content.ClipData) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter) CheckBox(android.widget.CheckBox) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Feed(de.danoeh.antennapod.core.feed.Feed) AdapterView(android.widget.AdapterView) Log(android.util.Log) DialogInterface(android.content.DialogInterface) IntentUtils(de.danoeh.antennapod.core.util.IntentUtils) R(de.danoeh.antennapod.R) TextUtils(android.text.TextUtils) AppCompatActivity(android.support.v7.app.AppCompatActivity) Spinner(android.widget.Spinner) LangUtils(de.danoeh.antennapod.core.util.LangUtils) FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) Iconify(com.joanzapata.iconify.Iconify) Document(org.jsoup.nodes.Document) DBReader(de.danoeh.antennapod.core.storage.DBReader) Jsoup(org.jsoup.Jsoup) Subscription(rx.Subscription) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AdapterView(android.widget.AdapterView) Document(org.jsoup.nodes.Document) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter)

Example 23 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project android_frameworks_base by DirtyUnicorns.

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)

Example 24 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project SharedPreferenceInspector by PrashamTrivedi.

the class SharedPreferencesItem method onItemClick.

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 * <p/>
 * Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.
 *
 * @param parent
 * 		The AdapterView where the click happened.
 * @param view
 * 		The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position
 * 		The position of the view in the adapter.
 * @param id
 * 		The row id of the item that was clicked.
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    String cancel = "Cancel";
    /**
     * Checks if entered in test mode. If not, clicking on preferences will prompt user to enter test mode first. If already entered in
     * test mode,
     * it will present the UI to change the value. Once it's changed, it will store original value
     */
    if (preferenceUtils.getBoolean(testModeOpened, false)) {
        final Pair<String, Object> keyValue = (Pair<String, Object>) parent.getItemAtPosition(position);
        Object second = keyValue.second;
        final String valueType = second.getClass().getSimpleName();
        AlertDialog.Builder builder = new Builder(getActivity());
        View editView = LayoutInflater.from(getActivity()).inflate(R.layout.edit_mode, null);
        final EditText et_value = (EditText) editView.findViewById(R.id.value);
        final SwitchCompat booleanSwitch = (SwitchCompat) editView.findViewById(R.id.switchBoolean);
        Spinner type = (Spinner) editView.findViewById(R.id.type);
        final String value = second.toString();
        et_value.setText(value);
        OnItemSelectedListener listener = new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (typePosition != position) {
                    et_value.setText("");
                    typePosition = position;
                }
                booleanSwitch.setVisibility(View.GONE);
                et_value.setVisibility(View.VISIBLE);
                if (typePosition == SharedPreferenceUtils.SPINNER_STRING) {
                    et_value.setInputType(InputType.TYPE_CLASS_TEXT);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_INT || typePosition == SharedPreferenceUtils.SPINNER_LONG) {
                    et_value.setInputType(InputType.TYPE_CLASS_NUMBER);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_FLOAT) {
                    et_value.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_BOOLEAN) {
                    et_value.setVisibility(View.GONE);
                    booleanSwitch.setVisibility(View.VISIBLE);
                    boolean isPreferenceTrue = !ConstantMethods.isEmptyString(value) && value.equalsIgnoreCase("true");
                    booleanSwitch.setText(isPreferenceTrue ? "true" : "false");
                    booleanSwitch.setChecked(isPreferenceTrue);
                    booleanSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            buttonView.setText(isChecked ? "true" : "false");
                        }
                    });
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                typePosition = 0;
            }
        };
        type.setOnItemSelectedListener(listener);
        OnClickListener listener2 = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
            // TODO: Hell nothing right now.
            }
        };
        OnClickListener clearListener = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                storeOriginal(keyValue);
                preferenceUtils.clear(keyValue.first);
                refreshKeyValues();
            }
        };
        if (valueType.equalsIgnoreCase(SharedPreferenceUtils.INT)) {
            typePosition = SharedPreferenceUtils.SPINNER_INT;
            type.setSelection(SharedPreferenceUtils.SPINNER_INT);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.LONG)) {
            typePosition = SharedPreferenceUtils.SPINNER_LONG;
            type.setSelection(SharedPreferenceUtils.SPINNER_LONG);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.FLOAT)) {
            typePosition = SharedPreferenceUtils.SPINNER_FLOAT;
            type.setSelection(SharedPreferenceUtils.SPINNER_FLOAT);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.BOOLEAN)) {
            typePosition = SharedPreferenceUtils.SPINNER_BOOLEAN;
            type.setSelection(SharedPreferenceUtils.SPINNER_BOOLEAN);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.STRING)) {
            typePosition = SharedPreferenceUtils.SPINNER_STRING;
            type.setSelection(SharedPreferenceUtils.SPINNER_STRING);
        }
        final AlertDialog dialog = builder.setTitle("Change Value").setView(editView).setPositiveButton("Set", null).setNegativeButton(cancel, listener2).setNeutralButton("Clear", clearListener).create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog1) {
                Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                b.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        storeOriginal(keyValue);
                        Editable text = et_value.getText();
                        switch(typePosition) {
                            case SharedPreferenceUtils.SPINNER_STRING:
                                preferenceUtils.putString(keyValue.first, String.valueOf(text));
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_INT:
                                int number = SharedPreferenceUtils.getNumber(text);
                                preferenceUtils.putInt(keyValue.first, number);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_LONG:
                                long numberLong = SharedPreferenceUtils.getNumberLong(text);
                                preferenceUtils.putLong(keyValue.first, numberLong);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_BOOLEAN:
                                boolean value = booleanSwitch.isChecked();
                                preferenceUtils.putBoolean(keyValue.first, value);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_FLOAT:
                                float numberFloat = SharedPreferenceUtils.getNumberFloat(text);
                                preferenceUtils.putFloat(keyValue.first, numberFloat);
                                dialog.dismiss();
                                break;
                        }
                        refreshKeyValues();
                    }
                });
            }
        });
        dialog.show();
    } else {
        AlertDialog.Builder builder = new Builder(getActivity());
        builder.setTitle("Test mode not enabled").setMessage("If you want to edit value for testing, testing mode should be enabled. It's available in options menu").setPositiveButton("Enable test mode", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                getActivity().supportInvalidateOptionsMenu();
                changeTestMode();
                onItemClick(parent, view, position, id);
            }
        }).setNegativeButton(cancel, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                dialog.cancel();
            }
        }).show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) Builder(android.support.v7.app.AlertDialog.Builder) Builder(android.support.v7.app.AlertDialog.Builder) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Editable(android.text.Editable) Pair(android.support.v4.util.Pair) EditText(android.widget.EditText) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) OnClickListener(android.content.DialogInterface.OnClickListener) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 25 with OnItemSelectedListener

use of android.widget.AdapterView.OnItemSelectedListener in project XCL-Charts by xcltapestry.

the class SpinnerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_spinner);
    Bundle bunde = this.getIntent().getExtras();
    String title = bunde.getString("title");
    this.setTitle(title);
    mSelected = bunde.getInt("selected");
    mLaychart = (LinearLayout) this.findViewById(R.id.lay_chart);
    mSpinner = (Spinner) findViewById(R.id.spinner1);
    mMoveHeight = mSpinner.getHeight();
    String[] mItems = null;
    // 建立数据源
    if (0 == mSelected) {
        mItems = getResources().getStringArray(R.array.spinnerbarstyle);
    } else {
        mItems = getResources().getStringArray(R.array.spinnercirstyle);
    }
    ArrayAdapter<String> _Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mItems);
    mSpinner.setAdapter(_Adapter);
    mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            renderChart(position);
        }
    });
    renderChart(0);
}
Also used : Bundle(android.os.Bundle) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) SpinnerBarChart01View(com.demo.xclcharts.view.SpinnerBarChart01View) SpinnerPieChart01View(com.demo.xclcharts.view.SpinnerPieChart01View) View(android.view.View) AdapterView(android.widget.AdapterView) 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