|
2 | 2 |
|
3 | 3 | import android.content.Context; |
4 | 4 | import android.content.SharedPreferences; |
| 5 | +import android.content.res.Resources; |
5 | 6 | import android.text.TextUtils; |
6 | 7 | import android.view.LayoutInflater; |
7 | 8 | import android.view.View; |
@@ -39,17 +40,24 @@ private void refreshQuote() { |
39 | 40 | String text = mQuotePrefs.getString(PrefKeys.PREF_QUOTES_TEXT, null); |
40 | 41 | String source = mQuotePrefs.getString(PrefKeys.PREF_QUOTES_SOURCE, null); |
41 | 42 | if (text == null || source == null) { |
42 | | - text = sModuleRes.getString(RES_STRING_OPEN_APP_1); |
43 | | - source = sModuleRes.getString(RES_STRING_OPEN_APP_2); |
| 43 | + try { |
| 44 | + text = sModuleRes.getString(RES_STRING_OPEN_APP_1); |
| 45 | + source = sModuleRes.getString(RES_STRING_OPEN_APP_2); |
| 46 | + } catch (Resources.NotFoundException e) { |
| 47 | + Xlog.e(TAG, "Could not load string resource", e); |
| 48 | + text = null; |
| 49 | + source = null; |
| 50 | + } |
44 | 51 | } |
45 | 52 | mQuoteTextView.setText(text); |
| 53 | + mSourceTextView.setText(source); |
| 54 | + |
46 | 55 | // Hide source textview if there is no source |
47 | 56 | if (TextUtils.isEmpty(source)) { |
48 | 57 | mSourceTextView.setVisibility(View.GONE); |
49 | 58 | } else { |
50 | 59 | mSourceTextView.setVisibility(View.VISIBLE); |
51 | 60 | } |
52 | | - mSourceTextView.setText(source); |
53 | 61 |
|
54 | 62 | // Update font size |
55 | 63 | int textFontSize = Integer.parseInt(mCommonPrefs.getString( |
@@ -80,12 +88,23 @@ protected void afterHookedMethod(MethodHookParam param) { |
80 | 88 | GridLayout self = (GridLayout)param.thisObject; |
81 | 89 | Context context = self.getContext(); |
82 | 90 | LayoutInflater layoutInflater = LayoutInflater.from(context); |
83 | | - XmlPullParser parser = sModuleRes.getLayout(RES_LAYOUT_QUOTE_LAYOUT); |
| 91 | + XmlPullParser parser; |
| 92 | + try { |
| 93 | + parser = sModuleRes.getLayout(RES_LAYOUT_QUOTE_LAYOUT); |
| 94 | + } catch (Resources.NotFoundException e) { |
| 95 | + Xlog.e(TAG, "Could not find quote layout, aborting", e); |
| 96 | + return; |
| 97 | + } |
84 | 98 | View view = layoutInflater.inflate(parser, null); |
85 | 99 | self.addView(view); |
86 | 100 |
|
87 | | - mQuoteTextView = (TextView)sModuleRes.findViewById(view, RES_ID_QUOTE_TEXTVIEW); |
88 | | - mSourceTextView = (TextView)sModuleRes.findViewById(view, RES_ID_SOURCE_TEXTVIEW); |
| 101 | + try { |
| 102 | + mQuoteTextView = (TextView)sModuleRes.findViewById(view, RES_ID_QUOTE_TEXTVIEW); |
| 103 | + mSourceTextView = (TextView)sModuleRes.findViewById(view, RES_ID_SOURCE_TEXTVIEW); |
| 104 | + } catch (Resources.NotFoundException e) { |
| 105 | + Xlog.e(TAG, "Could not find text views, aborting", e); |
| 106 | + return; |
| 107 | + } |
89 | 108 |
|
90 | 109 | Xlog.i(TAG, "View injection complete, registering preferences..."); |
91 | 110 | mCommonPrefs = new RemotePreferences(context, PreferenceProvider.AUTHORITY, PrefKeys.PREF_COMMON); |
|
0 commit comments