Search in sources :

Example 31 with Spinner

use of android.widget.Spinner in project flexbox-layout by google.

the class MainActivityTest method testAlignContentSpinner.

@Test
@SuppressWarnings("unchecked")
@FlakyTest
public void testAlignContentSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_align_content));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int spaceAroundPosition = spinnerAdapter.getPosition(activity.getString(R.string.space_around));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(spaceAroundPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND));
    final int stretchPosition = spinnerAdapter.getPosition(activity.getString(R.string.stretch));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(stretchPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) NavigationView(android.support.design.widget.NavigationView) Spinner(android.widget.Spinner) MainActivity(com.google.android.apps.flexbox.MainActivity) Menu(android.view.Menu) ArrayAdapter(android.widget.ArrayAdapter) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 32 with Spinner

use of android.widget.Spinner in project RecyclerViewItemAnimators by gabrielemariotti.

the class AnimationGridActivity method setupSpinner.

private void setupSpinner() {
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.adapters, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
            switch(position) {
                case 0:
                    AlphaAnimatorAdapter animatorAdapter = new AlphaAnimatorAdapter(mAdapter, mRecyclerView);
                    mRecyclerView.setAdapter(animatorAdapter);
                    break;
                case 1:
                    SlideInLeftAnimatorAdapter slideInLeftAnimationRecyclerViewAdapter = new SlideInLeftAnimatorAdapter(mAdapter, mRecyclerView);
                    mRecyclerView.setAdapter(slideInLeftAnimationRecyclerViewAdapter);
                    break;
                case 2:
                    SlideInRightAnimatorAdapter slideInRightAnimatorAdapter = new SlideInRightAnimatorAdapter(mAdapter, mRecyclerView);
                    mRecyclerView.setAdapter(slideInRightAnimatorAdapter);
                    break;
                case 3:
                    SlideInBottomAnimatorAdapter slideInBottomAnimatorAdapter = new SlideInBottomAnimatorAdapter(mAdapter, mRecyclerView);
                    mRecyclerView.setAdapter(slideInBottomAnimatorAdapter);
                    break;
                case 4:
                    ScaleInAnimatorAdapter scaleInRecyclerViewAnimationAdapter = new ScaleInAnimatorAdapter(mAdapter, mRecyclerView);
                    mRecyclerView.setAdapter(scaleInRecyclerViewAnimationAdapter);
                    break;
                case 5:
                    SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(mAdapter, mRecyclerView);
                    mRecyclerView.setAdapter(swingBottomInAnimationAdapter);
                    break;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
}
Also used : Spinner(android.widget.Spinner) SwingBottomInAnimationAdapter(it.gmariotti.recyclerview.adapter.SwingBottomInAnimationAdapter) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) SlideInBottomAnimatorAdapter(it.gmariotti.recyclerview.adapter.SlideInBottomAnimatorAdapter) ScaleInAnimatorAdapter(it.gmariotti.recyclerview.adapter.ScaleInAnimatorAdapter) SlideInLeftAnimatorAdapter(it.gmariotti.recyclerview.adapter.SlideInLeftAnimatorAdapter) AlphaAnimatorAdapter(it.gmariotti.recyclerview.adapter.AlphaAnimatorAdapter) AdapterView(android.widget.AdapterView) SlideInRightAnimatorAdapter(it.gmariotti.recyclerview.adapter.SlideInRightAnimatorAdapter)

Example 33 with Spinner

use of android.widget.Spinner in project RecyclerViewItemAnimators by gabrielemariotti.

the class ListActivity method setupSpinner.

private void setupSpinner() {
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.animators, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
            switch(position) {
                case 0:
                    mRecyclerView.setItemAnimator(new SlideInOutLeftItemAnimator(mRecyclerView));
                    break;
                case 1:
                    mRecyclerView.setItemAnimator(new SlideInOutRightItemAnimator(mRecyclerView));
                    break;
                case 2:
                    mRecyclerView.setItemAnimator(new SlideInOutTopItemAnimator(mRecyclerView));
                    break;
                case 3:
                    mRecyclerView.setItemAnimator(new SlideInOutBottomItemAnimator(mRecyclerView));
                    break;
                case 4:
                    mRecyclerView.setItemAnimator(new ScaleInOutItemAnimator(mRecyclerView));
                    break;
                case 5:
                    mRecyclerView.setItemAnimator(new SlideScaleInOutRightItemAnimator(mRecyclerView));
                    break;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
}
Also used : Spinner(android.widget.Spinner) SlideInOutTopItemAnimator(it.gmariotti.recyclerview.itemanimator.SlideInOutTopItemAnimator) SlideInOutRightItemAnimator(it.gmariotti.recyclerview.itemanimator.SlideInOutRightItemAnimator) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) SlideInOutLeftItemAnimator(it.gmariotti.recyclerview.itemanimator.SlideInOutLeftItemAnimator) ScaleInOutItemAnimator(it.gmariotti.recyclerview.itemanimator.ScaleInOutItemAnimator) SlideScaleInOutRightItemAnimator(it.gmariotti.recyclerview.itemanimator.SlideScaleInOutRightItemAnimator) AdapterView(android.widget.AdapterView) SlideInOutBottomItemAnimator(it.gmariotti.recyclerview.itemanimator.SlideInOutBottomItemAnimator)

Example 34 with Spinner

use of android.widget.Spinner in project WordPress-Android by wordpress-mobile.

the class LegacyEditorFragment method onTouch.

@Override
public boolean onTouch(View v, MotionEvent event) {
    float pos = event.getY();
    if (event.getAction() == 0)
        mLastYPos = pos;
    if (event.getAction() > 1) {
        int scrollThreshold = DisplayUtils.dpToPx(getActivity(), 2);
        if (((mLastYPos - pos) > scrollThreshold) || ((pos - mLastYPos) > scrollThreshold))
            mScrollDetected = true;
    }
    mLastYPos = pos;
    if (event.getAction() == MotionEvent.ACTION_UP) {
        ActionBar actionBar = getActionBar();
        if (actionBar != null && actionBar.isShowing()) {
            setContentEditingModeVisible(true);
            return false;
        }
    }
    if (event.getAction() == MotionEvent.ACTION_UP && !mScrollDetected) {
        Layout layout = ((TextView) v).getLayout();
        int x = (int) event.getX();
        int y = (int) event.getY();
        x += v.getScrollX();
        y += v.getScrollY();
        if (layout != null) {
            int line = layout.getLineForVertical(y);
            int charPosition = layout.getOffsetForHorizontal(line, x);
            Spannable spannable = mContentEditText.getText();
            if (spannable == null) {
                return false;
            }
            // check if image span was tapped
            WPImageSpan[] imageSpans = spannable.getSpans(charPosition, charPosition, WPImageSpan.class);
            if (imageSpans.length != 0) {
                final WPImageSpan imageSpan = imageSpans[0];
                MediaFile mediaFile = imageSpan.getMediaFile();
                if (mediaFile == null)
                    return false;
                if (!mediaFile.isVideo()) {
                    LayoutInflater factory = LayoutInflater.from(getActivity());
                    final View alertView = factory.inflate(R.layout.alert_image_options, null);
                    if (alertView == null)
                        return false;
                    final EditText imageWidthText = (EditText) alertView.findViewById(R.id.imageWidthText);
                    final EditText titleText = (EditText) alertView.findViewById(R.id.title);
                    final EditText caption = (EditText) alertView.findViewById(R.id.caption);
                    final CheckBox featuredCheckBox = (CheckBox) alertView.findViewById(R.id.featuredImage);
                    final CheckBox featuredInPostCheckBox = (CheckBox) alertView.findViewById(R.id.featuredInPost);
                    // show featured image checkboxes if supported
                    if (mFeaturedImageSupported) {
                        featuredCheckBox.setVisibility(View.VISIBLE);
                        featuredInPostCheckBox.setVisibility(View.VISIBLE);
                    }
                    featuredCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            if (isChecked) {
                                featuredInPostCheckBox.setVisibility(View.VISIBLE);
                            } else {
                                featuredInPostCheckBox.setVisibility(View.GONE);
                            }
                        }
                    });
                    final SeekBar seekBar = (SeekBar) alertView.findViewById(R.id.imageWidth);
                    final Spinner alignmentSpinner = (Spinner) alertView.findViewById(R.id.alignment_spinner);
                    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.alignment_array, android.R.layout.simple_spinner_item);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    alignmentSpinner.setAdapter(adapter);
                    seekBar.setProgress(mediaFile.getWidth());
                    titleText.setText(mediaFile.getTitle());
                    caption.setText(mediaFile.getCaption());
                    featuredCheckBox.setChecked(mediaFile.isFeatured());
                    if (mediaFile.isFeatured()) {
                        featuredInPostCheckBox.setVisibility(View.VISIBLE);
                    } else {
                        featuredInPostCheckBox.setVisibility(View.GONE);
                    }
                    featuredInPostCheckBox.setChecked(mediaFile.isFeaturedInPost());
                    alignmentSpinner.setSelection(mediaFile.getHorizontalAlignment(), true);
                    final int maxWidth = MediaUtils.getMaximumImageWidth(getActivity(), imageSpan.getImageSource(), mBlogSettingMaxImageWidth);
                    seekBar.setMax(maxWidth / 10);
                    imageWidthText.setText(String.format(Locale.US, "%dpx", maxWidth));
                    if (mediaFile.getWidth() != 0) {
                        seekBar.setProgress(mediaFile.getWidth() / 10);
                    }
                    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {
                        }

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                            if (progress == 0) {
                                progress = 1;
                            }
                            imageWidthText.setText(String.format(Locale.US, "%dpx", progress * 10));
                        }
                    });
                    imageWidthText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

                        @Override
                        public void onFocusChange(View v, boolean hasFocus) {
                            if (hasFocus) {
                                imageWidthText.setText("");
                            }
                        }
                    });
                    imageWidthText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

                        @Override
                        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                            int width = getEditTextIntegerClamped(imageWidthText, 10, maxWidth);
                            seekBar.setProgress(width / 10);
                            imageWidthText.setSelection((String.valueOf(width).length()));
                            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(imageWidthText.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
                            return true;
                        }
                    });
                    showImageSettings(alertView, titleText, caption, imageWidthText, featuredCheckBox, featuredInPostCheckBox, maxWidth, alignmentSpinner, imageSpan);
                    mScrollDetected = false;
                    return true;
                }
            } else {
                mContentEditText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
                int selectionStart = mContentEditText.getSelectionStart();
                if (selectionStart >= 0 && mContentEditText.getSelectionEnd() >= selectionStart)
                    mContentEditText.setSelection(selectionStart, mContentEditText.getSelectionEnd());
            }
            // get media gallery spans
            MediaGalleryImageSpan[] gallerySpans = spannable.getSpans(charPosition, charPosition, MediaGalleryImageSpan.class);
            if (gallerySpans.length > 0) {
                final MediaGalleryImageSpan gallerySpan = gallerySpans[0];
                Intent intent = new Intent(ACTION_MEDIA_GALLERY_TOUCHED);
                intent.putExtra(EXTRA_MEDIA_GALLERY, gallerySpan.getMediaGallery());
                getActivity().sendBroadcast(intent);
            }
        }
    } else if (event.getAction() == 1) {
        mScrollDetected = false;
    }
    return false;
}
Also used : Spinner(android.widget.Spinner) InputMethodManager(android.view.inputmethod.InputMethodManager) KeyEvent(android.view.KeyEvent) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) MediaFile(org.wordpress.android.util.helpers.MediaFile) WPEditText(org.wordpress.android.util.widgets.WPEditText) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) WPImageSpan(org.wordpress.android.util.helpers.WPImageSpan) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) Layout(android.text.Layout) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) MediaGalleryImageSpan(org.wordpress.android.util.helpers.MediaGalleryImageSpan) Spannable(android.text.Spannable) CompoundButton(android.widget.CompoundButton)

Example 35 with Spinner

use of android.widget.Spinner in project XobotOS by xamarin.

the class ActionBarView method setNavigationMode.

public void setNavigationMode(int mode) {
    final int oldMode = mNavigationMode;
    if (mode != oldMode) {
        switch(oldMode) {
            case ActionBar.NAVIGATION_MODE_LIST:
                if (mListNavLayout != null) {
                    removeView(mListNavLayout);
                }
                break;
            case ActionBar.NAVIGATION_MODE_TABS:
                if (mTabScrollView != null && mIncludeTabs) {
                    removeView(mTabScrollView);
                }
        }
        switch(mode) {
            case ActionBar.NAVIGATION_MODE_LIST:
                if (mSpinner == null) {
                    mSpinner = new Spinner(mContext, null, com.android.internal.R.attr.actionDropDownStyle);
                    mListNavLayout = new LinearLayout(mContext, null, com.android.internal.R.attr.actionBarTabBarStyle);
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
                    params.gravity = Gravity.CENTER;
                    mListNavLayout.addView(mSpinner, params);
                }
                if (mSpinner.getAdapter() != mSpinnerAdapter) {
                    mSpinner.setAdapter(mSpinnerAdapter);
                }
                mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
                addView(mListNavLayout);
                break;
            case ActionBar.NAVIGATION_MODE_TABS:
                if (mTabScrollView != null && mIncludeTabs) {
                    addView(mTabScrollView);
                }
                break;
        }
        mNavigationMode = mode;
        requestLayout();
    }
}
Also used : Spinner(android.widget.Spinner) LinearLayout(android.widget.LinearLayout)

Aggregations

Spinner (android.widget.Spinner)418 View (android.view.View)185 AdapterView (android.widget.AdapterView)146 TextView (android.widget.TextView)134 ArrayAdapter (android.widget.ArrayAdapter)132 EditText (android.widget.EditText)67 ArrayList (java.util.ArrayList)49 LinearLayout (android.widget.LinearLayout)48 Intent (android.content.Intent)45 Button (android.widget.Button)45 ImageView (android.widget.ImageView)43 CheckBox (android.widget.CheckBox)42 DialogInterface (android.content.DialogInterface)41 ViewGroup (android.view.ViewGroup)27 CompoundButton (android.widget.CompoundButton)27 RecyclerView (android.support.v7.widget.RecyclerView)26 LayoutInflater (android.view.LayoutInflater)26 ListView (android.widget.ListView)25 Test (org.junit.Test)23 Context (android.content.Context)19