|
|
@@ -19,38 +19,120 @@ import java.util.concurrent.TimeUnit;
|
|
|
import io.reactivex.rxjava3.functions.Consumer;
|
|
|
import kotlin.Unit;
|
|
|
import org.las2mile.scrcpy.R;
|
|
|
+import android.widget.TextView;
|
|
|
+import org.las2mile.scrcpy.MainActivity;
|
|
|
+import org.las2mile.ui.MessageEvent;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.Window;
|
|
|
+import android.view.WindowManager;
|
|
|
+import org.las2mile.okio.utils.ZipUtils;
|
|
|
+import org.las2mile.okio.client.DownTaskHandler;
|
|
|
+import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
+import android.provider.DocumentsContract;
|
|
|
+import android.content.ComponentName;
|
|
|
+import java.io.File;
|
|
|
+import androidx.core.content.FileProvider;
|
|
|
|
|
|
//https://www.cnblogs.com/dwcg/articles/17933292.html
|
|
|
public class DownloadTaskDialog {
|
|
|
private Activity mActivity;
|
|
|
AlertDialog alertDialog;
|
|
|
+ TextView tv_remote_ver,tv_log_dl,tv_img_dl;
|
|
|
+
|
|
|
public DownloadTaskDialog(Activity a){
|
|
|
mActivity = a;
|
|
|
init();
|
|
|
}
|
|
|
+
|
|
|
private void init(){
|
|
|
AlertDialog.Builder customizeDialog =
|
|
|
new AlertDialog.Builder(mActivity);
|
|
|
final View dialogView = LayoutInflater.from(mActivity)
|
|
|
.inflate(R.layout.download_task_dialog,null);
|
|
|
customizeDialog.setView(dialogView);
|
|
|
+ tv_remote_ver = dialogView.findViewById(R.id.tv_remote_ver);
|
|
|
RxView.clicks( dialogView.findViewById(R.id.btn_close))
|
|
|
- .throttleFirst( 2 , TimeUnit.SECONDS )
|
|
|
+ .throttleFirst( 500 , TimeUnit.MILLISECONDS )
|
|
|
.subscribe(new Consumer<Unit>() {
|
|
|
@Override
|
|
|
public void accept(Unit unit) throws Throwable {
|
|
|
- Toast.makeText(mActivity, "点击了", Toast.LENGTH_SHORT).show();
|
|
|
- EventBus.getDefault().post(new MessageEvent("Hello everyone!"));
|
|
|
+ //EventBus.getDefault().post(MessageEvent.getMessageEvent(MessageEvent.EVENT_CLICK_IMG_BTN));
|
|
|
dismiss();
|
|
|
}
|
|
|
});
|
|
|
+ tv_log_dl = dialogView.findViewById(R.id.tv_log_dl);
|
|
|
+ RxView.clicks( dialogView.findViewById(R.id.btn_log_dl))
|
|
|
+ .throttleFirst( 500 , TimeUnit.MILLISECONDS )
|
|
|
+ .subscribe(new Consumer<Unit>() {
|
|
|
+ @Override
|
|
|
+ public void accept(Unit unit) throws Throwable {
|
|
|
+ LogEndStickyMsgEvent stickyEvent = EventBus.getDefault().getStickyEvent(LogEndStickyMsgEvent.class);
|
|
|
+ if(stickyEvent != null) {
|
|
|
+ EventBus.getDefault().removeStickyEvent(stickyEvent);
|
|
|
+ }
|
|
|
+ EventBus.getDefault().post(MessageEvent.getMessageEvent(MessageEvent.EVENT_CLICK_LOG_BTN));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tv_img_dl = dialogView.findViewById(R.id.tv_img_dl);
|
|
|
+ RxView.clicks( dialogView.findViewById(R.id.btn_img_dl))
|
|
|
+ .throttleFirst( 500 , TimeUnit.MILLISECONDS )
|
|
|
+ .subscribe(new Consumer<Unit>() {
|
|
|
+ @Override
|
|
|
+ public void accept(Unit unit) throws Throwable {
|
|
|
+ ImgEndStickyMsgEvent stickyEvent = EventBus.getDefault().getStickyEvent(ImgEndStickyMsgEvent.class);
|
|
|
+ if(stickyEvent != null) {
|
|
|
+ EventBus.getDefault().removeStickyEvent(stickyEvent);
|
|
|
+ }
|
|
|
+ EventBus.getDefault().post(MessageEvent.getMessageEvent(MessageEvent.EVENT_CLICK_IMG_BTN));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ RxView.clicks( dialogView.findViewById(R.id.btn_show_all))
|
|
|
+ .throttleFirst( 500 , TimeUnit.MILLISECONDS )
|
|
|
+ .subscribe(new Consumer<Unit>() {
|
|
|
+ @Override
|
|
|
+ public void accept(Unit unit) throws Throwable {
|
|
|
+ dismiss();
|
|
|
+ shareViaWechat();
|
|
|
+ }
|
|
|
+ });
|
|
|
alertDialog = customizeDialog.create();
|
|
|
alertDialog.setCancelable(false);
|
|
|
}
|
|
|
|
|
|
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
|
|
|
- public void onEvent(MessageEvent event){
|
|
|
- Toast.makeText(mActivity, event.message, Toast.LENGTH_SHORT).show();
|
|
|
+ public void onMessageEvent(MessageEvent event){
|
|
|
+ MessageEvent stickyEvent = EventBus.getDefault().getStickyEvent(MessageEvent.class);
|
|
|
+ //Log.e("Scrcpy: ","DownloadTaskDialog onMessageEvent "+event.what+" "+(stickyEvent != null ? stickyEvent.what:0));
|
|
|
+ if(event.what == MessageEvent.EVENT_GOT_REMOTE_VERSION){
|
|
|
+ String remoteVer = String.format(mActivity.getResources().getString(R.string.str_remote_dev_info),(String)event.message);
|
|
|
+ tv_remote_ver.setText(remoteVer);
|
|
|
+ }else if(event.what == MessageEvent.EVENT_GOT_REMOTE_LOG_PROCEDURE){
|
|
|
+ LogDlMsgEvent logDlMsgEvent = (LogDlMsgEvent)event;
|
|
|
+ String sizeFmt = ZipUtils.formetFileSize(logDlMsgEvent.srcfileSize);
|
|
|
+ String stateStr = logDlMsgEvent.isDownloaded == DownTaskHandler.DURING_DOWNLOAD ? "下载中":"未知";
|
|
|
+ String str_save_log_to_local = String.format(mActivity.getResources().getString(R.string.str_save_log_to_local),logDlMsgEvent.mZipPath,sizeFmt,logDlMsgEvent.downloadedpercent+"%",stateStr);
|
|
|
+ tv_log_dl.setText(str_save_log_to_local);
|
|
|
+ }else if(event.what == MessageEvent.EVENT_GOT_REMOTE_LOG_PROCEDURE_END){
|
|
|
+ LogEndStickyMsgEvent logEndStickyMsgEvent = (LogEndStickyMsgEvent)event;
|
|
|
+ String sizeFmt = ZipUtils.formetFileSize(logEndStickyMsgEvent.srcfileSize);
|
|
|
+ String stateStr = logEndStickyMsgEvent.isDownloaded== DownTaskHandler.SUC_DOWNLOAD? "成功":"失败";
|
|
|
+ String str_save_log_to_local = String.format(mActivity.getResources().getString(R.string.str_save_log_to_local),logEndStickyMsgEvent.mZipPath,sizeFmt,logEndStickyMsgEvent.downloadedpercent+"%",stateStr);
|
|
|
+ tv_log_dl.setText(str_save_log_to_local);
|
|
|
+ }else if(event.what == MessageEvent.EVENT_GOT_REMOTE_IMG_PROCEDURE){
|
|
|
+ ImgDlMsgEvent imgDlMsgEvent = (ImgDlMsgEvent)event;
|
|
|
+ String sizeFmt = ZipUtils.formetFileSize(imgDlMsgEvent.srcfileSize);
|
|
|
+ String stateStr = imgDlMsgEvent.isDownloaded == DownTaskHandler.DURING_DOWNLOAD? "下载中":"未知";
|
|
|
+ String str_save_log_to_local = String.format(mActivity.getResources().getString(R.string.str_save_log_to_local),imgDlMsgEvent.mZipPath,sizeFmt,imgDlMsgEvent.downloadedpercent+"%",stateStr);
|
|
|
+ tv_img_dl.setText(str_save_log_to_local);
|
|
|
+ }else if(event.what == MessageEvent.EVENT_GOT_REMOTE_IMG_PROCEDURE_END){
|
|
|
+ ImgEndStickyMsgEvent imgEndStickyMsgEvent = (ImgEndStickyMsgEvent)event;
|
|
|
+ String sizeFmt = ZipUtils.formetFileSize(imgEndStickyMsgEvent.srcfileSize);
|
|
|
+ String stateStr = imgEndStickyMsgEvent.isDownloaded== DownTaskHandler.SUC_DOWNLOAD ? "成功":"失败";
|
|
|
+ String str_save_log_to_local = String.format(mActivity.getResources().getString(R.string.str_save_log_to_local),imgEndStickyMsgEvent.mZipPath,sizeFmt,imgEndStickyMsgEvent.downloadedpercent+"%",stateStr);
|
|
|
+ tv_img_dl.setText(str_save_log_to_local);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void show(){
|
|
|
@@ -62,4 +144,27 @@ public class DownloadTaskDialog {
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
alertDialog.dismiss();
|
|
|
}
|
|
|
+
|
|
|
+ private void shareViaWechat(){
|
|
|
+ Intent shareContent = new Intent();
|
|
|
+ shareContent.setAction(Intent.ACTION_SEND);
|
|
|
+ shareContent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI"));
|
|
|
+ Uri uri = FileProvider.getUriForFile(mActivity,
|
|
|
+ "org.las2mile.scrcpy.provider",
|
|
|
+ new File("/sdcard/phone/img_20250110_175038.zip"));
|
|
|
+ shareContent.putExtra(Intent.EXTRA_STREAM,uri);
|
|
|
+ shareContent.setType("*/*");
|
|
|
+ mActivity.startActivity(shareContent);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showViaFileManager(){
|
|
|
+ String path = "%2fphone%2f";
|
|
|
+ Uri uri = Uri.parse("content://com.android.externalstorage.documents/document/primary:"+path);
|
|
|
+ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
|
|
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
+ intent.setType("*/*");
|
|
|
+ intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI,uri);
|
|
|
+ mActivity.startActivityForResult(intent,0);
|
|
|
+
|
|
|
+ }
|
|
|
}
|