Home | History | Annotate | Download | only in mms
      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 
     18 package com.google.android.mms;
     19 
     20 import java.util.ArrayList;
     21 
     22 public class ContentType {
     23     public static final String MMS_MESSAGE       = "application/vnd.wap.mms-message";
     24     // The phony content type for generic PDUs (e.g. ReadOrig.ind,
     25     // Notification.ind, Delivery.ind).
     26     public static final String MMS_GENERIC       = "application/vnd.wap.mms-generic";
     27     public static final String MULTIPART_MIXED   = "application/vnd.wap.multipart.mixed";
     28     public static final String MULTIPART_RELATED = "application/vnd.wap.multipart.related";
     29     public static final String MULTIPART_ALTERNATIVE = "application/vnd.wap.multipart.alternative";
     30 
     31     public static final String TEXT_PLAIN        = "text/plain";
     32     public static final String TEXT_HTML         = "text/html";
     33     public static final String TEXT_VCALENDAR    = "text/x-vCalendar";
     34     public static final String TEXT_VCARD        = "text/x-vCard";
     35 
     36     public static final String IMAGE_UNSPECIFIED = "image/*";
     37     public static final String IMAGE_JPEG        = "image/jpeg";
     38     public static final String IMAGE_JPG         = "image/jpg";
     39     public static final String IMAGE_GIF         = "image/gif";
     40     public static final String IMAGE_WBMP        = "image/vnd.wap.wbmp";
     41     public static final String IMAGE_PNG         = "image/png";
     42     public static final String IMAGE_X_MS_BMP    = "image/x-ms-bmp";
     43 
     44     public static final String AUDIO_UNSPECIFIED = "audio/*";
     45     public static final String AUDIO_AAC         = "audio/aac";
     46     public static final String AUDIO_AMR         = "audio/amr";
     47     public static final String AUDIO_IMELODY     = "audio/imelody";
     48     public static final String AUDIO_MID         = "audio/mid";
     49     public static final String AUDIO_MIDI        = "audio/midi";
     50     public static final String AUDIO_MP3         = "audio/mp3";
     51     public static final String AUDIO_MPEG3       = "audio/mpeg3";
     52     public static final String AUDIO_MPEG        = "audio/mpeg";
     53     public static final String AUDIO_MPG         = "audio/mpg";
     54     public static final String AUDIO_MP4         = "audio/mp4";
     55     public static final String AUDIO_X_MID       = "audio/x-mid";
     56     public static final String AUDIO_X_MIDI      = "audio/x-midi";
     57     public static final String AUDIO_X_MP3       = "audio/x-mp3";
     58     public static final String AUDIO_X_MPEG3     = "audio/x-mpeg3";
     59     public static final String AUDIO_X_MPEG      = "audio/x-mpeg";
     60     public static final String AUDIO_X_MPG       = "audio/x-mpg";
     61     public static final String AUDIO_3GPP        = "audio/3gpp";
     62     public static final String AUDIO_X_WAV       = "audio/x-wav";
     63     public static final String AUDIO_OGG         = "application/ogg";
     64 
     65     public static final String VIDEO_UNSPECIFIED = "video/*";
     66     public static final String VIDEO_3GPP        = "video/3gpp";
     67     public static final String VIDEO_3G2         = "video/3gpp2";
     68     public static final String VIDEO_H263        = "video/h263";
     69     public static final String VIDEO_MP4         = "video/mp4";
     70 
     71     public static final String APP_SMIL          = "application/smil";
     72     public static final String APP_WAP_XHTML     = "application/vnd.wap.xhtml+xml";
     73     public static final String APP_XHTML         = "application/xhtml+xml";
     74 
     75     public static final String APP_DRM_CONTENT   = "application/vnd.oma.drm.content";
     76     public static final String APP_DRM_MESSAGE   = "application/vnd.oma.drm.message";
     77 
     78     private static final ArrayList<String> sSupportedContentTypes = new ArrayList<String>();
     79     private static final ArrayList<String> sSupportedImageTypes = new ArrayList<String>();
     80     private static final ArrayList<String> sSupportedAudioTypes = new ArrayList<String>();
     81     private static final ArrayList<String> sSupportedVideoTypes = new ArrayList<String>();
     82 
     83     static {
     84         sSupportedContentTypes.add(TEXT_PLAIN);
     85         sSupportedContentTypes.add(TEXT_HTML);
     86         sSupportedContentTypes.add(TEXT_VCALENDAR);
     87         sSupportedContentTypes.add(TEXT_VCARD);
     88 
     89         sSupportedContentTypes.add(IMAGE_JPEG);
     90         sSupportedContentTypes.add(IMAGE_GIF);
     91         sSupportedContentTypes.add(IMAGE_WBMP);
     92         sSupportedContentTypes.add(IMAGE_PNG);
     93         sSupportedContentTypes.add(IMAGE_JPG);
     94         sSupportedContentTypes.add(IMAGE_X_MS_BMP);
     95         //supportedContentTypes.add(IMAGE_SVG); not yet supported.
     96 
     97         sSupportedContentTypes.add(AUDIO_AAC);
     98         sSupportedContentTypes.add(AUDIO_AMR);
     99         sSupportedContentTypes.add(AUDIO_IMELODY);
    100         sSupportedContentTypes.add(AUDIO_MID);
    101         sSupportedContentTypes.add(AUDIO_MIDI);
    102         sSupportedContentTypes.add(AUDIO_MP3);
    103         sSupportedContentTypes.add(AUDIO_MPEG3);
    104         sSupportedContentTypes.add(AUDIO_MPEG);
    105         sSupportedContentTypes.add(AUDIO_MPG);
    106         sSupportedContentTypes.add(AUDIO_X_MID);
    107         sSupportedContentTypes.add(AUDIO_X_MIDI);
    108         sSupportedContentTypes.add(AUDIO_X_MP3);
    109         sSupportedContentTypes.add(AUDIO_X_MPEG3);
    110         sSupportedContentTypes.add(AUDIO_X_MPEG);
    111         sSupportedContentTypes.add(AUDIO_X_MPG);
    112         sSupportedContentTypes.add(AUDIO_X_WAV);
    113         sSupportedContentTypes.add(AUDIO_3GPP);
    114         sSupportedContentTypes.add(AUDIO_OGG);
    115 
    116         sSupportedContentTypes.add(VIDEO_3GPP);
    117         sSupportedContentTypes.add(VIDEO_3G2);
    118         sSupportedContentTypes.add(VIDEO_H263);
    119         sSupportedContentTypes.add(VIDEO_MP4);
    120 
    121         sSupportedContentTypes.add(APP_SMIL);
    122         sSupportedContentTypes.add(APP_WAP_XHTML);
    123         sSupportedContentTypes.add(APP_XHTML);
    124 
    125         sSupportedContentTypes.add(APP_DRM_CONTENT);
    126         sSupportedContentTypes.add(APP_DRM_MESSAGE);
    127 
    128         // add supported image types
    129         sSupportedImageTypes.add(IMAGE_JPEG);
    130         sSupportedImageTypes.add(IMAGE_GIF);
    131         sSupportedImageTypes.add(IMAGE_WBMP);
    132         sSupportedImageTypes.add(IMAGE_PNG);
    133         sSupportedImageTypes.add(IMAGE_JPG);
    134         sSupportedImageTypes.add(IMAGE_X_MS_BMP);
    135 
    136         // add supported audio types
    137         sSupportedAudioTypes.add(AUDIO_AAC);
    138         sSupportedAudioTypes.add(AUDIO_AMR);
    139         sSupportedAudioTypes.add(AUDIO_IMELODY);
    140         sSupportedAudioTypes.add(AUDIO_MID);
    141         sSupportedAudioTypes.add(AUDIO_MIDI);
    142         sSupportedAudioTypes.add(AUDIO_MP3);
    143         sSupportedAudioTypes.add(AUDIO_MPEG3);
    144         sSupportedAudioTypes.add(AUDIO_MPEG);
    145         sSupportedAudioTypes.add(AUDIO_MPG);
    146         sSupportedAudioTypes.add(AUDIO_MP4);
    147         sSupportedAudioTypes.add(AUDIO_X_MID);
    148         sSupportedAudioTypes.add(AUDIO_X_MIDI);
    149         sSupportedAudioTypes.add(AUDIO_X_MP3);
    150         sSupportedAudioTypes.add(AUDIO_X_MPEG3);
    151         sSupportedAudioTypes.add(AUDIO_X_MPEG);
    152         sSupportedAudioTypes.add(AUDIO_X_MPG);
    153         sSupportedAudioTypes.add(AUDIO_X_WAV);
    154         sSupportedAudioTypes.add(AUDIO_3GPP);
    155         sSupportedAudioTypes.add(AUDIO_OGG);
    156 
    157         // add supported video types
    158         sSupportedVideoTypes.add(VIDEO_3GPP);
    159         sSupportedVideoTypes.add(VIDEO_3G2);
    160         sSupportedVideoTypes.add(VIDEO_H263);
    161         sSupportedVideoTypes.add(VIDEO_MP4);
    162     }
    163 
    164     // This class should never be instantiated.
    165     private ContentType() {
    166     }
    167 
    168     public static boolean isSupportedType(String contentType) {
    169         return (null != contentType) && sSupportedContentTypes.contains(contentType);
    170     }
    171 
    172     public static boolean isSupportedImageType(String contentType) {
    173         return isImageType(contentType) && isSupportedType(contentType);
    174     }
    175 
    176     public static boolean isSupportedAudioType(String contentType) {
    177         return isAudioType(contentType) && isSupportedType(contentType);
    178     }
    179 
    180     public static boolean isSupportedVideoType(String contentType) {
    181         return isVideoType(contentType) && isSupportedType(contentType);
    182     }
    183 
    184     public static boolean isTextType(String contentType) {
    185         return (null != contentType) && contentType.startsWith("text/");
    186     }
    187 
    188     public static boolean isImageType(String contentType) {
    189         return (null != contentType) && contentType.startsWith("image/");
    190     }
    191 
    192     public static boolean isAudioType(String contentType) {
    193         return (null != contentType) && contentType.startsWith("audio/");
    194     }
    195 
    196     public static boolean isVideoType(String contentType) {
    197         return (null != contentType) && contentType.startsWith("video/");
    198     }
    199 
    200     public static boolean isDrmType(String contentType) {
    201         return (null != contentType)
    202                 && (contentType.equals(APP_DRM_CONTENT)
    203                         || contentType.equals(APP_DRM_MESSAGE));
    204     }
    205 
    206     public static boolean isUnspecified(String contentType) {
    207         return (null != contentType) && contentType.endsWith("*");
    208     }
    209 
    210     @SuppressWarnings("unchecked")
    211     public static ArrayList<String> getImageTypes() {
    212         return (ArrayList<String>) sSupportedImageTypes.clone();
    213     }
    214 
    215     @SuppressWarnings("unchecked")
    216     public static ArrayList<String> getAudioTypes() {
    217         return (ArrayList<String>) sSupportedAudioTypes.clone();
    218     }
    219 
    220     @SuppressWarnings("unchecked")
    221     public static ArrayList<String> getVideoTypes() {
    222         return (ArrayList<String>) sSupportedVideoTypes.clone();
    223     }
    224 
    225     @SuppressWarnings("unchecked")
    226     public static ArrayList<String> getSupportedTypes() {
    227         return (ArrayList<String>) sSupportedContentTypes.clone();
    228     }
    229 }
    230