Example usage for android.widget PopupWindow PopupWindow

List of usage examples for android.widget PopupWindow PopupWindow

Introduction

In this page you can find the example usage for android.widget PopupWindow PopupWindow.

Prototype

public PopupWindow(View contentView, int width, int height) 

Source Link

Document

Create a new non focusable popup window which can display the contentView.

Usage

From source file:Main.java

public static void showPopWindow(Context context, View parent, int drawableId) {
    if (drawableId == 0) {
        return;/*from  ww  w .j a  v a2s. c om*/
    }
    if (pop == null) {
        ImageView imageView = null;
        imageView = new ImageView(context);
        imageView.setBackgroundResource(drawableId);
        pop = new PopupWindow(imageView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pop != null) {
                    pop.dismiss();
                    pop = null;
                }
            }
        });
    }
    if (!pop.isShowing()) {
        pop.showAtLocation(parent, Gravity.BOTTOM, 0, 0);

    }
}

From source file:Main.java

public static PopupWindow showPopWindow(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;//w  w  w .  ja v  a  2  s . co m
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAsDropDown(targetView);
    return popupWindow;
}

From source file:Main.java

public static PopupWindow showPopWindow2(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;/*from   w  ww.j  av a2 s .  co  m*/
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);
    return popupWindow;
}

From source file:Main.java

public static PopupWindow showPopWindow3(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;//  w w  w  .ja  v a  2 s .  co  m
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    return popupWindow;
}

From source file:com.knurld.dropboxdemo.KnurldActivity.java

public PopupWindow showLoadingPopup(View view) {
    View spinnerView = LayoutInflater.from((Activity) context).inflate(R.layout.loading_popup, null);
    ProgressBar progressBar = (ProgressBar) spinnerView.findViewById(R.id.speakProgress);
    progressBar.getIndeterminateDrawable().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);

    PopupWindow popupWindow = new PopupWindow(spinnerView, 500, 500);
    popupWindow.setFocusable(true);/*from  w  ww  . j  a v a2s. c  o m*/
    popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
    return popupWindow;
}

From source file:com.knurld.dropboxdemo.KnurldActivity.java

public void showInstructions(View view) {
    Activity parent = (Activity) context;
    View spinnerView = LayoutInflater.from(parent).inflate(R.layout.instructions_popup, null);

    TextView textView = (TextView) spinnerView.findViewById(R.id.phraseText);
    textView.setText("Press record to begin recording enrollment");

    PopupWindow popupWindow = new PopupWindow(spinnerView, 500, 500);
    popupWindow.setFocusable(true);/* w ww.j av a2s.c om*/
    popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);

    final PopupWindow finalPopupWindow = popupWindow;
    new android.os.Handler().postDelayed(new Runnable() {
        public void run() {
            finalPopupWindow.dismiss();
        }
    }, 3000);

}

From source file:de.vanita5.twittnuker.popup.AccountSelectorPopupWindow.java

public AccountSelectorPopupWindow(Context context, View anchor) {
    mContext = context;//from w  ww.  j  ava2 s.  c  om
    mAnchor = anchor;
    final int themeAttr;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        themeAttr = android.R.attr.actionOverflowMenuStyle;
    } else {
        themeAttr = android.R.attr.popupMenuStyle;
    }
    mAdapter = new AccountsGridAdapter(context);
    final Resources resources = context.getResources();
    final LayoutInflater inflater = LayoutInflater.from(context);
    final int themeColor = ThemeUtils.getUserAccentColor(context);
    if (!(context instanceof Factory)) {
        inflater.setFactory2(new ThemedViewFactory(themeColor));
    }
    final View contentView = inflater.inflate(R.layout.popup_account_selector, null);
    mGridView = (GridView) contentView.findViewById(R.id.grid_view);
    mGridView.setAdapter(mAdapter);
    mGridView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    mGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mAccountSelectionListener == null)
                return;

            mAccountSelectionListener.onSelectionChanged(getSelectedAccountIds());
        }
    });
    mPopup = new PopupWindow(context, null, themeAttr);
    mPopup.setFocusable(true);
    mPopup.setWidth(Utils.getActionBarHeight(context) * 2);
    mPopup.setWindowLayoutMode(0, ViewGroup.LayoutParams.WRAP_CONTENT);
    mPopup.setContentView(contentView);
}

From source file:com.knurld.dropboxdemo.KnurldActivity.java

public void showMessage(View view, String message) {
    Activity parent = (Activity) context;
    View spinnerView = LayoutInflater.from(parent).inflate(R.layout.instructions_popup, null);

    TextView textView = (TextView) spinnerView.findViewById(R.id.phraseText);
    textView.setText(message);/*w w w  . j a va 2s .c o  m*/

    PopupWindow popupWindow = new PopupWindow(spinnerView, 500, 500);
    popupWindow.setFocusable(true);
    popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);

    final PopupWindow finalPopupWindow = popupWindow;
    new android.os.Handler().postDelayed(new Runnable() {
        public void run() {
            finalPopupWindow.dismiss();
        }
    }, 3000);

}

From source file:com.actionbarsherlock.internal.widget.IcsListPopupWindow.java

public IcsListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
    mContext = context;//  w  w w.j a  va2  s  . co m
    mPopup = new PopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
}

From source file:org.mariotaku.twidere.util.TwidereActionModeForChildListener.java

ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    if (mActionMode != null) {
        mActionMode.finish();/*from  ww  w  .  ja  va  2 s. c om*/
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);

    if (mActionModeView == null) {
        if (mIsFloating && mUsePopup) {
            // Use the action bar theme.
            final Context actionBarContext;
            actionBarContext = ThemeUtils.getActionBarThemedContext(mActivity,
                    mThemed.getCurrentThemeResourceId(), mThemed.getCurrentThemeColor());

            mActionModeView = new ActionBarContextView(actionBarContext);
            mActionModePopup = new PopupWindow(actionBarContext, null,
                    android.support.v7.appcompat.R.attr.actionModePopupWindowStyle);
            mActionModePopup.setContentView(mActionModeView);
            mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

            final TypedValue outValue = new TypedValue();
            actionBarContext.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize,
                    outValue, true);
            final int height = TypedValue.complexToDimensionPixelSize(outValue.data,
                    actionBarContext.getResources().getDisplayMetrics());
            mActionModeView.setContentHeight(height);
            ThemeUtils.setActionBarContextViewBackground(mActionModeView, mThemed.getCurrentThemeResourceId(),
                    mThemed.getCurrentThemeColor(), mThemed.getCurrentThemeBackgroundOption(), false);
            mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
            mShowActionModePopup = new Runnable() {
                @Override
                public void run() {
                    mActionModePopup.showAtLocation(mWindow.getDecorView(),
                            Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
                }
            };
        } else {
            mActionModeView = (ActionBarContextView) mWindow.findViewById(R.id.action_context_bar);
        }
    }

    if (mActionModeView != null) {
        mActionModeView.killMode();
        ActionMode mode = new StandaloneActionMode(mActionModeView.getContext(), mActionModeView,
                wrappedCallback, mActionModePopup == null);
        if (callback.onCreateActionMode(mode, mode.getMenu())) {
            mode.invalidate();
            mActionModeView.initForMode(mode);
            mActionModeView.setVisibility(View.VISIBLE);
            mActionMode = mode;
            if (mActionModePopup != null) {
                mWindow.getDecorView().post(mShowActionModePopup);
            }
            mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

            if (mActionModeView.getParent() != null) {
                ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
            }
        } else {
            mActionMode = null;
        }

    }
    if (mActionMode != null && mAppCompatCallback != null) {
        mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
}