View Javadoc

1   /* ***** BEGIN LICENSE BLOCK *****
2    * Version: MPL 1.1
3    *
4    * The contents of this file are subject to the Mozilla Public License Version
5    * 1.1 (the "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    * http://www.mozilla.org/MPL/
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis,
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11   * for the specific language governing rights and limitations under the
12   * License.
13   *
14   * The Original Code is "SMS Library for the Java platform".
15   *
16   * The Initial Developer of the Original Code is Markus Eriksson.
17   * Portions created by the Initial Developer are Copyright (C) 2002
18   * the Initial Developer. All Rights Reserved.
19   *
20   * Contributor(s):
21   *
22   * ***** END LICENSE BLOCK ***** */
23  package org.marre.sms.nokia;
24  
25  import java.io.ByteArrayOutputStream;
26  import java.io.IOException;
27  
28  import org.marre.sms.SmsConstants;
29  import org.marre.sms.SmsPduUtil;
30  import org.marre.sms.SmsPortAddressedMessage;
31  import org.marre.sms.SmsUserData;
32  
33  /***
34   * Nokia Operator Logo message
35   * 
36   * @author Markus Eriksson
37   * @version $Id: NokiaOperatorLogo.java,v 1.13 2004/11/20 19:02:35 c95men Exp $
38   */
39  public class NokiaOperatorLogo extends SmsPortAddressedMessage
40  {
41      /***
42       * If set to true it will make the message two bytes shorter to make it
43       * possible to fit a 72x14 pixel image in one SMS instead of two. <br>
44       * <b>Note! </b> This will probably only work on Nokia phones...
45       */
46      protected boolean myDiscardNokiaHeaders;
47      
48      /*** The ota image as a byte array */
49      protected byte[] myBitmap;
50      
51      /*** GSM Mobile Country Code */
52      protected int myMcc;
53      
54      /*** GSM Mobile Network Code */
55      protected int myMnc;
56  
57      /***
58       * Creates a Nokia Operator Logo message
59       * 
60       * @param theOtaBitmap
61       * @param theMcc
62       *            GSM Mobile Country Code
63       * @param theMnc
64       *            GSM Mobile Network Code
65       */
66      public NokiaOperatorLogo(OtaBitmap theOtaBitmap, int theMcc, int theMnc)
67      {
68          this(theOtaBitmap.getBytes(), theMcc, theMnc);
69      }
70  
71      /***
72       * Creates a Nokia Operator Logo message
73       * 
74       * @param theOtaImage
75       *            The ota image as a byte array
76       * @param theMcc
77       *            GSM Mobile Country Code
78       * @param theMnc
79       *            GSM Mobile Network Code
80       */
81      public NokiaOperatorLogo(byte[] theOtaImage, int theMcc, int theMnc)
82      {
83          super(SmsConstants.PORT_NOKIA_OPERATOR_LOGO, 0);
84          
85          myBitmap = theOtaImage;
86          myMcc = theMcc;
87          myMnc = theMnc;
88      }
89  
90      /***
91       * Creates a Nokia Operator Logo message
92       * 
93       * @param theOtaImage
94       *            The ota image as a byte array
95       * @param theMcc
96       *            GSM Mobile Country Code
97       * @param theMnc
98       *            GSM Mobile Network Code
99       */
100     public NokiaOperatorLogo(byte[] theOtaImage, int theMcc, int theMnc, boolean discardHeaders)
101     {
102         super(SmsConstants.PORT_NOKIA_OPERATOR_LOGO, 0);
103         
104         myDiscardNokiaHeaders = discardHeaders;
105         myBitmap = theOtaImage;
106         myMcc = theMcc;
107         myMnc = theMnc;
108     }
109 
110     /***
111      * Creates a Nokia Operator Logo message
112      * 
113      * @param theBitmap
114      * @param theOperatorMccMnc
115      *            Operator defined in org.marre.sms.util.GsmOperators
116      */
117     public NokiaOperatorLogo(OtaBitmap theBitmap, int[] theOperatorMccMnc)
118     {
119         this(theBitmap, theOperatorMccMnc[0], theOperatorMccMnc[1]);
120     }
121 
122     /***
123      * Creates a Nokia Operator Logo message
124      * 
125      * @param theOtaImage
126      *            The ota image as a byte array
127      * @param theOperatorMccMnc
128      */
129     public NokiaOperatorLogo(byte[] theOtaImage, int[] theOperatorMccMnc)
130     {
131         this(theOtaImage, theOperatorMccMnc[0], theOperatorMccMnc[1]);
132     }
133 
134     public SmsUserData getUserData()
135     {
136         ByteArrayOutputStream baos = new ByteArrayOutputStream(140);
137 
138         try
139         {
140             if (!myDiscardNokiaHeaders)
141             {
142                 // Header??
143                 baos.write(0x30);
144             }
145 
146             // mcc
147             SmsPduUtil.writeBcdNumber(baos, "" + myMcc);
148             // mnc
149             if (myMnc < 10)
150             {
151                 SmsPduUtil.writeBcdNumber(baos, "0" + myMnc);
152             }
153             else
154             {
155                 SmsPduUtil.writeBcdNumber(baos, "" + myMnc);
156             }
157 
158             if (!myDiscardNokiaHeaders)
159             {
160                 // Start of content?
161                 baos.write(0x0A);
162             }
163             // bitmap
164             baos.write(myBitmap);
165 
166             baos.close();
167         }
168         catch (IOException ex)
169         {
170             // Should not happen!
171         }
172 
173         return new SmsUserData(baos.toByteArray());
174     }
175 }