Skip to content

Commit 8bb6dde

Browse files
committed
16th and 17th class added
1 parent 4e22eeb commit 8bb6dde

File tree

75 files changed

+3041
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3041
-1
lines changed

16-SixteenthClass/.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/gradle.xml
8+
/.idea/vcs.xml
9+
/.idea/misc.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild

16-SixteenthClass/.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

16-SixteenthClass/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Android Ninja - Class No: 16
2+
Date: 27 October, 2017
3+
4+
## Topics ##
5+
- Show Google Map using `SupportMapFragment`
6+
- Show user's current location on Map

16-SixteenthClass/app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

16-SixteenthClass/app/build.gradle

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
defaultConfig {
6+
applicationId "com.hellohasan.sixteenthclass"
7+
minSdkVersion 15
8+
targetSdkVersion 26
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
implementation fileTree(dir: 'libs', include: ['*.jar'])
23+
implementation 'com.android.support:appcompat-v7:26.1.0'
24+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25+
implementation 'com.google.android.gms:play-services-maps:11.4.2'
26+
testImplementation 'junit:junit:4.12'
27+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
28+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
29+
30+
//pretty logger library
31+
compile 'com.orhanobut:logger:2.1.1'
32+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.hellohasan.sixteenthclass;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.hellohasan.sixteenthclass", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<resources>
2+
<!--
3+
TODO: Before you run your application, you need a Google Maps API key.
4+
5+
To get one, follow this link, follow the directions and press "Create" at the end:
6+
7+
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=01:66:A8:C2:C5:B2:F4:A2:03:03:1D:09:1B:64:F2:07:E5:7A:80:32%3Bcom.hellohasan.sixteenthclass
8+
9+
You can also add your credentials to an existing key, using these values:
10+
11+
Package name:
12+
01:66:A8:C2:C5:B2:F4:A2:03:03:1D:09:1B:64:F2:07:E5:7A:80:32
13+
14+
SHA-1 certificate fingerprint:
15+
01:66:A8:C2:C5:B2:F4:A2:03:03:1D:09:1B:64:F2:07:E5:7A:80:32
16+
17+
Alternatively, follow the directions here:
18+
https://developers.google.com/maps/documentation/android/start#get-key
19+
20+
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
21+
string in this file.
22+
-->
23+
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyCdauENofUa2zU1XujpR-QA59Bxf-WApUY</string>
24+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.hellohasan.sixteenthclass">
4+
5+
<!--
6+
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
7+
Google Maps Android API v2, but you must specify either coarse or fine
8+
location permissions for the 'MyLocation' functionality.
9+
-->
10+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
11+
12+
<application
13+
android:allowBackup="true"
14+
android:icon="@mipmap/ic_launcher"
15+
android:label="@string/app_name"
16+
android:roundIcon="@mipmap/ic_launcher_round"
17+
android:supportsRtl="true"
18+
android:theme="@style/AppTheme">
19+
20+
<!--
21+
The API key for Google Maps-based APIs is defined as a string resource.
22+
(See the file "res/values/google_maps_api.xml").
23+
Note that the API key is linked to the encryption key used to sign the APK.
24+
You need a different API key for each encryption key, including the release key that is used to
25+
sign the APK for publishing.
26+
You can define the keys for the debug and release targets in src/debug/ and src/release/.
27+
-->
28+
<meta-data
29+
android:name="com.google.android.geo.API_KEY"
30+
android:value="@string/google_maps_key" />
31+
32+
<activity
33+
android:name=".MapsActivity"
34+
android:label="@string/title_activity_maps">
35+
<intent-filter>
36+
<action android:name="android.intent.action.MAIN" />
37+
38+
<category android:name="android.intent.category.LAUNCHER" />
39+
</intent-filter>
40+
</activity>
41+
</application>
42+
43+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package com.hellohasan.sixteenthclass;
2+
3+
import android.content.pm.PackageManager;
4+
import android.os.Bundle;
5+
import android.support.annotation.NonNull;
6+
import android.support.v4.app.ActivityCompat;
7+
import android.support.v4.app.FragmentActivity;
8+
import android.support.v4.content.ContextCompat;
9+
10+
import com.google.android.gms.maps.CameraUpdateFactory;
11+
import com.google.android.gms.maps.GoogleMap;
12+
import com.google.android.gms.maps.OnMapReadyCallback;
13+
import com.google.android.gms.maps.SupportMapFragment;
14+
import com.google.android.gms.maps.model.LatLng;
15+
import com.google.android.gms.maps.model.MarkerOptions;
16+
import com.orhanobut.logger.AndroidLogAdapter;
17+
import com.orhanobut.logger.Logger;
18+
19+
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
20+
21+
private GoogleMap mMap;
22+
private boolean mLocationPermissionGranted = false;
23+
private final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1001;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_maps);
29+
Logger.addLogAdapter(new AndroidLogAdapter());
30+
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
31+
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
32+
.findFragmentById(R.id.map);
33+
mapFragment.getMapAsync(this);
34+
35+
getLocationPermission();
36+
37+
}
38+
39+
40+
/**
41+
* Manipulates the map once available.
42+
* This callback is triggered when the map is ready to be used.
43+
* This is where we can add markers or lines, add listeners or move the camera. In this case,
44+
* we just add a marker near Sydney, Australia.
45+
* If Google Play services is not installed on the device, the user will be prompted to install
46+
* it inside the SupportMapFragment. This method will only be triggered once the user has
47+
* installed Google Play services and returned to the app.
48+
*/
49+
@Override
50+
public void onMapReady(GoogleMap googleMap) {
51+
mMap = googleMap;
52+
53+
// Add a marker in Sydney and move the camera
54+
LatLng ahmadNagar = new LatLng(23.794469, 90.358917);
55+
mMap.addMarker(new MarkerOptions().position(ahmadNagar).title("Marker in Ahmad Nagar"));
56+
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ahmadNagar, 15));
57+
58+
updateLocationUI();
59+
}
60+
61+
@Override
62+
public void onRequestPermissionsResult(int requestCode,
63+
@NonNull String permissions[],
64+
@NonNull int[] grantResults) {
65+
mLocationPermissionGranted = false;
66+
switch (requestCode) {
67+
case PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: {
68+
// If request is cancelled, the result arrays are empty.
69+
if (grantResults.length > 0
70+
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
71+
mLocationPermissionGranted = true;
72+
}
73+
}
74+
}
75+
updateLocationUI();
76+
77+
}
78+
79+
private void updateLocationUI() {
80+
if (mMap == null) {
81+
Logger.d("Map is null");
82+
return;
83+
}
84+
try {
85+
if (mLocationPermissionGranted) {
86+
mMap.setMyLocationEnabled(true);
87+
mMap.getUiSettings().setMyLocationButtonEnabled(true);
88+
} else {
89+
mMap.setMyLocationEnabled(false);
90+
mMap.getUiSettings().setMyLocationButtonEnabled(false);
91+
// mLastKnownLocation = null;
92+
getLocationPermission();
93+
}
94+
} catch (SecurityException e) {
95+
Logger.d(e.getMessage());
96+
}
97+
}
98+
99+
private void getLocationPermission() {
100+
/*
101+
* Request location permission, so that we can get the location of the
102+
* device. The result of the permission request is handled by a callback,
103+
* onRequestPermissionsResult.
104+
*/
105+
if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
106+
android.Manifest.permission.ACCESS_FINE_LOCATION)
107+
== PackageManager.PERMISSION_GRANTED) {
108+
mLocationPermissionGranted = true;
109+
} else {
110+
ActivityCompat.requestPermissions(this,
111+
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
112+
PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
113+
}
114+
}
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportHeight="108"
6+
android:viewportWidth="108">
7+
<path
8+
android:fillType="evenOdd"
9+
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
10+
android:strokeColor="#00000000"
11+
android:strokeWidth="1">
12+
<aapt:attr name="android:fillColor">
13+
<gradient
14+
android:endX="78.5885"
15+
android:endY="90.9159"
16+
android:startX="48.7653"
17+
android:startY="61.0927"
18+
android:type="linear">
19+
<item
20+
android:color="#44000000"
21+
android:offset="0.0" />
22+
<item
23+
android:color="#00000000"
24+
android:offset="1.0" />
25+
</gradient>
26+
</aapt:attr>
27+
</path>
28+
<path
29+
android:fillColor="#FFFFFF"
30+
android:fillType="nonZero"
31+
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
32+
android:strokeColor="#00000000"
33+
android:strokeWidth="1" />
34+
</vector>

0 commit comments

Comments
 (0)