اندرويد ببساطة

230

Upload: assem-makhyoun

Post on 22-Jun-2015

19 views

Category:

Documents


0 download

DESCRIPTION

about androiid

TRANSCRIPT

1 2

) / 2010 ( ) / 2011 (

1 3

) Java SE ( ) Android SDK ( ) Eclipse ( ) ADT ( ) Eclipse ( ) Android ( ) ( ) ( ) Mash up ( ) (

1 4

) 2009 ( ) 4 ( ) 2010 ( .

.

.

1 5

) (

) iPhone/iPad ( ) Android ( ) Windows Mobile ( ) Blackberry (

: www.badwi.com : [email protected] : 00966503415343 : http://twitter.com/badwi : http://www.facebook.com/badwi

) (

Data Mining .. - ) .(

: [email protected] : http://twitter.com/waelalwani 1 6

) 2005 ( ) 2007 ( . ) OHA )( OpenHandsetAlliance ( ) 48 ( . ) 2008 ( ) HTC ( ) Android ( ) 2009 ( ) T-Mobile ( ) HTC ( ) ( .

) Linux2.6 kernel ( ) GNU/Linux ( ) nativewindowingsystem ( ) glibc support ( ) GNU/Linux ( ) security ( ) memory management ( ) process management ( ) network stack ( ) drivermodel ( ) abstraction layer ( .

) ( ) Java ( ) Managed Code ( 1 7 ) Java( ) Java5 SE ( ) JDV ( ) JavaDalvik Virtual ( ) JVM ( ) JavaVirtual Machine ( .

. . . ) Web Kit OSS ( ) Googlechrome ( . ) OpenGLES ( ) SQLite ( . ) GPS ( ) accelerometer ( .

. .

) LinuxKernel ( :Display Driver Bluetooth DriverCamera Driver 1 8 Flash Memory Driver Binder (IPC) Driver Keypad Driver USB Driver Wi-Fi Driver Audio Driver Power Management

:Dalvik Virtual Machine Core Libraries

:Surface Manager Media Framework SQLite OpenGL ES Free Type Web Kit SGL SSL Libbc

1 9 :Activity Manager Window Manager Content Provider View System Notification Manager Package Manager Telephony Manager Resource Location Manager Sensor Manager :Home Contacts Phone Browser .

1 10

: - 1 11 : Activity Intent Service Content Provider

:

) Activity (

) Class ( ) Intent ( .

) Activity (

) Start ( ) Activity ( On Create On Start Om Restore Instance State On Resume 1 12 ) Running ( :On Start On Restart On Resume On Push On Save Instance State

) Paused ( :On Save Instance State On Resume On Stop

) Destroyed ( :On Destroy

/ ) Intent (

. 1 13

) Service (

) Media Player ( ) Service ( .

) Content Provider (

) Contacts ( .

) Activity (

) Window (

) Linear Layout (

) verticalor horizontal .( 1 14

) Frame Layout (

. ) Relative Layout (

) A ( ) B ( . ) Table Layout (

) HTML ( .

1 15

SDK (Software Development Kit) \ .NDA (Native Development Kit) ADT (Android Development Tools) JDK (Java Development Kit) JRE (Java Runtime Environment) JVM (Java Virtual Machine) AVD (Android Virtual Device) AVDM (Android Virtual Device Manager) APK (Android Package) 1 16 DDMS (Dalvik Debug Monitor Server) GPS (Global Position System) CMD (Command Line) ADB (Android Debug Bridge)

1 17

.

1 18 ) Java SE (

) JavaSE ( ) Java StandardEdition ( ) JDK 6 ( ) JDK ( (JavaDevelopmentKit ( ) JRE ( ) Java Runtime Environment( ) JRE ( ) JDK ( :

http://java.sun.com/javase/downloads/index.jsp

:

) Windows (

1 19

) Skip (

) SunDownload Manager ( 1 20

) Save (

1 21

) 70 (

) Accept (

1 22

) Next (

1 23

) Next (

1 24

) Finish (

1 25 ) Android SDK (

) Android SDK (

http://developer.android.com/sdk/index.html

) Windows (

1 26 - (: ) Download ( ) Save (

1 27 ) Save (

) 22 (

) WinZip ( ) Windows (

1 28

) Copy ( ) Paste (

) android-sdk-windows (

1 29

) SDK Setup (

) https ( 1 30

) Close (

) Cancel ( ) Settings (

1 31 ) ForceHttps ( ) Https ( ) Available Packages (

) 1.6 (

1 32

) 1.6 ( ) 2.1 ( ) 50 (% ) 1.6 ( . . ) 1.5 ( .

) Install Selected (

1 33 ) Accept All ( ) Install (

.. 1 34 ) Eclipse (

) Eclipse ( ) IBM ( .

:

e.org/downloads Eclipse http://www.

) Eclipse Classic 3.5.2 (

1 35

) Torrent ( .

) Save (

1 36

) Save (

) Eclipsee-SDK-3.5.2-win32 (

1 37 ) 163 ( ) WinZip ( ) Windows ( :

) Copy ( ) Paste ( :

) Eclipse (

1 38

1 39 ) ADT (

) ADT ( ) Eclipse (

) Eclipse (

) Usethisasdefaultanddonotaskagain (

) OK ( 1 40

) welcome ( ) X (

1 41 ) ADT ( ) Help ( ) Install New Software (

1 42 ) Add (

) Android ( ) Name ( ) Location (

e Eclipse ssl.google.com/android/ - https://dl /

) OK ( 1 43

) S ( ) https ( ) http (

1 44 ) Next (

1 45 ) I accept ( ) Finish (

) Eclipse ( 1 46

.

.

window ) Preferences ( : 1 47

:

1 48 ) Android ( :

) Browse ( : 1 49

) OK ( :

1 50 ) Apply ( :

.

. 1 51

) HellWorld () ( .

) ( . ) Eclipse (

1 52 ) File ( ) New ( ) New Project (

1 53

) Next (

1 54

) 1.6 ( :

Project Nam: AndroidVerySimple Build Target: 1.6 Application Name:VerySimple Package name:com.book.VerySimple Create Activity:Activity_VerySimple 1 55 ) Finish (

) Res ( ) Layout ( ) main.xml ( 1 56 ) Hello World (

1 57

) Eclipse (

) Properties ( ) Advanced (

1 58

) EnvironmentVariables (

1 59 ) UserEnvironment ( ) New (

) Name ( ) Path ( ) VariableValue (

C:\Documents and Settings\UserName\Desktop\android-sdk-windows\tools

) UserName ( ) tools (

1 60

) OK (

1 61

) OK ( ) OK (

) Start >>Run ( ) CMD (

1 62 ) OK (

android list target

) Enter (

1 63

) 1 (

android create project -n AndroidVerySimple -p c:\1\-k com.book.VerySimple -a Activity_VerySimple -t 1

) (

:

) AndroidVerySimple ( ) ProjectName ( ) -n (

1 64 ) com.book.VerySimple ( ) Package Name ( ) -k (

) Activity_VerySimple ( ) Activity Name ( ) -a (

) c:\1\ ( ) Path ( ) -p (

) 1 ( ) Target ( ) -t (

) Enter (

) c:\1 ( 1 65 ) Eclipse (

C:\Documents and Settings\UserName\workspace

1 66 ) Android (

) Window ( ) AndroidSDKandAVD Manager (

1 67

) android-sdk-windows ( ) SDKSetup ( .

) Virtual Devices ( ) New ( .

1 68

) 1.6 ( ) SD ( .

) VM_Android1.6 ( ) 1.6 ( ) 500 ( 1 69 ) Hardware ( ) New (

) SDCardSupport ( ) OK ( ) New ( GPS Support Accelerometer

1 70

) Create AVD (

) OK (

1 71

) Start ( ) Launch (

1 72

) RunAs ( ) Android Application ( 1 73

) HelloWorld ( 1 74

) Project ( ) Clean ( 1 75

) OK (

) X ( .

1 76

) Environment Variables (

) Start>>Run ( ) CMD (

) OK (

1 77

Android h

) enter (

) android-h ( ) h ( ) android (

1 78

android list target

) Enter (

1 79 ) 1 ( ) Enter (

android create avd -n VM_Android1.6 -t 1 ) VM_Android1.6 ( ) create avd-n ( ) -t ( ) 1 ( ) yes ( ) No ( ) Enter ( [yes]

1 80

: ) VM_Android1.6 ( ) VM_Android1.6_1 (

emulator -avd VM_Android1.6_1 1 81

: ) SDKSetup ( . 1 82 ) : DroidSans-Bold.ttf, DroidSansFallback.ttf, DroidSans.ttf (

adb remount adb shell rm /system/fonts/* adb push c:\fontss\DroidSans-Bold.ttf/system/fonts/ adb push c:\fontss\DroidSansFallback.ttf/system/fonts/ adb push c:\fontss\DroidSans.ttf/system/fonts/ :adb shell rm /system/app/AlarmClock.apk

adb install c:\Vending.apk 1 83

) DDMS (

) Eclipse ( ) DDMS ( ) + (

) DDMS ( 1 84

) DDMS ( ) Java (

) DDMS ( 1 85

) File Explorer ( ) Threads ( ) Heap ( ) Allocation Tracker (

) FileExplorer ( ) sdcard ( . : ) ( . ) Devices ( ) USB 1 86 Driver ( ) SDK ( .

) Emulator Control ( ) SMS ( ) GPS ( ) Longitude ( ) latitude ( ) GPS ( .

1 87

) Browser ( 1 88

) Google.com in English(

: 1 89

) slideme.org (

1 90

) SAMv2.42 (

1 91

1 92 ) Done (

) Slide Me ( ) Menu ( 1 93

) Settings (

1 94 ) Applications (

) Unknownsources ( ) Development (

1 95 ) DDMS (

) SlideMe (

1 96 ) slideme.org (

) Utilities ( ) OI ShoppingList (

) Utilities ( ) OIShopping List (

1 97

) Terms&Download (

1 98

) Install ( ) Notifications (

1 99 ) Install (

) Open (

) apk ( ) Download ( ) SDCard ( SlideMe ) AppsInstaller ( ) apk ( ) Slide Me (

1 100 .

: ) DDMS ( ) Devices ( ) ( ) ScreenCapture (

android-sdk-windows\platforms\android-1.6\skins\HVGA

1 101 ) (

.

) ( .

) Eclipse ( ) Task List ( : 1 102

1 103

) X ( ) Project>>Clean ( .

) ( ) src ( ) com.android.TaskList ( ) Activity_TaskList (

1 104

) ( ) res ( ) layout ( ) main.xml ( 1 105

) main.xml ( ) Config ( ) Landscape ( ) Portrait ( 1 106

) Layout ( ) Views ( .

) main.xml ( ) layout ( ) main.xml ( : 1 107

1 2 7 12 1 108

) Eclipse ( ) Show Line Numbers (

1 109

1 ) XML ( ) UTF-8 (

2 1 110 ) 2 ( ) 6 (

) LinearLayout ( ) 4 (

) LinearLayout ( ) orientation ( ) horizontal ( ) layout_width ( ) layout_height ( ) fill_parent (

7 1 111 ) 7 ( ) 11 (

) layout_width ( ) fill_parent ( ) layout_height ( ) wrap_content ( ) text ( ) @string/hello (

12 ) 12 ( ) LinearLayout (

) TextView ( ) res ( ) Value ( () 1 112

) hell ( ) HelloWorld,Activity_TaskList (! ) Task List (

1 113

) app_name ( ) TaskList ( ) My1stApplication (

) add ( 1 114

) color ( ) OK ( Name : TextViewBackColor Value: #FF0000

1 115 ) #FF0000 ( ) RGB ( ) HTML ( ) FF ( ) R ( ) Red ( ) 00 ( ) G ( ) Green ( ) 00 ( ) B ( ) Blue (

) string.xml (

) main.xml ( ) layout (

) background ( ) TextViewBackColor ( 1 116

) My 1st Application ( ) Task List (

: ) String ( ) String ( 1 117

) TextView ( ) MainTextView (

) res >> layout( ) Properties ( ) id ( ) MainTextView ( 1 118

) main.xml (

android:id="@+id/MainTextView" 1 119 ) MainTextView ( ) Relative (

) @+id/ (

@id/MainTextView

) + (

) (

) Title ( ) Details ( 1 120 ) Menu (

) Menu (

) Activity_TaskList ( ) Menu ( ) View (

import android.view.Menu; import android.view.View;

import android.widget.TextView;

import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.Menu; import android.widget.TextView; public class Activity_TaskList extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { 1 121 super.onCreate(savedInstanceState); setContentView(R.layout.main); }} ) (

) activities,alertdialog,toast (

) Welcome (

import android.widget.Toast; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

Toast.makeText(Activity_TaskList.this,"Welcome",0).show(); 1 122 TextView[] tvs; tvs = new TextView[10]; for (int i=0; inew>project Android Android Project

1 140

:

1 141

1 142

UTF-8 . Properties:

1 143

Class intro:

:

1 144

( android.app.Activity ) ) ( . main.xml .

1 145

: . main.xml colors.xml values( values new>file>colors.xml. lowercase ). :

#FFFFFFFF

1 146

. strings.xml . main.xml :

ImageView . res/drawable-hdpi res/drawable ) ). LinearLayout RelativeLayout . 1 148 RelativeLayout ) ( . . android:layout_below . Layout :

intro . ) : ) package android.prog.easily; 1 149 import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button; public class intro extends Activity {// private Button getbest50; @Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); // main setContentView(R.layout.main);setUpViews();} private void setUpViews() {getbest50 = (Button)findViewById(R.id.search);getbest50.setText(" "); // getbest50.setOnClickListener(new View.OnClickListener() {public void onClick(View v) 1 150 {top50Handler();}}); } protected void top50Handler() { }} : . intro.java ( ( RatedItem.java : package android.prog.easily; import java.io.Serializable; public class RatedItem implements Serializable {private static final long serialVersionUID = 5500258407135652423L; 1 151 private String name;private int id;private int voteCount;private double wScore; public RatedItem(String name, int id, int voteCount, double wScore) {this.name = name;this.id = id;this.voteCount = voteCount;this.wScore = wScore;} public String getName() {return name;} public void setName(String name) {this.name = name;} public int getId() {return id;} public void setId(int id) { 1 152 this.id = id;} public int getVoteCount() {return voteCount;} public void setVoteCount(int voteCount) {this.voteCount = voteCount;} public double getwScore() {return wScore;} public void setwScore(int wScore) {this.wScore = wScore;} } RestDroidApplication.java Activities ) ). 1 153 : package android.prog.easily; import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.ArrayList; import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.DefaultHttpClient;import org.json.JSONException;import org.json.JSONObject;import android.app.Application; public class RestDroidApplication extends Application{ API KeyQaym //private String key = "xxxxxxxxxxxxxxxxxxxx"; private int[] countryAndCityIds;private JSONObject[] ratedRestaurants;; globalAdapterData >RatedItem ArrayList< private; itemOnMap RatedItem privateprivate String branchesDetailsText; public String getBranchesDetailsText() 1 154 {return branchesDetailsText;} public void setBranchesDetailsText(String branchesDetailsText) {this.branchesDetailsText = branchesDetailsText;} getItemOnMap()RatedItem public{; itemOnMap return} itemOnMap)RatedItem setItemOnMap( void public{= itemOnMap; itemOnMap . this} @Overridepublic void onCreate() {super.onCreate();} @Overridepublic void onTerminate() {super.onTerminate();} 1 155 // HTTP RESTpublic String queryRESTurl(String url){ HttpClient httpclient = new DefaultHttpClient();

HttpGet httpget = new HttpGet(url); HttpResponse response; try { response = httpclient.execute(httpget);

HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String result1 = convertStreamToString(instream); instream.close();

return result1; } }

catch (IOException e) 1 156 {

}

return null; }// String public String convertStreamToString(InputStream is) throws IOException {

if (is != null) {StringBuilder sb = new StringBuilder();String line; try {BufferedReader reader = new BufferedReader(new while ((line = reader.readLine()) != null) {sb.append(line).append("\n");}} finally {is.close();} 1 157

return sb.toString();}

else {return "";}}/* JSON JSON Key/value .. ) ..( " " JSON*/public JSONObject[] retrieveJSONs(String urlString) {String result = queryRESTurl(urlString);JSONObject[] jarr = null;

if (result != null) { try { result = result.substring(1, result.length()-1); 1 158 int counter = 0; boolean firstSeen = false; boolean secondSeen = false; // for JSON for (int i = 0; i < result.length(); i++) { if (result.charAt(i) == '{' && firstSeen == { firstSeen = true; counter++; } else if (result.charAt(i) == '{' && firstSeen ==true) { secondSeen = true; } if (result.charAt(i) == '}' && secondSeen ==true) { secondSeen = false; } else if (result.charAt(i) == '}' && secondSeen ==false) { firstSeen = false; 1 159 } } jarr = new JSONObject [counter];

int ind1 = 0; int ind2 = 0; boolean firstSeenS = false; boolean secondSeenS = false; // JSON for (int i = 0; i < result.length(); i++) { firstSeenS = false; secondSeenS = false; if (result.charAt(i) == '{' && firstSeenS ==false) { firstSeenS = true; ind1 = i; for (int j = i+1; j < result.length(); j++) { if (result.charAt(j) == '{' && { secondSeenS = true; } 1 160 if (result.charAt(j) == '}' && { secondSeenS = false; } else if (result.charAt(j) == '}' && secondSeenS == false) { String mid = jarr[ind2] = new ind2++; i = j; break; } } } } } catch (JSONException e) { }}

return jarr;}

// API public String getUrlStringCommand(String command) 1 161 { ;" http://api.qaym.com/0.1/ " String service_url = String url = "";url = service_url + command + "/key=" + key;

return url;} public void setCountryAndCityIds(int[] countryAndCityIds) {this.countryAndCityIds = countryAndCityIds;} public int[] getCountryAndCityIds() {return countryAndCityIds;} public JSONObject[] getRatedRestaurants() {return ratedRestaurants;} public void setRatedRestaurants(JSONObject[] ratedRestaurants) {this.ratedRestaurants = ratedRestaurants;} > getGlobalAdapterData()RatedItem ArrayList< public 1 162 {; globalAdapterData return} public void >RatedItem ist< setGlobalAdapterData(ArrayLglobalAdapter) {= globalAdapter; globalAdapterData . this} int getGlobalAdapterDataItem( RatedItem publicposition) {.get(position); globalAdapterData return}} intro.java : protected void top50Handler() {try {// API " "String attrcommand = "cities/" + "57" + "/items/top"; 1 163 // accessApplicationMethods() RestDroidApplication.java String attributesCommand = accessApplicationMethods().getUrlStringCommand(attrcommand); JSONObject[] topCities = accessApplicationMethods().retrieveJSONs(attributesCommand); // ReatedItem \ JSON ArrayList sRest = new ArrayList(); if (topCities != null){for (int ff = 0; ff < topCities.length; ff++){// JSON "item_id" int id = Integer.parseInt(topCities[ff].getString("item_id")); 1 164 String name = topCities[ff].getString("item_name"); int voteConutt = Integer.parseInt(topCities[ff].getString("total_number_of_votes")); double weScore = Double.parseDouble(topCities[ff].getString("weighted_score")); // double weScoreR = weScore * 100;weScoreR = Math.round(weScoreR);weScoreR = weScoreR / 10 / 2; RatedItem singleRest = new RatedItem(name,id, voteConutt, weScoreR);sRest.add(singleRest);}}else{RatedItem singleRest = new RatedItem("Empty List",0, 0, 0);sRest.add(singleRest);} 1 165 accessApplicationMethods().setGlobalAdapterData(sRest);goToBest50Act();// ***} catch (JSONException e) { }} // RestDroidApplication.java protected RestDroidApplication accessApplicationMethods() {return (RestDroidApplication)getApplication();} . : // *** goToBest50Act : protected void goToBest50Act() {); class . Best50 ,this Intent( new Intent goToBest = startActivity(goToBest);} 1 166 intro.java : package android.prog.easily; import java.util.ArrayList; import org.json.JSONException;import org.json.JSONObject; import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button; public class intro extends Activity {// private Button getbest50; @Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// main setContentView(R.layout.main);setUpViews();} private void setUpViews() 1 167 {getbest50 = (Button)findViewById(R.id.search);.setText(" // getbest50.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {top50Handler();}}); } protected void goToBest50Act() {); class . Best50 ,this Intent( new Intent goToBest = startActivity(goToBest);} protected void top50Handler() {try {// API " "String attrcommand = "cities/" + "57" + "/items/top"; 1 168 // accessApplicationMethods() RestDroidApplication.javaString attributesCommand = accessApplicationMethods().getUrlStringCommand(attrcommand); JSONObject[] topCities = accessApplicationMethods().retrieveJSONs(attributesCommand); // ReatedItem \ JSON ArrayList sRest = new ArrayList(); if (topCities != null){for (int ff = 0; ff < topCities.length; ff++){// JSON "item_id" int id = Integer.parseInt(topCities[ff].getString("item_id")); String name = topCities[ff].getString("item_name"); int voteConutt = 1 169 Integer.parseInt(topCities[ff].getString("total_number_of_votes")); double weScore = Double.parseDouble(topCities[ff].getString("weighted_score")); // double weScoreR = weScore * 100;weScoreR = Math.round(weScoreR);weScoreR = weScoreR / 10 / 2; RatedItem singleRest = new RatedItem(name,id, voteConutt, weScoreR);sRest.add(singleRest);}}else{RatedItem singleRest = new RatedItem("Empty List",0, 0, 0);sRest.add(singleRest);} // RestDroidApplication.java Activities 1 170 accessApplicationMethods().setGlobalAdapterData(sRest);goToBest50Act();} catch (JSONException e) { }} // RestDroidApplication.java protected RestDroidApplication accessApplicationMethods() {return (RestDroidApplication)getApplication();} } RestDroidApplications . Intent ( action ( . 1 171 Best50.java. : RatedRestaurantListItem.java rest_list_item.xml ) ( - - \ RelativeLayout . RelativeLayout xml - -. RatedRestaurantListItem.java : package android.prog.easily; import android.content.Context;import android.util.AttributeSet;import android.widget.RelativeLayout; public class RatedRestaurantListItem extends RelativeLayout{ public RatedRestaurantListItem(Context context, AttributeSet attr) {super(context, attr);}} rest_list_item.xml : 1 172 res>layout( layoutnew>file). ) ) ( ): 1 173 RatedRestaurantListItem.java ) .( : 1 174 package android.prog.easily; import android.prog.easily.R;import android.content.Context;import android.util.AttributeSet;import android.widget.CheckedTextView;import android.widget.RelativeLayout;import android.widget.TextView; public class RatedRestaurantListItem extends RelativeLayout{private CheckedTextView ratedButton;private RatedItem ratedItem1;private TextView texty;private TextView texty2; public RatedRestaurantListItem(Context context, AttributeSet attr) {super(context, attr);} // xml @Overrideprotected void onFinishInflate() {super.onFinishInflate();ratedButton = (CheckedTextView)findViewById(R.id.ctext); 1 175 texty = (TextView)findViewById(R.id.ratedlabel);texty2 = (TextView)findViewById(R.id.scorelabel);} // public void setRatedItem(RatedItem ratedItem1) {this.ratedItem1 = ratedItem1;ratedButton.setText(ratedItem1.getName());texty.setText(" : "+ratedItem1.getVoteCount());texty2.setText(" : "+ratedItem1.getwScore() + "/5");} public RatedItem getRatedItem() {return ratedItem1;}} Best50.java : rated_rest_list.xml :

Best50.java. . \ Activityintro.java. ListActivityList Adapter Design Patterns . ) ( ) Best50).Best50 Best50.java. ) ( 1 177 ! innerclass . : package android.prog.easily; import java.util.ArrayList; import android.app.Activity;import android.app.ListActivity;import android.content.Intent;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.RatingBar;import android.widget.TextView; public class Best50 extends ListActivity{private TextView selectAttr;private RatedRestaurantListAdapter adapter; @Overridepublic void onCreate(Bundle savedInstanceState) { 1 178 super.onCreate(savedInstanceState);setContentView(R.layout.rated_rest_list);setUpViews();} // @Overrideprotected void onListItemClick(ListView l, View v, int position, long id) {super.onListItemClick(l, v, position, id); RatedItem ite = accessApplicationMethods().getGlobalAdapterDataItem(position); accessApplicationMethods().setItemOnMap(ite); goToViewOnMapActivity(); } private void goToViewOnMapActivity() {,this Intent( new Intent goToMapActivity = startActivity(goToMapActivity);} private void setUpViews() 1 179 {selectAttr = (TextView)findViewById(R.id.RRselect);selectAttr.setText(" "); // adapter = new RatedRestaurantListAdapter setListAdapter(adapter);} // InnerClass Adapter .// ArrayAdapterclass RatedRestaurantListAdapter extends ArrayAdapter { Activity context;private ArrayList myRatedItems;RatedRestaurantListAdapter(Activity context, {super(context, R.layout.rest_list_item, items);this.context=context;this.myRatedItems = items;}// - -public View getView(int position, View 1 180 convertView, ViewGroupparent) { RatedRestaurantListItem row = (RatedRestaurantListItem)convertView;if (null == row) {// LayoutInflator // // LayoutInflater inflater=context.getLayoutInflater(); row = (RatedRestaurantListItem)inflater.inflate(R.layout.rest_list_item, null);} row.setRatedItem(myRatedItems.get(position)); RatingBar rateBar = (RatingBar)row.findViewById(R.id.rate);rateBar.setStepSize((float) 0.1); rateBar.setRating((float)myRatedItems.get(position).getwSco 1 181 re()); return row;} public RatedItem getItem(int position){return myRatedItems.get(position);} public void reload(){// notifyDataSetChanged();} } protected RestDroidApplication accessApplicationMethods() {return (RestDroidApplication)getApplication();} } OnListItemClick . ) position 1 182 . ( . ViewOnMapActivity.java . xml( ( : view_map.xml : android:apikey . ) SDK- debugging .( ) cmd trminal shell): $ keytool -list -alias androiddebugkey \ -keystore xxx \ -storepass android -keypass android xxx :Windows Vista: C:\Users\\.android\debug.keystore Windows XP: C:\Documents and Settings\\.android\debug.keystore OS X and Linux: ~/.android/debug.keystore :Certificate fingerprint (MD5): 94:1E:43:49:87:73:BB:E6:A6:88:D7:20:F1:8E:B5:98 :signup.html - api - http://code.google.com/android/maps 1 184 . API xxxxxxxxxx. :- ons/google - com/android/add http://code.google.apis/mapkey.html ViewOnMapActivity.java : AddressOverlay.java: package android.prog.easily; import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Point;import android.location.Address; import com.google.android.maps.GeoPoint;import com.google.android.maps.MapView;import com.google.android.maps.Overlay;import com.google.android.maps.Projection; public class AddressOverlay extends Overlay{private static final int CONTAINER_RADIUSprivate static final int CONTAINER_SHADOW_OFFSET = 1; 1 185 private Address address;private GeoPoint geopoint;Bitmap bb; public AddressOverlay(Address address) {super();assert(null != address);// this.setAddress(address);Double convertedLongitude = address.getLongitude() * 1E6;Double convertedLatitude = address.getLatitude() * 1E6; setGeopoint(new GeoPoint(convertedLatitude.intValue(),convertedLongitude.intValue()));} // @Overridepublic void draw(Canvas canvas, MapView mapView, boolean shadow) {super.draw(canvas, mapView, shadow); Point locationPoint = new Point(); Projection projection = mapView.getProjection(); projection.toPixels(getGeopoint(), locationPoint); Paint containerPaint = new Paint();containerPaint.setAntiAlias(true); 1 186 int containerX = locationPoint.x; int containerY = locationPoint.y;if (shadow) {containerX += CONTAINER_SHADOW_OFFSET;containerY += CONTAINER_SHADOW_OFFSET;containerPaint.setARGB(90, 0, 0, 0); canvas.drawCircle(containerX, containerY, CONTAINER_RADIUS, containerPaint);} else {containerPaint.setColor(Color.GREEN);canvas.drawCircle(containerX, containerY, CONTAINER_RADIUS, containerPaint);}} public void setAddress(Address address) {this.address = address;} public Address getAddress() {return address;} 1 187 public void setGeopoint(GeoPoint geopoint) {this.geopoint = geopoint;} public GeoPoint getGeopoint() {return geopoint;}} ViewOnMapActivity.java: package android.prog.easily; import java.io.IOException;import java.util.List; import org.json.JSONException;import org.json.JSONObject; import android.graphics.Bitmap;import android.location.Address;import android.location.Geocoder;import android.os.Bundle;import android.widget.TextView; import com.google.android.maps.GeoPoint;import com.google.android.maps.MapActivity; 1 188 import com.google.android.maps.MapController;import com.google.android.maps.MapView;import com.google.android.maps.Overlay; public class ViewOnMapActivity extends MapActivity{public static final String ADDRESS_RESULT = "address"; private MapView mapView;private Address address;private TextView restName;private JSONObject[] restaurantsLocObjects;private String[] restaurantsBranchesNames;private double [][] longLat;private int maxLat = 0;private int minLat = 0;private int maxLon = 0;private int minLon = 0;Bitmap bmp; @Overrideprotected void onCreate(Bundle bundle) {super.onCreate(bundle);setContentView(R.layout.view_map);setUpViews(); bringRestLocations(); 1 189 mapCurrentAddress();}

// private void bringRestLocations() {try{// ID Best50.java RestDroidApplicationint restNum = accessApplicationMethods().getItemOnMap().getId(); // API String command = "items/" + restNum + "/locations"; String restaurantsCommand = accessApplicationMethods().getUrlStringCommand(command); restaurantsLocObjects = accessApplicationMethods().retrieveJSONs(restaurantsCommand); restaurantsBranchesNames = new String[restaurantsLocObjects.length]; longLat = new double[restaurantsLocObjects.length][2]; 1 190 for (int i = 0; i < restaurantsBranchesNames.length; i++){restaurantsBranchesNames[i] = (i+1) + "\n" +" : " + restaurantsLocObjects[i].getString("country") + "\n"+ " : " + restaurantsLocObjects[i].getString("city") + "\n"+ " : "+ restaurantsLocObjects[i].getString("location_id") + "\n"+ " : "+ restaurantsLocObjects[i].getString("address") + "\n"+ " : "+ restaurantsLocObjects[i].getString("phone") + "\n"+ " : "+ restaurantsLocObjects[i].getString("title") + "\n"; longLat[i][0] = Double.parseDouble(restaurantsLocObjects[i].getString("latitude"));longLat[i][1] = Double.parseDouble(restaurantsLocObjects[i].getString("longitude"));} 1 191 } catch (JSONException e) { } } // protected void mapCurrentAddress() {Geocoder g = new Geocoder(this);List addresses; boolean firstTime = true; for (int i = 0; i < restaurantsBranchesNames.length; i++){try {addresses = g.getFromLocation(longLat[i][0], longLat[i][1], 1);if (addresses.size() > 0) {address = addresses.get(0);List mapOverlays = mapView.getOverlays();AddressOverlay addressOverlay = new AddressOverlay(address); 1 192 mapOverlays.add(addressOverlay); // zoom // if (firstTime){minLat = addressOverlay.getGeopoint().getLatitudeE6();maxLat = addressOverlay.getGeopoint().getLatitudeE6();minLon = addressOverlay.getGeopoint().getLongitudeE6();maxLon = addressOverlay.getGeopoint().getLongitudeE6();firstTime = false;} minLat = (minLat > addressOverlay.getGeopoint().getLatitudeE6()) ? addressOverlay.getGeopoint().getLatitudeE6() : minLat;maxLat = (maxLat < addressOverlay.getGeopoint().getLatitudeE6()) ? addressOverlay.getGeopoint().getLatitudeE6() : maxLat; minLon = (minLon > addressOverlay.getGeopoint().getLongitudeE6()) ? 1 193 addressOverlay.getGeopoint().getLongitudeE6() : minLon;maxLon = (maxLon < addressOverlay.getGeopoint().getLongitudeE6()) ? addressOverlay.getGeopoint().getLongitudeE6() : maxLon; mapView.invalidate();}else { }} catch (IOException e) { }} final MapController mapController = mapView.getController();GeoPoint center = new GeoPoint((maxLat + minLat)/2,(maxLon + minLon)/2); mapController.animateTo(center, new Runnable() {public void run() {mapController.zoomToSpan(maxLat - minLat,maxLon - minLon);} 1 194 }); } private void setUpViews() {restName = (TextView)findViewById(R.id.restaurantNameMap); restName.setText(accessApplicationMethods().getItemOnMap().getName());mapView = (MapView)findViewById(R.id.map); // Zoomin/outmapView.setBuiltInZoomControls(true);} @Overrideprotected boolean isLocationDisplayed() {return true;} @Overrideprotected boolean isRouteDisplayed() {return false;} protected RestDroidApplication 1 195 accessApplicationMethods() {return (RestDroidApplication)getApplication();}} :

1 196

! .. AndroidManifest.xml 1 197 . . :

1 198

1 199

:

1 200 1 201 1 202

1 203 :- ) ( : $ cd /Developer/android-sdk-mac_86/tools/ $ ./adb devices : List of devices attachedemulator-5554device - ) ( : $ cd /Developer/android-sdk-mac_86/tools/ $ ./emulator -avd GPSenables -partition-size 500 -avdGPSenables \ . . - ) ( : 1 204 $ ./adb remount

remount succeeded ) ): $ ./adb push /Users/wa2el/Desktop/fontss/DroidSans-Bold.ttf/system/fonts/ $ ./adb push /Users/wa2el/Desktop/fontss/DroidSans.ttf/system/fonts/ $ ./adb push /Users/wa2el/Desktop/fontss/DroidSansFallback.ttf/system/fonts/ -) xml) .

1 205 : : - - - - \ :

Orientation Widgets . Vertical Horizontal . 1 206 layout_width fill_parent. layout_height . .

android:text .android:id . . . fill_parent 1 207 (layout_width layout_height). wrap_content . . ) ):

1 208 ( Layout .. XML )

:

. LinearLayoutOrientation. Widgets : ) ): 1 210

android:layout_weight . :

1 212

Widgets android:layout_agravity Widgets alignment . android:layout_marginLeft Pixels . android:layout_marginLeftandroid:orientation=horizontal :

android:layout_gravityandroid:orientation=vertical:

1 214

.

android:gravityandroid:paddingLeft . \ Orientation . . x.setOrientation(LinearLayout.HORIZONTAL); 1 215 x Widget . - . >TableRow