• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Gallery with wallpapers

Fenyx

Lurker
Hi,

I am having a bit of trouble creating what I think should be a pretty simple app. Here's the description:

The app will look like a gallery of 4-7 images. The user can see and scroll through these images and choose any one of them as his phone's wallpaper by pressing a button on the bottom of the page.

Implementation 1: as a grid of the images. The user then "clicks" on an image to view a larger version of it, and also gets the "Set as Wallpaper" button.
Implementation 2: the top of the screen contains small versions of the images, like a scrollable gallery. The lower part of the screen contains the photo which is now selected and at the bottom there is the "Set Wallpaper" button.
Implementation 3: the images can be positioned 1 below the other at about 50% of their size and under each image there will be a "Set Wallpaper" button. This is not the most elegant but I think it's the easiest way.

I would really appreciate it if someone could give me some tips about how i could achieve any of these implementations.

PS: the app will be free on the market and used to promote my company at a trade show.

Thank you!
 
Ok, figured out the gallery part, and the button part, now I just need to figure out how to make the button set the currently viewed image as the wallpaper.

Here's the code:

Code:
package com.example.hellogallery;

import java.io.IOException;

import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;

public class HelloGallery extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);

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

   Button buttonSetWallpaper = (Button)findViewById(R.id.set);
   
   buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			WallpaperManager myWallpaperManager 
				= WallpaperManager.getInstance(getApplicationContext());
			try {
				[B][U]myWallpaperManager.setResource(R.drawable.image_01)[/U][/B];
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}});
}

public class ImageAdapter extends BaseAdapter {
   int mGalleryItemBackground;
   private Context mContext;

   private Integer[] mImageIds = {
           R.drawable.image_01,
           R.drawable.image_02,
           R.drawable.image_03,
           R.drawable.image_04,
           R.drawable.image_05
   };

   public ImageAdapter(Context c) {
       mContext = c;
       TypedArray a = obtainStyledAttributes(R.styleable.Theme);
       mGalleryItemBackground = a.getResourceId(
         R.styleable.Theme_android_galleryItemBackground,
                   0);
       a.recycle();
   }

   public int getCount() {
       return mImageIds.length;
   }

   public Object getItem(int position) {
       return position;
   }

   public long getItemId(int position) {
       return position;
   }

   public View getView(int position,
       View convertView, ViewGroup parent) {
       ImageView i = new ImageView(mContext);

       i.setImageResource(mImageIds[position]);
       i.setLayoutParams(new Gallery.LayoutParams(384, 320));
       i.setScaleType(ImageView.ScaleType.FIT_XY);
       i.setBackgroundResource(mGalleryItemBackground);

       return i;
   }
}
}

Now I only need to figure out what to replace the R.drawable.image_01 with, so it selects the currently viewed image as the wallpaper.

PS: i basically stitched together 2 programs so I might have gotten it wrong or there may be an easier way to do it.

Please help :D
 
Application Requests isn't the place for this question. You'd get much better results in Application Development or Developer 101.
 
Back
Top Bottom