Search in sources :

Example 26 with PopupWindow

use of android.widget.PopupWindow in project sexytopo by richsmith.

the class StationContextMenu method getFakeStationContextMenu.

public static PopupWindow getFakeStationContextMenu(Context context, Station station, final View.OnClickListener listener) {
    final PopupWindow fakeMenu = new PopupWindow(context);
    LayoutInflater inflater = (LayoutInflater) (context.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
    View view = inflater.inflate(R.layout.graph_station_menu, null);
    Button title = (Button) (view.findViewById(R.id.graph_station_title));
    title.setText(station.getName());
    fakeMenu.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
    fakeMenu.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    fakeMenu.setContentView(view);
    int[] ids = new int[] { R.id.graph_station_comment, R.id.graph_station_delete, R.id.graph_station_reverse, R.id.graph_station_new_cross_section, R.id.graph_station_start_new_survey, R.id.graph_station_unlink_survey };
    for (int id : ids) {
        ((Button) (view.findViewById(id))).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                fakeMenu.dismiss();
                listener.onClick(view);
            }
        });
    }
    fakeMenu.setFocusable(true);
    fakeMenu.setOutsideTouchable(true);
    return fakeMenu;
}
Also used : Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) PopupWindow(android.widget.PopupWindow) View(android.view.View)

Example 27 with PopupWindow

use of android.widget.PopupWindow in project android_frameworks_base by crdroidandroid.

the class KeyboardView method showKey.

private void showKey(final int keyIndex) {
    final PopupWindow previewPopup = mPreviewPopup;
    final Key[] keys = mKeys;
    if (keyIndex < 0 || keyIndex >= mKeys.length)
        return;
    Key key = keys[keyIndex];
    if (key.icon != null) {
        mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon);
        mPreviewText.setText(null);
    } else {
        mPreviewText.setCompoundDrawables(null, null, null, null);
        mPreviewText.setText(getPreviewText(key));
        if (key.label.length() > 1 && key.codes.length < 2) {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
            mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
            mPreviewText.setTypeface(Typeface.DEFAULT);
        }
    }
    mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
    final int popupHeight = mPreviewHeight;
    LayoutParams lp = mPreviewText.getLayoutParams();
    if (lp != null) {
        lp.width = popupWidth;
        lp.height = popupHeight;
    }
    if (!mPreviewCentered) {
        mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + mPaddingLeft;
        mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
    } else {
        // TODO: Fix this if centering is brought back
        mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
        mPopupPreviewY = -mPreviewText.getMeasuredHeight();
    }
    mHandler.removeMessages(MSG_REMOVE_PREVIEW);
    getLocationInWindow(mCoordinates);
    // Offset may be zero
    mCoordinates[0] += mMiniKeyboardOffsetX;
    // Offset may be zero
    mCoordinates[1] += mMiniKeyboardOffsetY;
    // Set the preview background state
    mPreviewText.getBackground().setState(key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
    mPopupPreviewX += mCoordinates[0];
    mPopupPreviewY += mCoordinates[1];
    // If the popup cannot be shown above the key, put it on the side
    getLocationOnScreen(mCoordinates);
    if (mPopupPreviewY + mCoordinates[1] < 0) {
        // the right, offset by enough to see at least one key to the left/right.
        if (key.x + key.width <= getWidth() / 2) {
            mPopupPreviewX += (int) (key.width * 2.5);
        } else {
            mPopupPreviewX -= (int) (key.width * 2.5);
        }
        mPopupPreviewY += popupHeight;
    }
    if (previewPopup.isShowing()) {
        previewPopup.update(mPopupPreviewX, mPopupPreviewY, popupWidth, popupHeight);
    } else {
        previewPopup.setWidth(popupWidth);
        previewPopup.setHeight(popupHeight);
        previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY, mPopupPreviewX, mPopupPreviewY);
    }
    mPreviewText.setVisibility(VISIBLE);
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) PopupWindow(android.widget.PopupWindow) Key(android.inputmethodservice.Keyboard.Key) Paint(android.graphics.Paint)

Example 28 with PopupWindow

use of android.widget.PopupWindow in project android_frameworks_base by crdroidandroid.

the class KeyboardView method showPreview.

private void showPreview(int keyIndex) {
    int oldKeyIndex = mCurrentKeyIndex;
    final PopupWindow previewPopup = mPreviewPopup;
    mCurrentKeyIndex = keyIndex;
    // Release the old key and press the new key
    final Key[] keys = mKeys;
    if (oldKeyIndex != mCurrentKeyIndex) {
        if (oldKeyIndex != NOT_A_KEY && keys.length > oldKeyIndex) {
            Key oldKey = keys[oldKeyIndex];
            oldKey.onReleased(mCurrentKeyIndex == NOT_A_KEY);
            invalidateKey(oldKeyIndex);
            final int keyCode = oldKey.codes[0];
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT, keyCode);
            // TODO: We need to implement AccessibilityNodeProvider for this view.
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED, keyCode);
        }
        if (mCurrentKeyIndex != NOT_A_KEY && keys.length > mCurrentKeyIndex) {
            Key newKey = keys[mCurrentKeyIndex];
            newKey.onPressed();
            invalidateKey(mCurrentKeyIndex);
            final int keyCode = newKey.codes[0];
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, keyCode);
            // TODO: We need to implement AccessibilityNodeProvider for this view.
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, keyCode);
        }
    }
    // If key changed and preview is on ...
    if (oldKeyIndex != mCurrentKeyIndex && mShowPreview) {
        mHandler.removeMessages(MSG_SHOW_PREVIEW);
        if (previewPopup.isShowing()) {
            if (keyIndex == NOT_A_KEY) {
                mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_REMOVE_PREVIEW), DELAY_AFTER_PREVIEW);
            }
        }
        if (keyIndex != NOT_A_KEY) {
            if (previewPopup.isShowing() && mPreviewText.getVisibility() == VISIBLE) {
                // Show right away, if it's already visible and finger is moving around
                showKey(keyIndex);
            } else {
                mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SHOW_PREVIEW, keyIndex, 0), DELAY_BEFORE_PREVIEW);
            }
        }
    }
}
Also used : PopupWindow(android.widget.PopupWindow) Paint(android.graphics.Paint) Key(android.inputmethodservice.Keyboard.Key)

Example 29 with PopupWindow

use of android.widget.PopupWindow in project android_frameworks_base by crdroidandroid.

the class DecorView method createStandaloneActionMode.

private ActionMode createStandaloneActionMode(ActionMode.Callback callback) {
    endOnGoingFadeAnimation();
    cleanupPrimaryActionMode();
    // cleanupPrimaryActionMode() invocation above.
    if (mPrimaryActionModeView == null || !mPrimaryActionModeView.isAttachedToWindow()) {
        if (mWindow.isFloating()) {
            // Use the action bar theme.
            final TypedValue outValue = new TypedValue();
            final Resources.Theme baseTheme = mContext.getTheme();
            baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
            final Context actionBarContext;
            if (outValue.resourceId != 0) {
                final Resources.Theme actionBarTheme = mContext.getResources().newTheme();
                actionBarTheme.setTo(baseTheme);
                actionBarTheme.applyStyle(outValue.resourceId, true);
                actionBarContext = new ContextThemeWrapper(mContext, 0);
                actionBarContext.getTheme().setTo(actionBarTheme);
            } else {
                actionBarContext = mContext;
            }
            mPrimaryActionModeView = new ActionBarContextView(actionBarContext);
            mPrimaryActionModePopup = new PopupWindow(actionBarContext, null, R.attr.actionModePopupWindowStyle);
            mPrimaryActionModePopup.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION);
            mPrimaryActionModePopup.setContentView(mPrimaryActionModeView);
            mPrimaryActionModePopup.setWidth(MATCH_PARENT);
            actionBarContext.getTheme().resolveAttribute(R.attr.actionBarSize, outValue, true);
            final int height = TypedValue.complexToDimensionPixelSize(outValue.data, actionBarContext.getResources().getDisplayMetrics());
            mPrimaryActionModeView.setContentHeight(height);
            mPrimaryActionModePopup.setHeight(WRAP_CONTENT);
            mShowPrimaryActionModePopup = new Runnable() {

                public void run() {
                    mPrimaryActionModePopup.showAtLocation(mPrimaryActionModeView.getApplicationWindowToken(), Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
                    endOnGoingFadeAnimation();
                    if (shouldAnimatePrimaryActionModeView()) {
                        mFadeAnim = ObjectAnimator.ofFloat(mPrimaryActionModeView, View.ALPHA, 0f, 1f);
                        mFadeAnim.addListener(new AnimatorListenerAdapter() {

                            @Override
                            public void onAnimationStart(Animator animation) {
                                mPrimaryActionModeView.setVisibility(VISIBLE);
                            }

                            @Override
                            public void onAnimationEnd(Animator animation) {
                                mPrimaryActionModeView.setAlpha(1f);
                                mFadeAnim = null;
                            }
                        });
                        mFadeAnim.start();
                    } else {
                        mPrimaryActionModeView.setAlpha(1f);
                        mPrimaryActionModeView.setVisibility(VISIBLE);
                    }
                }
            };
        } else {
            ViewStub stub = (ViewStub) findViewById(R.id.action_mode_bar_stub);
            if (stub != null) {
                mPrimaryActionModeView = (ActionBarContextView) stub.inflate();
                mPrimaryActionModePopup = null;
            }
        }
    }
    if (mPrimaryActionModeView != null) {
        mPrimaryActionModeView.killMode();
        ActionMode mode = new StandaloneActionMode(mPrimaryActionModeView.getContext(), mPrimaryActionModeView, callback, mPrimaryActionModePopup == null);
        return mode;
    }
    return null;
}
Also used : Context(android.content.Context) PopupWindow(android.widget.PopupWindow) Paint(android.graphics.Paint) StandaloneActionMode(com.android.internal.view.StandaloneActionMode) ViewStub(android.view.ViewStub) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ContextThemeWrapper(android.view.ContextThemeWrapper) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ActionMode(android.view.ActionMode) StandaloneActionMode(com.android.internal.view.StandaloneActionMode) FloatingActionMode(com.android.internal.view.FloatingActionMode) ActionBarContextView(com.android.internal.widget.ActionBarContextView) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 30 with PopupWindow

use of android.widget.PopupWindow in project double-espresso by JakeWharton.

the class SendActivity method showPopupView.

public boolean showPopupView(View view) {
    View content = getLayoutInflater().inflate(R.layout.popup_window, null, false);
    popupWindow = new PopupWindow(content, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
    content.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            popupWindow.dismiss();
        }
    });
    popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
    return true;
}
Also used : PopupWindow(android.widget.PopupWindow) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

PopupWindow (android.widget.PopupWindow)133 View (android.view.View)66 TextView (android.widget.TextView)48 ColorDrawable (android.graphics.drawable.ColorDrawable)27 ImageView (android.widget.ImageView)24 Paint (android.graphics.Paint)22 Key (android.inputmethodservice.Keyboard.Key)14 AdapterView (android.widget.AdapterView)14 LinearLayout (android.widget.LinearLayout)14 LayoutInflater (android.view.LayoutInflater)13 Button (android.widget.Button)13 ListView (android.widget.ListView)13 Activity (android.app.Activity)12 BitmapDrawable (android.graphics.drawable.BitmapDrawable)12 OnClickListener (android.view.View.OnClickListener)11 ViewGroup (android.view.ViewGroup)11 Context (android.content.Context)10 Resources (android.content.res.Resources)10 EditText (android.widget.EditText)10 ScrollView (android.widget.ScrollView)10