Help me.
main.xml
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#ff000000"
- >
- <TextView
- id="@+id/tvcurrentwallpaper"
- android:textColor="#ffffffff"
- android:textSize="12dip"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textAlign="center"
- android:text="Current wallpaper"
- android:layout_marginTop="5dip"
- android:textStyle="bold"
- android:layout_marginBottom="5dip"
- />
- <ImageSwitcher
- id="@+id/switcher"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_alignParentLeft="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentBottom="true"
- android:layout_below="@id/tvcurrentwallpaper"
- />
- <Gallery id="@+id/gallery"
- android:background="#55000000"
- android:layout_width="fill_parent"
- android:layout_height="60dip"
- android:layout_alignParentLeft="true"
- android:layout_alignParentRight="true"
- android:gravity="center_vertical"
- android:spacing="16"
- android:layout_above="@+id/btnsetwallpaper"
- />
- <Button
- id="@+id/btnsetwallpaper"
- android:text="Set as wallpaper"
- android:textSize="12dip"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentLeft="true"
- android:textAlign="center"
- />
- <Button
- id="@+id/btnaddpicture"
- android:text="Add picture"
- android:textSize="12dip"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentRight="true"
- android:textAlign="center"
- />
- </RelativeLayout>
Parsed in 0.007 seconds, using GeSHi 1.0.8.4
WallpaperSwitcher.java
Using java Syntax Highlighting
- package maximyudin.wallpaperswitcher;
- import java.util.ArrayList;
- import android.app.*;
- import android.content.*;
- import android.os.Bundle;
- import android.view.*;
- import android.view.animation.AnimationUtils;
- import android.widget.*;
- import android.widget.Gallery.LayoutParams;
- import android.graphics.Bitmap;
- import android.graphics.Canvas;
- import android.graphics.drawable.Drawable;
- public class WallpaperSwitcher extends Activity implements
- ViewSwitcher.ViewFactory, AdapterView.OnItemSelectedListener {
- /** Called when the activity is first created. */
- private ImageSwitcher mISwitcher;
- private int mCurrentSelectedImage;
- private TextView mTVCurrentWallpaper;
- 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]));
- }
- mISwitcher = (ImageSwitcher) findViewById(R.id.switcher);
- mISwitcher.setFactory(this);
- mISwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
- android.R.anim.fade_in));
- mISwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
- android.R.anim.fade_out));
- Gallery gallery = (Gallery) findViewById(R.id.gallery);
- gallery.setAdapter(new ImageAdapter(this));
- gallery.setSelectorSkin(getResources().getDrawable(android.R.drawable.box));
- gallery.setOnItemSelectedListener(this);
- final Button btnSetWallpaper = (Button) findViewById(R.id.btnsetwallpaper);
- btnSetWallpaper.setOnClickListener(btnSetWallpaperListener);
- mTVCurrentWallpaper = (TextView) findViewById(R.id.tvcurrentwallpaper);
- }
- private Button.OnClickListener btnSetWallpaperListener = new Button.OnClickListener()
- {
- public void onClick(View v)
- {
- NotificationManager nm = (NotificationManager)
- getSystemService(NOTIFICATION_SERVICE);
- try {
- Bitmap newwallpaper = Bitmap.createBitmap(320, 240, true);
- Canvas myCanvas = new Canvas(newwallpaper);
- allimages.get(mCurrentSelectedImage).draw(myCanvas);
- setWallpaper(newwallpaper);
- broadcastIntent(new Intent (Intent.WALLPAPER_CHANGED_ACTION));
- nm.notifyWithText(R.id.btnsetwallpaper,
- getText(R.string.newwallpaperset),
- NotificationManager.LENGTH_SHORT, null);
- }
- catch (Exception e) {
- nm.notifyWithText(R.id.btnsetwallpaper,
- getText(R.string.newwallpaperfailed),
- NotificationManager.LENGTH_SHORT, null);
- }
- }
- };
- public void onItemSelected(AdapterView parent, View v, int position, long id) {
- mCurrentSelectedImage = position;
- mISwitcher.setImageDrawable(allimages.get(position));
- mTVCurrentWallpaper.setText(getText(R.string.selectedpicture) + " [ "
- + (mCurrentSelectedImage + 1) + "/" + allimages.size()
- + " ]");
- }
- public void onNothingSelected(AdapterView parent) {
- }
- public View makeView() {
- ImageView i = new ImageView(this);
- i.setBackgroundColor(0xFF000000);
- i.setScaleType(ImageView.ScaleType.FIT_CENTER);
- i.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
- LayoutParams.FILL_PARENT));
- return i;
- }
- public class ImageAdapter extends BaseAdapter {
- private Context mContext;
- public ImageAdapter(Context c) {
- mContext = c;
- }
- public int getCount() {
- return allimages.size();
- }
- public Object getItem(int position) {
- return position;
- }
- public long getItemId(int position) {
- return position;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- ImageView galleryview = new ImageView(mContext);
- galleryview.setImageDrawable(allimages.get(position));
- galleryview.setAdjustViewBounds(true);
- galleryview.setLayoutParams(new Gallery.LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
- galleryview.setBackground(android.R.drawable.picture_frame);
- return galleryview;
- }
- public float getAlpha(boolean focused, int offset) {
- return Math.max(0.2f, 1.0f - (0.2f * Math.abs(offset)));
- }
- public float getScale(boolean focused, int offset) {
- return Math.max(0, offset == 0 ? 1.0f : 0.6f);
- }
- }
- private Integer[] mImageIds = {
- R.drawable.sample_0, R.drawable.sample_1};
- }
Parsed in 0.048 seconds, using GeSHi 1.0.8.4



Too I want to add feature for change wallpaper by timer, e.g. every 15 min it will be change wallpaper from set of pictures 
!!!