From aad6211cf27853bb137a9245b26ef35e304fa8ff Mon Sep 17 00:00:00 2001 From: Hamed Date: Mon, 5 Aug 2019 11:53:47 +0430 Subject: [PATCH] set gravity for layout --- .idea/encodings.xml | 4 ++ .idea/gradle.xml | 15 +++++++ .idea/misc.xml | 9 +++++ .idea/runConfigurations.xml | 12 ++++++ .idea/vcs.xml | 6 +++ app/build.gradle | 2 +- .../floatinglayout/MainActivity.java | 14 ++++++- app/src/main/res/layout/activity_main.xml | 4 +- .../floatinglayout/FLGravity.java | 40 +++++++++++++++++++ .../floatinglayout/FloatingLayout.java | 10 +++-- .../FloatingLayoutPresenter.java | 7 +++- .../floatinglayout/FloatingLayoutService.java | 19 +++++---- 12 files changed, 125 insertions(+), 17 deletions(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 floatinglayout/src/main/java/com/hamedtaherpour/floatinglayout/FLGravity.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..2996d53 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.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/app/build.gradle b/app/build.gradle index 9eae60e..fcf0bc9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "com.hamedtaherpour.floatinglayout" minSdkVersion 19 - targetSdkVersion 28 + targetSdkVersion 21 versionCode 1 versionName "1.0" } diff --git a/app/src/main/java/com/hamedtaherpour/floatinglayout/MainActivity.java b/app/src/main/java/com/hamedtaherpour/floatinglayout/MainActivity.java index e444770..6c0c9db 100644 --- a/app/src/main/java/com/hamedtaherpour/floatinglayout/MainActivity.java +++ b/app/src/main/java/com/hamedtaherpour/floatinglayout/MainActivity.java @@ -1,7 +1,12 @@ package com.hamedtaherpour.floatinglayout; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import android.provider.Settings; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.Gravity; import android.view.View; import android.widget.Button; import android.widget.Toast; @@ -16,8 +21,15 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - floatingLayout = new FloatingLayout(this, R.layout.floating_layout, this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!Settings.canDrawOverlays(this)) { + // ask for setting + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); + startActivityForResult(intent, 25); + } + } + floatingLayout = new FloatingLayout(this, R.layout.floating_layout, new FLGravity(Gravity.LEFT | Gravity.CENTER, 50, 0), this); button = findViewById(R.id.btn_run); button.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5a4061c..12a7907 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -8,13 +8,13 @@