Android Open Source - VideoExtand Custom Popup Window






From Project

Back to project page VideoExtand.

License

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.

Java Source Code

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);
  }
  
}




Java Source Code List

com.example.androidtest.MainActivity.java
com.yuninfo.videoextand.BaseActivity.java
com.yuninfo.videoextand.Config.java
com.yuninfo.videoextand.ReadCardActivity.java
com.yuninfo.videoextand.SendCardActivity.java
com.yuninfo.videoextand.bean.CommonReq.java
com.yuninfo.videoextand.bean.ReadVideoResp.java
com.yuninfo.videoextand.bean.SendVideoResp.java
com.yuninfo.videoextand.bean.UploadReq.java
com.yuninfo.videoextand.bean.UploadResp.java
com.yuninfo.videoextand.player.VideoPlayerActivity.java
com.yuninfo.videoextand.recorder.RecorderActivity.java
com.yuninfo.videoextand.uploader.ProgressListener.java
com.yuninfo.videoextand.uploader.ProgressMultipartEntity.java
com.yuninfo.videoextand.uploader.ProgressOutputStream.java
com.yuninfo.videoextand.uploader.UploadHandler.java
com.yuninfo.videoextand.uploader.UploadThread.java
com.yuninfo.videoextand.utils.BeanRefUtil.java
com.yuninfo.videoextand.utils.DateUtil.java
com.yuninfo.videoextand.utils.FileUtil.java
com.yuninfo.videoextand.utils.HttpUtil.java
com.yuninfo.videoextand.utils.LogUtil.java
com.yuninfo.videoextand.utils.StringUtil.java
com.yuninfo.videoextand.widget.CustomPopupWindow.java
com.yuninfo.videoextand.widget.TitleBar.java
com.yuninfo.videoextand.widget.dialog.MenuDialog.java