Skip to content

Commit

Permalink
Merge pull request #7399 from sriks/TIMOB-19859
Browse files Browse the repository at this point in the history
[TIMOB-19859] Android: Deprecate Ti.Android.R.drawable
  • Loading branch information
ashcoding committed Nov 6, 2015
2 parents a3441cf + 0f62f4c commit 0eb9cac
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ public InputStream openInputStream(String path, boolean report)
if (TI_RESOURCE_PREFIX.equals(section)) {
is = TiFileHelper.class.getResourceAsStream("/org/appcelerator/titanium/res/drawable/" + resid + ".png");
} else if ("Sys".equals(section)) {
Integer id = systemIcons.get(resid);
if (id != null) {
is = Resources.getSystem().openRawResource(id);
} else {
Log.w(TAG, "Drawable not found for system id: " + path);
}
Log.e(TAG, "Accessing Android system icons is deprecated. Instead copy to res folder.");
Integer id = systemIcons.get(resid);
if (id != null) {
is = Resources.getSystem().openRawResource(id);
} else {
Log.w(TAG, "Drawable not found for system id: " + path);
}
} else {
Log.e(TAG, "Unknown section identifier: " + section);
}
Expand Down Expand Up @@ -407,12 +408,13 @@ public Drawable getTitaniumResource(Context context, String s) {
}
}
} else if ("Sys".equals(section)) {
Integer id = systemIcons.get(resid);
if (id != null) {
d = Resources.getSystem().getDrawable(id);
} else {
Log.w(TAG, "Drawable not found for system id: " + s);
}
Log.e(TAG, "Accessing Android system icons is deprecated. Instead copy to res folder.");
Integer id = systemIcons.get(resid);
if (id != null) {
d = Resources.getSystem().getDrawable(id);
} else {
Log.w(TAG, "Drawable not found for system id: " + s);
}
} else {
Log.e(TAG, "Unknown section identifier: " + section);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,30 @@ protected static int getResource(String prefix, String path) throws ResourceNotF
}

protected static int lookupResource(String prefix, String path, String[] classAndFieldNames) throws ResourceNotFoundException {
// Get the clsPrefixApplication if this is the first time
if (clsPrefixApplication == null)
clsPrefixApplication = TiApplication.getInstance().getApplicationInfo().packageName + ".R$";
if (prefix == null) {
prefix = clsPrefixApplication;
}

Integer i = null;
// Load the field
try {
i = getClass(prefix + classAndFieldNames[0]).getDeclaredField(classAndFieldNames[1]).getInt(null);
} catch (Exception e) {
Log.e(TAG, "Error looking up resource: " + e.getMessage(), e, Log.DEBUG_MODE);
valCache.put(path, 0);
throw new ResourceNotFoundException(path);
}

valCache.put(path, i);
return i;
if (prefix != null && path != null
&& prefix.startsWith("android.R") && path.startsWith("drawable.")) {
Log.w(TAG, "Using android.R.drawable is not recommended since they are changed/removed across Android versions. Instead copy images to res folder.");
}

// Get the clsPrefixApplication if this is the first time
if (clsPrefixApplication == null)
clsPrefixApplication = TiApplication.getInstance().getApplicationInfo().packageName + ".R$";
if (prefix == null) {
prefix = clsPrefixApplication;
}

Integer i = null;
// Load the field
try {
i = getClass(prefix + classAndFieldNames[0]).getDeclaredField(classAndFieldNames[1]).getInt(null);
} catch (Exception e) {
Log.e(TAG, "Error looking up resource: " + e.getMessage(), e, Log.DEBUG_MODE);
valCache.put(path, 0);
throw new ResourceNotFoundException(path);
}

valCache.put(path, i);
return i;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions apidoc/Titanium/Android/R.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ description: |
See also: [android.R](http://developer.android.com/reference/android/R.html) in the
Android Developer Reference.
Accessing drawables using Ti.Android.R.drawable is deprecated and not a recommended practice since the system provided drawables can be
removed across Android versions. Prefer to copy the images to application res folder.
extends: Titanium.Proxy
platforms: [android]
createable: false
Expand Down Expand Up @@ -67,6 +70,8 @@ properties:
Drawable resources. See
[R.drawable](http://developer.android.com/reference/android/R.drawable.html)
in the Android Developer Reference.
Accessing drawables using Ti.Android.R.drawable is deprecated and not a recommended practice since the system provided
drawables can be removed across Android versions. Prefer to copy the images to application res folder.
type: Object
accessors: false
permission: read-only
Expand Down

0 comments on commit 0eb9cac

Please sign in to comment.