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

Commit 6cb54a7

Browse files
committed
[ADDED] [#50] Virtual guideline barrier example.
Fixes #50
1 parent 564d540 commit 6cb54a7

File tree

7 files changed

+170
-2
lines changed

7 files changed

+170
-2
lines changed

app/src/main/AndroidManifest.xml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
package="com.hossainkhan.android.demo">
45

56
<application
@@ -9,7 +10,8 @@
910
android:label="@string/app_name"
1011
android:roundIcon="@mipmap/ic_launcher_round"
1112
android:supportsRtl="true"
12-
android:theme="@style/AppTheme">
13+
android:theme="@style/AppTheme"
14+
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
1315
<activity android:name=".browse.LayoutBrowseActivity">
1416
<intent-filter>
1517
<action android:name="android.intent.action.MAIN" />
@@ -26,6 +28,9 @@
2628
<activity
2729
android:name=".layoutpreview.LayoutChainStyleActivity"
2830
android:parentActivityName=".browse.LayoutBrowseActivity" />
31+
<activity
32+
android:name=".layoutpreview.LayoutGuidelineBarrierActivity"
33+
android:parentActivityName=".browse.LayoutBrowseActivity" />
2934
</application>
3035

3136
</manifest>

app/src/main/java/com/hossainkhan/android/demo/browse/LayoutBrowseActivity.kt

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.recyclerview.widget.GridLayoutManager
2323
import androidx.recyclerview.widget.RecyclerView
2424
import com.hossainkhan.android.demo.R
2525
import com.hossainkhan.android.demo.layoutpreview.LayoutChainStyleActivity
26+
import com.hossainkhan.android.demo.layoutpreview.LayoutGuidelineBarrierActivity
2627
import com.hossainkhan.android.demo.layoutpreview.LayoutPreviewBaseActivity
2728
import com.hossainkhan.android.demo.layoutpreview.LayoutVisibilityGoneActivity
2829
import com.hossainkhan.android.demo.viewmodel.LayoutPreviewViewModelFactory
@@ -84,6 +85,9 @@ class LayoutBrowseActivity : AppCompatActivity() {
8485
R.layout.preview_chain_style_main -> {
8586
startActivity(LayoutChainStyleActivity.createStartIntent(this))
8687
}
88+
R.layout.preview_virtual_helper_barrier -> {
89+
startActivity(LayoutGuidelineBarrierActivity.createStartIntent(this))
90+
}
8791
else -> {
8892
startActivity(LayoutPreviewBaseActivity.createStartIntent(this, layoutResId))
8993
}

app/src/main/java/com/hossainkhan/android/demo/dagger/ActivityBindingModule.kt

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.hossainkhan.android.demo.dagger
1818

1919
import com.hossainkhan.android.demo.layoutpreview.LayoutChainStyleActivity
20+
import com.hossainkhan.android.demo.layoutpreview.LayoutGuidelineBarrierActivity
2021
import com.hossainkhan.android.demo.layoutpreview.LayoutPreviewBaseActivity
2122
import com.hossainkhan.android.demo.layoutpreview.LayoutVisibilityGoneActivity
2223
import dagger.Module
@@ -57,4 +58,8 @@ abstract class ActivityBindingModule {
5758
@ActivityScope
5859
@ContributesAndroidInjector
5960
abstract fun layoutChainActivity(): LayoutChainStyleActivity
61+
62+
@ActivityScope
63+
@ContributesAndroidInjector
64+
abstract fun layoutGuidelineBarrierActivity(): LayoutGuidelineBarrierActivity
6065
}

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ class LayoutDataStore @Inject constructor(
124124
title = "Virtual Helper: Guideline",
125125
description = "The Guideline object allows you to create Horizontal and Vertical guidelines which " +
126126
"are positioned relative to the ConstraintLayout container." +
127-
"Widgets can then be positioned by constraining them to such guidelines. ")
127+
"Widgets can then be positioned by constraining them to such guidelines. "),
128+
129+
LayoutInformation(
130+
layoutResourceId = R.layout.preview_virtual_helper_barrier,
131+
thumbnailResourceId = R.drawable.thumb_virtual_helper_guideline,
132+
title = "Virtual Helper: Barrier",
133+
description = "A Barrier references multiple widgets as input, and creates a virtual guideline " +
134+
"based on the most extreme widget on the specified side.")
128135

129136

130137
/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2019 Hossain Khan
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.hossainkhan.android.demo.layoutpreview
18+
19+
import android.content.Context
20+
import android.content.Intent
21+
import android.os.Bundle
22+
import android.widget.Button
23+
import android.widget.TextView
24+
import com.hossainkhan.android.demo.R
25+
26+
class LayoutGuidelineBarrierActivity : LayoutPreviewBaseActivity() {
27+
28+
companion object {
29+
/**
30+
* Creates an intent with required information to start this activity.
31+
*
32+
* @param context Activity context.
33+
*/
34+
fun createStartIntent(context: Context): Intent {
35+
val intent = Intent(context, LayoutGuidelineBarrierActivity::class.java)
36+
intent.putExtra(BUNDLE_KEY_LAYOUT_RESID, R.layout.preview_virtual_helper_barrier)
37+
return intent
38+
}
39+
}
40+
41+
override fun onCreate(savedInstanceState: Bundle?) {
42+
super.onCreate(savedInstanceState)
43+
44+
// Setup additional view that is only available in this screen.
45+
val toggleButton = findViewById<Button>(R.id.toggle_label_text_size)
46+
val textLabel = findViewById<TextView>(R.id.text_label)
47+
48+
toggleButton.setOnClickListener {
49+
if (textLabel.text == getString(R.string.barrier_label_text_small)) {
50+
textLabel.setText(R.string.barrier_label_text_long)
51+
} else {
52+
textLabel.setText(R.string.barrier_label_text_small)
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
4+
~ Copyright (c) 2019 Hossain Khan
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
20+
xmlns:app="http://schemas.android.com/apk/res-auto"
21+
xmlns:tools="http://schemas.android.com/tools"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
24+
android:layout_margin="16dp">
25+
26+
<androidx.constraintlayout.widget.Barrier
27+
android:id="@+id/barrier"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
app:barrierDirection="right"
31+
app:constraint_referenced_ids="action_button,text_label" />
32+
33+
<TextView
34+
android:id="@+id/text_label"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:text="@string/barrier_label_text_small"
38+
app:layout_constraintEnd_toEndOf="@id/barrier"
39+
app:layout_constraintStart_toStartOf="parent"
40+
app:layout_constraintTop_toTopOf="parent" />
41+
42+
<Button
43+
android:id="@+id/action_button"
44+
android:layout_width="wrap_content"
45+
android:layout_height="wrap_content"
46+
android:text="@string/barrier_label_button_small"
47+
app:layout_constraintStart_toStartOf="parent"
48+
app:layout_constraintTop_toBottomOf="@+id/text_label" />
49+
50+
<TextView
51+
android:id="@+id/text_content_constrained_on_barrier"
52+
android:layout_width="0dp"
53+
android:layout_height="wrap_content"
54+
android:layout_marginStart="16dp"
55+
android:ellipsize="end"
56+
android:text="@string/barrier_guide_text"
57+
app:layout_constraintEnd_toEndOf="parent"
58+
app:layout_constraintStart_toStartOf="@id/barrier"
59+
app:layout_constraintTop_toTopOf="parent" />
60+
61+
62+
<!-- _________________ IGNORE VIEWS BELOW THIS LINE _________________ -->
63+
64+
<!--
65+
A button to dynamically set label text to showcase the barrier in effect.
66+
-->
67+
<Button
68+
android:id="@+id/toggle_label_text_size"
69+
android:layout_width="wrap_content"
70+
android:layout_height="wrap_content"
71+
android:layout_marginStart="8dp"
72+
android:layout_marginEnd="8dp"
73+
android:layout_marginBottom="8dp"
74+
android:text="Toggle Text Size"
75+
app:layout_constraintBottom_toBottomOf="parent"
76+
app:layout_constraintEnd_toEndOf="parent"
77+
app:layout_constraintStart_toStartOf="parent"
78+
tools:ignore="HardcodedText" />
79+
80+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/strings.xml

+11
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@
1111
<string name="view_guide_chain_style_spread_inside">Chained views with \nlayout_constraintHorizontal_chainStyle=\'spread_inside\'</string>
1212
<string name="view_guide_chain_style_spread">Chained views with \nlayout_constraintHorizontal_chainStyle=\'spread\'</string>
1313
<string name="view_guide_chain_style_packed">Chained views with \nlayout_constraintHorizontal_chainStyle=\'packed\'</string>
14+
15+
<string name="lorem_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum facilisis nisl id nibh dictum vulputate nec ut lacus. Curabitur eget sodales nulla. Morbi suscipit aliquam orci vel convallis. Donec at nunc a purus interdum volutpat. Curabitur eu elementum libero, vel sodales nisi. Donec eget orci tristique, luctus odio eget, pellentesque risus. Morbi varius rhoncus nibh, ut lacinia enim porta non. Aliquam a enim quam. Fusce facilisis magna ut enim sagittis aliquam. Vivamus cursus lacus eu lorem dictum aliquam.</string>
16+
17+
<string name="barrier_guide_text">In this Barrier example, the barrier is set on the right side of "Small Label" and "ACTION LABEL". Notice initially how this description is pushed by the action button. Now, if you toggle the label text, you will see the barrier also grows with it and pushes this content event further.</string>
18+
19+
<string name="barrier_label_text_small">Small Label</string>
20+
<string name="barrier_label_text_long">Much Longer Translated Label</string>
21+
22+
<string name="barrier_label_button_small">Action Label</string>
23+
<string name="barrier_label_button_long">Action Longer Translated Label</string>
24+
1425
</resources>

0 commit comments

Comments
 (0)