changing system wallpaper

by Bam » Sat, 14 Mar 2009 02:11:12 GMT


Sponsored Links
 ello guys,
i have a problem. when i select an image from an
image switcher , i want to set this selected image as the background
of my application when i click on a button .. how can i do this.. here
is a sample of my codes.

thanxs in Advance.
----------------------------------------------------------------------

package com.androwall;

import java.util.ArrayList;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import android.widget.Gallery.LayoutParams;


public class androwall extends Activity implements
ViewSwitcher.ViewFactory, AdapterView.OnItemSelectedListener {

/** Called when the activity is first created. */

private int mCurrentSelectedImage;
private TextView mTVCurrentWallpaper;
private Boolean bool = true;

private ArrayList<Drawable> allimages = new ArrayList<Drawable>
();

@Override
public void onCreate(Bundle icicle)

{
super.onCreate(icicle);

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView
(R.layout.main);

for (int i = 0; i < mImageIds.length; i++)
{
allimages.add(this.getResources().getDrawable(mImageIds
[i]));
}


mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));

Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));

gallery.setOnItemSelectedListener(this);

final Button btnSetWallpaper = (Button) findViewById
(R.id.btnsetwallpaper);
btnSetWallpaper.setOnClickListener
(btnSetWallpaperListener);


}//end of onCreate


//when clicked on button set as wallpaper
private Button.OnClickListener btnSetWallpaperListener = new
Button.OnClickListener()
{
public void onClick(View v)
{
NotificationManager nm = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
try
{


Bitmap newwallpaper = Bitmap.createBitmap
(newwallpaper, 320, 240, mCurrentSelectedImage, mCurrentSelectedImage,
null, true);



Canvas myCanvas = new Canvas(newwallpaper);
allimages.get(mCurrentSelectedImage).draw
(myCanvas);
setWallpaper(newwallpaper);



broadcastIntent (new Intent
(Intent.ACTION_WALLPAPER_CHANGED)); //added by arvish for test

}
catch (Exception e)



Other Threads

1. How to make Big button (text)

I using eclipse to develop an app.  In eclipse I set the text size for
a button and in the emulator they look as I expect much bigger than
default.  But when I create the apk and load it into my Motorola Droid
the text size looks like the default, no matter what I set it to in
the project they are the same size.

I'd appreciate any help in tracking down what I'm doing wrong.

Joe

-- 

2. change TextView Dynamically

can  i change a TextView dynamically....

-- 

3. Latest Android ADT Preference Pane Not appearing in Eclipse

4. getting soft keyboard to show for input field in a webview

5. Pick events from calendar?

6. m3u playlist support in USB/MSC mode

7. Questions about program structure for real-time games