66 * published by the Free Software Foundation. Codename One designates this
77 * particular file as subject to the "Classpath" exception as provided
88 * by Oracle in the LICENSE file that accompanied this code.
9- *
9+ *
1010 * This code is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1313 * version 2 for more details (a copy is included in the LICENSE file that
1414 * accompanied this code).
15- *
15+ *
1616 * You should have received a copy of the GNU General Public License version
1717 * 2 along with this work; if not, write to the Free Software Foundation,
1818 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19- *
20- * Please contact Codename One through http://www.codenameone.com/ if you
19+ *
20+ * Please contact Codename One through http://www.codenameone.com/ if you
2121 * need additional information or have any questions.
2222 */
2323package com .codename1 .ads ;
2424
2525import com .codename1 .components .Ads ;
2626import com .codename1 .io .ConnectionRequest ;
27- import com .codename1 .io .Storage ;
2827import com .codename1 .ui .Display ;
2928import com .codename1 .ui .events .ActionEvent ;
30- import com . codename1 . ui . html . HTMLComponent ;
29+
3130import java .io .IOException ;
3231import java .io .InputStream ;
3332
3433/**
3534 * This is an Ad service implementation by InnerActive see:
3635 * http://console.inner-active.com/iamp/publisher/register?ref_id=affiliate_CodenameOne
37- *
36+ *
3837 * @author Chen
3938 */
40- public class InnerActive extends AdsService { // PMD Fix: UnusedPrivateField removed obsolete field
41-
42- private final String REQUEST_URL = "http://m2m1.inner-active.com/simpleM2M/clientRequestHtmlAd" ;
39+ public class InnerActive extends AdsService { // PMD Fix: UnusedPrivateField removed obsolete field
4340
41+ private static final String protocolVersion = "Sm2m-1.5.3" ;
42+ private static boolean testAds = true ;
43+ private final String REQUEST_URL = "http://m2m1.inner-active.com/simpleM2M/clientRequestHtmlAd" ;
4444 //Distribution channel ID
4545 private int po = 559 ;
46-
4746 private String os ;
48-
49- private static final String protocolVersion = "Sm2m-1.5.3" ;
50-
5147 //UDID/IMEI
5248 private String hid ;
53-
5449 private boolean banner = true ;
55-
56- private static boolean testAds = true ;
5750
5851 /**
5952 * Empty constructor of the inner active ads service.
@@ -67,62 +60,63 @@ private static void addParam(ConnectionRequest req, String key, String val) {
6760 }
6861 }
6962
63+ /**
64+ * If true and no ads exists the network will return house holds ads
65+ *
66+ * @param test
67+ */
68+ public static void setTestAds (boolean test ) {
69+ testAds = test ;
70+ }
71+
7072 /**
7173 * Sets this ads type, by default this a banner type.
72- *
74+ *
7375 * @param banner sets the ads to banners or text ads
7476 */
7577 public void setBanner (boolean banner ) {
7678 this .banner = banner ;
7779 }
7880
79- /**
80- * If true and no ads exists the network will return house holds ads
81- * @param test
82- */
83- public static void setTestAds (boolean test ) {
84- testAds = test ;
85- }
86-
8781 /**
8882 * initialize the ads service
8983 */
90- public void initService (Ads ads ){
84+ public void initService (Ads ads ) {
9185 this .os = Display .getInstance ().getPlatformName ();
92- if (os .equals ("and" )){
93- if (banner ){
86+ if (os .equals ("and" )) {
87+ if (banner ) {
9488 po = 559 ;
95- }else {
96- po = 600 ;
89+ } else {
90+ po = 600 ;
9791 }
98- }else if (os .equals ("rim" )){
99- if (banner ){
100- po = 635 ;
101- }else {
102- po = 634 ;
92+ } else if (os .equals ("rim" )) {
93+ if (banner ) {
94+ po = 635 ;
95+ } else {
96+ po = 634 ;
10397 }
104- }else if (os .equals ("ios" )){
105- if (banner ){
106- if (Display .getInstance ().isTablet ()){
107- po = 947 ;
108- }else {
109- po = 642 ;
98+ } else if (os .equals ("ios" )) {
99+ if (banner ) {
100+ if (Display .getInstance ().isTablet ()) {
101+ po = 947 ;
102+ } else {
103+ po = 642 ;
110104 }
111- }else {
112- if (Display .getInstance ().isTablet ()){
113- po = 946 ;
114- }else {
115- po = 632 ;
105+ } else {
106+ if (Display .getInstance ().isTablet ()) {
107+ po = 946 ;
108+ } else {
109+ po = 632 ;
116110 }
117111 }
118- }else if (os .equals ("me" )){
119- if (banner ){
120- po = 551 ;
121- }else {
122- po = 519 ;
112+ } else if (os .equals ("me" )) {
113+ if (banner ) {
114+ po = 551 ;
115+ } else {
116+ po = 519 ;
123117 }
124118 }
125-
119+
126120 String url = REQUEST_URL ;
127121 setPost (false );
128122 setUrl (url );
@@ -131,9 +125,9 @@ public void initService(Ads ads){
131125 //protocol version
132126 String version = protocolVersion ;
133127 addParam (this , "v" , version );
134- if (os .equals ("ios" )){
135- hid = Display .getInstance ().getProperty ("UDID" , null );
136- }else {
128+ if (os .equals ("ios" )) {
129+ hid = Display .getInstance ().getProperty ("UDID" , null );
130+ } else {
137131 hid = Display .getInstance ().getProperty ("IMEI" , null );
138132 }
139133 addParam (this , "hid" , hid );
@@ -144,19 +138,19 @@ public void initService(Ads ads){
144138 addParam (this , "a" , ads .getAge ());
145139 addParam (this , "g" , ads .getGender ());
146140 addParam (this , "c" , ads .getCategory ());
147- addParam (this , "l" , ads .getLocation ());
148-
141+ addParam (this , "l" , ads .getLocation ());
142+
149143 addParam (this , "mn" , Display .getInstance ().getProperty ("MSISDN" , null ));
150- String [] keywords = ads .getKeywords ();
151- if (keywords != null && keywords .length > 0 ){
144+ String [] keywords = ads .getKeywords ();
145+ if (keywords != null && keywords .length > 0 ) {
152146 int klen = keywords .length ;
153147 String k = "" ;
154148 for (int i = 0 ; i < klen ; i ++) {
155149 k += "," + keywords [i ];
156150 }
157151 addParam (this , "k" , k .substring (1 ));
158- }
159- if (testAds ){
152+ }
153+ if (testAds ) {
160154 addParam (this , "test" , "1" );
161155 }
162156 setDuplicateSupported (true );
@@ -172,10 +166,10 @@ protected void readResponse(InputStream input) throws IOException {
172166 while ((len = input .read (buffer )) > 0 ) {
173167 String temp = new String (buffer , 0 , len , "UTF-8" );
174168 int endOfFile = temp .indexOf ("/html>" );
175- if ( endOfFile > 0 ){
169+ if ( endOfFile > 0 ) {
176170 buf .append (temp .toCharArray (), 0 , endOfFile + 6 );
177171 break ;
178- }else {
172+ } else {
179173 buf .append (temp );
180174 }
181175 }
@@ -187,7 +181,7 @@ protected void readResponse(InputStream input) throws IOException {
187181// Storage.getInstance().flushStorageCache();
188182// addParam(this, "cid", cid);
189183// }
190- fireResponseListener (new ActionEvent (s ,ActionEvent .Type .Response ));
184+ fireResponseListener (new ActionEvent (s , ActionEvent .Type .Response ));
191185 }
192186
193187}
0 commit comments