Skip to content

Commit 00ac0e7

Browse files
committed
Enforce default padding,
Remove Deck.setDefaultPadding method
1 parent bec392f commit 00ac0e7

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

app/src/main/java/com/example/bloder/deck/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ class MainActivity : AppCompatActivity() {
1616
setContentView(R.layout.activity_main)
1717
deckPager.offscreenPageLimit = 5
1818
deckPager.adapter = DeckAdapter(this)
19-
deckPager.setDefaultPadding(this)
2019
}
2120
}

lib/src/main/java/com/example/lib/Deck.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class Deck : ViewPager {
1717

1818
private val pageTransformer = CoverFlowTransformer()
1919

20-
constructor(context: Context) : super(context)
20+
constructor(context: Context) : super(context) {
21+
setPercentagePadding(context, DEFAULT_PERCENTAGE_PADDING)
22+
}
2123

2224
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) {
2325
val typedArray: TypedArray = context.obtainStyledAttributes(attributeSet, R.styleable.Deck)
@@ -30,6 +32,11 @@ class Deck : ViewPager {
3032
initProperties(context, dipPaddingXmlInPixel.toFloat())
3133
}
3234
typedArray.recycle()
35+
36+
// set the default padding if no properties from XML
37+
if (percentagePaddingXml == Integer.MAX_VALUE && dipPaddingXmlInPixel == Integer.MAX_VALUE) {
38+
setPercentagePadding(context, DEFAULT_PERCENTAGE_PADDING)
39+
}
3340
}
3441

3542
init {
@@ -40,13 +47,6 @@ class Deck : ViewPager {
4047
setPageTransformer(true, pageTransformer)
4148
}
4249

43-
/**
44-
* Set left and right padding with default value
45-
*/
46-
fun setDefaultPadding(context: Context) {
47-
setPercentagePadding(context, DEFAULT_PERCENTAGE_PADDING)
48-
}
49-
5050
/**
5151
* Set left and right padding based on percentage of the screen width
5252
* If the percentage is more than 18, the left and right items height might not be consistent

0 commit comments

Comments
 (0)