Search in sources :

Example 66 with PopupWindow

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();
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) PopupWindow(android.widget.PopupWindow) Activity(android.app.Activity) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) DisplayMetrics(android.util.DisplayMetrics)

Example 67 with PopupWindow

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;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ViewGroup(android.view.ViewGroup) PopupWindow(android.widget.PopupWindow) LinearLayout(android.widget.LinearLayout)

Aggregations

PopupWindow (android.widget.PopupWindow)67 View (android.view.View)28 Paint (android.graphics.Paint)20 TextView (android.widget.TextView)20 ImageView (android.widget.ImageView)17 Key (android.inputmethodservice.Keyboard.Key)14 ColorDrawable (android.graphics.drawable.ColorDrawable)12 LinearLayout (android.widget.LinearLayout)12 ViewGroup (android.view.ViewGroup)10 ScrollView (android.widget.ScrollView)10 OnClickListener (android.view.View.OnClickListener)9 Context (android.content.Context)8 Resources (android.content.res.Resources)8 LayoutParams (android.view.ViewGroup.LayoutParams)7 Animator (android.animation.Animator)5 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)5 ObjectAnimator (android.animation.ObjectAnimator)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 TypedValue (android.util.TypedValue)5 ActionMode (android.view.ActionMode)5