diff --git a/README.md b/README.md index f2b0ab2..c280cd5 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ For information : checkout [Sample App Code](https://github.com/vipulasri/Ticket ``` gradle dependencies { - compile 'com.vipulasri:ticketview:1.0.5' + compile 'com.vipulasri:ticketview:1.0.7' } ``` diff --git a/sample/build.gradle b/sample/build.gradle index a5b3481..01510be 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -10,7 +10,7 @@ android { applicationId "com.vipulasri.ticketview.sample" minSdkVersion versions.minSdk targetSdkVersion versions.targetSdk - versionCode 3 + versionCode 4 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/sample/src/main/java/com/vipulasri/ticketview/sample/MainActivity.kt b/sample/src/main/java/com/vipulasri/ticketview/sample/MainActivity.kt index d300aa4..7cf1a7e 100644 --- a/sample/src/main/java/com/vipulasri/ticketview/sample/MainActivity.kt +++ b/sample/src/main/java/com/vipulasri/ticketview/sample/MainActivity.kt @@ -29,6 +29,8 @@ import kotlinx.android.synthetic.main.item_corner_options.* class MainActivity : BaseActivity() { + private lateinit var mBottomSheetBehavior: BottomSheetBehavior + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -54,17 +56,17 @@ class MainActivity : BaseActivity() { private fun initOptionsBottomSheet() { - val behavior = BottomSheetBehavior.from(bottomSheet) + mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) - view_options_header.setOnClickListener({ - if (behavior!!.state == BottomSheetBehavior.STATE_COLLAPSED) { - behavior.state = BottomSheetBehavior.STATE_EXPANDED + view_options_header.setOnClickListener { + if (mBottomSheetBehavior.state == BottomSheetBehavior.STATE_COLLAPSED) { + mBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED } else { - behavior.state = BottomSheetBehavior.STATE_COLLAPSED + mBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED } - }) + } - behavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + mBottomSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { override fun onStateChanged(@NonNull bottomSheet: View, newState: Int) { when(newState) { BottomSheetBehavior.STATE_COLLAPSED -> image_toggle.setImageResource(R.drawable.ic_expand_less_black_24dp) @@ -89,7 +91,7 @@ class MainActivity : BaseActivity() { TicketView.Orientation.VERTICAL -> radioButton_vertical.isChecked = true } - radioGroup_orientation.setOnCheckedChangeListener(RadioGroup.OnCheckedChangeListener { group, checkedId -> + radioGroup_orientation.setOnCheckedChangeListener { group, checkedId -> when(checkedId) { R.id.radioButton_horizontal -> ticketView.orientation = TicketView.Orientation.HORIZONTAL R.id.radioButton_vertical -> ticketView.orientation = TicketView.Orientation.VERTICAL @@ -97,13 +99,13 @@ class MainActivity : BaseActivity() { ticketView.orientation = TicketView.Orientation.HORIZONTAL } } - }) + } //background properties - image_background_color.setOnClickListener({ + image_background_color.setOnClickListener { showColorPicker(ticketView.backgroundColor, image_background_color) - }) + } seekBar_elevation.setOnProgressChangeListener(progressChangeListener) @@ -128,28 +130,28 @@ class MainActivity : BaseActivity() { ticketView.isShowBorder = false checkbox_show_border.isChecked = false - checkbox_show_border.setOnCheckedChangeListener({ compoundButton, checked -> + checkbox_show_border.setOnCheckedChangeListener { compoundButton, checked -> ticketView.isShowBorder = checked - }) + } seekBar_border_width.progress = Utils.pxToDp(ticketView.borderWidth.toFloat(), this) seekBar_border_width.setOnProgressChangeListener(progressChangeListener) - image_border_color.setOnClickListener({ + image_border_color.setOnClickListener { showColorPicker(ticketView.borderColor, image_border_color) - }) + } //divider properties ticketView.isShowDivider = true checkbox_show_divider.isChecked = true - checkbox_show_divider.setOnCheckedChangeListener({ compoundButton, checked -> + checkbox_show_divider.setOnCheckedChangeListener { compoundButton, checked -> ticketView.isShowDivider = checked - }) + } - image_divider_color.setOnClickListener({ + image_divider_color.setOnClickListener { showColorPicker(ticketView.dividerColor, image_divider_color) - }) + } spinner_divider_type.setSelection(1) spinner_divider_type.onItemSelectedListener = object : OnItemSelectedListener { @@ -213,7 +215,7 @@ class MainActivity : BaseActivity() { .setSelectedColor(selectedColor) .setDismissOnColorSelected(true) .setOutlineWidth(1) - .setOnColorSelectedListener({ positiveResult, color -> + .setOnColorSelectedListener { positiveResult, color -> if (positiveResult) { colorView.background.setColorFilter(color, PorterDuff.Mode.SRC_ATOP) @@ -227,7 +229,7 @@ class MainActivity : BaseActivity() { } } - }).build().show(supportFragmentManager, "ColorPicker") + }.build().show(supportFragmentManager, "ColorPicker") } private var progressChangeListener: DiscreteSeekBar.OnProgressChangeListener = object : DiscreteSeekBar.OnProgressChangeListener { @@ -256,4 +258,12 @@ class MainActivity : BaseActivity() { } } + + override fun onBackPressed() { + if(mBottomSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) { + mBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + } else { + super.onBackPressed() + } + } }