Search in sources :

Example 71 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 = 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()));
}
Also used : Rect(android.graphics.Rect) WindowManager(android.view.WindowManager) R(org.hwyl.sexytopo.R) Colour(org.hwyl.sexytopo.model.sketch.Colour) GraphActivity(org.hwyl.sexytopo.control.activity.GraphActivity) AttributeSet(android.util.AttributeSet) Map(java.util.Map) View(android.view.View) Canvas(android.graphics.Canvas) SketchDetail(org.hwyl.sexytopo.model.sketch.SketchDetail) SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) Projection2D(org.hwyl.sexytopo.model.graph.Projection2D) TextTools(org.hwyl.sexytopo.control.util.TextTools) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) Set(java.util.Set) SketchTool(org.hwyl.sexytopo.model.sketch.SketchTool) ScaleGestureDetector(android.view.ScaleGestureDetector) Direction(org.hwyl.sexytopo.model.graph.Direction) AlertDialog(android.app.AlertDialog) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) List(java.util.List) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) CrossSectioner(org.hwyl.sexytopo.control.util.CrossSectioner) Symbol(org.hwyl.sexytopo.model.sketch.Symbol) Paint(android.graphics.Paint) Context(android.content.Context) Path(android.graphics.Path) GestureDetector(android.view.GestureDetector) PlanActivity(org.hwyl.sexytopo.control.activity.PlanActivity) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) Station(org.hwyl.sexytopo.model.survey.Station) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) SurveyUpdater(org.hwyl.sexytopo.control.util.SurveyUpdater) MotionEvent(android.view.MotionEvent) Line(org.hwyl.sexytopo.model.graph.Line) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) Leg(org.hwyl.sexytopo.model.survey.Leg) Survey(org.hwyl.sexytopo.model.survey.Survey) PreferenceAccess(org.hwyl.sexytopo.control.util.PreferenceAccess) Space2DUtils(org.hwyl.sexytopo.control.util.Space2DUtils) PopupWindow(android.widget.PopupWindow) Log(org.hwyl.sexytopo.control.Log) BrushColour(org.hwyl.sexytopo.model.sketch.BrushColour) ExtendedElevationActivity(org.hwyl.sexytopo.control.activity.ExtendedElevationActivity) SurveyStats(org.hwyl.sexytopo.control.util.SurveyStats) Space(org.hwyl.sexytopo.model.graph.Space) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail) Gravity(android.view.Gravity) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) SharedPreferences(android.content.SharedPreferences) CohenSutherlandAlgorithm(org.hwyl.sexytopo.control.util.CohenSutherlandAlgorithm) Bitmap(android.graphics.Bitmap) EditText(android.widget.EditText) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) PopupWindow(android.widget.PopupWindow) ExtendedElevationActivity(org.hwyl.sexytopo.control.activity.ExtendedElevationActivity) Direction(org.hwyl.sexytopo.model.graph.Direction) View(android.view.View)

Example 72 with PopupWindow

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;
}
Also used : Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) PopupWindow(android.widget.PopupWindow) View(android.view.View)

Example 73 with PopupWindow

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();
        }
    });
}
Also used : TypedArray(android.content.res.TypedArray) PopupWindow(android.widget.PopupWindow) Paint(android.graphics.Paint) Resources(android.content.res.Resources) ValueAnimator(android.animation.ValueAnimator) AbsoluteLayout(android.widget.AbsoluteLayout)

Example 74 with PopupWindow

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);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) PopupWindow(android.widget.PopupWindow)

Example 75 with PopupWindow

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
        }
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) PopupWindow(android.widget.PopupWindow) ParseException(java.text.ParseException)

Aggregations

PopupWindow (android.widget.PopupWindow)145 View (android.view.View)68 TextView (android.widget.TextView)52 ColorDrawable (android.graphics.drawable.ColorDrawable)29 Paint (android.graphics.Paint)26 ImageView (android.widget.ImageView)24 AdapterView (android.widget.AdapterView)15 Key (android.inputmethodservice.Keyboard.Key)14 LayoutInflater (android.view.LayoutInflater)14 LinearLayout (android.widget.LinearLayout)14 ListView (android.widget.ListView)14 BitmapDrawable (android.graphics.drawable.BitmapDrawable)13 Button (android.widget.Button)13 Activity (android.app.Activity)12 Context (android.content.Context)11 Resources (android.content.res.Resources)11 OnClickListener (android.view.View.OnClickListener)11 ViewGroup (android.view.ViewGroup)11 EditText (android.widget.EditText)11 ScrollView (android.widget.ScrollView)10