Skip to content

Commit

Permalink
[ shit ] Fuck google
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Dec 19, 2017
1 parent 9697466 commit 77cb43e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 55 deletions.
5 changes: 3 additions & 2 deletions frice/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'
// apply plugin: 'com.android.library'
apply plugin: 'com.android.application'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'kotlin-android'

Expand All @@ -23,7 +24,7 @@ android {
dependencies {
compile "org.jetbrains.anko:anko-common:$anko_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}

Expand Down
21 changes: 19 additions & 2 deletions frice/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
<manifest package="org.frice">
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.frice">

<application
android:allowBackup="true"
android:label="FriceEngine"
android:supportsRtl="true">
<activity android:name=".Game">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
90 changes: 43 additions & 47 deletions frice/src/main/kotlin/org/frice/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

package org.frice

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.PixelFormat
import android.net.*
import android.os.Bundle
import android.os.PersistableBundle
import android.support.v7.app.AppCompatActivity
import android.view.SurfaceView
import android.view.Window
import android.view.*
import android.widget.FrameLayout
import org.frice.event.*
import org.frice.obj.button.FText
import org.frice.platform.FriceGame
Expand All @@ -29,7 +27,6 @@ import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import java.net.URL
import java.util.*
import kotlin.concurrent.thread


/**
Expand All @@ -44,8 +41,8 @@ import kotlin.concurrent.thread
* @author ice1000
* @since v0.2.3
*/
@Suppress("LeakingThis")
open class Game @JvmOverloads constructor(layerCount: Int = 1) : AppCompatActivity(), FriceGame<DroidDrawer> {
open class Game @JvmOverloads constructor(layerCount: Int = 1) :
Activity(), FriceGame<DroidDrawer>, Runnable {
private var screenWidth: Int = -1
private var screenHeight: Int = -1

Expand All @@ -65,11 +62,16 @@ open class Game @JvmOverloads constructor(layerCount: Int = 1) : AppCompatActivi
field = value
}

override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
window.setFormat(PixelFormat.TRANSLUCENT)
surfaceView = SurfaceView(this)
frameLayout = FrameLayout(this)
frameLayout.addView(surfaceView, ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT))
setContentView(frameLayout)
surfaceView.setOnClickListener {
mouse(OnMouseEvent(it.x.toDouble(), it.y.toDouble(), MOUSE_CLICKED))
onMouse(OnMouseEvent(it.x.toDouble(), it.y.toDouble(), MOUSE_CLICKED))
Expand All @@ -79,42 +81,36 @@ open class Game @JvmOverloads constructor(layerCount: Int = 1) : AppCompatActivi
onMouse(OnMouseEvent(it.x.toDouble(), it.y.toDouble(), MOUSE_PRESSED))
return@setOnTouchListener false
}
setContentView(surfaceView)
screenWidth = resources.displayMetrics.widthPixels
screenHeight = resources.displayMetrics.heightPixels
onInit()
FLog.v("height: $screenHeight, width: $screenWidth")
thread {
onLastInit()
loop {
try {
onRefresh()
// only update per "refreshTime"
if (!paused && !stopped && refresh.ended() && surfaceView.holder.surface.isValid) {
val canvas = surfaceView.holder.lockCanvas()
val localDrawer = drawer ?: DroidDrawer(canvas).also { drawer = it }
localDrawer.canvas = canvas
clearScreen(localDrawer)
drawEverything(localDrawer)

// if (loseFocus and loseFocusChangeColor) {
// repeat(localDrawer.canvas.width) { x: Int ->
// repeat(localDrawer.canvas.height) { y: Int ->
// localDrawer.canvas[x, y] = drawer.friceImage[x, y].darker()
// }
// }
// }

localDrawer.restore()
localDrawer.init()
localDrawer.color = ColorResource.DARK_GRAY
if (showFPS) localDrawer.drawString("fps: ${fpsCounter.display}", 30.0, height - 30.0)

fpsCounter.refresh()
surfaceView.holder.unlockCanvasAndPost(canvas)
}
} catch (ignored: ConcurrentModificationException) {
Thread(this).start()
}

override fun run() {
onLastInit()
loop {
try {
onRefresh()
// only update per "refreshTime"
if (!paused && !stopped && refresh.ended() && surfaceView.holder.surface.isValid) {
val canvas = surfaceView.holder.lockCanvas()
val localDrawer = drawer ?: DroidDrawer(canvas).also { drawer = it }
localDrawer.canvas = canvas
clearScreen(localDrawer)
drawEverything(localDrawer)
// if (loseFocus and loseFocusChangeColor) repeat(localDrawer.canvas.width) { x: Int -> repeat(localDrawer.canvas.height) { y: Int -> localDrawer.canvas[x, y] = drawer.friceImage[x, y].darker() } }

localDrawer.restore()
localDrawer.init()
localDrawer.color = ColorResource.DARK_GRAY
if (showFPS) localDrawer.drawString("fps: ${fpsCounter.display}", 30.0, height - 30.0)

fpsCounter.refresh()
surfaceView.holder.unlockCanvasAndPost(canvas)
}
} catch (ignored: ConcurrentModificationException) {
}
}
}
Expand Down Expand Up @@ -163,8 +159,9 @@ open class Game @JvmOverloads constructor(layerCount: Int = 1) : AppCompatActivi
refresh.time = value
}

private lateinit var surfaceView: SurfaceView
var drawer: DroidDrawer? = null
lateinit var frameLayout: FrameLayout
lateinit var surfaceView: SurfaceView

val fpsCounter = FpsCounter()

Expand All @@ -173,7 +170,7 @@ open class Game @JvmOverloads constructor(layerCount: Int = 1) : AppCompatActivi
}

open fun onExit() {
TODO()
// TODO()
}

override fun measureText(text: FText): FRectangle {
Expand All @@ -190,13 +187,12 @@ open class Game @JvmOverloads constructor(layerCount: Int = 1) : AppCompatActivi
get() = (getSystemService(Context.CONNECTIVITY_SERVICE)
as ConnectivityManager).activeNetworkInfo


/**
* if this value is null,
* it means I have 2 load data from Sp.
*/
val isNetConnected: Boolean
get() = connection != null && connection!!.isConnected
get() = connection?.isConnected ?: false

/**
* this will cache the data into SharedPreference
Expand All @@ -208,8 +204,8 @@ open class Game @JvmOverloads constructor(layerCount: Int = 1) : AppCompatActivi
@JvmOverloads
fun webResource(
url: String,
submit: (String) -> Unit,
default: String = "DEFAULT_VALUE") {
default: String = "DEFAULT_VALUE",
submit: (String) -> Unit) {
var ret = ""
doAsync {
ret = readString(default)
Expand Down
6 changes: 2 additions & 4 deletions frice/src/main/kotlin/org/frice/utils/data/SpUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
package org.frice.utils.data

import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import android.support.v7.app.AppCompatActivity

/**
* insert a value in2 SharedPreference
Expand Down Expand Up @@ -36,6 +36,4 @@ fun Context.readBoolean(key: String, default: Boolean = false) = openPreference(
* @return a SharedPreference
*/
private fun Context.openPreference(): SharedPreferences =
getSharedPreferences("MainPreference", AppCompatActivity.MODE_ENABLE_WRITE_AHEAD_LOGGING)


getSharedPreferences("MainPreference", Activity.MODE_APPEND)

0 comments on commit 77cb43e

Please sign in to comment.