This is a universal look at the era of face, mobile phones are the same. Beautiful app to add a lot of color to the mobile phone, then hurry to your girlfriend dress up.
From setting up static wallpapers, to live wallpapers, to lock screen wallpapers, to themes, it's not that simple.
1. Set Static wallpaper
Mainactivity.java
public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Wallpapermanager = Wallpapermanager.getinstance (This ); Registerreceiver (Broadcastreceiver, New Intentfilter (intent.action_wallpaper_changed));} Wallpapermanager wallpapermanager;public void OnClick (View v) {switch (V.getid ()) {case R.id.btn_setwallpaper:file File = New File (environment.getexternalstoragedirectory () + "/pictures/field.png"); try {InputStream is = new FileInputStream (file);//contextwrapper method, readable bitmap, inputstream//need Set_wallpaper permission. Read files need write_external_storage permission SetWallpaper (IS);} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();} Break;case r.id.btn_setwallpaper2://can load res, InputStream, bitmaptry {wallpapermanager.setresource (R.drawable.frame) ;} catch (IOException e) {e.printstacktrace ();} Break;case r.id.btn_clearwallpaper://Clear Wallpaper try {wallpapermanager.clear ();} CATCH (IOException e) {e.printstacktrace ();}}} Receive wallpaper change broadcast private broadcastreceiver broadcastreceiver = new Broadcastreceiver () {@Overridepublic void OnReceive ( Context context, Intent Intent) {if (Intent.getaction (). Equals (intent.action_wallpaper_changed)) {Toast.maketext ( Mainactivity.this, "changed wallpaper", Toast.length_short). Show ();}};}
Activity_main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout android:layout_width= "Match_parent" Android:layout_ height= "match_parent" android:orientation= "vertical" xmlns:android= "http://schemas.android.com/apk/res/android" > <button android:id= "@+id/btn_setwallpaper" android:layout_width= "Match_parent" Android:la yout_height= "Wrap_content" android:onclick= "OnClick" android:text= "SetWallpaper"/> <button Android:id= "@+id/btn_setwallpaper2" android:layout_width= "match_parent" android:layout_height= "Wrap_content" android:onclick= "OnClick" android:text= "SetWallpaper2"/> <button android:id= "@+id/btn_clea Rwallpaper "android:layout_width=" match_parent "android:layout_height=" Wrap_content "android:onClick= "OnClick" android:text= "Clearwallpaper"/></linearlayout>
2. Set Live Wallpaper
Mywallpaperservice.java, selecting the current wallpaper from the Live wallpaper gallery will trigger the service instantiation and call Oncreateengine
/** * Wrapper service, used to instantiate and manage engine */public class Mywallpaperservice extends Wallpaperservice {private static final String TA G = MyWallpaperService.class.getSimpleName ();p ublic Mywallpaperservice () {super (); LOG.D (TAG, "Mywallpaperservice");} @Overridepublic Engine Oncreateengine () {LOG.D (TAG, "Oncreateengine"); return new Mywallpaperserviceengine (this);}}
Mywallpaperserviceengine.java
/** * Engine encapsulates a surfaceview * <p>surfaceview dual cache mechanism for displaying wallpaper: A front buffer, a back buffer. Assuming that the current display is front, if the content changes, * back on the original basis to draw the content. Then back and front swap positions. <P> */public class Mywallpaperserviceengine extends Wallpaperservice.engine {private static final String TAG = Mywal LpaperServiceEngine.class.getSimpleName ();//30 frameprivate/sec. static final int FPS = 5;private final Handler Handler = NE W Handler ();p ublic mywallpaperserviceengine (wallpaperservice wp) {wp.super ();p aint = new paint ();p Aint.setargb (255, 255, 255, 255);} @Overridepublic void OnCreate (Surfaceholder surfaceholder) {super.oncreate (surfaceholder);} @Overridepublic void onoffsetschanged (float xoffset, float yoffset,float xoffsetstep, float yoffsetstep, int Xpixeloffset,int ypixeloffset) {super.onoffsetschanged (Xoffset, Yoffset, Xoffsetstep, YOffsetStep, XPixelOffset, Ypixeloffset);} @Overridepublic void Ontouchevent (Motionevent event) {super.ontouchevent (event);} timer timer; @Overridepublic void onsurfacecreated (Surfaceholder holDer) {super.onsurfacecreated (holder); timer = new timer (); Timer.schedule (new TimerTask () {@Overridepublic void run () { Drawframe ();}}, 0, 1000/fps);} public void onsurfacedestroyed (Surfaceholder holder) {timer.cancel ();}; Paint paint;float y = 300f;private void Drawframe () {final Surfaceholder holder = Getsurfaceholder (); Canvas Canvas = Null;try{canvas = Holder.lockcanvas (new Rect (+, +, 1100)), if (canvas!=null) {//clear screen, Resets the pixel group Canvas.drawcolor (color.black);//Draw Canvas.drawcircle (300f, y, 200f, paint) on the canvas; y + = 20f;if (y>900f) {y = 300f;}}} Finally{if (canvas!=null) {holder.unlockcanvasandpost (canvas);}} Handler.removecallbacks (Drawsurface);//handler.postdelayed (Drawsurface, 1000/fps);} Private final Runnable drawsurface = new Runnable () {@Overridepublic void run () {drawframe ();}};}
Androidmanifest.xml
<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "Com.qinuli.compiletest" Android: Versioncode= "1" android:versionname= "1.0" > <uses-permission android:name= "Android.permission.SET_WALLPAPER" /> <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-sdk Android oid:minsdkversion= "8" android:targetsdkversion= "/>" <application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" android:theme= "@style/apptheme" android:permission= "Android.permission.BIND_WALLPAPER" > <activity android:name= "com.qinuli.compiletest.m Ainactivity "> <intent-filter > <action android:name=" Android.intent.action.MAIN "/> ; <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </ACTIVITY&G T &lT;activity android:name= "com.qinuli.compiletest.SettingsActivity" ></activity> <service android:name= " Com.qinuli.compiletest.MyWallpaperService "> <intent-filter > <action android:name=" a Ndroid.service.wallpaper.WallpaperService "/> </intent-filter> <meta-data Android:name= "Android.service.wallpaper" android:resource= "@xml/mylivewallpaper"/> </service& Gt </application></manifest>
Mylivewallpaper.xml
<wallpaper xmlns:android= "http://schemas.android.com/apk/res/android" android:author= "@string/ Author " android:description=" @string/description " android:thumbnail=" @drawable/wallpapericon " android:settingsactivity= "Com.qinuli.compiletest.SettingsActivity"/>
Res/values/strings.xml
<string name= "Author" > Shixin </string><string name= "description" > Live interactive wallpaper </string>
Settingsactivity.java
public class Settingsactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_settings);}}
Activity_settings.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout android:layout_width= "Match_parent" Android : layout_height= "match_parent" android:orientation= "vertical" xmlns:android= "http://schemas.android.com /apk/res/android "> <button android:layout_width=" match_parent " android:layout_height=" Wrap_ Content " android:text=" Feel free to ask! " /></linearlayout>
Settings for Android Wallpaper