Search in sources :

Example 21 with PopupWindow

use of android.widget.PopupWindow in project XobotOS by xamarin.

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);
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT, oldKey.codes[0]);
        }
        if (mCurrentKeyIndex != NOT_A_KEY && keys.length > mCurrentKeyIndex) {
            Key newKey = keys[mCurrentKeyIndex];
            newKey.onPressed();
            invalidateKey(mCurrentKeyIndex);
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, newKey.codes[0]);
        }
    }
    // 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 22 with PopupWindow

use of android.widget.PopupWindow in project XobotOS by xamarin.

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 23 with PopupWindow

use of android.widget.PopupWindow in project platform_frameworks_base by android.

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)

Example 24 with PopupWindow

use of android.widget.PopupWindow in project Qblog_Android by qiaoyhh.

the class BlogTypePop method initView.

private void initView() {
    if (popupWindow == null) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.view_common, null);
        popupWindow = new PopupWindow(view, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setFocusable(true);
        RecyclerView rv_view_main = (RecyclerView) view.findViewById(R.id.view_main);
        mAdapter = new BlogTypeAdapter(R.layout.item_blogtype_view, null);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        rv_view_main.setLayoutManager(linearLayoutManager);
        rv_view_main.setHasFixedSize(true);
        rv_view_main.addItemDecoration(new RecyclerViewDecoration(mContext, LinearLayoutManager.HORIZONTAL, R.drawable.divider_mileage));
        rv_view_main.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {
                if (mListener != null) {
                    if (currentPositon != position) {
                        currentPositon = position;
                        mListener.BlogType(position);
                        closePopWindow();
                    }
                }
            }
        });
    }
}
Also used : BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) PopupWindow(android.widget.PopupWindow) RecyclerView(android.support.v7.widget.RecyclerView) BlogTypeAdapter(com.qyh.myblog_android.ui.adapter.BlogTypeAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 25 with PopupWindow

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

the class GraphView method showContextMenu.

private void showContextMenu(MotionEvent event, final Station station) {
    OnClickListener listener = new OnClickListener() {

        @Override
        public void onClick(View view) {
            switch(view.getId()) {
                case R.id.graph_station_comment:
                    openCommentDialog(station);
                    break;
                case R.id.graph_station_reverse:
                    SurveyUpdater.reverseLeg(survey, station);
                    SurveyManager.getInstance(getContext()).broadcastSurveyUpdated();
                    invalidate();
                    break;
                case R.id.graph_station_delete:
                    askAboutDeletingStation(station);
                    invalidate();
                    break;
                case R.id.graph_station_new_cross_section:
                    setSketchTool(SketchTool.POSITION_CROSS_SECTION);
                    activity.showSimpleToast(R.string.position_cross_section_instruction);
                    break;
                case R.id.graph_station_start_new_survey:
                    if (!survey.isSaved()) {
                        activity.showSimpleToast(R.string.cannot_extend_unsaved_survey);
                    }
                    activity.continueSurvey(station);
                    break;
                case R.id.graph_station_unlink_survey:
                    activity.unlinkSurvey(station);
                    break;
            }
        }
    };
    PopupWindow menu = StationContextMenu.getFakeStationContextMenu(getContext(), station, listener);
    View unlinkSurveyButton = menu.getContentView().findViewById(R.id.graph_station_unlink_survey);
    unlinkSurveyButton.setEnabled(survey.hasLinkedSurveys(station));
    View commentButton = menu.getContentView().findViewById(R.id.graph_station_comment);
    commentButton.setEnabled(station != survey.getOrigin());
    menu.showAtLocation(this, Gravity.LEFT | Gravity.TOP, (int) (event.getX()), (int) (event.getY()));
}
Also used : PopupWindow(android.widget.PopupWindow) 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