banner



How To Set Wallpaper In Android Studio

New Update Version i.6:

  • Add cropping role
  • Scale bitmap data earlier setting as wallpaper

To create an Android wallpaper app, the cropping picture function is quite necessary. To support multiple Android screens, I have to brand sure to assign the right size pictures to Android wallpaper. In my solution, I will prepare a set of loftier resolution pictures to fit the majority Android screen size. When users choose ane picture show, I will allow them to trim the pictures in a specific aspect ratio to perfectly fit the screen size. For case, I will fix the big image in 1600×1000. When users want to gear up wallpaper on their 480×800 Android phone, I volition provide a cropping tool which can only trims the image in 3:five aspect ratio. Now, let me prove you how I add this cropping characteristic in my Android Wallpaper app.

This Android Wallpaper App case includes four tutorials:

  • Android Wallpaper App Case 1: Android GridView Case in Real App
  • Android Wallpaper App Example ii: Download Epitome with Progress Dialog
  • Android Wallpaper App Example 3: Relieve And Load Downloading File Locally
  • Android Wallpaper App Case iv: Load Images And Set Wallpaper
  • Android Wallpaper App Example 5: Crop Prototype in Android

Adding Cropper Project in Eclipse

I am using the 3rd party Android library to implement the cropping part in my Wallpaper project. When you lot get my source code zilch package, you will find at that place are two projection, one is Cropper library project. Yous follow these steps to import the library project in Eclipse.

  • Choose File -> Import menu detail
  • Select "Annal File" in the popup window
  • Choose the Cropper.nada file in the next window
  • Click finish to import the projection in Eclipse

eclipse-cropper-library-project

import cropper 2

import cropper 3

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
  • Become to Android section and add Cropper library

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-car"         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 Paradigm into Cropper

Now, let'due south talk about how to load the image into cropper image widget. Actually it is very simple. But hither I volition 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 prepare the ingather ratio 2 times wider than the Android screen size resolution attribute ratio. Here is some case 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 = calibration; bitmapOptions.inJustDecodeBounds = simulated; Bitmap wallpaperBitmap = BitmapFactory.decodeStream(fileInputStream, zero, bitmapOptions);  cropImageView = (CropImageView)this.findViewById(R.id.CropImageView); cropImageView.setImageBitmap(imageBitmap); cropImageView.setFixedAspectRatio(true); cropImageView.setAspectRatio(screenWidth * 2, screenHeight);        

crop image

Crop Image to Prepare Wallpaper For Android

Now, users can crop the images past dragging the corner. Afterwards users decide the size and area they want to set equally wallpaper, they can click "set up wallpaper" menu to set up the Android wallpaper. Here is the android case source code to demonstrate how to trim the bitmap from original epitome.

RectF rect = cropImageView.getActualCropRect(); int cropx = (int) rect.left * scale; int cropy = (int) rect.elevation * calibration; int cropw = (int) rect.width() * scale; int croph = (int) rect.meridian() * calibration; Bitmap bitmapSource = BitmapFactory.decodeStream(fileInputStream); concluding Bitmap croppedBitmap = Bitmap.createBitmap(bitmapSource, cropx, cropy, cropw, croph); wallpaperManager.setBitmap(croppedBitmap);        

Endeavor Example Android App

You tin 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 information technology is helpful, please support me past clicking the banner within the app.
Download and Run This Example on Your Android Phone
chart

Get Total Source Code under $half dozen.99


You will get whole Android Wallpaper App source code at $six.99. With this source code, you tin do everything y'all desire:

  • Load your own wallpaper;
  • Monetize the app with your ain AdMob publish id;
  • Use the source code in your ain projection;
  • Publish this app in your android develop account;

How To Set Wallpaper In Android Studio,

Source: https://jmsliu.com/2455/android-crop-image-and-assign-wallpaper.html

Posted by: gallagherthly1983.blogspot.com

0 Response to "How To Set Wallpaper In Android Studio"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel