Closed thekalinga closed 8 years ago
@thekalinga you should not have to add the font to your project. that's already inside the project. icon fonts can't be painted from the preview in AS as far as i know, so you should disable adding the icon in the preview by checking:
if (!isInEditMode()) {
as in the IconicsImageView
https://github.com/mikepenz/Android-Iconics/blob/develop/library-core/src/main/java/com/mikepenz/iconics/view/IconicsImageView.java#L52
to be fair i never used the AS preview :D i paint those xml's in my head. and now with instant run, running the app on a device is really fast :D
This library claims to work with Android Studio. Can you check this once
@thekalinga because it does not use a Path
to draw the icon, but directly uses a canvas. downside of their approach is that they do not offer a contour, etc...
I don't think the preview is really necessary. I will try a few things, perhaps i can get it to work but i can't promise it
Sure. Thanks for your prompt response
@thekalinga and you are sure it fails for you because of the stacktrace you showed and not because it can't resolve the font? i can't get it to read in the typeface. (changed the silent "null" return to throw the excaption inside the font)
I just renamed the font in my assets/fonts/material-design-iconic-font-v2.2.0.ttf
to assets/fonts/material-design-iconic-font-v2.2.0.ttf.bak
& this is the error I get
Asset not found: fonts/material-design-iconic-font-v2.2.0.ttf
If I rename the file back, I get the same exception trace I mentioned in the description.
I use ubuntu 14.04 & my Android studio details are
Android Studio 1.4.1
Build #AI-141.2343393, built on October 15, 2015
JRE: 1.8.0_66-b17 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
Isn't it possible do it like in this post? http://stackoverflow.com/a/35266586/4024146 it looks like working solution without canvas and uses Path assets.
Maybe with step 0 from this lib: https://github.com/code-mc/material-icon-lib#step-0 ?
@mikepenz Any news on this? Using isInEditingMode() "everywhere" in client code is not very user friendly. Isn't there any other solution to mute the exception directly in IconicsDrawable?
The icon already has isInEditingMode()
@Robyer https://github.com/mikepenz/Android-Iconics/blob/develop/iconics-view-library/src/main/java/com/mikepenz/iconics/view/IconicsTextView.java#L48
@mikepenz Your views are using isInEditingMode()
, but I have custom view inside which I programmatically create new instance of IconicsDrawable
and in that case preview shows error.
As possible solution I can see adding new method IconicsDrawable.setInEditingMode(boolean)
, because drawable obviously doesn't have that method itself. So I could set it once during initialization of my custom view, and thus doesn't have to wrap all usages of the drawable in if (isInEditingMode()
.
@Robyer please just add isInEditingMode()
to your custom view as usual. Drawables don't have the inEditingMode
your view is having the bug in the end.
@mikepenz I don't think bug is in my view if exception is thrown when calling sizeDp(...)
on IconicsDrawable
.
This code:
IconicsDrawable drawable = new IconicsDrawable(context, icon); drawable.sizeDp(32);
Causes this exception in preview:
java.awt.geom.IllegalPathStateException: missing initial moveto in path definition at java.awt.geom.Path2D$Double.needRoom(Path2D.java:1192) at java.awt.geom.Path2D.closePath(Path2D.java:1876) at android.graphics.Path_Delegate.close(Path_Delegate.java:810) at android.graphics.Path_Delegate.native_close(Path_Delegate.java:325) at android.graphics.Path.native_close(Path.java) at android.graphics.Path.close(Path.java:495) at com.mikepenz.iconics.IconicsDrawable.onBoundsChange(IconicsDrawable.java:839) at android.graphics.drawable.Drawable.setBounds(Drawable.java:217) at com.mikepenz.iconics.IconicsDrawable.sizePx(IconicsDrawable.java:464) at com.mikepenz.iconics.IconicsDrawable.sizeDp(IconicsDrawable.java:452) (...)
You advises adding isInEditingMode()
in my custom view, but that means not using IconicsDrawable
at all when isEditingMode()
returns true. Which is uncomfortable.
Having something like this IconicsDrawable.setInEditingMode(isInEditingMode());
and ignoring the exceptions internally would be great.
Also I read your comment saying:
because it does not use a Path to draw the icon, but directly uses a canvas. downside of their approach is that they do not offer a contour, etc...
So having ability to force drawing directly to canvas in case of isInEditingMode()
to have working Preview, even without contours etc. would be even better. For example IconicsDrawable.useCompatibilityDrawing(isInEditingMode());
but that's the point of isInEditingMode
disabling all components of your custom view, not working in the editor
@Robyer if you want to add something like IconicsDrawable.setInEditingMode(isInEditingMode());
to the library via a PR I am more than glad to merge it.
@mikepenz I fixed the exception. See https://github.com/mikepenz/Android-Iconics/pull/364
I have added the image to the custom component using
Tho, I am able to see the icon in the actual application, the Android Studio previewer complains that the
font/material-design-iconic-font-v2.2.0.ttf
could not be found. So I added the fontmaterial-design-iconic-font-v2.2.0.ttf
explicitly to myassets/fonts
, along with the gradle dependency. After this change, I get the following exception in the Studio previewerHere is my gradle configuration
and this is how I am plugging the wrapper into activity
Are there steps that I need to follow to make sure that preview works?