Skip to content

Commit

Permalink
InflationX#30 ; Fixed matchesResourceIdName resulting in NotFoundExce…
Browse files Browse the repository at this point in the history
…ption on Android P when trying expand WebView PopUp list (#1)
  • Loading branch information
tpiDev authored May 20, 2019
1 parent 2b7f3fe commit a2e6ee3
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.TextView;

import java.lang.ref.WeakReference;
import java.lang.reflect.Method;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;

class Calligraphy {

private static final String ACTION_BAR_TITLE = "action_bar_title";
private static final String ACTION_BAR_SUBTITLE = "action_bar_subtitle";
private static final String TAG = Calligraphy.class.getSimpleName();

/**
* Some styles are in sub styles, such as actionBarTextStyle etc..
Expand Down Expand Up @@ -91,7 +95,7 @@ protected static boolean parentIsToolbarV7(View view) {
*/
protected static boolean matchesResourceIdName(View view, String matches) {
if (view.getId() == View.NO_ID) return false;
final String resourceEntryName = view.getResources().getResourceEntryName(view.getId());
final String resourceEntryName = getResourceEntryName(view);
return resourceEntryName.equalsIgnoreCase(matches);
}

Expand All @@ -103,6 +107,16 @@ public Calligraphy(CalligraphyConfig calligraphyConfig) {
this.mAttributeId = new int[]{calligraphyConfig.getAttrId()};
}

@NonNull
private static String getResourceEntryName(@NonNull View view) {
try {
return view.getResources().getResourceEntryName(view.getId());
} catch (Resources.NotFoundException exception) {
Log.w(TAG, "An error occurred when trying to get resource entry name. \nStackTrace:" + exception);
return "";
}
}

/**
* Handle the created view
*
Expand Down

0 comments on commit a2e6ee3

Please sign in to comment.