Search in sources :

Example 26 with Spinner

use of android.widget.Spinner in project platform_frameworks_base by android.

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);
                    mSpinner.setId(com.android.internal.R.id.action_bar_spinner);
                    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)

Example 27 with Spinner

use of android.widget.Spinner in project android-maps-utils by googlemaps.

the class HeatmapsDemoActivity method startDemo.

@Override
protected void startDemo() {
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-25, 143), 4));
    // Set up the spinner/dropdown list
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.heatmaps_datasets_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new SpinnerActivity());
    try {
        mLists.put(getString(R.string.police_stations), new DataSet(readItems(R.raw.police), getString(R.string.police_stations_url)));
        mLists.put(getString(R.string.medicare), new DataSet(readItems(R.raw.medicare), getString(R.string.medicare_url)));
    } catch (JSONException e) {
        Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
    }
// Make the handler deal with the map
// Input: list of WeightedLatLngs, minimum and maximum zoom levels to calculate custom
// intensity from, and the map to draw the heatmap on
// radius, gradient and opacity not specified, so default are used
}
Also used : Spinner(android.widget.Spinner) JSONException(org.json.JSONException) LatLng(com.google.android.gms.maps.model.LatLng)

Example 28 with Spinner

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

the class FlexItemEditFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_flex_item_edit, container, false);
    getDialog().setTitle(String.valueOf(mFlexItem.index + 1));
    final TextInputLayout orderTextInput = (TextInputLayout) view.findViewById(R.id.input_layout_order);
    EditText orderEdit = (EditText) view.findViewById(R.id.edit_text_order);
    orderEdit.setText(String.valueOf(mFlexItem.order));
    orderEdit.addTextChangedListener(new FlexEditTextWatcher(orderTextInput, new IntegerInputValidator(), R.string.must_be_integer));
    final TextInputLayout flexGrowInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_grow);
    final EditText flexGrowEdit = (EditText) view.findViewById(R.id.edit_text_flex_grow);
    flexGrowEdit.setText(String.valueOf(mFlexItem.flexGrow));
    flexGrowEdit.addTextChangedListener(new FlexEditTextWatcher(flexGrowInput, new NonNegativeDecimalInputValidator(), R.string.must_be_non_negative_float));
    final TextInputLayout flexShrinkInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_shrink);
    EditText flexShrinkEdit = (EditText) view.findViewById(R.id.edit_text_flex_shrink);
    flexShrinkEdit.setText(String.valueOf(mFlexItem.flexShrink));
    flexShrinkEdit.addTextChangedListener(new FlexEditTextWatcher(flexShrinkInput, new NonNegativeDecimalInputValidator(), R.string.must_be_non_negative_float));
    final TextInputLayout flexBasisPercentInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_basis_percent);
    EditText flexBasisPercentEdit = (EditText) view.findViewById(R.id.edit_text_flex_basis_percent);
    if (mFlexItem.flexBasisPercent != FlexboxLayout.LayoutParams.FLEX_BASIS_PERCENT_DEFAULT) {
        flexBasisPercentEdit.setText(String.valueOf(Math.round(mFlexItem.flexBasisPercent * 100)));
    } else {
        flexBasisPercentEdit.setText(String.valueOf((int) mFlexItem.flexBasisPercent));
    }
    flexBasisPercentEdit.addTextChangedListener(new FlexEditTextWatcher(flexBasisPercentInput, new FlexBasisPercentInputValidator(), R.string.must_be_minus_one_or_non_negative_integer));
    final TextInputLayout widthInput = (TextInputLayout) view.findViewById(R.id.input_layout_width);
    EditText widthEdit = (EditText) view.findViewById(R.id.edit_text_width);
    widthEdit.setText(String.valueOf(mFlexItem.width));
    widthEdit.addTextChangedListener(new FlexEditTextWatcher(widthInput, new DimensionInputValidator(), R.string.must_be_minus_one_or_minus_two_or_non_negative_integer));
    final TextInputLayout heightInput = (TextInputLayout) view.findViewById(R.id.input_layout_height);
    EditText heightEdit = (EditText) view.findViewById(R.id.edit_text_height);
    heightEdit.setText(String.valueOf(mFlexItem.height));
    heightEdit.addTextChangedListener(new FlexEditTextWatcher(heightInput, new DimensionInputValidator(), R.string.must_be_minus_one_or_minus_two_or_non_negative_integer));
    final TextInputLayout minWidthInput = (TextInputLayout) view.findViewById(R.id.input_layout_min_width);
    EditText minWidthEdit = (EditText) view.findViewById(R.id.edit_text_min_width);
    minWidthEdit.setText(String.valueOf(mFlexItem.minWidth));
    minWidthEdit.addTextChangedListener(new FlexEditTextWatcher(minWidthInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout minHeightInput = (TextInputLayout) view.findViewById(R.id.input_layout_min_height);
    EditText minHeightEdit = (EditText) view.findViewById(R.id.edit_text_min_height);
    minHeightEdit.setText(String.valueOf(mFlexItem.minHeight));
    minHeightEdit.addTextChangedListener(new FlexEditTextWatcher(minHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout maxWidthInput = (TextInputLayout) view.findViewById(R.id.input_layout_max_width);
    EditText maxWidthEdit = (EditText) view.findViewById(R.id.edit_text_max_width);
    maxWidthEdit.setText(String.valueOf(mFlexItem.maxWidth));
    maxWidthEdit.addTextChangedListener(new FlexEditTextWatcher(maxWidthInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout maxHeightInput = (TextInputLayout) view.findViewById(R.id.input_layout_max_height);
    EditText maxHeightEdit = (EditText) view.findViewById(R.id.edit_text_max_height);
    maxHeightEdit.setText(String.valueOf(mFlexItem.maxHeight));
    maxHeightEdit.addTextChangedListener(new FlexEditTextWatcher(maxHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    setNextFocusesOnEnterDown(orderEdit, flexGrowEdit, flexShrinkEdit, flexBasisPercentEdit, widthEdit, heightEdit, minWidthEdit, minHeightEdit, maxWidthEdit, maxHeightEdit);
    Spinner alignSelfSpinner = (Spinner) view.findViewById(R.id.spinner_align_self);
    ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.array_align_self, R.layout.spinner_item);
    alignSelfSpinner.setAdapter(arrayAdapter);
    alignSelfSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selected = parent.getItemAtPosition(position).toString();
            if (selected.equals(ALIGN_SELF_AUTO)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_AUTO;
            } else if (selected.equals(ALIGN_SELF_FLEX_START)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_FLEX_START;
            } else if (selected.equals(ALIGN_SELF_FLEX_END)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_FLEX_END;
            } else if (selected.equals(ALIGN_SELF_CENTER)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_CENTER;
            } else if (selected.equals(ALIGN_SELF_BASELINE)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_BASELINE;
            } else if (selected.equals(ALIGN_SELF_STRETCH)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_STRETCH;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // No op
        }
    });
    CheckBox wrapBeforeCheckBox = (CheckBox) view.findViewById(R.id.checkbox_wrap_before);
    wrapBeforeCheckBox.setChecked(mFlexItem.wrapBefore);
    wrapBeforeCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mFlexItem.wrapBefore = isChecked;
        }
    });
    int alignSelfPosition = arrayAdapter.getPosition(alignSelfAsString(mFlexItem.alignSelf));
    alignSelfSpinner.setSelection(alignSelfPosition);
    view.findViewById(R.id.button_cancel).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    final Button okButton = (Button) view.findViewById(R.id.button_ok);
    okButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (orderTextInput.isErrorEnabled() || flexGrowInput.isErrorEnabled() || flexBasisPercentInput.isErrorEnabled() || widthInput.isErrorEnabled() || heightInput.isErrorEnabled() || minWidthInput.isErrorEnabled() || minHeightInput.isErrorEnabled() || maxWidthInput.isErrorEnabled() || maxHeightInput.isErrorEnabled()) {
                Toast.makeText(getActivity(), R.string.invalid_values_exist, Toast.LENGTH_SHORT).show();
                return;
            }
            if (mFlexItemChangedListener != null) {
                mFlexItemChangedListener.onFlexItemChanged(mFlexItem);
            }
            dismiss();
        }
    });
    return view;
}
Also used : DimensionInputValidator(com.google.android.apps.flexbox.validators.DimensionInputValidator) FixedDimensionInputValidator(com.google.android.apps.flexbox.validators.FixedDimensionInputValidator) FixedDimensionInputValidator(com.google.android.apps.flexbox.validators.FixedDimensionInputValidator) Spinner(android.widget.Spinner) IntegerInputValidator(com.google.android.apps.flexbox.validators.IntegerInputValidator) NonNegativeDecimalInputValidator(com.google.android.apps.flexbox.validators.NonNegativeDecimalInputValidator) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextInputLayout(android.support.design.widget.TextInputLayout) EditText(android.widget.EditText) FlexBasisPercentInputValidator(com.google.android.apps.flexbox.validators.FlexBasisPercentInputValidator) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) Nullable(android.support.annotation.Nullable)

Example 29 with Spinner

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

the class MainActivity method initializeSpinner.

private void initializeSpinner(int currentValue, int menuItemId, Menu navigationMenu, int arrayResourceId, AdapterView.OnItemSelectedListener listener, ValueToStringConverter converter) {
    Spinner spinner = (Spinner) MenuItemCompat.getActionView(navigationMenu.findItem(menuItemId));
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arrayResourceId, R.layout.spinner_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(listener);
    String selectedAsString = converter.asString(currentValue);
    int position = adapter.getPosition(selectedAsString);
    spinner.setSelection(position);
}
Also used : Spinner(android.widget.Spinner)

Example 30 with Spinner

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

the class MainActivityTest method testFlexDirectionSpinner.

@Test
@SuppressWarnings("unchecked")
@FlakyTest
public void testFlexDirectionSpinner() {
    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_flex_direction));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int columnPosition = spinnerAdapter.getPosition(activity.getString(R.string.column));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(columnPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    final int rowReversePosition = spinnerAdapter.getPosition(activity.getString(R.string.row_reverse));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(rowReversePosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE));
}
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)

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