Android Wallpaper App

Wallpaper App in Android – Code

MainCLASS

package com.example.malik.test;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.io.IOException;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

ImageView display, image1, image2, image3, image4, image5, image6, image7;
int toPhone;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

display = (ImageView) findViewById(R.id.IVDisplay);
image1 = (ImageView) findViewById(R.id.IVImage1);
image2 = (ImageView) findViewById(R.id.IVImage2);
image3 = (ImageView) findViewById(R.id.IVImage3);
image4 = (ImageView) findViewById(R.id.IVImage4);
image5 = (ImageView) findViewById(R.id.IVImage5);
image6 = (ImageView) findViewById(R.id.IVImage6);
image7 = (ImageView) findViewById(R.id.IVImage7);
Button setWall = (Button) findViewById(R.id.bSetWall);

toPhone = R.drawable.pic1;

image1.setOnClickListener(this);
image2.setOnClickListener(this);
image3.setOnClickListener(this);
image4.setOnClickListener(this);
image5.setOnClickListener(this);
image6.setOnClickListener(this);
image7.setOnClickListener(this);
setWall.setOnClickListener(this);

}

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.IVImage1:
display.setImageResource(R.drawable.pic1);
toPhone = R.drawable.pic1;
break;
case R.id.IVImage2:
display.setImageResource(R.drawable.pic2);
toPhone = R.drawable.pic2;
break;
case R.id.IVImage3:
display.setImageResource(R.drawable.pic3);
toPhone = R.drawable.pic3;
break;
case R.id.IVImage4:
display.setImageResource(R.drawable.pic4);
toPhone = R.drawable.pic4;
break;
case R.id.IVImage5:
display.setImageResource(R.drawable.pic5);
toPhone = R.drawable.pic5;
break;
case R.id.IVImage6:
display.setImageResource(R.drawable.pic6);
toPhone = R.drawable.pic6;
break;
case R.id.IVImage7:
display.setImageResource(R.drawable.pic7);
toPhone = R.drawable.pic7;
break;
case R.id.bSetWall:
Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(toPhone));
try{
getApplicationContext().setWallpaper(bitmap);
} catch (IOException e){
e.printStackTrace();
}

break;
}
}
}

 

MainXML

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.example.malik.test.MainActivity”>
<ImageView
android:id=”@+id/IVDisplay”
android:layout_width=”200dp”
android:layout_height=”200dp”
android:layout_gravity=”center_horizontal”
android:src=”@drawable/pic1″ />

<Button
android:id=”@+id/bSetWall”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_gravity=”center_horizontal”
android:text=”Set Wallpaper” />

<HorizontalScrollView
android:layout_width=”200dp”
android:layout_height=”wrap_content”
android:layout_gravity=”center”>

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:orientation=”horizontal”>

<ImageView
android:id=”@+id/IVImage1″
android:layout_width=”125dp”
android:layout_height=”125dp”
android:layout_gravity=”center_horizontal”
android:layout_marginTop=”10dp”
android:padding=”15dp”
android:src=”@drawable/pic1″ />

<ImageView
android:id=”@+id/IVImage2″
android:layout_width=”125dp”
android:layout_height=”125dp”
android:layout_gravity=”center_horizontal”
android:layout_marginTop=”10dp”
android:padding=”15dp”
android:src=”@drawable/pic2″ />

<ImageView
android:id=”@+id/IVImage3″
android:layout_width=”125dp”
android:layout_height=”125dp”
android:layout_gravity=”center_horizontal”
android:layout_marginTop=”10dp”
android:padding=”15dp”
android:src=”@drawable/pic3″ />

<ImageView
android:id=”@+id/IVImage4″
android:layout_width=”125dp”
android:layout_height=”125dp”
android:layout_gravity=”center_horizontal”
android:layout_marginTop=”10dp”
android:padding=”15dp”
android:src=”@drawable/pic4″ />

<ImageView
android:id=”@+id/IVImage5″
android:layout_width=”125dp”
android:layout_height=”125dp”
android:layout_gravity=”center_horizontal”
android:layout_marginTop=”10dp”
android:padding=”15dp”
android:src=”@drawable/pic5″ />

<ImageView
android:id=”@+id/IVImage6″
android:layout_width=”125dp”
android:layout_height=”125dp”
android:layout_gravity=”center_horizontal”
android:layout_marginTop=”10dp”
android:padding=”15dp”
android:src=”@drawable/pic6″ />

<ImageView
android:id=”@+id/IVImage7″
android:layout_width=”125dp”
android:layout_height=”125dp”
android:layout_gravity=”center_horizontal”
android:layout_marginTop=”10dp”
android:padding=”15dp”
android:src=”@drawable/pic7″ />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>

 

Manifest FILE

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.example.malik.test”>

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

<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>

</application>

</manifest>

 

Output :

pic1

 

Share

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.