From 81c99a8ed7086819b1e7569c34c3ad1b7bab0b1d Mon Sep 17 00:00:00 2001 From: Christopher Jenkins Date: Thu, 5 Mar 2015 21:24:12 +0000 Subject: [PATCH] fixed The correct context being passed to `createView` Should of fixed #135, #120. --- .../CalligraphyLayoutInflater.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyLayoutInflater.java b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyLayoutInflater.java index a1ef50c..850deec 100644 --- a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyLayoutInflater.java +++ b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyLayoutInflater.java @@ -175,15 +175,15 @@ protected View onCreateView(String name, AttributeSet attrs) throws ClassNotFoun * will fall back through to the PhoneLayoutInflater method of inflating custom views where * Calligraphy will NOT have a hook into. * - * @param parent parent view - * @param view view if it has been inflated by this point, if this is not null this method - * just returns this value. - * @param name name of the thing to inflate. - * @param context Context to inflate by if parent is null - * @param attrs Attr for this view which we can steal fontPath from too. + * @param parent parent view + * @param view view if it has been inflated by this point, if this is not null this method + * just returns this value. + * @param name name of the thing to inflate. + * @param viewContext Context to inflate by if parent is null + * @param attrs Attr for this view which we can steal fontPath from too. * @return view or the View we inflate in here. */ - private View createCustomViewInternal(View parent, View view, String name, Context context, AttributeSet attrs) { + private View createCustomViewInternal(View parent, View view, String name, Context viewContext, AttributeSet attrs) { // I by no means advise anyone to do this normally, but Google have locked down access to // the createView() method, so we never get a callback with attributes at the end of the // createViewFromTag chain (which would solve all this unnecessary rubbish). @@ -200,7 +200,10 @@ private View createCustomViewInternal(View parent, View view, String name, Conte final Object[] mConstructorArgsArr = (Object[]) ReflectionUtils.getValue(mConstructorArgs, this); final Object lastContext = mConstructorArgsArr[0]; - mConstructorArgsArr[0] = parent != null ? parent.getContext() : context; + // The LayoutInflater actually finds out the correct context to use. We just need to set + // it on the mConstructor for the internal method. + // Set the constructor ars up for the createView, not sure why we can't pass these in. + mConstructorArgsArr[0] = viewContext; ReflectionUtils.setValue(mConstructorArgs, this, mConstructorArgsArr); try { view = createView(name, null, attrs);