How To Make Wallpaper App -Part 2

 

How To Make Wallpaper App

How To Make Wallpaper App In the first Part of How To Make Wallpaper App we arranged required classes for How To Make Wallpaper App. In this, we’ll begin adding one by one screen to the application and toward the finish of the article, we ought to have the capacity to finish the application.

 First Part  
Styling The Action Bar
12. You may saw that this application activity bar is having altered foundation shading. That should be possible by characterizing a custom subject in res ⇒ values ⇒ styles.xml envelop. Additionally, this isn’t an entire activity bar customization. I am simply changing the foundation shade of it.
In the event that you need to redo it totally, Styling the Action Bar will cause you. Include underneath code in res ⇒ values ⇒ styles.xml. In the event that you don’t discover styles.xml, make another document in values envelope.

styles.xml
<resources>

<style name=”FreeWallTheme” parent=”@android:style/Theme.Holo.Light”>
<item name=”android:actionBarStyle”>@style/MyActionBarTheme</item>
<item name=”android:actionOverflowButtonStyle”>@style/OverFlow</item>
</style>

<style name=”MyActionBarTheme” parent=”@android:style/Widget.Holo.Light.ActionBar”>
<item name=”android:background”>@color/action_bar</item>
<item name=”android:titleTextStyle”>@style/TitleTextStyle</item>
</style>

<style name=”TitleTextStyle” parent=”android:TextAppearance.Holo.Widget.ActionBar.Title”>
<item name=”android:textColor”>@color/action_bar_title</item>
</style>

<style name=”OverFlow” parent=”android:style/Widget.Holo.ActionButton.Overflow”>
<item name=”android:src”>@drawable/ic_action_overflow</item>
</style>

</resources>

13. Presently so as to apply this style, open the AndroidManifest.XML record and include the style utilizing android: theme characteristic for the tag. Additionally include authorizations as well.

INTERNET – To consume internet
WRITE_EXTERNAL_STORAGE – To store wallpapers in SDCard
SET_WALLPAPER – To update the device wallpaper

AndroidManifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.musaiftech.Mt Wallpaper”
android:versionCode=”1″
android:versionName=”1.0″ >

<uses-sdk
android:minSdkVersion=”14″
android:targetSdkVersion=”19″ />

<uses-permission android:name=”android.permission.INTERNET” />
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />
<uses-permission android:name=”android.permission.SET_WALLPAPER” />

<application
android:name=”com.musaiftech.Mt Wallpaper.app.AppController”
android:allowBackup=”true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/FreeWallTheme” >
<!– all the activities goes here –>
</application>

</manifest>

Presently in the event that you run the application, you should see the activity bar shading changed.

Including the Splash Screen

Sprinkle screens are redundant for each application. However, for our application, it bodes well to have a sprinkle screen as we need to download backdrops classes before going into the application. In short, we make a demand to Picasa to get rundown of open collections (for our situation those are backdrops classifications) and store them in shared inclinations. So how about we make the vital documents for the sprinkle screen.

14. Make a XML document named activity_splash.xml under res ⇒ format organizer.

activity_splash.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical” >

<ImageView android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:src=”@drawable/splash_screen”
android:scaleType=”centerCrop”/>

</LinearLayout>

15. Presently make a class named SplashActivity.java in the application primary bundle and glue the beneath code. Here we are making a json call to Picasa and bringing rundown of collections. When collections are gotten we are putting away them in Shared Preferences. Later these classifications will be stacked into route cabinet.

SplashActivity.java
package com.musaiftech.Mt Wallpaper;

import com.musaiftech.Mt Wallpaper.app.AppConst;
import com.musaiftech.Mt Wallpaper.app.AppController;
import com.musaiftech.Mt Wallpaper.picasa.model.Category;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.Toast;

import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;

public class SplashActivity extends Activity {
private static final String TAG = SplashActivity.class.getSimpleName();
private static final String TAG_FEED = “feed”, TAG_ENTRY = “entry”,
TAG_GPHOTO_ID = “gphoto$id”, TAG_T = “$t”,
TAG_ALBUM_TITLE = “title”;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.activity_splash);

// Picasa request to get list of albums
String url = AppConst.URL_PICASA_ALBUMS
.replace(“_PICASA_USER_”, AppController.getInstance()
.getPrefManger().getGoogleUserName());

Log.d(TAG, “Albums request url: ” + url);

// Preparing volley’s json object request
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET, url,
null, new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {
Log.d(TAG, “Albums Response: ” + response.toString());
List<Category> albums = new ArrayList<Category>();
try {
// Parsing the json response
JSONArray entry = response.getJSONObject(TAG_FEED)
.getJSONArray(TAG_ENTRY);

// loop through albums nodes and add them to album
// list
for (int i = 0; i < entry.length(); i++) {
JSONObject albumObj = (JSONObject) entry.get(i);
// album id
String albumId = albumObj.getJSONObject(
TAG_GPHOTO_ID).getString(TAG_T);

// album title
String albumTitle = albumObj.getJSONObject(
TAG_ALBUM_TITLE).getString(TAG_T);

Category album = new Category();
album.setId(albumId);
album.setTitle(albumTitle);

// add album to list
albums.add(album);

Log.d(TAG, “Album Id: ” + albumId
+ “, Album Title: ” + albumTitle);
}

// Store albums in shared pref
AppController.getInstance().getPrefManger()
.storeCategories(albums);

// String the main activity
Intent intent = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(intent);
// closing spalsh activity
finish();

} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
getString(R.string.msg_unknown_error),
Toast.LENGTH_LONG).show();
}

}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, “Volley Error: ” + error.getMessage());

// show error toast
Toast.makeText(getApplicationContext(),
getString(R.string.splash_error),
Toast.LENGTH_LONG).show();

// Unable to fetch albums
// check for existing Albums data in Shared Preferences
if (AppController.getInstance().getPrefManger()
.getCategories() != null && AppController.getInstance().getPrefManger()
.getCategories().size() > 0) {
// String the main activity
Intent intent = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(intent);
// closing spalsh activity
finish();
} else {
// Albums data not present in the shared preferences
// Launch settings activity, so that user can modify
// the settings

Intent i = new Intent(SplashActivity.this,
SettingsActivity.class);
// clear all the activities
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}

}
});

// disable the cache for this request, so that it always fetches updated
// json
jsonObjReq.setShouldCache(false);

// Making the request
AppController.getInstance().addToRequestQueue(jsonObjReq);

}

}

16. Now add the SplashActivity as launcher activity in the AndroidManifest.xml inside <application>

<application ….>
<activity
android:name=”com.musaiftech.Mt Wallpaper.SplashActivity”
android:label=”@string/app_name”
android:screenOrientation=”portrait” >
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>

Presently in the event that you run the application, you should see collections json signed in LogCat. In the event that yes, we can move to the subsequent stage i.e including route cabinet and showing the backdrop classes.

Including Navigation Drawer

Before following this progression ensure that you read Android Sliding Menu utilizing Navigation Drawer instructional exercise to make this progression straightforward for you. To include route cabinet, we have to make fewer designs and classes.

17. Make drawer_list_item.xml under res ⇒ design catalog. This is the design petition for route cabinet list thing to show backdrop classification name.

drawer_list_item.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”48dp”
android:background=”@drawable/list_selector”>

<TextView
android:id=”@+id/title”
android:layout_width=”wrap_content”
android:layout_height=”match_parent”
android:layout_alignParentLeft=”true”
android:minHeight=”?android:attr/listPreferredItemHeightSmall”
android:textAppearance=”?android:attr/textAppearanceListItemSmall”
android:textColor=”@color/list_item_title”
android:gravity=”center_vertical”
android:paddingRight=”10dp”
android:paddingLeft=”10dp”/>

</RelativeLayout>

18. Create NavDrawerItem.java in your project’s main package and paste the below code. This is a model class for navigation list item.

NavDrawerItem.java
package com.musaiftech.Mt Wallpaper;

public class NavDrawerItem {

private String albumId, albumTitle;
// boolean flag to check for recent album
private boolean isRecentAlbum = false;

public NavDrawerItem() {
}

public NavDrawerItem(String albumId, String albumTitle) {
this.albumId = albumId;
this.albumTitle = albumTitle;
}

public NavDrawerItem(String albumId, String albumTitle,
boolean isRecentAlbum) {
this.albumTitle = albumTitle;
this.isRecentAlbum = isRecentAlbum;
}

public String getAlbumId() {
return albumId;
}

public void setAlbumId(String albumId) {
this.albumId = albumId;
}

public String getTitle() {
return this.albumTitle;
}

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

public boolean isRecentAlbum() {
return isRecentAlbum;
}

public void setRecentAlbum(boolean isRecentAlbum) {
this.isRecentAlbum = isRecentAlbum;
}
}

19. Presently we have to make the custom rundown connector class which gives information to route list see. Make a class named NavDrawerListAdapter.java under connector bundle. This connector class swells the drawer_list_item.xml design by showing proper backdrop classification name.
NavDrawerListAdapter.java
package com.musaiftech.Mt Wallpaper.helper;

import com.musaiftech.Mt Wallpaper.NavDrawerItem;
import com.musaiftech.Mt Wallpaper.R;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NavDrawerListAdapter extends BaseAdapter {

private Context context;
private ArrayList<NavDrawerItem> navDrawerItems;

public NavDrawerListAdapter(Context context,
ArrayList<NavDrawerItem> navDrawerItems) {
this.context = context;
this.navDrawerItems = navDrawerItems;
}

@Override
public int getCount() {
return navDrawerItems.size();
}

@Override
public Object getItem(int position) {
return navDrawerItems.get(position);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.drawer_list_item, null);
}

TextView txtTitle = (TextView) convertView.findViewById(R.id.title);

txtTitle.setText(navDrawerItems.get(position).getTitle());

return convertView;
}

}

20. Now we need to create a list view element in our main activity. Create an xml named activity_main.xml with the below content.

activity_main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/drawer_layout”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

<!– Framelayout to display Fragments –>
<FrameLayout
android:id=”@+id/frame_container”
android:layout_width=”match_parent”
android:layout_height=”match_parent” />

<!– Listview to display slider menu –>
<ListView
android:id=”@+id/list_slidermenu”
android:layout_width=”240dp”
android:layout_height=”match_parent”
android:layout_gravity=”start”
android:choiceMode=”singleChoice”
android:divider=”@color/list_divider”
android:dividerHeight=”1dp”
android:listSelector=”@drawable/list_selector”
android:background=”@color/list_background”/>

</android.support.v4.widget.DrawerLayout>

How To Make Wallpaper App link to part 3

Leave a Reply

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