This commit is contained in:
lunaticbum 2023-03-27 18:43:46 +09:00
parent 389182c38a
commit 2d00a605e0
18 changed files with 719 additions and 332 deletions

View File

@ -1 +1,4 @@
# tokkiz # tokkiz
resource from : https://www.flaticon.com/search/2?word=rotate&color=black&shape=fill

View File

@ -1,5 +1,6 @@
package com.mime.dualscreenview.activity package com.mime.dualscreenview.activity
import android.content.res.Configuration
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.os.Message import android.os.Message
@ -18,6 +19,12 @@ import android.view.KeyEvent.KEYCODE_VOLUME_UP
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.mime.dualscreenview.common.Blog import com.mime.dualscreenview.common.Blog
import com.mime.dualscreenview.dto.HistoryItem
import com.mime.dualscreenview.dto.LastInfo
import io.realm.kotlin.Realm
import io.realm.kotlin.RealmConfiguration
import io.realm.kotlin.types.BaseRealmObject
import kotlin.reflect.KClass
open class Base : AppCompatActivity() { open class Base : AppCompatActivity() {
@ -26,18 +33,6 @@ open class Base : AppCompatActivity() {
override fun handleMessage(msg: Message) { override fun handleMessage(msg: Message) {
super.handleMessage(msg) super.handleMessage(msg)
} }
//
// override fun dispatchMessage(msg: Message) {
// super.dispatchMessage(msg)
// }
//
// override fun getMessageName(message: Message): String {
// return super.getMessageName(message)
// }
//
// override fun sendMessageAtTime(msg: Message, uptimeMillis: Long): Boolean {
// return super.sendMessageAtTime(msg, uptimeMillis)
// }
} }
val baseHandler = BaseHandler() val baseHandler = BaseHandler()
var didBackPress = false var didBackPress = false
@ -131,5 +126,12 @@ open class Base : AppCompatActivity() {
return false return false
} }
fun openRealm() : Realm {
val clazz : Set<KClass<out BaseRealmObject>> = setOf(LastInfo::class, HistoryItem::class)
val config = RealmConfiguration.Builder(clazz)
.schemaVersion(1)
.build()
return Realm.open(config)
}
} }

View File

@ -6,8 +6,8 @@ import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Color
import android.hardware.display.DisplayManager import android.hardware.display.DisplayManager
import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
@ -16,21 +16,21 @@ import android.view.View
import android.view.View.* import android.view.View.*
import android.webkit.WebView import android.webkit.WebView
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.LinearLayout
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatButton import androidx.appcompat.widget.AppCompatButton
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.updateLayoutParams
import com.google.gson.Gson import com.google.gson.Gson
import com.lge.display.DisplayManagerHelper import com.lge.display.DisplayManagerHelper
import com.mime.dualscreenview.R import com.mime.dualscreenview.R
import com.mime.dualscreenview.common.Blog import com.mime.dualscreenview.common.Blog
import com.mime.dualscreenview.dialog.StyleSelectInterface
import com.mime.dualscreenview.dialog.Stylez
import com.mime.dualscreenview.dto.BookPageInfo
import com.mime.dualscreenview.dto.BookPageInfos import com.mime.dualscreenview.dto.BookPageInfos
import com.mime.dualscreenview.dto.HistoryItem
import com.mime.dualscreenview.dto.LastInfo import com.mime.dualscreenview.dto.LastInfo
import com.mime.dualscreenview.view.PagedTextLayout import com.mime.dualscreenview.view.PagedTextLayout
import com.mime.dualscreenview.view.PagedTextViewInterface import com.mime.dualscreenview.view.PagedTextViewInterface
@ -41,8 +41,13 @@ import com.mime.dualscreenview.webcontents.contentsinfo.Booktoki
import com.mime.dualscreenview.webcontents.contentsinfo.GotoSomeWhere import com.mime.dualscreenview.webcontents.contentsinfo.GotoSomeWhere
import io.realm.kotlin.Realm import io.realm.kotlin.Realm
import io.realm.kotlin.RealmConfiguration import io.realm.kotlin.RealmConfiguration
import io.realm.kotlin.UpdatePolicy
import io.realm.kotlin.ext.copyFromRealm import io.realm.kotlin.ext.copyFromRealm
import io.realm.kotlin.ext.query import io.realm.kotlin.ext.query
import java.lang.System.currentTimeMillis
import java.net.URI
import java.text.SimpleDateFormat
import java.util.Date
class Intro : Base() , MainControllInterface, PagedTextViewInterface { class Intro : Base() , MainControllInterface, PagedTextViewInterface {
@ -60,18 +65,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
private lateinit var mBaseWebContentsViewer : BaseWebContentsViewer private lateinit var mBaseWebContentsViewer : BaseWebContentsViewer
var lastInfo : LastInfo? = null var lastInfo : LastInfo? = null
val colors = arrayOf<Array<String>>(
arrayOf<String>("#E1F5FE", "#263238"),
arrayOf<String>("#F0F4C3", "#37474F"),
arrayOf<String>("#ECEFF1", "#455A64"),
arrayOf<String>("#E0F7FA", "#263238"),
arrayOf<String>("#F5F5F5", "#263238"),
arrayOf<String>("#ECEFF1", "#263238"),
arrayOf<String>("#F8BBD0", "#263238"),
arrayOf<String>("#E6EE9C", "#455A64"),
arrayOf<String>("#CFD8DC", "#455A64"),
arrayOf<String>("#FFF59D", "#37474F")
)
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
@ -80,10 +74,9 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
Blog.LOGD(log= "onCreate ${this::class.java.name} >> savedInstanceState ${savedInstanceState}") Blog.LOGD(log= "onCreate ${this::class.java.name} >> savedInstanceState ${savedInstanceState}")
setContentView(R.layout.intro) setContentView(R.layout.intro)
mBaseWebContentsViewer = BaseWebContentsViewer(findViewById<WebView>(R.id.menu_web),this) mBaseWebContentsViewer = BaseWebContentsViewer(findViewById<WebView>(R.id.menu_web),this)
try { try {
// Try to construct the DisplayMangerHelper. // Try to construct the DisplayMangerHelper.
@ -106,8 +99,15 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
findViewById<ImageButton>(R.id.btn_list).setOnClickListener { v -> findViewById<ImageButton>(R.id.btn_list).setOnClickListener { v ->
mBaseWebContentsViewer?.findListItem {result -> mBaseWebContentsViewer?.findListItem {result ->
var infos = Gson().fromJson(result, BookPageInfos::class.java) if (result != null && "null".equals(result) == false && result?.length ?: 0 > 10) {
showList(infos) try {
Gson().fromJson(result, BookPageInfos::class.java)?.let{
showList(it)
}
} catch (e : Exception) {
}
}
} }
} }
@ -117,32 +117,46 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
findViewById<View>(R.id.btn_setting).setOnClickListener { v-> findViewById<View>(R.id.btn_setting).setOnClickListener { v->
showStyleList() showStyleList()
} }
findViewById<View>(R.id.btn_home).setOnClickListener { v-> findViewById<View>(R.id.btn_history).setOnClickListener { v->
mBaseWebContentsViewer.loadContents(Booktoki()) var realm = openRealm()
realm.query<HistoryItem>()?.find()?.let {
showHistory(realm.copyFromRealm(it))
} }
val config = RealmConfiguration.Builder(setOf(LastInfo::class)).schemaVersion(1)
.build()
val realm = Realm.open(config)
try {
lastInfo = realm?.query<LastInfo>()?.find()?.last()?.copyFromRealm()
} catch (e : Exception) {
}
if (lastInfo != null) {
setRequestedOrientation(lastInfo!!.displayOrientation);
mBaseWebContentsViewer.loadLastInfo(lastInfo!!)
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mBaseWebContentsViewer.loadContents(Booktoki())
}
Blog.LOGD(log ="Successfully opened realm: ${realm.configuration.name}")
realm.close() realm.close()
} }
findViewById<View>(R.id.btn_home).setOnClickListener { v->
pagedTextLayout?.visibility = GONE
mBaseWebContentsViewer.loadContents(Booktoki())
}
}
fun reloadLastInfo() {
val realm = openRealm()
try { lastInfo = realm?.query<LastInfo>()?.find()?.last()?.copyFromRealm() } catch (e : Exception) { }
val configuration: Configuration = getResources().getConfiguration()
if(lastInfo != null && lastInfo?.displayOrientation != configuration.orientation) {
findViewById<View>(R.id.btn_rotate).performClick()
}
realm.close()
}
fun reloadTo(lastInfo: LastInfo?) {
findViewById<WebView>(R.id.menu_web)?.postDelayed({
if (lastInfo != null) {
mBaseWebContentsViewer.loadLastInfo(lastInfo!!)
} else {
mBaseWebContentsViewer.loadContents(Booktoki())
}
},200L)
}
override fun onResume() {
super.onResume()
reloadLastInfo()
reloadTo(lastInfo)
}
fun switcvhOrient(){ fun switcvhOrient(){
val windowManager = getSystemService(WINDOW_SERVICE)
val configuration: Configuration = getResources().getConfiguration() val configuration: Configuration = getResources().getConfiguration()
setRequestedOrientation( setRequestedOrientation(
if(configuration.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE } if(configuration.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE }
@ -150,9 +164,65 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
) )
} }
fun showHistory(infos: List<HistoryItem>) {
val builderSingle: AlertDialog.Builder = AlertDialog.Builder(this@Intro)
builderSingle.setTitle("${currentTitle} : ${currentChapter} -> Select One ")
val arrayAdapter =
ArrayAdapter<String>(this@Intro, android.R.layout.select_dialog_singlechoice)
for (item in infos) {
arrayAdapter.addAll(item.title)
}
builderSingle.setNegativeButton("cancel",
DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() })
builderSingle.setAdapter(arrayAdapter,
DialogInterface.OnClickListener { dialog, which ->
val strName = arrayAdapter.getItem(which)
val item = infos.get(which)
val builderInner: AlertDialog.Builder = AlertDialog.Builder(this@Intro)
builderInner.setMessage(strName)
builderInner.setTitle("${infos.get(which).title}로 이동 고고!?")
builderInner.setPositiveButton("Ok",
DialogInterface.OnClickListener {
dialog, which ->
reloadTo(item.makeLastInfo())
dialog.dismiss()
})
builderInner.setNeutralButton("삭제",
DialogInterface.OnClickListener {
dialog, which ->
var realm = openRealm()
realm?.writeBlocking {
this.query<HistoryItem>().query("title == '${item.title}'", ).find()?.last()?.let{
this.delete(it)
}
}
realm.close()
dialog.dismiss()
})
builderInner.setNegativeButton("취소",
DialogInterface.OnClickListener {
dialog, which ->
dialog.dismiss()
})
builderInner.show()
})
var ddddd= builderSingle.create()
ddddd.setOnShowListener { d->
(d as? AlertDialog)?.let{
it.listView?.setSelection(currentChapter)
}
}
ddddd.show()
}
fun showList(infos: BookPageInfos) { fun showList(infos: BookPageInfos) {
val builderSingle: AlertDialog.Builder = AlertDialog.Builder(this@Intro) val builderSingle: AlertDialog.Builder = AlertDialog.Builder(this@Intro)
builderSingle.setTitle("Select One Name:-") builderSingle.setTitle("${currentTitle} : ${currentChapter} -> Select One ")
val arrayAdapter = val arrayAdapter =
ArrayAdapter<String>(this@Intro, android.R.layout.select_dialog_singlechoice) ArrayAdapter<String>(this@Intro, android.R.layout.select_dialog_singlechoice)
arrayAdapter.addAll(infos.getTitleArray()) arrayAdapter.addAll(infos.getTitleArray())
@ -164,60 +234,51 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
builderSingle.setAdapter(arrayAdapter, builderSingle.setAdapter(arrayAdapter,
DialogInterface.OnClickListener { dialog, which -> DialogInterface.OnClickListener { dialog, which ->
val strName = arrayAdapter.getItem(which) val strName = arrayAdapter.getItem(which)
val item = infos.list?.get(which)
val builderInner: AlertDialog.Builder = AlertDialog.Builder(this@Intro) val builderInner: AlertDialog.Builder = AlertDialog.Builder(this@Intro)
builderInner.setMessage(strName) builderInner.setMessage(strName)
builderInner.setTitle("Your Selected Item is") builderInner.setTitle("Your Selected Item is")
builderInner.setPositiveButton("Ok", builderInner.setPositiveButton("Ok",
DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() }) DialogInterface.OnClickListener { dialog, which ->
// mBaseWebContentsViewer?.webview?.loadUrl()
moveTo(item)
dialog.dismiss()
}
)
builderInner.show() builderInner.show()
}) })
var ddddd= builderSingle.create() var ddddd= builderSingle.create()
ddddd.setOnShowListener { d-> ddddd.setOnShowListener { d->
(d as? AlertDialog)?.let{ (d as? AlertDialog)?.let{
it.listView?.smoothScrollToPosition(currentChapter) it.listView?.setSelection(currentChapter)
} }
} }
ddddd.show() ddddd.show()
} }
private fun moveTo(item: BookPageInfo?) {
item?.link?.let {newPath ->
mBaseWebContentsViewer?.webview?.url?.let{currentUrl ->
Uri.parse(currentUrl)?.lastPathSegment?.let {
currentUrl.replace(it,newPath)?.let {
mBaseWebContentsViewer?.webview?.loadUrl(it)
}
}
}
}
}
fun showStyleList() { fun showStyleList() {
val builderSingle: AlertDialog.Builder = AlertDialog.Builder(this@Intro) var mStylez = Stylez(this@Intro)
builderSingle.setTitle("Select One Name:-") mStylez.styleSelectInterface = object : StyleSelectInterface {
val arrayAdapter = override fun onSelectStyle(bgColor: String, textColor: String) {
ArrayAdapter<String>(this@Intro, android.R.layout.select_dialog_singlechoice) pagedTextLayout?.setColorStyle(arrayOf(textColor,bgColor))
var styleNum = 1;
for (a in colors) {
arrayAdapter.add("스타일 ${styleNum}")
styleNum = styleNum.inc()
}
builderSingle.setNegativeButton("cancel",
DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() })
builderSingle.setAdapter(arrayAdapter,
DialogInterface.OnClickListener { dialog, which ->
val color = colors.get(which)
val builderInner: AlertDialog.Builder = AlertDialog.Builder(this@Intro)
builderInner.setMessage("스타일 ${which + 1}")
builderInner.setTitle("Your Selected Item is")
builderInner.setPositiveButton("Ok",
DialogInterface.OnClickListener { dialog, which -> dialog.dismiss()
pg?.setColorStyle(color)
findViewById<View>(R.id.intro_bg).setBackgroundColor(Color.parseColor(color.get(1)))
})
builderInner.show()
})
var ddddd= builderSingle.create()
ddddd.setOnShowListener { d->
(d as? AlertDialog)?.let{
it.listView?.smoothScrollToPosition(currentChapter)
} }
} }
mStylez.show()
ddddd.show()
} }
@ -339,7 +400,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
} }
} }
} }
var pg : PagedTextLayout? = null; var pagedTextLayout : PagedTextLayout? = null;
var onNextClickAction: GotoSomeWhere? = null var onNextClickAction: GotoSomeWhere? = null
override fun showNextBtn(find : Boolean , onClickAction: GotoSomeWhere) { override fun showNextBtn(find : Boolean , onClickAction: GotoSomeWhere) {
@ -354,9 +415,9 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
} }
fun actionNextEvent() { fun actionNextEvent() {
if (pg != null && pg!!.visibility == View.VISIBLE && pg!!.size() > 0 && (pg!!.current() < pg!!.size() - 1) ) { if (pagedTextLayout != null && pagedTextLayout!!.visibility == View.VISIBLE && pagedTextLayout!!.size() > 0 && (pagedTextLayout!!.current() < pagedTextLayout!!.size() - 1) ) {
pg!!.doNext() pagedTextLayout!!.doNext()
updateLastInfo(pg!!) updateLastInfo(pagedTextLayout!!)
}else { }else {
onNextClickAction?.let { it() } onNextClickAction?.let { it() }
} }
@ -375,9 +436,9 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
fun actionPrevEvent() { fun actionPrevEvent() {
if (pg != null && pg!!.visibility == View.VISIBLE && pg!!.size() > 0 && pg!!.current() > 0 ) { if (pagedTextLayout != null && pagedTextLayout!!.visibility == View.VISIBLE && pagedTextLayout!!.size() > 0 && pagedTextLayout!!.current() > 0 ) {
pg!!.doPrev() pagedTextLayout!!.doPrev()
updateLastInfo(pg!!) updateLastInfo(pagedTextLayout!!)
} else { } else {
onPrevClickAction?.let{ it() } onPrevClickAction?.let{ it() }
} }
@ -407,10 +468,8 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
firstBackPress() firstBackPress()
return return
} }
finish()
didBackPress = false didBackPress = false
super.onBackPressed()
} }
@ -419,19 +478,19 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
} }
override fun onLoadedContents(contents: String) { override fun onLoadedContents(contents: String) {
pg = null; pagedTextLayout = null;
findViewById<PagedTextLayout>(R.id.paged_layer).apply { findViewById<PagedTextLayout>(R.id.paged_layer).apply {
if (contents != null) { if (contents != null) {
pg = this pagedTextLayout = this
visibility = VISIBLE visibility = VISIBLE
mPagedTextViewInterface = this@Intro mPagedTextViewInterface = this@Intro
setText(contents.replace("\\n", System.getProperty("line.separator"))) setText(contents.replace("\\n", System.getProperty("line.separator")))
setTextSize(22f) setTextSize(22f)
if(lastInfo != null && lastInfo!!.pageUrl.equals(mBaseWebContentsViewer.webview.url)) { if(lastInfo != null && lastInfo!!.pageUrl.equals(mBaseWebContentsViewer.webview.url)) {
this@Intro.findViewById<ProgressBar>(R.id.progress)?.visibility = VISIBLE this@Intro.findViewById<ProgressBar>(R.id.progress)?.visibility = VISIBLE
pg?.postDelayed({ pagedTextLayout?.postDelayed({
next(lastInfo!!.pageIndex) next(lastInfo!!.pageIndex)
pg?.post { pagedTextLayout?.post {
this@Intro.findViewById<ProgressBar>(R.id.progress)?.visibility = GONE this@Intro.findViewById<ProgressBar>(R.id.progress)?.visibility = GONE
} }
},1000) },1000)
@ -452,9 +511,20 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
Blog.LOGI(TAG,"onFindTitle >> " + contents + " ::: ${testRegex.replace(contents,"")}") Blog.LOGI(TAG,"onFindTitle >> " + contents + " ::: ${testRegex.replace(contents,"")}")
if(contents.contains("-")) { if(contents.contains("-")) {
currentTitle = contents.split("-")[0] currentTitle = contents.split("-")[0]
try {
currentChapter = testRegex.replace(contents.split("-")[1],"").toInt() currentChapter = testRegex.replace(contents.split("-")[1],"").toInt()
} catch (e : Exception) {
currentChapter = 0
}
} else if(testRegex.replace(contents,"").length > 0){
currentChapter = testRegex.replace(contents,"").toInt()
currentTitle = contents.split(testRegex.replace(contents,""))[0]
} else {
val dateFormat = "yyyyMMdd-HH"
val date = Date(currentTimeMillis())
val simpleDateFormat = SimpleDateFormat(dateFormat)
currentTitle = simpleDateFormat.format(date)
} }
} }
@ -463,39 +533,54 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
} }
override fun completePageLoad(lastInfo: LastInfo) { override fun completePageLoad(lastInfo: LastInfo) {
if(this.lastInfo == null || !(this.lastInfo?.pageUrl.equals(lastInfo?.pageUrl))) { val configuration: Configuration = getResources().getConfiguration()
if(this.lastInfo == null || !(this.lastInfo?.pageUrl.equals(lastInfo?.pageUrl)) || this.lastInfo?.displayOrientation != configuration?.orientation) {
lastInfo.displayOrientation = configuration?.orientation ?: ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
saveLastInfo(lastInfo) saveLastInfo(lastInfo)
} }
findViewById<ProgressBar>(R.id.progress).visibility = GONE findViewById<ProgressBar>(R.id.progress).visibility = GONE
} }
fun saveLastInfo(lastInfo: LastInfo) { fun saveLastInfo(lastInfo: LastInfo) {
val windowManager = getSystemService(WINDOW_SERVICE) val realm = openRealm()
val configuration: Configuration = getResources().getConfiguration() if((realm.query<LastInfo>()?.count()?.find() ?: 0) > 0) {
val config = RealmConfiguration.Builder(setOf(LastInfo::class)) realm.writeBlocking {
.schemaVersion(1) this.query<LastInfo>()?.find()?.last()?.let{
.build() it.pageUrl = lastInfo.pageUrl
val realm = Realm.open(config) it.title = currentTitle
it.chapter = currentChapter
it.pageIndex = lastInfo.pageIndex
it.contentsName = lastInfo.contentsName
it.displayOrientation = lastInfo.displayOrientation
this@Intro.lastInfo = copyFromRealm(it)
}
}
} else {
realm.writeBlocking { realm.writeBlocking {
lastInfo.displayOrientation = configuration.orientation
copyToRealm(lastInfo) copyToRealm(lastInfo)
} }
}
Blog.LOGD(log ="Successfully opened realm: ${realm.configuration.name}") Blog.LOGD(log ="Successfully opened realm: ${realm.configuration.name}")
realm.close() realm.close()
} }
fun updateLastInfo(pagedTextLayout: PagedTextLayout) { fun updateLastInfo(pagedTextLayout: PagedTextLayout) {
val windowManager = getSystemService(WINDOW_SERVICE)
val configuration: Configuration = getResources().getConfiguration() val configuration: Configuration = getResources().getConfiguration()
val config = RealmConfiguration.Builder(setOf(LastInfo::class)) val realm = openRealm()
.schemaVersion(1)
.build()
val realm = Realm.open(config)
realm.writeBlocking { realm.writeBlocking {
var info = this.query<LastInfo>()?.find()?.last() this.query<LastInfo>()?.find()?.last()?.let{
info?.pageIndex = pagedTextLayout.current() it.displayOrientation = configuration.orientation
info?.displayOrientation = configuration.orientation it.title = currentTitle
it.chapter = currentChapter
it.pageIndex = pagedTextLayout.current()
this@Intro.lastInfo = copyFromRealm(it)
}
if (currentTitle.length > 0 && currentChapter > 0) {
this@Intro.lastInfo?.makeHistoryItem()?.let{
copyToRealm(it, UpdatePolicy.ALL)
}
}
} }
Blog.LOGD(log ="Successfully opened realm: ${realm.configuration.name}") Blog.LOGD(log ="Successfully opened realm: ${realm.configuration.name}")
@ -522,7 +607,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
findViewById<View>(R.id.textView).visibility = VISIBLE findViewById<View>(R.id.textView).visibility = VISIBLE
findViewById<View>(R.id.btn_home).visibility = VISIBLE findViewById<View>(R.id.btn_home).visibility = VISIBLE
findViewById<View>(R.id.btn_list).visibility = VISIBLE findViewById<View>(R.id.btn_list).visibility = VISIBLE
findViewById<View>(R.id.btn_menu).visibility = VISIBLE findViewById<View>(R.id.btn_history).visibility = VISIBLE
findViewById<View>(R.id.btn_rotate).visibility = VISIBLE findViewById<View>(R.id.btn_rotate).visibility = VISIBLE
} }
@ -561,7 +646,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
findViewById<View>(R.id.textView).visibility = GONE findViewById<View>(R.id.textView).visibility = GONE
findViewById<View>(R.id.btn_home).visibility = GONE findViewById<View>(R.id.btn_home).visibility = GONE
findViewById<View>(R.id.btn_list).visibility = GONE findViewById<View>(R.id.btn_list).visibility = GONE
findViewById<View>(R.id.btn_menu).visibility = GONE findViewById<View>(R.id.btn_history).visibility = GONE
findViewById<View>(R.id.btn_rotate).visibility = GONE findViewById<View>(R.id.btn_rotate).visibility = GONE
} }

View File

@ -0,0 +1,15 @@
package com.mime.dualscreenview.common
val colorz = arrayOf<Array<String>>(
arrayOf<String>("#E1F5FE", "#263238"),
arrayOf<String>("#F0F4C3", "#37474F"),
arrayOf<String>("#ECEFF1", "#455A64"),
arrayOf<String>("#E0F7FA", "#263238"),
arrayOf<String>("#F5F5F5", "#263238"),
arrayOf<String>("#ECEFF1", "#263238"),
arrayOf<String>("#F8BBD0", "#263238"),
arrayOf<String>("#E6EE9C", "#455A64"),
arrayOf<String>("#CFD8DC", "#455A64"),
arrayOf<String>("#FFF59D", "#37474F")
)

View File

@ -0,0 +1,99 @@
package com.mime.dualscreenview.dialog
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.mime.dualscreenview.R
import com.mime.dualscreenview.common.colorz
import kotlin.random.Random
interface StyleSelectInterface {
fun onSelectStyle(bgColor : String, textColor : String)
}
class Stylez : Dialog {
constructor(context: Context) : super(context) {initView(context)}
constructor(context: Context, themeResId: Int) : super(context, themeResId) {initView(context)}
constructor(
context: Context,
cancelable: Boolean,
cancelListener: DialogInterface.OnCancelListener?
) : super(context, cancelable, cancelListener) {initView(context)}
var styleSelectInterface : StyleSelectInterface? = null
fun initView(context: Context) {
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setCancelable(true)
setContentView(R.layout.dialog_stylesz)
val recyclerView: RecyclerView = findViewById(R.id.stylez_recyclerview)
val adapterRe = AdapterRe(context, colorz)
recyclerView.adapter = adapterRe
recyclerView.layoutManager =
GridLayoutManager(context, 2, GridLayoutManager.VERTICAL, false)
}
inner class AdapterRe(ctx: Context, myImageNameList: Array<Array<String>>) :
RecyclerView.Adapter<StylezViewHolder>() {
private val inflater: LayoutInflater
private val myImageNameList: Array<Array<String>>
private val ctx : Context
init {
inflater = LayoutInflater.from(ctx)
this.ctx = ctx
this.myImageNameList = myImageNameList
}
override fun onCreateViewHolder (
parent: ViewGroup,
viewType: Int
): StylezViewHolder {
val view: View = inflater.inflate(R.layout.item_colorz, parent, false)
return StylezViewHolder(view)
}
override fun onBindViewHolder(holder: StylezViewHolder, position: Int) {
var colorz = myImageNameList.get(position)
var sampleTextz = ctx.resources.getStringArray(R.array.sample_textz)
holder?.setStyle(bgColor = colorz.get(1), textColor = colorz.get(0),sampleTextz.get(Random.nextInt(9876) % sampleTextz.size))
}
override fun getItemCount(): Int {
return myImageNameList.size
}
}
inner class StylezViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var textView: TextView
var bg : View
init {
textView = itemView.findViewById(R.id.textview_sample)
bg = itemView.findViewById(R.id.bg_sample)
}
fun setStyle(bgColor : String, textColor : String, sampleText : String ) {
bg.setBackgroundColor(Color.parseColor(bgColor))
textView.setTextColor(Color.parseColor(textColor))
textView.text = sampleText
itemView?.setOnClickListener { v ->
styleSelectInterface?.onSelectStyle(bgColor,textColor)
dismiss()
}
}
}
}

View File

@ -11,5 +11,5 @@ var list : ArrayList<BookPageInfo>? = null
} }
class BookPageInfo { class BookPageInfo {
var title : String? = "" var title : String? = ""
var lastPath : String? = "" var link : String? = ""
} }

View File

@ -7,15 +7,43 @@ import org.mongodb.kbson.ObjectId
class LastInfo() : RealmObject { class LastInfo() : RealmObject {
@PrimaryKey
var _id : String = "UniqLastId" var _id : String = "UniqLastId"
var pageUrl : String = "" var pageUrl : String = ""
var title : String = "" var title : String = ""
var contentsData : String = "" var chapter : Int = 0
var pageIndex : Int = 0 var pageIndex : Int = 0
var contentsName : String = "" var contentsName : String = ""
var displayOrientation : Int = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT var displayOrientation : Int = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
fun makeHistoryItem() : HistoryItem = HistoryItem().apply {
title = this@LastInfo.title
pageUrl = this@LastInfo.pageUrl
chapter = this@LastInfo.chapter
pageIndex = this@LastInfo.pageIndex
contentsName = this@LastInfo.contentsName
displayOrientation = this@LastInfo.displayOrientation
}
}
class HistoryItem() : RealmObject {
@PrimaryKey
var title : String = ""
var pageUrl : String = ""
var chapter : Int = 0
var pageIndex : Int = 0
var contentsName : String = ""
var displayOrientation : Int = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
fun makeLastInfo() = LastInfo().apply{
_id = "UniqLastId"
title = this@HistoryItem.title
pageUrl = this@HistoryItem.pageUrl
chapter = this@HistoryItem.chapter
pageIndex = this@HistoryItem.pageIndex
contentsName = this@HistoryItem.contentsName
displayOrientation = this@HistoryItem.displayOrientation
}
}
class Bookmark() : RealmObject { class Bookmark() : RealmObject {
@PrimaryKey @PrimaryKey
var pageUrl : String = "" var pageUrl : String = ""

View File

@ -66,8 +66,10 @@ class PagedTextLayout : ConstraintLayout , PagedTextGenerateInterface {
var isCenterTouch = TouchArea.Center.equals(touchArea) var isCenterTouch = TouchArea.Center.equals(touchArea)
hanler.removeCallbacks(touchTimeover) hanler.removeCallbacks(touchTimeover)
mPagedTextViewInterface?.onTouch(touchArea) mPagedTextViewInterface?.onTouch(touchArea)
if(isCenterTouch) {
hanler?.postDelayed(touchTimeover, 3000L) hanler?.postDelayed(touchTimeover, 3000L)
} }
}
}) })
} }

View File

@ -8,7 +8,7 @@ import com.mime.dualscreenview.webcontents.contentsinfo.DidFindContents
abstract class BaseWebContents : ContentsInfoInterface { abstract class BaseWebContents : ContentsInfoInterface {
var lastNumber : Int = 221 open var lastNumber : Int = 221
var completeAction : ActionByBool? = null var completeAction : ActionByBool? = null
val definedActionCount = 5 val definedActionCount = 5
var completeActionCount = 0 var completeActionCount = 0

View File

@ -143,7 +143,7 @@ open class BaseWebContentsViewer {
currentContentsProvider?.doOnloaded(it , { result -> currentContentsProvider?.doOnloaded(it , { result ->
result?.let { mainControllInterface.onLoadedContents(it) } result?.let { mainControllInterface.onLoadedContents(it) }
} , { } , {
it?.let { mainControllInterface.onFindTitle(it) } it?.let { mainControllInterface.onFindTitle(it.replace("\"","")) }
}, {btn -> }, {btn ->
mainControllInterface?.showNextBtn (btn != null){ mainControllInterface?.showNextBtn (btn != null){
webview?.evaluateJavascript("if(document.getElementById('${currentContentsProvider!!.getNextButtonJs()}') != null) document.getElementById('${currentContentsProvider!!.getNextButtonJs()}').click()") { webview?.evaluateJavascript("if(document.getElementById('${currentContentsProvider!!.getNextButtonJs()}') != null) document.getElementById('${currentContentsProvider!!.getNextButtonJs()}').click()") {

View File

@ -4,7 +4,7 @@ import com.mime.dualscreenview.webcontents.BaseWebContents
class Booktoki : BaseWebContents() { class Booktoki : BaseWebContents() {
override var lastNumber : Int = 222
override fun getWebcontentsName(): String { override fun getWebcontentsName(): String {
return "Booktoki" return "Booktoki"

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp"
android:layout_gravity="center"
android:layout_height="420dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/style_dialog_title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="0dp"
android:gravity="center"
android:layout_height="@dimen/main_top_height"/>
<androidx.recyclerview.widget.RecyclerView
app:layout_constraintTop_toBottomOf="@id/style_dialog_title"
android:id="@+id/stylez_recyclerview"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="0dp"
android:layout_height="0dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -80,18 +80,18 @@
android:background="#8FFF" android:background="#8FFF"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/btn_list" app:layout_constraintLeft_toRightOf="@id/btn_list"
app:layout_constraintRight_toLeftOf="@+id/btn_menu" app:layout_constraintRight_toLeftOf="@+id/btn_history"
app:layout_constraintHorizontal_chainStyle="spread_inside" app:layout_constraintHorizontal_chainStyle="spread_inside"
/> />
<ImageButton <ImageButton
android:id="@+id/btn_menu" android:id="@+id/btn_history"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="@dimen/main_top_height" android:layout_height="@dimen/main_top_height"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:scaleType="centerInside" android:scaleType="centerInside"
android:background="#8FFF" android:background="#8FFF"
android:src="@drawable/bookmark" android:src="@drawable/history"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_chainStyle="spread_inside" app:layout_constraintHorizontal_chainStyle="spread_inside"

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_margin="5dp"
android:id="@+id/bg_sample"
android:layout_height="140dp">
<TextView
android:gravity="center"
android:text=""
android:id="@+id/textview_sample"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,4 +2,70 @@
<string name="app_name">DualScreenView</string> <string name="app_name">DualScreenView</string>
<string name="display_the_second_screen">화면 옮 기 기</string> <string name="display_the_second_screen">화면 옮 기 기</string>
<string name="main_desc">it\'s 두번째화면</string> <string name="main_desc">it\'s 두번째화면</string>
<string-array name="sample_textz">
<item>여섯글자마다&#160;방점을찍어놔
가사관찰하다&#160;반쯤놓치거나
해석잘안되면&#160;몇번돌리든가
이건이를테면&#160;덤비는리듬과
손묶인채붙는&#160;일종의노름판</item>
<item>신도구제불능&#160;내가물오른밤
감방에날가둬&#160;내가패를까도
가난한니네가&#160;판돈잃지않게
나하고니네가&#160;의견일치한게
아마처음일걸&#160;그마저운일걸</item>
<item>존나좋음이퀄&#160;내중저음일걸
이배열어쩌면&#160;너에대한배려
너에겐어쩌면&#160;언어적배리어
그럼넌글렀어&#160;지망생여기에
잠들다글로써&#160;훗날니묘비에</item>
<item>For&#160;sale&#160;my&#160;rhymes&#160;never&#160;used
For&#160;sale&#160;my&#160;rhymes&#160;never&#160;used
판매자바로너&#160;니가씨발오너
For&#160;sale&#160;my&#160;rhymes&#160;never&#160;used</item>
<item>노예처럼일해서왕처럼지배
성탄처럼지내설탕뿌려위에
성공을말했기에난그길위에
선딱그어이젠자봐주의깊게</item>
<item>멈칫할시간도없는듯써내려
활자로활짝갠곳에돈비내려
초라한핀조명과낮은무대위
목표를조준하기에충분했지</item>
<item>시인의신이될준비는치밀해
흘러군침이계속이기기위해
처음시작했던이유따윈잊어</item>
<item>맨발맨손으로역사들을빚어
미안해난비션갖고와내기적
자음모음이어리듬위에띄어
금은보화이쁜걸로손에끼워</item>
<item>Uh&#160;she&#160;suckin\'&#160;my&#160;soul&#160;like
De&#160;La&#160;to&#160;the&#160;Soul
I&#160;shout&#160;out&#160;to&#160;the&#160;Rhonda
But&#160;before&#160;I\'m&#160;sober</item>
<item>변태는&#160;변태인데&#160;underground&#160;모범생
맨날&#160;&#160;오덕&#160;&#160;활자에&#160;꼬여
&#160;팔자도&#160;고쳐낼&#160;하나의&#160;초월체를
만들려&#160;고쳐댄&#160;rhyme들만&#160;&#160;truck&#160;</item>
<item>그러다&#160;깨어나&#160;여기에
빼어난&#160;묘기에&#160;없네&#160;기본기
&#160;눈엔&#160;수명이&#160;대본처럼&#160;읽히네
뭐처럼&#160;비치네&#160;뭐처럼&#160;비치네</item>
<item>Fuck&#160;all&#160;of&#160;ya&#160;list&#160;man
If&#160;it&#160;ain\'t&#160;Forbes&#160;list&#160;mayne
Your&#160;wristwatch&#160;cheaper&#160;than
My&#160;profile&#160;picture&#160;damn</item>
<item>Picture&#160;the&#160;future&#160;and
믿어&#160;like&#160;it\'s&#160;happend
Big&#160;ass&#160;house&#160;foreign&#160;cars&#160;have&#160;several</item>
<item>미녀&#160;fine&#160;ass&#160;apple&#160;hip&#160;&#160;옆에&#160;같이&#160;태우고
Top&#160;of&#160;the&#160;top으로&#160;&#160;죽어야&#160;들어&#160;잠은
&#160;&#160;죽었다는&#160;
갖은&#160;&#160;잡으면&#160;뭐하냐</item>
<item>좆밥들&#160;&#160;반년만&#160;가면&#160;
&#160;들어가는&#160;&#160;&#160;보여
&#160;눈엔&#160;너가&#160;금방&#160;죽어
다음&#160;무덤&#160;&#160;들어갈&#160;주검
&#160;우물&#160;파는&#160;&#160;밟고서
땅을&#160;쳐봐&#160;&#160;발자국을</item>
</string-array>
</resources> </resources>

269
gradlew vendored
View File

@ -1,7 +1,7 @@
#!/usr/bin/env sh #!/bin/sh
# #
# Copyright 2015 the original author or authors. # Copyright © 2015-2021 the original authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -17,67 +17,101 @@
# #
############################################################################## ##############################################################################
## #
## Gradle start up script for UN*X # Gradle start up script for POSIX generated by Gradle.
## #
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
############################################################################## ##############################################################################
# Attempt to set APP_HOME # Attempt to set APP_HOME
# Resolve links: $0 may be a link # Resolve links: $0 may be a link
PRG="$0" app_path=$0
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do # Need this for daisy-chained symlinks.
ls=`ls -ld "$PRG"` while
link=`expr "$ls" : '.*-> \(.*\)$'` APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
if expr "$link" : '/.*' > /dev/null; then [ -h "$app_path" ]
PRG="$link" do
else ls=$( ls -ld "$app_path" )
PRG=`dirname "$PRG"`"/$link" link=${ls#*' -> '}
fi case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle" APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"` APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum" MAX_FD=maximum
warn () { warn () {
echo "$*" echo "$*"
} } >&2
die () { die () {
echo echo
echo "$*" echo "$*"
echo echo
exit 1 exit 1
} } >&2
# OS specific support (must be 'true' or 'false'). # OS specific support (must be 'true' or 'false').
cygwin=false cygwin=false
msys=false msys=false
darwin=false darwin=false
nonstop=false nonstop=false
case "`uname`" in case "$( uname )" in #(
CYGWIN* ) CYGWIN* ) cygwin=true ;; #(
cygwin=true Darwin* ) darwin=true ;; #(
;; MSYS* | MINGW* ) msys=true ;; #(
Darwin* ) NONSTOP* ) nonstop=true ;;
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
if [ -n "$JAVA_HOME" ] ; then if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables # IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java" JAVACMD=$JAVA_HOME/jre/sh/java
else else
JAVACMD="$JAVA_HOME/bin/java" JAVACMD=$JAVA_HOME/bin/java
fi fi
if [ ! -x "$JAVACMD" ] ; then if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi fi
else else
JAVACMD="java" JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
@ -106,80 +140,95 @@ location of your Java installation."
fi fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
MAX_FD_LIMIT=`ulimit -H -n` case $MAX_FD in #(
if [ $? -eq 0 ] ; then max*)
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD=$( ulimit -H -n ) ||
MAX_FD="$MAX_FD_LIMIT" warn "Could not query maximum file descriptor limit"
fi esac
ulimit -n $MAX_FD case $MAX_FD in #(
if [ $? -ne 0 ] ; then '' | soft) :;; #(
warn "Could not set maximum file descriptor limit: $MAX_FD" *)
fi ulimit -n "$MAX_FD" ||
else warn "Could not set maximum file descriptor limit to $MAX_FD"
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
# Escape application args # Collect all arguments for the java command, stacking in reverse order:
save () { # * args from the command line
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done # * the main class name
echo " " # * -classpath
} # * -D...appname settings
APP_ARGS=`save "$@"` # * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# Collect all arguments for the java command, following the shell quoting and substitution rules # For Cygwin or MSYS, switch paths to Windows format before running java
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@" exec "$JAVACMD" "$@"