-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adam A. Porter
committed
Aug 5, 2019
1 parent
901f4f1
commit ac92616
Showing
20 changed files
with
623 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
*.aab | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
release/ | ||
/*/build/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
|
||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# IntelliJ | ||
*.iml | ||
.idea/workspace.xml | ||
.idea/tasks.xml | ||
.idea/gradle.xml | ||
.idea/assetWizardSettings.xml | ||
.idea/dictionaries | ||
.idea/libraries | ||
# Android Studio 3 in .gitignore file. | ||
.idea/caches | ||
.idea/modules.xml | ||
# Comment next line if keeping position of elements in Navigation Editor is relevant for you | ||
.idea/navEditor.xml | ||
|
||
# Keystore files | ||
# Uncomment the following lines if you do not want to check your keystore files in. | ||
#*.jks | ||
#*.keystore | ||
|
||
# External native build folder generated in Android Studio 2.2 and later | ||
.externalNativeBuild | ||
|
||
# Google Services (e.g. APIs or Firebase) | ||
# google-services.json | ||
|
||
# Freeline | ||
freeline.py | ||
freeline/ | ||
freeline_project_description.json | ||
|
||
# fastlane | ||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output | ||
fastlane/readme.md | ||
|
||
# Version control | ||
vcs.xml | ||
|
||
# lint | ||
lint/intermediates/ | ||
lint/generated/ | ||
lint/outputs/ | ||
lint/tmp/ | ||
# lint/reports/ | ||
|
||
# capture | ||
|
||
*.hprof |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
defaultConfig { | ||
applicationId "course.examples.ui.alertdialog" | ||
minSdkVersion 21 | ||
targetSdkVersion 28 | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'com.android.support:support-v4:28.0.0' | ||
} | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1" | ||
} |
23 changes: 23 additions & 0 deletions
23
ExamplesKotlin/UIAlertDialog/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="course.examples.ui.alertdialog" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<application | ||
android:allowBackup="false" | ||
android:theme="@style/MaterialTheme" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" > | ||
<activity | ||
android:name="course.examples.ui.alertdialog.AlertDialogActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
98 changes: 98 additions & 0 deletions
98
...lin/UIAlertDialog/app/src/main/java/course/examples/ui/alertdialog/AlertDialogActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package course.examples.ui.alertdialog | ||
|
||
import android.os.Bundle | ||
import android.support.v4.app.DialogFragment | ||
import android.support.v4.app.FragmentActivity | ||
import android.view.View | ||
import android.widget.Button | ||
import android.widget.ProgressBar | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
|
||
class AlertDialogActivity : FragmentActivity() { | ||
|
||
companion object { | ||
|
||
// Identifier for each type of Dialog | ||
private const val ALERT_ID = 0 | ||
private const val PROGRESS_ID = 1 | ||
|
||
@Suppress("unused") | ||
private const val TAG = "AlertDialogActivity" | ||
private const val ALERT_TAG = "AlertDialog" | ||
} | ||
|
||
private lateinit var mShutdownButton: Button | ||
private lateinit var mDialog: DialogFragment | ||
private lateinit var mProgressButton: ProgressBar | ||
|
||
public override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContentView(R.layout.main) | ||
|
||
// ShutDown Button | ||
mShutdownButton = findViewById(R.id.shutdownButton) | ||
|
||
// Progress Button | ||
mProgressButton = findViewById(R.id.indeterminateBar) | ||
|
||
} | ||
|
||
fun onShutDownButtonClicked(view: View) { | ||
showDialogUIElement(ALERT_ID) | ||
} | ||
|
||
// Show desired Dialog | ||
private fun showDialogUIElement(dialogID: Int) { | ||
|
||
when (dialogID) { | ||
|
||
// Show AlertDialog | ||
ALERT_ID -> { | ||
|
||
// Create a new AlertDialogFragment | ||
mDialog = AlertDialogFragment.newInstance() | ||
|
||
// Show AlertDialogFragment | ||
mDialog.show(supportFragmentManager, ALERT_TAG) | ||
} | ||
|
||
// Show ProgressDialog | ||
PROGRESS_ID -> | ||
//Make ProgressBar visible | ||
mProgressButton.visibility = View.VISIBLE | ||
} | ||
} | ||
|
||
// Abort or complete ShutDown based on value of shouldContinue | ||
internal fun continueShutdown(shouldContinue: Boolean) { | ||
if (shouldContinue) { | ||
|
||
// Prevent further interaction with the ShutDown Button | ||
mShutdownButton.isEnabled = false | ||
|
||
|
||
// Show ProgressDialog as shutdown process begins | ||
showDialogUIElement(PROGRESS_ID) | ||
|
||
// Finish the ShutDown process | ||
finishShutdown() | ||
|
||
} else { | ||
|
||
// Abort ShutDown and dismiss dialog | ||
mDialog.dismiss() | ||
} | ||
} | ||
|
||
private fun finishShutdown() { | ||
|
||
GlobalScope.launch(context = Dispatchers.Main) { | ||
delay(5000) | ||
finish() | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...lin/UIAlertDialog/app/src/main/java/course/examples/ui/alertdialog/AlertDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package course.examples.ui.alertdialog | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
|
||
import android.os.Bundle | ||
import android.support.v4.app.DialogFragment | ||
|
||
// Class that creates the AlertDialog | ||
class AlertDialogFragment : DialogFragment() { | ||
|
||
companion object { | ||
|
||
fun newInstance(): AlertDialogFragment { | ||
return AlertDialogFragment() | ||
} | ||
} | ||
|
||
// Build AlertDialog using AlertDialog.Builder | ||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
return AlertDialog.Builder(activity) | ||
.setMessage("Do you really want to exit?") | ||
|
||
// User cannot dismiss dialog by hitting back button | ||
.setCancelable(false) | ||
|
||
// Set up No Button | ||
.setNegativeButton( | ||
"No" | ||
) { _, _ -> | ||
(activity as AlertDialogActivity) | ||
.continueShutdown(false) | ||
} | ||
|
||
// Set up Yes Button | ||
.setPositiveButton( | ||
"Yes" | ||
) { _, _ -> | ||
(activity as AlertDialogActivity) | ||
.continueShutdown(true) | ||
}.create() | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
ExamplesKotlin/UIAlertDialog/app/src/main/res/layout/main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="@dimen/activity_margin"> | ||
|
||
<Button | ||
android:id="@+id/shutdownButton" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/shutdown_string" | ||
android:textColor="@android:color/white" | ||
android:textAppearance="@android:style/TextAppearance.Material.Medium" | ||
android:onClick="onShutDownButtonClicked"/> | ||
|
||
<ProgressBar | ||
android:id="@+id/indeterminateBar" | ||
android:layout_width="100dp" | ||
android:layout_height="100dp" | ||
android:layout_centerInParent="true" | ||
android:visibility="gone" | ||
android:indeterminateTint="@color/primary" | ||
/> | ||
|
||
</RelativeLayout> |
Binary file added
BIN
+7.48 KB
ExamplesKotlin/UIAlertDialog/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.69 KB
ExamplesKotlin/UIAlertDialog/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.2 KB
ExamplesKotlin/UIAlertDialog/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+24.2 KB
ExamplesKotlin/UIAlertDialog/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
ExamplesKotlin/UIAlertDialog/app/src/main/res/values/colors.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources xmlns:tools="http://schemas.android.com/tools"> | ||
<color name="primary">#FF5722</color> | ||
<color name="primary_dark">#E64A19</color> | ||
<color name="primary_light" tools:keep="@color/primary_light">#FFCCBC</color> | ||
<color name="accent">#536DFE</color> | ||
<color name="primary_text">#212121</color> | ||
<color name="edit_text">#212121</color> | ||
<color name="secondary_text">#757575</color> | ||
<color name="icons" tools:keep="@color/icons">#FFFFFF</color> | ||
<color name="divider" tools:keep="@color/divider">#BDBDBD</color> | ||
</resources> |
7 changes: 7 additions & 0 deletions
7
ExamplesKotlin/UIAlertDialog/app/src/main/res/values/dimens.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_margin">16dp</dimen> | ||
|
||
<!--Space between content areas: 8dp--> | ||
</resources> |
5 changes: 5 additions & 0 deletions
5
ExamplesKotlin/UIAlertDialog/app/src/main/res/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">UIAlertDialog</string> | ||
<string name="shutdown_string">ShutDown</string> | ||
</resources> |
12 changes: 12 additions & 0 deletions
12
ExamplesKotlin/UIAlertDialog/app/src/main/res/values/styles.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="MaterialTheme" parent="android:Theme.Material.Light.DarkActionBar"> | ||
<item name="android:colorPrimary">@color/primary</item> | ||
<item name="android:colorPrimaryDark">@color/primary_dark</item> | ||
<item name="android:colorAccent">@color/accent</item> | ||
<item name="android:textColorPrimary">@color/primary_text</item> | ||
<item name="android:textColorSecondary">@color/secondary_text</item> | ||
<item name="android:editTextColor">@color/edit_text</item> | ||
<item name="android:colorButtonNormal">@color/primary</item> | ||
</style> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
buildscript { | ||
ext.kotlin_version = '1.3.41' | ||
repositories { | ||
jcenter() | ||
google() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.4.2' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
google() | ||
} | ||
} |
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
ExamplesKotlin/UIAlertDialog/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Sun Aug 04 19:04:22 EDT 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip |
Oops, something went wrong.