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);
}
}
}
}
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);
}
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;
}
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();
}
}
}
});
}
}
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()));
}
Aggregations