Skip to content

Commit

Permalink
release 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryolitia committed Mar 20, 2019
1 parent c369829 commit cf9db38
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 56 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
minSdkVersion 19
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 21
versionCode 11
versionName '3.2'
versionCode 12
versionName '3.3'
resConfigs "zh", "zh-rCN"
}
buildTypes {
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/assets/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ <h3><font color="#448AFF">处理格式</font></h3>
<p>&nbsp;</p>
<hr/>
<h4>调试工具</h4>
<p>该工具在旗舰机型上处理速度可达每秒千张左右,但总有部分用户反馈认为如此快的处理速度是工作不正常的表现,故增加此调试选项来设置处理时的延时,以期能带给用户更好的使用体验。该设置项并无任何意义,请尽量不要调整。单位:毫秒</p>
<p>该工具在旗舰机型上处理速度可高于每秒千张,因此有部分用户反馈认为如此快的处理速度是工作不正常的表现,故增加此调试选项来设置处理时的延时,以期能带给用户更好的使用体验。该设置项并无任何意义,如无必要请勿调整。单位:毫秒</p>
<input type="button" value="打开调整工具" onclick="openGit.updateDelay();">
<hr/>
<h4>切换图标</h4>
<p>使用新版图标,如切换后出现异常请卸载本应用并重新安装</p>
<input type="button" value="切换图标" onclick="openGit.switchIcon();">
</body>
</html>
118 changes: 101 additions & 17 deletions app/src/main/java/photoTimeFix/CoreK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package photoTimeFix

import android.annotation.SuppressLint
import android.app.Activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.*
import android.content.pm.PackageManager
import android.database.Cursor
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.media.MediaScannerConnection
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
Expand All @@ -26,10 +26,9 @@ import android.view.View
import android.webkit.JavascriptInterface
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.RadioGroup
import android.widget.*
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ShellUtils
import org.jetbrains.anko.longToast
import org.jetbrains.anko.toast
import tech.lincaiqi.PhotoTimeFix.R
Expand All @@ -38,14 +37,15 @@ import java.text.SimpleDateFormat
import java.util.*
import java.util.regex.Pattern

class CoreK(private var context: Context, private var editor: SharedPreferences.Editor, private var activity: Activity?) {
class CoreK(private var context: Context, private var editor: SharedPreferences.Editor, private var activity: Activity?, private var sharedPreferences: SharedPreferences?) {

val EXIF_TAGS: Array<String> = arrayOf(ExifInterface.TAG_MAKE, ExifInterface.TAG_MODEL, ExifInterface.TAG_IMAGE_WIDTH, ExifInterface.TAG_IMAGE_LENGTH, ExifInterface.TAG_SOFTWARE, ExifInterface.TAG_EXPOSURE_TIME, ExifInterface.TAG_F_NUMBER, ExifInterface.TAG_PHOTOGRAPHIC_SENSITIVITY, ExifInterface.TAG_DATETIME, ExifInterface.TAG_EXPOSURE_BIAS_VALUE, ExifInterface.TAG_METERING_MODE, ExifInterface.TAG_LIGHT_SOURCE, ExifInterface.TAG_FOCAL_LENGTH)
private val EXIF_TAGS: Array<String> = arrayOf(ExifInterface.TAG_MAKE, ExifInterface.TAG_MODEL, ExifInterface.TAG_IMAGE_WIDTH, ExifInterface.TAG_IMAGE_LENGTH, ExifInterface.TAG_SOFTWARE, ExifInterface.TAG_EXPOSURE_TIME, ExifInterface.TAG_F_NUMBER, ExifInterface.TAG_PHOTOGRAPHIC_SENSITIVITY, ExifInterface.TAG_DATETIME, ExifInterface.TAG_EXPOSURE_BIAS_VALUE, ExifInterface.TAG_METERING_MODE, ExifInterface.TAG_LIGHT_SOURCE, ExifInterface.TAG_FOCAL_LENGTH)
private lateinit var TV:TextView

fun initFragment(preferences: SharedPreferences, editor: SharedPreferences.Editor, chooseBtn: Button, radioGroup: RadioGroup, fragment: Fragment) {
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 {
context.longToast("由于系统限制(其实是我懒),请选择文件夹内任意一张图片")
if (isFolder) context.longToast("由于系统限制(其实是我懒),请选择文件夹内任意一张图片")
chooseFile(fragment)
}
radioGroup.setOnCheckedChangeListener { _, i ->
Expand All @@ -58,14 +58,14 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
fun showAbout() {
val builder = AlertDialog.Builder(context)
try {
val view = LayoutInflater.from(context).inflate(R.layout.about, null)
val webView: WebView = view.findViewById(R.id.webview)
//val view = LayoutInflater.from(context).inflate(R.layout.about, null)
val webView = WebView(context)
webView.webViewClient = WebViewClient()
webView.loadUrl("file:///android_asset/about.html")
webView.settings.javaScriptEnabled = true
webView.requestFocusFromTouch()
webView.addJavascriptInterface(this, "openGit")
builder.setView(view)
builder.setView(webView)
} catch (e: Exception) {
builder.setMessage("加载WebView错误,已停止显示帮助窗口。\n该错误并不影响正常功能运行,且开发者仅在模拟器上遇到过,如果出现此对话框请与开发者联系。")
e.printStackTrace()
Expand Down Expand Up @@ -242,7 +242,6 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
var dateString: String = ""
}

@JavascriptInterface
fun switchIcon() {
val defaultComponentName = ComponentName(activity!!.baseContext,"photoTimeFix.MainActivity")
val newComponentName = ComponentName(activity!!.baseContext,"photoTimeFix.newIcon")
Expand All @@ -260,6 +259,92 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
.show()
}

fun test(){
val tV = TextView(context)
tV.setBackgroundColor(Color.parseColor("#efefef"))
tV.text = "正在运行兼容性测试..."
val ad = AlertDialog.Builder(context)
.setTitle("兼容性测试")
.setView(tV)
.setCancelable(false)
.show()
Thread { runTest(tV,ad) }.start()
}

private fun runTest(tv : TextView, ad : AlertDialog) {
TV=tv
printTest("\n正在创建测试文件(/sdcard/CompatibilityTestFile)...")
val file = File(Environment.getExternalStorageDirectory().path,"CompatibilityTestFile")
try {
file.createNewFile()
} catch (e : Exception) {
e.printStackTrace()
printTest("失败\n$e")
return
}
printTest("成功")
printTest("\n开始执行 模式一:Java 可用性检查...")
val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
val targetTime = sdf.parse("2002-07-19 05:21:00").time
if (file.setLastModified(targetTime)) {
printTest("\n命令执行成功...检查执行结果\n")
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 (Shell.rootAccess()) {
printTest("\n已获取root权限...检查touch命令\ntouch --help\n")
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(result2.out.toString())
if (result2.isSuccess) {
printTest("\n命令执行成功...检查执行结果\n")
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)...")
try {
file.delete()
} catch (e : Exception) {
e.printStackTrace()
printTest("失败\n$e")
return
}
activity!!.runOnUiThread {
tv.text = tv.text.toString() + "完成"
ad.setCancelable(true)
}
}

private fun printTest(string : String) {
activity!!.runOnUiThread {
TV.text = TV.text.toString() + string
}
}

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("实验性功能")
.setView(view)
.setPositiveButton("确定") {_,_->
editor.putBoolean("useEXIF",switch.isChecked)
editor.apply()
}.show()
}

fun newReadDate(name: String): String {
val date: Array<Char?> = arrayOfNulls(12)
var point = 0
Expand Down Expand Up @@ -368,5 +453,4 @@ class CoreK(private var context: Context, private var editor: SharedPreferences.
}
return date.joinToString("")
}

}
12 changes: 6 additions & 6 deletions app/src/main/java/photoTimeFix/Fragment1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class Fragment1 : Fragment() {
val view = inflater.inflate(R.layout.fragment_1, parent, false)
preferences = activity!!.getPreferences(Context.MODE_PRIVATE)
editor = preferences.edit()
coreK = CoreK(context!!,editor,null)
coreK = CoreK(context!!,editor,null,null)
locateTv = view!!.findViewById(R.id.locateText)
locateText = view.findViewById<EditText>(R.id.locateText)
locateText.setText(preferences.getString("locate", Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera"))
locateText.setText(preferences.getString("locate", Environment.getExternalStorageDirectory().path + "/DCIM/Camera"))
chooseBtn = view.findViewById<Button>(R.id.chooseButton)
radioGroup = view.findViewById(R.id.radioGroup)
coreK.initFragment(preferences, editor, chooseBtn, radioGroup, this)
coreK.initFragment(preferences, editor, chooseBtn, radioGroup, this,true)
val startBtn = view.findViewById<Button>(R.id.startButton)
startBtn.setOnClickListener {
val startNum: Int = Integer.valueOf(view.findViewById<EditText>(R.id.start).text.toString())
Expand All @@ -50,7 +50,7 @@ class Fragment1 : Fragment() {
val radio: Boolean = radioGroup.checkedRadioButtonId == R.id.radioButton
Log.d("radio", radioGroup.checkedRadioButtonId.toString())
Log.d("radio", R.id.radioButton.toString())
core.process(context, startNum, endNum, fileString, radio, activity, format, "",preferences.getInt("delay",0))
core.process(context, startNum, endNum, fileString, radio, activity, format, "",preferences.getInt("delay",0),preferences.getBoolean("useEXIF",false))
}
val freshButton = view.findViewById<Button>(R.id.freshButton)
freshButton.setOnClickListener {
Expand All @@ -74,7 +74,7 @@ class Fragment1 : Fragment() {
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
if (context != null && isVisibleToUser) {
coreK.initFragment(preferences, editor, chooseBtn, radioGroup, this)
coreK.initFragment(preferences, editor, chooseBtn, radioGroup, this,true)
coreK.updateAppbar(activity!!,true)
/* 作者:Silas_
来源:CSDN
Expand All @@ -83,4 +83,4 @@ class Fragment1 : Fragment() {
}
}

}
}
16 changes: 11 additions & 5 deletions app/src/main/java/photoTimeFix/Fragment2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Fragment2 : Fragment() {
locateTv = view.findViewById(R.id.locateText)
preferences = activity!!.getPreferences(Context.MODE_PRIVATE)
editor = preferences.edit()
coreK = CoreK(context!!,editor,null)
coreK = CoreK(context!!,editor,null,null)
chooseBtn = view.findViewById(R.id.chooseButton)
radioGroup = view.findViewById(R.id.radioGroup)
dateEdit = view.findViewById(R.id.nowDate)
Expand Down Expand Up @@ -107,7 +107,7 @@ class Fragment2 : Fragment() {
val fileString: String = view.findViewById<EditText>(R.id.locateText).text.toString()
val radio: Boolean = radioGroup.checkedRadioButtonId == R.id.radioButton
val selectDate = choseDateEdit.text.toString()
core.process(context, 0, 0, fileString, radio, activity, "yyyyMMddHHmm", selectDate,0)
core.process(context, 0, 0, fileString, radio, activity, "yyyyMMddHHmm", selectDate,0,false)
}

exifBtn.setOnClickListener {
Expand All @@ -122,12 +122,18 @@ class Fragment2 : Fragment() {
builder.show()
}

view.findViewById<TextView>(R.id.nowText).setOnClickListener {
val path:String = locateTv.text.toString()
val returnValue = coreK.updateDate(path,activity!!)
dateEdit.setText(returnValue[0])
}

return view
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
var path = coreK.resultSolve(requestCode, data)
super.onActivityResult(requestCode, resultCode, data)
var path = coreK.resultSolve(requestCode, data)
if (path != "error") {
locateTv.setText(path)
val returnValue = coreK.updateDate(path,activity!!)
Expand Down Expand Up @@ -156,10 +162,10 @@ class Fragment2 : Fragment() {
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
if (context != null && isVisibleToUser) {
coreK.initFragment(preferences, editor, chooseBtn, radioGroup, this)
coreK.initFragment(preferences, editor, chooseBtn, radioGroup, this,false)
//context!!.toast(bitmapIsNull.toString())
if (!bitmapIsNull) coreK.updateAppbar(activity!!,false)
}
}

}
}
27 changes: 23 additions & 4 deletions app/src/main/java/photoTimeFix/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MainActivity : AppCompatActivity() {
setSupportActionBar(toolbar)
preferences = getPreferences(Context.MODE_PRIVATE)
editor = preferences.edit()
coreK = CoreK(this,editor,this)
coreK = CoreK(this,editor,this,preferences)
if (preferences.getBoolean("ifFirst",true)) {
coreK.showAbout()
editor.putBoolean("ifFirst",false)
Expand All @@ -40,13 +40,32 @@ class MainActivity : AppCompatActivity() {
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
super.onCreateOptionsMenu(menu)
menuInflater.inflate(R.menu.info,menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
coreK.showAbout()
return true
if (item != null) {
return when (item.itemId) {
R.id.more -> {
coreK.showAbout()
true
}
R.id.experimentalFunctionMenu -> {
coreK.experimentalFunction()
true
}
R.id.test -> {
coreK.test()
true
}
else -> {
super.onOptionsItemSelected(item)
}
}
}
return super.onOptionsItemSelected(item)
}

private fun initTitle() {
Expand All @@ -64,4 +83,4 @@ class MainActivity : AppCompatActivity() {
mFragmentList.add(Fragment2())
}

}
}
19 changes: 18 additions & 1 deletion app/src/main/java/tech/lincaiqi/PhotoTimeFix/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.media.ExifInterface;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import com.topjohnwu.superuser.BusyBoxInstaller;
import com.topjohnwu.superuser.Shell;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Pattern;

import photoTimeFix.CoreK;

public class Core {

private boolean support = true;

public void process(Context context, int startnum, int endnum, String fileString, boolean radio, Activity activity, String format, String selectDate, int delay) {
public void process(Context context, int startnum, int endnum, String fileString, boolean radio, Activity activity, String format, String selectDate, int delay,Boolean exif) {
File file = new File(fileString);
//Log.d("EditText", locateTv.getText().toString());
if (!file.exists()) {
Expand Down Expand Up @@ -63,6 +67,19 @@ public void process(Context context, int startnum, int endnum, String fileString
if (i >= startnum && (endnum == 0 || i <= endnum)) {
String time = selectDate.equals("") ? f.getName() : selectDate;
time = Pattern.compile("[^0-9]").matcher(time).replaceAll("").trim();
if (exif) {
try {
ExifInterface exifInterface = new ExifInterface(f.getAbsolutePath());
if (exifInterface.getAttribute(ExifInterface.TAG_DATETIME) != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.getDefault());
Date d = sdf.parse(exifInterface.getAttribute(ExifInterface.TAG_DATETIME));
sdf = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
time = sdf.format(d);
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (time.contains("20") && time.substring(time.indexOf("20")).length() >= 12) {
String targetTime = time.substring(time.indexOf("20"), time.indexOf("20") + 12);
if (radio) {
Expand Down
Loading

0 comments on commit cf9db38

Please sign in to comment.