Android Live Wallpaper:
This tutorial describes about how to implement the live wallpaper for android.
Steps to develop live wallpaper:
Step 1:
· Create an XML folder in resource(res) folder.
Right click on res->new->directory-> enter xml and click ok.
Right click on res->new->directory-> enter xml and click ok.
· Create an xml resource file for wallpaper as follows wallpaper.xml
write your description and icon
write your description and icon
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/wallpaper_service_description"
android:settingsActivity="blog.thiru.livewallpaper.WallpaperSettingsActivity"
android:thumbnail="@drawable/thumb" />
android:description="@string/wallpaper_service_description"
android:settingsActivity="blog.thiru.livewallpaper.WallpaperSettingsActivity"
android:thumbnail="@drawable/thumb" />
Here description attribute is the wallpaper description will be shown in list of wallpapers and thumbnail is the icon that displays in wallpaper list. If you want Settings Activity create a settings activity by extending AppCompatActivity. If you don’t want to change the settings of the live wallpapers, just remove the android:settingsActivity attribute.
Step 2:
Create Wallpaper settings activity.
There are 3 ways to create the wallpaper settings activity
· Create an activity extending the AppcompatActivity
· Create a class and extends PreferenceFragment.
· Create a class and extend to PreferenceActivity.
Here I used first approach.
Step 3: WallpaperService Class
Create a Service class which extends WallpaperService class, which is base class for all live wallpapers in the systems. Need to implement onCreateEngine() method and return an object o type android.service.wallpaper.WallpaperService.Engine. The Engine class has few Life cycle methods such as,
- onCreate();
- onSurfaceCreated();
- onVisibilityChanged();
- onOffsetChanged();
- onTouchEvent();
- onCommand();
public class Wallpaper extends WallpaperService { private static final String TAG = "Wallpaper";
int positionX, postionY;
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public Engine onCreateEngine() {
return new WallpaperEngine();
}
class WallpaperEngine extends Engine {
private final Handler handler = new Handler(); private final Runnable drawRunner = new Runnable() { @Override public void run() { draw(); } };WallpaperEngine() {nameImage = Utils.bitmap = textBitmap;bgImage = BitmapFactory.decodeResource(getResources(),R.drawable.background); postionX=-130; postionY=200; }public void onCreate(SurfaceHolder surfaceHolder){ super.onCreate(surfaceHolder); } @Overridepublic void onVisibilityChanged(boolean mVisible) { this.mVisible = mVisible; if (mVisible){ handler.post(drawRunner); } else handler.removeCallbacks(drawRunner); } @Override public void onSurfaceDestroyed(SurfaceHolder holder){ super.onSurfaceDestroyed(holder); this.mVisible = false; handler.removeCallbacks(drawRunner); } public void onOffsetsChanged(float xOffset,float yOffset,float xStep,float yStep,int xPixels,int yPixels){ draw(); } void draw() { final SurfaceHolder holder = getSurfaceHolder(); Canvas c = null; try{ c = holder.lockCanvas(); c.drawColor(Color.BLACK); if (c != null){ c.drawBitmap(bgImage, 0, 0, null); c.drawBitmap(nameImage, postionX,postionY, null);c.drawBitmap(nameImage, postionY,postionX, null);int width=c.getWidth(); if( postionX>width+100){ postionX=-130; } postionX = postionX+1;postionY = postionY+1;
} } finally{ if (c != null) holder.unlockCanvasAndPost(c); } handler.removeCallbacks(drawRunner); if (mVisible){ handler.postDelayed(drawRunner, 10); // delay 10 mileseconds } }
}
Step 4:
Here is the Main Activity:
public class HomeActivity extends AppCompatActivity{
private AlertDialog.Builder alertDialog;
private View view;
private EditText fontText;
private TextView text1;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
text1 = (TextView) findViewById(R.id.txtToBitmap);
}
private void initDialog() {
alertDialog = new AlertDialog.Builder(this);
view = getLayoutInflater().inflate(R.layout.font_dialog, null);
fontText = (EditText) view.findViewById(R.id.fontText);
removeView();
alertDialog.setView(view);
alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
String font = fontText.getText().toString();
if(!font.equals("")) {
text1.setText(font);
text1.setTypeface(Typeface.createFromAsset(
text1.getContext().getAssets(),
"fonts/chunq_dipped.ttf"));
text1.post(new Runnable() {
@Override public void run() {
Bitmap textBitmap = getBitmapFromView(text1);
Utils.bitmap = textBitmap;
}
});
Intent intent = new Intent(
WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(HomeActivity.this, MyWallpaperService.class));
startActivity(intent);
}
dialog.dismiss();
}
});
}
private void removeView() {
if (view.getParent() != null) {
((ViewGroup) view.getParent()).removeView(view);
}
}
public Bitmap getBitmapFromView(TextView view) {
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
Drawable bgDrawable = view.getBackground();
bgDrawable.draw(canvas);
view.draw(canvas);
return returnedBitmap;
}
}
activity_home.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home_bg"
tools:context="com.ddrinfosystems.nameart.HomeActivity">
<TextView
android:id="@+id/txtToBitmap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:textColor="#FFFF00"
android:visibility="invisible" android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="70dp" />
Step 5:</RelativeLayout>
font_dialog.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"> <EditTextandroid:id="@+id/fontText"android:layout_width="match_parent"android:layout_height="wrap_content"android:padding="16dp"android:hint="Enter your name" android:layout_margin="16dp"></EditText> </LinearLayout>Utils class:public class Utils { static Bitmap bitmap;}
Setting up Manifest.xml
Live Wallpaper is a service, need to register the service in your manifest file. The Manifest file seems like..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="blog.thiru.livewallpaper" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="25" /> <uses-feature android:name="android.software.live_wallpaper" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/wallpaper_application_title" android:theme="@style/AppTheme" > <service android:name=".Wallpaper" android:label="@string/wallpaper_service_title" android:permission="android.permission.BIND_WALLPAPER" > <intent-filter> <action android:name="android.service.wallpaper.WallpaperService" /> </intent-filter> <meta-data android:name="android.service.wallpaper" android:resource="@xml/wallpaper" /> </service> <activity android:name=".WallpaperSettingsActivity" android:exported="true" android:label="@string/pref_screen_title" > </activity> <activity android:name=".WallpaperActivity" android:label="@string/wallpaper_application_title" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </activity> </application> </manifest>
Here it is just sample. You can customize the draw() method for your interest.
https://nextfreeads.com/586/posts/3-Services/131-Electrical/1198242-Wallpaper-repair-service-dubai-045864033.html
ReplyDeletehttps://classifiedonlineads.net/586/posts/3-Services/131-Electrical/2369706-Wallpaper-repair-service-dubai-045864033.html
https://classifieds4free.biz/586/posts/3-Services/131-Electrical/2377479-Wallpaper-repair-service-dubai-045864033.html
https://www.quora.com/What-are-the-best-ways-to-repair-drywall-without-removing-wallpaper/answer/Dubai-Technician?prompt_topic_bio=1
https://www.blogger.com/blog/post/preview/7208613335564859404/6764965724855994032
kuşadası
ReplyDeletemilas
çeşme
bağcılar
urfa
DJFFJ