use of android.widget.PopupWindow in project AndroidImagePopup by chathuralakmal.
the class ImagePopup method initiatePopup.
public void initiatePopup(Drawable drawable) {
try {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.popup, (ViewGroup) findViewById(R.id.popup));
layout.setBackgroundColor(getBackgroundColor());
ImageView imageView = (ImageView) layout.findViewById(R.id.imageView);
imageView.setImageDrawable(drawable);
Log.e("Image", "Height--> " + imageView.getDrawable().getMinimumHeight());
Log.e("Image", "Width--> " + imageView.getDrawable().getMinimumWidth());
// /** Height & Width Adjustments according to the Image size and Device Screen size **/
DisplayMetrics metrics = new DisplayMetrics();
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
Log.e("Phone Height", "-->" + metrics.heightPixels);
Log.e("Phone Width", "-->" + metrics.widthPixels);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
if (windowHeight != 0 || windowWidth != 0) {
width = windowWidth;
height = windowHeight;
}
// ((Activity) getContext()).getWindow().setLayout((int)(width*.8),(int)(height*.6));
//
popupWindow = new PopupWindow(layout, (int) (width * .8), (int) (height * .6), true);
popupWindow.showAtLocation(layout, Gravity.CENTER, 0, 0);
ImageView closeIcon = (ImageView) layout.findViewById(R.id.closeBtn);
if (isHideCloseIcon()) {
closeIcon.setVisibility(View.GONE);
}
closeIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
}
});
if (isImageOnClickClose()) {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
}
});
}
/** Background dim part **/
// WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
// WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) layout.getLayoutParams();
// layoutParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
// layoutParams.dimAmount = 0.3f;
// windowManager.updateViewLayout(layout, layoutParams);
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.widget.PopupWindow in project android_frameworks_base by crdroidandroid.
the class FloatingToolbar method createPopupWindow.
private static PopupWindow createPopupWindow(ViewGroup content) {
ViewGroup popupContentHolder = new LinearLayout(content.getContext());
PopupWindow popupWindow = new PopupWindow(popupContentHolder);
// TODO: Use .setLayoutInScreenEnabled(true) instead of .setClippingEnabled(false)
// unless FLAG_LAYOUT_IN_SCREEN has any unintentional side-effects.
popupWindow.setClippingEnabled(false);
popupWindow.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL);
popupWindow.setAnimationStyle(0);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
content.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
popupContentHolder.addView(content);
return popupWindow;
}
Aggregations