Code Monkey home page Code Monkey logo

calligraphy's Introduction

Calligraphy

Android Arsenal

Custom fonts in Android an OK way.

Are you fed up of Custom Views to set fonts? Or traversing the ViewTree to find TextViews? Yeah me too.

alt text

Getting started

Dependency

Include the dependency Download (.aar) as well as the ViewPump library:

dependencies {
    implementation 'io.github.inflationx:calligraphy3:3.1.1'
    implementation 'io.github.inflationx:viewpump:2.0.3'
}

Add Fonts

Add your custom fonts to assets/. All font definitions are relative to this path.

Assuming that you are using Gradle you should create the assets directory under src/main/ in your project directory if it does not already exist. As it's popular to use multi-project build with Gradle the path is usually app/src/main/assets/, where app is the project name.

You might consider creating a fonts/ subdirectory in the assets directory (as in examples).

Usage

<TextView fontPath="fonts/MyFont.ttf"/>

Note: The missing namespace, this IS intentional.

Installation

Define your default font using CalligraphyConfig, in your Application class in the #onCreate() method and pass it to the CalligraphyInterceptor that you add to your ViewPump builder.

@Override
public void onCreate() {
    super.onCreate();
    ViewPump.init(ViewPump.builder()
        .addInterceptor(new CalligraphyInterceptor(
                new CalligraphyConfig.Builder()
                    .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf")
                    .setFontAttrId(R.attr.fontPath)
                    .build()))
        .build());
    //....
}

Note: You don't need to define CalligraphyConfig but the library will apply no default font and use the default attribute of R.attr.fontPath.

Inject into Context

Wrap the Activity Context:

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
}

You're good to go!

Usage

Custom font per TextView

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fontPath="fonts/Roboto-Bold.ttf"/>

Note: Popular IDE's (Android Studio, IntelliJ) will likely mark this as an error despite being correct. You may want to add tools:ignore="MissingPrefix" to either the View itself or its parent ViewGroup to avoid this. You'll need to add the tools namespace to have access to this "ignore" attribute. xmlns:tools=" http://schemas.android.com/tools". See https://code.google.com/p/android/issues/detail?id=65176.

Custom font in TextAppearance

<style name="TextAppearance.FontPath" parent="android:TextAppearance">
    <!-- Custom Attr-->
    <item name="fontPath">fonts/RobotoCondensed-Regular.ttf</item>
</style>
<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="@style/TextAppearance.FontPath"/>

Custom font in Styles

<style name="TextViewCustomFont">
    <item name="fontPath">fonts/RobotoCondensed-Regular.ttf</item>
</style>

Custom font defined in Theme

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:textViewStyle">@style/AppTheme.Widget.TextView</item>
</style>

<style name="AppTheme.Widget"/>

<style name="AppTheme.Widget.TextView" parent="android:Widget.Holo.Light.TextView">
    <item name="fontPath">fonts/Roboto-ThinItalic.ttf</item>
</style>

FAQ

Font Resolution

The CalligraphyFactory looks for the font in a pretty specific order, for the most part it's very similar to how the Android framework resolves attributes.

  1. View xml - attr defined here will always take priority.
  2. Style xml - attr defined here is checked next.
  3. TextAppearance xml - attr is checked next, the only caveat to this is IF you have a font defined in the Style and a TextAttribute defined in the View the Style attribute is picked first!
  4. Theme - if defined this is used.
  5. Default - if defined in the CalligraphyConfig this is used of none of the above are found OR if one of the above returns an invalid font.

Why not piggyback off of fontFamily attribute?

We originally did, but it conflicted with users wanting to actually use that attribute, you now have to define a custom attribute.

Why no jar?

We needed to ship a custom ID with Calligraphy to improve the Font Injection flow. This unfortunately means that is has to be an aar. But you're using Gradle now anyway right?

Multiple Typeface's per TextView / Spannables

It is possible to use multiple Typefaces inside a TextView, this isn't new concept to Android.

This could be achieved using something like the following code.

SpannableStringBuilder sBuilder = new SpannableStringBuilder();
sBuilder.append("Hello!") // Bold this
        .append("I use Calligraphy"); // Default TextView font.
// Create the Typeface you want to apply to certain text
CalligraphyTypefaceSpan typefaceSpan = new CalligraphyTypefaceSpan(TypefaceUtils.load(getAssets(), "fonts/Roboto-Bold.ttf"));
// Apply typeface to the Spannable 0 - 6 "Hello!" This can of course by dynamic.
sBuilder.setSpan(typefaceSpan, 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
setText(sBuilder, TextView.BufferType.SPANNABLE);

Of course this is just an example. Your mileage may vary.

Exceptions / Pitfalls

To our knowledge (try: grep -r -e "void set[^(]*(Typeface " <android source dir>) there are two standard Android widgets that have multiple methods to set typefaces. They are:

  • android.support.v7.widget.SwitchCompat
  • android.widget.Switch

Both have a method called setSwitchTypeface that sets the typeface within the switch (e.g. on/off, yes/no). SetTypeface sets the typeface of the label. You will need to create your own subclass that overrides setTypeface and calls both super.setTypeface and super.setSwitchTypeface.

Collaborators

Note

This library was created because it is currently not possible to declare a custom font in XML files in Android.

If you feel this should be possible to do, please star this issue on the official Android bug tracker.

Licence

Copyright 2013 Christopher Jenkins

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Badge

calligraphy's People

Contributors

barbosa avatar bod avatar bryant1410 avatar chrisjenx avatar cs-victor-nascimento avatar dlew avatar ened avatar fingertricks avatar jbarr21 avatar kibotu avatar libtastic avatar loeschg avatar loganj avatar manish05 avatar manuelpeinado avatar marcomirisola avatar matthewmichihara avatar mluedke2 avatar nsk-mironov avatar ryanmeador avatar scottyab avatar shaunidiot avatar smuldr avatar taxomania avatar ukeller avatar veinhorn avatar wasabeef avatar wieczorek1990 avatar zacsweers avatar zhougongzaishi 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

calligraphy's Issues

crash on android Q

hi calligraphy crash on android Q please check it
this part of code make crash

 @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
    }

Unresolved reference: fontPath

Hi , i get this error --> The R.attr.fontPath not resolve. for this line --> setFontAttrId(R.attr.fontPath)

ViewPump.init(
ViewPump.builder()
.addInterceptor(
CalligraphyInterceptor(
CalligraphyConfig.Builder()
.setDefaultFontPath(FONTS_ASSET_PATH + FONT_NAME_REGULAR)
.setFontAttrId(R.attr.fontPath)
.build()
)
)
.build()

Library using implementation 'io.github.inflationx:calligraphy3:3.1.1'

crash on Android Q

I test the library targeting Android Q
I have a crash. Seems related to reflection
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference at io.github.inflationx.viewpump.ReflectionUtils.getValue(ReflectionUtils.java:25) at io.github.inflationx.viewpump.ViewPumpLayoutInflater.createCustomViewInternal(ViewPumpLayoutInflater.java:196) at io.github.inflationx.viewpump.ViewPumpLayoutInflater.access$000(ViewPumpLayoutInflater.java:14) at io.github.inflationx.viewpump.ViewPumpLayoutInflater$PrivateWrapperFactory2ViewCreator.onCreateView(ViewPumpLayoutInflater.java:405) at io.github.inflationx.viewpump.FallbackViewCreationInterceptor.intercept(FallbackViewCreationInterceptor.java:11) at io.github.inflationx.viewpump.InterceptorChain.proceed(InterceptorChain.java:37) at io.github.inflationx.calligraphy3.CalligraphyInterceptor.intercept(CalligraphyInterceptor.java:18) at io.github.inflationx.viewpump.InterceptorChain.proceed(InterceptorChain.java:37) at io.github.inflationx.viewpump.ViewPump.inflate(ViewPump.java:49) at io.github.inflationx.viewpump.ViewPumpLayoutInflater$PrivateWrapperFactory2.onCreateView(ViewPumpLayoutInflater.java:385) at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:235)

Change Default font at run time

I have two types of fonts in my app. And i want to apply one font as default till user registration process and after that i want to apply other font as default , please suggest this.

Crash

I download your demo,targetSdkVersion 28:can run.When i change to 29,not working.My app is adapter Android 10.

fontPath attribute not working with DialogFragment

Hi,
fontPath attribute is not working with any type of DialogFragment.
I am using BottomSheetDialogFragment and in its layout i am defining the fontPath attribute just like i do for normal activities and fragments but the font is not working.

My configuration is correct because i am using it across the app and it works. It only does not work for Dialog Fragments.
Please help to resolve this

Calligraphy crashes on Android P when trying expand WebView Popup list.

Calligraphy crashes on Android P when trying expand WebView PopUp list. It seems to be Samsung specific crash. Reproduction is 100%. It does not reproduce with Pixel (Android 9)
With removed Calligraphy from project, WebView displays properly.

Affected device: Samsung Galaxy Tab A 10.1 2019 32GB LTE SM-T515 (SM-T515NZKDXEO)
OS: Android 9
com.android.chrome: 74.0.3729.157 (code 372915702)

minSdkVersion: 19
targetSdkVersion: 28
io.github.inflationx:calligraphy: 3:3.1
io.github.inflationx:viewpump: 2.0.2

StackTrace:

2019-05-17 11:53:29.836 W/System.err: android.view.InflateException: Binary XML file line #32: Binary XML file line #32: Error inflating class TextView
2019-05-17 11:53:29.836 W/System.err: Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class TextView
2019-05-17 11:53:29.841 W/System.err: Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x20b017c
2019-05-17 11:53:29.841 W/System.err:     at android.content.res.ResourcesImpl.getResourceEntryName(ResourcesImpl.java:291)
2019-05-17 11:53:29.841 W/System.err:     at android.content.res.Resources.getResourceEntryName(Resources.java:2017)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.calligraphy3.Calligraphy.matchesResourceIdName(Calligraphy.java:94)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.calligraphy3.Calligraphy.isActionBarTitle(Calligraphy.java:57)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.calligraphy3.Calligraphy.getStyleForTextView(Calligraphy.java:33)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.calligraphy3.Calligraphy.onViewCreatedInternal(Calligraphy.java:139)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.calligraphy3.Calligraphy.onViewCreated(Calligraphy.java:117)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.calligraphy3.CalligraphyInterceptor.intercept(CalligraphyInterceptor.java:19)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.viewpump.internal.-InterceptorChain.proceed(-InterceptorChain.kt:30)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.viewpump.ViewPump.inflate(ViewPump.kt:36)
2019-05-17 11:53:29.841 W/System.err:     at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater$WrapperFactory2.onCreateView(-ViewPumpLayoutInflater.kt:350)
2019-05-17 11:53:29.841 W/System.err:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:811)
2019-05-17 11:53:29.842 W/System.err:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
2019-05-17 11:53:29.842 W/System.err:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:902)
2019-05-17 11:53:29.842 W/System.err:     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:863)
2019-05-17 11:53:29.842 W/System.err:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:905)
2019-05-17 11:53:29.842 W/System.err:     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:863)
2019-05-17 11:53:29.842 W/System.err:     at android.view.LayoutInflater.inflate(LayoutInflater.java:554)
2019-05-17 11:53:29.842 W/System.err:     at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.kt:53)
2019-05-17 11:53:29.842 W/System.err:     at android.view.LayoutInflater.inflate(LayoutInflater.java:461)
2019-05-17 11:53:29.842 W/System.err:     at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.kt:44)
2019-05-17 11:53:29.842 W/System.err:     at android.view.LayoutInflater.inflate(LayoutInflater.java:383)
2019-05-17 11:53:29.842 W/System.err:     at cJL.getView(PG:19)
2019-05-17 11:53:29.842 W/System.err:     at android.widget.AbsListView.obtainView(AbsListView.java:3219)
2019-05-17 11:53:29.842 W/System.err:     at android.widget.ListView.onMeasure(ListView.java:1326)
2019-05-17 11:53:29.842 W/System.err:     at android.view.View.measure(View.java:24954)
2019-05-17 11:53:29.842 W/System.err:     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7134)
2019-05-17 11:53:29.842 W/System.err:     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
2019-05-17 11:53:29.842 W/System.err:     at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
2019-05-17 11:53:29.842 W/System.err:     at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
2019-05-17 11:53:29.842 W/System.err:     at android.view.View.measure(View.java:24954)
2019-05-17 11:53:29.842 W/System.err:     at cMB.d(PG:53)
2019-05-17 11:53:29.843 W/System.err:     at cJO.a(PG:8)
2019-05-17 11:53:29.843 W/System.err:     at cwX.<init>(PG:11)
2019-05-17 11:53:29.843 W/System.err:     at org.chromium.content.browser.input.SelectPopup.show(PG:40)
2019-05-17 11:53:29.843 W/System.err:     at android.os.MessageQueue.nativePollOnce(Native Method)
2019-05-17 11:53:29.843 W/System.err:     at android.os.MessageQueue.next(MessageQueue.java:326)
2019-05-17 11:53:29.843 W/System.err:     at android.os.Looper.loop(Looper.java:181)
2019-05-17 11:53:29.843 W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7072)
2019-05-17 11:53:29.843 W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2019-05-17 11:53:29.843 W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
2019-05-17 11:53:29.843 W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
2019-05-17 11:53:29.847 E/WifiConnectivityMonitor: msg.arg1 != mRssiFetchToken
2019-05-17 11:53:29.854 A/chromium: [FATAL:jni_android.cc(249)] Please include Java exception stack in crash report
2019-05-17 11:53:29.856 A/libc: Fatal signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0xe6735000 in tid 10822 (roid.production), pid 10822 (roid.production)
2019-05-17 11:53:29.938 I/crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
2019-05-17 11:53:29.942 I//system/bin/tombstoned: received crash request for pid 10822
2019-05-17 11:53:29.944 I/crash_dump32: performing dump of process 10822 (target tid = 10822)
2019-05-17 11:53:29.965 A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2019-05-17 11:53:29.965 A/DEBUG: Build fingerprint: 'samsung/gta3xleea/gta3xl:9/PPR1.180610.011/T515XXU1ASCK:user/release-keys'
2019-05-17 11:53:29.965 A/DEBUG: Revision: '4'
2019-05-17 11:53:29.965 A/DEBUG: ABI: 'arm'
2019-05-17 11:53:29.965 A/DEBUG: signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0xe6735000
2019-05-17 11:53:29.965 A/DEBUG: Abort message: '[FATAL:jni_android.cc(249)] Please include Java exception stack in crash report
    '
2019-05-17 11:53:29.965 A/DEBUG:     r0  00000000  r1  c88e12a0  r2  00000400  r3  00000000
2019-05-17 11:53:29.965 A/DEBUG:     r4  ffdc3108  r5  d0ee14d8  r6  e70683c8  r7  ffdc30ec
2019-05-17 11:53:29.965 A/DEBUG:     r8  e706dd94  r9  ffdc3544  r10 ffdc3540  r11 ffdc353c
2019-05-17 11:53:29.965 A/DEBUG:     ip  ffdc310c  sp  ffdc30d8  lr  cf8f32d1  pc  cf8f33ba
2019-05-17 11:53:30.054 A/DEBUG: backtrace:
2019-05-17 11:53:30.054 A/DEBUG:     #00 pc 023003ba  /data/app/com.android.chrome-1HS2RCE7TlSpdPbYl-VZLg==/base.apk (offset 0x1ee5000)

Theme level styling not working for me

Hey, this might not be a library issue, but most probably mine.

I've set the fontAttr like this

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
       ...
        <item name="materialButtonStyle">@style/CustomButtonStyle</item>
    </style>

    <style name="CustomButtonStyle" parent="Widget.MaterialComponents.Button.OutlinedButton">
        <item name="fontPath">fonts/GoogleSans-Bold.ttf</item>
        <item name="android:textSize">50sp</item>
    </style>

but the font's not getting changed for the button, (textSize attr works).
(Note: If i set the fontPath attr directly to the widget,it works. but i want to do it via style.xml)
What am i doing wrong?

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.google.firebase.iid.FirebaseInstanceIdReceiver

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassCastException: io.github.inflationx.viewpump.ViewPumpContextWrapper cannot be cast to android.app.ContextImpl

The above message appears and closes the application when the application running in the device for the first time.
Keep appearing once updated the code with the line under my custom application class

override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(ViewPumpContextWrapper.wrap(base!!))
    }

As per the documentation its mandatory to implement the above mention code to load or inject the custom font.

Toolbar's subtitle is cleared if subtitle set programmatically

I have a toolbar whose subtitle is set programmatically based on arguments supplied to the fragment. If I use Calligraphy, the subtitle is cleared after it is set. The culprit is Calligraphy.

Calligraphy sets a ToolbarLayoutListener whenever a layout is inflated that contained a Toolbar. When this listener is registered, it immediately takes a snapshot of the value of the subtitle. On global layout, it then restores the value of the subtitle to the value it snapshotted. The issue is, if I set the subtitle of the Toolbar between these events (eg. in onViewCreated()), then that value is discarded.

I'm not certain why Calligraphy needs to snapshot the subtitle but this behavior is unintuitive and the only fix I can think of is registering my own GlobalLayoutListener and setting the subtitle after Calligraphy is done restoring the snapshotted subtitle.

Code where caligraphy registers the global layout listener: https://github.com/InflationX/Calligraphy/blob/master/calligraphy/src/main/java/io/github/inflationx/calligraphy3/Calligraphy.java#L158
Code where caligraphy is snapshotting the value of the subtitle: https://github.com/InflationX/Calligraphy/blob/master/calligraphy/src/main/java/io/github/inflationx/calligraphy3/Calligraphy.java#L230
Code where caligraphy restores the value of the subtitle: https://github.com/InflationX/Calligraphy/blob/master/calligraphy/src/main/java/io/github/inflationx/calligraphy3/Calligraphy.java#L253

Jumping toolbar titles

I faced with a problem that is similar to this one. I have separate toolbar on each fragment and after transition toolbar's title is oddly jumping. If I set toolbar's subtitle to null the problem is gone (as in that old issue).

Font not getting applied to PopupMenus or the BottomNavigationView

Hi, I'm currently experiencing an issue in which the font I've setup to be used everywhere in the app is not working for the PopupMenus or the BottomNavigationView.

I've also tried specifying the fontPath in the items.xml files but it didn't help.

Any ideas?

Thank you!

NoClassDefFoundError: Failed resolution of: Landroidx/core/os/BuildCompat;

Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.os.BuildCompat" on path: DexPathList.
Suppressed: java.io.IOException: No original dex files found for dex location

About My App:-
-App in java language
-not using android x
-App testing in Android 8.0 (oreo) - SDK (26)

I get android.content.res.Resources$NotFoundException. How can I solve this?

I use version 3.1.1.

Caused by android.content.res.Resources$NotFoundException
Unable to find resource ID #0x7f090543
android.content.res.ResourcesImpl.getResourceEntryName (ResourcesImpl.java:289)
android.content.res.Resources.getResourceEntryName (Resources.java:1996)
io.github.inflationx.calligraphy3.Calligraphy.matchesResourceIdName (Calligraphy.java:94)
io.github.inflationx.calligraphy3.Calligraphy.isActionBarTitle (Calligraphy.java:57)
io.github.inflationx.calligraphy3.Calligraphy.getStyleForTextView (Calligraphy.java:33)
io.github.inflationx.calligraphy3.Calligraphy.onViewCreatedInternal (Calligraphy.java:139)
io.github.inflationx.calligraphy3.Calligraphy.onViewCreated (Calligraphy.java:117)
io.github.inflationx.calligraphy3.CalligraphyInterceptor.intercept (CalligraphyInterceptor.java:19)
io.github.inflationx.viewpump.internal.-InterceptorChain.proceed (-InterceptorChain.java:30)
io.github.inflationx.viewpump.ViewPump.inflate (ViewPump.java:36)
io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater$WrapperFactory2.onCreateView (-ViewPumpLayoutInflater.java:358)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:772)

font for whole app not working

hello, I've gone over the docs and tried everything but the fonts still don't show.
This is what I've done so far:

  • Copied and pasted the fonts to assets/fonts (mind you, if I double click the ttf in Android Studio, it says "Unable to open font barlowregular.ttf")

  • Application class -> added
    ViewPump.init(ViewPump.builder()
    .addInterceptor(new CalligraphyInterceptor(
    new CalligraphyConfig.Builder()
    .setDefaultFontPath("fonts/barlowregular.ttf")
    .setFontAttrId(R.attr.fontPath)
    .build()))
    .build());

  • Added to every activity -> @OverRide
    protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
    }

thanks for any help!

about CalligraphyConfig.get()

before:CalligraphyUtils.applyFontToTextView(root.getContext(), textView, CalligraphyConfig.get(), null);
now:remove this mothed;
how can i use?

Can't set font on view via theme attr

I get the following log when I set a fontPath pointing to a theme attr

Error:

Calligraphy  W  Can't create asset from ?2130968815. Make sure you have passed in the correct path and file name.
                         W  java.lang.RuntimeException: Font asset not found ?2130968815
                         W      at android.graphics.Typeface.createFromAsset(Typeface.java:839)
                         W      at io.github.inflationx.calligraphy3.TypefaceUtils.load(TypefaceUtils.java:35)

Layout:

<TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ...
        fontPath="?boldFontPath"
        >

androidx.appcompat.widget.FitWindowsLinearLayout

**

How to solve it ...

**

java.lang.RuntimeException: Unable to start activity ComponentInfo{Packge_name.TextEdit(Activity)}: android.view.InflateException: Binary XML file line #17 in Packge_name:layout/abc_screen_simple: Binary XML file line #17 in Packge_name:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout

Caused by: android.view.InflateException: Binary XML file line #17 in Packge_name:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference

setFontAtrrId(R.attr.fontPath) fontPath not resolved

CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/" + getString(R.string.filename_default_font_narrow))
.setFontAttrId(R.attr.fontPath)
.build());
The R.attr.fontPath not resolve.

Library using implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
Support library: versions = [supportLib: "27.1.1"]
Gradle build tool version : classpath 'com.android.tools.build:gradle:3.1.4'

CalligraphyConfig().Builder issue

Hello,

I am upgrading to Calligraphy because my android app is crashing for android 10 and it was related to this library.

I added the two lines for the updated Calligraphy and Viewpump library. and Gradle sync succeeds.

when I add the below code in MyApplication.java,

ViewPump.init(ViewPump.builder()
                .addInterceptor(new CalligraphyInterceptor(
                        new CalligraphyConfig().Builder()
                                .setDefaultFontPath("fonts/HelveticaNeueLTStd_R.otf")
                                .setFontAttrId(R.attr.fontPath)
                                .build()))
                .build());

I get this error:

CalligraphyConfig(io.github.inflationx.calligraphy3.CalligraphyConfig.Builder)' has private access in 'io.github.inflationx.calligraphy3.CalligraphyConfig

How can we config the default font? and what I am doing wrong?

Please help asap! Our App live is keeping a crash from this issue.

Screen Shot 2020-10-01 at 2 29 06 PM

Crash (Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout)

I am facing an issue on Android Q (API 29), getting the following exception when open the app:

java.lang.RuntimeException: Unable to start activity 
     ComponentInfo{com.example.app/com.example.app.MainActivity}: 
     android.view.InflateException: Binary XML file line #17 
     in com.example.app:layout/abc_screen_simple: Binary XML file line #17 
     in com.example.app:layout/abc_screen_simple: 
         Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout

I don't have neither abc_screen_simple layout nor FitWindowsLinearLayout.
I tried many articles related even in old library versions but no luck. I would appreciate if you help with this.

Font not applied to Material Design NavigationView menu items

Hi,
I have an issue similar to what is mentioned in issue #47 where the font I've set to use is not getting applied to the menu items in NavigationView. Just wondering if it's a known problem with Calligraphy as I couldn't see any response in that issue thread or the Exceptions section in the readme. Could you please help me with this?

Thanks,
Arun

Android 9 does not render text

While devices running Android 8 show text in my app properly, all my views are 'empty' when using a device with Android 9.

The Layout Inspector of Android Studio does show the contents under "Text" -> "mText", but not visually in the view. No errors were triggered.

build.gradle:

implementation 'io.github.inflationx:calligraphy3:3.1.1'
implementation 'io.github.inflationx:viewpump:2.0.3'

AndroidManifest.xml application:

android:name=".App"

App.java:

public class App extends Application {
    ...

    @Override
    public void onCreate() {
        ...

        ViewPump.init(ViewPump.builder()
            .addInterceptor(new CalligraphyInterceptor(
                new CalligraphyConfig.Builder()
                    .setDefaultFontPath("fonts/Rubik-Regular.ttf")
                    .setFontAttrId(R.attr.fontPath)
                    .build()))
            .build());

        ...
    }
}

Activity.java:

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(
        ViewPumpContextWrapper.wrap(
                LokaliseContextWrapper.wrap(newBase)
        )
    );
}

And then, all my views containing texts are empty on Android 9.

NPE in ViewPumpContextWrapper for Android Q

For apps targeting Android Q:
ViewPumpContextWrapper.java uses mConstructorArgsproperty in createCustomViewInternal method via reflection. Currently, this causes a NPE in this method:
final Object[] mConstructorArgsArr = (Object[]) ReflectionUtils.getValue(mConstructorArgs, this);

From https://developer.android.com/preview/non-sdk-q:

Landroid/view/LayoutInflater;->mConstructorArgs:[Ljava/lang/Object; # LayoutInflater's mConstructorArgs was being accessed for two reasons: reading and writing the context. When onCreateView() was called, the inflation context was not being passed, so if the developer wanted to get it, they had to read it from mConstructorArgs. When the developer wanted to create a view, with createView(), the developer could not adjust the view's constructor context. New APIs for createView() and onCreateView() were added that take the View Context as an argument.

minSdkVersion: 21
targetSdkVersion: android-Q
io.github.inflationx:calligraphy: 3:3.1
io.github.inflationx:viewpump: 1.0.0

ViewPumpContextWrapper is final

I moved from v2 to v3 today and found that the new context wrapper is a final class. I was extending the old context wrapper to allow for locale changing in my app but now i cannot fulfill my need to allow for custom fonts + locale changes together. Is there any particular reason ViewPumpContextWrapper has to be final?

Toast

not working on toast

Add Support for Google Downloadable Fonts?

Been using calligraphy for a while now. However, theres an issue i would like to share. The only way to use calligraphy is via including your own .ttf files. (afaik ;_; correct me if im wrong) Since, .ttf files can get large for most fonts, they contribute heavily to the overall app size. Therefore, Google downloadable fonts are a much light weight alternative for custom fonts in android now.

It would be great if we could set a google downloadable font as the calligraphy global font. I dont know if this is possible in the current implementation (if at all) but will really appreciate this feature.

android.view.inflateException

at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater$NameAndAttrsViewCreator.onCreateView (-ViewPumpLayoutInflater.java)
at io.github.inflationx.viewpump.internal.-FallbackViewCreationInterceptor.intercept (-FallbackViewCreationInterceptor.java)
at io.github.inflationx.viewpump.internal.-InterceptorChain.a (-InterceptorChain.java)
at io.github.inflationx.calligraphy3.CalligraphyInterceptor.intercept (CalligraphyInterceptor.java)
at io.github.inflationx.viewpump.internal.-InterceptorChain.proceed (-InterceptorChain.java)
at io.github.inflationx.viewpump.ViewPump.inflate (ViewPump.java)

Proguard configuration not working

While enabling the proguard configuration its giving error on calligraphy library. No proguard configuration given for this library.

io.github.inflationx.calligraphy3.Calligraphy: can't find referenced class androidx.appcompat.widget.Toolbar
io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater: can't find referenced class androidx.core.os.BuildCompat
io.github.inflationx.calligraphy3.CalligraphyConfig: can't find referenced class androidx.appcompat.widget.AppCompatCheckedTextView
io.github.inflationx.calligraphy3.CalligraphyConfig: can't find referenced class androidx.appcompat.widget.AppCompatRadioButton

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.