Closed ruqqq closed 9 years ago
@ruqqq which app compat lib?
As I am using support-v4:21.0.0
with no problems.
@chrisjenx not sure its the same issue, but for me the default font set through CalligraphyConfig.initDefault(...) is not applied when using appcompat-v7:21.0.0
@justinelsberry OK. I'll double check tomorrow.
@chrisjenx appcompat-v7:21.0.0 library. nothing to do with support library I suppose.
@ruqqq @justinelsberry I've updated the Sample to v21
and everything seems to be working for me. Am I missing something obvious?
@ruqqq @justinelsberry Sorry just seen it, yes you're right
@chrisjenx it does appear to load the font when the layout was inflated manually. e.g. from an adapter.
@justinelsberry yeah I saw that, I ignores the default font very odd.
@justinelsberry @ruqqq Further investigation shows that its just the ActionBar/Toolbar not getting set correctly. I see TextView
's inside layouts getting set correctly by the initDefault()
.
Can you both confirm?
After upgrading build tools to 21.0.1, compileSdkVersion to 21 and all support libraries to 21.+ I can confirm that setting the font in the Application
class' onCreate
using CalligraphyConfig.initDefault()
and manually using fontPath="font.ttf"
in xml doesn't work.
Btw: Calligraphy version 1.1.+ is added as a dependency
@ChrisMCMine try 1.2.0. I've already fixed this.
@chrisjenx Hi Chris, I'm not able to make it work. Have updated to 1.2.0 already.
Have the main theme derived from AppCompat as follows:
<style name="AppTheme"
parent="Theme.AppCompat.Light">
<item name="android:textAppearance">@style/AppTheme.TextAppearance</item>
</style>
Have my TextAppearance as follows:
<style name="AppTheme.TextAppearance" parent="android:TextAppearance">
<item name="android:textStyle">normal</item>
<!-- Custom Attr-->
<item name="fontPath">Roboto-Light.ttf</item>
</style>
<style name="AppTheme.TextAppearance.Bold" parent="AppTheme.TextAppearance">
<!-- Custom Attr-->
<item name="fontPath">Roboto-Medium.ttf</item>
<item name="android:textStyle">bold</item>
</style>
Yeah that won't work. Text Appearance applied to the theme is never looked at, you need to either apply the TextAppearance to the View xml or the Style xml, I should probably make that clearer.
@chrisjenx This style was working fine ( even in L Preview), support-appcompat is causing this?.
And yes, I'm applying the AppTheme.TextAppearance to each TextView's style.
Oh really, that impl was never tested... mmm OK. I'll check then.
On 20 October 2014 18:02, ngenhit notifications@github.com wrote:
@chrisjenx https://github.com/chrisjenx This style was working fine ( even in L Preview), support-appcompat is causing this?.
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/84#issuecomment-59798316 .
@ngenhit so this has only stopped it working on 1.2.0?
@chrisjenx Just tested the code again. TextAppearance method is working. Everything's working fine except for Views in fragment.
Should i be injecting into each fragment?.
Edit:
Solved it when i used getActivity().getLayoutInflater() instead of the param1 (inflater) of the onCreateView() in the fragment. Is this the correct approach?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return mInflater.inflate(R.layout.fragment_overview_summary, container, false);
}
Same issue here and still present with 1.2.0. The key issue is the v21 AppCompat library. The issue only occurs in FragmentActivity sub classes.
OK thanks for specifying that.
Question does the sample app work for you guys? On 21 Oct 2014 04:48, "Sebastian Roth" notifications@github.com wrote:
Same issue here and still present with 1.2.0. The key issue is the v21 AppCompat library. The issue only occurs in FragmentActivity sub classes.
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/84#issuecomment-59875251 .
@ngenhit Ohh really? That is interesting.
But that makes no sense. The sample as you can see for yourself is:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
And that works fine.
It also makes no difference between using the inflater
param or using getActivity().getLayoutInflater()
works both ways.
Someone is going to need to give me a full example.
Just chiming in, I am not using the appCompact support lib but I am using FragmentActivity from the supportv4 lib. It does not work for me anymore. Was working before I updated to v21.
@mandeepsingh-ck I'm assuming you mean support-v4:21?
Yes. I am compiling with Google Apis 21, support-v4:21
@chrisjenx the same problem here and I agree with @ngenhit ,the font is not applied to textviews inside fragments but the ToolBar and actionbar are doing fine
Ok great thanks guys for all the extra info. I'll see if I can get to the bottom of this today. On 22 Oct 2014 09:57, "LloydBlv" notifications@github.com wrote:
@chrisjenx https://github.com/chrisjenx the same problem here,the font is not applied to textviews inside fragments but the ToolBar and actionbar are doing fine
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/84#issuecomment-60055028 .
@chrisjenx Thanks, the fontPath="fonts/yekan.ttf" does not work in fragments by the way
Yeah which is annoying as it works in the demo. I've been trying to reproduce it but struggling. How do you guys instantiate your fragments? XML or from code? On 22 Oct 2014 10:23, "LloydBlv" notifications@github.com wrote:
@chrisjenx https://github.com/chrisjenx Thanks, the fontPath="fonts/yekan.ttf" does not work in fragments by the way
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/84#issuecomment-60057886 .
@chrisjenx Sorry for the delayed response. Let me just take your sample code and try to make the changes ( which I think is breaking the lib ). Will get back to you in couple of minutes.
@chrisjenx I do it in the code using the lines below:
public static MainFragment newInstance(String serverResponse){ MainFragment mainFragment = new MainFragment_(); Bundle bundle = new Bundle(); bundle.putString(SplashActivity.SERVER_PRE_RESPONSE,serverResponse); mainFragment.setArguments(bundle); return mainFragment; }
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'uk.co.chrisjenx:calligraphy:1.2.0'
Does androidAnnotations has anything to do with this?
Possibly are you able to try without them I.e. break the example? On 22 Oct 2014 11:12, "LloydBlv" notifications@github.com wrote:
@chrisjenx https://github.com/chrisjenx I do it in the code using the lines below: public static MainFragment newInstance(String serverResponse){ MainFragment mainFragment = new MainFragment_(); Bundle bundle = new Bundle(); bundle.putString(SplashActivity.SERVER_PRE_RESPONSE,serverResponse); mainFragment.setArguments(bundle); return mainFragment; }
compile 'com.android.support:appcompat-v7:21.0.0' compile 'uk.co.chrisjenx:calligraphy:1.2.0'
Does androidAnnotations has anything to do with this?
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/84#issuecomment-60063310 .
@chrisjenx I just ran the sample application. lib is failing to apply fonts when the fragment is instantiated dynamically through:
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance())
.commit();
However as a workaround, if I apply the layout inflater from getActivity() in the fragment, it works fine. This works out
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
return getActivity().getLayoutInflater().inflate(R.layout.fragment_main, container, false);
}
This does not:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
OK managed to replicate. Investigating.
Well utter failure in the support lib, there is no source yet (Not until Lollipop reaches ASOP). So I have no code for reference.
It seems to clone the LayoutInflater
in the FragmentManager
for the Fragments
(But I can't confirm that). Thusly it sets a different context (and factory) over CalligraphyFactory
.
Looks like getActivity().getLayoutInflater()
is the way to fix it for now. FYI. thats the same object that onCreateView
gives you anyway.
For whatever reason they have changed this (I think for Transitions).
I can only suggest the work around for now. Apologies about that.
So we can't expect a fix until the release of the Lollipop source code? 😕
I've been talking to @chrisbanes about it. Unless he has a suggestion before then, its very difficult as am guessing from errors what is going on.
The source code for the support lib could be found in $ANDROID_HOME/extras/android/m2repository/com/android/support/support-v4/21.0.0/support-v4-21.0.0-sources.jar
FragmentManager
at line 920 & line 947 will create the Fragment
view like this:
f.mView = f.performCreateView(f.getLayoutInflater(
f.mSavedFragmentState), null, f.mSavedFragmentState);
When you then check out the default implementation of Fragment#getLayoutInflater(Bundle savedInstanceState)
, you see this:
/**
* @hide Hack so that DialogFragment can make its Dialog before creating
* its views, and the view construction can use the dialog's context for
* inflation. Maybe this should become a public API. Note sure.
*/
public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
LayoutInflater result = mActivity.getLayoutInflater().cloneInContext(mActivity);
getChildFragmentManager(); // Init if needed; use raw implementation below.
result.setFactory(mChildFragmentManager.getLayoutInflaterFactory());
return result;
}
The "cloneInContext" method perhaps doesn't honour the ContextWrapper as it's used by Calligraphy?
Anyhow, once I overwrite the getLayoutInflater
method in my Fragment like this:
@Override
public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
return getActivity().getLayoutInflater();
}
Then it can work, Calligraphy is back on.
Maybe it helps us to find a clean solution. I'm still testing for side effects.
Ahh nice one.
I was trying to override setFactory but of course if they are cloning then it won't have our factory set on it primarily.
I might be able to do something to work around this now.
Not sure the reason they decided to do this change now. I'll grab one of the google guys at Droidcon see if they know more about it. On 29 Oct 2014 03:06, "Sebastian Roth" notifications@github.com wrote:
The source code for the support lib could be found in $ANDROID_HOME/extras/android/m2repository/com/android/support/support-v4/21.0.0/support-v4-21.0.0-sources.jar
FragmentManager at line 920 & line 947 will create the Fragment view like this:
f.mView = f.performCreateView(f.getLayoutInflater( f.mSavedFragmentState), null, f.mSavedFragmentState);
When you then check out the default implementation of Fragment#getLayoutInflater(Bundle savedInstanceState), you see this:
/** * @hide Hack so that DialogFragment can make its Dialog before creating * its views, and the view construction can use the dialog's context for * inflation. Maybe this should become a public API. Note sure. */ public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { LayoutInflater result = mActivity.getLayoutInflater().cloneInContext(mActivity); getChildFragmentManager(); // Init if needed; use raw implementation below. result.setFactory(mChildFragmentManager.getLayoutInflaterFactory()); return result; }
The "cloneInContext" method perhaps doesn't honour the ContextWrapper as it's used by Calligraphy?
Anyhow, once I overwrite the getLayoutInflater method in my Fragment like this:
@Override public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { return getActivity().getLayoutInflater(); }
Then it can work, Calligraphy is back on.
Maybe it helps us to find a clean solution. I'm still testing for side effects.
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/84#issuecomment-60867464 .
Boom fixed it!
Hat tip to @ened for the nudge in the right direction.
1.2.1-SNAPSHOT just been pushed.
@chrisjenx Testing 1.2.1-SNAPSHOT. It now appears to work with fragment transactions but layouts inflated in my adapters that were working previously are not. :(. Using something like: LayoutInflater.from(getContext()).inflate(...) in an ArrayAdapter.
@justinelsberry pushed another snapshot, try that and let me know.
@chrisjenx Still not working for me. This is the latest snapshot i see: calligraphy-1.2.1-20141029.163410-1
Refresh your dependencies --refresh-dependencies
for gradle it should be -2
at the end, [https://oss.sonatype.org/content/repositories/snapshots/uk/co/chrisjenx/calligraphy/1.2.1-SNAPSHOT/]() /cc @justinelsberry
@chrisjenx Sorry about that I did refresh but I am proxying through another sonatype server and it didn't update the index. Rebuilt the index and now its working great! Thanks for all your help.
@justinelsberry no worries! Good to hear. If some more people could have a look through and give it a go before I merge and release that would be great! All in time for Droidcon tomorrow :+1:
Any news about this? I'd like to try the snapshot version but I have no idea on how to set it to snapshot in my gradle build
You can try changing the version number to Snapshot build code 1.2.1-SNAPSHOT instead of the 1.2.1+ you're having now. I haven't updated to Snapshot yet. But this should work. On Nov 8, 2014 5:16 PM, "Ludovic Vialle" notifications@github.com wrote:
Any news about this? I'd like to try the snapshot version but I have no idea on how to set it to snapshot in my gradle build
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/84#issuecomment-62255041 .
unfortunately that is not enough: Error:Failed to find: uk.co.chrisjenx:calligraphy:1.2.1-SNAPSHOT
Edit: I downloaded the .jar (SNAPSHOT-2) and for me Calligraphy is still not working
I can't find uk.co.chrisjenx:calligraphy:1.2.1-SNAPSHOT either. Forgive my noobness, where to I get the jar?
The snapshot repos is : [https://oss.sonatype.org/content/repositories/snapshots/]().
Add it like:
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
into you dependencies after jcenter
or mavenCentral
Thanks. Tested with Android Annotations + App Compat + Android 4.4/5.0. Looks like things are working fine now! Great work.
Just a side note, perhaps because I'm using AA, I didn't need the support-v4:21.0.0
fix:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
return getActivity().getLayoutInflater().inflate(R.layout.fragment_main, container, false);
}
On Android 4.4 with AppCompat Library, Calligraphy 1.1.+ doesn't work. However, Calligraphy 0.7.+ works fine.
On Android 5.0 with AppCompat Libary, both Calligraphy 1.1.+ and 0.7.+ does not seem to work.