summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2012-01-05 15:13:15 -0800
committerMarco Nelissen <marcone@google.com>2012-01-05 15:15:53 -0800
commitad35f9165e7f2641812a5069de9c3cd3fdd16923 (patch)
treec7c1546354052b924fe4f48abe87c666af5222b0 /media
parenta8719ad9d53d3fe51e8031b2471e9558b8ef727f (diff)
downloadframeworks_base-ad35f9165e7f2641812a5069de9c3cd3fdd16923.zip
frameworks_base-ad35f9165e7f2641812a5069de9c3cd3fdd16923.tar.gz
frameworks_base-ad35f9165e7f2641812a5069de9c3cd3fdd16923.tar.bz2
Also accept non-parenthesized genre numbers
b/5790684 Change-Id: Ia13feebeaadd45d9196486c012538c5b80840163
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/MediaScanner.java52
1 files changed, 46 insertions, 6 deletions
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index 386986e..55074aa 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -396,6 +396,7 @@ public class MediaScanner
setDefaultRingtoneFileNames();
mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
+ //mClient.testGenreNameConverter();
}
private void setDefaultRingtoneFileNames() {
@@ -623,9 +624,37 @@ public class MediaScanner
mCompilation = parseSubstring(value, 0, 0);
} else if (name.equalsIgnoreCase("isdrm")) {
mIsDrm = (parseSubstring(value, 0, 0) == 1);
+ } else {
+ //Log.v(TAG, "unknown tag: " + name + " (" + mProcessGenres + ")");
}
}
+ private boolean convertGenreCode(String input, String expected) {
+ String output = getGenreName(input);
+ if (output.equals(expected)) {
+ return true;
+ } else {
+ Log.d(TAG, "'" + input + "' -> '" + output + "', expected '" + expected + "'");
+ return false;
+ }
+ }
+ private void testGenreNameConverter() {
+ convertGenreCode("2", "Country");
+ convertGenreCode("(2)", "Country");
+ convertGenreCode("(2", "(2");
+ convertGenreCode("2 Foo", "Country");
+ convertGenreCode("(2) Foo", "Country");
+ convertGenreCode("(2 Foo", "(2 Foo");
+ convertGenreCode("2Foo", "2Foo");
+ convertGenreCode("(2)Foo", "Country");
+ convertGenreCode("200 Foo", "Foo");
+ convertGenreCode("(200) Foo", "Foo");
+ convertGenreCode("200Foo", "200Foo");
+ convertGenreCode("(200)Foo", "Foo");
+ convertGenreCode("200)Foo", "200)Foo");
+ convertGenreCode("200) Foo", "200) Foo");
+ }
+
public String getGenreName(String genreTagValue) {
if (genreTagValue == null) {
@@ -633,18 +662,23 @@ public class MediaScanner
}
final int length = genreTagValue.length();
- if (length > 0 && genreTagValue.charAt(0) == '(') {
+ if (length > 0) {
+ boolean parenthesized = false;
StringBuffer number = new StringBuffer();
- int i = 1;
- for (; i < length - 1; ++i) {
+ int i = 0;
+ for (; i < length; ++i) {
char c = genreTagValue.charAt(i);
- if (Character.isDigit(c)) {
+ if (i == 0 && c == '(') {
+ parenthesized = true;
+ } else if (Character.isDigit(c)) {
number.append(c);
} else {
break;
}
}
- if (genreTagValue.charAt(i) == ')') {
+ char charAfterNumber = i < length ? genreTagValue.charAt(i) : ' ';
+ if ((parenthesized && charAfterNumber == ')')
+ || !parenthesized && Character.isWhitespace(charAfterNumber)) {
try {
short genreIndex = Short.parseShort(number.toString());
if (genreIndex >= 0) {
@@ -655,7 +689,13 @@ public class MediaScanner
} else if (genreIndex < 0xFF && (i + 1) < length) {
// genre is valid but unknown,
// if there is a string after the value we take it
- return genreTagValue.substring(i + 1);
+ if (parenthesized && charAfterNumber == ')') {
+ i++;
+ }
+ String ret = genreTagValue.substring(i).trim();
+ if (ret.length() != 0) {
+ return ret;
+ }
} else {
// else return the number, without parentheses
return number.toString();