Commit 4452a6b8 authored by feihuaduo's avatar feihuaduo

决斗助手快速保存复制的卡组文本

parent a457c6c7
......@@ -3,10 +3,13 @@ package cn.garymb.ygomobile.ui.cards.deck;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.bean.DeckInfo;
import cn.garymb.ygomobile.utils.IOUtils;
......@@ -126,4 +129,21 @@ public class DeckUtils {
}
return true;
}
public static File save(String name,String deckMessage) throws IOException {
FileWriter fw = null;
//如果文件存在,则重写内容;如果文件不存在,则创建文件
File f = new File(AppsSettings.get().getDeckDir(),name+".ydk");
fw = new FileWriter(f, false);
PrintWriter pw = new PrintWriter(fw);
pw.println(deckMessage);
pw.flush();
fw.flush();
pw.close();
fw.close();
return f;
}
}
......@@ -25,9 +25,11 @@ import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
......@@ -37,6 +39,8 @@ import cn.garymb.ygomobile.bean.ServerList;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.adapters.ServerListAdapter;
import cn.garymb.ygomobile.ui.cards.CardSearchAcitivity;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.ui.cards.deck.DeckUtils;
import cn.garymb.ygomobile.ui.home.MainActivity;
import cn.garymb.ygomobile.ui.home.ServerListManager;
import cn.garymb.ygomobile.utils.IOUtils;
......@@ -80,7 +84,7 @@ public class ServiceDuelAssistant extends Service {
//卡查内容
public static String cardSearchMessage = "";
//卡组复制
public static final String[] DeckTextKey = new String[]{"#Created by", "#main"};
public static final String[] DeckTextKey = new String[]{ "#main"};
public static String DeckText = "";
//悬浮窗布局View
......@@ -148,21 +152,16 @@ public class ServiceDuelAssistant extends Service {
if (TextUtils.isEmpty(clipMessage)) {
return;
}
//如果复制的内容是多行则视为卡组
//如果复制的内容是多行作为卡组去判断
if (clipMessage.contains("\n")) {
for (String s : DeckTextKey) {
int DeckTextStart = clipMessage.indexOf(s);
if (DeckTextStart != -1) {
DeckText = clipMessage.substring(DeckTextStart + s.length(), clipMessage.length());
if (TextUtils.isEmpty(DeckText)) {
//只要包含其中一个关键字就视为卡组
if (clipMessage.contains(s)) {
saveDeck(clipMessage);
return;
}
//如果卡组文本包含“#extra”并且复制的内容包含“!side”则作为卡组打开
if (DeckText.contains("#extra")&&clipMessage.contains("!side")) {
}
}
}
return;
}
int start = -1;
int end = -1;
......@@ -317,6 +316,44 @@ public class ServiceDuelAssistant extends Service {
}
}
private void saveDeck(String deckMessage){
tv_message.setText("检测到卡组文本,是否保存?");
bt_close.setText(R.string.search_close);
bt_join.setText("保存并打开");
disJoinDialog();
showJoinDialog();
new Handler().postDelayed(() -> {
if (isdis) {
isdis = false;
mWindowManager.removeView(mFloatLayout);
}
}, TIME_DIS_WINDOW);
bt_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
disJoinDialog();
}
});
bt_join.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
disJoinDialog();
try {
//以当前时间戳作为卡组名保存卡组
File file=DeckUtils.save("助手保存:"+System.currentTimeMillis(),deckMessage);
Intent startdeck = new Intent(ServiceDuelAssistant.this, DeckManagerActivity.getDeckManager());
startdeck.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
startdeck.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startdeck);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(ServiceDuelAssistant.this,"保存失败,原因为"+e,Toast.LENGTH_SHORT).show();
}
}
});
}
private void joinRoom(String ss, int start, int end) {
final String password = ss.substring(start, ss.length());
tv_message.setText(getString(R.string.quick_join) + password + "\"");
......
......@@ -37,6 +37,7 @@
<CheckBoxPreference
android:key="pref_key_start_serviceduelassistant"
android:persistent="true"
android:summary="快速卡查,加入决斗等"
android:title="@string/Start_ServiceDuelAssistant"/>
<CheckBoxPreference
android:key="pref_key_game_sound_effect"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment