use of android.widget.PopupWindow in project BaseProject by fly803.
the class ViewUtils method showPopupWindow.
/**
* 显示PopupWindow
* @param context
* @param resId
* @param root
* @param paramsType
* @return
*/
public static View showPopupWindow(Context context, int resId, View root, int paramsType) {
View popupView;
popupView = LayoutInflater.from(context).inflate(resId, null);
switch(paramsType) {
case 1:
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
break;
case 2:
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
break;
case 3:
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
break;
case 4:
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
break;
default:
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
break;
}
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(root);
return popupView;
}
use of android.widget.PopupWindow in project BaseProject by fly803.
the class NiceSpinner method init.
private void init(Context context, AttributeSet attrs) {
Resources resources = getResources();
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner);
int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit);
setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding, defaultPadding);
setClickable(true);
backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector, R.drawable.selector);
setBackgroundResource(backgroundSelector);
textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context));
setTextColor(textColor);
listView = new ListView(context);
// Set the spinner's id into the listview to make it pretend to be the right parent in
// onItemClick
listView.setId(getId());
listView.setDivider(null);
listView.setItemsCanFocus(true);
// hide vertical and horizontal scrollbars
listView.setVerticalScrollBarEnabled(false);
listView.setHorizontalScrollBarEnabled(false);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position >= selectedIndex && position < adapter.getCount()) {
position++;
}
// Need to set selected index before calling listeners or getSelectedIndex() can be
// reported incorrectly due to race conditions.
selectedIndex = position;
if (onItemClickListener != null) {
onItemClickListener.onItemClick(parent, view, position, id);
}
if (onItemSelectedListener != null) {
onItemSelectedListener.onItemSelected(parent, view, position, id);
}
adapter.setSelectedIndex(position);
setTextInternal(adapter.getItemInDataset(position).toString());
dismissDropDown();
}
});
popupWindow = new PopupWindow(context);
popupWindow.setContentView(listView);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
popupWindow.setElevation(DEFAULT_ELEVATION);
popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.spinner_drawable));
} else {
popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.drop_down_shadow));
}
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
if (!isArrowHidden) {
animateArrow(false);
}
}
});
isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false);
arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, Integer.MAX_VALUE);
arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow);
dropDownListPaddingBottom = typedArray.getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0);
typedArray.recycle();
measureDisplayHeight();
}
use of android.widget.PopupWindow in project glitch-hq-android by tinyspeck.
the class SkillFragment method setupSettings.
private void setupSettings() {
final Button btnSettings = (Button) m_root.findViewById(R.id.btnSettings);
btnSettings.setVisibility(View.VISIBLE);
btnSettings.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
final PopupWindow pw = Util.showPopup(getActivity(), R.layout.skill_settings, true, btnSettings, 5, 5);
View v = pw.getContentView();
Button btn = (Button) v.findViewById(R.id.btn_learning);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
pw.dismiss();
((HomeScreen) getActivity()).setCurrentFragmentSkills();
}
});
btn = (Button) v.findViewById(R.id.btn_unlearning);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
pw.dismiss();
((HomeScreen) getActivity()).setCurrentFragmentUnlearn();
}
});
}
});
}
use of android.widget.PopupWindow in project glitch-hq-android by tinyspeck.
the class UnlearnFragment method setupSettings.
private void setupSettings() {
final Button btnSettings = (Button) m_root.findViewById(R.id.btnSettings);
btnSettings.setVisibility(View.VISIBLE);
btnSettings.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
final PopupWindow pw = Util.showPopup(getActivity(), R.layout.skill_settings, true, btnSettings, 5, 5);
View v = pw.getContentView();
Button btn = (Button) v.findViewById(R.id.btn_learning);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
pw.dismiss();
((HomeScreen) getActivity()).setCurrentFragmentSkills();
}
});
btn = (Button) v.findViewById(R.id.btn_unlearning);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
pw.dismiss();
((HomeScreen) getActivity()).setCurrentFragmentUnlearn();
}
});
}
});
}
use of android.widget.PopupWindow in project smoke by textbrowser.
the class MemberChat method showDetailsOfMessage.
private void showDetailsOfMessage(int oid) {
if (MemberChat.this.isFinishing())
return;
else if (m_lastContextMenuPosition[0] < 0 || m_lastContextMenuPosition[1] < 0)
return;
class SingleShot implements Runnable {
private int m_oid = -1;
SingleShot(int oid) {
m_oid = oid;
}
@Override
public void run() {
MemberChat.this.runOnUiThread(new Runnable() {
@Override
public void run() {
PopupWindow popupWindow = new PopupWindow(MemberChat.this);
String string = s_databaseHelper.messageDetails(m_oid).trim();
TextView textView1 = new TextView(MemberChat.this);
float density = getApplicationContext().getResources().getDisplayMetrics().density;
textView1.setBackgroundColor(Color.rgb(255, 255, 255));
textView1.setPaddingRelative((int) (10 * density), (int) (10 * density), (int) (10 * density), (int) (10 * density));
textView1.setTextSize(16);
if (string.isEmpty())
textView1.setText("Cannot retrieve message details.");
else
textView1.setText(string);
popupWindow.setContentView(textView1);
popupWindow.setOutsideTouchable(true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
popupWindow.setHeight(450);
popupWindow.setWidth(700);
}
popupWindow.showAtLocation(findViewById(R.id.recycler_view), Gravity.START | Gravity.TOP, m_lastContextMenuPosition[0], m_lastContextMenuPosition[1]);
m_lastContextMenuPosition[0] = m_lastContextMenuPosition[1] = -1;
}
});
}
}
Thread thread = new Thread(new SingleShot(oid));
thread.start();
}
Aggregations