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

Commit 05b5eae

Browse files
committed
[ADDED] [#28] Layout visibility screen and icons.
Refactoring required.
1 parent 2c94cf2 commit 05b5eae

File tree

10 files changed

+292
-10
lines changed

10 files changed

+292
-10
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<category android:name="android.intent.category.LAUNCHER" />
1818
</intent-filter>
1919
</activity>
20-
<activity android:name=".layoutpositioning.LayoutPositioningDemoActivity"></activity>
20+
<activity android:name=".layoutpositioning.LayoutPositioningDemoActivity" />
21+
<activity android:name=".layoutpositioning.LayoutVisibilityGoneActivity"></activity>
2122
</application>
2223

2324
</manifest>

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import android.view.View
2525
import com.hossainkhan.android.demo.R
2626
import com.hossainkhan.android.demo.data.AppDataStore
2727
import com.hossainkhan.android.demo.layoutpositioning.LayoutPositioningDemoActivity
28+
import com.hossainkhan.android.demo.layoutpositioning.LayoutVisibilityGoneActivity
2829
import dagger.android.AndroidInjection
2930
import timber.log.Timber
3031
import javax.inject.Inject
@@ -66,7 +67,16 @@ class MainActivity : AppCompatActivity() {
6667
fun onLayoutItemSelected(layoutResId: Int) {
6768
Timber.i("Selected layout id: %s", layoutResId)
6869

69-
startActivity(LayoutPositioningDemoActivity
70-
.createStartIntent(this, layoutResId))
70+
when (layoutResId) {
71+
R.layout.preview_visibility_gone -> {
72+
startActivity(LayoutVisibilityGoneActivity
73+
.createStartIntent(this))
74+
}
75+
else -> {
76+
startActivity(LayoutPositioningDemoActivity
77+
.createStartIntent(this, layoutResId))
78+
}
79+
}
80+
7181
}
7282
}

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

Lines changed: 5 additions & 0 deletions
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.layoutpositioning.LayoutPositioningDemoActivity
20+
import com.hossainkhan.android.demo.layoutpositioning.LayoutVisibilityGoneActivity
2021
import dagger.Module
2122
import dagger.android.ContributesAndroidInjector
2223

@@ -47,4 +48,8 @@ abstract class ActivityBindingModule {
4748
@ActivityScope
4849
@ContributesAndroidInjector
4950
abstract fun layoutPositioningActivity(): LayoutPositioningDemoActivity
51+
52+
@ActivityScope
53+
@ContributesAndroidInjector
54+
abstract fun layoutVisibilityActivity(): LayoutVisibilityGoneActivity
5055
}

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ import javax.inject.Singleton
2626
@Singleton
2727
class LayoutDataStore @Inject constructor(
2828
private val resources: Resources) {
29+
/**
30+
* Various layouts features and it's information mostly taken from official documentation.
31+
*
32+
* See:
33+
* - https://github.com/amardeshbd/android-constraint-layout-cheatsheet/blob/master/app/src/main/res/layout/.README.md
34+
* - https://developer.android.com/reference/android/support/constraint/ConstraintLayout#VisibilityBehavior
35+
*/
2936
val supportedLayoutInfos = listOf(
3037
LayoutInformation(
3138
layoutResourceId = R.layout.preview_positioning_top_left,
@@ -45,7 +52,16 @@ class LayoutDataStore @Inject constructor(
4552
"\n\n" +
4653
"layout_constraintCircle : references another widget id\n" +
4754
"layout_constraintCircleRadius : the distance to the other widget center\n" +
48-
"layout_constraintCircleAngle : which angle the widget should be at (in degrees, from 0 to 360)\n")
55+
"layout_constraintCircleAngle : which angle the widget should be at (in degrees, from 0 to 360)\n"),
56+
LayoutInformation(
57+
layoutResourceId = R.layout.preview_visibility_gone,
58+
thumbnailResourceId = R.drawable.thumb_visibility_behaviour,
59+
title = "Visibility: GONE behaviour",
60+
description = "A view marked as GONE are not going to be displayed and are not part of the layout itself.\n" +
61+
"But in terms of the layout computations, GONE widgets are still part of it, with an important distinction:" +
62+
"\n\n" +
63+
" * For the layout pass, their dimension will be considered as zero (basically, they will be resolved to a point)\n" +
64+
" * If they have constraints to other widgets they will still be respected, but any margins will be as if equals to zero")
4965
)
5066

5167
/**
@@ -66,12 +82,12 @@ class LayoutDataStore @Inject constructor(
6682
// com.hossainkhan.android.demo:layout/preview_positioning_top_left
6783
val resourceName = resources.getResourceName(layoutResourceId)
6884

69-
if(!resourceName.contains("layout")) {
85+
if (!resourceName.contains("layout")) {
7086
throw IllegalStateException("Only layout resource is allowed.")
7187
}
7288

7389
return AppConfig.GITHUB_BASE_URL.plus("/blob/master/app/src/main/res/") +
7490
resourceName.split(':')
75-
.last().plus(".xml")
91+
.last().plus(".xml")
7692
}
7793
}

app/src/main/java/com/hossainkhan/android/demo/layoutpositioning/LayoutPositioningDemoActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import javax.inject.Inject
3838
* Those constraints allow you to position a given widget relative to another one.
3939
* You can constrain a widget on the horizontal and vertical axis.
4040
*/
41-
class LayoutPositioningDemoActivity : AppCompatActivity() {
41+
open class LayoutPositioningDemoActivity : AppCompatActivity() {
4242

4343
companion object {
4444
private const val BUNDLE_KEY_LAYOUT_RESID = "KEY_LAYOUT_RESOURCE_ID"
@@ -57,10 +57,10 @@ class LayoutPositioningDemoActivity : AppCompatActivity() {
5757
}
5858

5959
@Inject
60-
lateinit var appDataStore: AppDataStore
60+
internal lateinit var appDataStore: AppDataStore
6161

62-
lateinit var layoutInformation: LayoutInformation
63-
var flashbar: Flashbar? = null
62+
internal lateinit var layoutInformation: LayoutInformation
63+
internal var flashbar: Flashbar? = null
6464

6565
override fun onCreate(savedInstanceState: Bundle?) {
6666
AndroidInjection.inject(this)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2018 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.layoutpositioning
18+
19+
import android.content.Context
20+
import android.content.Intent
21+
import android.os.Bundle
22+
import android.view.View
23+
import android.widget.Button
24+
import com.hossainkhan.android.demo.R
25+
26+
class LayoutVisibilityGoneActivity : LayoutPositioningDemoActivity() {
27+
28+
companion object {
29+
private const val BUNDLE_KEY_LAYOUT_RESID = "KEY_LAYOUT_RESOURCE_ID"
30+
31+
/**
32+
* Creates an intent with required information to start this activity.
33+
*
34+
* @param context Activity context.
35+
* @param layoutResourceId The layout resource ID to load into the view.
36+
*/
37+
fun createStartIntent(context: Context): Intent {
38+
val intent = Intent(context, LayoutVisibilityGoneActivity::class.java)
39+
intent.putExtra(BUNDLE_KEY_LAYOUT_RESID, R.layout.preview_visibility_gone)
40+
return intent
41+
}
42+
}
43+
44+
override fun onCreate(savedInstanceState: Bundle?) {
45+
super.onCreate(savedInstanceState)
46+
47+
val toggleButton = findViewById<Button>(R.id.toggle_view_visibility_button)
48+
val firstView = findViewById<View>(R.id.visibility_behaviour_box_start)
49+
50+
toggleButton.setOnClickListener {
51+
when (firstView.visibility) {
52+
View.VISIBLE -> firstView.visibility = View.GONE
53+
else -> firstView.visibility = View.VISIBLE
54+
}
55+
}
56+
}
57+
58+
59+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<!--
2+
~ Copyright (c) 2018 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+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="24dp"
19+
android:height="24dp"
20+
android:viewportWidth="640"
21+
android:viewportHeight="640">
22+
<path
23+
android:fillAlpha="0"
24+
android:fillColor="#FF000000"
25+
android:pathData="M2.19,637.84L637.81,637.84L637.81,2.16L2.19,2.16L2.19,637.84Z"
26+
android:strokeWidth="2"
27+
android:strokeAlpha="1"
28+
android:strokeColor="#000000" />
29+
<path
30+
android:fillAlpha="1"
31+
android:fillColor="#00acc1"
32+
android:pathData="M593.85,97.35C596.4,97.35 598.46,99.42 598.46,101.97C598.46,119.95 598.46,169.28 598.46,187.27C598.46,189.81 596.4,191.88 593.85,191.88C566.21,191.88 487.91,191.88 460.27,191.88C457.72,191.88 455.65,189.81 455.65,187.27C455.65,169.28 455.65,119.95 455.65,101.97C455.65,99.42 457.72,97.35 460.27,97.35C487.91,97.35 566.21,97.35 593.85,97.35Z" />
33+
<path
34+
android:fillAlpha="1"
35+
android:fillColor="#0c5d18"
36+
android:pathData="M47.18,52.31L72.82,52.31L72.82,540L47.18,540L47.18,52.31Z" />
37+
<path
38+
android:fillAlpha="1"
39+
android:fillColor="#c18600"
40+
android:pathData="M336.53,102.74C339.08,102.74 341.15,104.8 341.15,107.35C341.15,125.33 341.15,174.67 341.15,192.65C341.15,195.2 339.08,197.26 336.53,197.26C309,197.26 231,197.26 203.47,197.26C200.92,197.26 198.85,195.2 198.85,192.65C198.85,174.67 198.85,125.33 198.85,107.35C198.85,104.8 200.92,102.74 203.47,102.74C231,102.74 309,102.74 336.53,102.74Z" />
41+
<path
42+
android:fillAlpha="0"
43+
android:fillColor="#FF000000"
44+
android:pathData="M365.31,136.45L346.15,151.78L365.31,136.45Z"
45+
android:strokeWidth="6"
46+
android:strokeAlpha="0.85"
47+
android:strokeColor="#006064" />
48+
<path
49+
android:fillAlpha="0"
50+
android:fillColor="#FF000000"
51+
android:pathData="M345.94,149.01L365.7,163.55L345.94,149.01Z"
52+
android:strokeWidth="6"
53+
android:strokeAlpha="0.85"
54+
android:strokeColor="#006064" />
55+
<path
56+
android:fillAlpha="0"
57+
android:fillColor="#FF000000"
58+
android:pathData="M109.61,136.13L90.45,151.46L109.61,136.13Z"
59+
android:strokeWidth="6"
60+
android:strokeAlpha="0.85"
61+
android:strokeColor="#006064" />
62+
<path
63+
android:fillAlpha="0"
64+
android:fillColor="#FF000000"
65+
android:pathData="M90.24,149.33L110,163.87L90.24,149.33Z"
66+
android:strokeWidth="6"
67+
android:strokeAlpha="0.85"
68+
android:strokeColor="#006064" />
69+
<path
70+
android:fillAlpha="0"
71+
android:fillColor="#FF000000"
72+
android:pathData="M92,150L192,150"
73+
android:strokeWidth="8"
74+
android:strokeAlpha="0.85"
75+
android:strokeColor="#006064" />
76+
<path
77+
android:fillAlpha="0"
78+
android:fillColor="#FF000000"
79+
android:pathData="M348.67,150L448.67,150"
80+
android:strokeWidth="8"
81+
android:strokeAlpha="0.85"
82+
android:strokeColor="#006064" />
83+
<path
84+
android:fillAlpha="1"
85+
android:fillColor="#00acc1"
86+
android:pathData="M337.91,342.74C340.46,342.74 342.52,344.8 342.52,347.35C342.52,365.33 342.52,414.67 342.52,432.65C342.52,435.2 340.46,437.26 337.91,437.26C310.27,437.26 231.97,437.26 204.33,437.26C201.78,437.26 199.72,435.2 199.72,432.65C199.72,414.67 199.72,365.33 199.72,347.35C199.72,344.8 201.78,342.74 204.33,342.74C231.97,342.74 310.27,342.74 337.91,342.74Z" />
87+
<path
88+
android:fillAlpha="0"
89+
android:fillColor="#FF000000"
90+
android:pathData="M109.37,381.84L90.21,397.17L109.37,381.84Z"
91+
android:strokeWidth="6"
92+
android:strokeAlpha="0.85"
93+
android:strokeColor="#006064" />
94+
<path
95+
android:fillAlpha="0"
96+
android:fillColor="#FF000000"
97+
android:pathData="M90,394.39L109.76,408.93L90,394.39Z"
98+
android:strokeWidth="6"
99+
android:strokeAlpha="0.85"
100+
android:strokeColor="#006064" />
101+
<path
102+
android:fillAlpha="0"
103+
android:fillColor="#FF000000"
104+
android:pathData="M93.24,395.3L193.24,395.3"
105+
android:strokeWidth="8"
106+
android:strokeAlpha="0.85"
107+
android:strokeColor="#006064" />
108+
<path
109+
android:fillAlpha="1"
110+
android:fillColor="#ad0000"
111+
android:pathData="M256.87,148.72L238.46,167.13L248.77,177.44L267.18,159.03L285.59,177.44L295.9,167.13L277.49,148.72L295.9,130.31L285.59,120L267.18,138.41L248.77,120L238.46,130.31L256.87,148.72Z" />
112+
<path
113+
android:fillAlpha="1"
114+
android:fillColor="#fffb3a"
115+
android:pathData="M272.4,406.51L272.41,406.51L261.04,420L240,395.01L251.36,381.52L261.04,393.01L289.92,358.72L301.28,372.21L272.4,406.51Z" />
116+
<path
117+
android:fillAlpha="1"
118+
android:fillColor="#fffb3a"
119+
android:pathData="M528.56,157.79L528.56,157.79L517.2,171.28L496.15,146.29L507.51,132.8L517.2,144.3L546.08,110L557.44,123.49L528.56,157.79Z" />
120+
</vector>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
4+
~ Copyright (c) 2018 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+
<android.support.constraint.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:animateLayoutChanges="true">
25+
26+
<View
27+
android:id="@+id/visibility_behaviour_box_start"
28+
style="@style/MediumBox"
29+
android:layout_marginStart="80dp"
30+
app:layout_constraintBottom_toBottomOf="parent"
31+
app:layout_constraintStart_toStartOf="parent"
32+
app:layout_constraintTop_toTopOf="parent" />
33+
34+
<View
35+
android:id="@+id/visibility_behaviour_box_dependent"
36+
style="@style/MediumBox.Purple"
37+
android:layout_marginStart="20dp"
38+
app:layout_constraintBottom_toBottomOf="@+id/visibility_behaviour_box_start"
39+
app:layout_constraintStart_toEndOf="@+id/visibility_behaviour_box_start"
40+
app:layout_constraintTop_toTopOf="@+id/visibility_behaviour_box_start" />
41+
42+
43+
<!-- _________________ IGNORE VIEWS BELOW THIS LINE _________________ -->
44+
45+
<!--
46+
A button to dynamically show and hide the initial box to showcase the visibility behaviour
47+
-->
48+
<Button
49+
android:id="@+id/toggle_view_visibility_button"
50+
android:layout_width="wrap_content"
51+
android:layout_height="wrap_content"
52+
android:layout_marginStart="8dp"
53+
android:layout_marginEnd="8dp"
54+
android:layout_marginBottom="8dp"
55+
android:text="Toggle Visibility"
56+
app:layout_constraintBottom_toBottomOf="parent"
57+
app:layout_constraintEnd_toEndOf="parent"
58+
app:layout_constraintStart_toStartOf="parent"
59+
tools:ignore="HardcodedText" />
60+
61+
62+
</android.support.constraint.ConstraintLayout>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
<item name="android:background">@color/md_red_700</item>
1515
</style>
1616

17+
<style name="MediumBox.Purple">
18+
<item name="android:layout_width">@dimen/box_size_medium</item>
19+
<item name="android:layout_height">@dimen/box_size_medium</item>
20+
<item name="android:background">@color/md_deep_purple_700</item>
21+
</style>
22+
1723
<style name="SimpleInfoTextView">
1824
<item name="android:layout_width">wrap_content</item>
1925
<item name="android:layout_height">wrap_content</item>

0 commit comments

Comments
 (0)