Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit 981834a

Browse files
committed
1 parent ec4fef8 commit 981834a

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A demo application for Android `ConstraintLayout` with various usage with sample
3030
* [ ] `WRAP_CONTENT` : enforcing constraints _(Added in 1.1)_
3131
* [ ] Widgets dimension constraints
3232
- [ ] Chains
33-
* [ ] Chain Style
33+
* [x] Chain Style
3434
* [ ] Weighted chains
3535
* [ ] Margins and chains _(Added in 1.1)_
3636
- [ ] Virtual Helpers objects

app/src/main/java/com/hossainkhan/android/demo/data/LayoutDataStore.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class LayoutDataStore @Inject constructor(
7878
LayoutInformation(
7979
layoutResourceId = R.layout.preview_chain_style_main,
8080
thumbnailResourceId = R.drawable.thumb_chain_style,
81-
title = "Chain: Style",
81+
title = "Chain: Pack Style",
8282
description = "When setting the attribute `constraintHorizontal_chainStyle` or " +
8383
"`constraintVertical_chainStyle` on the first element of a chain, " +
8484
"the behavior of the chain will change according to the specified style (default is CHAIN_SPREAD)." +

app/src/main/java/com/hossainkhan/android/demo/layoutpreview/LayoutChainStyleActivity.kt

+18-22
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.hossainkhan.android.demo.layoutpreview
1919
import android.content.Context
2020
import android.content.Intent
2121
import android.os.Bundle
22+
import android.support.annotation.StringRes
2223
import android.support.constraint.ConstraintLayout
2324
import android.support.constraint.ConstraintSet
2425
import android.support.constraint.ConstraintSet.CHAIN_PACKED
@@ -52,7 +53,7 @@ class LayoutChainStyleActivity : LayoutPreviewBaseActivity() {
5253
}
5354

5455
private lateinit var constraintLayout: ConstraintLayout
55-
private lateinit var guideText: TextView
56+
private lateinit var guideTextView: TextView
5657
/**
5758
* Use constraint set to dynamically update constraints
5859
* https://developer.android.com/reference/android/support/constraint/ConstraintSet
@@ -63,41 +64,36 @@ class LayoutChainStyleActivity : LayoutPreviewBaseActivity() {
6364
super.onCreate(savedInstanceState)
6465

6566
constraintLayout = findViewById(R.id.constraint_layout_root)
66-
guideText = findViewById(R.id.view_chain_horizontal_guide_text)
67+
guideTextView = findViewById(R.id.view_chain_horizontal_guide_text)
6768
constraintSet.clone(constraintLayout)
6869
}
6970

7071
fun onRadioButtonClicked(view: View) {
71-
Timber.d("Constraint style change requested %s", view)
72-
// Is the button now checked?
7372
val checked = (view as RadioButton).isChecked
7473

7574
// Check which radio button was clicked
7675
when (view.getId()) {
7776
R.id.radio_chain_action_packed -> {
78-
if (checked) {
79-
guideText.setText(R.string.view_guide_chain_style_packed)
80-
TransitionManager.beginDelayedTransition(constraintLayout)
81-
constraintSet.setHorizontalChainStyle(R.id.view_chain_view_first, CHAIN_PACKED)
82-
constraintSet.applyTo(constraintLayout)
83-
}
77+
applyChainStyle(checked, R.string.view_guide_chain_style_packed, CHAIN_PACKED)
8478
}
8579
R.id.radio_chain_action_spread -> {
86-
if (checked) {
87-
guideText.setText(R.string.view_guide_chain_style_spread)
88-
TransitionManager.beginDelayedTransition(constraintLayout)
89-
constraintSet.setHorizontalChainStyle(R.id.view_chain_view_first, CHAIN_SPREAD)
90-
constraintSet.applyTo(constraintLayout)
91-
}
80+
applyChainStyle(checked, R.string.view_guide_chain_style_spread, CHAIN_SPREAD)
9281
}
9382
R.id.radio_chain_action_spread_inside -> {
94-
if (checked) {
95-
guideText.setText(R.string.view_guide_chain_style_spread_inside)
96-
TransitionManager.beginDelayedTransition(constraintLayout)
97-
constraintSet.setHorizontalChainStyle(R.id.view_chain_view_first, CHAIN_SPREAD_INSIDE)
98-
constraintSet.applyTo(constraintLayout)
99-
}
83+
applyChainStyle(checked, R.string.view_guide_chain_style_spread_inside, CHAIN_SPREAD_INSIDE)
10084
}
10185
}
10286
}
87+
88+
private fun applyChainStyle(isChecked: Boolean, @StringRes guideText: Int, chainStyle: Int) {
89+
if (isChecked) {
90+
Timber.d("Updating chain style to %s, and text to %s", chainStyle, getString(guideText))
91+
guideTextView.setText(guideText)
92+
TransitionManager.beginDelayedTransition(constraintLayout)
93+
constraintSet.setHorizontalChainStyle(R.id.view_chain_view_first, chainStyle)
94+
constraintSet.applyTo(constraintLayout)
95+
} else {
96+
Timber.i("View was not checked. Not taking action.")
97+
}
98+
}
10399
}

0 commit comments

Comments
 (0)