Trying to custom my action bar after logged in.
authorgumartinm <gustavo@gumartinm.name>
Thu, 21 Jun 2012 08:22:43 +0000 (10:22 +0200)
committergumartinm <gustavo@gumartinm.name>
Thu, 21 Jun 2012 08:22:43 +0000 (10:22 +0200)
WIP

19 files changed:
Android/MobiAdsReloaded/AndroidManifest.xml
Android/MobiAdsReloaded/gen/de/android/mobiads/R.java
Android/MobiAdsReloaded/res/drawable-hdpi/ic_menu_login.png [new file with mode: 0644]
Android/MobiAdsReloaded/res/drawable-hdpi/ic_menu_settings_holo_light.png [new file with mode: 0644]
Android/MobiAdsReloaded/res/drawable-ldpi/ic_menu_login.png [new file with mode: 0644]
Android/MobiAdsReloaded/res/drawable-mdpi/ic_menu_login.png [new file with mode: 0644]
Android/MobiAdsReloaded/res/drawable-mdpi/ic_menu_settings_holo_light.png [new file with mode: 0644]
Android/MobiAdsReloaded/res/drawable-xhdpi/ic_menu_login.png [new file with mode: 0644]
Android/MobiAdsReloaded/res/drawable-xhdpi/ic_menu_settings_holo_light.png [new file with mode: 0644]
Android/MobiAdsReloaded/res/menu/menuads.xml
Android/MobiAdsReloaded/res/menu/selectedmenuads.xml
Android/MobiAdsReloaded/res/values/strings.xml
Android/MobiAdsReloaded/src/de/android/mobiads/MobiAdsLoginActivity.java
Android/MobiAdsReloaded/src/de/android/mobiads/MobiAdsPreferences.java
Android/MobiAdsReloaded/src/de/android/mobiads/MobiAdsSettings.java [new file with mode: 0644]
Android/MobiAdsReloaded/src/de/android/mobiads/MobiAdsTabsActivity.java
Android/MobiAdsReloaded/src/de/android/mobiads/list/MobiAdsLatest.java
Android/MobiAdsReloaded/src/de/android/mobiads/list/MobiAdsLatestList.java
Android/MobiAdsReloaded/src/de/android/mobiads/list/MobiAdsList.java

index 8140b7f..8a7185f 100644 (file)
             android:theme="@android:style/Theme.Holo"
             android:screenOrientation="portrait"
             android:configChanges="touchscreen|keyboard"
-            android:launchMode="standard"
-            android:uiOptions="splitActionBarWhenNarrow" >
+            android:uiOptions="splitActionBarWhenNarrow"
+            android:launchMode="standard">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
+        </activity>            
+        
+        <activity
+            android:label="@string/app_name"
+            android:name=".MobiAdsSettings" 
+            android:screenOrientation="portrait" 
+            android:configChanges="touchscreen|keyboard"
+            android:theme="@android:style/Theme.Holo" 
+            android:launchMode="standard"
+            android:description="@string/app_description">
+            <intent-filter >
+                <action android:name="android.intent.action.MOBIADSSETTINGS" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
         </activity>
         
+        
+        
         <activity
             android:label="@string/app_name"
             android:name=".MobiAdsLoginActivity" 
index 7db5fe9..feca53b 100644 (file)
@@ -12,7 +12,9 @@ public final class R {
     }
     public static final class drawable {
         public static final int ic_launcher=0x7f020000;
-        public static final int wheelnotification=0x7f020001;
+        public static final int ic_menu_login=0x7f020001;
+        public static final int ic_menu_settings_holo_light=0x7f020002;
+        public static final int wheelnotification=0x7f020003;
     }
     public static final class id {
         public static final int ads_entry_icon=0x7f070000;
@@ -22,16 +24,10 @@ public final class R {
         public static final int frameLayout2=0x7f070007;
         public static final int list_frag=0x7f070003;
         public static final int login_button=0x7f070008;
-        public static final int menu_gus=0x7f07000c;
-        public static final int menu_gusa=0x7f07000d;
-        public static final int menu_gusas=0x7f07000e;
-        public static final int menu_gusass=0x7f070010;
-        public static final int menu_gusasss=0x7f07000f;
-        public static final int menu_prueba=0x7f07000b;
-        public static final int menu_save=0x7f07000a;
-        public static final int menuadsremove=0x7f070009;
+        public static final int menuads_login=0x7f070009;
+        public static final int menuads_settings=0x7f07000a;
         public static final int password=0x7f070006;
-        public static final int selectedmenuads=0x7f070011;
+        public static final int selectedmenu_remove=0x7f07000b;
         public static final int username=0x7f070005;
     }
     public static final class layout {
@@ -60,10 +56,12 @@ public final class R {
         public static final int desc=0x7f05001d;
         public static final int encoded_web_service=0x7f05001c;
         public static final int error_dialog_connection_error=0x7f050005;
-        public static final int error_dialog_no_local_ads=0x7f05001f;
+        public static final int error_dialog_no_local_ads=0x7f050021;
         public static final int error_dialog_userpwd_error=0x7f050006;
         public static final int header_bar=0x7f050000;
+        public static final int menuads_login=0x7f050020;
         public static final int menuads_remove=0x7f05001e;
+        public static final int menuads_settings=0x7f05001f;
         public static final int new_ads=0x7f050001;
         public static final int password=0x7f050008;
         public static final int remote_service_content_empty_notification=0x7f050015;
diff --git a/Android/MobiAdsReloaded/res/drawable-hdpi/ic_menu_login.png b/Android/MobiAdsReloaded/res/drawable-hdpi/ic_menu_login.png
new file mode 100644 (file)
index 0000000..afa152b
Binary files /dev/null and b/Android/MobiAdsReloaded/res/drawable-hdpi/ic_menu_login.png differ
diff --git a/Android/MobiAdsReloaded/res/drawable-hdpi/ic_menu_settings_holo_light.png b/Android/MobiAdsReloaded/res/drawable-hdpi/ic_menu_settings_holo_light.png
new file mode 100644 (file)
index 0000000..577e055
Binary files /dev/null and b/Android/MobiAdsReloaded/res/drawable-hdpi/ic_menu_settings_holo_light.png differ
diff --git a/Android/MobiAdsReloaded/res/drawable-ldpi/ic_menu_login.png b/Android/MobiAdsReloaded/res/drawable-ldpi/ic_menu_login.png
new file mode 100644 (file)
index 0000000..d4181de
Binary files /dev/null and b/Android/MobiAdsReloaded/res/drawable-ldpi/ic_menu_login.png differ
diff --git a/Android/MobiAdsReloaded/res/drawable-mdpi/ic_menu_login.png b/Android/MobiAdsReloaded/res/drawable-mdpi/ic_menu_login.png
new file mode 100644 (file)
index 0000000..122ba33
Binary files /dev/null and b/Android/MobiAdsReloaded/res/drawable-mdpi/ic_menu_login.png differ
diff --git a/Android/MobiAdsReloaded/res/drawable-mdpi/ic_menu_settings_holo_light.png b/Android/MobiAdsReloaded/res/drawable-mdpi/ic_menu_settings_holo_light.png
new file mode 100644 (file)
index 0000000..f32a37e
Binary files /dev/null and b/Android/MobiAdsReloaded/res/drawable-mdpi/ic_menu_settings_holo_light.png differ
diff --git a/Android/MobiAdsReloaded/res/drawable-xhdpi/ic_menu_login.png b/Android/MobiAdsReloaded/res/drawable-xhdpi/ic_menu_login.png
new file mode 100644 (file)
index 0000000..5095ed9
Binary files /dev/null and b/Android/MobiAdsReloaded/res/drawable-xhdpi/ic_menu_login.png differ
diff --git a/Android/MobiAdsReloaded/res/drawable-xhdpi/ic_menu_settings_holo_light.png b/Android/MobiAdsReloaded/res/drawable-xhdpi/ic_menu_settings_holo_light.png
new file mode 100644 (file)
index 0000000..aa33c38
Binary files /dev/null and b/Android/MobiAdsReloaded/res/drawable-xhdpi/ic_menu_settings_holo_light.png differ
index 979dae7..0dbe93e 100644 (file)
@@ -1,54 +1,24 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
-      <item android:id="@+id/menuadsremove"
-          android:icon="@android:drawable/ic_menu_upload"
-          android:title="@string/menuads_remove"
-          android:titleCondensed="@string/menuads_remove"
+      <item android:id="@+id/menuads_login"
+          android:icon="@drawable/ic_menu_login"
+          android:title="@string/menuads_login"
+          android:titleCondensed="@string/menuads_login"
           android:showAsAction="ifRoom|withText"
           android:alphabeticShortcut="string"
           android:numericShortcut="string"
           android:checkable="false"
           android:visible="true"
           android:enabled="true" />
-      <item android:id="@+id/menu_save"
-          android:icon="@android:drawable/ic_menu_save"
-          android:title="@string/menuads_remove"
-          android:visible="true"
-          android:showAsAction="ifRoom|withText" />
-      <item android:id="@+id/menu_prueba"
-          android:icon="@android:drawable/ic_menu_upload"
-          android:title="@string/menuads_remove"
-          android:visible="true"
-          android:showAsAction="ifRoom|withText" />
-      <item android:id="@+id/menu_gus"
-          android:icon="@android:drawable/ic_menu_upload"
-          android:title="@string/menuads_remove"
-          android:visible="true"
-          android:showAsAction="ifRoom|withText" />
-      
-      <item android:id="@+id/menu_gusa"
-          android:icon="@android:drawable/ic_menu_upload"
-          android:title="@string/menuads_remove"
-          android:visible="true"
-          android:showAsAction="ifRoom|withText" />
-      <item android:id="@+id/menu_gusas"
-          android:icon="@android:drawable/ic_menu_upload"
-          android:title="@string/menuads_remove"
-          android:visible="true"
-          android:showAsAction="ifRoom|withText" />
       
-      <item android:id="@+id/menu_gusasss"
-          android:icon="@android:drawable/ic_menu_upload"
-          android:title="@string/menuads_remove"
+      <item android:id="@+id/menuads_settings"
+          android:icon="@drawable/ic_menu_settings_holo_light"
+          android:title="@string/menuads_settings"
+          android:titleCondensed="@string/menuads_settings"
           android:visible="true"
-          android:showAsAction="ifRoom|withText" />
-      
-      
-      <item android:id="@+id/menu_gusass"
-          android:icon="@android:drawable/ic_menu_upload"
-          android:title="@string/menuads_remove"
-          android:visible="true"
-          android:showAsAction="ifRoom|withText" /> 
+          android:checkable="false"
+          android:enabled="false"
+          android:showAsAction="ifRoom|withText"/>
      
       <!-- I want overflow menu button if there is no room: android:showAsAction="ifRoom|withText" -->
 </menu>
\ No newline at end of file
index e9c31cf..72d3cf7 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
-      <item android:id="@+id/selectedmenuads"
-          android:icon="@android:drawable/ic_menu_upload"
+      <item android:id="@+id/selectedmenu_remove"
+          android:icon="@android:drawable/ic_menu_delete"
           android:title="@string/menuads_remove"
           android:titleCondensed="@string/menuads_remove"
           android:showAsAction="never"
index c1dd817..1fe577e 100644 (file)
@@ -31,5 +31,7 @@
     <string name="encoded_web_service">UTF-8</string>
     <string name="desc">description</string>
     <string name="menuads_remove">Remove</string>
+    <string name="menuads_settings">Settings</string>
+    <string name="menuads_login">Login</string>
     <string name="error_dialog_no_local_ads">You have no downloaded ads.</string>
 </resources>
\ No newline at end of file
index 5000294..f4b617d 100644 (file)
@@ -52,67 +52,65 @@ public class MobiAdsLoginActivity extends Activity {
                HttpEntity httpEntity = null;
                HttpResponse httpResponse = null;
                final List<NameValuePair> formParams = new ArrayList<NameValuePair>(2);
-               
-               Cookie.setCookie("prueba");
-               
-//             httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, getResources().getString(R.string.encoded_web_service));
-//             httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, getResources().getString(R.string.user_agent_web_service));
-//             httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
-//             //TODO: RESTful Web Service must use JSON instead of signin array :(
-//             formParams.add(new BasicNameValuePair("signin[username]", username.getText().toString()));
-//             formParams.add(new BasicNameValuePair("signin[password]", password.getText().toString()));
-//        try {
-//                     httpEntity = new UrlEncodedFormEntity(formParams, getResources().getString(R.string.encoded_web_service));
-//                     httpPost.setEntity(httpEntity);
-//             httpResponse = httpClient.execute(httpPost);
-//             } catch (UnsupportedEncodingException e) {
-//                     Log.e(TAG, "Error while encoding POST parameters.", e);
-//                     return;
-//             } catch (ClientProtocolException e) {
-//                     Log.e(TAG, "Error while executing HTTP client connection.", e);
-//                     createErrorDialog(R.string.error_dialog_connection_error);
-//                     return;
-//             } catch (IOException e) {
-//                     Log.e(TAG, "Error while executing HTTP client connection.", e);
-//                     createErrorDialog(R.string.error_dialog_connection_error);
-//                     return;
-//             } finally {
-//                     httpClient.getConnectionManager().shutdown();
-//             }
-//        
-//        if (httpResponse != null) {
-//            switch (httpResponse.getStatusLine().getStatusCode()) {
-//             case HttpStatus.SC_OK:
-//                     String cookie = httpResponse.getLastHeader(SETCOOKIEFIELD).getValue();
-//                     if (cookie != null) {
-//                             cookie = cookie.split(";")[0];
-//                                     //Go to the next activity
-//                                     StrictMode.setThreadPolicy(currentPolicy);
-//                                     Cookie.setCookie(cookie);
-//                                     this.finish();
-//                     } else {
-//                             Log.e(TAG, "There must be a weird issue with the server because... There is not cookie!!!!");
-//                             createErrorDialog(R.string.error_dialog_connection_error);
-//                     }
-//                             break;
-//                     case HttpStatus.SC_UNAUTHORIZED:
-//                             //Username or password is incorrect
-//                             createErrorDialog(R.string.error_dialog_userpwd_error);
-//                             break;
-//                     case HttpStatus.SC_BAD_REQUEST:
-//                             //What the heck are you doing?
-//                             createErrorDialog(R.string.error_dialog_userpwd_error);
-//                             break;
-//                     default:
-//                             Log.e(TAG, "Error while retrieving the HTTP status line.");
-//                             createErrorDialog(R.string.error_dialog_connection_error);
-//                             break;
-//            }                
-//        } 
-//        else {
-//             Log.e(TAG, "No response? This should never have happened.");
-//             createErrorDialog(R.string.error_dialog_connection_error);
-//        }
+                               
+               httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, getResources().getString(R.string.encoded_web_service));
+               httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, getResources().getString(R.string.user_agent_web_service));
+               httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
+               //TODO: RESTful Web Service must use JSON instead of signin array :(
+               formParams.add(new BasicNameValuePair("signin[username]", username.getText().toString()));
+               formParams.add(new BasicNameValuePair("signin[password]", password.getText().toString()));
+        try {
+                       httpEntity = new UrlEncodedFormEntity(formParams, getResources().getString(R.string.encoded_web_service));
+                       httpPost.setEntity(httpEntity);
+               httpResponse = httpClient.execute(httpPost);
+               } catch (UnsupportedEncodingException e) {
+                       Log.e(TAG, "Error while encoding POST parameters.", e);
+                       return;
+               } catch (ClientProtocolException e) {
+                       Log.e(TAG, "Error while executing HTTP client connection.", e);
+                       createErrorDialog(R.string.error_dialog_connection_error);
+                       return;
+               } catch (IOException e) {
+                       Log.e(TAG, "Error while executing HTTP client connection.", e);
+                       createErrorDialog(R.string.error_dialog_connection_error);
+                       return;
+               } finally {
+                       httpClient.getConnectionManager().shutdown();
+               }
+        
+        if (httpResponse != null) {
+            switch (httpResponse.getStatusLine().getStatusCode()) {
+               case HttpStatus.SC_OK:
+                       String cookie = httpResponse.getLastHeader(SETCOOKIEFIELD).getValue();
+                       if (cookie != null) {
+                               cookie = cookie.split(";")[0];
+                                       //Go to the next activity
+                                       StrictMode.setThreadPolicy(currentPolicy);
+                                       Cookie.setCookie(cookie);
+                                       this.finish();
+                       } else {
+                               Log.e(TAG, "There must be a weird issue with the server because... There is not cookie!!!!");
+                               createErrorDialog(R.string.error_dialog_connection_error);
+                       }
+                               break;
+                       case HttpStatus.SC_UNAUTHORIZED:
+                               //Username or password is incorrect
+                               createErrorDialog(R.string.error_dialog_userpwd_error);
+                               break;
+                       case HttpStatus.SC_BAD_REQUEST:
+                               //What the heck are you doing?
+                               createErrorDialog(R.string.error_dialog_userpwd_error);
+                               break;
+                       default:
+                               Log.e(TAG, "Error while retrieving the HTTP status line.");
+                               createErrorDialog(R.string.error_dialog_connection_error);
+                               break;
+            }          
+        } 
+        else {
+               Log.e(TAG, "No response? This should never have happened.");
+               createErrorDialog(R.string.error_dialog_connection_error);
+        }
     }
     
     public void onClickLocalAds(View v) {
index e717474..a999c4d 100644 (file)
@@ -1,55 +1,76 @@
 package de.android.mobiads;
 
+import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.ActivityManager.RunningServiceInfo;
+import android.app.FragmentManager;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceFragment;
+import de.android.mobiads.list.MobiAdsList.MobiAdsListFragment;
 
-public class MobiAdsPreferences extends PreferenceFragment {
+public class MobiAdsPreferences extends Activity {
 
        @Override
-    public void onCreate(Bundle savedInstanceState) {
+    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        // Load the preferences from an XML resource
-        addPreferencesFromResource(R.xml.preferences);
+        FragmentManager fm = getFragmentManager();
+
+        // Create the list fragment and add it as our sole content.
+        if (fm.findFragmentById(android.R.id.content) == null) {
+               MobiAdsListFragment list = new MobiAdsListFragment();
+            fm.beginTransaction().add(android.R.id.content, list).commit();
+        }
+        
+        
     }
        
-       @Override 
-       public void onActivityCreated(Bundle savedInstanceState) {
-               super.onActivityCreated(savedInstanceState);
+       public static class MobiAdsPreferencesFragment extends PreferenceFragment  {
+               
+               @Override
+               public void onCreate(Bundle savedInstanceState) {
+                       super.onCreate(savedInstanceState);
+
+                       // Load the preferences from an XML resource
+                       addPreferencesFromResource(R.xml.preferences);
+               }
+       
+               @Override 
+               public void onActivityCreated(Bundle savedInstanceState) {
+                       super.onActivityCreated(savedInstanceState);
         
-        CheckBoxPreference checkBoxPreference = (CheckBoxPreference) findPreference("service_started");
-        checkBoxPreference.setChecked(isMyServiceRunning());
-        checkBoxPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+                       CheckBoxPreference checkBoxPreference = (CheckBoxPreference) findPreference("service_started");
+                       checkBoxPreference.setChecked(isMyServiceRunning());
+                       checkBoxPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                        
-                       @Override
-                       public boolean onPreferenceClick(Preference preference) {
-                               CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
-                               if (checkBoxPreference.isChecked()) {
-                                       Intent intent = new Intent(getActivity(), MobiAdsService.class);
-                                       intent.putExtra("cookie", Cookie.getCookie());
-                                       getActivity().startService(intent);
+                               @Override
+                               public boolean onPreferenceClick(Preference preference) {
+                                       CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
+                                       if (checkBoxPreference.isChecked()) {
+                                               Intent intent = new Intent(getActivity(), MobiAdsService.class);
+                                               intent.putExtra("cookie", Cookie.getCookie());
+                                               getActivity().startService(intent);
+                                       }
+                                       else {
+                                               getActivity().stopService(new Intent(getActivity(), MobiAdsService.class));
+                                       }
+                                       return false;
                                }
-                               else {
-                                       getActivity().stopService(new Intent(getActivity(), MobiAdsService.class));
+                       });
+               }
+       
+               private boolean isMyServiceRunning() {
+                       ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
+                       for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+                               if (MobiAdsService.class.getName().equals(service.service.getClassName())) {
+                                       return true;
                                }
-                               return false;
                        }
-               });
-    }
-       
-       private boolean isMyServiceRunning() {
-        ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
-        for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
-            if (MobiAdsService.class.getName().equals(service.service.getClassName())) {
-                return true;
-            }
-        }
-        return false;
-    }
+                       return false;
+               }
+       }
 }
diff --git a/Android/MobiAdsReloaded/src/de/android/mobiads/MobiAdsSettings.java b/Android/MobiAdsReloaded/src/de/android/mobiads/MobiAdsSettings.java
new file mode 100644 (file)
index 0000000..edaa4bb
--- /dev/null
@@ -0,0 +1,75 @@
+package de.android.mobiads;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningServiceInfo;
+import android.app.FragmentManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceFragment;
+
+public class MobiAdsSettings extends Activity {
+
+       @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        FragmentManager fm = getFragmentManager();
+
+        // Create the list fragment and add it as our sole content.
+        if (fm.findFragmentById(android.R.id.content) == null) {
+               MobiAdsSettingsFragment list = new MobiAdsSettingsFragment();
+            fm.beginTransaction().add(android.R.id.content, list).commit();
+        }
+        
+        
+    }
+       
+       public static class MobiAdsSettingsFragment extends PreferenceFragment  {
+               
+               @Override
+               public void onCreate(Bundle savedInstanceState) {
+                       super.onCreate(savedInstanceState);
+
+                       // Load the preferences from an XML resource
+                       addPreferencesFromResource(R.xml.preferences);
+               }
+       
+               @Override 
+               public void onActivityCreated(Bundle savedInstanceState) {
+                       super.onActivityCreated(savedInstanceState);
+        
+                       CheckBoxPreference checkBoxPreference = (CheckBoxPreference) findPreference("service_started");
+                       checkBoxPreference.setChecked(isMyServiceRunning());
+                       checkBoxPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+                       
+                               @Override
+                               public boolean onPreferenceClick(Preference preference) {
+                                       CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
+                                       if (checkBoxPreference.isChecked()) {
+                                               Intent intent = new Intent(getActivity(), MobiAdsService.class);
+                                               intent.putExtra("cookie", Cookie.getCookie());
+                                               getActivity().startService(intent);
+                                       }
+                                       else {
+                                               getActivity().stopService(new Intent(getActivity(), MobiAdsService.class));
+                                       }
+                                       return false;
+                               }
+                       });
+               }
+       
+               private boolean isMyServiceRunning() {
+                       ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
+                       for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+                               if (MobiAdsService.class.getName().equals(service.service.getClassName())) {
+                                       return true;
+                               }
+                       }
+                       return false;
+               }
+       }
+}
index d40cdec..fb3c27b 100644 (file)
@@ -36,8 +36,8 @@ public class MobiAdsTabsActivity extends Activity {
         if (Cookie.getCookie() != null || isMyServiceRunning()) {
                bar.addTab(bar.newTab()
                     .setText("Control Panel")
-                       .setTabListener(new TabListener<MobiAdsPreferences>(
-                                               this, "controlpanel", MobiAdsPreferences.class)));
+                       .setTabListener(new TabListener<MobiAdsPreferences.MobiAdsPreferencesFragment>(
+                                               this, "controlpanel", MobiAdsPreferences.MobiAdsPreferencesFragment.class)));
         }
                
         bar.addTab(bar.newTab()
@@ -63,8 +63,8 @@ public class MobiAdsTabsActivity extends Activity {
        if ((Cookie.getCookie() != null) && (getActionBar().getTabCount() == 2)) {
                getActionBar().addTab(getActionBar().newTab()
                                .setText("Control Panel")
-                                       .setTabListener(new TabListener<MobiAdsPreferences>(
-                                          this, "controlpanel", MobiAdsPreferences.class)), 1);
+                                       .setTabListener(new TabListener<MobiAdsPreferences.MobiAdsPreferencesFragment>(
+                                          this, "controlpanel", MobiAdsPreferences.MobiAdsPreferencesFragment.class)), 1);
 
         }
     }
index 767a3e7..8160366 100644 (file)
@@ -94,7 +94,7 @@ public class MobiAdsLatest extends Activity {
                                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                                        // Respond to clicks on the actions in the CAB
                                        switch (item.getItemId()) {
-                                       case R.id.menuadsremove:
+                                       case R.id.selectedmenu_remove:
                                                SparseBooleanArray itemsPositions = getListView().getCheckedItemPositions();
                                                Collection<AdsEntry> aux = new ArrayList<AdsEntry>(mAdapter.getCount());
                                                for (int i=0; i< itemsPositions.size(); i++) {
index 3796d71..6fad3e0 100644 (file)
@@ -95,7 +95,7 @@ public class MobiAdsLatestList extends ListActivity implements LoaderManager.Loa
        public boolean onContextItemSelected(MenuItem item) {
                AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
                switch (item.getItemId()) {
-                       case R.id.menuadsremove:
+                       case R.id.selectedmenu_remove:
                                removeAd(info.position);
                                return true;
                        default:
index a33a35e..9b0b868 100644 (file)
@@ -17,6 +17,7 @@ import android.app.LoaderManager;
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.content.AsyncTaskLoader;
+import android.content.ComponentName;
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
@@ -43,21 +44,25 @@ import android.widget.ListView;
 import android.widget.SearchView;
 import android.widget.SearchView.OnQueryTextListener;
 import android.widget.TextView;
+import de.android.mobiads.Cookie;
 import de.android.mobiads.MobiAdsService;
 import de.android.mobiads.R;
 import de.android.mobiads.provider.Indexer;
 
 public class MobiAdsList extends Activity {
+       Menu mMenu;
        
        @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        final ActionBar bar = getActionBar();
+        final ActionBar actionBar = getActionBar();
         
-        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
-        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
-        bar.setTitle(getResources().getString(R.string.header_bar));
+        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
+        actionBar.setTitle(getResources().getString(R.string.header_bar));
+        //actionBar.setDisplayHomeAsUpEnabled(true);
+
         
         
         FragmentManager fm = getFragmentManager();
@@ -73,12 +78,31 @@ public class MobiAdsList extends Activity {
        
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
-               return super.onOptionsItemSelected(item);
+               super.onOptionsItemSelected(item);
+               Intent intent = null;
+        switch (item.getItemId()) {
+            case R.id.menuads_settings:
+               intent = new Intent("android.intent.action.MOBIADS").
+                                                               setComponent(new ComponentName("de.android.mobiads", "de.android.mobiads.MobiAdsSettings"));
+               this.startActivity(intent);
+                return true;
+            case R.id.menuads_login:
+               intent = new Intent("android.intent.action.MOBIADS").
+                               setComponent(new ComponentName("de.android.mobiads", "de.android.mobiads.MobiAdsLoginActivity"));
+               this.startActivity(intent);
+               return true;
+            default:
+                return false;
+        }
        }
        
        @Override
-       public boolean onPrepareOptionsMenu(Menu menu) {
-               return super.onPrepareOptionsMenu(menu);
+       public boolean onPrepareOptionsMenu(Menu menu) {        
+               super.onPrepareOptionsMenu(menu);
+               MenuItem item = menu.findItem(R.id.menuads_settings);
+               item.getIcon().setAlpha(70);    
+               mMenu = menu;
+               return true;
        }
        
        @Override
@@ -89,6 +113,28 @@ public class MobiAdsList extends Activity {
            
            return true;
        }
+       
+       public void onOptionsMenuClosed(Menu menu) {
+        super.onOptionsMenuClosed(menu);
+    }
+       
+       //Si doy al boton pa tras pasa por onCreateOptionsMenu y onPrepareOptionsMenu
+       //Si doy al boton home solo pasa por onResume
+       //:/
+       @Override
+       protected void onResume() {
+               super.onResume();
+               
+//             if (Cookie.getCookie() != null) {
+//                     MenuItem item = mMenu.findItem(R.id.menuads_settings);
+//                     item.getIcon().setAlpha(255);
+//                     item = mMenu.findItem(R.id.menuads_settings);
+//                     item.setEnabled(true);
+//                     item = mMenu.findItem(R.id.menuads_login);
+//                     item.setEnabled(false);
+//                     item.setVisible(false);
+//             }
+       }
 
        
        /**
@@ -269,7 +315,7 @@ public class MobiAdsList extends Activity {
                                    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                                        // Respond to clicks on the actions in the CAB
                                        switch (item.getItemId()) {
-                                           case R.id.selectedmenuads:
+                                           case R.id.selectedmenu_remove:
                                                SparseBooleanArray itemsPositions = getListView().getCheckedItemPositions();
                                                Collection<AdsEntry> aux = new ArrayList<AdsEntry>(mAdapter.getCount());
                                                for (int i=0; i< itemsPositions.size(); i++) {
@@ -328,7 +374,7 @@ public class MobiAdsList extends Activity {
                                setEmptyText("No downloaded Ads.");
 
                                // We have a menu item to show in action bar.
-                               setHasOptionsMenu(false);      
+                               setHasOptionsMenu(true);      
 
 
                                mAdapter = new AdsEntryAdapter(getActivity(), R.layout.ads_entry_list_item);
@@ -374,46 +420,17 @@ public class MobiAdsList extends Activity {
                
                /**
                 * When setHasOptionsMenu(true) we populate the action bar with this menu. It is merged to the
-                * current action bar menu (if there is no)
+                * current action bar menu (if there is no one)
                 */
                @Override 
                public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
                        // Place an action bar item for searching.
                        MenuItem item = menu.add("Search");
                        item.setIcon(android.R.drawable.ic_menu_search);
-                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                        SearchView sv = new SearchView(getActivity());
                        sv.setOnQueryTextListener(this);
                        item.setActionView(sv);
-                       
-                       item = menu.add("Login");
-                       item.setIcon(android.R.drawable.ic_lock_power_off);
-                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-                       
-                       item = menu.add("Login");
-                       item.setIcon(android.R.drawable.ic_lock_power_off);
-                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-                       
-                       item = menu.add("Login");
-                       item.setIcon(android.R.drawable.ic_lock_power_off);
-                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-                       
-                       item = menu.add("Login");
-                       item.setIcon(android.R.drawable.ic_lock_power_off);
-                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-                       
-                       item = menu.add("Login");
-                       item.setIcon(android.R.drawable.ic_lock_power_off);
-                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-                       
-                       item = menu.add("Login");
-                       item.setIcon(android.R.drawable.ic_menu_upload);
-                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-                       
-                       item = menu.add("Login");
-                       item.setIcon(android.R.drawable.ic_lock_power_off);
-                       item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-
                }
 
                @Override