android - ShowcaseView's details text won't go to the new line -
that's problem, tried using setpadding, setright , other stupid methods, won't help.
i need text go new lines when display limits has reached, so, please me.
it seems have place if use target, target.none, other times, when use button , etc, lines go down should , ok, need intro text show first time without specific elements selected.
i solved problem through adding child view showcaseview
.
upd,
i've been asked share solution, i'll share code use.
here's complete code using showcaseview
: use fragment
show it, therefore don't need copy code in every time, made improvements make life easier using it:
frshowcase.java:
/** * created movsar bekaev on 02/09/2015. */ public class frshowcase extends fragment { static boolean is_sc_done; static arraylist<xschowcasetarget> elements; static showcaseview sv; int svstep = 0; relativelayout.layoutparams svbuttonparams; textview tvsvtitle, tvsvdetail; view additional_view = null; handler mhandler; //showcase thing************************************ private view.onclicklistener showcaselistener = new view.onclicklistener() { @override public void onclick(view view) { sv.hidebutton(); handler handler = new handler(); handler.postdelayed(new runnable() { public void run() { showcaseswitcher(); sv.showbutton(); } }, 50); } }; public static frshowcase newinstance(arraylist<xschowcasetarget> _elements) { frshowcase f = new frshowcase(); bundle args = new bundle(); elements = new arraylist<xschowcasetarget>(); sv = null; (xschowcasetarget se : _elements) { elements.add(se); } is_sc_done = false; f.setarguments(args); return f; } public void svsetbuttonposition(cbactivity.position buttonportraitposition) { switch (buttonportraitposition) { case bottom_left: svbuttonparams = new relativelayout.layoutparams((int) getactivity().getresources().getdimension(r.dimen.btns_width), (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.align_parent_left); svbuttonparams.addrule(relativelayout.align_parent_bottom); svbuttonparams.topmargin = 0; break; case bottom_right: svbuttonparams = new relativelayout.layoutparams((int) getactivity().getresources().getdimension(r.dimen.btns_width), (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.align_parent_right); svbuttonparams.addrule(relativelayout.align_parent_bottom); svbuttonparams.topmargin = 0; break; case top_left: svbuttonparams = new relativelayout.layoutparams((int) getactivity().getresources().getdimension(r.dimen.btns_width), (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.align_parent_top); svbuttonparams.addrule(relativelayout.align_parent_left); svbuttonparams.topmargin = (int) getactivity().getresources().getdimension(r.dimen.btns_heigh); break; case top_right: svbuttonparams = new relativelayout.layoutparams((int) getactivity().getresources().getdimension(r.dimen.btns_width), (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.align_parent_top); svbuttonparams.addrule(relativelayout.align_parent_right); svbuttonparams.topmargin = (int) getactivity().getresources().getdimension(r.dimen.btns_heigh); break; case center: svbuttonparams = new relativelayout.layoutparams((int) getactivity().getresources().getdimension(r.dimen.btns_width), (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.center_in_parent); svbuttonparams.topmargin = 0; break; case fill_bottom: svbuttonparams = new relativelayout.layoutparams(viewgroup.layoutparams.fill_parent, (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.center_horizontal); svbuttonparams.addrule(relativelayout.align_parent_bottom); svbuttonparams.topmargin = 0; break; case fill_top: svbuttonparams = new relativelayout.layoutparams(viewgroup.layoutparams.fill_parent, (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.center_horizontal); svbuttonparams.addrule(relativelayout.align_parent_top); svbuttonparams.topmargin = (int) getactivity().getresources().getdimension(r.dimen.btns_heigh); break; case bottom_center: svbuttonparams = new relativelayout.layoutparams((int) getactivity().getresources().getdimension(r.dimen.btns_width), (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.center_horizontal); svbuttonparams.addrule(relativelayout.align_parent_bottom); svbuttonparams.topmargin = 0; break; case center_top: svbuttonparams = new relativelayout.layoutparams((int) getactivity().getresources().getdimension(r.dimen.btns_width), (int) getactivity().getresources().getdimension(r.dimen.btns_heigh)); svbuttonparams.addrule(relativelayout.center_horizontal); svbuttonparams.addrule(relativelayout.align_parent_top); svbuttonparams.topmargin = (int) getactivity().getresources().getdimension(r.dimen.btns_heigh); break; } sv.setbuttonposition(svbuttonparams); } private void svsetupotherview() { sv.setcontenttitle(""); sv.setcontenttext(""); additional_view = view.inflate(getactivity(), r.layout.showcase_text, null); relativelayout.layoutparams lps = new relativelayout.layoutparams(viewgroup.layoutparams.fill_parent, viewgroup.layoutparams.wrap_content); lps.addrule(relativelayout.center_in_parent); tvsvtitle = (textview) additional_view.findviewbyid(r.id.tvsvtitle); tvsvtitle.settext(elements.get(svstep).title); tvsvdetail = (textview) additional_view.findviewbyid(r.id.tvsvdetailtext); tvsvdetail.settext(elements.get(svstep).description); sv.addview(additional_view, 0, lps); } private void showcaseswitcher() { if (svstep < elements.size()) { if (additional_view != null) sv.removeview(additional_view); sv.setshowcase(elements.get(svstep).target, true); svsetbuttonposition(elements.get(svstep).b_pos); if (elements.get(svstep).use_splashscreen) { svsetupotherview(); } else { sv.setcontenttitle(elements.get(svstep).title); sv.setcontenttext(elements.get(svstep).description); } svstep++; } else { viewgroup mrootview = (viewgroup) getactivity().getwindow().getdecorview().findviewbyid(android.r.id.content); (view v : getallchildrenbfs(mrootview)) v.setenabled(true); sv.hide(); if (elements.get(svstep - 1).title.equals(getstring(r.string.sv_intention_addweek_title))) { final message m1 = mhandler.obtainmessage(123); mhandler.sendmessage(m1); } getactivity().setrequestedorientation(activityinfo.screen_orientation_user); } } public void sethandler(handler handler) { this.mhandler = handler; } @override public void onattach(activity ac) { super.onattach(ac); log.d("123", "onattach"); } private list<view> getallchildrenbfs(view v) { list<view> visited = new arraylist<view>(); list<view> unvisited = new arraylist<view>(); unvisited.add(v); while (!unvisited.isempty()) { view child = unvisited.remove(0); visited.add(child); if (!(child instanceof viewgroup)) continue; viewgroup group = (viewgroup) child; final int childcount = group.getchildcount(); (int i=0; i<childcount; i++) unvisited.add(group.getchildat(i)); } return visited; } @override public void oncreate(bundle b) { super.oncreate(b); log.d("123", "oncreate"); } public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { //showcase initialization thing************************************************************* if (!is_sc_done && frshowcase.elements != null) { getactivity().setrequestedorientation(activityinfo.screen_orientation_portrait); if (getresources().getconfiguration().orientation == configuration.orientation_portrait) { powermanager pm = (powermanager) getactivity().getsystemservice(context.power_service); boolean isscreenon = pm.isscreenon(); if (isscreenon) { is_sc_done = true; viewgroup mrootview = (viewgroup) getactivity().getwindow().getdecorview().findviewbyid(android.r.id.content); (view v : getallchildrenbfs(mrootview)) v.setenabled(false); cbactivity.booltopref(getactivity().getlocalclassname(), false); sv = new showcaseview.builder(getactivity()) .settarget(frshowcase.elements.get(0).target) .setcontenttitle(frshowcase.elements.get(svstep).title) .setcontenttext(frshowcase.elements.get(svstep).description) .setstyle(r.style.customshowcasetheme) .setonclicklistener(showcaselistener) .build(); if (elements.get(svstep).use_splashscreen) svsetupotherview(); svsetbuttonposition(frshowcase.elements.get(0).b_pos); sv.setbuttontext(getactivity().getstring(r.string.next)); svstep++; } } return sv; } //************************************************************************************** return container; } }
here class targets use pass targets
activities
fragment
xshowcasetargets.java
import com.github.amlcurran.showcaseview.targets.target; /** * created movsar bekaev on 15/09/2015. */ public class xschowcasetarget{ protected cbactivity.position b_pos = cbactivity.position.bottom_right; protected target target = null; protected string title = ""; protected string description = ""; protected boolean use_splashscreen = false; public xschowcasetarget(target target, string title, string desc, cbactivity.position position, boolean usesplash) { this.b_pos = position; this.target = target; this.title = title; this.description = desc; this.use_splashscreen = usesplash; } public xschowcasetarget(target target, string title, string desc, cbactivity.position position) { this.b_pos = position; this.target = target; this.title = title; this.description = desc; this.use_splashscreen = false; } }
this xml custom layout showcaseview use when default 1 won't job (text go off screen, button not there should , etc.)
showcase_text.xml
<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <scrollview android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/scvshowcase" > <linearlayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/welcome" android:id="@+id/tvsvtitle" android:layout_gravity="center_horizontal" android:layout_margintop="50dp" android:textcolor="?attr/color_7" android:textsize="@dimen/h1_size" android:textstyle="bold" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/welcome_text" android:id="@+id/tvsvdetailtext" android:layout_gravity="center_horizontal" android:textcolor="?attr/color_4" android:layout_margintop="30dp" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:textsize="@dimen/text_normal_size" android:gravity="center" /> </linearlayout> </scrollview> </framelayout>
as cbactivity.boolfrompref(getlocalclassname(), false)
- use shared preferences check whether or not activity has been started, line checks value, in fragment's code see blocking views of layout while presentation, if don't need - don't call that.
if need use custom view, add "true" when creating target
this:
svelements.add(new xschowcasetarget(target.none, getstring(r.string.welcome), getstring(r.string.welcome_text), position.fill_bottom, true));
and last thing is, cbactivity - mybase class activities, use here reference common methods , vars, position enum declared in class, , looks like:
public enum position {top_right, top_left, bottom_right, bottom_left, center, bottom_center, center_top, fill_bottom, fill_top}
here example of how call showcaseview activities:
if (cbactivity.boolfrompref(getlocalclassname(), false)) { arraylist<xschowcasetarget> svelements = new arraylist<xschowcasetarget>(); svelements.add(new xschowcasetarget(target.none, getstring(r.string.welcome), getstring(r.string.welcome_text), position.fill_bottom, true)); svelements.add(new xschowcasetarget(new viewtarget(r.id.xxx, actmain.this), getstring(r.string.xxx), getstring(r.string.xxx), position.bottom_left)); svelements.add(new xschowcasetarget(new viewtarget(r.id.xxx, actmain.this), getstring(r.string.xxx), getstring(r.xxx), position.bottom_right)); if (isthereactionmenubutton()) svelements.add(new xschowcasetarget(new actionviewtarget(actmain.this, actionviewtarget.type.overflow), getstring(r.string.xxx), getstring(r.string.xxx), position.fill_bottom)); svelements.add(new xschowcasetarget(new viewtarget(r.id.xxx, actmain.this), getstring(r.string.xxx), getstring(r.string.xxx), position.center)); frshowcase frsc = frshowcase.newinstance(svelements); fm.begintransaction().add(frsc , "xxx").commit(); }
Comments
Post a Comment