diff --git a/README.md b/README.md
new file mode 100644
index 0000000..22ea4e9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+# bottom-sheet-tutorial
+Android Material Design Bottom Sheets Tutorial :
+http://www.androidtutorialshub.com/android-material-design-bottom-sheets-tutorial/
+
+**`Customize DialogFragment To be Resizable , STATE_EXPANDED`**
diff --git a/app/build.gradle b/app/build.gradle
index d8192dd..5591ffe 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,15 @@
apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-android'
android {
- compileSdkVersion 23
- buildToolsVersion "23.0.2"
+ compileSdkVersion 28
+ buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.androidtutorialshub.bottomsheets"
minSdkVersion 15
- targetSdkVersion 23
+ targetSdkVersion 28
versionCode 1
versionName "1.0"
}
@@ -16,12 +18,16 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
+ debug{
+ }
}
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:23.2.1'
- compile 'com.android.support:design:23.2.1'
-}
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ testImplementation'junit:junit:4.12'
+ implementation 'androidx.appcompat:appcompat:1.0.2'
+ implementation 'com.google.android.material:material:1.0.0'
+ implementation "androidx.core:core-ktx:+"
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" //implementation
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/androidtutorialshub/bottomsheets/CustomBottomSheetDialogFragment.java b/app/src/main/java/com/androidtutorialshub/bottomsheets/CustomBottomSheetDialogFragment.java
deleted file mode 100644
index edb777b..0000000
--- a/app/src/main/java/com/androidtutorialshub/bottomsheets/CustomBottomSheetDialogFragment.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.androidtutorialshub.bottomsheets;
-
-import android.os.Bundle;
-import android.support.design.widget.BottomSheetDialogFragment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment {
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.content_dialog_bottom_sheet, container, false);
- return v;
- }
-
-
-}
diff --git a/app/src/main/java/com/androidtutorialshub/bottomsheets/CustomBottomSheetDialogFragment.kt b/app/src/main/java/com/androidtutorialshub/bottomsheets/CustomBottomSheetDialogFragment.kt
new file mode 100644
index 0000000..2c36648
--- /dev/null
+++ b/app/src/main/java/com/androidtutorialshub/bottomsheets/CustomBottomSheetDialogFragment.kt
@@ -0,0 +1,55 @@
+package com.androidtutorialshub.bottomsheets
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.view.WindowManager
+import android.widget.RelativeLayout
+import android.widget.Toast
+import androidx.fragment.app.DialogFragment
+import com.google.android.material.bottomsheet.BottomSheetBehavior
+import com.google.android.material.bottomsheet.BottomSheetDialogFragment
+import kotlinx.android.synthetic.main.content_dialog_bottom_sheet.*
+import android.widget.FrameLayout
+import com.google.android.material.bottomsheet.BottomSheetDialog
+import android.content.DialogInterface
+
+
+
+class CustomBottomSheetDialogFragment : BottomSheetDialogFragment(){
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ //Here is our bottomsheet dialog customization
+ initDialogListeners()
+
+ val view = inflater.inflate(R.layout.content_dialog_bottom_sheet, container, false)
+ return view
+ }
+
+ private fun initDialogListeners() {
+ dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
+ dialog.setOnShowListener { dialog ->
+ //BottomSheetDialog wrapInBottomSheet() method
+ val bottomSheet = (dialog as BottomSheetDialog).findViewById(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout?
+ BottomSheetBehavior.from(bottomSheet).state = BottomSheetBehavior.STATE_EXPANDED
+ }
+ }
+
+ override fun onStart() {
+ super.onStart()
+ initviews()
+
+ }
+ private fun initviews() {
+ bottomSheetSubmitButton.setOnClickListener {
+ val text = bottomSheetInput.text.toString()
+ Toast.makeText(context, "submit :: " + text, Toast.LENGTH_SHORT).show()
+ }
+
+
+ }
+
+
+
+}
diff --git a/app/src/main/java/com/androidtutorialshub/bottomsheets/MainActivity.java b/app/src/main/java/com/androidtutorialshub/bottomsheets/MainActivity.java
deleted file mode 100644
index 295e13f..0000000
--- a/app/src/main/java/com/androidtutorialshub/bottomsheets/MainActivity.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.androidtutorialshub.bottomsheets;
-
-import android.os.Bundle;
-import android.support.design.widget.BottomSheetBehavior;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.TextView;
-
-public class MainActivity extends AppCompatActivity implements View.OnClickListener {
-
- // BottomSheetBehavior variable
- private BottomSheetBehavior bottomSheetBehavior;
-
- // TextView variable
- private TextView bottomSheetHeading;
-
- // Button variables
- private Button expandBottomSheetButton;
- private Button collapseBottomSheetButton;
- private Button hideBottomSheetButton;
- private Button showBottomSheetDialogButton;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- initViews();
- initListeners();
-
-
- }
-
- /**
- * method to initialize the views
- */
- private void initViews() {
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
-
- bottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottomSheetLayout));
- bottomSheetHeading = (TextView) findViewById(R.id.bottomSheetHeading);
- expandBottomSheetButton = (Button) findViewById(R.id.expand_bottom_sheet_button);
- collapseBottomSheetButton = (Button) findViewById(R.id.collapse_bottom_sheet_button);
- hideBottomSheetButton = (Button) findViewById(R.id.hide_bottom_sheet_button);
- showBottomSheetDialogButton = (Button) findViewById(R.id.show_bottom_sheet_dialog_button);
-
-
- }
-
-
- /**
- * method to initialize the listeners
- */
- private void initListeners() {
- // register the listener for button click
- expandBottomSheetButton.setOnClickListener(this);
- collapseBottomSheetButton.setOnClickListener(this);
- hideBottomSheetButton.setOnClickListener(this);
- showBottomSheetDialogButton.setOnClickListener(this);
-
- // Capturing the callbacks for bottom sheet
- bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
- @Override
- public void onStateChanged(View bottomSheet, int newState) {
-
- if (newState == BottomSheetBehavior.STATE_EXPANDED) {
- bottomSheetHeading.setText(getString(R.string.text_collapse_me));
- } else {
- bottomSheetHeading.setText(getString(R.string.text_expand_me));
- }
-
- // Check Logs to see how bottom sheets behaves
- switch (newState) {
- case BottomSheetBehavior.STATE_COLLAPSED:
- Log.e("Bottom Sheet Behaviour", "STATE_COLLAPSED");
- break;
- case BottomSheetBehavior.STATE_DRAGGING:
- Log.e("Bottom Sheet Behaviour", "STATE_DRAGGING");
- break;
- case BottomSheetBehavior.STATE_EXPANDED:
- Log.e("Bottom Sheet Behaviour", "STATE_EXPANDED");
- break;
- case BottomSheetBehavior.STATE_HIDDEN:
- Log.e("Bottom Sheet Behaviour", "STATE_HIDDEN");
- break;
- case BottomSheetBehavior.STATE_SETTLING:
- Log.e("Bottom Sheet Behaviour", "STATE_SETTLING");
- break;
- }
- }
-
-
- @Override
- public void onSlide(View bottomSheet, float slideOffset) {
-
- }
- });
-
-
- }
-
- /**
- * onClick Listener to capture button click
- *
- * @param v
- */
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.collapse_bottom_sheet_button:
- // Collapsing the bottom sheet
- bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
- break;
- case R.id.expand_bottom_sheet_button:
- // Expanding the bottom sheet
- bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
- break;
- case R.id.hide_bottom_sheet_button:
- // Hiding the bottom sheet
- bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
- break;
- case R.id.show_bottom_sheet_dialog_button:
- // Opening the Dialog Bottom Sheet
- new CustomBottomSheetDialogFragment().show(getSupportFragmentManager(), "Dialog");
- break;
-
- }
- }
-}
diff --git a/app/src/main/java/com/androidtutorialshub/bottomsheets/MainActivity.kt b/app/src/main/java/com/androidtutorialshub/bottomsheets/MainActivity.kt
new file mode 100644
index 0000000..636526b
--- /dev/null
+++ b/app/src/main/java/com/androidtutorialshub/bottomsheets/MainActivity.kt
@@ -0,0 +1,19 @@
+package com.androidtutorialshub.bottomsheets
+
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import kotlinx.android.synthetic.main.content_main.*
+
+class MainActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_main)
+ initListeners()
+ }
+
+ private fun initListeners() {
+ show_bottom_sheet_dialog_button.setOnClickListener { it ->
+ CustomBottomSheetDialogFragment().show(supportFragmentManager, "Dialog")
+ }
+ }
+}
\ 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 323ef5f..a0ac5e1 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,31 +1,31 @@
-
-
-
-
+
+
-
-
-
+
-
+
diff --git a/app/src/main/res/layout/content_bottom_sheet.xml b/app/src/main/res/layout/content_bottom_sheet.xml
deleted file mode 100644
index 5c28a5d..0000000
--- a/app/src/main/res/layout/content_bottom_sheet.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/content_dialog_bottom_sheet.xml b/app/src/main/res/layout/content_dialog_bottom_sheet.xml
index 9d95666..88e3a47 100644
--- a/app/src/main/res/layout/content_dialog_bottom_sheet.xml
+++ b/app/src/main/res/layout/content_dialog_bottom_sheet.xml
@@ -1,28 +1,47 @@
-
-
+ android:layout_margin="@dimen/activity_horizontal_margin"
+ />
-
+
+
-
\ No newline at end of file
+ android:layout_gravity="center"
+ android:text="submit"
+ android:layout_margin="@dimen/activity_horizontal_margin" />
+
+
+
+
diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml
index 299c1ec..b119da4 100644
--- a/app/src/main/res/layout/content_main.xml
+++ b/app/src/main/res/layout/content_main.xml
@@ -1,5 +1,6 @@
-
-
-
-
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 545b9c6..083c770 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -14,7 +14,6 @@
-
diff --git a/build.gradle b/build.gradle
index e0b366a..0c442c2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,19 +1,21 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
buildscript {
+ ext.kotlin_version = '1.3.50'
repositories {
+ google()
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.5.0'
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
+ classpath 'com.android.tools.build:gradle:3.4.2'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
+
+
allprojects {
repositories {
+ google()
jcenter()
}
}
diff --git a/gradle.properties b/gradle.properties
index 1d3591c..915f0e6 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
\ No newline at end of file
+# org.gradle.parallel=true
+android.enableJetifier=true
+android.useAndroidX=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index f23df6e..3d4d94d 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Oct 21 11:34:03 PDT 2015
+#Thu Sep 05 10:45:36 EET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip