diff --git a/.gitignore b/.gitignore index ccf2efe..9c4de58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,7 @@ -# Built application files -*.apk -*.ap_ - -# Files for the Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ - -# Gradle files -.gradle/ -build/ -/*/build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..73b7192 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +RuntimePermissionsWorkshop \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..5f8ec24 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c7894c3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/RuntimePermissionWorkshop.iml b/RuntimePermissionWorkshop.iml new file mode 100644 index 0000000..8efe09e --- /dev/null +++ b/RuntimePermissionWorkshop.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..9f93e04 --- /dev/null +++ b/app/app.iml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..689cc94 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" + + defaultConfig { + applicationId "pl.tajchert.runpermissionswork" + minSdkVersion 15 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.jakewharton:butterknife:7.0.1' + compile 'com.android.support:design:22.2.1' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..83a1757 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Tajchert-Laptop\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/pl/tajchert/runpermissionswork/ApplicationTest.java b/app/src/androidTest/java/pl/tajchert/runpermissionswork/ApplicationTest.java new file mode 100644 index 0000000..35b18d2 --- /dev/null +++ b/app/src/androidTest/java/pl/tajchert/runpermissionswork/ApplicationTest.java @@ -0,0 +1,13 @@ +package pl.tajchert.runpermissionswork; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d76a2b2 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/pl/tajchert/runpermissionswork/MainActivity.java b/app/src/main/java/pl/tajchert/runpermissionswork/MainActivity.java new file mode 100644 index 0000000..d690b64 --- /dev/null +++ b/app/src/main/java/pl/tajchert/runpermissionswork/MainActivity.java @@ -0,0 +1,25 @@ +package pl.tajchert.runpermissionswork; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.Toast; + +import butterknife.ButterKnife; +import butterknife.OnClick; + +public class MainActivity extends AppCompatActivity { + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + ButterKnife.bind(this); + } + + @OnClick(R.id.buttonLocation) + public void clickButtLocation() { + boolean hasAccess = Tools.accessLocation(this); + Toast.makeText(this, "Location access = " + hasAccess, Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/pl/tajchert/runpermissionswork/Tools.java b/app/src/main/java/pl/tajchert/runpermissionswork/Tools.java new file mode 100644 index 0000000..774f10b --- /dev/null +++ b/app/src/main/java/pl/tajchert/runpermissionswork/Tools.java @@ -0,0 +1,28 @@ +package pl.tajchert.runpermissionswork; + +import android.content.Context; +import android.location.Criteria; +import android.location.Location; +import android.location.LocationManager; + +/** + * Created by Tajchert on 23.08.2015. + */ +public class Tools { + public static boolean accessLocation(Context context) { + LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + Criteria criteria = new Criteria(); + criteria.setPowerRequirement(Criteria.POWER_LOW); + String bestProvider = locationManager.getBestProvider(criteria, false); + if (bestProvider == null) { + //No android.permission-group.LOCATION + return false; + } + Location location = locationManager.getLastKnownLocation(bestProvider); + if(location == null) { + //it is either off or we lack of permission + return false; + } + return true; + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..aa33a9e --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,20 @@ + + +