Admob adview in live wallpaper settings screen?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Admob adview in live wallpaper settings screen?

Postby jgittins » Sat Oct 23, 2010 12:06 pm

I've seen the Mario live wallpaper uses admob adds in the settings screen but I haven't been able to do it myself. If I put an adview in the settings.xml I get a class cast exception. Can anyone explain how it's done?
jgittins
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Oct 12, 2010 4:26 pm

Top

Re: Admob adview in live wallpaper settings screen?

Postby Jug6ernaut » Mon Oct 25, 2010 2:43 pm

I also am very interested in this, just adding it to the settings.xml will not work bc your trying to add a view to as a preference. I would guess the view would have to be adapted into a custom preference, but i havent been able to do this yet.
Jug6ernaut
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Jun 17, 2010 7:00 pm

Re: Admob adview in live wallpaper settings screen?

Postby jgittins » Mon Oct 25, 2010 7:09 pm

I have managed to achieve the effect by nesting my settings activity inside a tab activity that uses a normal layout with an admob adview at the top. Then I just set android:visibility="invisible" and android:layout_height="1dp" on the tab widget in the layout.xml to hide the tab headings.
jgittins
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Oct 12, 2010 4:26 pm

Re: Admob adview in live wallpaper settings screen?

Postby Jug6ernaut » Mon Oct 25, 2010 7:29 pm

Forgive me for being imposing, but could you show me a code example of this?, im not quite sure how to go about the "nesting" of the settings activity.

Afterwards did you have to change the androd:settingsactivity pointer to the new activity?
Jug6ernaut
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Jun 17, 2010 7:00 pm

Re: Admob adview in live wallpaper settings screen?

Postby jgittins » Mon Oct 25, 2010 7:58 pm

Yes change the android:settingsactivity to point at the tab activity. Make sure you have both the normal preferences activity and the new tab activity in your android manifest.

Then this is the code you put in the tab activity class.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class SettingsTabActivity extends TabActivity {
  2.        
  3.         public void onCreate(Bundle savedInstanceState) {
  4.             super.onCreate(savedInstanceState);
  5.             setContentView(R.layout.tablayout);
  6.            
  7.             TabHost tabHost = getTabHost();  // The activity TabHost
  8.             TabHost.TabSpec spec;  // Resusable TabSpec for each tab
  9.             Intent intent;  // Reusable Intent for each tab
  10.  
  11.             // Create an Intent for the regular live wallpaper preferences activity
  12.             intent = new Intent().setClass(this, Preferences.class);
  13.  
  14.             // Initialize a TabSpec and set the intent
  15.             spec = tabHost.newTabSpec("TabTitle").setContent(intent);
  16.             spec.setIndicator("TabTitle");
  17.            
  18.             tabHost.addTab(spec);
  19.  
  20.             tabHost.setCurrentTab(0);      
  21.         }
  22. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


And this is the tablayout.xml code. Notice how I set visibility to invisible and height = 1dp on the tabWidget, this is important to make it not look like it is really a tab.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  4.         xmlns:myapp="http://schemas.android.com/apk/res/*your package name goes here for admob*"
  5.         android:id="@android:id/tabhost" android:layout_width="fill_parent"
  6.         android:layout_height="fill_parent">
  7.  
  8.         <LinearLayout android:orientation="vertical"
  9.                 android:layout_width="fill_parent" android:layout_height="fill_parent">
  10.  
  11.                 <com.admob.android.ads.AdView android:id="@+id/ad"
  12.                         android:layout_width="fill_parent" android:layout_height="wrap_content"
  13.                         myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
  14.                         myapp:secondaryTextColor="#CCCCCC" />
  15.  
  16.                 <TabWidget android:id="@android:id/tabs"
  17.                         android:layout_width="fill_parent" android:layout_height="1dp"
  18.                         android:tabStripEnabled="false" android:visibility="invisible" />
  19.  
  20.                 <FrameLayout android:id="@android:id/tabcontent"
  21.                         android:layout_width="fill_parent" android:layout_height="fill_parent"
  22.                         android:padding="1dp" />
  23.         </LinearLayout>
  24. </TabHost>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
jgittins
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Oct 12, 2010 4:26 pm

Re: Admob adview in live wallpaper settings screen?

Postby Jug6ernaut » Mon Oct 25, 2010 8:09 pm

Wow your awesome :), thank you so much! Ill try it out and report back.
Jug6ernaut
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Jun 17, 2010 7:00 pm

Top

Re: Admob adview in live wallpaper settings screen?

Postby Jug6ernaut » Tue Oct 26, 2010 1:29 am

I got it working, i had to add something else to the manifest.xml but beyond that your code worked prefectly, thanks again xD.
Jug6ernaut
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Jun 17, 2010 7:00 pm

Re: Admob adview in live wallpaper settings screen?

Postby Jug6ernaut » Wed Oct 27, 2010 7:39 pm

I have but one complaint with this, it works perfectly, except when you got a sub-preference teh add is no longer shown. Normally this would be fine but if the user goes to fast the add wont have time to be shown at all.
Jug6ernaut
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Jun 17, 2010 7:00 pm

Re: Admob adview in live wallpaper settings screen?

Postby jgittins » Thu Oct 28, 2010 2:59 pm

I'm not sure what you mean by sub-preference. If you mean another screen of preferences then you could put that inside a second tabActivity in exactly the same way.
jgittins
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Oct 12, 2010 4:26 pm

Re: Admob adview in live wallpaper settings screen?

Postby Jug6ernaut » Fri Oct 29, 2010 4:14 am

jgittins wrote:I'm not sure what you mean by sub-preference. If you mean another screen of preferences then you could put that inside a second tabActivity in exactly the same way.


lol no i mean like preference categories, but its not that big of an issue.
Jug6ernaut
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Jun 17, 2010 7:00 pm

Re: Admob adview in live wallpaper settings screen?

Postby ckim06 » Fri Dec 17, 2010 7:43 am

I can't seem to get this to work, i get the following error,

12-17 06:40:59.450: ERROR/AndroidRuntime(275): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.Christmas/java.util.prefs.Preferences}; have you declared this activity in your AndroidManifest.xml?

then in the manifest I have,
<activity android:label="@string/wallpaper_tab_settings" android:name="TabSettings" android:exported="true">

Can anyone help me out?
ckim06
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Dec 17, 2010 7:36 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests