[go: nahoru, domu]

Skip to content

Commit

Permalink
Convert to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam A. Porter committed Aug 4, 2019
1 parent 58a1e19 commit 901f4f1
Show file tree
Hide file tree
Showing 22 changed files with 574 additions and 0 deletions.
87 changes: 87 additions & 0 deletions ExamplesKotlin/HelloAndroidWithMenus/.gitignore
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
27 changes: 27 additions & 0 deletions ExamplesKotlin/HelloAndroidWithMenus/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28

defaultConfig {
applicationId "course.examples.helloandroidwithmenu"
minSdkVersion 21
targetSdkVersion 28

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
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.helloandroidwithmenu"
android:versionCode="1"
android:versionName="1.0">

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MaterialTheme">
<activity
android:name=".HelloAndroidWithMenuActivity"
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package course.examples.helloandroidwithmenu

import android.app.Activity
import android.os.Bundle
import android.view.ContextMenu
import android.view.ContextMenu.ContextMenuInfo
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import android.widget.Toast

class HelloAndroidWithMenuActivity : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.main)

// Long presses on TextView invoke Context Menu
registerForContextMenu(findViewById<TextView>(R.id.text_view))

}

// Create Options Menu
override fun onCreateOptionsMenu(menu: Menu): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.top_menu, menu)
return true
}

// Process clicks on Options Menu items
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.help -> {
showToast(R.string.helped_string)
true
}
R.id.more_help -> {
showToast(R.string.helped_more_string)
true
}
R.id.even_more_help -> true
else -> false
}
}

// Create Context Menu
override fun onCreateContextMenu(
menu: ContextMenu, v: View,
menuInfo: ContextMenuInfo?
) {
super.onCreateContextMenu(menu, v, menuInfo)
val inflater = menuInflater
inflater.inflate(R.menu.context_menu, menu)
}

// Process clicks on Context Menu Items
override fun onContextItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.help_guide -> {
showToast(R.string.context_menu_shown_string)
true
}
else -> false
}
}

private fun showToast(msg: Int) {
Toast.makeText(applicationContext, msg, Toast.LENGTH_SHORT).show()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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">

<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/hello_android"
android:textAppearance="@android:style/TextAppearance.Material.Display1" />

</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/help_guide"
android:title="@string/guide"/>

</menu>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/help"
android:icon="@mipmap/ic_menu_help"
android:title="@string/help"/>
<item
android:id="@+id/more_help"
android:icon="@mipmap/ic_menu_help"
android:title="@string/more_help"/>
<item
android:id="@+id/even_more_help"
android:icon="@mipmap/ic_menu_help"
android:title="@string/even_more_help">
<menu>
<item
android:title="@string/give_up"/>
</menu>
</item>

</menu>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#FF5722</color>
<color name="primary_dark">#E64A19</color>
<color name="accent">#CCE5FF</color>
<color name="primary_text">#000000</color>
<color name="secondary_text">#727272</color>
<color name="edit_text">#202020</color>
</resources>
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">HelloAndroidWithMenus</string>
<string name="help">Help</string>
<string name="more_help">Help!</string>
<string name="even_more_help">Help!!</string>
<string name="guide">Hit the Menu Button!</string>
<string name="give_up">There is no more help!</string>
<string name="hello_android">Hello Android!</string>
<string name="helped_string">you\'ve been helped</string>
<string name="helped_more_string">you\'ve been helped more</string>
<string name="context_menu_shown_string">ContextMenu Shown</string>

</resources>
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>
19 changes: 19 additions & 0 deletions ExamplesKotlin/HelloAndroidWithMenus/build.gradle
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Sun Aug 04 18:32:17 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
Loading

0 comments on commit 901f4f1

Please sign in to comment.