-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
Small additions (Stop server button in notification) Show notification on Android Oreo Rewrite source code app from Java to Kotlin
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.scer.pocketmine | ||
|
||
import android.app.NotificationManager | ||
import android.app.NotificationChannel | ||
import android.os.Build | ||
import android.app.Application | ||
import android.support.annotation.RequiresApi | ||
|
||
const val CHANNEL_ID = "pocketmine_service_channel" | ||
|
||
class App : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
createNotificationChannel() | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
private fun createNotificationChannel() { | ||
val serviceChannel = NotificationChannel( | ||
CHANNEL_ID, | ||
"Pocketmine Service Channel", | ||
NotificationManager.IMPORTANCE_DEFAULT | ||
) | ||
|
||
val manager = getSystemService(NotificationManager::class.java) | ||
manager!!.createNotificationChannel(serviceChannel) | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.scer.pocketmine | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import android.os.Handler | ||
import android.os.Message | ||
import android.support.v7.app.AppCompatActivity | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import android.widget.ScrollView | ||
import io.scer.pocketmine.server.Server | ||
import kotlinx.android.synthetic.main.activity_console.* | ||
|
||
class ConsoleActivity : AppCompatActivity(), Handler.Callback { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_console) | ||
|
||
instance = this | ||
|
||
labelLog.textSize = MainActivity.fontSize.toFloat() | ||
|
||
send.setOnClickListener { | ||
Server.getInstance().sendCommand(editCommand.text.toString()) | ||
editCommand.setText("") | ||
} | ||
|
||
labelLog.text = currentLog | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||
menuInflater.inflate(R.menu.console, menu) | ||
return true | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
when (item.itemId) { | ||
R.id.clear -> { | ||
labelLog.text = "" | ||
currentLog = "" | ||
} | ||
} | ||
return super.onOptionsItemSelected(item) | ||
} | ||
|
||
override fun handleMessage(message: Message): Boolean { | ||
return false | ||
} | ||
|
||
companion object { | ||
@SuppressLint("StaticFieldLeak") | ||
var instance: ConsoleActivity? = null | ||
var currentLog = "" | ||
|
||
fun log(text: String) { | ||
currentLog += text | ||
if (instance != null) { | ||
instance!!.runOnUiThread { | ||
instance!!.labelLog.append(text) | ||
instance!!.scroll.fullScroll(ScrollView.FOCUS_DOWN) | ||
} | ||
} | ||
} | ||
} | ||
} |