androidviewandroid-custom-viewloupe

Implementing magnifier/loupe for custom dynamic view on android


I'm looking for a way to implement Magnifier/Loupe for custom view on android which is dynamically rebuilding.


Solution

  • I've figured it out Myself. So here is variant for dynamic changing view.

    1) At first we are Creating new bitmap(whole) with same Height and Width in Overriden on Draw method;

    2) create Canvas(temporalCanvas) from our bitmap(whole)

    3) draw everything that we need on canvas(temporalCanvas)

    4) draw out bitmap to original canvas(canvas) that is given in onDraw income

    5) take coordinates from MotionEvent (it should be made global static on ACTION_DOWN) so this would be the SAME MotionEvent after invalidating and drawing view

    6) Cut bitmap around selected(MotionEvent.GetX/Y) position

    7) Draw trimmed bitmap on original (canvas) canvas

    Possible difficulties: -Motion event returns different coordinates X,Y when it's called either from overriden onTouchEvent or from static event that where made on ACTION_DOWN; (just make x,y coordinate static) and don't forget to remove static touch event, and x,y coordinates on action UP

    -2 canvas should be used or you can magnifier magnifier)