SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Downloaden Sie, um offline zu lesen
Þ‰î ð°FJ™ ºîL™
¬ôš õ£™«ðŠðK¬ù
(Livewallpaper) à¼õ£‚°õ¶
âšõ£Á â¡ð¬îŠ 𣘂è
«ð£A«ø£‹.
݇†ó£Œ®¡ «ý£‹
vWKQ™ (Home screen) ÜQ
¬ôš õ£™«ðŠð˜!
<?xml version="1.0" encoding="UTF-8"?>
<wallpaper
xmlns:android="http://schemas.android.com/apk/res/andro
id"
android:thumbnail="@drawable/icon"
android:description="@string/wallpaper_description"
android:settingsActivity="ram.android.wallpaper.MyPreference
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/andro
id"
package="ram.android.wallpaper"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<service android:name="MyWallpaperService"
android:enabled="true"
android:permission="android.permission.BIND_WALLPAPER"
android:label="Wallpaper Example ">
<intent-filter>
<action
android:name="android.service.wallpaper.WallpaperService"
></action>
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="@xml/mywallpaper"></meta-data>
</service>
<activity android:label="@string/app_name"
android:name=".MyPreferencesActivity"
android:theme="@android:style/Theme.Light.WallpaperSetti
ngs"
android:exported="true">
</activity>
</application>
<uses-sdk android:minSdkVersion="10" />
<uses-feature
android:name="android.software.live_wallpaper"
android:required="true"></uses-feature>
</manifest>
Gó™-1
Gó™-2
ðì‹-2
ðì‹-1
«ñûÂì¡ ÜŠO«è û¬ù
à¼õ£‚°õ«î Þî¡ «ï£‚è
񣰋.
¬ôš õ£™ «ðŠðK¬ù
à¼õ£‚°õ õ£™«ðŠð˜
îèõL¬ù ªè£‡´œ÷ xml
ç¬ðL¬ù ºîL™ à¼õ£‚è
Ý¡†ó£Œ´ -2
Þ󣋰ñ£˜ ªô†²Iï£ó£òí¡
22
package
ram.android.wallpaper;
public class MyPoint {
String text;
private int x;
private int y;
public MyPoint(String
text, int x, int y) {
this.text = text;
this.x = x;
this.y = y;
}
}
package ram.android.wallpaper;
import android.os.Bundle;
import android.preference.Preference;
import
android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.widget.Toast;
public class MyPreferencesActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
// We want to add a validator to the number of circles
so that it only
// accepts numbers
Preference circlePreference =
getPreferenceScreen().findPreference("numberOfCircles");
// Add the validator
circlePreference.setOnPreferenceChangeListener(numberCheckL
istener);
}
/**
* Checks that a preference is a valid numerical value
*/
Preference.OnPreferenceChangeListener
numberCheckListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference
preference, Object newValue) {
// Check that the string is an integer
if (newValue != null &&
newValue.toString().length() > 0
&& newValue.toString().matches("d*")) {
return true;
}
// If now create a message to the user
Toast.makeText(MyPreferencesActivity.this,
"Invalid Input",
Toast.LENGTH_SHORT).show();
return false;
}
};
}
<?xml version="1.0"
encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://sche
mas.android.com/apk/res/an
droid">
<CheckBoxPreference
android:key="touch"
android:title="Enable
Touch"></CheckBoxPreferen
ce>
<EditTextPreference
android:key="numberOfCircl
es"
android:title="Number of
Circles"></EditTextPreferen
ce>
</PreferenceScreen>
«õ‡´‹. xml
ç¬ðL™ ÜŠO
«èû¡ ðŸPò
îèõ™è¬÷»‹
ñŸÁ‹ ñ£Ÿøƒ
è¬÷ ÜÂñF‚
°‹ ªêò™è¬÷
Gó™-3
Gó™-4
Gó™-5
ðì‹-3
package ram.android.wallpaper;
import java.util.ArrayList;
import java.util.List;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import
android.preference.PreferenceManager;
import
android.service.wallpaper.WallpaperService;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
public class MyWallpaperService extends
WallpaperService {
@Override
public Engine onCreateEngine() {
return new MyWallpaperEngine();
}
private class MyWallpaperEngine
extends Engine {
private final Handler handler = new
Handler();
private final Runnable drawRunner
= new Runnable() {
@Override
public void run() {
draw();
}
};
private List<MyPoint> circles;
private Paint paint = new Paint();
private int width;
int height;
private boolean visible = true;
private int maxNumber;
private boolean touchEnabled;
public MyWallpaperEngine() {
SharedPreferences prefs =
PreferenceManager
.getDefaultSharedPreferences(MyWallpaperSer
vice.this);
maxNumber = Integer
.valueOf(prefs.getString("numberOfCircles",
"4"));
touchEnabled =
prefs.getBoolean("touch", false);
circles = new
ArrayList<MyPoint>();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(10f);
handler.post(drawRunner);
}
@Override
public void
onVisibilityChanged(boolean visible) {
this.visible = visible;
if (visible) {
handler.post(drawRunner);
} else {
handler.removeCallbacks(drawRunner);
}
}
}
Gó™-6
ðì‹-4
»‹ ªè£‡®¼‚è «õ‡
´‹.
õ£™«ðŠð˜ ê˜iv â¡ø
A÷£vC¬ù Ü®Šð¬ìò£è
ªè£‡´ ¬ôš õ£™«ðŠð˜
èœ Ý‡†ó£Œ´ ªê™«ðC
J™ ªêò™ð´Aø¶.
Þ‰î º¬øJ™ on create
engine â¡ø º¬øJ¬ù
implement ªêŒ¶ F¼‹ð
ªðÁ‹ return object õ¬èò£è
'engine' â¡ðî¬ù ªðø «õ‡
´‹.
android.permission.BIND.WA
LLPAPER â¡ø ð‡H¬ù
ÜÂñF ªè£´Šðî¡ Íô‹
android.wallpaper.wallpaperser
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
this.visible = false;
handler.removeCallbacks(drawRunner);
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
this.width = width;
this.height = height;
super.onSurfaceChanged(holder, format, width, height);
}
@Override
public void onTouchEvent(MotionEvent event) {
if (touchEnabled) {
float x = event.getX();
float y = event.getY();
SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
if (canvas != null) {
canvas.drawColor(Color.BLACK);
circles.clear();
circles.add(new MyPoint(String.valueOf(circles.size() + 1), x, y));
drawCircles(canvas, circles);
}
} finally {
if (canvas != null)
holder.unlockCanvasAndPost(canvas);
}
super.onTouchEvent(event);
}
}
private void draw() {
SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
if (canvas != null) {
if (circles.size() >= maxNumber) {
circles.clear();
}
int x = (int) (width * Math.random());
int y = (int) (height * Math.random());
circles.add(new MyPoint(String.valueOf(circles.size() + 1),
x, y));
drawCircles(canvas, circles);
}
} finally {
if (canvas != null)
holder.unlockCanvasAndPost(canvas);
}
handler.removeCallbacks(drawRunner);
if (visible) {
handler.postDelayed(drawRunner, 5000);
}
}
// Surface view requires that all elements are drawn completely
private void drawCircles(Canvas canvas, List<MyPoint> circles) {
canvas.drawColor(Color.BLACK);
for (MyPoint point : circles) {
canvas.drawCircle(point.x, point.y, 20.0f, paint);
}
}
}
Gó™-7
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/a
pk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="30dip"
android:orientation="horizontal">
<LinearLayout android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center">
<TextView android:text="My App"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="24.5sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="one" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="two" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="three" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="four" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/
apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="15dip"
android:orientation="horizontal">
<LinearLayout android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:paddingLeft="20dip"
android:paddingRight="20dip">
<TextView android:text="My App"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:textSize="24.5sp" />
<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button android:text="one" />
<Button android:text="two" />
</TableRow>
<TableRow>
<Button android:text="three" />
<Button android:text="four" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
Gó™-8 Gó™-9
vice â¡ø android ÜŠO
«èûQ™ ªêò™ð´‹. android.
service.wallpaper.wallpaperserv
ice engine â¡ø A÷£«ê ¬ôš
õ£™«ðŠðK¬ù ªêò™
𴈶õîŸè£ù A÷£ê£°‹.
Þî¬ù îMó ïñ¶ ÜŠO
«èûQ™ àœ÷ android mani
fest.xml -™ "android software.
live-wallpaper"ðò¡ð´ˆ¶
A«ø£‹ â¡ðî¬ù ÜŠO«è
ê‚°ˆ ªîKòŠð´ˆî «õ‡
´‹. Þî¡ Íô‹ ¬ôš õ£™
«ðŠð˜ ðò¡ð´ˆî£î ªê™
«ðCJ™ ÜŠO«èû¡ ðò¡
𴋫𣶠ãŸð´‹ H¬ö¬ò
îM˜‚èô£‹.
¹Fò Šó£ªü‚† å¡P¬ù
ªî£ìƒA ram.android.wall
paper â¡Á ªðòK´ƒèœ.
Þƒ° Ý‚®M†®J¬ù à¼
õ£‚è£b˜èœ,
res/xml â¡ø ç«ð£™
ìK¬ù à¼õ£‚A ÜF™ my
wallpaper.xml ç¬ðL¬ù à¼
õ£‚°ƒèœ. mywallpaper. xml
ç¬ðL™ õ£™«ðŠð¼‚è£ù
îèõ½‹ ñŸÁ‹ Aó£çH‚
îèõ½‹ Þ¼‚°‹, ªêò™ð
´‹ õ£™«ðŠðK¡ CPò ðìˆ
F¬ù "android thumbnail" â¡
ðF™ ªè£´‚èô£‹.
¬ñ õ£™«ðŠð¼‚è£ù
Gó™èœ (Gó™-1)-™ ªè£´‚èŠ
ð†´œ÷¶.
Ü´ˆîî£è androidmain
fest.xmlL™ "mywallpaperservi
ce" ðŸPò îèõL¬ù ªîKòŠ
ð´ˆî «õ‡´‹. androidmain
fest.xml L¬ù Gó™-2™ àœ
÷¶ «ð£¡ø¶ ñ£Ÿøƒèœ
ªêŒFì «õ‡´‹.
¬ñ ð£J¡† (Mypoint)
â¡ø A÷£C¬ù Ü´ˆîî£è
à¼õ£‚è «õ‡´‹. õ¬ó‰î
- ªî£ì¼‹
ðìƒèO¡ îèõL¬ù «êIŠ
ð ðò¡ð´‹. A÷£CŸ
è£ù¬õ Gó™-3™ ªè£´‚èŠ
ð†´œ÷¶.
preference â¡ð¶ îèõ¬ô
«êIˆ¶ H¡¹ ÜŠO«èû¡
ªêò™ðì ªî£ìƒAò¾ì¡
îèõ™è¬÷ F¼‹ð ªðÁ
õ ðò¡ð´Aø¶.
Þî¡ Íô‹ ðòù£÷˜èœ
«î˜¾ Ü™ô¶ «î˜‰ªî´ˆî
ªêò™èœ F¼‹ð A¬ì‚°‹.
꣡ø£è ðòù£÷˜ ÜŠO«è
êQ™ background GøˆF¬ù
ñ…ê÷£è ñ£ŸP»œ÷£˜.
e‡´‹ ÜŠO«èû¡
«î£¡Á‹«ð£¶ ñ…ê÷£è
«î£¡Áñ£Á ܬñ‚è «õ‡
´‹ â¡ø£™ preference ðò¡
ð´ˆîô£‹.
ÜŠO«èûQ™ instence
Ýù shared preference-™ îè
õ™ «êI‚°ñ£Á ܬñ‚è
ô£‹.
H¡¹ ðò¡ð´ˆ¶õ
getshared preference ðò¡
𴈶õî¡ Íô‹ ꣈Fòñ£‚
èô£‹.
res/xml ç«ð£™ìK™ prefs.
xml â¡ø ç¬ðL¬ù à¼õ£‚
A´ƒèœ. Ü«î «ïóˆF™ mypre
ference activity â¡ø ªðò
¼¬ìò preference activity å¡
P¬ù à¼õ£‚A´ƒèœ. pref.
xml-è£ù¬õ Gó™-4™ ªè£´‚
èŠð†´œ÷¶.
mypreference activity-
è£ù¬õ Gó™-5™ ªè£´‚èŠ
ð†´œ÷¶.
preference activity J¬ù
à¼õ£‚Aò H¡ õ£™«ðŠð˜
ê˜ivC¬ù à¼õ£‚Aì
«õ‡´‹. õ£™ «ðŠð˜ ê˜iv
CŸè£ù¬õ Gó™ -6 ñŸÁ‹
Gó™-7™ ªè£´‚èŠð†´œ
֦.
ÜŠO«èû¡ ªêò™ð†ì
¾ì¡ ðì‹-1™ àœ÷¶
«ð£¡Á F¬ó «î£¡Á‹
Þ‰î õ£™«ðŠð˜ Íô‹ «î¬õ
ò£ù õ†ìƒè¬÷ Þ¬í‚è
¾‹ ñŸÁ‹ ÜN‚辋 º®
»‹. Ü´ˆîî£è, F¬ó‚° ãŸð
F¬óJ™ àœ÷ îèõ™ ñ£Á
ñ£Á ܬñŠð¬îŠ 𣘊
«ð£‹.
Šó£ªü‚† ªðòK¬ù
screenorientationâ¡Áªè£´‚
辋. res/layout/main.xmlâ¡ø
ç¬ðL¡ Gó™ 8-™ àœ÷¶
«ð£¡Á ܬñˆF´ƒèœ.
«ô‡† v«èŠHŸè£ù
F¬ó ܬñŠ¬ð ãŸð´ˆ¶õ
 layout-land â¡ø ç«ð£™
ìK¬ù ðì‹-2™ àœ÷¶
«ð£¡Á à¼õ£‚A´ƒèœ.
res/layout-land/main.xml
è£ù Gó™ 9-™ àœ÷¶
«ð£¡Á ܬñˆF´ƒèœ.
ÜŠO«èû¬ù ªêò™ð´ˆ
Fù£™«ð£˜†ªóŒ†«ñ£®™
ðì‹-3™ àœ÷¶ «ð£¡Á‹
«ô‡† v«èŠ «ñ£®™
ðì‹- 4™ àœ÷¶ «ð£¡Á‹
«î£¡Á‹.

Weitere ähnliche Inhalte

Was ist angesagt?

241 Ch
241 Ch241 Ch
241 Ch
anjaan
 

Was ist angesagt? (20)

2016 06-11 Дмитрий Алексеенков. Android Data Binding
2016 06-11 Дмитрий Алексеенков. Android Data Binding2016 06-11 Дмитрий Алексеенков. Android Data Binding
2016 06-11 Дмитрий Алексеенков. Android Data Binding
 
Skaters and BMXers from all over the U.S. descend on Grant Park
Skaters and BMXers from all over the U.S. descend on Grant ParkSkaters and BMXers from all over the U.S. descend on Grant Park
Skaters and BMXers from all over the U.S. descend on Grant Park
 
Best Fried Chicken
Best Fried ChickenBest Fried Chicken
Best Fried Chicken
 
Best hotel
Best hotelBest hotel
Best hotel
 
2015 Key Ingredient Cook-Off
2015 Key Ingredient Cook-Off2015 Key Ingredient Cook-Off
2015 Key Ingredient Cook-Off
 
George McCaskey's handling of the Ray McDonald affair offers a lesson to the ...
George McCaskey's handling of the Ray McDonald affair offers a lesson to the ...George McCaskey's handling of the Ray McDonald affair offers a lesson to the ...
George McCaskey's handling of the Ray McDonald affair offers a lesson to the ...
 
Check out our photos of the Pixies' Metro show
Check out our photos of the Pixies' Metro showCheck out our photos of the Pixies' Metro show
Check out our photos of the Pixies' Metro show
 
Creating List in Android App (in tamil)
Creating List in Android App (in tamil)Creating List in Android App (in tamil)
Creating List in Android App (in tamil)
 
Get more votes!
Get more votes!Get more votes!
Get more votes!
 
Pianist and composer Jeff Kowalkowski releases strong new trio album
Pianist and composer Jeff Kowalkowski releases strong new trio albumPianist and composer Jeff Kowalkowski releases strong new trio album
Pianist and composer Jeff Kowalkowski releases strong new trio album
 
Creating Image Gallery - Android app (in tamil)
Creating Image Gallery - Android app (in tamil)Creating Image Gallery - Android app (in tamil)
Creating Image Gallery - Android app (in tamil)
 
A slew of AACM 50th anniversary celebrations this weekend
A slew of AACM 50th anniversary celebrations this weekendA slew of AACM 50th anniversary celebrations this weekend
A slew of AACM 50th anniversary celebrations this weekend
 
Pimp your site with jQuery!
Pimp your site with jQuery!Pimp your site with jQuery!
Pimp your site with jQuery!
 
jQuery Tutorial
jQuery TutorialjQuery Tutorial
jQuery Tutorial
 
「レガシーコード」とはいったい?
「レガシーコード」とはいったい?「レガシーコード」とはいったい?
「レガシーコード」とはいったい?
 
241 Ch
241 Ch241 Ch
241 Ch
 
Here's the Downtown Sound lineup for 2015
Here's the Downtown Sound lineup for 2015Here's the Downtown Sound lineup for 2015
Here's the Downtown Sound lineup for 2015
 
Poetry in the age of hip-hop
Poetry in the age of hip-hopPoetry in the age of hip-hop
Poetry in the age of hip-hop
 
Sis quiz
Sis quizSis quiz
Sis quiz
 
Jquery Framework
Jquery FrameworkJquery Framework
Jquery Framework
 

Mehr von Dr. Ramkumar Lakshminarayanan

Mehr von Dr. Ramkumar Lakshminarayanan (20)

IT security awareness
IT security awarenessIT security awareness
IT security awareness
 
Basics of IT security
Basics of IT securityBasics of IT security
Basics of IT security
 
IT Security Awareness Posters
IT Security Awareness PostersIT Security Awareness Posters
IT Security Awareness Posters
 
Normalisation revision
Normalisation revisionNormalisation revision
Normalisation revision
 
Windows mobile programming
Windows mobile programmingWindows mobile programming
Windows mobile programming
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Web technology today
Web technology todayWeb technology today
Web technology today
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Phonegap for Android
Phonegap for AndroidPhonegap for Android
Phonegap for Android
 
Create and Sell Android App (in tamil)
Create and Sell Android App (in tamil)Create and Sell Android App (in tamil)
Create and Sell Android App (in tamil)
 
Android Tips (Tamil)
Android Tips (Tamil)Android Tips (Tamil)
Android Tips (Tamil)
 
Android Animation (in tamil)
Android Animation (in tamil)Android Animation (in tamil)
Android Animation (in tamil)
 
Single Touch event view in Android (in tamil)
Single Touch event view in Android (in tamil)Single Touch event view in Android (in tamil)
Single Touch event view in Android (in tamil)
 
Android Application using seekbar (in tamil)
Android Application using seekbar (in tamil)Android Application using seekbar (in tamil)
Android Application using seekbar (in tamil)
 
GPS in Android (in tamil)
GPS in Android (in tamil)GPS in Android (in tamil)
GPS in Android (in tamil)
 
Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)
 
Shared Preference in Android App
Shared Preference in Android AppShared Preference in Android App
Shared Preference in Android App
 
Data Storage in Android App
Data Storage in Android AppData Storage in Android App
Data Storage in Android App
 
Part 7
Part 7Part 7
Part 7
 
Layout Object in Android App
Layout Object in Android AppLayout Object in Android App
Layout Object in Android App
 

Android app - Creating Live Wallpaper (tamil)

  • 1. Þ‰î ð°FJ™ ºîL™ ¬ôš õ£™«ðŠðK¬ù (Livewallpaper) à¼õ£‚°õ¶ âšõ£Á â¡ð¬îŠ ð£˜‚è «ð£A«ø£‹. ݇†ó£Œ®¡ «ý£‹ vWKQ™ (Home screen) ÜQ ¬ôš õ£™«ðŠð˜! <?xml version="1.0" encoding="UTF-8"?> <wallpaper xmlns:android="http://schemas.android.com/apk/res/andro id" android:thumbnail="@drawable/icon" android:description="@string/wallpaper_description" android:settingsActivity="ram.android.wallpaper.MyPreference <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/andro id" package="ram.android.wallpaper" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <service android:name="MyWallpaperService" android:enabled="true" android:permission="android.permission.BIND_WALLPAPER" android:label="Wallpaper Example "> <intent-filter> <action android:name="android.service.wallpaper.WallpaperService" ></action> </intent-filter> <meta-data android:name="android.service.wallpaper" android:resource="@xml/mywallpaper"></meta-data> </service> <activity android:label="@string/app_name" android:name=".MyPreferencesActivity" android:theme="@android:style/Theme.Light.WallpaperSetti ngs" android:exported="true"> </activity> </application> <uses-sdk android:minSdkVersion="10" /> <uses-feature android:name="android.software.live_wallpaper" android:required="true"></uses-feature> </manifest> Gó™-1 Gó™-2 ðì‹-2 ðì‹-1
  • 2. «ñûÂì¡ ÜŠO«è û¬ù à¼õ£‚°õ«î Þî¡ «ï£‚è ñ£°‹. ¬ôš õ£™ «ðŠðK¬ù à¼õ£‚°õ õ£™«ðŠð˜ îèõL¬ù ªè£‡´œ÷ xml ç¬ðL¬ù ºîL™ à¼õ£‚è Ý¡†ó£Œ´ -2 Þ󣋰ñ£˜ ªô†²Iï£ó£òí¡ 22 package ram.android.wallpaper; public class MyPoint { String text; private int x; private int y; public MyPoint(String text, int x, int y) { this.text = text; this.x = x; this.y = y; } } package ram.android.wallpaper; import android.os.Bundle; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceActivity; import android.widget.Toast; public class MyPreferencesActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); // We want to add a validator to the number of circles so that it only // accepts numbers Preference circlePreference = getPreferenceScreen().findPreference("numberOfCircles"); // Add the validator circlePreference.setOnPreferenceChangeListener(numberCheckL istener); } /** * Checks that a preference is a valid numerical value */ Preference.OnPreferenceChangeListener numberCheckListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // Check that the string is an integer if (newValue != null && newValue.toString().length() > 0 && newValue.toString().matches("d*")) { return true; } // If now create a message to the user Toast.makeText(MyPreferencesActivity.this, "Invalid Input", Toast.LENGTH_SHORT).show(); return false; } }; } <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://sche mas.android.com/apk/res/an droid"> <CheckBoxPreference android:key="touch" android:title="Enable Touch"></CheckBoxPreferen ce> <EditTextPreference android:key="numberOfCircl es" android:title="Number of Circles"></EditTextPreferen ce> </PreferenceScreen> «õ‡´‹. xml ç¬ðL™ ÜŠO «èû¡ ðŸPò îèõ™è¬÷»‹ ñŸÁ‹ ñ£Ÿøƒ è¬÷ ÜÂñF‚ °‹ ªêò™è¬÷ Gó™-3 Gó™-4 Gó™-5 ðì‹-3
  • 3. package ram.android.wallpaper; import java.util.ArrayList; import java.util.List; import android.content.SharedPreferences; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Handler; import android.preference.PreferenceManager; import android.service.wallpaper.WallpaperService; import android.view.MotionEvent; import android.view.SurfaceHolder; public class MyWallpaperService extends WallpaperService { @Override public Engine onCreateEngine() { return new MyWallpaperEngine(); } private class MyWallpaperEngine extends Engine { private final Handler handler = new Handler(); private final Runnable drawRunner = new Runnable() { @Override public void run() { draw(); } }; private List<MyPoint> circles; private Paint paint = new Paint(); private int width; int height; private boolean visible = true; private int maxNumber; private boolean touchEnabled; public MyWallpaperEngine() { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(MyWallpaperSer vice.this); maxNumber = Integer .valueOf(prefs.getString("numberOfCircles", "4")); touchEnabled = prefs.getBoolean("touch", false); circles = new ArrayList<MyPoint>(); paint.setAntiAlias(true); paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeWidth(10f); handler.post(drawRunner); } @Override public void onVisibilityChanged(boolean visible) { this.visible = visible; if (visible) { handler.post(drawRunner); } else { handler.removeCallbacks(drawRunner); } } } Gó™-6 ðì‹-4 »‹ ªè£‡®¼‚è «õ‡ ´‹. õ£™«ðŠð˜ ê˜iv â¡ø A÷£vC¬ù Ü®Šð¬ìò£è ªè£‡´ ¬ôš õ£™«ðŠð˜ èœ Ý‡†ó£Œ´ ªê™«ðC J™ ªêò™ð´Aø¶. Þ‰î º¬øJ™ on create engine â¡ø º¬øJ¬ù implement ªêŒ¶ F¼‹ð ªðÁ‹ return object õ¬èò£è 'engine' â¡ðî¬ù ªðø «õ‡ ´‹. android.permission.BIND.WA LLPAPER â¡ø ð‡H¬ù ÜÂñF ªè£´Šðî¡ Íô‹ android.wallpaper.wallpaperser
  • 4. @Override public void onSurfaceDestroyed(SurfaceHolder holder) { super.onSurfaceDestroyed(holder); this.visible = false; handler.removeCallbacks(drawRunner); } @Override public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { this.width = width; this.height = height; super.onSurfaceChanged(holder, format, width, height); } @Override public void onTouchEvent(MotionEvent event) { if (touchEnabled) { float x = event.getX(); float y = event.getY(); SurfaceHolder holder = getSurfaceHolder(); Canvas canvas = null; try { canvas = holder.lockCanvas(); if (canvas != null) { canvas.drawColor(Color.BLACK); circles.clear(); circles.add(new MyPoint(String.valueOf(circles.size() + 1), x, y)); drawCircles(canvas, circles); } } finally { if (canvas != null) holder.unlockCanvasAndPost(canvas); } super.onTouchEvent(event); } } private void draw() { SurfaceHolder holder = getSurfaceHolder(); Canvas canvas = null; try { canvas = holder.lockCanvas(); if (canvas != null) { if (circles.size() >= maxNumber) { circles.clear(); } int x = (int) (width * Math.random()); int y = (int) (height * Math.random()); circles.add(new MyPoint(String.valueOf(circles.size() + 1), x, y)); drawCircles(canvas, circles); } } finally { if (canvas != null) holder.unlockCanvasAndPost(canvas); } handler.removeCallbacks(drawRunner); if (visible) { handler.postDelayed(drawRunner, 5000); } } // Surface view requires that all elements are drawn completely private void drawCircles(Canvas canvas, List<MyPoint> circles) { canvas.drawColor(Color.BLACK); for (MyPoint point : circles) { canvas.drawCircle(point.x, point.y, 20.0f, paint); } } } Gó™-7
  • 5. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/a pk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:padding="30dip" android:orientation="horizontal"> <LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="center"> <TextView android:text="My App" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_marginBottom="25dip" android:textSize="24.5sp" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="one" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="two" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="three" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="four" /> </LinearLayout> </LinearLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/ apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:padding="15dip" android:orientation="horizontal"> <LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="center" android:paddingLeft="20dip" android:paddingRight="20dip"> <TextView android:text="My App" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_marginBottom="20dip" android:textSize="24.5sp" /> <TableLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:stretchColumns="*"> <TableRow> <Button android:text="one" /> <Button android:text="two" /> </TableRow> <TableRow> <Button android:text="three" /> <Button android:text="four" /> </TableRow> </TableLayout> </LinearLayout> </LinearLayout> Gó™-8 Gó™-9 vice â¡ø android ÜŠO «èûQ™ ªêò™ð´‹. android. service.wallpaper.wallpaperserv ice engine â¡ø A÷£«ê ¬ôš õ£™«ðŠðK¬ù ªêò™ 𴈶õîŸè£ù A÷£ê£°‹. Þî¬ù îMó ïñ¶ ÜŠO «èûQ™ àœ÷ android mani fest.xml -™ "android software. live-wallpaper"ðò¡ð´ˆ¶ A«ø£‹ â¡ðî¬ù ÜŠO«è ê‚°ˆ ªîKòŠð´ˆî «õ‡ ´‹. Þî¡ Íô‹ ¬ôš õ£™ «ðŠð˜ ðò¡ð´ˆî£î ªê™ «ðCJ™ ÜŠO«èû¡ ðò¡ 𴋫𣶠ãŸð´‹ H¬ö¬ò îM˜‚èô£‹. ¹Fò Šó£ªü‚† å¡P¬ù ªî£ìƒA ram.android.wall paper â¡Á ªðòK´ƒèœ. Þƒ° Ý‚®M†®J¬ù ༠õ£‚è£b˜èœ, res/xml â¡ø ç«ð£™ ìK¬ù à¼õ£‚A ÜF™ my wallpaper.xml ç¬ðL¬ù ༠õ£‚°ƒèœ. mywallpaper. xml ç¬ðL™ õ£™«ðŠð¼‚è£ù îèõ½‹ ñŸÁ‹ Aó£çH‚ îèõ½‹ Þ¼‚°‹, ªêò™ð ´‹ õ£™«ðŠðK¡ CPò ðìˆ F¬ù "android thumbnail" â¡ ðF™ ªè£´‚èô£‹. ¬ñ õ£™«ðŠð¼‚è£ù Gó™èœ (Gó™-1)-™ ªè£´‚èŠ ð†´œ÷¶. Ü´ˆîî£è androidmain fest.xmlL™ "mywallpaperservi ce" ðŸPò îèõL¬ù ªîKòŠ ð´ˆî «õ‡´‹. androidmain fest.xml L¬ù Gó™-2™ àœ ÷¶ «ð£¡ø¶ ñ£Ÿøƒèœ ªêŒFì «õ‡´‹. ¬ñ ð£J¡† (Mypoint) â¡ø A÷£C¬ù Ü´ˆîî£è à¼õ£‚è «õ‡´‹. õ¬ó‰î
  • 6. - ªî£ì¼‹ ðìƒèO¡ îèõL¬ù «êIŠ ð ðò¡ð´‹. A÷£CŸ è£ù¬õ Gó™-3™ ªè£´‚èŠ ð†´œ÷¶. preference â¡ð¶ îèõ¬ô «êIˆ¶ H¡¹ ÜŠO«èû¡ ªêò™ðì ªî£ìƒAò¾ì¡ îèõ™è¬÷ F¼‹ð ªðÁ õ ðò¡ð´Aø¶. Þî¡ Íô‹ ðòù£÷˜èœ «î˜¾ Ü™ô¶ «î˜‰ªî´ˆî ªêò™èœ F¼‹ð A¬ì‚°‹. ꣡ø£è ðòù£÷˜ ÜŠO«è êQ™ background GøˆF¬ù ñ…ê÷£è ñ£ŸP»œ÷£˜. e‡´‹ ÜŠO«èû¡ «î£¡Á‹«ð£¶ ñ…ê÷£è «î£¡Áñ£Á ܬñ‚è «õ‡ ´‹ â¡ø£™ preference ðò¡ ð´ˆîô£‹. ÜŠO«èûQ™ instence Ýù shared preference-™ îè õ™ «êI‚°ñ£Á ܬñ‚è ô£‹. H¡¹ ðò¡ð´ˆ¶õ getshared preference ðò¡ 𴈶õî¡ Íô‹ ꣈Fòñ£‚ èô£‹. res/xml ç«ð£™ìK™ prefs. xml â¡ø ç¬ðL¬ù à¼õ£‚ A´ƒèœ. Ü«î «ïóˆF™ mypre ference activity â¡ø ªðò ¼¬ìò preference activity å¡ P¬ù à¼õ£‚A´ƒèœ. pref. xml-è£ù¬õ Gó™-4™ ªè£´‚ èŠð†´œ÷¶. mypreference activity- è£ù¬õ Gó™-5™ ªè£´‚èŠ ð†´œ÷¶. preference activity J¬ù à¼õ£‚Aò H¡ õ£™«ðŠð˜ ê˜ivC¬ù à¼õ£‚Aì «õ‡´‹. õ£™ «ðŠð˜ ê˜iv CŸè£ù¬õ Gó™ -6 ñŸÁ‹ Gó™-7™ ªè£´‚èŠð†´œ ÷¶. ÜŠO«èû¡ ªêò™ð†ì ¾ì¡ ðì‹-1™ àœ÷¶ «ð£¡Á F¬ó «î£¡Á‹ Þ‰î õ£™«ðŠð˜ Íô‹ «î¬õ ò£ù õ†ìƒè¬÷ Þ¬í‚è ¾‹ ñŸÁ‹ ÜN‚辋 º® »‹. Ü´ˆîî£è, F¬ó‚° ãŸð F¬óJ™ àœ÷ îèõ™ ñ£Á ñ£Á ܬñŠð¬îŠ 𣘊 «ð£‹. Šó£ªü‚† ªðòK¬ù screenorientationâ¡Áªè£´‚ 辋. res/layout/main.xmlâ¡ø ç¬ðL¡ Gó™ 8-™ àœ÷¶ «ð£¡Á ܬñˆF´ƒèœ. «ô‡† v«èŠHŸè£ù F¬ó ܬñŠ¬ð ãŸð´ˆ¶õ  layout-land â¡ø ç«ð£™ ìK¬ù ðì‹-2™ àœ÷¶ «ð£¡Á à¼õ£‚A´ƒèœ. res/layout-land/main.xml è£ù Gó™ 9-™ àœ÷¶ «ð£¡Á ܬñˆF´ƒèœ. ÜŠO«èû¬ù ªêò™ð´ˆ Fù£™«ð£˜†ªóŒ†«ñ£®™ ðì‹-3™ àœ÷¶ «ð£¡Á‹ «ô‡† v«èŠ «ñ£®™ ðì‹- 4™ àœ÷¶ «ð£¡Á‹ «î£¡Á‹.