| | |
| | | import android.os.Handler |
| | | import android.os.Looper |
| | | import android.provider.Settings |
| | | import android.util.Log |
| | | import android.widget.Toast |
| | | import androidx.core.app.ActivityCompat |
| | | import cn.sinata.rxnetty.NettyClient |
| | | import cn.sinata.xldutils.utils.* |
| | | import com.amap.api.location.AMapLocation |
| | |
| | | import com.future.driver.ui.main.event.MineEventActivity |
| | | import com.future.driver.ui.mine.MineActivity |
| | | import com.future.driver.ui.mine.MsgActivity |
| | | import com.future.driver.utils.AudioRecordUtils |
| | | import com.future.driver.utils.Cache.CacheKey |
| | | import com.future.driver.utils.DateUtil |
| | | import com.future.driver.utils.OSSUtil |
| | | import com.future.driver.utils.download.DownloadUtil |
| | | import com.google.gson.Gson |
| | | import com.lljjcoder.style.citylist.Toast.ToastUtils |
| | |
| | | import org.jetbrains.anko.startActivity |
| | | import org.jetbrains.anko.toast |
| | | |
| | | |
| | | class MainActivity : MyBaseActivity(), AMapLocationListener { |
| | | class MainActivity : MyBaseActivity(), AMapLocationListener, |
| | | AudioRecordUtils.OnAudioStatusUpdateListener { |
| | | |
| | | val mainFragment by lazy { |
| | | MainFragment() |
| | |
| | | setContentView(R.layout.activity_main) |
| | | } |
| | | |
| | | private var recorder:AudioRecordUtils? = null //录音器 |
| | | private val VOICE_LENGTH = 1000L*60*5 //实际5分钟一个片段 |
| | | // private val VOICE_LENGTH = 1000L*15 //测试15秒一个片段 |
| | | |
| | | override fun initView() { |
| | | MyApplication.canPlayVoice = true |
| | | // var packageName = "com.android.providers.downloads"; |
| | | // var intent = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
| | | // intent.setData(Uri.parse("package:" + packageName)); |
| | | // startActivity(intent); |
| | | if (CacheKey.getKeyStr(Const.REFUSE_LOCATION).isNotEmpty()&&!RxPermissions(this).isGranted(Manifest.permission.ACCESS_FINE_LOCATION)){ |
| | | if (CacheKey.getKeyStr(Const.REFUSE_LOCATION).isNotEmpty()&&!RxPermissions(this).isGranted( |
| | | Manifest.permission.ACCESS_FINE_LOCATION |
| | | )){ |
| | | toast("没有定位权限,您将无法收到新订单推送") |
| | | }else{ |
| | | if (!RxPermissions(this).isGranted(Manifest.permission.ACCESS_FINE_LOCATION)){ |
| | | DialogUtil.getDelAndSureDialog(this,"去授权","否","《未来出行司机》需要获取您的当前位置信息,用于查询当前城市是否开通服务,我们会将您的位置实时上传至后端为您匹配和推送附近订单。如果拒绝定位权限,您将无法正常接单。",{ |
| | | DialogUtil.getDelAndSureDialog( |
| | | this, |
| | | "去授权", |
| | | "否", |
| | | "《未来出行司机》需要获取您的当前位置信息,用于查询当前城市是否开通服务,我们会将您的位置实时上传至后端为您匹配和推送附近订单。如果拒绝定位权限,您将无法正常接单。", |
| | | { |
| | | }){ |
| | | val subscribe = |
| | | RxPermissions(this).request(Manifest.permission.ACCESS_FINE_LOCATION).subscribe { |
| | |
| | | BaseEvent.FACE_FAILED -> { |
| | | tv_face.visible() |
| | | } |
| | | BaseEvent.START_RECORD -> { |
| | | if (!MyApplication.isRecording) |
| | | startRecord() |
| | | } |
| | | BaseEvent.FINISH_RECORD -> { |
| | | recorder?.stopRecord() |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private fun startRecord(){ |
| | | if (recorder == null){ |
| | | recorder = AudioRecordUtils(getExternalFilesDir(null)?.path+"/") |
| | | recorder?.setOnAudioStatusUpdateListener(this) |
| | | } |
| | | if (RxPermissions(this).isGranted(Manifest.permission.RECORD_AUDIO)&&RxPermissions(this).isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)){ |
| | | Log.e("mmp","订单${MyApplication.recordOrderId} 开始录音...") |
| | | recorder?.startRecord() |
| | | } |
| | | else |
| | | toast("缺少录音相关权限") |
| | | } |
| | | |
| | | private fun updateVoice(filePath: String) { |
| | | val ossUtil = OSSUtil(this) |
| | | ossUtil.uploadSingleWithSize(filePath, object : OSSUtil.OSSUploadCallBack() { |
| | | override fun onFinishWithSize(url: String?, size: Long) { |
| | | super.onFinishWithSize(url, size) |
| | | Log.e("mmp","录音保存路径:${url},大小:${size/1024}kb") |
| | | val mapByAny = getMapByAny() |
| | | mapByAny["fileFormat"] = "caf" |
| | | mapByAny["fileLink"] = url |
| | | mapByAny["fileSize"] = size/1024 |
| | | mapByAny["orderId"] = MyApplication.recordOrderId |
| | | mapByAny["orderType"] = MyApplication.recordOrderType |
| | | callNet(false,Api.tape,mapByAny){ |
| | | |
| | | } |
| | | } |
| | | |
| | | override fun onFial(message: String?) { |
| | | super.onFial(message) |
| | | runOnUiThread { |
| | | Toast.makeText(this@MainActivity, "录音上传失败,请检查网络", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | override fun onUpdate(db: Double, time: Long) { |
| | | MyApplication.isRecording = true |
| | | if (time >= VOICE_LENGTH) { |
| | | Log.e("mmp","订单${MyApplication.recordOrderId} 录音片段完成") |
| | | recorder?.stopRecord() //结束录音 |
| | | } |
| | | } |
| | | |
| | | override fun onStop(filePath: String) { |
| | | MyApplication.isRecording = false |
| | | Thread { |
| | | updateVoice(filePath) |
| | | }.start() |
| | | if (MyApplication.currentOrderId.isNotEmpty()){//行程未结束 继续录制下一段 |
| | | Log.e("mmp","订单${MyApplication.recordOrderId} 开始下一片段录音") |
| | | recorder?.startRecord() |
| | | } |
| | | } |
| | | |
| | | override fun onStartPlay() { |
| | | } |
| | | |
| | | override fun onFinishPlay() { |
| | | } |
| | | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | MyApplication.canPlayVoice = false |