Java Code Examples for android.widget.PopupWindow#setContentView()

The following examples show how to use android.widget.PopupWindow#setContentView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViemoPlayerMenu.java    From Android-VimeoPlayer with MIT License 6 votes vote down vote up
@NonNull
private PopupWindow createPopupWindow() {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if(inflater == null)
        throw new RuntimeException("can't access LAYOUT_INFLATER_SERVICE");

    View view = inflater.inflate(R.layout.player_menu, null);

    RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
    setUpRecyclerView(recyclerView);

    PopupWindow popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setFocusable(true);
    popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
    popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    popupWindow.setContentView(view);

    return popupWindow;
}
 
Example 2
Source File: MainActivity.java    From qingyang with Apache License 2.0 6 votes vote down vote up
/**
 * 显示菜单
 * 
 * @param x
 * @param y
 */
public void showPopMenu(int x, int y) {
	LinearLayout layout = (LinearLayout) LayoutInflater.from(
			MainActivity.this).inflate(R.layout.pop_menu, null);
	ListView listView = (ListView) layout.findViewById(R.id.menu_list);
	listView.setAdapter(new ArrayAdapter<String>(MainActivity.this,
			R.layout.pop_menu_item, R.id.tv_text, title));

	popupWindow = new PopupWindow(MainActivity.this);
	popupWindow.setBackgroundDrawable(new BitmapDrawable());
	if (application.isTablet()) {
		popupWindow.setWidth(screenWidth / 4);
	} else {
		popupWindow.setWidth(screenWidth / 3);
	}
	popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
	popupWindow.setOutsideTouchable(true);
	popupWindow.setFocusable(true);
	popupWindow.setContentView(layout);
	// 需要指定Gravity,默认情况是center
	popupWindow.showAtLocation(view, Gravity.RIGHT | Gravity.TOP, x, y);
	listView.setOnItemClickListener(new MenuItemClick());
}
 
Example 3
Source File: SelectRemindWayPopup.java    From Android-AlarmManagerClock with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public SelectRemindWayPopup(Context context) {
    mContext = context;
    mPopupWindow = new PopupWindow(context);
    mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
    mPopupWindow.setWidth(WindowManager.LayoutParams.FILL_PARENT);
    mPopupWindow.setHeight(WindowManager.LayoutParams.FILL_PARENT);
    mPopupWindow.setTouchable(true);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setAnimationStyle(R.style.AnimBottom);
    mPopupWindow.setContentView(initViews());

    mPopupWindow.getContentView().setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mPopupWindow.setFocusable(false);
            mPopupWindow.dismiss();
            return true;
        }
    });

}
 
Example 4
Source File: ProgressDialog.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void  progressPopUp(final Activity context,String data){
	
	RelativeLayout layoutId = (RelativeLayout)context.findViewById(R.id.dialog_rootView);
	LayoutInflater layoutInflater  = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	View layout = layoutInflater.inflate(R.layout.progresspopup, layoutId);
	txtWaiting = (TextView)layout.findViewById(R.id.txtWaiting);

	paymentAlert = new PopupWindow(context);
	paymentAlert.setContentView(layout);		
	paymentAlert.setHeight(WindowManager.LayoutParams.MATCH_PARENT);		
	paymentAlert.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
	paymentAlert.setFocusable(true);		
	paymentAlert.setBackgroundDrawable(new BitmapDrawable());
	paymentAlert.showAtLocation(layout, Gravity.CENTER, 0, 0);	
	if(data !=null)
		txtWaiting.setText(data);
   }
 
Example 5
Source File: ProgressDialog.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void  progressPopUp(final Activity context,String data){
	
	RelativeLayout layoutId = (RelativeLayout)context.findViewById(R.id.dialog_rootView);
	LayoutInflater layoutInflater  = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	View layout = layoutInflater.inflate(R.layout.progresspopup, layoutId);
	txtWaiting = (TextView)layout.findViewById(R.id.txtWaiting);

	paymentAlert = new PopupWindow(context);
	paymentAlert.setContentView(layout);		
	paymentAlert.setHeight(WindowManager.LayoutParams.MATCH_PARENT);		
	paymentAlert.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
	paymentAlert.setFocusable(true);		
	paymentAlert.setBackgroundDrawable(new BitmapDrawable());
	paymentAlert.showAtLocation(layout, Gravity.CENTER, 0, 0);	
	if(data !=null)
		txtWaiting.setText(data);
   }
 
Example 6
Source File: OverflowHelper.java    From browser with GNU General Public License v2.0 6 votes vote down vote up
public OverflowHelper(Context ctx) {
    mContext = ctx;
    mNormalColor = mContext.getResources().getColor(R.color.white);
    mDisabledColor = mContext.getResources().getColor(R.color.text_disabled);
    mPopupLayout = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.comm_popup_menu, null, true);
    mListView = (PopupMenuListView) mPopupLayout.findViewById(R.id.comm_popup_list);
    mAdapter = new OverflowAdapter(this, ctx);
    mListView.setAdapter(mAdapter);
    mListView.setOnKeyListener(mOnKeyListener);
    mPopupWindow = new PopupWindow(mPopupLayout, -2, -2, true);
    mPopupWindow.setContentView(mPopupLayout);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setWidth(414);
    mPopupWindow.getContentView().setOnTouchListener(mOnTouchListener);
    mPopupWindow.update();
}
 
Example 7
Source File: SelectRemindCyclePopup.java    From Android-AlarmManagerClock with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public SelectRemindCyclePopup(Context context) {
    mContext = context;
    mPopupWindow = new PopupWindow(context);
    mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
    mPopupWindow.setWidth(WindowManager.LayoutParams.FILL_PARENT);
    mPopupWindow.setHeight(WindowManager.LayoutParams.FILL_PARENT);
    mPopupWindow.setTouchable(true);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setAnimationStyle(R.style.AnimBottom);
    mPopupWindow.setContentView(initViews());
    mPopupWindow.getContentView().setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mPopupWindow.setFocusable(false);
            // mPopupWindow.dismiss();
            return true;
        }
    });

}
 
Example 8
Source File: EmojiPopup.java    From Emoji with Apache License 2.0 6 votes vote down vote up
EmojiPopup(@NonNull final EmojiPopup.Builder builder, @NonNull final EditText editText) {
  this.context = Utils.asActivity(builder.rootView.getContext());
  this.rootView = builder.rootView.getRootView();
  this.editText = editText;
  this.recentEmoji = builder.recentEmoji;
  this.variantEmoji = builder.variantEmoji;

  popupWindow = new PopupWindow(context);
  variantPopup = new EmojiVariantPopup(rootView, internalOnEmojiClickListener);

  final EmojiView emojiView = new EmojiView(context,
          internalOnEmojiClickListener, internalOnEmojiLongClickListener, builder);

  emojiView.setOnEmojiBackspaceClickListener(internalOnEmojiBackspaceClickListener);

  popupWindow.setContentView(emojiView);
  popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
  popupWindow.setBackgroundDrawable(new BitmapDrawable(context.getResources(), (Bitmap) null)); // To avoid borders and overdraw.
  popupWindow.setOnDismissListener(onDismissListener);

  if (builder.keyboardAnimationStyle != 0) {
    popupWindow.setAnimationStyle(builder.keyboardAnimationStyle);
  }

  rootView.addOnAttachStateChangeListener(onAttachStateChangeListener);
}
 
Example 9
Source File: ReactionsPopup.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor to create a new reactions popup with an anchor view.
 *
 * @param context Context the reactions popup is running in, through which it
 * can access the current theme, resources, etc.
 * @param anchor Anchor view for this popup. The popup will appear on top of
 */

public ReactionsPopup(@NonNull Context context, @NonNull View anchor) {
  this.anchorView = anchor;

  popup = new PopupWindow();
  popup.setWindowLayoutMode(WindowManager.LayoutParams.WRAP_CONTENT,
      WindowManager.LayoutParams.WRAP_CONTENT);
  reactionsView = new ReactionsView(context);
  reactionsView.setVisibility(View.VISIBLE);
  popup.setContentView(reactionsView);
  popup.setFocusable(true);
  popup.setClippingEnabled(true);
  popup.setBackgroundDrawable(
      ContextCompat.getDrawable(context, R.drawable.rounded_corners_reactions));
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    popup.setElevation(10);
  }

  reactionsView.setCallback(reactionType -> {
    if (reactionClickListener != null) {
      reactionClickListener.onReactionItemClick(reactionType);
    }
  });

  popup.setOnDismissListener(() -> {
    if (onDismissListener != null) {
      onDismissListener.onDismiss(reactionsView);
    }
  });
}
 
Example 10
Source File: BasePop.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
private void initPop()
{
    mPopupWindow = new PopupWindow(mContext);
    mPopupWindow.setFocusable(setFocusable());
    boolean outsideTouchacle = setOutsideTouchable();
    mPopupWindow.setOutsideTouchable(outsideTouchacle);
    mPopupWindow.setBackgroundDrawable(new ShapeDrawable());
    mPopupWindow.setWidth(setLayoutWidthParams());
    mPopupWindow.setHeight(setLayoutHeightParams());
    int animStyle = setAnimStyle();
    if (animStyle != 0)
        mPopupWindow.setAnimationStyle(animStyle);
    //设置内容布局
    mContentView = mContext.getLayoutInflater().inflate(setContentViewId()
            , (ViewGroup) mContext.findViewById(android.R.id.content), false);
    mContentView.measure(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
    mPopupWindow.setContentView(mContentView);
    //设置点击外部关闭pop
    if (outsideTouchacle)
        mPopupWindow.setTouchInterceptor(new View.OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                if (event.getAction() == MotionEvent.ACTION_OUTSIDE)
                {
                    mPopupWindow.dismiss();
                    return true;
                }
                return false;
            }
        });
}
 
Example 11
Source File: PostRowViewBinder.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public static void showPopup(View v) {
    final Context c = v.getContext();
    LayoutInflater inflater = LayoutInflater.from(c);
    TextView contentView = (TextView) inflater.inflate(R.layout.participant_popup_item, null);
    contentView.setText(v.getContentDescription());
    PopupWindow popup = new PopupWindow(c);
    popup.setContentView(contentView);
    popup.setOutsideTouchable(true);
    popup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    popup.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.poster_popup_bg));
    popup.showAsDropDown(v, 0, -v.getHeight() * 2);
}
 
Example 12
Source File: TopicRowViewBinder.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public static void showPopup(View v) {
    final Context c = v.getContext();
    LayoutInflater inflater = LayoutInflater.from(c);
    TextView contentView = (TextView) inflater.inflate(R.layout.participant_popup_item, null);
    contentView.setText(c.getString(R.string.participant_popup_text, v.getTag(R.id.poster_name), v.getTag(R.id.poster_des)));
    PopupWindow popup = new PopupWindow(c);
    popup.setContentView(contentView);
    popup.setOutsideTouchable(true);
    popup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    popup.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.poster_popup_bg));
    popup.showAsDropDown(v);
}
 
Example 13
Source File: MovementTrackActivity.java    From RunMap with Apache License 2.0 5 votes vote down vote up
private void showShareLayout() {
    mSharePopWindow = new PopupWindow(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    View view = LayoutInflater.from(this).inflate(R.layout.sharelayout, null);
    view.findViewById(R.id.btn_share_to_circle).setOnClickListener(this);
    view.findViewById(R.id.btn_share_to_friend).setOnClickListener(this);
    mSharePopWindow.setContentView(view);
    mSharePopWindow.setFocusable(false);
    mSharePopWindow.setBackgroundDrawable(new BitmapDrawable());
    mSharePopWindow.setOutsideTouchable(true);
    mSharePopWindow.showAtLocation(findViewById(android.R.id.content), Gravity.BOTTOM,0,0);
}
 
Example 14
Source File: CandidateView.java    From hackerskeyboard with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a CandidateView for showing suggested words for completion.
 * @param context
 * @param attrs
 */
public CandidateView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mSelectionHighlight = context.getResources().getDrawable(
            R.drawable.list_selector_background_pressed);

    LayoutInflater inflate =
        (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Resources res = context.getResources();
    mPreviewPopup = new PopupWindow(context);
    mPreviewText = (TextView) inflate.inflate(R.layout.candidate_preview, null);
    mPreviewPopup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    mPreviewPopup.setContentView(mPreviewText);
    mPreviewPopup.setBackgroundDrawable(null);
    mPreviewPopup.setAnimationStyle(R.style.KeyPreviewAnimation);
    // Enable clipping for Android P, keep disabled for older versions.
    boolean clippingEnabled = (Build.VERSION.SDK_INT >= 28 /* Build.VERSION_CODES.P */);
    mPreviewPopup.setClippingEnabled(clippingEnabled);
    mColorNormal = res.getColor(R.color.candidate_normal);
    mColorRecommended = res.getColor(R.color.candidate_recommended);
    mColorOther = res.getColor(R.color.candidate_other);
    mDivider = res.getDrawable(R.drawable.keyboard_suggest_strip_divider);
    mAddToDictionaryHint = res.getString(R.string.hint_add_to_dictionary);

    mPaint = new Paint();
    mPaint.setColor(mColorNormal);
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(mPreviewText.getTextSize() * LatinIME.sKeyboardSettings.candidateScalePref);
    mPaint.setStrokeWidth(0);
    mPaint.setTextAlign(Align.CENTER);
    mDescent = (int) mPaint.descent();
    mMinTouchableWidth = (int)res.getDimension(R.dimen.candidate_min_touchable_width);
    
    mGestureDetector = new GestureDetector(
            new CandidateStripGestureListener(mMinTouchableWidth));
    setWillNotDraw(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);
    scrollTo(0, getScrollY());
}
 
Example 15
Source File: EmojiPopup.java    From hipda with GNU General Public License v2.0 4 votes vote down vote up
private EmojiPopup(final View rootView, final EmojiEditText emojiEditText, @Nullable final RecentEmoji recent) {
    this.context = rootView.getContext();
    this.rootView = rootView;
    this.emojiEditText = emojiEditText;
    this.recentEmoji = recent != null ? recent : new RecentEmojiManager(context);
    this.keyBoardHeight = getPreferences().getInt(PREF_KEYBOARD_HEIGHT, 0);

    popupWindow = new PopupWindow(context);
    popupWindow.setBackgroundDrawable(new BitmapDrawable(context.getResources(), (Bitmap) null)); // To avoid borders & overdraw

    final EmojiView emojiView = new EmojiView(context, new OnEmojiClickedListener() {
        @Override
        public void onEmojiClicked(final Emoji emoji) {
            emojiEditText.input(emoji);
            recentEmoji.addEmoji(emoji);

            if (onEmojiClickedListener != null) {
                onEmojiClickedListener.onEmojiClicked(emoji);
            }
        }
    }, this.recentEmoji);

    emojiView.setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() {
        @Override
        public void onEmojiBackspaceClicked(final View v) {
            emojiEditText.backspace();

            if (onEmojiBackspaceClickListener != null) {
                onEmojiBackspaceClickListener.onEmojiBackspaceClicked(v);
            }
        }
    });

    popupWindow.setContentView(emojiView);
    popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    popupWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
    popupWindow.setHeight((int) context.getResources().getDimension(R.dimen.emoji_keyboard_height));
    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (onEmojiPopupDismissListener != null) {
                onEmojiPopupDismissListener.onEmojiPopupDismiss();
            }
        }
    });

    setupListener();
}
 
Example 16
Source File: AnalyzerViews.java    From audio-analyzer-for-android with Apache License 2.0 4 votes vote down vote up
private PopupWindow popupMenuCreate(String[] popUpContents, int resId) {

        // initialize a pop up window type
        PopupWindow popupWindow = new PopupWindow(activity);

        // the drop down list is a list view
        ListView listView = new ListView(activity);

        // set our adapter and pass our pop up window contents
        ArrayAdapter<String> aa = popupMenuAdapter(popUpContents);
        listView.setAdapter(aa);

        // set the item click listener
        listView.setOnItemClickListener(activity);

        // button resource ID, so we can trace back which button is pressed
        listView.setTag(resId);

        // get max text width
        Paint mTestPaint = new Paint();
        mTestPaint.setTextSize(listItemTextSize);
        float w = 0;  // max text width in pixel
        float wi;
        for (String popUpContent : popUpContents) {
            String sts[] = popUpContent.split("::");
            if (sts.length == 0) continue;
            String st = sts[0];
            if (sts.length == 2 && sts[1].equals("0")) {
                mTestPaint.setTextSize(listItemTitleTextSize);
                wi = mTestPaint.measureText(st);
                mTestPaint.setTextSize(listItemTextSize);
            } else {
                wi = mTestPaint.measureText(st);
            }
            if (w < wi) {
                w = wi;
            }
        }

        // left and right padding, at least +7, or the whole app will stop respond, don't know why
        w = w + 23 * DPRatio;
        if (w < 40 * DPRatio) {
            w = 40 * DPRatio;
        }

        // some other visual settings
        popupWindow.setFocusable(true);
        popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        // Set window width according to max text width
        popupWindow.setWidth((int)w);
        // also set button width
        ((Button) activity.findViewById(resId)).setWidth((int)(w + 5 * DPRatio));
        // Set the text on button in loadPreferenceForView()

        // set the list view as pop up window content
        popupWindow.setContentView(listView);

        return popupWindow;
    }
 
Example 17
Source File: WXMask.java    From incubator-weex-playground with Apache License 2.0 4 votes vote down vote up
@Override
protected View initComponentHostView(@NonNull Context context) {

  mContainerView = new WXMaskView(context);
  mPopupWindow = new PopupWindow(context);
  mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
    mPopupWindow.setAttachedInDecor(true);
  }

  //setClippingEnabled(false) will cause INPUT_ADJUST_PAN invalid.
  //mPopupWindow.setClippingEnabled(false);

  mPopupWindow.setContentView(mContainerView);
  mPopupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
  mPopupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
  mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN |
      WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
  mPopupWindow.setFocusable(true);

  mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
    @Override
    public void onDismiss() {
      fireVisibleChangedEvent(false);
    }
  });

  int y = 0;
  int statusBarHeight = 0;
  int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
  if (resourceId > 0) {
    statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
    y = statusBarHeight;
  }

  mPopupWindow.showAtLocation(((Activity) context).getWindow().getDecorView(),
      Gravity.TOP | Gravity.START,
      0,
      y);
  fireVisibleChangedEvent(true);

  return mContainerView;
}
 
Example 18
Source File: LatinKeyboardView.java    From hackerskeyboard with Apache License 2.0 4 votes vote down vote up
public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // TODO(klausw): migrate attribute styles to LatinKeyboardView?
    TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.LatinKeyboardBaseView, defStyle, R.style.LatinKeyboardBaseView);
    LayoutInflater inflate =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);

        switch (attr) {
        case R.styleable.LatinKeyboardBaseView_keyPreviewLayout:
            previewLayout = a.getResourceId(attr, 0);
            if (previewLayout == R.layout.null_layout) previewLayout = 0;
            break;
        case R.styleable.LatinKeyboardBaseView_keyPreviewOffset:
            mPreviewOffset = a.getDimensionPixelOffset(attr, 0);
            break;
        case R.styleable.LatinKeyboardBaseView_keyPreviewHeight:
            mPreviewHeight = a.getDimensionPixelSize(attr, 80);
            break;
        case R.styleable.LatinKeyboardBaseView_popupLayout:
            mPopupLayout = a.getResourceId(attr, 0);
            if (mPopupLayout == R.layout.null_layout) mPopupLayout = 0;
            break;
        }
    }

    final Resources res = getResources();

    // If true, popups are forced to remain inside the keyboard area. If false,
    // they can extend above it. Enable clipping just for Android P since drawing
    // outside the keyboard area doesn't work on that version.
    boolean clippingEnabled = (Build.VERSION.SDK_INT >= 28 /* Build.VERSION_CODES.P */);

    if (previewLayout != 0) {
        mPreviewPopup = new PopupWindow(context);
        if (!isInEditMode())
            Log.i(TAG, "new mPreviewPopup " + mPreviewPopup + " from " + this);
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) res.getDimension(R.dimen.key_preview_text_size_large);
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
        mPreviewPopup.setTouchable(false);
        mPreviewPopup.setAnimationStyle(R.style.KeyPreviewAnimation);
        mPreviewPopup.setClippingEnabled(clippingEnabled);
    } else {
        mShowPreview = false;
    }

    if (mPopupLayout != 0) {
        mMiniKeyboardParent = this;
        mMiniKeyboardPopup = new PopupWindow(context);
        if (!isInEditMode())
            Log.i(TAG, "new mMiniKeyboardPopup " + mMiniKeyboardPopup + " from " + this);
        mMiniKeyboardPopup.setBackgroundDrawable(null);
        mMiniKeyboardPopup.setAnimationStyle(R.style.MiniKeyboardAnimation);
        mMiniKeyboardPopup.setClippingEnabled(clippingEnabled);
        mMiniKeyboardVisible = false;
    }
}
 
Example 19
Source File: CustomKeyboardView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
public CustomKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    LayoutInflater inflate =
            (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int keyTextSize = 0;
    mKeyBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mKeyCapStartBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mVerticalCorrection = 0;
    previewLayout = 0;
    mPreviewOffset = 0;
    mPreviewHeight = 80;
    mKeyTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_text_size);
    mKeyTextColor = 0xFFFFFFFF;
    mLabelTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_longtext_size);
    mPopupLayout = R.layout.keyboard;
    mShadowColor = 0;
    mShadowRadius = 0;
    mBackgroundDimAmount = 0.5f;
    clearHover();

    mPreviewPopup = new PopupWindow(context);
    if (previewLayout != 0) {
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
    } else {
        mShowPreview = false;
    }

    mPreviewPopup.setTouchable(false);

    mPopupKeyboard = new PopupWindow(context);
    mPopupKeyboard.setBackgroundDrawable(null);
    //mPopupKeyboard.setClippingEnabled(false);

    mPopupParent = this;
    //mPredicting = true;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(keyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);
    mPaint.setTypeface(Typeface.create("sans-serif",Typeface.NORMAL));

    mPadding = new Rect(0, 0, 0, 0);
    mMiniKeyboardCache = new HashMap<>();
    mKeyBackground.getPadding(mPadding);
    mKeyboardHoveredPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_hovered_padding);
    mKeyboardPressedPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_pressed_padding);

    mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
    mDisambiguateSwipe = false;

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    resetMultiTap();

    mForegroundColor = context.getColor(R.color.asphalt);
    mSelectedForegroundColor = context.getColor(R.color.fog);
}
 
Example 20
Source File: KeyboardView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public KeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(
            attrs, android.R.styleable.KeyboardView, defStyleAttr, defStyleRes);

    LayoutInflater inflate =
            (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int keyTextSize = 0;

    int n = a.getIndexCount();

    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);

        switch (attr) {
        case com.android.internal.R.styleable.KeyboardView_keyBackground:
            mKeyBackground = a.getDrawable(attr);
            break;
        case com.android.internal.R.styleable.KeyboardView_verticalCorrection:
            mVerticalCorrection = a.getDimensionPixelOffset(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyPreviewLayout:
            previewLayout = a.getResourceId(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyPreviewOffset:
            mPreviewOffset = a.getDimensionPixelOffset(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyPreviewHeight:
            mPreviewHeight = a.getDimensionPixelSize(attr, 80);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyTextSize:
            mKeyTextSize = a.getDimensionPixelSize(attr, 18);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyTextColor:
            mKeyTextColor = a.getColor(attr, 0xFF000000);
            break;
        case com.android.internal.R.styleable.KeyboardView_labelTextSize:
            mLabelTextSize = a.getDimensionPixelSize(attr, 14);
            break;
        case com.android.internal.R.styleable.KeyboardView_popupLayout:
            mPopupLayout = a.getResourceId(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_shadowColor:
            mShadowColor = a.getColor(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_shadowRadius:
            mShadowRadius = a.getFloat(attr, 0f);
            break;
        }
    }

    a = mContext.obtainStyledAttributes(
            com.android.internal.R.styleable.Theme);
    mBackgroundDimAmount = a.getFloat(android.R.styleable.Theme_backgroundDimAmount, 0.5f);

    mPreviewPopup = new PopupWindow(context);
    if (previewLayout != 0) {
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
    } else {
        mShowPreview = false;
    }

    mPreviewPopup.setTouchable(false);

    mPopupKeyboard = new PopupWindow(context);
    mPopupKeyboard.setBackgroundDrawable(null);
    //mPopupKeyboard.setClippingEnabled(false);

    mPopupParent = this;
    //mPredicting = true;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(keyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);

    mPadding = new Rect(0, 0, 0, 0);
    mMiniKeyboardCache = new HashMap<Key,View>();
    mKeyBackground.getPadding(mPadding);

    mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
    mDisambiguateSwipe = getResources().getBoolean(
            com.android.internal.R.bool.config_swipeDisambiguation);

    mAccessibilityManager = AccessibilityManager.getInstance(context);
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    resetMultiTap();
}