Skip to content

Commit

Permalink
1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
cczhr committed Apr 11, 2022
1 parent fa16a79 commit 3a04cec
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 46 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.cczhr.otglocation"
minSdkVersion 24
targetSdkVersion 30
versionCode 6
versionName "1.1.3"
versionCode 7
versionName "1.1.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -66,4 +66,5 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.github.getActivity:XXPermissions:12.5'
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
package="com.cczhr.otglocation">
<!--都是高德地图要的权限.....-->
<!--允许程序打开网络套接字-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<!--允许程序设置内置sd卡的写权限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--允许程序获取网络状态-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--允许程序访问WiFi网络信息-->
Expand Down
51 changes: 30 additions & 21 deletions app/src/main/java/com/cczhr/otglocation/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import com.cczhr.otglocation.utils.Application
import com.cczhr.otglocation.utils.CommonUtil
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext

Expand All @@ -40,27 +45,31 @@ abstract class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope()
init()
}
fun requestPermissions(result: (Boolean) -> Unit) {
permissionsResult = result
val permissions = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_STATE
)
var isGetAllPermissions = true
for (p in permissions) {
if (ContextCompat.checkSelfPermission(this, p) == PackageManager.PERMISSION_DENIED) {
isGetAllPermissions = false
break
}
}
if (!isGetAllPermissions) {
ActivityCompat.requestPermissions(this, permissions, 100)
} else {
permissionsResult.invoke(true)
}
permissionsResult= result

XXPermissions.with(this) // 申请安装包权限
.permission(Permission.MANAGE_EXTERNAL_STORAGE)
.permission(Permission.ACCESS_FINE_LOCATION)
.permission(Permission.ACCESS_COARSE_LOCATION)
.permission(Permission.READ_PHONE_STATE)
.request(object : OnPermissionCallback {
override fun onGranted(permissions: List<String>, all: Boolean) {
permissionsResult.invoke(true)
}

override fun onDenied(permissions: List<String>, never: Boolean) {
permissionsResult.invoke(false)
if (never) {
CommonUtil.showToast(Application.context,"获取权限失败!请手动赋予权限")
// 如果是被永久拒绝就跳转到应用权限系统设置页面
XXPermissions.startPermissionActivity(this@BaseActivity, permissions)
} else {
CommonUtil.showToast(Application.context,"获取权限失败!请手动赋予权限")
// 如果是被永久拒绝就跳转到应用权限系统设置页面
XXPermissions.startPermissionActivity(this@BaseActivity, permissions)
}
}
})
}


Expand Down
40 changes: 37 additions & 3 deletions app/src/main/java/com/cczhr/otglocation/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ import android.content.Intent
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.ArrayAdapter
import androidx.lifecycle.Observer
import com.amap.api.mapcore.util.it
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.model.LatLng
import com.cczhr.otglocation.database.AppDatabase
import com.cczhr.otglocation.database.LocationData
import com.cczhr.otglocation.net.RetrofitManager
import com.cczhr.otglocation.utils.*
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main.select_location
import kotlinx.android.synthetic.main.activity_main.text_input_layout
import kotlinx.android.synthetic.main.activity_map.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
Expand All @@ -30,9 +38,9 @@ class MainActivity : BaseActivity() {
var isRoot = false
var isConnected = false
var hasDeveloperImg = false

var progressDialog: ProgressDialog? = null

lateinit var locationAdapter: ArrayAdapter<LocationData>
val locationData = ArrayList<LocationData>()
@SuppressLint("SetTextI18n")


Expand All @@ -42,9 +50,33 @@ class MainActivity : BaseActivity() {
progressDialog?.dismiss()
}

override fun init() {
private fun loadLocationData() {
launch {
locationData.clear()
locationAdapter.notifyDataSetChanged()
withContext(Dispatchers.IO) {
locationData.addAll(
AppDatabase.getDatabase(this@MainActivity).locationDataDao().getAll()
)
}
locationAdapter.notifyDataSetChanged()
}
}


override fun onResume() {
super.onResume()
loadLocationData()
}


override fun init() {
locationAdapter = ArrayAdapter(this, R.layout.popup_location_item, locationData)
select_location.setOnItemClickListener { _, _, position, _ ->
latitude.setText( locationData[position].lat)
longitude.setText( locationData[position].lon)
}
select_location.setAdapter(locationAdapter)
version?.text = "V ${Application.getVersion()}"
latitude.setText(Application.getLat())
longitude.setText(Application.getLon())
Expand Down Expand Up @@ -186,6 +218,7 @@ class MainActivity : BaseActivity() {
Application.saveLon(lon.toString())

libTools.modifyLocation(lat, lon) {
logAdd("定位修改成功")
CommonUtil.showToast(Application.context, "定位修改成功")
}
}
Expand All @@ -199,6 +232,7 @@ class MainActivity : BaseActivity() {

libTools.resetLocation {
CommonUtil.showToast(Application.context, "定位已还原")
logAdd("定位已还原")
}

}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/cczhr/otglocation/net/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import retrofit2.http.Url
* @since 2021/6/10 10:06
*/
interface Api {
@GET("repos/iGhibli/iOS-DeviceSupport/contents/DeviceSupport")
@GET("repos/filsv/iPhoneOSDeviceSupport/contents")
suspend fun getDeviceSupport(): DeviceSupportBean?

@Streaming
Expand Down
18 changes: 8 additions & 10 deletions app/src/main/java/com/cczhr/otglocation/utils/FileUtils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cczhr.otglocation.utils

import android.util.Log
import java.io.File
import java.io.FileFilter

Expand All @@ -10,20 +11,17 @@ import java.io.FileFilter
*/
class FileUtils {
companion object{
fun findFile(dir: File,fileName:String):String{
if (dir.isDirectory) {
val files = dir.listFiles()
for (file in files) {
if(file.isDirectory)
return findFile(file,fileName)
else if(file.isFile&&file.name==fileName){
return file.absolutePath
}
fun findFile(dir: File,fileName:String):String {

val fileTreeWalk = dir.walk()
fileTreeWalk.iterator().forEach {
if (it.name == fileName && it.isFile) {
return it.absolutePath
}

}
return ""
}

/**
* Delete the all in directory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class IMobileDeviceTools {
successResult = BufferedReader(InputStreamReader(process!!.inputStream))
errorResult = BufferedReader(InputStreamReader(process!!.errorStream))
os = DataOutputStream(process!!.outputStream)
os?.write(".$saveFilePath/usbmuxd -v -f --pidfile NONE --usbfd $fd ".toByteArray())//--pidfile NONE --usbfd $fd --usbfd $fd
os?.write(".$saveFilePath/usbmuxd -v -f ".toByteArray())//--pidfile NONE --usbfd $fd --usbfd $fd
os?.writeBytes("\n")
os?.flush()
os?.close()
Expand Down
40 changes: 33 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
android:text="@string/latitude" />

<EditText
android:selectAllOnFocus="true"
android:id="@+id/latitude"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -142,7 +143,7 @@
android:text="@string/longitude" />

<EditText

android:selectAllOnFocus="true"
android:id="@+id/longitude"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -159,12 +160,37 @@
android:layout_height="wrap_content"
android:text="@string/cancel_location_offset" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="downloadDriver"
android:text="@string/download_the_developer_driver"
android:textColor="@color/white" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="downloadDriver"
android:text="@string/download_the_developer_driver"
android:textColor="@color/white" />

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/text_input_layout2"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:hint="@string/local_location"
app:errorEnabled="false"
app:helperTextEnabled="true">
<AutoCompleteTextView
android:id="@+id/select_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>





Expand Down

0 comments on commit 3a04cec

Please sign in to comment.