android.widget.Adapter Java Examples

The following examples show how to use android.widget.Adapter. 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: AddAccountConfigAppItemSelectedListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemSelected(AdapterView<?> parent, View view,
		int position, long id) {
	Adapter adapter = parent.getAdapter();
	Authorization auth = context.getAuth();
	if (auth == null) {
		Logger.error("auth can't be null");
		return;
	}
	
	ConfigApp configApp = (ConfigApp)adapter.getItem(position);		
	if (configApp.getAppId() == -2l) {
		Intent intent = new Intent();
		intent.setClass(context, AddConfigAppActivity.class);
		intent.putExtra("spNo", auth.getServiceProvider().getSpNo());
		context.startActivityForResult(intent, Constants.REQUEST_CODE_CONFIG_APP_ADD);
		return;
	}
	
	OAuthConfig oauthConfig = auth.getoAuthConfig();
	oauthConfig.setConsumerKey(configApp.getAppKey());
	oauthConfig.setConsumerSecret(configApp.getAppSecret());
	oauthConfig.setCallbackUrl(configApp.getCallbackUrl());
	Logger.debug("callback:{}", oauthConfig.getCallbackUrl());
}
 
Example #2
Source File: SeparatedListAdapter.java    From sensordatacollector with GNU General Public License v2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    int sectionnum = 0;
    for(String section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if(position == 0)
            return headers.getView(sectionnum, convertView, parent);
        if(position < size)
            return adapter.getView(position - 1, convertView, parent);

        // otherwise jump into next section
        position -= size;
        sectionnum++;
    }
    return null;
}
 
Example #3
Source File: BaikeFragment.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
protected void bindEvents()
{
	listView.setOnItemClickListener(new OnItemClickListener()
	{

		@Override
		public void onItemClick(Adapter adapter, View view, int position, long id)
		{
			Intent intent = new Intent(getContext(), ImageGridActivity.class);
			intent.putExtra(RockyIntent.EXTRA_ALBUM, (AlbumInfo) adapter.getItem(position));
			startActivity(intent);
		}

	});

	warning_close.setOnClickListener(this);
}
 
Example #4
Source File: AdapterViewProtocols.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Override
public EspressoOptional<AdaptedData> getDataRenderedByView(
    AdapterView<? extends Adapter> adapterView, View descendantView) {
  if (adapterView == descendantView.getParent()) {
    int position = adapterView.getPositionForView(descendantView);
    if (position != AdapterView.INVALID_POSITION) {
      return EspressoOptional.of(
          new AdaptedData.Builder()
              .withDataFunction(
                  new StandardDataFunction(adapterView.getItemAtPosition(position), position))
              .withOpaqueToken(Integer.valueOf(position))
              .build());
    }
  }
  return EspressoOptional.absent();
}
 
Example #5
Source File: AdapterViewTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
private static Matcher<View> withAdaptedData(final Matcher<Object> dataMatcher) {
  return new TypeSafeMatcher<View>() {

    @Override
    public void describeTo(Description description) {
      description.appendText("with class name: ");
      dataMatcher.describeTo(description);
    }

    @Override
    public boolean matchesSafely(View view) {
      if (!(view instanceof AdapterView)) {
        return false;
      }
      @SuppressWarnings("rawtypes")
      Adapter adapter = ((AdapterView) view).getAdapter();
      for (int i = 0; i < adapter.getCount(); i++) {
        if (dataMatcher.matches(adapter.getItem(i))) {
          return true;
        }
      }
      return false;
    }
  };
}
 
Example #6
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 6 votes vote down vote up
private void updateNote(){
    Adapter a = lvItemList.getAdapter();
    JSONArray jsonArray = new JSONArray();

    try {
        CheckListItem temp;
        for (int i = 0; i < itemNamesList.size(); i++) {
            temp = (CheckListItem) a.getItem(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("name", temp.getName());
            jsonObject.put("checked", temp.isChecked());
            jsonArray.put(jsonObject);
        }
        fillNameIfEmpty();
        DbAccess.updateNote(getBaseContext(), id, etName.getText().toString(), jsonArray.toString(), currentCat);
        Toast.makeText(getApplicationContext(), R.string.toast_updated, Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #7
Source File: PullToRefreshList.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 判断第一个child是否完全显示出来
 * 
 * @return true完全显示出来,否则false
 */
private boolean isFirstItemVisible() {
    final Adapter adapter = mfakeListView.getAdapter();

    if (null == adapter || adapter.isEmpty()) {
        return true;
    }

    int mostTop = (mfakeListView.getChildCount() > 0) ? mfakeListView
            .getChildAt(0).getTop() : mfakeListView.getTop();
    if (mostTop >= 0) {
        return true;
    }

    return false;
}
 
Example #8
Source File: PullToRefreshAdapterViewBase.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private boolean c()
{
    Adapter adapter = ((AbsListView)l).getAdapter();
    if (adapter == null || adapter.isEmpty())
    {
        Log.d("PullToRefresh", "isFirstItemVisible. Empty View.");
        return true;
    }
    if (((AbsListView)l).getFirstVisiblePosition() <= 1)
    {
        View view = ((AbsListView)l).getChildAt(0);
        if (view != null)
        {
            return view.getTop() >= ((AbsListView)l).getTop();
        }
    }
    return false;
}
 
Example #9
Source File: AdapterUtil.java    From YiBo with Apache License 2.0 6 votes vote down vote up
public static CacheAdapter<?> getCacheAdapter(Adapter adapter) {
	if (adapter == null) {
		return null;
	}
	CacheAdapter<?> cacheAdapter = null;
	if (adapter instanceof CacheAdapter<?>) {
        cacheAdapter = (CacheAdapter<?>)adapter;
	} else if (adapter instanceof HeaderViewListAdapter) {
		HeaderViewListAdapter headerViewAdapter = (HeaderViewListAdapter)adapter;
		if (headerViewAdapter.getWrappedAdapter() instanceof CacheAdapter<?>) {
			cacheAdapter = (CacheAdapter<?>)headerViewAdapter.getWrappedAdapter();
		}
	}
	
	return cacheAdapter;
}
 
Example #10
Source File: DraggableGridViewPager.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public void setAdapter(Adapter adapter) {
	if (mAdapter != null) {
		mAdapter.unregisterDataSetObserver(mDataSetObserver);
		removeAllViews();
		mCurItem = 0;
		scrollTo(0, 0);
	}
	mAdapter = adapter;
	if (mAdapter != null) {
		mAdapter.registerDataSetObserver(mDataSetObserver);
		for (int i = 0; i < mAdapter.getCount(); i++) {
			final View child = mAdapter.getView(i, null, this);
			addView(child);
		}
	}
}
 
Example #11
Source File: FlipViewController.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public void setAdapter(Adapter adapter, int initialPosition) {
  if (this.adapter != null) {
    this.adapter.unregisterDataSetObserver(adapterDataObserver);
  }

  Assert.assertNotNull("adapter should not be null", adapter);

  this.adapter = adapter;
  adapterDataCount = adapter.getCount();

  adapterDataObserver = new MyDataSetObserver();
  this.adapter.registerDataSetObserver(adapterDataObserver);
  if (adapterDataCount > 0) {
    setSelection(initialPosition);
  }
}
 
Example #12
Source File: PullToRefreshAdapterViewBase.java    From MagicHeaderViewPager with Apache License 2.0 6 votes vote down vote up
private boolean isFirstItemVisible() {
    final Adapter adapter = mRefreshableView.getAdapter();

    if(null == adapter || adapter.isEmpty()) {
        return true;

    } else {

        /**
         * This check should really just be: mRefreshableView.getFirstVisiblePosition() == 0, but PtRListView internally use a
         * HeaderView which messes the positions up. For now we'll just add one to account for it and rely on the inner
         * condition which checks getTop().
         */
        if(mRefreshableView.getFirstVisiblePosition() <= 1) {
            final View firstVisibleChild = mRefreshableView.getChildAt(0);
            if(firstVisibleChild != null) {
                return firstVisibleChild.getTop() >= mRefreshableView.getTop();
            }
        }
    }

    return false;
}
 
Example #13
Source File: ConversationItemClickListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
		long id) {
	Adapter adapter = parent.getAdapter();
	message = (DirectMessage)adapter.getItem(position);
       if (message == null 
       	|| (message instanceof LocalDirectMessage
       		&& ((LocalDirectMessage)message).isDivider())) {
       	return;
       }

       if (adapter instanceof HeaderViewListAdapter) {
       	adapter = ((HeaderViewListAdapter)adapter).getWrappedAdapter();
       }
	CacheAdapter<DirectMessage> cacheAdapter = (CacheAdapter<DirectMessage>)adapter;

       Dialog dialog = onCreateDialog(cacheAdapter, position);
       if (dialog != null) {
       	dialog.show();
       }
}
 
Example #14
Source File: ViewFlow.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
public void setAdapter(Adapter adapter, int initialPosition) {
	if (mAdapter != null) {
		mAdapter.unregisterDataSetObserver(mDataSetObserver);
	}

	mAdapter = adapter;

	if (mAdapter != null) {
		mDataSetObserver = new AdapterDataSetObserver();
		mAdapter.registerDataSetObserver(mDataSetObserver);

	}
	if (mAdapter == null || mAdapter.getCount() == 0)
		return;
	
	setSelection(initialPosition);		
}
 
Example #15
Source File: FoldableListLayout.java    From FoldableLayout with Apache License 2.0 6 votes vote down vote up
private void setupAdapterView(FoldableItemLayout layout, int position) {
    // Binding layout to new data
    int type = adapter.getItemViewType(position);

    View recycledView = null;
    if (type != Adapter.IGNORE_ITEM_VIEW_TYPE) {
        Queue<View> cache = recycledViews.get(type);
        recycledView = cache == null ? null : cache.poll();
    }

    View view = adapter.getView(position, recycledView, layout.getBaseLayout());

    if (type != Adapter.IGNORE_ITEM_VIEW_TYPE) {
        viewsTypesMap.put(view, type);
    }

    layout.getBaseLayout().addView(view, PARAMS);
}
 
Example #16
Source File: SectionListAdapter.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
@Override
public int getItemViewType(int position)
{
    int type = 1;
    
    for (final Object section : sectionMap.keySet())
    {
        
        final Adapter adapter = sectionMap.get(section);
        final int size = adapter.getCount() + (hasSectionHeader ? 1 : 0);
        
        if (position == 0 && hasSectionHeader)
            return TYPE_SECTION_HEADER;
        
        if (position < size)
            return type + adapter.getItemViewType(position - 1);
        
        position -= size;
        type += adapter.getViewTypeCount();
    }
    
    return -1;
}
 
Example #17
Source File: SwipeLayout.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * if working in {@link android.widget.AdapterView}, we should response
 * {@link android.widget.Adapter} isEnable(int position).
 *
 * @return true when item is enabled, else disabled.
 */
private boolean isEnabledInAdapterView() {
    AdapterView adapterView = getAdapterView();
    boolean enable = true;
    if (adapterView != null) {
        Adapter adapter = adapterView.getAdapter();
        if (adapter != null) {
            int p = adapterView.getPositionForView(SwipeLayout.this);
            if (adapter instanceof BaseAdapter) {
                enable = ((BaseAdapter) adapter).isEnabled(p);
            } else if (adapter instanceof ListAdapter) {
                enable = ((ListAdapter) adapter).isEnabled(p);
            }
        }
    }
    return enable;
}
 
Example #18
Source File: AdapterUtil.java    From YiBo with Apache License 2.0 6 votes vote down vote up
public static BaseListAdapter<?> getBaseListAdapter(Adapter adapter) {
	if (adapter == null) {
		return null;
	}
	
	BaseListAdapter<?> baseListAdapter = null;
	if (adapter instanceof BaseListAdapter<?>) {
        baseListAdapter = (BaseListAdapter<?>)adapter;
	} else if (adapter instanceof HeaderViewListAdapter) {
		HeaderViewListAdapter headerViewAdapter = (HeaderViewListAdapter)adapter;
		if (headerViewAdapter.getWrappedAdapter() instanceof BaseListAdapter<?>) {
			baseListAdapter = (BaseListAdapter<?>)headerViewAdapter.getWrappedAdapter();
		}
	}
	
	return baseListAdapter;
}
 
Example #19
Source File: SeparatedListAdapter.java    From sensordatacollector with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getItemViewType(int position)
{
    int type = 1;
    for(String section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if(position == 0)
            return TYPE_SECTION_HEADER;
        if(position < size)
            return type + adapter.getItemViewType(position - 1);

        // otherwise jump into next section
        position -= size;
        type += adapter.getViewTypeCount();
    }
    return -1;
}
 
Example #20
Source File: SectionListAdapter.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
public Adapter getAdapter(int position)
{
    for (final Adapter adapter : sectionMap.values())
    {
        final int size = adapter.getCount() + (hasSectionHeader ? 1 : 0);
        
        if (position == 0 && hasSectionHeader)
            return null;
        
        if (position < size)
            return adapter;
        
        position -= size;
    }
    
    return null;
}
 
Example #21
Source File: SeparatedListAdapter.java    From RoMote with Apache License 2.0 6 votes vote down vote up
public int getItemViewType(int position) {
    int type = 1;
    for(Object section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if(position == 0) return TYPE_SECTION_HEADER;
        if(position < size) return type + adapter.getItemViewType(position - 1);

        // otherwise jump into next section
        position -= size;
        type += adapter.getViewTypeCount();
    }
    return -1;
}
 
Example #22
Source File: StarkSpinner.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
public void setSelectedItem(int position) {
    Adapter adapter = mSpinnerListView.getAdapter();
    if (adapter instanceof ISpinnerSelectedView) {
        View selectedView = ((ISpinnerSelectedView) adapter).getSelectedView(position);
        mCurrSelectedView = new SelectedView(selectedView, position, selectedView.getId());
        mSpinnerListView.setSelection(position);
    } else {
        TextView textView = new TextView(mContext);
        textView.setText(mRevealEmptyText);
        mCurrSelectedView = new SelectedView(textView, -1, 0);
        mRevealItem.addView(textView);
    }
    if (mCurrSelectedView == null) {
        if (mOnItemSelected != null)
            mOnItemSelected.onNothingSelected();
    } else if (mCurrSelectedView != null) {
        mRevealItem.removeAllViews();
        mSpinnerListView.removeViewInLayout(mCurrSelectedView.getView());
        mRevealItem.addView(mCurrSelectedView.getView());
        ((BaseAdapter) mSpinnerListView.getAdapter()).notifyDataSetChanged();
        if (mOnItemSelected != null)
            mOnItemSelected.onItemSelected(mCurrSelectedView.getView(), mCurrSelectedView.getPosition(), mCurrSelectedView.getId());
    }
    hideEdit();
}
 
Example #23
Source File: DraggableGridViewPager.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public void setAdapter(Adapter adapter) {
	if (mAdapter != null) {
		mAdapter.unregisterDataSetObserver(mDataSetObserver);
		removeAllViews();
		mCurItem = 0;
		scrollTo(0, 0);
	}
	mAdapter = adapter;
	if (mAdapter != null) {
		mAdapter.registerDataSetObserver(mDataSetObserver);
		for (int i = 0; i < mAdapter.getCount(); i++) {
			final View child = mAdapter.getView(i, null, this);
			addView(child);
		}
	}
}
 
Example #24
Source File: DirectMessagesItemClickListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
		long id) {
	Adapter adapter = parent.getAdapter();
	message = (DirectMessage)adapter.getItem(position);
       if (message == null 
       	|| (message instanceof LocalDirectMessage
       		&& ((LocalDirectMessage)message).isDivider())) {
       	return;
       }

       if (adapter instanceof HeaderViewListAdapter) {
       	adapter = ((HeaderViewListAdapter)adapter).getWrappedAdapter();
       }
	CacheAdapter<DirectMessage> cacheAdapter = (CacheAdapter<DirectMessage>)adapter;

       Dialog dialog = onCreateDialog(cacheAdapter, position);
       if (dialog != null) {
       	dialog.show();
       }
}
 
Example #25
Source File: ShortcutLauncherFolderActivity.java    From FreezeYou with Apache License 2.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

    if ("pkgS".equals(key)) {
        final GridView slf_apps_gridView = findViewById(R.id.slf_apps_gridView);
        if (slf_apps_gridView != null) {
            Adapter adapter = slf_apps_gridView.getAdapter();
            if (adapter instanceof ReplaceableSimpleAdapter) {
                final ArrayList<Map<String, Object>> folderItems = new ArrayList<>();
                generateFolderItems(folderItems, sharedPreferences);
                ((ReplaceableSimpleAdapter) adapter).replaceAllInFormerArrayList(folderItems);
            }
        }
    } else if ("folderName".equals(key)) {
        final TextView slf_folderName_textView = findViewById(R.id.slf_folderName_textView);
        if (slf_folderName_textView != null) {
            slf_folderName_textView.setText(sharedPreferences.getString("folderName", getString(R.string.folder)));
        }
    }
}
 
Example #26
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 6 votes vote down vote up
private void saveNote(){
    Adapter a = lvItemList.getAdapter();
    JSONArray jsonArray = new JSONArray();
    try {
        CheckListItem temp;
        for (int i = 0; i < itemNamesList.size(); i++) {
            temp = (CheckListItem) a.getItem(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("name", temp.getName());
            jsonObject.put("checked", temp.isChecked());
            jsonArray.put(jsonObject);
        }
        fillNameIfEmpty();
        id = DbAccess.addNote(getBaseContext(), etName.getText().toString(), jsonArray.toString(), DbContract.NoteEntry.TYPE_CHECKLIST, currentCat);
        Toast.makeText(getApplicationContext(), R.string.toast_saved, Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #27
Source File: ProofActivity.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
private static int getWidestView(Context context, Adapter adapter)
{
	int maxWidth = 0;
	View view = null;
	FrameLayout fakeParent = new FrameLayout(context);
	for (int i=0, count=adapter.getCount(); i<count; i++) {
		view = adapter.getView(i, view, fakeParent);
		view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
		int width = view.getMeasuredWidth();
		if (width > maxWidth) {
			maxWidth = width;
		}
	}
	return maxWidth;
}
 
Example #28
Source File: SwipeFlingAdapterView.java    From SwipeCardView with Apache License 2.0 5 votes vote down vote up
/**
 * A shortcut method to set both the listeners and the adapter.
 *
 * @param context The activity context which extends onFlingListener, OnItemClickListener or both
 * @param mAdapter The adapter you have to set.
 */
public void init(final Context context, Adapter mAdapter) {
    if(context instanceof onFlingListener) {
        mFlingListener = (onFlingListener) context;
    }else{
        throw new RuntimeException("Activity does not implement SwipeFlingAdapterView.onFlingListener");
    }
    if(context instanceof OnItemClickListener){
        mOnItemClickListener = (OnItemClickListener) context;
    }
    setAdapter(mAdapter);
}
 
Example #29
Source File: InboxLayoutListView.java    From InboxLayout with MIT License 5 votes vote down vote up
protected boolean isReadyForDragStart(){
    final Adapter adapter = dragableView.getAdapter();
    if(null == adapter || adapter.isEmpty()){
        return true;
    }else{
        if( dragableView.getFirstVisiblePosition()<=1 ){
            final View firstVisibleChild = dragableView.getChildAt(0);
            if(firstVisibleChild != null){
                return firstVisibleChild.getTop() >= dragableView.getTop();
            }
        }
    }
    return false;
}
 
Example #30
Source File: PullToRefreshAdapterViewBase.java    From sctalk with Apache License 2.0 5 votes vote down vote up
private boolean isLastItemVisible() {
	final Adapter adapter = mRefreshableView.getAdapter();

	if (null == adapter || adapter.isEmpty()) {
		if (DEBUG) {
			Log.d(LOG_TAG, "isLastItemVisible. Empty View.");
		}
		return true;
	} else {
		final int lastItemPosition = mRefreshableView.getCount() - 1;
		final int lastVisiblePosition = mRefreshableView.getLastVisiblePosition();

		if (DEBUG) {
			Log.d(LOG_TAG, "isLastItemVisible. Last Item Position: " + lastItemPosition + " Last Visible Pos: "
					+ lastVisiblePosition);
		}

		/**
		 * This check should really just be: lastVisiblePosition ==
		 * lastItemPosition, but PtRListView internally uses a FooterView
		 * which messes the positions up. For me we'll just subtract one to
		 * account for it and rely on the inner condition which checks
		 * getBottom().
		 */
		if (lastVisiblePosition >= lastItemPosition - 1) {
			final int childIndex = lastVisiblePosition - mRefreshableView.getFirstVisiblePosition();
			final View lastVisibleChild = mRefreshableView.getChildAt(childIndex);
			if (lastVisibleChild != null) {
				return lastVisibleChild.getBottom() <= mRefreshableView.getBottom();
			}
		}
	}

	return false;
}