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 = view -> {
int id = view.getId();
// because IDs are no longer final
if (id == R.id.graph_station_select) {
setActiveStation(station);
invalidate();
} else if (id == R.id.graph_station_toggle_left_right) {
Direction newDirection = station.getExtendedElevationDirection().opposite();
SurveyUpdater.setDirectionOfSubtree(station, newDirection);
broadcastSurveyUpdated();
invalidate();
} else if (id == R.id.graph_station_comment) {
openCommentDialog(station);
} else if (id == R.id.graph_station_reverse) {
SurveyUpdater.reverseLeg(survey, station);
broadcastSurveyUpdated();
invalidate();
} else if (id == R.id.graph_station_delete) {
askAboutDeletingStation(station);
invalidate();
} else if (id == R.id.graph_station_new_cross_section) {
setActiveStation(station);
setSketchTool(SketchTool.POSITION_CROSS_SECTION);
activity.showSimpleToast(R.string.position_cross_section_instruction);
} else if (id == R.id.graph_station_jump_to_table) {
activity.jumpToStation(station, TableActivity.class);
} else if (id == R.id.graph_station_jump_to_plan) {
activity.jumpToStation(station, PlanActivity.class);
} else if (id == R.id.graph_station_jump_to_ee) {
activity.jumpToStation(station, ExtendedElevationActivity.class);
} else if (id == R.id.graph_station_start_new_survey) {
if (!survey.isSaved()) {
activity.showSimpleToast(R.string.cannot_extend_unsaved_survey);
}
activity.continueSurvey(station);
} else if (id == R.id.graph_station_unlink_survey) {
activity.unlinkSurvey(station);
}
};
PopupWindow menu = activity.getContextMenu(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.START | Gravity.TOP, (int) (event.getX()), (int) (event.getY()));
}
use of android.widget.PopupWindow in project sexytopo by richsmith.
the class StationContextMenu method getFakeStationContextMenu.
public 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);
postCreationHook(view);
Button title = 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_select, R.id.graph_station_toggle_left_right, 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_jump_to_table, R.id.graph_station_start_new_survey, R.id.graph_station_unlink_survey };
for (int id : ids) {
view.findViewById(id).setOnClickListener(view1 -> {
fakeMenu.dismiss();
listener.onClick(view1);
});
}
fakeMenu.setFocusable(true);
fakeMenu.setOutsideTouchable(true);
return fakeMenu;
}
use of android.widget.PopupWindow in project EhViewer by seven332.
the class Slider method init.
@SuppressWarnings("deprecation")
private void init(Context context, AttributeSet attrs) {
mContext = context;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextAlign(Paint.Align.CENTER);
Resources resources = context.getResources();
mBubbleMinWidth = resources.getDimensionPixelOffset(R.dimen.slider_bubble_width);
mBubbleMinHeight = resources.getDimensionPixelOffset(R.dimen.slider_bubble_height);
mBubble = new BubbleView(context, textPaint);
mBubble.setScaleX(0.0f);
mBubble.setScaleY(0.0f);
AbsoluteLayout absoluteLayout = new AbsoluteLayout(context);
absoluteLayout.addView(mBubble);
absoluteLayout.setBackgroundDrawable(null);
mPopup = new PopupWindow(absoluteLayout);
mPopup.setOutsideTouchable(false);
mPopup.setTouchable(false);
mPopup.setFocusable(false);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider);
textPaint.setColor(a.getColor(R.styleable.Slider_textColor, Color.WHITE));
textPaint.setTextSize(a.getDimensionPixelSize(R.styleable.Slider_textSize, 12));
updateTextSize();
setRange(a.getInteger(R.styleable.Slider_start, 0), a.getInteger(R.styleable.Slider_end, 0));
setProgress(a.getInteger(R.styleable.Slider_slider_progress, 0));
mThickness = a.getDimension(R.styleable.Slider_thickness, 2);
mRadius = a.getDimension(R.styleable.Slider_radius, 6);
setColor(a.getColor(R.styleable.Slider_color, Color.BLACK));
mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBgPaint.setColor(a.getBoolean(R.styleable.Slider_dark, false) ? 0x4dffffff : 0x42000000);
a.recycle();
mProgressAnimation = new ValueAnimator();
mProgressAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
mProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(@NonNull ValueAnimator animation) {
float value = (Float) animation.getAnimatedValue();
mDrawPercent = value;
mDrawProgress = Math.round(MathUtils.lerp((float) mStart, mEnd, value));
updateBubblePosition();
mBubble.setProgress(mDrawProgress);
invalidate();
}
});
mBubbleScaleAnimation = new ValueAnimator();
mBubbleScaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(@NonNull ValueAnimator animation) {
float value = (Float) animation.getAnimatedValue();
mDrawBubbleScale = value;
mBubble.setScaleX(value);
mBubble.setScaleY(value);
invalidate();
}
});
}
use of android.widget.PopupWindow in project apps-android-wikipedia by wikimedia.
the class PageActionOverflowView method show.
public void show(@NonNull View anchorView, @Nullable Callback callback, @NonNull Tab currentTab) {
this.callback = callback;
popupWindowHost = new PopupWindow(this, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
popupWindowHost.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
PopupWindowCompat.setOverlapAnchor(popupWindowHost, true);
final int compatOffset = 8;
PopupWindowCompat.showAsDropDown(popupWindowHost, anchorView, 0, Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? -DimenUtil.getToolbarHeightPx(anchorView.getContext()) + DimenUtil.roundedDpToPx(compatOffset) : 0, Gravity.END);
final float disabledAlpha = 0.5f;
backButton.setEnabled(currentTab.canGoBack());
backButton.setAlpha(backButton.isEnabled() ? 1.0f : disabledAlpha);
forwardButton.setEnabled(currentTab.canGoForward());
forwardButton.setAlpha(forwardButton.isEnabled() ? 1.0f : disabledAlpha);
}
use of android.widget.PopupWindow in project apps-android-wikipedia by wikimedia.
the class ReadingListsOverflowView method show.
public void show(@NonNull View anchorView, @Nullable Callback callback) {
this.callback = callback;
popupWindowHost = new PopupWindow(this, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
popupWindowHost.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
PopupWindowCompat.setOverlapAnchor(popupWindowHost, true);
final int compatOffset = 8;
PopupWindowCompat.showAsDropDown(popupWindowHost, anchorView, 0, Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? -DimenUtil.getToolbarHeightPx(anchorView.getContext()) + DimenUtil.roundedDpToPx(compatOffset) : 0, Gravity.END);
String lastSyncTime = Prefs.getReadingListsLastSyncTime();
lastSync.setVisibility(TextUtils.isEmpty(lastSyncTime) ? View.GONE : View.VISIBLE);
if (!TextUtils.isEmpty(lastSyncTime)) {
try {
lastSync.setText(String.format(getContext().getString(R.string.reading_list_menu_last_sync), DateUtil.getReadingListsLastSyncDateString(Prefs.getReadingListsLastSyncTime())));
} catch (ParseException e) {
// ignore
}
}
}
Aggregations