android verysimplebook... أندرويد ببساطة

230

Upload: ahmed-ismail

Post on 12-May-2015

1.187 views

Category:

Education


13 download

DESCRIPTION

تعلم أندرويد ببساطة

TRANSCRIPT

  • 1. 1 2 )/2010( )/2011(

2. 1 3 )Java SE( )Android SDK( )Eclipse( )ADT( )Eclipse( )Android( ) ( ) ( )Mash up( ) ( 3. 1 4 )2009( )4()2010( . . . 4. 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 5. 1 6 )2005( )2007(. )OHA) (Open Handset Alliance( )48( . )2008( )HTC( )Android( )2009( )T-Mobile( )HTC( )(. )Linux 2.6 kernel( )GNU/Linux( )native windowing system()glibc support( )GNU/Linux( )security( )memory management( )process management( )network stack( )driver model( )abstraction layer(. )( )Java()Managed Code( 6. 1 7 )Java( )Java5 SE( )JDV( )Java Dalvik Virtual( )JVM( )Java Virtual Machine(. . . . )Web Kit OSS( )Google chrome(. )OpenGL ES( )SQLite( . )GPS( )accelerometer(. . . )Linux Kernel( : Display Driver Bluetooth Driver Camera Driver 7. 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 8. 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 . 9. 1 10 : - 10. 1 11 : Activity Intent Service Content Provider : )Activity( )Class( )Intent( . )Activity( )Start()Activity( On Create On Start Om Restore Instance State On Resume 11. 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( . 12. 1 13 )Service( )Media Player( )Service(. )Content Provider( )Contacts(. )Activity( )Window( )Linear Layout( )vertical or horizontal.( 13. 1 14 )Frame Layout( . )Relative Layout( )A( )B(. )Table Layout( )HTML(. 14. 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) 15. 1 16 DDMS (Dalvik Debug Monitor Server) GPS (Global Position System) CMD (Command Line) ADB (Android Debug Bridge) 16. 1 17 . 17. 1 18 )Java SE( )Java SE( )Java Standard Edition( )JDK 6( )JDK( (Java Development Kit( )JRE( )Java Runtime Environment( )JRE( )JDK( : http://java.sun.com/javase/downloads/index.jsp : )Windows( 18. 1 19 )Skip( )Sun Download Manager( 19. 1 20 )Save( 20. 1 21 )70( )Accept( 21. 1 22 )Next( 22. 1 23 )Next( 23. 1 24 )Finish( 24. 1 25 )Android SDK( )Android SDK( http://developer.android.com/sdk/index.html )Windows( 25. 1 26 -( : )Download( )Save( 26. 1 27 )Save( )22( )WinZip( )Windows( 27. 1 28 )Copy( )Paste( )android-sdk-windows( 28. 1 29 )SDK Setup( )https( 29. 1 30 )Close( )Cancel( )Settings( 30. 1 31 )Force Https( )Https( )Available Packages( )1.6( 31. 1 32 )1.6( )2.1( )50(% )1.6(. . )1.5( . )Install Selected( 32. 1 33 )Accept All( )Install( .. 33. 1 34 )Eclipse( )Eclipse( )IBM( . : e.org/downloadsEclipsehttp://www. )Eclipse Classic 3.5.2( 34. 1 35 )Torrent( . )Save( 35. 1 36 )Save( )Eclipsee-SDK-3.5.2- win32( 36. 1 37 )163( )Win Zip( )Windows( : )Copy( )Paste( : )Eclipse( 37. 1 38 38. 1 39 )ADT( )ADT( )Eclipse( )Eclipse( )Use this as default and do not ask again( )OK( 39. 1 40 )welcome( )X( 40. 1 41 )ADT( )Help( )Install New Software( 41. 1 42 )Add( )Android( )Name( )Location( eEclipsessl.google.com/android/-https://dl/ )OK( 42. 1 43 )S( )https()http( 43. 1 44 )Next( 44. 1 45 )I accept( )Finish( )Eclipse( 45. 1 46 . . window )Preferences( : 46. 1 47 : 47. 1 48 )Android( : )Browse( : 48. 1 49 )OK( : 49. 1 50 )Apply( : . . 50. 1 51 )Hell World( ) ( . ) ( . )Eclipse( 51. 1 52 )File( )New()New Project( 52. 1 53 )Next( 53. 1 54 )1.6( : Project Nam: AndroidVerySimple Build Target: 1.6 Application Name:VerySimple Package name:com.book.VerySimple Create Activity:Activity_VerySimple 54. 1 55 )Finish( )Res( )Layout( )main.xml( 55. 1 56 )Hello World( 56. 1 57 )Eclipse( )Properties( )Advanced( 57. 1 58 )Environment Variables( 58. 1 59 )User Environment( )New( )Name( )Path( )Variable Value( C:Documents and SettingsUserNameDesktopandroid-sdk-windowstools )UserName( )tools( 59. 1 60 )OK( 60. 1 61 )OK( )OK( )Start >> Run( )CMD( 61. 1 62 )OK( android list target )Enter( 62. 1 63 )1( android create project -n AndroidVerySimple -p c:1 -k com.book.VerySimple -a Activity_VerySimple -t 1 ) ( : )AndroidVerySimple( )Project Name( )-n( 63. 1 64 )com.book.VerySimple( )Package Name( )-k( )Activity_VerySimple( )Activity Name( )-a( )c:1( )Path( )-p( )1( )Target( )-t( )Enter( )c:1( 64. 1 65 )Eclipse( C:Documents and SettingsUserNameworkspace 65. 1 66 )Android( )Window( )Android SDK and AVD Manager( 66. 1 67 )android- sdk-windows( )SDK Setup( . )Virtual Devices( )New( . 67. 1 68 )1.6( )SD( . )VM_Android1.6( )1.6( )500( 68. 1 69 )Hardware( )New( )SD Card Support( )OK( )New( GPS Support Accelerometer 69. 1 70 )Create AVD( )OK( 70. 1 71 )Start( )Launch( 71. 1 72 )Run As( )Android Application( 72. 1 73 )HelloWorld( 73. 1 74 )Project( )Clean( 74. 1 75 )OK( )X( . 75. 1 76 )Environment Variables( )Start >> Run( )CMD( )OK( 76. 1 77 Android h )enter( )android -h( )h( )android( 77. 1 78 android list target )Enter( 78. 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] 79. 1 80 : )VM_Android1.6( )VM_Android1.6_1( emulator -avd VM_Android1.6_1 80. 1 81 : )SDK Setup( . 81. 1 82 ) :DroidSans-Bold.ttf, DroidSansFallback.ttf, DroidSans.ttf( adb remount adb shell rm /system/fonts/* adb push c:fontssDroidSans-Bold.ttf /system/fonts/ adb push c:fontssDroidSansFallback.ttf /system/fonts/ adb push c:fontssDroidSans.ttf /system/fonts/ : adb shell rm /system/app/AlarmClock.apk adb install c:Vending.apk 82. 1 83 )DDMS( )Eclipse( )DDMS( )+( )DDMS( 83. 1 84 )DDMS( )Java( )DDMS( 84. 1 85 )File Explorer( )Threads()Heap( )Allocation Tracker( )File Explorer( )sd card( . : ) ( . )Devices( )USB 85. 1 86 Driver( )SDK( . )Emulator Control( )SMS( )GPS( )Longitude()latitude( )GPS(. 86. 1 87 )Browser( 87. 1 88 )Google.com in English( : 88. 1 89 )slideme.org( 89. 1 90 )SAM v2.42( 90. 1 91 91. 1 92 )Done( )Slide Me( )Menu( 92. 1 93 )Settings( 93. 1 94 )Applications( )Unknown sources( )Development( 94. 1 95 )DDMS( )Slide Me( 95. 1 96 )slideme.org( )Utilities( )OI Shopping List( )Utilities( )OI Shopping List( 96. 1 97 )Terms & Download( 97. 1 98 )Install( )Notifications( 98. 1 99 )Install( )Open( )apk( )Download( )SD Card( Slide Me )Apps Installer( )apk( )Slide Me( 99. 1 100 . : )DDMS( )Devices( ) ()Screen Capture( android-sdk-windowsplatformsandroid-1.6skinsHVGA 100. 1 101 ) ( . )( . )Eclipse( )Task List( : 101. 1 102 102. 1 103 )X( )Project >> Clean( . )( )src( )com.android.TaskList( )Activity_TaskList( 103. 1 104 ) ( )res( )layout( )main.xml( 104. 1 105 )main.xml( )Config( )Landscape( )Portrait( 105. 1 106 )Layout( )Views( . )main.xml( )layout( )main.xml( : 106. 1 107 1 2 7 12 107. 1 108 )Eclipse( )Show Line Numbers( 108. 1 109 1 )XML( )UTF-8( 2 109. 1 110 )2( )6( )LinearLayout( )4( )LinearLayout( )orientation( )horizontal( )layout_width( )layout_height( )fill_parent( 7 110. 1 111 )7( )11( )layout_width( )fill_parent( )layout_height( )wrap_content( )text( )@string/hello( 12 )12( )LinearLayout( )TextView( )res( )Value( () 111. 1 112 )hell( )Hello World, Activity_TaskList(! )Task List( 112. 1 113 )app_name( )Task List()My 1st Application( )add( 113. 1 114 )color( )OK( Name : TextViewBackColor Value: #FF0000 114. 1 115 )#FF0000( )RGB( )HTML( )FF( )R( )Red( )00( )G( )Green( )00( )B( )Blue( )string.xml( )main.xml( )layout( )background( )TextViewBackColor( 115. 1 116 )My 1st Application( )Task List( : )String( )String( 116. 1 117 )TextView( )MainTextView( )res >> layout( )Properties( )id( )MainTextView( 117. 1 118 )main.xml( android:id="@+id/MainTextView" 118. 1 119 )MainTextView( )Relative( )@+id/( @id/MainTextView )+( ) ( )Title( )Details( 119. 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) { 120. 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() ; 121. 1 122 TextView[] tvs; tvs = new TextView[10]; for (int i=0; inew>project Android Android Project 139. 1 140 : 140. 1 141 141. 1 142 UTF-8 . Properties: 142. 1 143 Classintro: : 143. 1 144 ( android.app.Activity ) ) ( . main.xml . 144. 1 145 : . main.xml colors.xml values ( values new>file>colors.xml . lower case ). : #FFFFFFFF 145. 1 146 . strings.xml . main.xml : ImageView . res/drawable-hdpires/drawable ) ). LinearLayoutRelativeLayout . 147. 1 148 RelativeLayout ) ( . . android:layout_below . Layout : intro . ) : ) package android.prog.easily; 148. 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; @Override public 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) 149. 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; 150. 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) { 151. 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 ) ). 152. 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>RatedItemArrayList getGlobalAdapterData()RatedItemArrayListRatedItemist 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")); 163. 1 164 String name = topCities[ff].getString("item_name"); int voteConutt = Integer.parseInt(topCities[ff].getString("total_number_of_vot es")); 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); } 164. 1 165 accessApplicationMethods().setGlobalAdapterData(sRest); goToBest50Act();// *** } catch (JSONException e) { } } // RestDroidApplication.java protected RestDroidApplication accessApplicationMethods() { return (RestDroidApplication)getApplication(); } . : // *** goToBest50Act : protected void goToBest50Act() { );class.Best50,thisIntent(newIntent goToBest = startActivity(goToBest); } 165. 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; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // main setContentView(R.layout.main); setUpViews(); } private void setUpViews() 166. 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,thisIntent(newIntent goToBest = startActivity(goToBest); } protected void top50Handler() { try { // API " " String attrcommand = "cities/" + "57" + "/items/top"; 167. 1 168 // accessApplicationMethods() RestDroidApplication.java String attributesCommand = accessApplicationMethods().getUrlStringCommand(attrcom mand); JSONObject[] topCities = accessApplicationMethods().retrieveJSONs(attributesComma nd); // 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 = 168. 1 169 Integer.parseInt(topCities[ff].getString("total_number_of_vot es")); 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 169. 1 170 accessApplicationMethods().setGlobalAdapterData(sRest); goToBest50Act(); } catch (JSONException e) { } } // RestDroidApplication.java protected RestDroidApplication accessApplicationMethods() { return (RestDroidApplication)getApplication(); } } RestDroidApplications . Intent ( action ( . 170. 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 : 171. 1 172 res>layout ( layout new>file). ))( ): 172. 1 173 RatedRestaurantListItem.java ) .( : 173. 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 @Override protected void onFinishInflate() { super.onFinishInflate(); ratedButton = (CheckedTextView)findViewById(R.id.ctext); 174. 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. . Activity intro.java.ListActivity List Adapter Design Patterns . )( ) Best50). Best50 Best50.java. ) ( 176. 1 177 ! inner class . : 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; @Override public void onCreate(Bundle savedInstanceState) { 177. 1 178 super.onCreate(savedInstanceState); setContentView(R.layout.rated_rest_list); setUpViews(); } // @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); RatedItem ite = accessApplicationMethods().getGlobalAdapterDataItem(posi tion); accessApplicationMethods().setItemOnMap(ite); goToViewOnMapActivity(); } private void goToViewOnMapActivity() { ,thisIntent(newIntent goToMapActivity = startActivity(goToMapActivity); } private void setUpViews() 178. 1 179 { selectAttr = (TextView)findViewById(R.id.RRselect); selectAttr.setText(" "); // adapter = new RatedRestaurantListAdapter setListAdapter(adapter); } // InnerClass Adapter . // ArrayAdapter class 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 179. 1 180 convertView, ViewGroupparent) { RatedRestaurantListItem row = (RatedRestaurantListItem)convertView; if (null == row) { // LayoutInflator // // LayoutInflater inflater=context.getLayoutInflater(); row = (RatedRestaurantListItem)inflater.inflate(R.layout.rest_list_it em, 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 180. 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 181. 1 182 . ( . ViewOnMapActivity.java . xml ( ( : view_map.xml : android:apikey . ) SDK- debugging .( ) cmdtrminal shell): $ keytool -list -alias androiddebugkey-keystore xxx-storepass android -keypass android xxx : Windows Vista: C:Users.androiddebug.keystore Windows XP: C:Documents and Settings.androiddebug.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 183. 1 184 . API xxxxxxxxxx. : -ons/google-com/android/addhttp://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_RADIUS private static final int CONTAINER_SHADOW_OFFSET= 1; 184. 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())); } // @Override public 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); 185. 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; } 186. 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; 187. 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; @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.view_map); setUpViews(); bringRestLocations(); 188. 1 189 mapCurrentAddress(); } // private void bringRestLocations() { try { // ID Best50.java RestDroidApplication int restNum = accessApplicationMethods().getItemOnMap().getId(); // API String command = "items/" + restNum + "/locations"; String restaurantsCommand = accessApplicationMethods().getUrlStringCommand(comman d); restaurantsLocObjects = accessApplicationMethods().retrieveJSONs(restaurantsCom mand); restaurantsBranchesNames = new String[restaurantsLocObjects.length]; longLat = new double[restaurantsLocObjects.length][2]; 189. 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("latit ude")); longLat[i][1] = Double.parseDouble(restaurantsLocObjects[i].getString("lon gitude")); } 190. 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); 191. 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()) ? 192. 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); } 193. 1 194 }); } private void setUpViews() { restName = (TextView)findViewById(R.id.restaurantNameMap); restName.setText(accessApplicationMethods().getItemOnMa p().getName()); mapView = (MapView)findViewById(R.id.map); // Zoomin/out mapView.setBuiltInZoomControls(true); } @Override protected boolean isLocationDisplayed() { return true; } @Override protected boolean isRouteDisplayed() { return false; } protected RestDroidApplication 194. 1 195 accessApplicationMethods() { return (RestDroidApplication)getApplication(); } } : 195. 1 196 !.. AndroidManifest.xml 196. 1 197 . . : 197. 1 198 198. 1 199 : 199. 1 200 200. 1 201 201. 1 202 202. 1 203 : - )( : $ cd /Developer/android-sdk-mac_86/tools/ $ ./adb devices : List of devices attached emulator-5554 device - ) ( : $ cd /Developer/android-sdk-mac_86/tools/ $ ./emulator -avd GPSenables -partition-size 500 -avd GPSenables . . - ) ( : 203. 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) . 204. 1 205 : : - - - - : Orientation Widgets . Vertical Horizontal . 205. 1 206 layout_width fill_parent. layout_height . . android:text . android:id . ..fill_parent 206. 1 207 (layout_widthlayout_height). wrap_content . . ) ): 207. 1 208 ( Layout .. XML ) : . LinearLayout Orientation. Widgets : ) ): 209. 1 210 android:layout_weight .: 211. 1 212 Widgets android:layout_agravity Widgets alignment . android:layout_marginLeft Pixels . android:layout_marginLeft android:orientation=horizontal : android:layout_gravity android:orientation=vertical: 213. 1 214 . android:gravity android:paddingLeft . Orientation . . x.setOrientation(LinearLayout.HORIZONTAL); 214. 1 215 x Widget . - . >TableRow< . : - android:layout_span : . Columns . - android:layout_column : Widget. . - android:stretchColumns : ) Widgets ) . - android:shrinkColumns : . : : 215. 1 216 : 218. 1 219 - . . ) Widgets ). 223. 1 224 225. 1 226 227. 1 228 229. 1 230