I am wondering if someone can help. I would like to create a simple wallpaper test app. I have tried a few things with no success. Eventually, I started playing with gallery codes and have a few achievements. But ... I am not sure how to attach a wallpaper function to the gallery. I am new to all this (I am only a few months into learning Droid apps with eclipse) is there someplace where I can find complete Java coding and possibly the XML files for a working wallpaper? I cannot build from scratch but I am getting better reading the source code creating buttons etc.
Another option is how can I insert a save as wallpaper function to the working gallery I have? I am assuming I can set a long press function but I am not sure how to go about that either. I do have a tutorial for creating long presses but I am not sure about the proper Java setup to accompany this.
Any help will be appreciated. Keep in mind I am new to both Java and Android coding. In other words keep it as simple as possible please. Or if someone has a simple wallpaper app and they don't mind sharing the source code ... that would help immensely.
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
if(imagePath!=null){
System.out.println("Hi I am try to open Bit map");
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
wallpaperManager.setBitmap(useThisBitmap);
................................................. if you have image URI then use this
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);
.............. Let me know if there is any issue .
If you have image URL then use
WallpaperManager wpm = WallpaperManager.getInstance(context);
InputStream ins = new URL("absolute/path/of/image").openStream();
wpm.setStream(ins);
If you have image URI then use
WallpaperManager wpm = WallpaperManager.getInstance(context);
wpm.setResource(Uri.of.image);
If you want to use wallpaper as your app's background, then you have to use Wallpaper theme & call the Intent.Action_Set_Wallpaper to pick wallpaper.
public void onCreate(Bundle savedInstanceState) {
Activity.this.setTheme(android.R.style.Theme_Wallpaper);
super.onCreate(savedInstanceState);
setContentView(/*some layout*/);
}
//on button click
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
Related
Is there any good way to use frame by frame animation AnimationDrawable using UIL library. AnimationDrawable accept only BitmpaDrawable . Is there any way to convert quickly to bitmaps my images or any maybe there is method like imageLoader.getBitmap, I haven't find anything like that.
Please help , I would be very grateful for any help .
Edit I have my images in assets folder. Maybe there any way to get bitmap from cache or something else . I need open new activity , maybe several times . I need to show animation from files , but if I use decode it takes a lot of time to decode them . Please suggest something
If your images are resources you can use this for obtain Bitmap:
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_resource);
else, if you want donwload the image you can use this:
String name = c.getString(url);
URL urlAux = new URL(name);
ImageView prueba = (ImageView)v.findViewById(R.id.iv_prueba);
if (prueba != null) {
Bitmap bitmap =
BitmapFactory.decodeStream(urlAux.openConnection().getInputStream());
prueba.setImageBitmap(bitmap);
}
Hope it helps you.
Having kind of an issue with initiating 9patch drawables from input streams. I need to skin my app and need to download skin elements and images from a web service.
Sought through a reasonable amount of resources both in SO and android dev guides, but none seem to work for me.
Setting a drawable from a resource does handle 9patch properly so logically the smarts to do so is there, but for some reason the following code, which I derived from the android sources itself, fails to handle 9patch properly
Rect pad = new Rect();
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScreenDensity = DisplayMetrics.DENSITY_DEFAULT;
Bitmap bm = BitmapFactory.decodeResourceStream(resources, typedValue, new FileInputStream(path), pad, opts);
if (bm != null) {
byte[] np = bm.getNinePatchChunk();
if (np == null || !NinePatch.isNinePatchChunk(np)) {
np = null;
pad = null;
}
if (np != null) {
drawable = new NinePatchDrawable(resources, bm, np, pad, path);
} else {
drawable = new BitmapDrawable(resources, bm);
}
}
I have changed the input source to be the one of my files (FileInputStream(path)), in the android sources it is the input source initiated on resource images.
This code always returns BitmapDrawable even if the input image is a 9-patch.
Does anyone succeed actually getting this functionality working?
I'd appreciate any help or hint towards a solution.
Thank you in advance.
Okay, the solution is that there's no solution here, because 9 patch requires nine patch chunk as an array which is being generated at compile time. Obviously we do not have a compile phase when loading images from a web resource.
To Android engineers - maybe future release of android SDKs will be able to generate the nine patch chunk at run time.
I've created this gist to create 9patches at runtime: https://gist.github.com/4391807
I am receiving images from a URL and they display on the emulator but when I use a device the default image is shown. Im not totally sure which part of the code you require so Ill add more on request:
pubImage = extras.getString("pubImage");
ImageView ivimage = (ImageView) findViewById(R.id.image);
try{
ivimage.setImageDrawable(grabImageDrawableFromUrl(pubImage));
Log.d(TAG, pubImage);
}catch(Exception e){
e.printStackTrace();
}
I use Prime for all of my image loading in Android. If you were using it then you would not have to worry about issues like this.
try this...
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
ivimage.setImageDrawable(drawable);
if you still not get solution then use Universal Image Loader
Look at the answer to this question, it seems as if you might be missing a few details, but perhaps you should paste grabImageDrawableFromUrl() either way.
When it comes to making Android live wallpaper, what are the things that are exactly needed. So far I could gist as WallpaperService.Engine, SurfaceView, some major changes in Android.manifest and xml/string.xml apart from this one png drawble (i think this may be optional if i use paint).
And what else do I need to develop whole different logic for the animation to happen? is it with mathematical calculations always? I am very keen about making different kind of live wallpaper. but i am not in the right track i think.
Please suggest me some way out to right direction summarizing me what all i need so that i can make any kind of live wallpaper.
Can somebody please summarize what all is needed for live wall paper.
Thanks in Advance.
Hi you can use this code if You have Image path.
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
if(imagePath!=null){
System.out.println("Hi I am try to open Bit map");
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
wallpaperManager.setBitmap(useThisBitmap);
................................................. if you have image URI then use this
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);
.............. Let me know if there is any issue .
Yes, you need to use a different approach for live wallpaper than "normal" animation in Android. The standard approach is to make a self-rescheduling runnable that draws to canvas.
In answer to one of your specific questions: no, you do not need to limit yourself to mathematical calculations; you can use bitmaps/sprites if you choose, but you will need to animate them yourself.
Your best place to start is the resources in the SDK:
http://developer.android.com/resources/articles/live-wallpapers.html
http://developer.android.com/resources/samples/CubeLiveWallpaper/index.html
I take a picture with the camera using
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult( intent, 22 );
When the activity completes, I write the bitmap picture out to a PNG file.
java.io.FileOutputStream out = openFileOutput("myfile.png", Context.MODE_PRIVATE);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
That goes OK, and I can see the file is created in my app private data space.
I'm having difficulty when I later want to display that image using an ImageView.
Can anyone suggest code to do this?
If I try to create a File with path separators in, it fails.
If I try to create a Uri from a name without separators, that fails.
I can open the file OK using:
java.io.FileInputStream in = openFileInput("myfile.png");
But that doesn't give me the Uri I need to set an image with
iv.setImageURI(u)
Summary: I have the picture in a png file in private app data. What's the code to set that into an ImageView?
Thanks.
Try BitmapFactory.decodeFile() and then setImageBitmap() on the ImageView.
Also possible:
java.io.FileInputStream in = openFileInput("myfile.png");
iv.setImageBitmap(BitmapFactory.decodeStream(in));
iv.setImageURI(Uri.fromFile(in));
Why not this way:
ImageView MyImageView = (ImageView)findViewById(R.id.imageView1);
Drawable d = Drawable.createFromPath( PATH TO FILE );
MyImageView.setImageDrawable(d);
bitmap = BitmapFactory.decodeFile(imageInSD);
There should be no difference between decodeStream() and decodeFile(). decodeFile() method opens an inputstream and calls decodeStream(). This was already answered at this link