From 315d4dbfe7bdc4982491d63969fdb5cc76637f65 Mon Sep 17 00:00:00 2001 From: Omer Iyioz Date: Sun, 24 May 2020 09:42:42 +0300 Subject: [PATCH 1/9] migrated to androidX, kotlin. refactored. --- .idea/codeStyles/Project.xml | 134 ++++++++++++++---- .idea/compiler.xml | 8 ++ .idea/gradle.xml | 3 + .idea/jarRepositories.xml | 45 ++++++ .idea/misc.xml | 2 +- app/build.gradle | 25 ++-- .../bottomsheet/ExampleInstrumentedTest.java | 4 +- .../bottomsheet/BottomSheetFragment.java | 27 ---- .../bottomsheet/BottomSheetFragment.kt | 17 +++ .../droidbyme/bottomsheet/MenuActivity.java | 59 -------- .../com/droidbyme/bottomsheet/MenuActivity.kt | 49 +++++++ .../bottomsheet/PersistentActivity.java | 80 ----------- .../bottomsheet/PersistentActivity.kt | 63 ++++++++ app/src/main/res/layout/activity_main.xml | 10 +- app/src/main/res/layout/activity_menu.xml | 6 +- app/src/main/res/layout/bottom_sheet.xml | 4 +- build.gradle | 8 +- gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 2 +- 19 files changed, 331 insertions(+), 217 deletions(-) create mode 100644 .idea/compiler.xml create mode 100644 .idea/jarRepositories.xml delete mode 100644 app/src/main/java/com/droidbyme/bottomsheet/BottomSheetFragment.java create mode 100644 app/src/main/java/com/droidbyme/bottomsheet/BottomSheetFragment.kt delete mode 100644 app/src/main/java/com/droidbyme/bottomsheet/MenuActivity.java create mode 100644 app/src/main/java/com/droidbyme/bottomsheet/MenuActivity.kt delete mode 100644 app/src/main/java/com/droidbyme/bottomsheet/PersistentActivity.java create mode 100644 app/src/main/java/com/droidbyme/bottomsheet/PersistentActivity.kt diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 30aa626..ae78c11 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,29 +1,113 @@ - - - - - - - - - - + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
\ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..9147562 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 7ac24c7..9bba60d 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,8 +1,10 @@ + diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..8bd3a09 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 37a7509..7bfef59 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 9908c7a..2c6a30f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,14 +1,16 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { applicationId "com.droidbyme.bottomsheet" minSdkVersion 19 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { release { @@ -20,10 +22,15 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support:design:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.13' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation "androidx.core:core-ktx:1.2.0" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + jcenter() } diff --git a/app/src/androidTest/java/com/droidbyme/bottomsheet/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/droidbyme/bottomsheet/ExampleInstrumentedTest.java index bd51726..7d7f23f 100644 --- a/app/src/androidTest/java/com/droidbyme/bottomsheet/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/droidbyme/bottomsheet/ExampleInstrumentedTest.java @@ -1,8 +1,8 @@ package com.droidbyme.bottomsheet; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/app/src/main/java/com/droidbyme/bottomsheet/BottomSheetFragment.java b/app/src/main/java/com/droidbyme/bottomsheet/BottomSheetFragment.java deleted file mode 100644 index a5dabdf..0000000 --- a/app/src/main/java/com/droidbyme/bottomsheet/BottomSheetFragment.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.droidbyme.bottomsheet; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.design.widget.BottomSheetDialogFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -public class BottomSheetFragment extends BottomSheetDialogFragment { - - public BottomSheetFragment() { - - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.bottom_sheet, container, false); - } -} diff --git a/app/src/main/java/com/droidbyme/bottomsheet/BottomSheetFragment.kt b/app/src/main/java/com/droidbyme/bottomsheet/BottomSheetFragment.kt new file mode 100644 index 0000000..353e0a0 --- /dev/null +++ b/app/src/main/java/com/droidbyme/bottomsheet/BottomSheetFragment.kt @@ -0,0 +1,17 @@ +package com.droidbyme.bottomsheet + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.google.android.material.bottomsheet.BottomSheetDialogFragment + +class BottomSheetFragment : BottomSheetDialogFragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.bottom_sheet, container, false) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/droidbyme/bottomsheet/MenuActivity.java b/app/src/main/java/com/droidbyme/bottomsheet/MenuActivity.java deleted file mode 100644 index 9e9a177..0000000 --- a/app/src/main/java/com/droidbyme/bottomsheet/MenuActivity.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.droidbyme.bottomsheet; - -import android.content.Intent; -import android.os.Bundle; -import android.support.design.widget.BottomSheetDialog; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.View; -import android.widget.Button; - -public class MenuActivity extends AppCompatActivity implements View.OnClickListener { - - private android.widget.Button btnPersistent; - private android.widget.Button btnModal; - private android.support.v7.widget.Toolbar toolbar; - private Button btnModalFragment; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - init(); - } - - private void init() { - setContentView(R.layout.activity_menu); - this.btnModalFragment = (Button) findViewById(R.id.btnModalFragment); - this.toolbar = (Toolbar) findViewById(R.id.toolbar); - toolbar.setTitle("Bottom Sheet"); - this.btnModal = (Button) findViewById(R.id.btnModal); - this.btnPersistent = (Button) findViewById(R.id.btnPersistent); - - btnPersistent.setOnClickListener(this); - btnModal.setOnClickListener(this); - btnModalFragment.setOnClickListener(this); - } - - @Override - public void onClick(View view) { - Intent intent; - switch (view.getId()) { - case R.id.btnPersistent: - intent = new Intent(this, PersistentActivity.class); - startActivity(intent); - break; - - case R.id.btnModal: - View dialogView = getLayoutInflater().inflate(R.layout.bottom_sheet, null); - BottomSheetDialog dialog = new BottomSheetDialog(this); - dialog.setContentView(dialogView); - dialog.show(); - break; - - case R.id.btnModalFragment: - BottomSheetFragment bottomSheetFragment = new BottomSheetFragment(); - bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag()); - break; - } - } -} diff --git a/app/src/main/java/com/droidbyme/bottomsheet/MenuActivity.kt b/app/src/main/java/com/droidbyme/bottomsheet/MenuActivity.kt new file mode 100644 index 0000000..9b33ce3 --- /dev/null +++ b/app/src/main/java/com/droidbyme/bottomsheet/MenuActivity.kt @@ -0,0 +1,49 @@ +package com.droidbyme.bottomsheet + +import android.content.Intent +import android.os.Bundle +import android.view.View +import android.widget.Button +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.Toolbar +import com.google.android.material.bottomsheet.BottomSheetDialog +import kotlinx.android.synthetic.main.activity_menu.* + +class MenuActivity : AppCompatActivity(), View.OnClickListener { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + init() + } + + private fun init() { + setContentView(R.layout.activity_menu) + + toolbar.title = "Bottom Sheet" + + btnPersistent.setOnClickListener(this) + btnModal.setOnClickListener(this) + btnModalFragment.setOnClickListener(this) + } + + override fun onClick(view: View) { + val intent: Intent + when (view.id) { + R.id.btnPersistent -> { + intent = Intent(this, PersistentActivity::class.java) + startActivity(intent) + } + R.id.btnModal -> { + val dialogView = layoutInflater.inflate(R.layout.bottom_sheet, null) + val dialog = BottomSheetDialog(this) + dialog.setContentView(dialogView) + dialog.show() + } + R.id.btnModalFragment -> { + val bottomSheetFragment = BottomSheetFragment() + bottomSheetFragment.show(supportFragmentManager, bottomSheetFragment.tag) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/droidbyme/bottomsheet/PersistentActivity.java b/app/src/main/java/com/droidbyme/bottomsheet/PersistentActivity.java deleted file mode 100644 index fbcf35a..0000000 --- a/app/src/main/java/com/droidbyme/bottomsheet/PersistentActivity.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.droidbyme.bottomsheet; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.design.widget.BottomSheetBehavior; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.View; -import android.widget.Button; -import android.widget.LinearLayout; - -public class PersistentActivity extends AppCompatActivity { - - private BottomSheetBehavior sheetBehavior; - private Toolbar toolbar; - private Button btn_bottom_sheet; - private LinearLayout bottom_sheet; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - btn_bottom_sheet = findViewById(R.id.btn_bottom_sheet); - bottom_sheet = findViewById(R.id.bottom_sheet); - this.toolbar = (Toolbar) findViewById(R.id.toolbar); - toolbar.setTitle("Persistent Bottom Sheet"); - - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - toolbar.setNavigationOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - finish(); - } - }); - - sheetBehavior = BottomSheetBehavior.from(bottom_sheet); - - btn_bottom_sheet.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (sheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) { - sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); - btn_bottom_sheet.setText("Close sheet"); - } else { - sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); - btn_bottom_sheet.setText("Expand sheet"); - } - } - }); - - sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { - @Override - public void onStateChanged(@NonNull View view, int newState) { - switch (newState) { - case BottomSheetBehavior.STATE_HIDDEN: - break; - case BottomSheetBehavior.STATE_EXPANDED: { - btn_bottom_sheet.setText("Close Sheet"); - } - break; - case BottomSheetBehavior.STATE_COLLAPSED: { - btn_bottom_sheet.setText("Expand Sheet"); - } - break; - case BottomSheetBehavior.STATE_DRAGGING: - break; - case BottomSheetBehavior.STATE_SETTLING: - break; - } - } - - @Override - public void onSlide(@NonNull View view, float v) { - - } - }); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/droidbyme/bottomsheet/PersistentActivity.kt b/app/src/main/java/com/droidbyme/bottomsheet/PersistentActivity.kt new file mode 100644 index 0000000..5935e0a --- /dev/null +++ b/app/src/main/java/com/droidbyme/bottomsheet/PersistentActivity.kt @@ -0,0 +1,63 @@ +package com.droidbyme.bottomsheet + +import android.os.Bundle +import android.view.View +import android.widget.Button +import android.widget.LinearLayout +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.Toolbar +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback +import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.bottom_sheet.* +import kotlinx.android.synthetic.main.content_main.* + +class PersistentActivity : AppCompatActivity() { + private lateinit var sheetBehavior: BottomSheetBehavior<*> + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + toolbar.title = "Persistent Bottom Sheet" + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + toolbar.setNavigationOnClickListener { finish() } + + sheetBehavior = BottomSheetBehavior.from(bottom_sheet) + btn_bottom_sheet.setOnClickListener(View.OnClickListener { + if (sheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) { + sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED) + btn_bottom_sheet.setText("Close sheet") + } else { + sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED) + btn_bottom_sheet.setText("Expand sheet") + } + }) + sheetBehavior.addBottomSheetCallback(object : BottomSheetCallback() { + override fun onStateChanged(view: View, newState: Int) { + when (newState) { + BottomSheetBehavior.STATE_HIDDEN -> { + } + BottomSheetBehavior.STATE_EXPANDED -> { + btn_bottom_sheet.setText("Close Sheet") + } + BottomSheetBehavior.STATE_COLLAPSED -> { + btn_bottom_sheet.setText("Expand Sheet") + } + BottomSheetBehavior.STATE_DRAGGING -> { + + } + BottomSheetBehavior.STATE_SETTLING -> { + + } + BottomSheetBehavior.STATE_HALF_EXPANDED -> { + + } + } + } + + override fun onSlide(view: View, v: Float) {} + }) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d96e187..3fd962e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,28 +1,28 @@ - - - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_menu.xml b/app/src/main/res/layout/activity_menu.xml index b720cb1..9c366b6 100644 --- a/app/src/main/res/layout/activity_menu.xml +++ b/app/src/main/res/layout/activity_menu.xml @@ -8,19 +8,19 @@ android:orientation="vertical" tools:context=".MenuActivity"> - - - +