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

Commit 0cf4677

Browse files
authored
Merge pull request #84 from amardeshbd/add-sample-screen
Add sample demo screen
2 parents 986ccc2 + 0d42a17 commit 0cf4677

15 files changed

+582
-2
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<activity
3838
android:name="com.hossainkhan.android.demo.ui.layoutpreview.LayoutDimensionMinMaxActivity"
3939
android:parentActivityName="com.hossainkhan.android.demo.ui.browse.LayoutBrowseActivity" />
40+
<activity
41+
android:name="com.hossainkhan.android.demo.ui.functionaldemo.MovieDetailsPreviewActivity"
42+
android:parentActivityName="com.hossainkhan.android.demo.ui.browse.LayoutBrowseActivity" />
4043
</application>
4144

4245
</manifest>

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,24 @@ class LayoutDataStore @Inject constructor(
159159
title = "Virtual Helper: Group",
160160
description = "This class controls the visibility of a set of referenced widgets. " +
161161
"Widgets are referenced by being added to a comma separated list of ids.\n\n" +
162-
"For example you can link multiple views: `app:constraint_referenced_ids=\"viewId1,viewId2,viewId3\"` and control their visibility at once.")
162+
"For example you can link multiple views: `app:constraint_referenced_ids=\"viewId1,viewId2,viewId3\"` and control their visibility at once."),
163+
164+
/*
165+
* This is a demo of movie details page using various features of constraint layout.
166+
*
167+
* .-'-.
168+
* /` |__
169+
* /` _.--`-,-`
170+
* '-|` a '<-. []
171+
* \ _\__) \=`
172+
* C_ ` ,_/
173+
* | ;----'
174+
*/
175+
LayoutInformation(
176+
layoutResourceId = R.layout.demo_movie_details,
177+
thumbnailResourceId = R.drawable.spider_verse_poster,
178+
title = "Demo: Movie Details",
179+
description = "A demo screen containing movie details.")
163180

164181

165182
/*

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.hossainkhan.android.demo.di
1818

19+
import com.hossainkhan.android.demo.ui.functionaldemo.MovieDetailsPreviewActivity
1920
import com.hossainkhan.android.demo.ui.layoutpreview.LayoutChainStyleActivity
2021
import com.hossainkhan.android.demo.ui.layoutpreview.LayoutDimensionMinMaxActivity
2122
import com.hossainkhan.android.demo.ui.layoutpreview.LayoutGuidelineBarrierActivity
@@ -73,4 +74,8 @@ abstract class ActivityBindingModule {
7374
@ActivityScope
7475
@ContributesAndroidInjector
7576
abstract fun layoutDimensionMinMaxActivity(): LayoutDimensionMinMaxActivity
77+
78+
@ActivityScope
79+
@ContributesAndroidInjector
80+
abstract fun layoutMovieDetailsPreviewActivity(): MovieDetailsPreviewActivity
7681
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.lifecycle.ViewModel
2222
import com.hossainkhan.android.demo.R
2323
import com.hossainkhan.android.demo.data.AppDataStore
2424
import com.hossainkhan.android.demo.data.LayoutInformation
25+
import com.hossainkhan.android.demo.ui.functionaldemo.MovieDetailsPreviewActivity
2526
import com.hossainkhan.android.demo.ui.layoutpreview.LayoutChainStyleActivity
2627
import com.hossainkhan.android.demo.ui.layoutpreview.LayoutDimensionMinMaxActivity
2728
import com.hossainkhan.android.demo.ui.layoutpreview.LayoutGuidelineBarrierActivity
@@ -69,6 +70,9 @@ class LayoutBrowseViewModel(
6970
R.layout.preview_dimension_min_max -> {
7071
browseNavigator.loadLayoutPreview(LayoutDimensionMinMaxActivity::class.java, layoutResId)
7172
}
73+
R.layout.demo_movie_details -> {
74+
browseNavigator.loadLayoutPreview(MovieDetailsPreviewActivity::class.java, layoutResId)
75+
}
7276
else -> {
7377
// By default it loads the preview activity with the layout requested.
7478
browseNavigator.loadLayoutPreview(layoutResId)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.ui.functionaldemo
18+
19+
import android.os.Bundle
20+
import android.view.View
21+
import android.widget.Button
22+
import android.widget.ImageButton
23+
import android.widget.Toast
24+
import com.hossainkhan.android.demo.R
25+
import com.hossainkhan.android.demo.ui.layoutpreview.LayoutPreviewBaseActivity
26+
import android.content.Intent
27+
import android.content.res.ColorStateList
28+
import android.net.Uri
29+
import android.widget.ImageView
30+
import androidx.annotation.ColorRes
31+
import androidx.core.content.ContextCompat
32+
import androidx.core.widget.ImageViewCompat
33+
34+
/**
35+
* Activity showcasing how visibility GONE affects constraints.
36+
*
37+
* See https://developer.android.com/reference/android/support/constraint/ConstraintLayout#VisibilityBehavior
38+
*/
39+
class MovieDetailsPreviewActivity : LayoutPreviewBaseActivity() {
40+
private val generalClickListener = View.OnClickListener { view ->
41+
Toast.makeText(view.context, "You tapped on ${view}", Toast.LENGTH_SHORT).show()
42+
43+
// Some custom logic to make the UI alive!
44+
when (view.id) {
45+
R.id.rating_thumbs_up, R.id.rating_thumbs_down -> {
46+
applyColorTint((view as ImageButton), R.color.white)
47+
}
48+
}
49+
}
50+
51+
52+
override fun onCreate(savedInstanceState: Bundle?) {
53+
super.onCreate(savedInstanceState)
54+
55+
val ratingThumbsUp = findViewById<ImageButton>(R.id.rating_thumbs_up)
56+
val ratingThumbsDown = findViewById<ImageButton>(R.id.rating_thumbs_down)
57+
val addToFav = findViewById<ImageButton>(R.id.rating_add_fav)
58+
val rentButton = findViewById<Button>(R.id.button_rent)
59+
val buyButton = findViewById<Button>(R.id.button_buy)
60+
val trailer = findViewById<Button>(R.id.movie_trailer)
61+
62+
// Apply generic toast listener to touchable views so that user gets feedback when they tap it
63+
applyToastListener(ratingThumbsUp, ratingThumbsDown, addToFav, rentButton, buyButton)
64+
65+
trailer.setOnClickListener {
66+
val youtubeTrailerUrl = "https://www.youtube.com/watch?v=g4Hbz2jLxvQ"
67+
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(youtubeTrailerUrl)))
68+
}
69+
}
70+
71+
private fun applyToastListener(vararg views: View) {
72+
views.forEach {
73+
it.setOnClickListener(generalClickListener)
74+
}
75+
}
76+
77+
private fun applyColorTint(view: ImageView, @ColorRes tintColor: Int) {
78+
ImageViewCompat.setImageTintList(view,
79+
ColorStateList.valueOf(ContextCompat.getColor(this.applicationContext, tintColor))
80+
)
81+
}
82+
}
Loading
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="18dp"
19+
android:height="18dp"
20+
android:alpha="0.9"
21+
android:tint="#666666"
22+
android:viewportWidth="24.0"
23+
android:viewportHeight="24.0">
24+
<path
25+
android:fillColor="#FF000000"
26+
android:pathData="M16,11c1.66,0 2.99,-1.34 2.99,-3S17.66,5 16,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zM8,11c1.66,0 2.99,-1.34 2.99,-3S9.66,5 8,5C6.34,5 5,6.34 5,8s1.34,3 3,3zM8,13c-2.33,0 -7,1.17 -7,3.5L1,19h14v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5zM16,13c-0.29,0 -0.62,0.02 -0.97,0.05 1.16,0.84 1.97,1.97 1.97,3.45L17,19h6v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5z" />
27+
</vector>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<vector android:alpha="0.9" android:height="24dp" android:tint="#666666"
18+
android:viewportHeight="24.0" android:viewportWidth="24.0"
19+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
20+
<path android:fillColor="#FF000000" android:pathData="M10,16.5l6,-4.5 -6,-4.5v9zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
21+
</vector>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<vector android:alpha="0.9" android:height="24dp" android:tint="#666666"
18+
android:viewportHeight="24.0" android:viewportWidth="24.0"
19+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
20+
<path android:fillColor="#FF000000" android:pathData="M14,10L2,10v2h12v-2zM14,6L2,6v2h12L14,6zM18,14v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zM2,16h8v-2L2,14v2z"/>
21+
</vector>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="18dp"
19+
android:height="18dp"
20+
android:alpha="0.9"
21+
android:tint="#666666"
22+
android:viewportWidth="24.0"
23+
android:viewportHeight="24.0">
24+
<path
25+
android:fillColor="#FF000000"
26+
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z" />
27+
</vector>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<vector android:alpha="0.9" android:height="24dp" android:tint="#666666"
18+
android:viewportHeight="24.0" android:viewportWidth="24.0"
19+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
20+
<path android:fillColor="#FF000000" android:pathData="M15,3L6,3c-0.83,0 -1.54,0.5 -1.84,1.22l-3.02,7.05c-0.09,0.23 -0.14,0.47 -0.14,0.73v1.91l0.01,0.01L1,14c0,1.1 0.9,2 2,2h6.31l-0.95,4.57 -0.03,0.32c0,0.41 0.17,0.79 0.44,1.06L9.83,23l6.59,-6.59c0.36,-0.36 0.58,-0.86 0.58,-1.41L17,5c0,-1.1 -0.9,-2 -2,-2zM19,3v12h4L23,3h-4z"/>
21+
</vector>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<vector android:alpha="0.9" android:height="24dp" android:tint="#666666"
18+
android:viewportHeight="24.0" android:viewportWidth="24.0"
19+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
20+
<path android:fillColor="#FF000000" android:pathData="M1,21h4L5,9L1,9v12zM23,10c0,-1.1 -0.9,-2 -2,-2h-6.31l0.95,-4.57 0.03,-0.32c0,-0.41 -0.17,-0.79 -0.44,-1.06L14.17,1 7.59,7.59C7.22,7.95 7,8.45 7,9v10c0,1.1 0.9,2 2,2h9c0.83,0 1.54,-0.5 1.84,-1.22l3.02,-7.05c0.09,-0.23 0.14,-0.47 0.14,-0.73v-1.91l-0.01,-0.01L23,10z"/>
21+
</vector>

0 commit comments

Comments
 (0)