How To Make A Wallpaper App

How To Make A Wallpaper App

At present I’m will present Methods How To Make wallpaper App using Picasa Net Albums API. On this educational observe, the likelihood is you may work out recommendations on the best way to coordinate fully totally different Android components like a splash present, navigation drawer, grid view, volley library in a single app.

How To Make A Wallpaper App

As this educational observe seems to be terribly protracted, I separated this into two sections. Inside the primary half, we do all basic setup like making the Picasa collections, arranging the gear define and making the Android enterprise and speak with some reusable segments required for the gear. Contained in the second half, the precise utilization of the gear begins the place we add one after the alternative module to the gear like a navigation drawer, grid view, volley library and assorted points to complete the gear.

 

1. Mandatory how  to make a Wallpaper App

As this utility is a whole utility we now have to coordinate fairly a couple of components collectively. It could be preferred inside the event you expertise beneath articles earlier than transferring into this educational observe as these concepts are basic organizing hinders this utility.

1. Directions to execute Android Splash Present This discloses recommendations on the best way so as to add a splash present to your utility when the gear ought to make few HTTP calls and convey fairly a couple of info earlier than going into precise utility stream.
2. Android Sliding Menu using Navigation Drawer This textual content material helps in together with a slider menu for the gear the place we’re able to point out a rundown of packages for backdrops.
3. Android working with Volley Library We make the most of volley to make deal with calls like downloading the JSON and images. Likewise, one totally different foremost favorable place of using volley is image retailer which makes the gear speedier.

4. Android Full-Present Picture Slider with Swipe and Pinch Zoom Gestures That is one totally different important article helps in making the gear’s precept Grid View present the place the thumbnail sees of every backdrop will doable be confirmed in a framework variety.

2. Google’s Picasa Net Albums API

The foremost and troublesome errand on this utility is organizing the server aspect components like an administrator board to cope with your backdrop info by giving doc swap totally different and assorted points. For this, it is important to likewise able to code in a lot of developments like HTML, CSS, JSP, PHP or MySQL which is as quickly as further a tricky course of for android amateurs.

So I chose Picasa Net Albums as a hearty reply to this. Picasa net collections are freed from value and vitally it uncovered an API (JSON and XML) for engineers. You may expertise Picasa Net Albums Information API to look out concerning the API’s uncovered.

We’re significantly eager on the following API requires this utility which does not require any validation as we characteristic out be taught duties merely on the open assortment

 

1. Demand a rundown of collections

(username must be supplanted alongside together with your Google username)

https://picasaweb.google.com/data/feed/api/user/username?kind=album&alt=json

2. Rundown images as of late transferred

(username must be supplanted alongside together with your Google username)

“https://picasaweb.google.com/data/feed/api/user/username?kind=photo&alt=jsoninterface/client/username?kind=photo&alt=json”

3. Rundown images in a gaggle

(album must be supplanted with exact assortment id which may uncover in collections response)

https://picasaweb.google.com/data/feed/api/user/username/albumid/albumid?alt=json

On the off likelihood that it is advisable to supply additional picks like giving the patron to comment, alter or erase selections you need to execute verification as acknowledged contained in the report.

Notion: alt parameter chooses the kind of response we predict every JSON or XML. Cross alt=json contained in the URL to get the response in JSON arranges.

3. Together with backdrops for Picasa Net Albums

Ahead of starting the Methods to make a Wallpapers App Utilizing Android Studio, we’ll embrace few Wallpapers in Picasa collections for testing. You may login into Picasa using your Google account. Take after beneath ventures to make collections and backdrops in Picasa net collections.

1. Login into Picasa.

(Contained in the occasion that you just diverted to your Google+ account, faucet on

Click on on on correct proper right here to backpedal to Picasa Net Albums to search out as soon as extra to Picasa Net or run with Google+ on the off likelihood that you just agreeable)

2. Faucet on the swap and enter your assortment title.

These collections go about as backdrop packages in our utility which is ready to doable be recorded in route cupboard menu.

Case: Animals, Automobiles, Meals, Motion pictures, Conventional and so forth.,

3. Every time you made the gathering, swap few backdrops to the gathering.

Guarantee that you just transferring the backdrops with good excessive willpower.

4. Presently make the gathering permeability as Public by tapping on Edit be a part of confirmed on the suitable.

“Uncover: Must you do not make your assortment as open, it will not be obtainable by your android utility. Because of it have been likelihood is you may’t see the gathering contained in the JSON response.”

5. Take after second, third and fourth means to make only a few additional collections and backdrops.

 

4. Designing The App

The plan of this utility is quite common with not very many shading mixes.

Widespread, it incorporates following segments.

1. Route cupboard (Slider Menu) to a degree out backdrop classifications.

2. Framework sees a present to a degree out the thumbnail of backdrops below a category.

3. Your complete-screen perspective of backdrop Set As Wallpaper and Purchase Wallpaper picks.

4. Settings present to design Picasa username, a variety of segments in the group and current image index.

 

 

 

5. Downloading Volley Library (volley.jar)

To make calls to Picasa API we’ll use Volley Library as a substitute of utilizing the java library talked about contained in the documentation.

On this enterprise, it performs a significant place in caching the photographs.

Purchase the precompiled volley.jar

Now it’s time to begin the android app. I’m naming this app as MT Wallpapers.

6. Creating New Enterprise

1. In Eclipse create a mannequin new enterprise by navigating to

File ⇒ New ⇒ Android Utility Enterprise and fill required particulars.

I gave my enterprise package deal deal deal title as com.musaiftech.mtwallpaper

2. As shortly as a result of the enterprise is created paste the volley.jar in the libs folder.

3. Purchase the belongings and place them in your enterprise’s respective folders.

On this downloaded zip you’ll uncover splash present background picture and fully totally different app icons.

4. Now add beneath useful helpful useful resource values in strings.xmlcolours.xml. These values are utilized in various locations contained in the enterprise.

strings.xml
strings.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<resources>

<string name=”app_name”>MT Wallpapers</string>
<string name=”action_settings”>Settings</string>
<string name=”nav_drawer_recently_added”>Recently Added</string>
<string name=”toast_saved”>Wallpaper saved to #</string>
<string name=”toast_saved_failed”>Sorry! Failed to save wallpaper</string>
<string name=”toast_wallpaper_set”>Wallpapaer updated!</string>
<string name=”toast_wallpaper_set_failed”>Sorry! Unable to set wallpaper</string>
<string name=”splash_error”>Unable to download wallpapers. Verify your google\’s user name in settings or device doesn\’t have internet connection!</string>
<string name=”set_wallpaper”>Set</string>
<string name=”download_wallpaper”>Download</string>
<string name=”msg_unknown_error”>Sorry! Unknown error occurred.</string>
<string name=”msg_wall_fetch_error”>Sorry! Unable to fetch wallpaper(s). Verify app settings or device doesn\’t have internet connection.</string>
<string name=”toast_enter_google_username”>Please enter google username</string>
<string name=”toast_enter_valid_grid_columns”>Please enter valid number of columns</string>
<string name=”toast_enter_gallery_name”>Please enter gallery directory name</string>
<string name=”lbl_google_username”>Google username</string>
<string name=”lbl_no_grid_columns”>Number of grid columns</string>
<string name=”lbl_gallery_name”>Gallery directory name</string>
<string name=”lbl_btn_save”>Save</string>

</resources>

colours.xml
colours.xml

<?xmlversion=”1.0″encoding=”utf-8″?>
<resources>
<colorname=”list_item_title”>#d7ddee</color>
<colorname=”list_background”>#1a1b1d</color>
<colorname=”list_background_pressed”>#131315</color>
<colorname=”list_divider”>#272727</color>
<colorname=”counter_text_bg”>#626262</color>
<colorname=”counter_text_color”>#c5c4c4</color>
<colorname=”black”>#000000</color>
<colorname=”grid_bg”>#000000</color>
<colorname=”grid_item_bg”>#1a1b1d</color>
<colorname=”action_bar”>#141416</color>
<colorname=”action_bar_title”>#ffffff</color>
<colorname=”white”>#ffffff</color>
<colorname=”settings_label”>#323232</color>
</resources>

5. Now create 5 packages named apphelperutil and picasa.mannequin below src folder.
Right, Click on on on src ⇒ New ⇒ Bundle deal.

com.musaiftech.mtwallpaper.app
com.musaiftech.mtwallpaper.helper
com.musaiftech.mtwallpaper.picasa.mannequin
com.musaiftech.mtwallpaper.util

6. Now create AppConst.java in app package deal deal deal.
Your complete app configuration like google username, picasa api urls, gallery itemizing title and fully totally different static variables goes on this class.
AppConst.java

 package com.musaiftech.mtwallpaper.app;

public class AppConst {

// Number of columns of Grid View
// by default 2 but user can configure this in settings activity
public static final int NUM_OF_COLUMNS = 2;

// Gridview image padding
public static final int GRID_PADDING = 4; // in dp

// Gallery directory name to save wallpapers
public static final String SDCARD_DIR_NAME = “MT Wallpapers”;

// Picasa/Google web album username
public static final String PICASA_USER = “freewallpapersapp”;

// Public albums list url
public static final String URL_PICASA_ALBUMS = “https://picasaweb.google.com/data/feed/api/user/_PICASA_USER_?kind=album&alt=json”;

// Picasa album photos url
public static final String URL_ALBUM_PHOTOS = “https://picasaweb.google.com/data/feed/api/user/_PICASA_USER_/albumid/_ALBUM_ID_?alt=json”;

// Picasa recenlty added photos url
public static final String URL_RECENTLY_ADDED = “https://picasaweb.google.com/data/feed/api/user/_PICASA_USER_?kind=photo&alt=json”;

 

7. Create one totally different class named AppController.java below app package deal .
This class extends from Utility and this may very well be a singleton class which initializes volley’s core objects and few fully totally different packages these might be utilized all by the app.
AppController.java

package com.musaiftech.mtwallpaper.app;import com.musaiftech.mtwallpaper.util.LruBitmapCache;
import com.musaiftech.mtwallpaper.util.PrefManager;
import android.app.Application;
import android.text.TextUtils;import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;public class AppController extends Application {public static final String TAG = AppController.class.getSimpleName();private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
LruBitmapCache mLruBitmapCache;private static AppController mInstance;
private PrefManager pref;@Override
public void onCreate() {
super.onCreate();
mInstance = this;
pref = new PrefManager(this);
}public static synchronized AppController getInstance() {
return mInstance;
}public PrefManager getPrefManger() {
if (pref == null) {
pref = new PrefManager(this);
}return pref;
}public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}return mRequestQueue;
}
public ImageLoader getImageLoader() {
getRequestQueue();
if (mImageLoader == null) {
getLruBitmapCache();
mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache);
}

return this.mImageLoader;
}

public LruBitmapCache getLruBitmapCache() {
if (mLruBitmapCache == null)
mLruBitmapCache = new LruBitmapCache();
return this.mLruBitmapCache;
}

public <T> void addToRequestQueue(Request<T> req, String tag) {
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}

public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}

8. Create Utils.java below util package deal deal deal.
This class incorporates few helper strategies.
Utils.java

package com.musaiftech.mtwallpaper.util;

import com.musaiftech.mtwallpaper.R;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Random;

import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.os.Environment;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;

public class Utils {
private String TAG = Utils.class.getSimpleName();
private Context _context;
private PrefManager pref;

// constructor
public Utils(Context context) {
this._context = context;
pref = new PrefManager(_context);
}

/*
* getting screen width
*/
@SuppressWarnings(“deprecation”)
public int getScreenWidth() {
int columnWidth;
WindowManager wm = (WindowManager) _context
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();

final Point point = new Point();
try {
display.getSize(point);
} catch (java.lang.NoSuchMethodError ignore) {
// Older device
point.x = display.getWidth();
point.y = display.getHeight();
}
columnWidth = point.x;
return columnWidth;
}

public void saveImageToSDCard(Bitmap bitmap) {
File myDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
pref.getGalleryName());

myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = “Wallpaper-” + n + “.jpg”;
File file = new File(myDir, fname);
if (file.exists())
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
Toast.makeText(
_context,
_context.getString(R.string.toast_saved).replace(“#”,
“\”” + pref.getGalleryName() + “\””),
Toast.LENGTH_SHORT).show();
Log.d(TAG, “Wallpaper saved to: ” + file.getAbsolutePath());

} catch (Exception e) {
e.printStackTrace();
Toast.makeText(_context,
_context.getString(R.string.toast_saved_failed),
Toast.LENGTH_SHORT).show();
}
}

public void setAsWallpaper(Bitmap bitmap) {
try {
WallpaperManager wm = WallpaperManager.getInstance(_context);

wm.setBitmap(bitmap);
Toast.makeText(_context,
_context.getString(R.string.toast_wallpaper_set),
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(_context,
_context.getString(R.string.toast_wallpaper_set_failed),
Toast.LENGTH_SHORT).show();
}
}
}

9. Create LruBitmapCache.java and paste the beneath code.
This class used to maintain the volley cached objects on the disk.
LruBitmapCache.java

 

package com.musaiftech.mtwallpaper.util;

import com.android.volley.toolbox.ImageLoader.ImageCache;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

public class LruBitmapCache extends LruCache<String, Bitmap> implements
ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;

return cacheSize;
}

public LruBitmapCache() {
this(getDefaultLruCacheSize());
}

public LruBitmapCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}

@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}

@Override
public Bitmap getBitmap(String url) {
return get(url);
}

@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
}

10. Create two packages named Class.java and Wallpaper.java below picasa.mannequin package deal deal deal.
These POJO packages will doable be helpful whereas parsing the JSON data fetched from Picasa.

Class.java

package com.musaiftech.mtwallpaper.picasa.model;

public class Category {
public String id, title;

public Category() {
}

public Category(String id, String title) {
this.id = id;
this.title = title;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}
}

 

Wallpaper.java

 

package com.musaiftech.mtwallpaper.picasa.model;

import java.io.Serializable;

public class Wallpaper implements Serializable {
private static final long serialVersionUID = 1L;
private String url, photoJson;
private int width, height;

public Wallpaper() {
}

public Wallpaper(String photoJson, String url, int width, int height) {
this.photoJson = photoJson;
this.url = url;
this.width = width;
this.height = height;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getPhotoJson() {
return photoJson;
}

public void setPhotoJson(String photoJson) {
this.photoJson = photoJson;
}

public int getWidth() {
return width;
}

public void setWidth(int width) {
this.width = width;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}
}

11. Lastly create one totally different class named PrefManager.java below utils package deal deal deal.
This class takes care of storing the information in Shared Preferences.
The data like google username, Picasa wallpaper classes, gallery title and fully totally different factors will doable be saved in shared preferences.
PrefManager.java

package com.musaiftech.mtwallpaper.util;

import com.musaiftech.mtwallpaper.app.AppConst;
import com.musaiftech.mtwallpaper.picasa.model.Category;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

import com.google.gson.Gson;

public class PrefManager {
private static final String TAG = PrefManager.class.getSimpleName();

// Shared Preferences
SharedPreferences pref;

// Editor for Shared preferences
Editor editor;

// Context
Context _context;

// Shared pref mode
int PRIVATE_MODE = 0;

// Sharedpref file name
private static final String PREF_NAME = “Mt Wallpaper”;

// Google’s username
private static final String KEY_GOOGLE_USERNAME = “google_username”;

// No of grid columns
private static final String KEY_NO_OF_COLUMNS = “no_of_columns”;

// Gallery directory name
private static final String KEY_GALLERY_NAME = “gallery_name”;

// gallery albums key
private static final String KEY_ALBUMS = “albums”;

public PrefManager(Context context) {
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);

}

/**
* Storing google username How to make a Wallpapers App Using Android Studio
* */
public void setGoogleUsername(String googleUsername) {
editor = pref.edit();

editor.putString(KEY_GOOGLE_USERNAME, googleUsername);

// commit changes
editor.commit();
}

public String getGoogleUserName() {
return pref.getString(KEY_GOOGLE_USERNAME, AppConst.PICASA_USER);
}

/**
* store number of grid columns”How to make a Wallpapers App Using Android Studio
* */
public void setNoOfGridColumns(int columns) {
editor = pref.edit();

editor.putInt(KEY_NO_OF_COLUMNS, columns);

// commit changes
editor.commit();
}

public int getNoOfGridColumns() {
return pref.getInt(KEY_NO_OF_COLUMNS, AppConst.NUM_OF_COLUMNS);
}

/**
* storing gallery name How to make a Wallpapers App Using Android Studio
* */
public void setGalleryName(String galleryName) {
editor = pref.edit();

editor.putString(KEY_GALLERY_NAME, galleryName);

// commit changes
editor.commit();
}

public String getGalleryName() {
return pref.getString(KEY_GALLERY_NAME, AppConst.SDCARD_DIR_NAME);
}

/**
* Storing albums in shared preferences How to make a Wallpapers App Using Android Studio
* */
public void storeCategories(List<Category> albums) {
editor = pref.edit();
Gson gson = new Gson();

Log.d(TAG, “Albums: ” + gson.toJson(albums));

editor.putString(KEY_ALBUMS, gson.toJson(albums));

// save changes
editor.commit();
}

public List<Category> getCategories() {
List<Category> albums = new ArrayList<Category>();

if (pref.contains(KEY_ALBUMS)) {
String json = pref.getString(KEY_ALBUMS, null);
Gson gson = new Gson();
Category[] albumArry = gson.fromJson(json, Category[].class);

albums = Arrays.asList(albumArry);
albums = new ArrayList<Category>(albums);
} else
return null;

List<Category> allAlbums = albums;

// Sort the albums in alphabetical order
Collections.sort(allAlbums, new Comparator<Category>() {
public int compare(Category a1, Category a2) {
return a1.getTitle().compareToIgnoreCase(a2.getTitle());
}
});

return allAlbums;

}

/**
* Comparing albums titles for sorting
* */
public class CustomComparator implements Comparator<Category> {
@Override
public int compare(Category c1, Category c2) {
return c1.getTitle().compareTo(c2.getTitle());
}
}
}

Second Part  How To Make A Wallpapers App part 2

 

Leave a Reply

Your email address will not be published. Required fields are marked *