use of android.widget.AbsListView in project AndroidPicker by gzu-liyujiang.
the class PathAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final Context context = parent.getContext();
ViewHolder holder;
if (convertView == null) {
int matchParent = ViewGroup.LayoutParams.MATCH_PARENT;
int wrapContent = ViewGroup.LayoutParams.WRAP_CONTENT;
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setGravity(Gravity.CENTER_VERTICAL);
// fixed: 17-1-8 #79 安卓4.x兼容问题,java.lang.ClassCastException……onMeasure……
if (parent instanceof AbsListView) {
layout.setLayoutParams(new AbsListView.LayoutParams(matchParent, matchParent));
} else {
layout.setLayoutParams(new ViewGroup.LayoutParams(matchParent, matchParent));
}
TextView textView = new TextView(context);
LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams(wrapContent, matchParent);
textView.setLayoutParams(tvParams);
textView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
int padding = ConvertUtils.toPx(context, 5);
textView.setPadding(padding, 0, padding, 0);
layout.addView(textView);
ImageView imageView = new ImageView(context);
int width = ConvertUtils.toPx(context, 20);
imageView.setLayoutParams(new LinearLayout.LayoutParams(width, matchParent));
imageView.setImageResource(android.R.drawable.ic_menu_report_image);
layout.addView(imageView);
convertView = layout;
holder = new ViewHolder();
holder.textView = textView;
holder.imageView = imageView;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(paths.get(position));
holder.imageView.setImageDrawable(arrowIcon);
return convertView;
}
use of android.widget.AbsListView in project TwinklingRefreshLayout by lcodecorex.
the class ScrollingUtil method scrollAViewBy.
public static void scrollAViewBy(View view, int height) {
if (view instanceof RecyclerView)
((RecyclerView) view).scrollBy(0, height);
else if (view instanceof ScrollView)
((ScrollView) view).smoothScrollBy(0, height);
else if (view instanceof AbsListView)
((AbsListView) view).smoothScrollBy(height, 0);
else {
try {
Method method = view.getClass().getDeclaredMethod("smoothScrollBy", Integer.class, Integer.class);
method.invoke(view, 0, height);
} catch (Exception e) {
view.scrollBy(0, height);
}
}
}
use of android.widget.AbsListView in project AndroidPicker by gzu-liyujiang.
the class WheelView method onScrollStateChanged.
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState != SCROLL_STATE_IDLE) {
return;
}
View itemView = getChildAt(0);
if (itemView == null) {
return;
}
float deltaY = itemView.getY();
// fixed: 17-1-7 Equality tests should not be made with floating point values.
if ((int) deltaY == 0 || itemHeightPixels == 0) {
return;
}
if (Math.abs(deltaY) < itemHeightPixels / 2) {
int d = obtainSmoothDistance(deltaY);
smoothScrollBy(d, SMOOTH_SCROLL_DURATION);
} else {
int d = obtainSmoothDistance(itemHeightPixels + deltaY);
smoothScrollBy(d, SMOOTH_SCROLL_DURATION);
}
}
use of android.widget.AbsListView in project AndroidPicker by gzu-liyujiang.
the class ImageAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = new ImageView(context);
ViewGroup.LayoutParams params;
if (parent instanceof AbsListView) {
//java.lang.ClassCastException:
// android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
params = new AbsListView.LayoutParams(width, height);
} else {
params = new ViewGroup.LayoutParams(width, height);
}
convertView.setLayoutParams(params);
viewHolder.imageView = (ImageView) convertView;
viewHolder.imageView.setScaleType(scaleType);
//加上key,避免和Glide框架冲突: You must not call setTag() on a view Glide is targeting
convertView.setTag(TAG_KEY_AVOID_CONFLICT_WITH_GLIDE, viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag(TAG_KEY_AVOID_CONFLICT_WITH_GLIDE);
}
final Object item = data.get(position);
viewHolder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onImageClickListener != null) {
onImageClickListener.onImageClick(position, item);
}
}
});
switch(mode) {
case INTEGER:
viewHolder.imageView.setImageResource((Integer) item);
break;
case DRAWABLE:
viewHolder.imageView.setImageDrawable((Drawable) item);
break;
case BITMAP:
viewHolder.imageView.setImageBitmap((Bitmap) item);
break;
default:
ImageHelper.getInstance().display(item.toString(), viewHolder.imageView, width, height);
break;
}
return convertView;
}
use of android.widget.AbsListView in project platform_frameworks_base by android.
the class ResolverActivity method onPrepareAdapterView.
public void onPrepareAdapterView(AbsListView adapterView, ResolveListAdapter adapter, boolean alwaysUseOption) {
final boolean useHeader = adapter.hasFilteredItem();
final ListView listView = adapterView instanceof ListView ? (ListView) adapterView : null;
adapterView.setAdapter(mAdapter);
final ItemClickListener listener = new ItemClickListener();
adapterView.setOnItemClickListener(listener);
adapterView.setOnItemLongClickListener(listener);
if (alwaysUseOption) {
listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
}
if (useHeader && listView != null) {
listView.addHeaderView(LayoutInflater.from(this).inflate(R.layout.resolver_different_item_header, listView, false));
}
}
Aggregations