/core/java/com/google/android/mms/ContentType.java

https://github.com/integralnd/android_frameworks_base · Java · 222 lines · 165 code · 34 blank · 23 comment · 18 complexity · a2fb1940a2e4c6064ed479f6e8b2e608 MD5 · raw file

  1. /*
  2. * Copyright (C) 2007-2008 Esmertec AG.
  3. * Copyright (C) 2007-2008 The Android Open Source Project
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.google.android.mms;
  18. import java.util.ArrayList;
  19. public class ContentType {
  20. public static final String MMS_MESSAGE = "application/vnd.wap.mms-message";
  21. // The phony content type for generic PDUs (e.g. ReadOrig.ind,
  22. // Notification.ind, Delivery.ind).
  23. public static final String MMS_GENERIC = "application/vnd.wap.mms-generic";
  24. public static final String MULTIPART_MIXED = "application/vnd.wap.multipart.mixed";
  25. public static final String MULTIPART_RELATED = "application/vnd.wap.multipart.related";
  26. public static final String TEXT_PLAIN = "text/plain";
  27. public static final String TEXT_HTML = "text/html";
  28. public static final String TEXT_VCALENDAR = "text/x-vCalendar";
  29. public static final String TEXT_VCARD = "text/x-vCard";
  30. public static final String IMAGE_UNSPECIFIED = "image/*";
  31. public static final String IMAGE_JPEG = "image/jpeg";
  32. public static final String IMAGE_JPG = "image/jpg";
  33. public static final String IMAGE_GIF = "image/gif";
  34. public static final String IMAGE_WBMP = "image/vnd.wap.wbmp";
  35. public static final String IMAGE_PNG = "image/png";
  36. public static final String AUDIO_UNSPECIFIED = "audio/*";
  37. public static final String AUDIO_AAC = "audio/aac";
  38. public static final String AUDIO_AMR = "audio/amr";
  39. public static final String AUDIO_IMELODY = "audio/imelody";
  40. public static final String AUDIO_MID = "audio/mid";
  41. public static final String AUDIO_MIDI = "audio/midi";
  42. public static final String AUDIO_MP3 = "audio/mp3";
  43. public static final String AUDIO_MPEG3 = "audio/mpeg3";
  44. public static final String AUDIO_MPEG = "audio/mpeg";
  45. public static final String AUDIO_MPG = "audio/mpg";
  46. public static final String AUDIO_MP4 = "audio/mp4";
  47. public static final String AUDIO_X_MID = "audio/x-mid";
  48. public static final String AUDIO_X_MIDI = "audio/x-midi";
  49. public static final String AUDIO_X_MP3 = "audio/x-mp3";
  50. public static final String AUDIO_X_MPEG3 = "audio/x-mpeg3";
  51. public static final String AUDIO_X_MPEG = "audio/x-mpeg";
  52. public static final String AUDIO_X_MPG = "audio/x-mpg";
  53. public static final String AUDIO_3GPP = "audio/3gpp";
  54. public static final String AUDIO_OGG = "application/ogg";
  55. public static final String VIDEO_UNSPECIFIED = "video/*";
  56. public static final String VIDEO_3GPP = "video/3gpp";
  57. public static final String VIDEO_3G2 = "video/3gpp2";
  58. public static final String VIDEO_H263 = "video/h263";
  59. public static final String VIDEO_MP4 = "video/mp4";
  60. public static final String APP_SMIL = "application/smil";
  61. public static final String APP_WAP_XHTML = "application/vnd.wap.xhtml+xml";
  62. public static final String APP_XHTML = "application/xhtml+xml";
  63. public static final String APP_DRM_CONTENT = "application/vnd.oma.drm.content";
  64. public static final String APP_DRM_MESSAGE = "application/vnd.oma.drm.message";
  65. private static final ArrayList<String> sSupportedContentTypes = new ArrayList<String>();
  66. private static final ArrayList<String> sSupportedImageTypes = new ArrayList<String>();
  67. private static final ArrayList<String> sSupportedAudioTypes = new ArrayList<String>();
  68. private static final ArrayList<String> sSupportedVideoTypes = new ArrayList<String>();
  69. static {
  70. sSupportedContentTypes.add(TEXT_PLAIN);
  71. sSupportedContentTypes.add(TEXT_HTML);
  72. sSupportedContentTypes.add(TEXT_VCALENDAR);
  73. sSupportedContentTypes.add(TEXT_VCARD);
  74. sSupportedContentTypes.add(IMAGE_JPEG);
  75. sSupportedContentTypes.add(IMAGE_GIF);
  76. sSupportedContentTypes.add(IMAGE_WBMP);
  77. sSupportedContentTypes.add(IMAGE_PNG);
  78. sSupportedContentTypes.add(IMAGE_JPG);
  79. //supportedContentTypes.add(IMAGE_SVG); not yet supported.
  80. sSupportedContentTypes.add(AUDIO_AAC);
  81. sSupportedContentTypes.add(AUDIO_AMR);
  82. sSupportedContentTypes.add(AUDIO_IMELODY);
  83. sSupportedContentTypes.add(AUDIO_MID);
  84. sSupportedContentTypes.add(AUDIO_MIDI);
  85. sSupportedContentTypes.add(AUDIO_MP3);
  86. sSupportedContentTypes.add(AUDIO_MPEG3);
  87. sSupportedContentTypes.add(AUDIO_MPEG);
  88. sSupportedContentTypes.add(AUDIO_MPG);
  89. sSupportedContentTypes.add(AUDIO_X_MID);
  90. sSupportedContentTypes.add(AUDIO_X_MIDI);
  91. sSupportedContentTypes.add(AUDIO_X_MP3);
  92. sSupportedContentTypes.add(AUDIO_X_MPEG3);
  93. sSupportedContentTypes.add(AUDIO_X_MPEG);
  94. sSupportedContentTypes.add(AUDIO_X_MPG);
  95. sSupportedContentTypes.add(AUDIO_3GPP);
  96. sSupportedContentTypes.add(AUDIO_OGG);
  97. sSupportedContentTypes.add(VIDEO_3GPP);
  98. sSupportedContentTypes.add(VIDEO_3G2);
  99. sSupportedContentTypes.add(VIDEO_H263);
  100. sSupportedContentTypes.add(VIDEO_MP4);
  101. sSupportedContentTypes.add(APP_SMIL);
  102. sSupportedContentTypes.add(APP_WAP_XHTML);
  103. sSupportedContentTypes.add(APP_XHTML);
  104. sSupportedContentTypes.add(APP_DRM_CONTENT);
  105. sSupportedContentTypes.add(APP_DRM_MESSAGE);
  106. // add supported image types
  107. sSupportedImageTypes.add(IMAGE_JPEG);
  108. sSupportedImageTypes.add(IMAGE_GIF);
  109. sSupportedImageTypes.add(IMAGE_WBMP);
  110. sSupportedImageTypes.add(IMAGE_PNG);
  111. sSupportedImageTypes.add(IMAGE_JPG);
  112. // add supported audio types
  113. sSupportedAudioTypes.add(AUDIO_AAC);
  114. sSupportedAudioTypes.add(AUDIO_AMR);
  115. sSupportedAudioTypes.add(AUDIO_IMELODY);
  116. sSupportedAudioTypes.add(AUDIO_MID);
  117. sSupportedAudioTypes.add(AUDIO_MIDI);
  118. sSupportedAudioTypes.add(AUDIO_MP3);
  119. sSupportedAudioTypes.add(AUDIO_MPEG3);
  120. sSupportedAudioTypes.add(AUDIO_MPEG);
  121. sSupportedAudioTypes.add(AUDIO_MPG);
  122. sSupportedAudioTypes.add(AUDIO_MP4);
  123. sSupportedAudioTypes.add(AUDIO_X_MID);
  124. sSupportedAudioTypes.add(AUDIO_X_MIDI);
  125. sSupportedAudioTypes.add(AUDIO_X_MP3);
  126. sSupportedAudioTypes.add(AUDIO_X_MPEG3);
  127. sSupportedAudioTypes.add(AUDIO_X_MPEG);
  128. sSupportedAudioTypes.add(AUDIO_X_MPG);
  129. sSupportedAudioTypes.add(AUDIO_3GPP);
  130. sSupportedAudioTypes.add(AUDIO_OGG);
  131. // add supported video types
  132. sSupportedVideoTypes.add(VIDEO_3GPP);
  133. sSupportedVideoTypes.add(VIDEO_3G2);
  134. sSupportedVideoTypes.add(VIDEO_H263);
  135. sSupportedVideoTypes.add(VIDEO_MP4);
  136. }
  137. // This class should never be instantiated.
  138. private ContentType() {
  139. }
  140. public static boolean isSupportedType(String contentType) {
  141. return (null != contentType) && sSupportedContentTypes.contains(contentType);
  142. }
  143. public static boolean isSupportedImageType(String contentType) {
  144. return isImageType(contentType) && isSupportedType(contentType);
  145. }
  146. public static boolean isSupportedAudioType(String contentType) {
  147. return isAudioType(contentType) && isSupportedType(contentType);
  148. }
  149. public static boolean isSupportedVideoType(String contentType) {
  150. return isVideoType(contentType) && isSupportedType(contentType);
  151. }
  152. public static boolean isTextType(String contentType) {
  153. return (null != contentType) && contentType.startsWith("text/");
  154. }
  155. public static boolean isImageType(String contentType) {
  156. return (null != contentType) && contentType.startsWith("image/");
  157. }
  158. public static boolean isAudioType(String contentType) {
  159. return (null != contentType) && contentType.startsWith("audio/");
  160. }
  161. public static boolean isVideoType(String contentType) {
  162. return (null != contentType) && contentType.startsWith("video/");
  163. }
  164. public static boolean isDrmType(String contentType) {
  165. return (null != contentType)
  166. && (contentType.equals(APP_DRM_CONTENT)
  167. || contentType.equals(APP_DRM_MESSAGE));
  168. }
  169. public static boolean isUnspecified(String contentType) {
  170. return (null != contentType) && contentType.endsWith("*");
  171. }
  172. @SuppressWarnings("unchecked")
  173. public static ArrayList<String> getImageTypes() {
  174. return (ArrayList<String>) sSupportedImageTypes.clone();
  175. }
  176. @SuppressWarnings("unchecked")
  177. public static ArrayList<String> getAudioTypes() {
  178. return (ArrayList<String>) sSupportedAudioTypes.clone();
  179. }
  180. @SuppressWarnings("unchecked")
  181. public static ArrayList<String> getVideoTypes() {
  182. return (ArrayList<String>) sSupportedVideoTypes.clone();
  183. }
  184. @SuppressWarnings("unchecked")
  185. public static ArrayList<String> getSupportedTypes() {
  186. return (ArrayList<String>) sSupportedContentTypes.clone();
  187. }
  188. }