Skip to content
This repository was archived by the owner on Jan 8, 2019. It is now read-only.

Commit 00efe66

Browse files
committed
Handle resource not found exceptions
1 parent e57c6fa commit 00efe66

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

src/com/crossbowffs/quotelock/xposed/LockscreenHook.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.SharedPreferences;
5+
import android.content.res.Resources;
56
import android.text.TextUtils;
67
import android.view.LayoutInflater;
78
import android.view.View;
@@ -39,17 +40,24 @@ private void refreshQuote() {
3940
String text = mQuotePrefs.getString(PrefKeys.PREF_QUOTES_TEXT, null);
4041
String source = mQuotePrefs.getString(PrefKeys.PREF_QUOTES_SOURCE, null);
4142
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+
}
4451
}
4552
mQuoteTextView.setText(text);
53+
mSourceTextView.setText(source);
54+
4655
// Hide source textview if there is no source
4756
if (TextUtils.isEmpty(source)) {
4857
mSourceTextView.setVisibility(View.GONE);
4958
} else {
5059
mSourceTextView.setVisibility(View.VISIBLE);
5160
}
52-
mSourceTextView.setText(source);
5361

5462
// Update font size
5563
int textFontSize = Integer.parseInt(mCommonPrefs.getString(
@@ -80,12 +88,23 @@ protected void afterHookedMethod(MethodHookParam param) {
8088
GridLayout self = (GridLayout)param.thisObject;
8189
Context context = self.getContext();
8290
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+
}
8498
View view = layoutInflater.inflate(parser, null);
8599
self.addView(view);
86100

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+
}
89108

90109
Xlog.i(TAG, "View injection complete, registering preferences...");
91110
mCommonPrefs = new RemotePreferences(context, PreferenceProvider.AUTHORITY, PrefKeys.PREF_COMMON);

0 commit comments

Comments
 (0)