Monday, 15 February 2010

android - Custom TextView can not show Standard Copy Paste -



android - Custom TextView can not show Standard Copy Paste -

i'm creating custom textview scalegesturedetector , gesturedetector. purpose rezise text size on doubletap event or onscale event. problem can not show standard feature re-create paste on android while did longtap. problem did not occur when used normal textview, can not utilize doubletap since trigger standard re-create paste on android occur.

here code

package com.text.apps.ux; import android.content.context; import android.graphics.canvas; import android.graphics.paint; import android.support.v4.view.gesturedetectorcompat; import android.util.attributeset; import android.util.typedvalue; import android.view.gesturedetector; import android.view.motionevent; import android.view.scalegesturedetector; import android.widget.textview; public class rtextview extends textview{ private static final string tag = "interactivetextview"; /** * number of individual points (samples) in chart series draw onscreen. */ private static final float default_font_size = 7.0f; private float mtextsize; private context mcontext; private paint mtextpaint; private scalegesturedetector mscalegesturedetector; private gesturedetectorcompat mgesturedetector; public rtextview(context context, attributeset attrs) { super(context, attrs); mcontext = context; initiliaze(); } private void initiliaze() { mtextpaint = new paint(); mtextpaint.set(this.getpaint()); this.settextsize(typedvalue.complex_unit_dip, default_font_size); mtextsize = this.gettextsize(); this.settextisselectable(true); // sets interactions mscalegesturedetector = new scalegesturedetector(mcontext, mscalegesturelistener); mgesturedetector = new gesturedetectorcompat(mcontext, mgesturelistener); } @override public boolean ontouchevent(motionevent event) { boolean retval = mscalegesturedetector.ontouchevent(event); retval = mgesturedetector.ontouchevent(event) || retval; homecoming retval || super.ontouchevent(event); } public rtextview(context context) { super(context); mcontext = context; initiliaze(); } @override protected void ondraw(canvas canvas) { super.ondraw(canvas); if(mtextsize<0.0f) mtextsize = default_font_size; this.settextsize (typedvalue.complex_unit_dip, mtextsize); } /** * scale listener, used handling multi-finger scale gestures. */ private final scalegesturedetector.onscalegesturelistener mscalegesturelistener = new scalegesturedetector.simpleonscalegesturelistener() { /** * active focal point in terms of viewport. local * variable kept here minimize per-frame allocations. */ @override public boolean onscalebegin(scalegesturedetector scalegesturedetector) { homecoming true; } @override public boolean onscale(scalegesturedetector scalegesturedetector) { float scalefactor = scalegesturedetector.getscalefactor(); if(scalefactor<1) { mtextsize -=1; }else{ mtextsize ++; } invalidate(); homecoming true; } }; private void selecttext(){ this.settextisselectable(true); this.setfocusableintouchmode(true); } /** * gesture listener, used handling simple gestures such double touches, scrolls, * , flings. */ private final gesturedetector.simpleongesturelistener mgesturelistener = new gesturedetector.simpleongesturelistener() { @override public void onshowpress(motionevent e){ selecttext(); } @override public boolean ondoubletap(motionevent e) { mtextsize ++; invalidate(); homecoming true; } }; }

thanks in advance

android textview

No comments:

Post a Comment