Back to project page VideoExtand.
The source code is released under:
Apache License
If you think the Android project VideoExtand listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.yuninfo.videoextand.widget; /* www . j ava 2 s . c o m*/ import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.ColorDrawable; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.PopupWindow; public class CustomPopupWindow extends PopupWindow { private Context mContext = null; private Resources mResources; private String mPackageName; private ListView mLvItems = null; private OnItemClickListener mItemClickListener = null; private String [] mItems = new String [0]; private boolean mDismissOnItemClicked = true; public CustomPopupWindow(Context context, AttributeSet attrs) { super(context, attrs); initView(context); } public CustomPopupWindow(Context context) { this(context, null); } private void initView(Context context) { mContext = context; mResources = mContext.getResources(); mPackageName = mContext.getPackageName(); mLvItems = new ListView(context); mLvItems.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mLvItems.setBackgroundResource(mResources.getIdentifier("yuninfo_bg_popupwindow", "drawable", mPackageName)); mLvItems.setCacheColorHint(mResources.getIdentifier("yuninfo_transparent", "color", mPackageName)); mLvItems.setSelector(mResources.getIdentifier("yuninfo_transparent", "color", mPackageName)); mLvItems.setFadingEdgeLength(0); mLvItems.setScrollingCacheEnabled(false); mLvItems.setDivider(context.getResources().getDrawable(mResources.getIdentifier("yuninfo_hint_color", "color", mPackageName))); int itemLayoutId = mResources.getIdentifier("yuninfo_pupup_item", "layout", mPackageName); mLvItems.setAdapter(new ArrayAdapter<String>(context, itemLayoutId, mItems)); mLvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(mItemClickListener != null) { mItemClickListener.onItemClick(parent, view, position, id); } if(mDismissOnItemClicked) { CustomPopupWindow.this.dismiss(); } } }); setWidth(LayoutParams.WRAP_CONTENT); setHeight(LayoutParams.WRAP_CONTENT); setFocusable(true); setBackgroundDrawable(new ColorDrawable()); setOutsideTouchable(true); int animId = mResources.getIdentifier("yuinfo_DropdownWindow", "anim", mPackageName); setAnimationStyle(animId); setContentView(mLvItems); } public void setItems(int id) { mItems = mContext.getResources().getStringArray(id); int itemLayoutId = mResources.getIdentifier("yuninfo_pupup_item", "layout", mPackageName); mLvItems.setAdapter(new ArrayAdapter<String>(mContext, itemLayoutId, mItems)); } public void setItems(String [] items) { mItems = items; int itemLayoutId = mResources.getIdentifier("yuninfo_pupup_item", "layout", mPackageName); mLvItems.setAdapter(new ArrayAdapter<String>(mContext, itemLayoutId, mItems)); } public void setOnItemClickListener(OnItemClickListener listener) { mItemClickListener = listener; } public void setOnItemClickListener(OnItemClickListener listener, boolean dismissOnItemClicked) { setOnItemClickListener(listener); setDismissOnItemClicked(dismissOnItemClicked); } public void setDismissOnItemClicked(boolean dismissOnItemClicked) { this.mDismissOnItemClicked = dismissOnItemClicked; } public String getItems(int position) { if(mItems == null) { return null; } if(mItems.length > position) { return mItems[position]; } return null; } public static interface OnItemClickListener { public void onItemClick(AdapterView<?> parent, View view, int position, long id); } }