Android native typeface cannot be made -
when run project classnotfoundexception genereted. problem class existes in project log:
caused by: java.lang.runtimeexception: native typeface cannot made @ android.graphics.typeface.(typeface.java:190) @ android.graphics.typeface.createfromasset(typeface.java:164) @ tabview.fakher.com.tabconfig.titleflowindicator.(titleflowindicator.java:110) at java.lang.reflect.constructor.constructnative(native method) at java.lang.reflect.constructor.newinstance(constructor.java:417) at android.view.layoutinflater.createview(layoutinflater.java:594) at android.view.layoutinflater.createviewfromtag(layoutinflater.java:696) at android.view.layoutinflater.rinflate(layoutinflater.java:755) at android.view.layoutinflater.rinflate(layoutinflater.java:758) at android.view.layoutinflater.inflate(layoutinflater.java:492) at android.view.layoutinflater.inflate(layoutinflater.java:397) at android.view.layoutinflater.inflate(layoutinflater.java:353) at android.support.v7.app.actionbaractivitydelegatebase.setcontentview(actionbaractivitydelegatebase.java:240) at android.support.v7.app.actionbaractivity.setcontentview(actionbaractivity.java:102) at tabview.fakher.com.tabconfig.mainactivity.oncreate(mainactivity.java:19) at android.app.activity.performcreate(activity.java:5234) at android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) at android.app.activitythread.performlaunchactivity(activitythread.java:2302) at android.app.activitythread.handlelaunchactivity(activitythread.java:2388) at android.app.activitythread.access$900(activitythread.java:148) at android.app.activitythread$h.handlemessage(activitythread.java:1319) at android.os.handler.dispatchmessage(handler.java:99) at android.os.looper.loop(looper.java:137) at android.app.activitythread.main(activitythread.java:5473) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:525) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:854) at com.android.internal.os.zygoteinit.main(zygoteinit.java:670) at dalvik.system.nativestart.main(native method)
and class titleflowindicator :
public class titleflowindicator extends textview implements flowindicator { private static final float title_padding = 10.0f; private static final float clip_padding = 0.0f; private static final int selected_color = 0xffffc445; private static final boolean selected_bold = false; private static final int text_color = 0xffaaaaaa; private static final int text_size = 15; private static final float footer_line_height = 4.0f; private static final int footer_color = 0xffffc445; private static final float footer_triangle_height = 10; private viewflow viewflow; private int currentscroll = 0; private titleprovider titleprovider = null; private int currentposition = 0; private paint painttext; private paint paintselected; private path path; private paint paintfooterline; private paint paintfootertriangle; private float footertriangleheight; private float titlepadding; /** * left , right side padding not active view titles. */ private float clippadding; private float footerlineheight; /* these hardcoded in textview */ private static final int sans = 1; private static final int serif = 2; private static final int monospace = 3; private typeface typeface; /** * default constructor */ public titleflowindicator(context context) { super(context); initdraw(text_color, text_size, selected_color, selected_bold, text_size, footer_line_height, footer_color); } /** * contructor used inflater * * @param context * @param attrs */ public titleflowindicator(context context, attributeset attrs) { super(context, attrs); // retrieve styles attributs int typefaceindex = attrs.getattributeintvalue("http://schemas.android.com/apk/res/android", "typeface", 0); int textstyleindex = attrs.getattributeintvalue("http://schemas.android.com/apk/res/android", "textstyle", 0); typedarray = context.obtainstyledattributes(attrs, r.styleable.titleflowindicator); string customtypeface = a.getstring(r.styleable.titleflowindicator_customtypeface); // retrieve colors used view , apply them. int footercolor = a.getcolor(r.styleable.titleflowindicator_footercolor, footer_color); footerlineheight = a.getdimension(r.styleable.titleflowindicator_footerlineheight, footer_line_height); footertriangleheight = a.getdimension(r.styleable.titleflowindicator_footertriangleheight, footer_triangle_height); int selectedcolor = a.getcolor(r.styleable.titleflowindicator_selectedcolor, selected_color); boolean selectedbold = a.getboolean(r.styleable.titleflowindicator_selectedbold, selected_bold); int textcolor = a.getcolor(r.styleable.titleflowindicator_textcolor, text_color); float textsize = a.getdimension(r.styleable.titleflowindicator_textsize, text_size); float selectedsize = a.getdimension(r.styleable.titleflowindicator_selectedsize, textsize); titlepadding = a.getdimension(r.styleable.titleflowindicator_titlepadding, title_padding); clippadding = a.getdimension(r.styleable.titleflowindicator_clippadding, clip_padding); initdraw(textcolor, textsize, selectedcolor, selectedbold, selectedsize, footerlineheight, footercolor); if (customtypeface != null) typeface = typeface.createfromasset(context.getassets(), customtypeface); else typeface = gettypefacebyindex(typefaceindex); typeface = typeface.create(typeface, textstyleindex); } /** * initialize draw objects */ private void initdraw(int textcolor, float textsize, int selectedcolor, boolean selectedbold, float selectedsize, float footerlineheight, int footercolor) { painttext = new paint(); painttext.setcolor(textcolor); painttext.settextsize(textsize); painttext.setantialias(true); paintselected = new paint(); paintselected.setcolor(selectedcolor); paintselected.settextsize(selectedsize); paintselected.setfakeboldtext(selectedbold); paintselected.setantialias(true); paintfooterline = new paint(); paintfooterline.setstyle(paint.style.fill_and_stroke); paintfooterline.setstrokewidth(footerlineheight); paintfooterline.setcolor(footercolor); paintfootertriangle = new paint(); paintfootertriangle.setstyle(paint.style.fill_and_stroke); paintfootertriangle.setcolor(footercolor); } /* * (non-javadoc) * * @see android.view.view#ondraw(android.graphics.canvas) */ @override protected void ondraw(canvas canvas) { super.ondraw(canvas); // calculate views bounds arraylist<rect> bounds = calculateallbounds(painttext); // if no value add fake 1 int count = (viewflow != null && viewflow.getadapter() != null) ? viewflow.getadapter().getcount() : 1; // verify if current view must clipped screen rect curviewbound = bounds.get(currentposition); int curviewwidth = curviewbound.right - curviewbound.left; if (curviewbound.left < 0) { // try clip screen (left side) clipviewontheleft(curviewbound, curviewwidth); } if (curviewbound.right > getleft() + getwidth()) { // try clip screen (right side) clipviewontheright(curviewbound, curviewwidth); } // left views starting current position if (currentposition > 0) { (int iloop = currentposition - 1; iloop >= 0; iloop--) { rect bound = bounds.get(iloop); int w = bound.right - bound.left; // si left side outside screen if (bound.left < 0) { // try clip screen (left side) clipviewontheleft(bound, w); // except if there's intersection right view if (iloop < count - 1 && currentposition != iloop) { rect rightbound = bounds.get(iloop + 1); // intersection if (bound.right + title_padding > rightbound.left) { bound.left = rightbound.left - (w + (int) titlepadding); } } } } } // right views starting current position if (currentposition < count - 1) { (int iloop = currentposition + 1; iloop < count; iloop++) { rect bound = bounds.get(iloop); int w = bound.right - bound.left; // if right side outside screen if (bound.right > getleft() + getwidth()) { // try clip screen (right side) clipviewontheright(bound, w); // except if there's intersection left view if (iloop > 0 && currentposition != iloop) { rect leftbound = bounds.get(iloop - 1); // intersection if (bound.left - title_padding < leftbound.right) { bound.left = leftbound.right + (int) titlepadding; } } } } } // draw views (int iloop = 0; iloop < count; iloop++) { // title string title = gettitle(iloop); rect bound = bounds.get(iloop); // if 1 side visible if ((bound.left > getleft() && bound.left < getleft() + getwidth()) || (bound.right > getleft() && bound.right < getleft() + getwidth())) { paint paint = painttext; // change color title closed center int middle = (bound.left + bound.right) / 2; if (math.abs(middle - (getwidth() / 2)) < 20) { paint = paintselected; } paint.settypeface(typeface); canvas.drawtext(title, bound.left, bound.bottom, paint); } } // draw footer line path = new path(); int coordy = getheight() - 1; coordy -= (footerlineheight % 2 == 1) ? footerlineheight / 2 : footerlineheight / 2 - 1; path.moveto(0, coordy); path.lineto(getwidth(), coordy); path.close(); canvas.drawpath(path, paintfooterline); // draw footer triangle path = new path(); path.moveto(getwidth() / 2, getheight() - footerlineheight - footertriangleheight); path.lineto(getwidth() / 2 + footertriangleheight, getheight() - footerlineheight); path.lineto(getwidth() / 2 - footertriangleheight, getheight() - footerlineheight); path.close(); canvas.drawpath(path, paintfootertriangle); } /** * set bounds right textview including clip padding. * * @param curviewbound * current bounds. * @param curviewwidth * width of view. */ private void clipviewontheright(rect curviewbound, int curviewwidth) { curviewbound.right = getleft() + getwidth() - (int) clippadding; curviewbound.left = curviewbound.right - curviewwidth; } /** * set bounds left textview including clip padding. * * @param curviewbound * current bounds. * @param curviewwidth * width of view. */ private void clipviewontheleft(rect curviewbound, int curviewwidth) { curviewbound.left = 0 + (int) clippadding; curviewbound.right = curviewwidth; } /** * calculate views bounds , scroll them according current index * * @param paint * @param //currentindex * @return */ private arraylist<rect> calculateallbounds(paint paint) { arraylist<rect> list = new arraylist<rect>(); // each views (if no values add fake one) int count = (viewflow != null && viewflow.getadapter() != null) ? viewflow.getadapter().getcount() : 1; (int iloop = 0; iloop < count; iloop++) { rect bounds = calcbounds(iloop, paint); int w = (bounds.right - bounds.left); int h = (bounds.bottom - bounds.top); bounds.left = (getwidth() / 2) - (w / 2) - currentscroll + (iloop * getwidth()); bounds.right = bounds.left + w; bounds.top = 0; bounds.bottom = h; list.add(bounds); } return list; } /** * calculate bounds view's title * * @param index * @param paint * @return */ private rect calcbounds(int index, paint paint) { // title string title = gettitle(index); // calculate text bounds rect bounds = new rect(); bounds.right = (int) paint.measuretext(title); bounds.bottom = (int) (paint.descent() - paint.ascent()); return bounds; } /** * returns title * * @param pos * @return */ private string gettitle(int pos) { // set default title string title = "title " + pos; // if titleprovider exist if (titleprovider != null) { title = titleprovider.gettitle(pos); } return title; } /* * (non-javadoc) * * @see org.taptwo.android.widget.flowindicator#onscrolled(int, int, int, * int) */ @override public void onscrolled(int h, int v, int oldh, int oldv) { currentscroll = h; invalidate(); } /* * (non-javadoc) * * @see * org.taptwo.android.widget.viewflow.viewswitchlistener#onswitched(android * .view.view, int) */ @override public void onswitched(view view, int position) { currentposition = position; invalidate(); } /* * (non-javadoc) * * @see * org.taptwo.android.widget.flowindicator#setviewflow(org.taptwo.android * .widget.viewflow) */ @override public void setviewflow(viewflow view) { viewflow = view; currentposition = view.getselecteditemposition(); invalidate(); } /** * set title provider * * @param provider */ public void settitleprovider(titleprovider provider) { titleprovider = provider; } /* * (non-javadoc) * * @see android.view.view#onmeasure(int, int) */ @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { setmeasureddimension(measurewidth(widthmeasurespec), measureheight(heightmeasurespec)); } /** * determines width of view * * @param measurespec * measurespec packed int * @return width of view, honoring constraints measurespec */ private int measurewidth(int measurespec) { int result = 0; int specmode = measurespec.getmode(measurespec); int specsize = measurespec.getsize(measurespec); if (specmode != measurespec.exactly) { throw new illegalstateexception("viewflow can used in mode."); } result = specsize; return result; } /** * determines height of view * * @param measurespec * measurespec packed int * @return height of view, honoring constraints measurespec */ private int measureheight(int measurespec) { int result = 0; int specmode = measurespec.getmode(measurespec); int specsize = measurespec.getsize(measurespec); // told how big if (specmode == measurespec.exactly) { result = specsize; } // measure height else { // calculate text bounds rect bounds = new rect(); bounds.bottom = (int) (painttext.descent() - painttext.ascent()); result = bounds.bottom - bounds.top + (int) footertriangleheight + (int) footerlineheight + 10; return result; } return result; } private typeface gettypefacebyindex(int typefaceindex) { switch (typefaceindex) { case sans: return typeface.sans_serif; case serif: return typeface.serif; case monospace: return typeface.monospace; default: return typeface.default; } } } the main class :
public class mainactivity extends actionbaractivity { private viewflow viewflow; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); settitle(r.string.title_title); setcontentview(r.layout.title_layout); viewflow = (viewflow) findviewbyid(r.id.viewflow); androidversionadapter adapter = new androidversionadapter(this); viewflow.setadapter(adapter, 3); titleflowindicator indicator = (titleflowindicator) findviewbyid(r.id.viewflowindic); indicator.settitleprovider(adapter); viewflow.setflowindicator(indicator); } } and layout :
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <linearlayout android:layout_width="fill_parent" android:gravity="center_horizontal" android:id="@+id/header_layout" android:orientation="vertical" android:layout_height="wrap_content"> <tabview.fakher.com.tabconfig.titleflowindicator android:id="@+id/viewflowindic" android:layout_height="wrap_content" android:layout_width="fill_parent" app:footerlineheight="2dp" app:customtypeface="fonts/antic.ttf" app:footertriangleheight="10dp" app:textcolor="#ffffffff" app:selectedcolor="#ffffc445" app:footercolor="#ffffc445" app:titlepadding="10dp" app:textsize="11dp" app:selectedsize="12dp" android:layout_margintop="10dip" app:clippadding="5dp"> </tabview.fakher.com.tabconfig.titleflowindicator> </linearlayout> <org.taptwo.android.widget.viewflow android:duplicateparentstate="true" android:id="@+id/viewflow" android:layout_width="fill_parent" android:layout_height="fill_parent"></org.taptwo.android.widget.viewflow> </linearlayout>
try place "assets/" folder within "src/main", not on same level "src/". must find folder in tutorial following.
Comments
Post a Comment