Skip to content

Commit 2d879e4

Browse files
committed
v1.07: updated to kotlin
1 parent bbf9643 commit 2d879e4

12 files changed

+271
-393
lines changed

app/build.gradle

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
24

35
android {
4-
compileSdkVersion 27
5-
buildToolsVersion "27.0.3"
6+
compileSdkVersion 28
67

78
defaultConfig {
89
minSdkVersion 14
9-
targetSdkVersion 27
10-
versionCode 6
11-
versionName "v1.06"
12-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
10+
targetSdkVersion 28
11+
versionCode 7
12+
versionName "v1.07"
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1314
}
1415

1516

@@ -35,9 +36,10 @@ android {
3536

3637
dependencies {
3738
testImplementation 'junit:junit:4.12'
38-
androidTestImplementation'junit:junit:4.12'
39-
implementation 'com.android.support:design:27.1.0'
40-
implementation 'com.github.danbrough.util:slf4j:1.0.6'
39+
androidTestImplementation 'junit:junit:4.12'
40+
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
41+
implementation 'com.github.danbrough.util:slf4j:1.0.7'
42+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
4143

4244
}
4345

@@ -51,6 +53,9 @@ project.afterEvaluate {
5153
}
5254
}
5355
}
56+
repositories {
57+
mavenCentral()
58+
}
5459

5560

5661

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package danbroid.searchview
2+
3+
import android.content.pm.PackageManager
4+
import android.text.Html
5+
import android.text.SpannableString
6+
import android.text.method.LinkMovementMethod
7+
import android.widget.TextView
8+
import androidx.appcompat.app.AlertDialog
9+
10+
/**
11+
* Function to display the about dialog
12+
*/
13+
14+
fun MainActivity.showAboutDialog() {
15+
val builder = AlertDialog.Builder(supportActionBar!!.themedContext,
16+
R.style.DialogTheme)
17+
builder.setPositiveButton(android.R.string.ok, null)
18+
var title = getString(R.string.app_name) + " version: "
19+
20+
21+
try {
22+
val packageInfo = packageManager.getPackageInfo(packageName, 0)
23+
title += " " + packageInfo.versionName
24+
} catch (e: PackageManager.NameNotFoundException) {
25+
//Handle exception
26+
}
27+
28+
builder.setTitle(title)
29+
30+
builder.setIcon(R.drawable.ic_launcher)
31+
val aboutMessage = SpannableString(Html.fromHtml(getString(R.string
32+
.msg_about)))
33+
builder.setMessage(aboutMessage)
34+
35+
val messageText = builder.show().findViewById<TextView>(android.R.id.message)
36+
messageText!!.movementMethod = LinkMovementMethod.getInstance()
37+
}

app/src/main/java/danbroid/searchview/MainActivity.java

Lines changed: 0 additions & 192 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package danbroid.searchview
2+
3+
import android.app.SearchManager
4+
import android.content.Intent
5+
import android.os.Bundle
6+
import android.view.Menu
7+
import android.view.MenuItem
8+
import android.widget.Toast
9+
10+
import androidx.appcompat.app.AppCompatActivity
11+
import kotlinx.android.synthetic.main.layout.*
12+
13+
14+
private val log by lazy {
15+
org.slf4j.LoggerFactory.getLogger(MainActivity::class.java)
16+
}
17+
18+
class MainActivity : AppCompatActivity() {
19+
20+
private lateinit var searchItem: MenuItem
21+
22+
private val searchViewSupport = SearchViewSupport(this)
23+
24+
25+
override fun onCreate(state: Bundle?) {
26+
log.info("onCreate() intent:{}", intent)
27+
super.onCreate(state)
28+
29+
setContentView(R.layout.layout)
30+
setSupportActionBar(toolbar)
31+
32+
33+
add_suggestion_button.setOnClickListener { searchViewSupport.addAnotherSuggestion() }
34+
35+
clear_button.setOnClickListener { searchViewSupport.clearSuggestions() }
36+
37+
38+
submit_enabled_checkbox.setOnCheckedChangeListener { _,
39+
isChecked ->
40+
searchViewSupport.searchView.isSubmitButtonEnabled = isChecked
41+
}
42+
43+
}
44+
45+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
46+
searchViewSupport.createSearchView(menu)
47+
48+
return super.onCreateOptionsMenu(menu)
49+
}
50+
51+
override fun onNewIntent(intent: Intent) {
52+
super.onNewIntent(intent)
53+
54+
log.info("onNewIntent() :{}", intent)
55+
searchViewSupport.showSearch = false
56+
57+
intent.extras?.let {
58+
/**
59+
* USER_QUERY will be set when the user uses the submit button to submit the query
60+
*/
61+
val msg = "SearchManager.USER_QUERY = ${it[SearchManager.USER_QUERY]}," +
62+
"SearchManager.QUERY = ${it[SearchManager.QUERY]}"
63+
64+
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
65+
log.info(msg)
66+
}
67+
68+
}
69+
70+
71+
/**
72+
* Called when the hardware search button is pressed
73+
*/
74+
override fun onSearchRequested(): Boolean {
75+
log.trace("onSearchRequested();")
76+
searchViewSupport.showSearch = false
77+
78+
// dont show the built-in search dialog
79+
return false
80+
}
81+
82+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
83+
when (item.itemId) {
84+
R.id.menu_about -> {
85+
showAboutDialog()
86+
return true
87+
}
88+
}
89+
return super.onOptionsItemSelected(item)
90+
}
91+
}
92+
93+

0 commit comments

Comments
 (0)