Skip to content

Commit 8071dc2

Browse files
committed
Update sample
Dynamic dialogs 4.2.1. Implement about dialog. Add FAB for sources link.
1 parent 604a38f commit 8071dc2

File tree

17 files changed

+528
-117
lines changed

17 files changed

+528
-117
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ buildscript {
2020
'minSdk' : 18,
2121
'targetSdk' : 32,
2222
'buildTools' : '32.0.0',
23-
'appcompat' : '1.3.0',
2423
'constraintlayout': '2.1.4',
24+
'dialogs' : '4.2.1',
2525
'kotlin' : '1.6.20',
2626
'viewpager2' : '1.0.0'
2727
]

sample/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
apply plugin: 'com.android.application'
18+
apply plugin: 'org.jetbrains.kotlin.android'
1819

1920
android {
2021
compileSdkVersion versions.compileSdk
@@ -36,9 +37,19 @@ android {
3637
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3738
}
3839
}
40+
41+
lintOptions {
42+
abortOnError false
43+
}
44+
45+
compileOptions {
46+
sourceCompatibility JavaVersion.VERSION_1_8
47+
targetCompatibility JavaVersion.VERSION_1_8
48+
}
3949
}
4050

4151
dependencies {
4252
implementation project(':dynamic-motion')
43-
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
53+
implementation "com.pranavpandey.android:dynamic-dialogs:${versions.dialogs}"
54+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
4455
}

sample/src/main/AndroidManifest.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
android:icon="@mipmap/ic_launcher"
2424
android:label="@string/app_name"
2525
android:theme="@style/AppTheme"
26-
android:supportsRtl="true"
27-
android:allowBackup="false">
26+
android:supportsRtl="true">
2827

2928
<meta-data android:name="android.max_aspect" android:value="2.1" />
3029

3130
<activity
3231
android:name=".DynamicMotionActivity"
33-
android:label="@string/app_name"
34-
android:theme="@style/AppTheme"
32+
android:theme="@style/AppTheme.NoActionBar"
3533
android:exported="true">
3634
<intent-filter>
3735
<action android:name="android.intent.action.VIEW" />

sample/src/main/java/com/pranavpandey/android/dynamic/motion/sample/DynamicMotionActivity.java

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2018-2022 Pranav Pandey
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.pranavpandey.android.dynamic.motion.sample
18+
19+
import android.content.res.Configuration
20+
import android.os.Bundle
21+
import android.view.Menu
22+
import android.view.MenuItem
23+
import android.view.View
24+
import androidx.appcompat.app.AppCompatActivity
25+
import androidx.appcompat.widget.Toolbar
26+
import androidx.core.content.ContextCompat
27+
import com.google.android.material.floatingactionbutton.FloatingActionButton
28+
import com.pranavpandey.android.dynamic.motion.sample.dialog.AboutDialogFragment
29+
import com.pranavpandey.android.dynamic.util.DynamicColorUtils
30+
import com.pranavpandey.android.dynamic.util.DynamicLinkUtils
31+
32+
class DynamicMotionActivity : AppCompatActivity(), View.OnClickListener {
33+
34+
companion object {
35+
36+
/**
37+
* Open source repository url.
38+
*/
39+
const val URL_GITHUB = "https://github.com/pranavpandey/dynamic-motion"
40+
}
41+
42+
override fun onCreate(savedInstanceState: Bundle?) {
43+
super.onCreate(savedInstanceState)
44+
45+
setContentView(R.layout.activity_dynamic_motion)
46+
val toolbar = findViewById<Toolbar>(R.id.toolbar)
47+
toolbar.setSubtitle(R.string.app_name_sample)
48+
setSupportActionBar(toolbar)
49+
50+
val fab = findViewById<FloatingActionButton>(R.id.fab)
51+
fab.setColorFilter(
52+
DynamicColorUtils.getTintColor(
53+
ContextCompat.getColor(this, R.color.color_accent)))
54+
55+
fab.setOnClickListener(this)
56+
}
57+
58+
override fun onClick(v: View) {
59+
when (v.id) {
60+
R.id.fab -> DynamicLinkUtils.viewUrl(this@DynamicMotionActivity, URL_GITHUB)
61+
}
62+
}
63+
64+
/**
65+
* Fix for AppCompat 1.1.0.
66+
*
67+
* https://issuetracker.google.com/issues/140602653
68+
*/
69+
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
70+
if (overrideConfiguration != null) {
71+
val uiMode = overrideConfiguration.uiMode
72+
overrideConfiguration.setTo(baseContext.resources.configuration)
73+
overrideConfiguration.uiMode = uiMode
74+
}
75+
super.applyOverrideConfiguration(resources.configuration)
76+
}
77+
78+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
79+
menuInflater.inflate(R.menu.main, menu)
80+
return super.onCreateOptionsMenu(menu)
81+
82+
}
83+
84+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
85+
if (item.itemId == R.id.menu_about) {
86+
AboutDialogFragment.newInstance().showDialog(this)
87+
88+
return true
89+
}
90+
return super.onOptionsItemSelected(item)
91+
}
92+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright 2018-2022 Pranav Pandey
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.pranavpandey.android.dynamic.motion.sample.dialog
18+
19+
import android.os.Build
20+
import android.os.Bundle
21+
import android.text.Html
22+
import android.text.Spanned
23+
import android.text.method.LinkMovementMethod
24+
import android.view.LayoutInflater
25+
import android.view.View
26+
import android.widget.LinearLayout
27+
import android.widget.TextView
28+
import androidx.core.content.ContextCompat
29+
import com.pranavpandey.android.dynamic.dialogs.DynamicDialog
30+
import com.pranavpandey.android.dynamic.dialogs.fragment.DynamicDialogFragment
31+
import com.pranavpandey.android.dynamic.motion.sample.R
32+
import com.pranavpandey.android.dynamic.util.DynamicLinkUtils
33+
34+
/**
35+
* About dialog to show library info.
36+
*/
37+
class AboutDialogFragment : DynamicDialogFragment() {
38+
39+
companion object {
40+
41+
/**
42+
* Url for other apps on Google Play.
43+
*/
44+
const val URL_PLAY_STORE =
45+
"https://play.google.com/store/apps/dev?id=6608630615059087491"
46+
47+
/**
48+
* Initialize the new instance of this fragment.
49+
*
50+
* @return An instance of [AboutDialogFragment].
51+
*/
52+
fun newInstance(): AboutDialogFragment {
53+
return AboutDialogFragment()
54+
}
55+
56+
/**
57+
* Method to handle [Html.fromHtml] deprecation.
58+
*/
59+
@Suppress("DEPRECATION")
60+
private fun fromHtml(html: String): Spanned {
61+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
62+
Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY)
63+
} else {
64+
Html.fromHtml(html)
65+
}
66+
}
67+
}
68+
69+
70+
/**
71+
* Customise [DynamicDialog.Builder] by overriding this method.
72+
*/
73+
override fun onCustomiseBuilder(
74+
alertDialogBuilder: DynamicDialog.Builder,
75+
savedInstanceState: Bundle?
76+
): DynamicDialog.Builder {
77+
// Customise dialog builder to add neutral, positive and negative buttons.
78+
// Also, set a view root to add top and bottom scroll indicators.
79+
return alertDialogBuilder.setTitle(R.string.about)
80+
.setPositiveButton(R.string.more_apps) { _, _ ->
81+
DynamicLinkUtils.viewUrl(requireContext(), URL_PLAY_STORE)
82+
}
83+
.setNegativeButton(android.R.string.cancel, null)
84+
// Set custom view for the dialog.
85+
.setView(
86+
LayoutInflater.from(context).inflate(
87+
R.layout.dialog_about,
88+
LinearLayout(context), false
89+
)
90+
)
91+
// Set view root to automatically add scroll dividers.
92+
.setViewRoot(R.id.dialog_about_root)
93+
}
94+
95+
/**
96+
* Customise [DynamicDialog] by overriding this method.
97+
*/
98+
override fun onCustomiseDialog(
99+
alertDialog: DynamicDialog,
100+
view: View?, savedInstanceState: Bundle?
101+
) {
102+
super.onCustomiseDialog(alertDialog, view, savedInstanceState)
103+
104+
// Customise the custom view.
105+
val message = view?.findViewById<TextView>(R.id.dialog_about_text)
106+
107+
message?.text = fromHtml(getString(R.string.about_content))
108+
message?.setLineSpacing(0f, 1.2f)
109+
message?.movementMethod = LinkMovementMethod.getInstance()
110+
message?.setLinkTextColor(ContextCompat.getColor(requireContext(), R.color.color_accent))
111+
}
112+
}

sample/src/main/java/com/pranavpandey/android/dynamic/motion/sample/widget/DynamicImageView.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)