Skip to content

Commit

Permalink
release 3.4
Browse files Browse the repository at this point in the history
targetSdkVersion升至API 28
迁移至AndroidX
增加国际化支持
  • Loading branch information
Cryolitia committed Dec 6, 2019
1 parent cf9db38 commit 6cac746
Show file tree
Hide file tree
Showing 16 changed files with 380 additions and 111 deletions.
19 changes: 10 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ android {
storePassword KEY_PASSWORD
}
}
compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
applicationId "tech.lincaiqi.PhotoTimeFix"
minSdkVersion 19
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 21
versionCode 12
versionName '3.3'
targetSdkVersion 28
versionCode 13
versionName '3.4'
resConfigs "zh", "zh-rCN"
}
buildTypes {
Expand All @@ -40,13 +40,14 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50'
implementation 'org.jetbrains.anko:anko-common:0.10.8'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:design:28.0.0'
def libsuVersion = '2.2.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
def libsuVersion = '2.5.0'
implementation "com.github.topjohnwu.libsu:core:${libsuVersion}"
/* Optional: For including a prebuild busybox */
implementation "com.github.topjohnwu.libsu:busybox:${libsuVersion}"
implementation "com.android.support:exifinterface:28.0.0"
implementation 'androidx.exifinterface:exifinterface:1.1.0'
implementation "androidx.versionedparcelable:versionedparcelable:1.1.0"
}
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:name="com.topjohnwu.superuser.ContainerApp"
android:allowBackup="false"
android:icon="@drawable/icon"
android:label="@string/app_name"
Expand Down
112 changes: 67 additions & 45 deletions app/src/main/java/photoTimeFix/CoreK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import android.net.Uri
import android.os.Environment
import android.os.Looper
import android.provider.MediaStore
import android.support.customtabs.CustomTabsIntent
import android.support.design.widget.AppBarLayout
import android.support.media.ExifInterface
import android.support.v4.app.Fragment
import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog
import androidx.browser.customtabs.CustomTabsIntent
import com.google.android.material.appbar.AppBarLayout
import androidx.exifinterface.media.ExifInterface
import androidx.fragment.app.Fragment
import androidx.core.content.ContextCompat
import androidx.appcompat.app.AlertDialog
import android.text.InputType
import android.util.Log
import android.view.LayoutInflater
Expand All @@ -45,7 +45,7 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
fun initFragment(preferences: SharedPreferences, editor: SharedPreferences.Editor, chooseBtn: Button, radioGroup: RadioGroup, fragment: Fragment, isFolder : Boolean) {
radioGroup.check(preferences.getInt("mode", R.id.radioButton))
chooseBtn.setOnClickListener {
if (isFolder) context.longToast("由于系统限制(其实是我懒),请选择文件夹内任意一张图片")
if (isFolder) context.longToast(context.getString(R.string.systemLimit))
chooseFile(fragment)
}
radioGroup.setOnCheckedChangeListener { _, i ->
Expand All @@ -67,10 +67,10 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
webView.addJavascriptInterface(this, "openGit")
builder.setView(webView)
} catch (e: Exception) {
builder.setMessage("加载WebView错误,已停止显示帮助窗口。\n该错误并不影响正常功能运行,且开发者仅在模拟器上遇到过,如果出现此对话框请与开发者联系。")
builder.setMessage(context.getString(R.string.webviewError))
e.printStackTrace()
}
builder.setPositiveButton("确定", null)
builder.setPositiveButton(context.getString(R.string.OK), null)
builder.show()
}

Expand All @@ -96,7 +96,7 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
intent.data = Uri.parse("coolmarket://u/$user")
context.startActivity(intent)
} catch (e: Exception) {
context.longToast("未安装酷安")
context.longToast(context.getString(R.string.notInstallCoolapk))
e.printStackTrace()
}

Expand Down Expand Up @@ -182,7 +182,7 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
val file = File(path)
val paths: Array<String?>
if (!file.exists()) {
context.toast("文件或目录不存在")
context.toast(context.getString(R.string.fileNotExistence))
return
}
if (file.isFile) {
Expand All @@ -196,17 +196,17 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
}
Log.d("path", paths.toString())
MediaScannerConnection.scanFile(context, paths, null) { _, _ -> }
context.toast("完成")
context.toast(R.string.finish)
}

@JavascriptInterface
fun updateDelay() {
val et = EditText(context)
et.inputType = InputType.TYPE_CLASS_NUMBER
var input: Int
AlertDialog.Builder(context).setTitle("设置延时")
AlertDialog.Builder(context).setTitle(R.string.setDelay)
.setView(et)
.setPositiveButton("确定") { _, _ ->
.setPositiveButton(R.string.OK) { _, _ ->
input = et.text.toString().toInt()
editor.putInt("delay", input)
editor.apply()
Expand Down Expand Up @@ -246,13 +246,13 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
val defaultComponentName = ComponentName(activity!!.baseContext,"photoTimeFix.MainActivity")
val newComponentName = ComponentName(activity!!.baseContext,"photoTimeFix.newIcon")
val packageManager = activity!!.packageManager
AlertDialog.Builder(context).setTitle("切换图标")
.setMessage("确定以使用新版,取消使用旧版")
.setPositiveButton("确定") { _, _ ->
AlertDialog.Builder(context).setTitle(R.string.switchIcon)
.setMessage(R.string.okToUseNew)
.setPositiveButton(R.string.OK) { _, _ ->
packageManager.setComponentEnabledSetting(defaultComponentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)
packageManager.setComponentEnabledSetting(newComponentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP)
}
.setNegativeButton("取消") {_, _ ->
.setNegativeButton(R.string.cancel) {_, _ ->
packageManager.setComponentEnabledSetting(newComponentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)
packageManager.setComponentEnabledSetting(defaultComponentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP)
}
Expand All @@ -262,9 +262,9 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
fun test(){
val tV = TextView(context)
tV.setBackgroundColor(Color.parseColor("#efefef"))
tV.text = "正在运行兼容性测试..."
tV.text = context.getString(R.string.runningTest)
val ad = AlertDialog.Builder(context)
.setTitle("兼容性测试")
.setTitle(R.string.test)
.setView(tV)
.setCancelable(false)
.show()
Expand All @@ -273,55 +273,55 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.

private fun runTest(tv : TextView, ad : AlertDialog) {
TV=tv
printTest("\n正在创建测试文件(/sdcard/CompatibilityTestFile)...")
printTest(R.string.creatingFile)
val file = File(Environment.getExternalStorageDirectory().path,"CompatibilityTestFile")
try {
file.createNewFile()
} catch (e : Exception) {
e.printStackTrace()
printTest("失败\n$e")
printTest(context.getString(R.string.fault) + e)
return
}
printTest("成功")
printTest("\n开始执行 模式一:Java 可用性检查...")
printTest(R.string.success)
printTest(R.string.startMode1)
val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
val targetTime = sdf.parse("2002-07-19 05:21:00").time
val targetTime = sdf.parse("2004-09-04 05:21:00").time
if (file.setLastModified(targetTime)) {
printTest("\n命令执行成功...检查执行结果\n")
printTest(R.string.checkResult)
val dateResult : String = sdf.format(Date(file.lastModified()))
printTest(dateResult)
if (dateResult == "2002-07-19 05:21:00") printTest("\n检查完毕...模式一:Java 完全可用")
else printTest("\n系统返回执行成功却未生效")
file.setLastModified(sdf.parse("2002-09-28 00:00:00").time)
} else printTest("\n命令执行失败,模式一:Java 不可用,请与作者联系以获得帮助")
printTest("\n开始执行 模式二:Shell 可用性检查...正在检查root权限")
if (dateResult == "2002-07-19 05:21:00") printTest(R.string.checkMode1Finish)
else printTest(R.string.returnButCannotUse)
file.setLastModified(sdf.parse("2004-09-04 00:00:00").time)
} else printTest(R.string.checkMode1Fault)
printTest(R.string.startCheckMode2)
if (Shell.rootAccess()) {
printTest("\n已获取root权限...检查touch命令\ntouch --help\n")
printTest(R.string.checkTouch)
val result : Shell.Result = Shell.su("touch --help").exec()
printTest(result.out.toString())
if (result.isSuccess) {
printTest("\n发现touch命令...检查可用性\ntouch /sdcard/CompatibilityTestFile -t 200207190521\n")
val result2 : Shell.Result = Shell.su("touch /sdcard/CompatibilityTestFile -t 200207190521").exec()
printTest(R.string.findTouch)
val result2 : Shell.Result = Shell.su("touch /sdcard/CompatibilityTestFile -t 200409040521").exec()
printTest(result2.out.toString())
if (result2.isSuccess) {
printTest("\n命令执行成功...检查执行结果\n")
printTest(R.string.checkResult)
val dateResult : String = sdf.format(Date(file.lastModified()))
printTest(dateResult)
if (dateResult == "2002-07-19 05:21:00") printTest("\n检查完毕...模式二:Shell 完全可用")
else printTest("\n系统返回执行成功却未生效")
} else printTest("\n命令执行失败,请与作者联系以获得帮助")
} else printTest("\ntouch命令不存在,请自行安装Busybox或与作者联系以获得帮助")
} else printTest("获取root权限失败,模式二:Shell 不可用")
printTest("\n正在清理测试文件(/sdcard/CompatibilityTestFile)...")
if (dateResult == "2004-09-04 05:21:00") printTest(R.string.checkMode2Finish)
else printTest(R.string.returnButCannotUse)
} else printTest(R.string.checkMode2Fault)
} else printTest(R.string.cannotFindTouch)
} else printTest(R.string.getRootFault)
printTest(R.string.cleaning)
try {
file.delete()
} catch (e : Exception) {
e.printStackTrace()
printTest("失败\n$e")
printTest(context.getString(R.string.fault) + e)
return
}
activity!!.runOnUiThread {
tv.text = tv.text.toString() + "完成"
tv.text = tv.text.toString() + context.getString(R.string.finish)
ad.setCancelable(true)
}
}
Expand All @@ -332,14 +332,36 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
}
}

private fun println (){
printTest("\n")
}

private fun printTest(int : Int) {
val string = context.getString(int)
var newString : String=""
for ((index,char) in string.withIndex()) {
if (char=='\\'&&string[index+1]=='n') {
printTest(newString)
newString=""
println()
} else{
if (char=='n'&&newString == "") {
} else {
newString += char;
}
}
}
printTest(newString)
}

fun experimentalFunction() {
val view = LayoutInflater.from(context).inflate(R.layout.experimental_function, null)
val switch: Switch = view.findViewById(R.id.switch1)
switch.isChecked = sharedPreferences!!.getBoolean("useEXIF",false)
view.findViewById<Button>(R.id.switchIconButton).setOnClickListener { switchIcon() }
AlertDialog.Builder(context).setTitle("实验性功能")
AlertDialog.Builder(context).setTitle(R.string.experimentalFunction)
.setView(view)
.setPositiveButton("确定") {_,_->
.setPositiveButton(R.string.okToUseNew) {_,_->
editor.putBoolean("useEXIF",switch.isChecked)
editor.apply()
}.show()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/photoTimeFix/Fragment1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.os.Environment
import android.support.v4.app.Fragment
import androidx.fragment.app.Fragment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -68,7 +68,7 @@ class Fragment1 : Fragment() {
locateTv.setText(path)
editor.putString("locate", path)
editor.apply()
} else context!!.longToast("选择出错,请手动填写路径并联系开发者")
} else context!!.longToast(getString(R.string.selectError))
}

override fun setUserVisibleHint(isVisibleToUser: Boolean) {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/photoTimeFix/Fragment2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.support.v4.app.Fragment
import androidx.fragment.app.Fragment
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
Expand Down Expand Up @@ -114,11 +114,11 @@ class Fragment2 : Fragment() {
val returnEXIF = coreK.readEXIF(locateTv.text.toString())
val builder = AlertDialog.Builder(context)
builder.setMessage(returnEXIF.strings.joinToString(separator = "\n"))
if (returnEXIF.dateExist) builder.setPositiveButton("使用EXIF时间") { _, _ ->
if (returnEXIF.dateExist) builder.setPositiveButton(getString(R.string.usingEXIF)) { _, _ ->
choseDateEdit.setText(returnEXIF.dateString)
}
else builder.setPositiveButton("确定",null)
builder.setNegativeButton("取消",null)
else builder.setPositiveButton(getString(R.string.OK),null)
builder.setNegativeButton(getString(R.string.cancel),null)
builder.show()
}

Expand Down Expand Up @@ -152,7 +152,7 @@ class Fragment2 : Fragment() {
editor.putString("locate", path)
editor.apply()
} else {
context!!.longToast("选择出错,请手动填写路径并联系开发者")
context!!.longToast(getString(R.string.selectError))
freshBtn.isEnabled = false
exifBtn.isEnabled = false
startBtn.isEnabled = false
Expand Down
Loading

0 comments on commit 6cac746

Please sign in to comment.