This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onMapReady(GoogleMap googleMap) { | |
mMap = googleMap; | |
// Add a marker in Sydney and move the camera | |
LatLng sydney = new LatLng(-34, 151); | |
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); | |
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); | |
// Start By Creating a new location to center our map On: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this coarse location is for location base on wifi and phone signal | |
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> | |
// This fine location is the wxact location with GPS | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
LocationManager locationManager; | |
LocationListener locationListener; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { | |
private GoogleMap mMap; | |
LocationManager locationManager; | |
LocationListener locationListener; | |
LatLng newLocation; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reverse GeoCoding | |
// Getting The address from a Location coordinates. | |
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault()); | |
// Locale: format for the address. getDefault() use the Locale of the user. | |
try { | |
List<Address> listAddresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); | |
// We have to say how many result we want, so that integer is for that. | |
// we do a check to see if we got something back or not. | |
if (listAddresses != null && listAddresses.size() > 0) { | |
String countryName = listAddresses.get(0).getCountryName(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//Converting result To Json and extracting Parts of it. | |
JSONObject myJSON = new JSONObject(weatherInfo); | |
// Checking if the City is found: | |
int resultCod = Integer.parseInt(myJSON.getString("cod")); | |
if (resultCod == 200) { | |
Log.i("Lord", "resultCod Is 200 - Continuing . . ."); | |
//Getting The Information We Need. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To Close The Keyboard as soon as button is clicked. | |
InputMethodManager mgr= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); | |
mgr.hideSoftInputFromWindow(edtCity.getWindowToken(),0); | |
// edtCity is the EditText that has the focus and keyboard is writing in it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To Encode the text of Edit Text So that cities with space are converted to url type and no error happens: | |
String encodedCityName= URLEncoder.encode(edtCity.getText().toString(),"UTF-8"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { | |
@Override | |
protected Bitmap doInBackground(String... strings) { | |
URL url; | |
HttpURLConnection httpURLConnection; | |
try { | |
url = new URL(strings[0]); | |
httpURLConnection = (HttpURLConnection) url.openConnection(); | |
InputStream in = httpURLConnection.getInputStream(); | |
Bitmap bitmap = BitmapFactory.decodeStream(in); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StringManipulation { | |
//Split: | |
// this is a method for spiliting a strings | |
String myString = "Mohammad x Faeze x Tommy x Mobina"; | |
// if i wanted to convert above string into an array which contained each of the name: | |
String[] splitString = myString.split(" x "); | |
// this takes myString and split it by x into an array; | |
//---------------------------------------- |
OlderNewer