android.widget.SpinnerAdapter Java Examples

The following examples show how to use android.widget.SpinnerAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlarmDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
public void setChoice( SolarEvents choice )
{
    if (choice != null)
    {
        this.choice = choice;
        if (spinner_scheduleMode != null)
        {
            SpinnerAdapter adapter = spinner_scheduleMode.getAdapter();
            if (adapter != null)
            {
                for (int i = 0; i < adapter.getCount(); i++)
                {
                    SolarEvents event = (SolarEvents) adapter.getItem(i);
                    if (event.equals(choice))
                    {
                        spinner_scheduleMode.setSelection(i);
                        break;
                    }
                }
            }
        }
    }
}
 
Example #2
Source File: VoiceRecognition.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private void updateSupportedLanguages(List<String> languages) {
    // We add "Default" at the beginning of the list to simulate default language.
    languages.add(0, "Default");

    SpinnerAdapter adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, languages.toArray(
                    new String[languages.size()]));
    mSupportedLanguageView.setAdapter(adapter);
}
 
Example #3
Source File: AutoResizeSpinner.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    SpinnerAdapter adapter = getAdapter();
    if (adapter != null && MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) {
        View view = adapter.getView(getSelectedItemPosition(), null, this);
        if (view.getLayoutParams() == null)
            view.setLayoutParams(mDefaultLayoutParams);
        view.measure(widthMeasureSpec, heightMeasureSpec);
        int width = view.getMeasuredWidth();
        if (getBackground() != null) {
            getBackground().getPadding(mTempRect);
            width += mTempRect.left + mTempRect.right;
        }

        this.setMeasuredDimension(Math.min(width, MeasureSpec.getSize(widthMeasureSpec)), this.getMeasuredHeight());
    }

}
 
Example #4
Source File: SoundActivityTest.java    From openwebnet-android with MIT License 6 votes vote down vote up
@Test
public void shouldVerifyOnCreate_initSpinner_noResult() {
    when(environmentService.findAll()).thenReturn(Observable.just(new ArrayList<>()));
    when(gatewayService.findAll()).thenReturn(Observable.just(new ArrayList<>()));

    createWithIntent(null);

    SpinnerAdapter adapterEnvironment = spinnerDeviceEnvironment.getAdapter();
    assertFalse("should not be empty", adapterEnvironment.isEmpty());
    assertEquals("should verify first element", labelNone, adapterEnvironment.getItem(0));

    SpinnerAdapter adapterGateway = spinnerDeviceGateway.getAdapter();
    assertFalse("should not be empty", adapterGateway.isEmpty());
    assertEquals("should verify first element", labelMissingGateway, adapterGateway.getItem(0));

    verifyInitSpinnerSoundType();
}
 
Example #5
Source File: MergeSpinnerAdapter.java    From AndroidBleManager with Apache License 2.0 6 votes vote down vote up
public View getDropDownView(int position, View convertView,
                            ViewGroup parent) {
    for (ListAdapter piece : getPieces()) {
        int size=piece.getCount();

        if (position<size) {
            return(((SpinnerAdapter)piece).getDropDownView(position,
                    convertView,
                    parent));
        }

        position-=size;
    }

    return(null);
}
 
Example #6
Source File: LightActivityTest.java    From openwebnet-android with MIT License 6 votes vote down vote up
@Test
public void shouldVerifyOnCreate_initSpinner_noResult() {
    when(environmentService.findAll()).thenReturn(Observable.just(new ArrayList<>()));
    when(gatewayService.findAll()).thenReturn(Observable.just(new ArrayList<>()));

    createWithIntent(null);

    SpinnerAdapter adapterEnvironment = spinnerDeviceEnvironment.getAdapter();
    assertFalse("should not be empty", adapterEnvironment.isEmpty());
    assertEquals("should verify first element", labelNone, adapterEnvironment.getItem(0));

    SpinnerAdapter adapterGateway = spinnerDeviceGateway.getAdapter();
    assertFalse("should not be empty", adapterGateway.isEmpty());
    assertEquals("should verify first element", labelMissingGateway, adapterGateway.getItem(0));

    verifyInitSpinnerLightType();
}
 
Example #7
Source File: IcsAbsSpinner.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The Adapter is used to provide the data which backs this Spinner.
 * It also provides methods to transform spinner items based on their position
 * relative to the selected item.
 * @param adapter The SpinnerAdapter to use for this Spinner
 */
@Override
public void setAdapter(SpinnerAdapter adapter) {
    if (null != mAdapter) {
        mAdapter.unregisterDataSetObserver(mDataSetObserver);
        resetList();
    }

    mAdapter = adapter;

    mOldSelectedPosition = INVALID_POSITION;
    mOldSelectedRowId = INVALID_ROW_ID;

    if (mAdapter != null) {
        mOldItemCount = mItemCount;
        mItemCount = mAdapter.getCount();
        checkFocus();

        mDataSetObserver = new AdapterDataSetObserver();
        mAdapter.registerDataSetObserver(mDataSetObserver);

        int position = mItemCount > 0 ? 0 : INVALID_POSITION;

        setSelectedPositionInt(position);
        setNextSelectedPositionInt(position);

        if (mItemCount == 0) {
            // Nothing selected
            checkSelectionChanged();
        }

    } else {
        checkFocus();
        resetList();
        // Nothing selected
        checkSelectionChanged();
    }

    requestLayout();
}
 
Example #8
Source File: DeviceActivityTest.java    From openwebnet-android with MIT License 5 votes vote down vote up
@Test
public void shouldVerifyOnCreate_initSpinner_selectedDefault() {
    List<EnvironmentModel> environments = Arrays.asList(newEnvironment(100, "env1"),
        newEnvironment(101, "env2"), newEnvironment(102, "env3"));

    List<GatewayModel> gateways = Arrays.asList(newGateway("uuid1", "1.1.1.1", 1),
        newGateway("uuid2", "2.2.2.2", 2), newGateway("uuid3", "3.3.3.3", 3));

    when(environmentService.findAll()).thenReturn(Observable.just(environments));
    when(gatewayService.findAll()).thenReturn(Observable.just(gateways));

    createActivityWithIntent(null, 101, "uuid2");

    SpinnerAdapter adapterEnvironment = spinnerDeviceEnvironment.getAdapter();
    assertFalse("should not be empty", adapterEnvironment.isEmpty());
    assertEquals("should verify 1st element", "env1", adapterEnvironment.getItem(0));
    assertEquals("should verify 2nd element", "env2", adapterEnvironment.getItem(1));
    assertEquals("should verify 3rd element", "env3", adapterEnvironment.getItem(2));
    assertEquals("should be selected", 1, spinnerDeviceEnvironment.getSelectedItemPosition());

    SpinnerAdapter adapterGateway = spinnerDeviceGateway.getAdapter();
    assertFalse("should not be empty", adapterGateway.isEmpty());
    assertEquals("should verify 1st element", "1.1.1.1:1", adapterGateway.getItem(0));
    assertEquals("should verify 2nd element", "2.2.2.2:2", adapterGateway.getItem(1));
    assertEquals("should verify 3rd element", "3.3.3.3:3", adapterGateway.getItem(2));
    assertEquals("should be selected", 1, spinnerDeviceGateway.getSelectedItemPosition());
}
 
Example #9
Source File: RecurActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private void editRecur(Recur recur) {
    editStartDate(recur.startDate);
    RecurInterval interval = recur.interval;
    SpinnerAdapter adapter = sInterval.getAdapter();
    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        SpinnerItem item = (SpinnerItem) adapter.getItem(i);
        if (interval == RecurInterval.valueOf(item.value)) {
            sInterval.setSelection(i);
            break;
        }
    }
    View v = selectInterval(interval);
    switch (interval) {
        case EVERY_X_DAY:
            editEveryXDay(v, recur);
            break;
        case WEEKLY:
            editWeekly(v, recur);
            break;
        case SEMI_MONTHLY:
            editSemiMonthly(v, recur);
            break;
    }
    RecurPeriod period = recur.period;
    sPeriod.setSelection(period.ordinal());
    v = selectPeriod(period);
    switch (period) {
        case EXACTLY_TIMES:
            editExactlyTimes(v, recur.periodParam);
            break;
        case STOPS_ON_DATE:
            editStopsOnDate(v, recur.periodParam);
            break;
    }
}
 
Example #10
Source File: ActionBarImpl.java    From zen4android with MIT License 5 votes vote down vote up
@Override
public int getNavigationItemCount() {
    switch (mActionView.getNavigationMode()) {
        case NAVIGATION_MODE_TABS:
            return mTabs.size();
        case NAVIGATION_MODE_LIST:
            SpinnerAdapter adapter = mActionView.getDropdownAdapter();
            return adapter != null ? adapter.getCount() : 0;
        default:
            return 0;
    }
}
 
Example #11
Source File: ActionBarImpl.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getNavigationItemCount() {
    switch (mActionView.getNavigationMode()) {
        case NAVIGATION_MODE_TABS:
            return mTabs.size();
        case NAVIGATION_MODE_LIST:
            SpinnerAdapter adapter = mActionView.getDropdownAdapter();
            return adapter != null ? adapter.getCount() : 0;
        default:
            return 0;
    }
}
 
Example #12
Source File: NoDefaultSpinner.java    From homeassist with Apache License 2.0 5 votes vote down vote up
protected SpinnerAdapterProxy(SpinnerAdapter obj) {
    this.obj = obj;
    try {
        this.getView = SpinnerAdapter.class.getMethod(
                "getView", int.class, View.class, ViewGroup.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #13
Source File: IcsSpinner.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <p>Creates a new ListAdapter wrapper for the specified adapter.</p>
 *
 * @param adapter the Adapter to transform into a ListAdapter
 */
public DropDownAdapter(SpinnerAdapter adapter) {
    this.mAdapter = adapter;
    if (adapter instanceof ListAdapter) {
        this.mListAdapter = (ListAdapter) adapter;
    }
}
 
Example #14
Source File: CustomInputStylePreference.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
private static void setSpinnerPosition(final Spinner spinner, final Object itemToSelect) {
    final SpinnerAdapter adapter = spinner.getAdapter();
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        final Object item = spinner.getItemAtPosition(i);
        if (item.equals(itemToSelect)) {
            spinner.setSelection(i);
            return;
        }
    }
}
 
Example #15
Source File: IcsSpinner.java    From android-apps with MIT License 5 votes vote down vote up
@Override
public void setAdapter(SpinnerAdapter adapter) {
    super.setAdapter(adapter);

    if (mPopup != null) {
        mPopup.setAdapter(new DropDownAdapter(adapter));
    } else {
        mTempAdapter = new DropDownAdapter(adapter);
    }
}
 
Example #16
Source File: AutomationActivityTest.java    From openwebnet-android with MIT License 5 votes vote down vote up
@Test
public void shouldVerifyOnCreate_initSpinner() {
    List<EnvironmentModel> environments = Arrays.
        asList(newEnvironment(100, "env1"), newEnvironment(101, "env2"));

    List<GatewayModel> gateways = Arrays.
        asList(newGateway("uuid1", "1.1.1.1", 1), newGateway("uuid2", "2.2.2.2", 2));

    when(environmentService.findAll()).thenReturn(Observable.just(environments));
    when(gatewayService.findAll()).thenReturn(Observable.just(gateways));

    createWithIntent(null);

    SpinnerAdapter adapterEnvironment = spinnerDeviceEnvironment.getAdapter();
    assertFalse("should not be empty", adapterEnvironment.isEmpty());
    assertEquals("should verify first element", "env1", adapterEnvironment.getItem(0));
    assertEquals("should verify second element", "env2", adapterEnvironment.getItem(1));
    assertEquals("should select default", 0, spinnerDeviceEnvironment.getSelectedItemPosition());

    SpinnerAdapter adapterGateway = spinnerDeviceGateway.getAdapter();
    assertFalse("should not be empty", adapterGateway.isEmpty());
    assertEquals("should verify first element", "1.1.1.1:1", adapterGateway.getItem(0));
    assertEquals("should verify second element", "2.2.2.2:2", adapterGateway.getItem(1));
    assertEquals("should select default", 0, spinnerDeviceGateway.getSelectedItemPosition());

    verifyInitSpinnerAutomationType();
}
 
Example #17
Source File: CustomInputStylePreference.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
private static void setSpinnerPosition(final Spinner spinner, final Object itemToSelect) {
    final SpinnerAdapter adapter = spinner.getAdapter();
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        final Object item = spinner.getItemAtPosition(i);
        if (item.equals(itemToSelect)) {
            spinner.setSelection(i);
            return;
        }
    }
}
 
Example #18
Source File: CustomInputStylePreference.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
private static void setSubtypeSpinnerPosition(final Spinner spinner, final SubtypeLocaleItem itemToSelect) {
    final SpinnerAdapter adapter = spinner.getAdapter();
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        final SubtypeLocaleItem item = (SubtypeLocaleItem)spinner.getItemAtPosition(i);
        if (item.mLocaleString.equals(itemToSelect.mLocaleString)) {
            spinner.setSelection(i);
            return;
        }
    }
}
 
Example #19
Source File: CustomInputStylePreference.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
private static void setSpinnerPosition(final Spinner spinner, final Object itemToSelect) {
    final SpinnerAdapter adapter = spinner.getAdapter();
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        final Object item = spinner.getItemAtPosition(i);
        if (item.equals(itemToSelect)) {
            spinner.setSelection(i);
            return;
        }
    }
}
 
Example #20
Source File: SoundActivityTest.java    From openwebnet-android with MIT License 5 votes vote down vote up
@Test
public void shouldVerifyOnCreate_initSpinner() {
    List<EnvironmentModel> environments = Arrays.
        asList(newEnvironment(100, "env1"), newEnvironment(101, "env2"));

    List<GatewayModel> gateways = Arrays.
        asList(newGateway("uuid1", "1.1.1.1", 1), newGateway("uuid2", "2.2.2.2", 2));

    when(environmentService.findAll()).thenReturn(Observable.just(environments));
    when(gatewayService.findAll()).thenReturn(Observable.just(gateways));

    createWithIntent(null);

    SpinnerAdapter adapterEnvironment = spinnerDeviceEnvironment.getAdapter();
    assertFalse("should not be empty", adapterEnvironment.isEmpty());
    assertEquals("should verify first element", "env1", adapterEnvironment.getItem(0));
    assertEquals("should verify second element", "env2", adapterEnvironment.getItem(1));
    assertEquals("should select default", 0, spinnerDeviceEnvironment.getSelectedItemPosition());

    SpinnerAdapter adapterGateway = spinnerDeviceGateway.getAdapter();
    assertFalse("should not be empty", adapterGateway.isEmpty());
    assertEquals("should verify first element", "1.1.1.1:1", adapterGateway.getItem(0));
    assertEquals("should verify second element", "2.2.2.2:2", adapterGateway.getItem(1));
    assertEquals("should select default", 0, spinnerDeviceGateway.getSelectedItemPosition());

    verifyInitSpinnerSoundType();
}
 
Example #21
Source File: ExchangeRatesListActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private SpinnerAdapter createCurrencyAdapter(List<Currency> currencies) {
    ArrayAdapter<Currency> a = new ArrayAdapter<Currency>(this, android.R.layout.simple_spinner_item, currencies) {
        @Override
        public long getItemId(int position) {
            return getItem(position).id;
        }
    };
    a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return a;
}
 
Example #22
Source File: IpcamActivityTest.java    From openwebnet-android with MIT License 5 votes vote down vote up
@Test
public void shouldVerifyOnCreate_initSpinnerEnvironment() {
    List<EnvironmentModel> environments = Arrays.
        asList(newEnvironment(100, "env1"), newEnvironment(101, "env2"));

    when(environmentService.findAll()).thenReturn(Observable.just(environments));

    createWithIntent(null);

    SpinnerAdapter adapterEnvironment = spinnerDeviceEnvironment.getAdapter();
    assertFalse("should not be empty", adapterEnvironment.isEmpty());
    assertEquals("should verify first element", "env1", adapterEnvironment.getItem(0));
    assertEquals("should verify second element", "env2", adapterEnvironment.getItem(1));
    assertEquals("should select default", 0, spinnerDeviceEnvironment.getSelectedItemPosition());
}
 
Example #23
Source File: ConnectionFragment.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
private void setSpinnerSelection(Spinner spinner, int position) {
    SpinnerAdapter adapter = spinner.getAdapter();
    if (adapter != null) {
        final int count = adapter.getCount();
        if (count > 0 && position < count) {
            spinner.setSelection(position, true);
        }
    }
}
 
Example #24
Source File: FileSelectorActivity.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
private void selectItemOfSpinner( Spinner spinner , String s )
{
    SpinnerAdapter adapter = spinner.getAdapter();
    int max = adapter.getCount();
    for( int i=0;i<max;i++ ){
        String item = (String)adapter.getItem(i);
        if ( s.equals(item) ){
            spinner.setSelection(i);
            break;
        }
    }
    return;
}
 
Example #25
Source File: IcsSpinner.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@Override
public void setAdapter(SpinnerAdapter adapter) {
    super.setAdapter(adapter);

    if (mPopup != null) {
        mPopup.setAdapter(new DropDownAdapter(adapter));
    } else {
        mTempAdapter = new DropDownAdapter(adapter);
    }
}
 
Example #26
Source File: DetailFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
void setSpinnerSelection(String notebookSummary){
    Spinner spinner = (Spinner) activity.findViewById(R.id.spinner_notebook);
    SpinnerAdapter adapter = spinner.getAdapter();
    for(int i=0;i<adapter.getCount();i++){
        String nbsummary = adapter.getItem(i).toString();
        if(nbsummary.equals(notebookSummary)){
            spinner.setSelection(i);
            break;
        }
    }
}
 
Example #27
Source File: CloudletFragment.java    From faceswap with Apache License 2.0 5 votes vote down vote up
private SpinnerAdapter createSpinnerAdapterFromList(List<String> items){
    ArrayAdapter<String> spinnerAdapter =
            new ArrayAdapter<String>(getContext(),
                    android.R.layout.simple_spinner_item, items);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return spinnerAdapter;
}
 
Example #28
Source File: ActionBarImpl.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@Override
public int getNavigationItemCount() {
    switch (mActionView.getNavigationMode()) {
        case NAVIGATION_MODE_TABS:
            return mTabs.size();
        case NAVIGATION_MODE_LIST:
            SpinnerAdapter adapter = mActionView.getDropdownAdapter();
            return adapter != null ? adapter.getCount() : 0;
        default:
            return 0;
    }
}
 
Example #29
Source File: IcsAbsSpinner.java    From zen4android with MIT License 5 votes vote down vote up
/**
 * The Adapter is used to provide the data which backs this Spinner.
 * It also provides methods to transform spinner items based on their position
 * relative to the selected item.
 * @param adapter The SpinnerAdapter to use for this Spinner
 */
@Override
public void setAdapter(SpinnerAdapter adapter) {
    if (null != mAdapter) {
        mAdapter.unregisterDataSetObserver(mDataSetObserver);
        resetList();
    }

    mAdapter = adapter;

    mOldSelectedPosition = INVALID_POSITION;
    mOldSelectedRowId = INVALID_ROW_ID;

    if (mAdapter != null) {
        mOldItemCount = mItemCount;
        mItemCount = mAdapter.getCount();
        checkFocus();

        mDataSetObserver = new AdapterDataSetObserver();
        mAdapter.registerDataSetObserver(mDataSetObserver);

        int position = mItemCount > 0 ? 0 : INVALID_POSITION;

        setSelectedPositionInt(position);
        setNextSelectedPositionInt(position);

        if (mItemCount == 0) {
            // Nothing selected
            checkSelectionChanged();
        }

    } else {
        checkFocus();
        resetList();
        // Nothing selected
        checkSelectionChanged();
    }

    requestLayout();
}
 
Example #30
Source File: MaterialSpinner.java    From MaterialSpinner with Apache License 2.0 5 votes vote down vote up
@Override
public void setAdapter(SpinnerAdapter adapter) {
    if(adapter instanceof HintAdapter) {
        super.setAdapter(adapter);
    } else {
        hintAdapter = new HintAdapter(adapter, getContext());
        super.setAdapter(hintAdapter);
    }
}