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.
/* * ??????MenuDialog.java/* w w w .j a v a2 s . c o m*/ * ?????<????> * ?????<????> * ????xiaoying * ?????2013-7-30 * ????xiaoying * ?????2013-7-30 * ???v1.0 */ package com.yuninfo.videoextand.widget.dialog; import java.util.List; import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.res.Resources; import android.os.Build; import android.view.Gravity; import android.view.View; import android.view.WindowManager.LayoutParams; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; /** * Menu dialog * @author xiaoying * */ public class MenuDialog extends Dialog { private ListView mLvItems; private Button mBtnNegative; private DialogInterface.OnClickListener mClickListener = null; private DialogInterface.OnClickListener mItemClickListener = null; private Resources mResources; private String mPackageName; public MenuDialog(Context context) { this(context, context.getResources().getIdentifier("yuninfo_MenuDialogTheme", "style", context.getPackageName())); } public MenuDialog(Context context, int theme) { super(context, theme); initView(context); } @SuppressLint("InlinedApi") @SuppressWarnings("deprecation") private void initView(Context context) { mResources = context.getResources(); mPackageName = context.getPackageName(); int layout = mResources.getIdentifier("yuninfo_layout_menu_dilaog", "layout", mPackageName); setContentView(layout); getWindow().setGravity(Gravity.BOTTOM); int animId = mResources.getIdentifier("yuninfo_MenuDialogAnimation", "style", mPackageName); getWindow().setWindowAnimations(animId); LayoutParams lp = getWindow().getAttributes(); if(Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) { lp.width = LayoutParams.FILL_PARENT; } else { lp.width = LayoutParams.MATCH_PARENT; } lp.height = LayoutParams.WRAP_CONTENT; getWindow().setAttributes(lp); mLvItems = (ListView) findViewById(mResources.getIdentifier("yuninfo_lv_menudialog_list", "id", mPackageName)); mBtnNegative = (Button) findViewById(mResources.getIdentifier("yuninfo_btn_menudialog_negative", "id", mPackageName)); mBtnNegative.setVisibility(View.GONE); mBtnNegative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(v.getVisibility() == View.VISIBLE && mClickListener != null) { mClickListener.onClick(MenuDialog.this, DialogInterface.BUTTON_NEGATIVE); } // MenuDialog.this.cancel(); } }); mLvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(mItemClickListener != null) { mItemClickListener.onClick(MenuDialog.this, position); } // MenuDialog.this.cancel(); } }); } /** * Set negative button. * @param resid * @param cl * @return */ public MenuDialog setNegativeButton(int resid, OnClickListener cl) { mClickListener = cl; mBtnNegative.setVisibility(View.VISIBLE); mBtnNegative.setText(resid); return this; } /** * Set negative button. * @param resid * @param cl * @return */ public MenuDialog setNegativeButton(String text, OnClickListener cl) { mClickListener = cl; mBtnNegative.setVisibility(View.VISIBLE); mBtnNegative.setText(text); return this; } /** * Set menu items. * @param items * @param listener * @return */ public MenuDialog setItems(String [] items, DialogInterface.OnClickListener listener) { mItemClickListener = listener; int itemResId = mResources.getIdentifier("yuninfo_item_menu_dialog", "layout", mPackageName); int itemTextId = mResources.getIdentifier("yuninfo_tv_item_menudialog", "id", mPackageName); mLvItems.setAdapter(new ArrayAdapter<String>(getContext(), itemResId, itemTextId, items)); return this; } /** * Set menu items. * @param items * @param listener * @return */ public MenuDialog setItems(List<String> items, DialogInterface.OnClickListener listener) { mItemClickListener = listener; int itemResId = mResources.getIdentifier("yuninfo_item_menu_dialog", "layout", mPackageName); int itemTextId = mResources.getIdentifier("yuninfo_tv_item_menudialog", "id", mPackageName); mLvItems.setAdapter(new ArrayAdapter<String>(getContext(), itemResId, itemTextId, items)); return this; } }