Code Monkey home page Code Monkey logo

johnkil / android-robototextview Goto Github PK

View Code? Open in Web Editor NEW
774.0 42.0 121.0 11.68 MB

Implementation of a TextView and all its direct/indirect subclasses with native support for the Roboto fonts, includes the brand new Roboto Slab fonts.

Home Page: http://johnkil.github.io/Android-RobotoTextView

License: Apache License 2.0

Java 77.98% Groovy 22.02%
android textview font roboto-fonts roboto-mono roboto-slab roboto-condensed typeface material

android-robototextview's Introduction

android-robototextview's People

Contributors

bdbergeron avatar intrications avatar johnkil avatar olegkrikun avatar rovkinmax avatar saik0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-robototextview's Issues

AAPT fails when using both RobotoTextView library and AppCompat library

With appcompat-v7 version 26+, both RobotoTextView and AppCompatTextView attempt to declare

<attr name="fontFamily">

However, for AppCompat its format is "string", whereas for RobotoTextView it's "enum"

Gradle build will fail with something like

/Users/ddennis/project/app/build/intermediates/res/merged/release/values/values.xml:194: error: Attribute "fontFamily" already defined with incompatible format.
/Users/ddennis/project/app/build/intermediates/res/merged/release/values/values.xml:5: Original attribute defined here.

Add support for "smallcaps" typeface

I'm seeing a new fontFamily: sans-serif-smallcaps in my project. I'm guessing this was added in Lollipop.

The font used is a non Roboto font, but I was wondering if it could be added to this library. I'd not prefer using another library just for that font :)

*Update: * The font is CarroisGothicSC-Regular

Use Sub-Pixel Rendering

When you have set the custom font and look at it in the application it usually does not look very nice. That is because there is no sub-pixel renderings.

setup vs set up in RobotoTypefaceUtils

RobotoTypefaceUtils class has two static methods called setup().

Setup is one word when it is a noun or an adjective. It is two words—set up—when it functions as a verb

I suggest a little fix — setUp()

Issue with any version above 2.2.0

Hi!
I've got issues with the lib if using any version above 2.2.0, starting with 2.3.0.
FOA the text in EditText looks like it has gravity top (2.2.0 - everything is ok) and if I tap the editbox the text vanishes like its textcolor becames white on white bg editText but the bigger issue gere - no keyboard appears so I'm unable to enter any text into editText.
Also buttons starts ignoring gravity of its text, so the text label with v 2.2.0 is centered but if I switch to 2.3.0 text appears at left instead.
You could see the diff here - http://prntscr.com/akfos1
The same applies to latest 2.50 version.
I don't use appCompat.v7 in my app but olny support.v4 of 23.1.1 version. However adding appcompat.v7 lib to build.gradle does not change anything. EditText are locked from entering text and almost every TextView/EditText looks like it has gravity top. Every single layout appears broken and looks strange...

Maven dependency as AAR

Thank you for such good library. But I'm sure maven dependency should be:

        <dependency>
            <groupId>com.github.johnkil.android-robototextview</groupId>
            <artifactId>robototextview</artifactId>
            <version>2.2.0</version>
            <type>aar</type>
        </dependency>

Also it requires using xmlns:app="http://schemas.android.com/apk/res-auto" namespace at least. In other case it does not compile.

Add to maven repository

Hi,

Can you add your lib to mave repository so we may add it to Gradle without having to clone your git and compile the lib?

Regards

ProGuard configuration

Hello,

It doesn't seem like RobotoTextView should need any proguard configuration in addition to the default configuration for Android. Can you confirm that this is the case?

Gradle plugin for removing unused fonts

Somthing like this:

apply plugin: 'com.android.application'
apply plugin: 'com.devspark.robototextview.gradle-plugin'

android {
    ....
}

robototextview {
    include 'Roboto-Regular', 'Roboto-Medium'
    // or
    exclude 'RobotoMono'
}

dependencies {
    ...
}

What do you think?

/

/closed old implementation interferred with this project

Exactly how to remove extra font?

I tried to put your code in gradle file but it's not working means not removing font.

So, can you please elaborate how to remove extra font.

Crash Samsung Devices Android 4.1

I have an issue with Samsung devices. On a Galaxy Tab 2 10" with Android 4.1. This exception appear only on Samsung device with Android 4.1.

In my xml layout I'm using RobotoTextView like this :

<com.devspark.robototextview.widget.RobotoTextView
          app:typeface="roboto_regular"
          android:id="@+id/hook2"
          android:layout_width="match_parent"
          android:gravity="start"
          android:layout_height="wrap_content"
          android:textColor="@android:color/white"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="@string/Hook2" />

The application crash at launch, caused by a NumberFormatException: Invalid int: 16.0dip. See logcat below :

 Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.devspark.robototextview.widget.RobotoTextView
            at android.view.LayoutInflater.createView(LayoutInflater.java:613)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.xxx.xxxx.ui.home.PredictiveItemListActivity.onCreate(PredictiveItemListActivity.java:161)
            at android.app.Activity.performCreate(Activity.java:5163)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
            at android.app.ActivityThread.access$600(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4895)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.xxx.xxx.ui.home.PredictiveItemListActivity.onCreate(PredictiveItemListActivity.java:161)
            at android.app.Activity.performCreate(Activity.java:5163)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
            at android.app.ActivityThread.access$600(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4895)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NumberFormatException: Invalid int: "16.0dip"
            at java.lang.Integer.invalidInt(Integer.java:138)
            at java.lang.Integer.parse(Integer.java:375)
            at java.lang.Integer.parseInt(Integer.java:366)
            at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
            at android.content.res.TypedArray.getInt(TypedArray.java:254)
            at android.widget.TextView.<init>(TextView.java:997)
            at android.widget.TextView.<init>(TextView.java:562)
            at com.devspark.robototextview.widget.RobotoTextView.<init>(RobotoTextView.java:59)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.xxx.xxx.ui.home.PredictiveItemListActivity.onCreate(PredictiveItemListActivity.java:161)
            at android.app.Activity.performCreate(Activity.java:5163)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
            at android.app.ActivityThread.access$600(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4895)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
            at dalvik.system.NativeStart.main(Native Method)

Not compiles if compileSdk/targetSdk was set lower than 23

Project can't be compiled if compileSdk/targetSdk was set lower than 23. It happens on 2.4.1 version also. But 2.4.0 version can be compiled successfuly.

So, I'm getting an error message:
...\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.0\res\values-v23\values-v23.xml
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

Crash on Android Lollipop

I have the following error showing up on the layout preview

Exception Details java.lang.NullPointerException   at 
android.content.res.BridgeResources.getAnimation(BridgeResources.java:292)   at 
android.animation.AnimatorInflater.loadStateListAnimator(AnimatorInflater.java:95)   at 
android.view.View.<init>(View.java:4016)   at android.widget.TextView.<init>(TextView.java:629)   at 
android.widget.Button.<init>(Button.java:111)   at android.widget.Button.<init>(Button.java:107)   at 
android.widget.Button.<init>(Button.java:103)   at 
com.devspark.robototextview.widget.RobotoButton.<init>(RobotoButton.java:59)   at 
java.lang.reflect.Constructor.newInstance(Constructor.java:526)   at 
android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:802)   at 
android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)   at 
android.view.LayoutInflater.rInflate(LayoutInflater.java:778)   at 
android.view.LayoutInflater.inflate(LayoutInflater.java:500)   at 
android.view.LayoutInflater.inflate(LayoutInflater.java:381)

This lead to a crash on the Activity.setContentView()

 Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070067 type #0x1d is not valid
        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2603)
        at android.content.res.Resources.getXml(Resources.java:1098)
        at android.transition.TransitionInflater.inflateTransition(TransitionInflater.java:75)
        at com.android.internal.policy.impl.PhoneWindow.getTransition(PhoneWindow.java:3696)
        at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3649)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:367)
        at android.app.Activity.setContentView(Activity.java:2144)

By looking at the code I think it searches for the animation xml added in Lollipop (for ripple effects and touch related animations).
Is there a way to bypass this exception, without having to rewrite the whole layout for v21?

EDIT: After some testing it appears that the library is not the cause of the crash, instead the style I used for the button is:

  style="?android:buttonBarButtonStyle"

The second problem was the android:accentColor in the Material theme being #rrggbb instead of #aarrggbb

Reuse of created typefaces.

You should only run Typeface.createFromAsset() once per font, not once per TextView. After a certain font has been created, hold it in a static variable and reuse it in all other TextViews throughout the app.

Android studio preview

Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in java.lang.RuntimeException: Font asset not found fonts/RobotoSlab-Bold.ttf
    at android.graphics.Typeface.createFromAsset(Typeface.java:190)
    at com.devspark.robototextview.util.RobotoTypefaceManager.createTypeface(RobotoTypefaceManager.java:314)
    at com.devspark.robototextview.util.RobotoTypefaceManager.obtainTypeface(RobotoTypefaceManager.java:45)
    at com.yoavst.timetable.ui.views.NextLessonView.getCalendarView(NextLessonView.java:69)
    at com.yoavst.timetable.ui.views.NextLessonView.init(NextLessonView.java:51)
    at com.yoavst.timetable.ui.views.NextLessonView.initPreview(NextLessonView.java:43)
    at com.yoavst.timetable.ui.views.NextLessonView.<init>(NextLessonView.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:379)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:99)
    at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:401)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:688)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:677)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
    at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:677)
    at com.android.tools.idea.rendering.RenderService.render(RenderService.java:815)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:589)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
    at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:584)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Incompatible with support v26.0.0

Hey there,

Looks like this breaks with 26.0.0 of the support library since they added font support:

screen shot 2017-07-24 at 3 24 53 pm

Probably need to rename the attribute to something else

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.