diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 8d88099..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 28 - - dataBinding { - enabled = true - } - defaultConfig { - applicationId "se.eelde.granter.app" - minSdkVersion 17 - targetSdkVersion 28 - versionCode 2 - versionName "1.0.1" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support:support-v4:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation project(path: ':granter') -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..217013d --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,39 @@ +plugins { + id("com.android.application") + kotlin("android") + kotlin("android.extensions") +} + +android { + compileSdkVersion(28) + + defaultConfig { + applicationId = "se.eelde.granter.app" + minSdkVersion(17) + targetSdkVersion(28) + versionCode = 2 + versionName = "1.0.1" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + getByName("release") { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation("androidx.appcompat:appcompat:1.0.2") + implementation("androidx.legacy:legacy-support-v4:1.0.0") + implementation("androidx.constraintlayout:constraintlayout:1.1.3") + implementation(project(path = ":granter")) + implementation(embeddedKotlin("stdlib-jdk7")) +} + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2604fe5..9afff45 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -9,12 +10,13 @@ + android:theme="@style/AppTheme" + tools:ignore="GoogleAppIndexingWarning"> @@ -24,8 +26,6 @@ - - \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..5302f47 Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/se/eelde/granter/app/DummyFragment.java b/app/src/main/java/se/eelde/granter/app/DummyFragment.java deleted file mode 100644 index 95b2557..0000000 --- a/app/src/main/java/se/eelde/granter/app/DummyFragment.java +++ /dev/null @@ -1,26 +0,0 @@ -package se.eelde.granter.app; - -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import se.eelde.granter.app.databinding.FragmentDummyBinding; - -public class DummyFragment extends Fragment { - public DummyFragment() { - } - - public static Fragment newInstance() { - return new DummyFragment(); - } - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { - FragmentDummyBinding binding = FragmentDummyBinding.inflate(inflater, container, false); - return binding.getRoot(); - } -} diff --git a/app/src/main/java/se/eelde/granter/app/DummyFragment.kt b/app/src/main/java/se/eelde/granter/app/DummyFragment.kt new file mode 100644 index 0000000..98e4234 --- /dev/null +++ b/app/src/main/java/se/eelde/granter/app/DummyFragment.kt @@ -0,0 +1,19 @@ +package se.eelde.granter.app + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment + +class DummyFragment : Fragment() { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_dummy, container, false) + } + + companion object { + internal fun newInstance(): Fragment { + return DummyFragment() + } + } +} diff --git a/app/src/main/java/se/eelde/granter/app/PermissionRequestingActivity.java b/app/src/main/java/se/eelde/granter/app/PermissionRequestingActivity.java deleted file mode 100644 index 408997c..0000000 --- a/app/src/main/java/se/eelde/granter/app/PermissionRequestingActivity.java +++ /dev/null @@ -1,91 +0,0 @@ -package se.eelde.granter.app; - -import android.Manifest; -import android.databinding.DataBindingUtil; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.util.Log; -import android.widget.Toast; - -import java.util.List; - -import pub.devrel.easypermissions.AfterPermissionGranted; -import pub.devrel.easypermissions.EasyPermissions; -import se.eelde.granter.Granter; -import se.eelde.granter.app.databinding.ActivityPermissionRequestingBinding; - -public class PermissionRequestingActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks { - - public static final int RC_CAMERA = 121; - public static final int RC_2 = 122; - public static final int RC_multiple = 123; - private static final String TAG = "PermissionActivity"; - private ActivityPermissionRequestingBinding binding; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - binding = DataBindingUtil.setContentView(this, R.layout.activity_permission_requesting); - - binding.regularPermission.setOnClickListener(view -> RegularPermissionActivity.start(this)); - - binding.permission1Button.setOnClickListener(view -> new Granter.Builder(this) - .requestCode(RC_CAMERA) - .addPermission(Manifest.permission.CAMERA) - .build() - .show()); - - binding.permission2Button.setOnClickListener(view -> new Granter.Builder(this) - .requestCode(RC_2) - .addPermission(Manifest.permission.SEND_SMS) - .build() - .show()); - - binding.permissionMultipleButton.setOnClickListener(view -> new Granter.Builder(this) - .requestCode(RC_multiple) - .addPermission(Manifest.permission.RECORD_AUDIO, Manifest.permission.ACCESS_FINE_LOCATION) - .rationale("This app neeeds access to audio and location!") - .build() - .show()); - - if (savedInstanceState == null) { - getSupportFragmentManager() - .beginTransaction() - .replace(binding.fragmentContainer.getId(), PermissionRequestingFragment.newInstance()) - .commit(); - } - } - - @AfterPermissionGranted(RC_CAMERA) - public void rc1() { - Toast.makeText(this, "TODO: rc1 things", Toast.LENGTH_SHORT).show(); - - getSupportFragmentManager() - .beginTransaction() - .replace(binding.fragmentContainer.getId(), DummyFragment.newInstance()) - .commit(); - } - - @AfterPermissionGranted(RC_2) - public void rc2() { - Toast.makeText(this, "TODO: rc2 things", Toast.LENGTH_SHORT).show(); - } - - @AfterPermissionGranted(RC_multiple) - public void rc_multiple() { - Toast.makeText(this, "TODO: rc_multiple things", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onPermissionsGranted(int requestCode, @NonNull List perms) { - Log.d(TAG, "onPermissionsGranted:" + requestCode + ":" + perms.size()); - } - - @Override - public void onPermissionsDenied(int requestCode, @NonNull List perms) { - Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + perms.size()); - } - -} diff --git a/app/src/main/java/se/eelde/granter/app/PermissionRequestingActivity.kt b/app/src/main/java/se/eelde/granter/app/PermissionRequestingActivity.kt new file mode 100644 index 0000000..6960629 --- /dev/null +++ b/app/src/main/java/se/eelde/granter/app/PermissionRequestingActivity.kt @@ -0,0 +1,91 @@ +package se.eelde.granter.app + +import android.Manifest +import android.os.Bundle +import android.util.Log +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import kotlinx.android.synthetic.main.activity_permission_requesting.* +import pub.devrel.easypermissions.AfterPermissionGranted +import pub.devrel.easypermissions.EasyPermissions +import se.eelde.granter.Granter + +class PermissionRequestingActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.activity_permission_requesting) + + regular_permission.setOnClickListener { RegularPermissionActivity.start(this) } + + permission_1_button.setOnClickListener { + Granter.Builder(this) + .requestCode(RC_CAMERA) + .addPermission(Manifest.permission.CAMERA) + .build() + .show() + } + + permission_2_button.setOnClickListener { + Granter.Builder(this) + .requestCode(RC_2) + .addPermission(Manifest.permission.SEND_SMS) + .build() + .show() + } + + permission_multiple_button.setOnClickListener { + Granter.Builder(this) + .requestCode(RC_multiple) + .addPermission(Manifest.permission.RECORD_AUDIO, Manifest.permission.ACCESS_FINE_LOCATION) + .rationale("This app neeeds access to audio and location!") + .build() + .show() + } + + if (savedInstanceState == null) { + supportFragmentManager + .beginTransaction() + .replace(fragment_container.id, PermissionRequestingFragment.newInstance()) + .commit() + } + } + + @AfterPermissionGranted(RC_CAMERA) + fun rc1() { + Toast.makeText(this, "TODO: rc1 things", Toast.LENGTH_SHORT).show() + + supportFragmentManager + .beginTransaction() + .replace(fragment_container.id, DummyFragment.newInstance()) + .commit() + } + + @AfterPermissionGranted(RC_2) + fun rc2() { + Toast.makeText(this, "TODO: rc2 things", Toast.LENGTH_SHORT).show() + } + + @AfterPermissionGranted(RC_multiple) + fun rc_multiple() { + Toast.makeText(this, "TODO: rc_multiple things", Toast.LENGTH_SHORT).show() + } + + override fun onPermissionsGranted(requestCode: Int, perms: List) { + Log.d(TAG, "onPermissionsGranted:" + requestCode + ":" + perms.size) + } + + override fun onPermissionsDenied(requestCode: Int, perms: List) { + Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + perms.size) + } + + companion object { + private const val TAG = "PermissionActivity" + private const val RC_CAMERA = 121 + private const val RC_2 = 122 + private const val RC_multiple = 123 + + } +} + diff --git a/app/src/main/java/se/eelde/granter/app/PermissionRequestingFragment.java b/app/src/main/java/se/eelde/granter/app/PermissionRequestingFragment.java deleted file mode 100644 index 9f2bcd1..0000000 --- a/app/src/main/java/se/eelde/granter/app/PermissionRequestingFragment.java +++ /dev/null @@ -1,44 +0,0 @@ -package se.eelde.granter.app; - -import android.Manifest; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; - -import pub.devrel.easypermissions.AfterPermissionGranted; -import se.eelde.granter.Granter; -import se.eelde.granter.app.databinding.FragmentPermissionRequestingBinding; - -/** - * Created in {@link R.layout#activity_permission_requesting} - */ -public class PermissionRequestingFragment extends Fragment { - - private static final int RC_READ_CONTACTS_PERM = 122; - - public static Fragment newInstance() { - return new PermissionRequestingFragment(); - } - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - FragmentPermissionRequestingBinding binding = FragmentPermissionRequestingBinding.inflate(inflater, container, false); - - binding.fragmentPermission1Button.setOnClickListener(view -> new Granter.Builder(this) - .requestCode(RC_READ_CONTACTS_PERM) - .addPermission(Manifest.permission.READ_CONTACTS) - .build() - .show()); - - return binding.getRoot(); - } - - @AfterPermissionGranted(RC_READ_CONTACTS_PERM) - private void contactsTask() { - Toast.makeText(getActivity(), "TODO: Read contacts things", Toast.LENGTH_LONG).show(); - } -} diff --git a/app/src/main/java/se/eelde/granter/app/PermissionRequestingFragment.kt b/app/src/main/java/se/eelde/granter/app/PermissionRequestingFragment.kt new file mode 100644 index 0000000..1dd88de --- /dev/null +++ b/app/src/main/java/se/eelde/granter/app/PermissionRequestingFragment.kt @@ -0,0 +1,47 @@ +package se.eelde.granter.app + +import android.Manifest +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.fragment.app.Fragment +import kotlinx.android.synthetic.main.fragment_permission_requesting.view.* +import pub.devrel.easypermissions.AfterPermissionGranted +import se.eelde.granter.Granter + +/** + * Created in [R.layout.activity_permission_requesting] + */ +class PermissionRequestingFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_permission_requesting, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + view.fragment_permission_1_button.setOnClickListener { + Granter.Builder(this) + .requestCode(RC_READ_CONTACTS_PERM) + .addPermission(Manifest.permission.READ_CONTACTS) + .build() + .show() + } + + } + + @AfterPermissionGranted(RC_READ_CONTACTS_PERM) + private fun contactsTask() { + Toast.makeText(activity, "TODO: Read contacts things", Toast.LENGTH_LONG).show() + } + + companion object { + + private const val RC_READ_CONTACTS_PERM = 122 + + internal fun newInstance(): Fragment { + return PermissionRequestingFragment() + } + } +} diff --git a/app/src/main/java/se/eelde/granter/app/RegularPermissionActivity.java b/app/src/main/java/se/eelde/granter/app/RegularPermissionActivity.java deleted file mode 100644 index a6e1370..0000000 --- a/app/src/main/java/se/eelde/granter/app/RegularPermissionActivity.java +++ /dev/null @@ -1,90 +0,0 @@ -package se.eelde.granter.app; - -import android.Manifest; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.databinding.DataBindingUtil; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; - -import se.eelde.granter.app.databinding.ActivityRegularPermissionBinding; - -public class RegularPermissionActivity extends AppCompatActivity { - - private static final int REQUEST_PERMISSION_LOCATION_RATIONALE = 213; - private static final int REQUEST_PERMISSION_LOCATION = 212; - private ActivityRegularPermissionBinding binding; - - public static void start(Context context) { - context.startActivity(new Intent(context, RegularPermissionActivity.class)); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_regular_permission); - binding = DataBindingUtil.setContentView(this, R.layout.activity_regular_permission); - - binding.regularPermissionButton.setOnClickListener(view -> checkPermissions()); - } - - private void moveToNextStep() { - getSupportFragmentManager() - .beginTransaction() - .replace(binding.fragmentContainer.getId(), DummyFragment.newInstance()) - .commit(); - } - - private void checkPermissions() { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - // Should we show an explanation? - if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { - new AlertDialog.Builder(this) - .setTitle("title") - .setMessage("message") - .setPositiveButton("ok", (dialog, which) -> ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION_LOCATION_RATIONALE)) - .setNegativeButton("nah", null) - .create() - .show(); - - } else { - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION_LOCATION); - } - } else { - moveToNextStep(); - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - switch (requestCode) { - case REQUEST_PERMISSION_LOCATION: { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - moveToNextStep(); - } else if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { - new AlertDialog.Builder(this) - .setTitle("title") - .setMessage("settings") - .setPositiveButton("ok", null) - .setNegativeButton("nah", null) - .create() - .show(); - - } - } - case REQUEST_PERMISSION_LOCATION_RATIONALE: { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - moveToNextStep(); - } - } - default: { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - } - } - } -} diff --git a/app/src/main/java/se/eelde/granter/app/RegularPermissionActivity.kt b/app/src/main/java/se/eelde/granter/app/RegularPermissionActivity.kt new file mode 100644 index 0000000..995172c --- /dev/null +++ b/app/src/main/java/se/eelde/granter/app/RegularPermissionActivity.kt @@ -0,0 +1,96 @@ +package se.eelde.granter.app + +import android.Manifest +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.os.Bundle +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat +import kotlinx.android.synthetic.main.activity_regular_permission.* + +class RegularPermissionActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_regular_permission) + + regular_permission_button.setOnClickListener { checkPermissions() } + } + + private fun moveToNextStep() { + supportFragmentManager + .beginTransaction() + .replace(fragment_container.id, DummyFragment.newInstance()) + .commit() + } + + private fun checkPermissions() { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + // Should we show an explanation? + if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { + AlertDialog.Builder(this) + .setTitle("title") + .setMessage("message") + .setPositiveButton("ok") { _, _ -> ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), REQUEST_PERMISSION_LOCATION_RATIONALE) } + .setNegativeButton("nah", null) + .create() + .show() + + } else { + ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), REQUEST_PERMISSION_LOCATION) + } + } else { + moveToNextStep() + } + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + when (requestCode) { + REQUEST_PERMISSION_LOCATION -> { + run { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + moveToNextStep() + } else if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { + AlertDialog.Builder(this) + .setTitle("title") + .setMessage("settings") + .setPositiveButton("ok", null) + .setNegativeButton("nah", null) + .create() + .show() + + } + } + run { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + moveToNextStep() + } + } + run { super.onRequestPermissionsResult(requestCode, permissions, grantResults) } + } + REQUEST_PERMISSION_LOCATION_RATIONALE -> { + run { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + moveToNextStep() + } + } + run { super.onRequestPermissionsResult(requestCode, permissions, grantResults) } + } + else -> { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + } + } + } + + companion object { + private const val REQUEST_PERMISSION_LOCATION_RATIONALE = 213 + private const val REQUEST_PERMISSION_LOCATION = 212 + + fun start(context: Context) { + context.startActivity(Intent(context, RegularPermissionActivity::class.java)) + } + } +} diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..a1e7fcb --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/app/src/main/res/layout/activity_permiso_permission.xml b/app/src/main/res/layout/activity_permiso_permission.xml index e1911e8..9e85ad0 100644 --- a/app/src/main/res/layout/activity_permiso_permission.xml +++ b/app/src/main/res/layout/activity_permiso_permission.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> - - + diff --git a/app/src/main/res/layout/activity_permission_requesting.xml b/app/src/main/res/layout/activity_permission_requesting.xml index bdb32e1..d74ce9a 100644 --- a/app/src/main/res/layout/activity_permission_requesting.xml +++ b/app/src/main/res/layout/activity_permission_requesting.xml @@ -1,70 +1,67 @@ - + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context="se.eelde.granter.app.PermissionRequestingActivity"> - +