Skip to content

Commit

Permalink
fix the bug of resource not found
Browse files Browse the repository at this point in the history
  • Loading branch information
vancebs committed Nov 24, 2015
1 parent cdfd0a4 commit a771666
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.hf.resreader"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
versionCode 5
versionName "2.3"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hf.resreader.resreader;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.TextView;

Expand Down Expand Up @@ -36,7 +37,11 @@ public View read(Context context, View convertView, String pkg, String type, Str

// set values
resIdView.setText(String.valueOf(resId));
valueView.setText(getValue(resContext, resId));
try {
valueView.setText(getValue(resContext, resId));
} catch (Resources.NotFoundException e) {
valueView.setText(R.string.err_not_found);
}

return view;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public View read(Context context, View convertView, String pkg, String type, Str
} catch (Resources.NotFoundException e) {
Log.d(TAG, "Resource not found. So set color as 0x000000", e);
color = 0x000000;
msg = "Resource not found";
msg = context.getResources().getString(R.string.err_not_found);
}

// set values
Expand Down
17 changes: 5 additions & 12 deletions app/src/main/java/com/hf/resreader/resreader/DimenResReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@ public class DimenResReader extends AbstractStringTypeResReader {

@Override
public String getValue(Context resContext, int resId) {
// ResourceNotFoundException Already handled by super class
Resources res = resContext.getResources();
String value;
try {
float dp = res.getDimension(resId);
int px = res.getDimensionPixelOffset(resId);
int size = res.getDimensionPixelSize(resId);
value = String.format(VALUE_FORMAT, dp, px, size);
} catch (Resources.NotFoundException e) {
Log.d(TAG, "Resource not found.", e);
value = "Resource not found";
}

return value;
float dp = res.getDimension(resId);
int px = res.getDimensionPixelOffset(resId);
int size = res.getDimensionPixelSize(resId);
return String.format(VALUE_FORMAT, dp, px, size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public View read(Context context, View convertView, String pkg, String type, Str
layoutView.addView(layout);
} catch (Resources.NotFoundException e) {
Log.d(TAG, "Resource not found.", e);
msgView.setText("Cannot find resource.");
msgView.setText(R.string.err_not_found);
msgView.setVisibility(View.VISIBLE);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/hf/resreader/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState( Bundle outState) {
super.onSaveInstanceState(outState);

outState.putString(EXTRA_PKG, mValuePkg);
Expand Down
6 changes: 6 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sonar.projectKey=ResReader
sonar.projectName=ResReader
sonar.projectVersion=2.2
sonar.sources=app/src/main/java
sonar.launguage=java
#sonar.sourceEncoding=GBK

0 comments on commit a771666

Please sign in to comment.