New Update Version 1.6:
- Add cropping function
- Scale bitmap data before setting as wallpaper
To create an Android wallpaper app, the cropping picture function is quite necessary. To support multiple Android screens, I have to make sure to assign the right size pictures to Android wallpaper. In my solution, I will prepare a set of high resolution pictures to fit the majority Android screen size. When users choose one picture, I will let them to trim the pictures in a specific aspect ratio to perfectly fit the screen size. For example, I will prepare the big image in 1600×1000. When users want to set wallpaper on their 480×800 Android phone, I will provide a cropping tool which can only trims the image in 3:5 aspect ratio. Now, let me show you how I add this cropping feature in my Android Wallpaper app.
This Android Wallpaper App example includes four tutorials:
- Android Wallpaper App Example 1: Android GridView Example in Real App
- Android Wallpaper App Example 2: Download Image with Progress Dialog
- Android Wallpaper App Example 3: Save And Load Downloading File Locally
- Android Wallpaper App Example 4: Load Images And Set Wallpaper
- Android Wallpaper App Example 5: Crop Image in Android
Adding Cropper Project in Eclipse
I am using the 3rd party Android library to implement the cropping function in my Wallpaper project. When you get my source code zip package, you will find there are two project, one is Cropper library project. You follow these steps to import the library project in Eclipse.
- Choose File -> Import menu item
- Select “Archive File” in the popup window
- Choose the Cropper.zip file in the next window
- Click finish to import the project in Eclipse
You can use the same steps to import my project in the Eclipse. After that, you need to add Cropper library in Android Wallpaper example project. Here are the steps:
- Right click on Android Wallpaper project
- Select Properties option
- Go to Android section and add Cropper library
Using CropImageView in previewpanel.xml
When users select one picture, I will show the image in the preview panel. In this preview panel, I will provide a crop tool for them to trim the image. Here is the layout xml example source code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.edmodo.cropper.CropImageView xmlns:custom="http://schemas.android.com/apk/res-auto" android:id="@+id/CropImageView" android:layout_below="@+id/adsContainerInPreview" android:layout_above="@+id/adsContainerInPreview2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center"/> </RelativeLayout>
Load Image into Cropper
Now, let’s talk about how to load the image into cropper image widget. Actually it is very simple. But here I will set the crop widget to keep aspect ratio. Android requires the wallpaper resolution 2 times wider than the actually screen resolution. So I have to set the crop ratio 2 times wider than the Android screen size resolution aspect ratio. Here is some example code:
File cacheDir = GlobalClass.instance().getCacheFolder(this); File cacheFile = new File(cacheDir, wallpaperFilePath); InputStream fileInputStream = new FileInputStream(cacheFile); BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inSampleSize = scale; bitmapOptions.inJustDecodeBounds = false; Bitmap wallpaperBitmap = BitmapFactory.decodeStream(fileInputStream, null, bitmapOptions); cropImageView = (CropImageView)this.findViewById(R.id.CropImageView); cropImageView.setImageBitmap(imageBitmap); cropImageView.setFixedAspectRatio(true); cropImageView.setAspectRatio(screenWidth * 2, screenHeight);
Crop Image to Prepare Wallpaper For Android
Now, users can crop the images by dragging the corner. After users decide the size and area they want to set as wallpaper, they can click “set wallpaper” menu to set the Android wallpaper. Here is the android example source code to demonstrate how to trim the bitmap from original image.
RectF rect = cropImageView.getActualCropRect(); int cropx = (int) rect.left * scale; int cropy = (int) rect.top * scale; int cropw = (int) rect.width() * scale; int croph = (int) rect.height() * scale; Bitmap bitmapSource = BitmapFactory.decodeStream(fileInputStream); final Bitmap croppedBitmap = Bitmap.createBitmap(bitmapSource, cropx, cropy, cropw, croph); wallpaperManager.setBitmap(croppedBitmap);
Try Example Android App
You can download and install this android app by click the following link, or scan the following QR code to download and install on your android phone simply. If you feel it is helpful, please support me by clicking the banner inside the app.
Download and Run This Example on Your Android Phone
Get Full Source Code under $6.99
You will get whole Android Wallpaper App source code at $6.99. With this source code, you can do everything you want:
- Load your own wallpaper;
- Monetize the app with your own AdMob publish id;
- Use the source code in your own project;
- Publish this app in your android develop account;
Hi james,
Very Good U did IT :-D, How to get the link of download ? (given that I already buy in step 4) ?
Thanks Man 🙂
No in fact I will buy you again because it’s a great job 😉
Why does in zip file, there is a folder cropper ?
Hello,
The cropper zip is the library project. You need to import both of them in your eclipse work space.
James
Hi,
You may get some error messages. I think it is because missing of Google Play service lib. If you don’t need the Admob ads banner, you can delete all adview, adrequest stuff.
If I delete it I can have money then :p
Instead, you can replace with your own admob id and monetize your app
Ok, I will try to do sthg and I keep you abreast 😉
I still have the problem :
http://img4.hostingpics.net/pics/704463google.png
What do u think I need to do ?
In the androidmanifest.xml I think that this error generate ad errors
http://img4.hostingpics.net/pics/588879manifest.png
Hello,
If you want to integrate admob in your app, you’d better to check this post:
http://jmsliu.com/2085/add-admob-with-google-play-service.html
OH YEAH IT’S COMPILE WITHOUT ERROR NOW , VERY GOOD DUDE ! 😀 AWESOME 🙂
Just a last answer how to display the ad because I ha an error :p but I think it’s easy to resolve, I tried but I didn’t success to resolve :p Check the picture in link pls :p
http://img11.hostingpics.net/pics/680460Screenshot20140917143700.png
I found it ! 😉
You need to change
to
good job
com.google.ads.AdActivity
to
com.google.android.gms.ads.AdActivity
You are great!!!
Hi James,
Given that I already paid, can you send me the link for the update 1.6 package by email please.
Thank you 🙂
What’s your email?
I don’t realy want to publish il in public :p Nevertheless, when I post this comment I put my email, can you see it ? :p
Thanks
Hello,
Sent to you already. Please check your email.
Thank you very much, I just receive it 🙂
i need this source code bt i haven’t paypal account …can u please sent ur account number i ll transfer u..thanks for advance
Hello,
As long as you have credit card, you can pay through paypal.
Hi! Say me please this wallpaper app can use images as animated Gif? Maybe html ?
The wallpaper only supports png and jpg. For Android animated wallpaper, we have to create new apps.
i want a link for download cropper.zip can you send me bro.
thank you.
Please send me a message via contact us with your real email. I will send your cropper.zip.
Hello I bought your code but I cannot run the ads. It gives me the error “There was a problem getting an ad response. ErrorCode: 0”. I changed the error in manifest so this is not the problem.
In addition, I tried to install the example but I cannot. Could you please fix it?
What do you mean “I tried to install the example”? You are able to debug the app in your device, aren’t you? After you build an apk file, you’d better uninstall the debug version on your device, then install the released apk file.
The example that you give in your post, is not working in my device.
Anyway could you help me with the admob problem?
Finally I could fix it just copying the code in the banner-example code that admob provides.
hi there,
On 21-4-2015 i had paid for this Android Wallpaper App full source code
twice by mistake,But still my Purchase Failed to Download and i was unable to Get this Source Code.
In other words…I have paid $6.99 + $6.99 to you…and i have nothing.
Please check this Problem and i am requesting you to solve this
problem and Refund my Money back.
Regards,
Akash.
I have made a refund for one of the payment. And I already sent the source code to your email.
Thanks a lot bro,
Regards,
Akash.
Thanks a lot bro
hi James, thanks for the template. I paid your fee and I did get the the main project.zip but I did not receive the cropper.zip that you said was included. Would you be able to email me a copy please? Thank you!
Hello,
I sent the missing library to your email.
Best Regards
James
amazing work . But i want link to cropper .zip file .So that i can use it . Please send me the Link.
Hello,
Please send me an email and I will reply you with the zip file.
Thanks
Hi James I see u are doing a great job here. OK am really new to android development and I wanna created a wallpaper app. Ok I have android studio and eclipse on my PC . it looks like d tutorial is broken into parts(example) can u compile d whole source code into one downloadable file so I can download and import directly to my eclipse . to avoid concussion cuz am kind of confused looking at it example by example. Thanks
Hello Dankeyz,
You can get the whole source code by clicking the PayPal pay button.
Ok which of d pay pal button? Is it d one for expample 1,2,3,4, or 5?
And pls how can I set image wallpaper from my resources drawable directly instead downloading I want something completely off line. Thanks in advance
Hello Dankeyz,
If you want to load offline image, please check the tutorial 1: Android GridView Example in Real Wallpaper App
Ok thanks for ur reply. But what I dont understand is I want create a wallpaper app. In my eclipse project and u have d source code broken can I get d full source code download to important in my eclipse or is there a way to join or merge each example together to get work. Thanks
Ok which of d pay pal button? Is it d one for expample 1,2,3,4, or 5?
Hello I just paid for d source code but it refuses to download. How can I get it?
Hi,
My website is too busy and the download service goes unfunctional. Now everything is going well. For your purchased source code, I will send it to your email.
Thanks
Ok I got d sour code thanks. It was two zip file can I import it directly to eclipse
Hello James pls do I have to buy souce code for example 2,3,4 or d source code for example 5 covers all
How to use it for android studio ?
No Android Studio version available. Too busy to create a new one.
My android studio version is 3.1.4 will your code sample still work on mine if I buy it
The example code is developed in Eclipse, not android studio.