Skip to content

Commit f1fb0c8

Browse files
authored
Merge pull request #147 from skydoves/feature/window-to-public
Implement padding attributes
2 parents af997b0 + 64ad757 commit f1fb0c8

File tree

5 files changed

+78
-10
lines changed

5 files changed

+78
-10
lines changed

powerspinner/api/powerspinner.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public final class com/skydoves/powerspinner/PowerSpinnerView : androidx/appcomp
153153
public final fun getSpinnerPopupMaxHeight ()I
154154
public final fun getSpinnerPopupWidth ()I
155155
public final fun getSpinnerRecyclerView ()Landroidx/recyclerview/widget/RecyclerView;
156+
public final fun getSpinnerWindow ()Landroid/widget/PopupWindow;
156157
public final fun isShowing ()Z
157158
public final fun notifyItemSelected (ILjava/lang/CharSequence;)V
158159
public fun onDestroy (Landroidx/lifecycle/LifecycleOwner;)V
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Designed and developed by 2019 skydoves (Jaewoong Eum)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.skydoves.powerspinner
18+
19+
internal data class PowerSpinnerPaddings constructor(
20+
var top: Int = 0,
21+
var start: Int = 0,
22+
var end: Int = 0,
23+
var bottom: Int = 0
24+
)

powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerView.kt

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class PowerSpinnerView : AppCompatTextView, DefaultLifecycleObserver {
6363
PowerspinnerLayoutBodyBinding.inflate(LayoutInflater.from(context), null, false)
6464

6565
/** PopupWindow for creating the spinner. */
66-
private val spinnerWindow: PopupWindow
66+
public val spinnerWindow: PopupWindow
6767

6868
/** Spinner is showing or not. */
6969
public var isShowing: Boolean = false
@@ -76,6 +76,9 @@ public class PowerSpinnerView : AppCompatTextView, DefaultLifecycleObserver {
7676
/** An adapter for composing items of the spinner. */
7777
private var adapter: PowerSpinnerInterface<*> = DefaultSpinnerAdapter(this)
7878

79+
/** A padding values for the content of the spinner. */
80+
private val padding: PowerSpinnerPaddings = PowerSpinnerPaddings()
81+
7982
/** The arrow will be animated or not when show and dismiss the spinner. */
8083
public var arrowAnimate: Boolean = true
8184

@@ -342,6 +345,36 @@ public class PowerSpinnerView : AppCompatTextView, DefaultLifecycleObserver {
342345
}
343346
}
344347

348+
if (hasValue(R.styleable.PowerSpinnerView_spinner_popup_top_padding)) {
349+
padding.top =
350+
getDimensionPixelSize(R.styleable.PowerSpinnerView_spinner_popup_top_padding, 0)
351+
}
352+
353+
if (hasValue(R.styleable.PowerSpinnerView_spinner_popup_end_padding)) {
354+
padding.end =
355+
getDimensionPixelSize(R.styleable.PowerSpinnerView_spinner_popup_end_padding, 0)
356+
}
357+
358+
if (hasValue(R.styleable.PowerSpinnerView_spinner_popup_bottom_padding)) {
359+
padding.bottom =
360+
getDimensionPixelSize(R.styleable.PowerSpinnerView_spinner_popup_bottom_padding, 0)
361+
}
362+
363+
if (hasValue(R.styleable.PowerSpinnerView_spinner_popup_start_padding)) {
364+
padding.start =
365+
getDimensionPixelSize(R.styleable.PowerSpinnerView_spinner_popup_start_padding, 0)
366+
}
367+
368+
if (hasValue(R.styleable.PowerSpinnerView_spinner_popup_padding)) {
369+
val value = getDimensionPixelSize(R.styleable.PowerSpinnerView_spinner_popup_padding, 0)
370+
padding.apply {
371+
top = value
372+
end = value
373+
bottom = value
374+
start = value
375+
}
376+
}
377+
345378
if (hasValue(R.styleable.PowerSpinnerView_spinner_arrow_padding)) {
346379
_arrowPadding =
347380
getDimensionPixelSize(R.styleable.PowerSpinnerView_spinner_arrow_padding, _arrowPadding)
@@ -516,17 +549,12 @@ public class PowerSpinnerView : AppCompatTextView, DefaultLifecycleObserver {
516549
}
517550
}
518551
binding.body.apply {
519-
if (this@PowerSpinnerView.spinnerPopupBackground == null) {
520-
background = this@PowerSpinnerView.background
552+
background = if (this@PowerSpinnerView.spinnerPopupBackground == null) {
553+
this@PowerSpinnerView.background
521554
} else {
522-
background = this@PowerSpinnerView.spinnerPopupBackground
555+
this@PowerSpinnerView.spinnerPopupBackground
523556
}
524-
setPadding(
525-
this.paddingLeft,
526-
this.paddingTop,
527-
this.paddingRight,
528-
this.paddingBottom
529-
)
557+
setPaddingRelative(padding.start, padding.top, padding.end, padding.bottom)
530558
if (this@PowerSpinnerView.showDivider) {
531559
val decoration = DividerItemDecoration(context, DividerItemDecoration.VERTICAL)
532560
val shape = GradientDrawable().apply {

powerspinner/src/main/res/values/attrs_powerspinner.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@
5858
<attr name="spinner_popup_height" format="dimension" />
5959
<!-- Sets the max height of the popup. -->
6060
<attr name="spinner_popup_max_height" format="dimension" />
61+
<!-- Sets the top padding of the popup. -->
62+
<attr name="spinner_popup_top_padding" format="dimension" />
63+
<!-- Sets the end padding of the popup. -->
64+
<attr name="spinner_popup_end_padding" format="dimension" />
65+
<!-- Sets the bottom padding of the popup. -->
66+
<attr name="spinner_popup_bottom_padding" format="dimension" />
67+
<!-- Sets the left padding of the popup. -->
68+
<attr name="spinner_popup_start_padding" format="dimension" />
69+
<!-- Sets the paddings of the popup. -->
70+
<attr name="spinner_popup_padding" format="dimension" />
6171
<!-- Sets a fixed item height of the popup. -->
6272
<attr name="spinner_item_height" format="dimension" />
6373
<!-- Sets the elevation size of the popup. -->

powerspinner/src/main/res/values/public.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<public name="spinner_popup_animation_style" type="attr" tools:ignore="ResourceName" />
3232
<public name="spinner_popup_width" type="attr" tools:ignore="ResourceName" />
3333
<public name="spinner_popup_height" type="attr" tools:ignore="ResourceName" />
34+
<public name="spinner_popup_top_padding" type="attr" tools:ignore="ResourceName" />
35+
<public name="spinner_popup_end_padding" type="attr" tools:ignore="ResourceName" />
36+
<public name="spinner_popup_bottom_padding" type="attr" tools:ignore="ResourceName" />
37+
<public name="spinner_popup_left_padding" type="attr" tools:ignore="ResourceName" />
38+
<public name="spinner_popup_padding" type="attr" tools:ignore="ResourceName" />
3439
<public name="spinner_popup_max_height" type="attr" tools:ignore="ResourceName" />
3540
<public name="spinner_item_height" type="attr" tools:ignore="ResourceName" />
3641
<public name="spinner_popup_elevation" type="attr" tools:ignore="ResourceName" />

0 commit comments

Comments
 (0)