优化:统一使用吐司框架 ToastUtils

This commit is contained in:
pppscn 2022-01-30 20:08:12 +08:00
parent e329308561
commit bfdc0e4fce
13 changed files with 142 additions and 140 deletions

View File

@ -6,13 +6,13 @@ import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.receiver.RebootBroadcastReceiver;
import com.idormy.sms.forwarder.utils.CacheUtil;
import com.idormy.sms.forwarder.utils.CommonUtil;
@ -25,7 +25,6 @@ import java.util.List;
public class AboutActivity extends AppCompatActivity {
@SuppressWarnings("FieldCanBeLocal")
private final String TAG = "AboutActivity";
@Override
@ -46,9 +45,9 @@ public class AboutActivity extends AppCompatActivity {
@Override
public void onGranted(List<String> permissions, boolean all) {
if (all) {
Toast.makeText(getBaseContext(), R.string.toast_granted_all, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_granted_all);
} else {
Toast.makeText(getBaseContext(), R.string.toast_granted_part, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_granted_part);
}
SettingUtil.switchEnableSms(true);
}
@ -56,11 +55,11 @@ public class AboutActivity extends AppCompatActivity {
@Override
public void onDenied(List<String> permissions, boolean never) {
if (never) {
Toast.makeText(getBaseContext(), R.string.toast_denied_never, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_denied_never);
// 如果是被永久拒绝就跳转到应用权限系统设置页面
XXPermissions.startPermissionActivity(AboutActivity.this, permissions);
} else {
Toast.makeText(getBaseContext(), R.string.toast_denied, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_denied);
}
SettingUtil.switchEnableSms(false);
}
@ -78,20 +77,21 @@ public class AboutActivity extends AppCompatActivity {
try {
String updateUrl = "https://xupdate.bms.ink/update/checkVersion?appKey=com.idormy.sms.forwarder&versionCode=";
updateUrl += CommonUtil.getVersionCode(AboutActivity.this);
Log.d(TAG, updateUrl);
EasyUpdate.create(AboutActivity.this, updateUrl)
.updateChecker(new DefaultUpdateChecker() {
@Override
public void onBeforeCheck() {
super.onBeforeCheck();
Toast.makeText(AboutActivity.this, R.string.checking, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.checking, 3000);
}
@Override
public void noNewVersion(Throwable throwable) {
super.noNewVersion(throwable);
// 没有最新版本的处理
Toast.makeText(AboutActivity.this, R.string.up_to_date, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.up_to_date, 3000);
}
})
.update();
@ -115,7 +115,7 @@ public class AboutActivity extends AppCompatActivity {
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(AboutActivity.this, R.string.cache_purged, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.cache_purged, 3000);
});
Button join_qq_group1 = findViewById(R.id.join_qq_group1);
@ -142,7 +142,7 @@ public class AboutActivity extends AppCompatActivity {
startActivity(intent);
} catch (Exception e) {
// 未安装手Q或安装的版本不支持
Toast.makeText(AboutActivity.this, R.string.unknown_qq_version, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.unknown_qq_version, 3000);
}
}

View File

@ -20,10 +20,10 @@ import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.adapter.AppAdapter;
import com.idormy.sms.forwarder.model.AppInfo;
@ -45,7 +45,7 @@ public class AppListActivity extends AppCompatActivity {
@Override
public void handleMessage(Message msg) {
if (msg.what == NOTIFY) {
Toast.makeText(AppListActivity.this, msg.getData().getString("DATA"), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(msg.getData().getString("DATA"), 3000);
} else if (msg.what == APP_LIST) {
AppAdapter adapter = new AppAdapter(AppListActivity.this, R.layout.item_app, appInfoList);
listView.setAdapter(adapter);
@ -91,7 +91,7 @@ public class AppListActivity extends AppCompatActivity {
ClipData mClipData = ClipData.newPlainText("pkgName", appInfo.getPkgName());
cm.setPrimaryClip(mClipData);
Toast.makeText(AppListActivity.this, getString(R.string.package_name_copied) + appInfo.getPkgName(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.package_name_copied) + appInfo.getPkgName(), 3000);
});
listView.setOnItemLongClickListener((parent, view, position, id) -> {
AppInfo appInfo = appInfoList.get(position);

View File

@ -10,12 +10,12 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.alibaba.fastjson.JSON;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.model.vo.CloneInfoVo;
import com.idormy.sms.forwarder.receiver.BaseServlet;
import com.idormy.sms.forwarder.receiver.RebootBroadcastReceiver;
@ -62,7 +62,7 @@ public class CloneActivity extends AppCompatActivity {
@Override
public void handleMessage(Message msg) {
if (msg.what == TOAST) {
Toast.makeText(CloneActivity.this, msg.getData().getString("DATA"), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(msg.getData().getString("DATA"), 3000);
} else if (msg.what == DOWNLOAD) {
String savePath = context.getCacheDir().getPath() + File.separator + BackupDbTask.BACKUP_FILE;
Log.d(TAG, savePath);
@ -110,6 +110,7 @@ public class CloneActivity extends AppCompatActivity {
sendBtn.setText(R.string.send);
sendTxt.setText(R.string.server_has_stopped);
}
//noinspection CommentedOutCode
sendBtn.setOnClickListener(v -> {
if (!HttpServer.asRunning() && NetUtil.NETWORK_WIFI != NetUtil.getNetWorkStatus()) {
Toast(handError, TAG, getString(R.string.no_wifi_network));

View File

@ -7,10 +7,11 @@ import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.hjq.toast.ToastUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
@ -99,7 +100,7 @@ public class CrashHandler implements UncaughtExceptionHandler {
@Override
public void run() {
Looper.prepare();
Toast.makeText(mContext, R.string.crash_tip, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.crash_tip, 3000);
Looper.loop();
}
}.start();

View File

@ -20,7 +20,6 @@ import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
@ -29,6 +28,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.adapter.LogAdapter;
import com.idormy.sms.forwarder.model.vo.LogVo;
import com.idormy.sms.forwarder.sender.HttpServer;
@ -171,9 +171,9 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
@Override
public void onGranted(List<String> permissions, boolean all) {
if (all) {
Toast.makeText(getBaseContext(), R.string.toast_granted_all, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_granted_all);
} else {
Toast.makeText(getBaseContext(), R.string.toast_granted_part, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_granted_part);
}
SettingUtil.switchEnableSms(true);
}
@ -181,11 +181,11 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
@Override
public void onDenied(List<String> permissions, boolean never) {
if (never) {
Toast.makeText(getBaseContext(), R.string.toast_denied_never, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_denied_never);
// 如果是被永久拒绝就跳转到应用权限系统设置页面
XXPermissions.startPermissionActivity(MainActivity.this, permissions);
} else {
Toast.makeText(getBaseContext(), R.string.toast_denied, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_denied);
}
SettingUtil.switchEnableSms(false);
}
@ -248,7 +248,7 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
LogUtil.delLog(id1, null);
initTLogs(); //初始化数据
showList(logVos);
Toast.makeText(getBaseContext(), R.string.delete_log_toast, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.delete_log_toast);
});
//添加AlertDialog.Builder对象的setNegativeButton()方法
@ -293,7 +293,7 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
//省电优化设置为无限制
if (MyApplication.showHelpTip && Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
if (!KeepAliveUtils.isIgnoreBatteryOptimization(this)) {
Toast.makeText(this, R.string.tips_battery_optimization, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.tips_battery_optimization, 3000);
}
}
@ -301,7 +301,7 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
if (SettingUtil.getSwitchEnableAppNotify() && !CommonUtil.isNotificationListenerServiceEnabled(this)) {
CommonUtil.toggleNotificationListenerService(this);
SettingUtil.switchEnableAppNotify(false);
Toast.makeText(this, R.string.tips_notification_listener, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.tips_notification_listener, 3000);
return;
}
@ -349,10 +349,10 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
if (requestCode == CommonUtil.NOTIFICATION_REQUEST_CODE) {
if (CommonUtil.isNotificationListenerServiceEnabled(this)) {
Toast.makeText(this, R.string.notification_listener_service_enabled, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.notification_listener_service_enabled);
CommonUtil.toggleNotificationListenerService(this);
} else {
Toast.makeText(this, R.string.notification_listener_service_disabled, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.notification_listener_service_disabled);
}
}
}
@ -411,7 +411,7 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
LogUtil.delLog(id, null);
initTLogs(); //初始化数据
showList(logVos);
Toast.makeText(MainActivity.this, R.string.delete_log_toast, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.delete_log_toast);
dialog.dismiss();
});
@ -424,7 +424,7 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
//对于发送失败的消息添加重发按钮
if (logVo.getForwardStatus() != 2) {
builder.setPositiveButton(R.string.resend, (dialog, which) -> {
Toast.makeText(MainActivity.this, R.string.resend_toast, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.resend_toast);
SendUtil.resendMsgByLog(MainActivity.this, handler, logVo);
dialog.dismiss();
});

View File

@ -18,11 +18,11 @@ import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.adapter.RuleAdapter;
import com.idormy.sms.forwarder.model.RuleModel;
import com.idormy.sms.forwarder.model.SenderModel;
@ -56,7 +56,7 @@ public class RuleActivity extends AppCompatActivity {
@Override
public void handleMessage(Message msg) {
if (msg.what == NOTIFY) {
Toast.makeText(RuleActivity.this, msg.getData().getString("DATA"), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(msg.getData().getString("DATA"), 3000);
}
}
};
@ -103,7 +103,7 @@ public class RuleActivity extends AppCompatActivity {
RuleUtil.delRule(ruleModels.get(position).getId());
initRules();
adapter.del(ruleModels);
Toast.makeText(getBaseContext(), R.string.delete_rule_toast, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.delete_rule_toast);
});
builder.setNeutralButton(R.string.clone, (dialog, which) -> {
@ -216,7 +216,7 @@ public class RuleActivity extends AppCompatActivity {
}
final Button btSetRuleSender = view1.findViewById(R.id.btSetRuleSender);
btSetRuleSender.setOnClickListener(view -> {
//Toast.makeText(RuleActivity.this, "selectSender", Toast.LENGTH_LONG).show();
//ToastUtils.show("selectSender", 3000);
selectSender(ruleSenderTv);
});
@ -261,7 +261,7 @@ public class RuleActivity extends AppCompatActivity {
buttonRuleOk.setOnClickListener(view -> {
Object senderId = ruleSenderTv.getTag();
if (senderId == null) {
Toast.makeText(RuleActivity.this, R.string.new_sender_first, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.new_sender_first, 3000);
return;
}
@ -269,7 +269,7 @@ public class RuleActivity extends AppCompatActivity {
String regexReplace = textRegexReplace.getText().toString().trim();
int lineNum = checkRegexReplace(regexReplace);
if (lineNum > 0) {
Toast.makeText(getBaseContext(), String.format(RuleActivity.this.getString(R.string.regex_check_tips), lineNum), Toast.LENGTH_SHORT).show();
ToastUtils.show("lineNum=" + lineNum);
return;
}
@ -321,7 +321,7 @@ public class RuleActivity extends AppCompatActivity {
buttonRuleTest.setOnClickListener(view -> {
Object senderId = ruleSenderTv.getTag();
if (senderId == null) {
Toast.makeText(RuleActivity.this, R.string.new_sender_first, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.new_sender_first, 3000);
return;
}
@ -329,7 +329,7 @@ public class RuleActivity extends AppCompatActivity {
String regexReplace = textRegexReplace.getText().toString().trim();
int lineNum = checkRegexReplace(regexReplace);
if (lineNum > 0) {
Toast.makeText(getBaseContext(), String.format(RuleActivity.this.getString(R.string.regex_check_tips), lineNum), Toast.LENGTH_SHORT).show();
ToastUtils.show("lineNum=" + lineNum);
return;
}
@ -525,7 +525,7 @@ public class RuleActivity extends AppCompatActivity {
public void selectSender(final TextView showTv) {
final List<SenderModel> senderModels = SenderUtil.getSender(null, null);
if (senderModels.isEmpty()) {
Toast.makeText(RuleActivity.this, R.string.add_sender_first, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.add_sender_first);
return;
}
final CharSequence[] senderNames = new CharSequence[senderModels.size()];
@ -536,7 +536,7 @@ public class RuleActivity extends AppCompatActivity {
builder.setTitle(R.string.select_sender);
//添加列表
builder.setItems(senderNames, (dialogInterface, which) -> {
Toast.makeText(RuleActivity.this, senderNames[which], Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(senderNames[which], 3000);
showTv.setText(senderNames[which]);
showTv.setTag(senderModels.get(which).getId());
});
@ -583,7 +583,7 @@ public class RuleActivity extends AppCompatActivity {
SmsVo testSmsVo = new SmsVo(editTextTestPhone.getText().toString().trim(), editTextTestMsgContent.getText().toString().trim(), new Date(), simInfo);
SendUtil.sendMsgByRuleModelSenderId(handler, ruleModel, testSmsVo, senderId);
} catch (Exception e) {
Toast.makeText(RuleActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(e.getMessage(), 3000);
}
});
ad1.show();// 显示对话框

View File

@ -32,12 +32,12 @@ import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.Switch;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.alibaba.fastjson.JSON;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.adapter.SenderAdapter;
import com.idormy.sms.forwarder.model.SenderModel;
import com.idormy.sms.forwarder.model.vo.BarkSettingVo;
@ -93,7 +93,7 @@ public class SenderActivity extends AppCompatActivity {
@Override
public void handleMessage(Message msg) {
if (msg.what == NOTIFY) {
Toast.makeText(SenderActivity.this, msg.getData().getString("DATA"), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(msg.getData().getString("DATA"), 3000);
}
}
};
@ -166,7 +166,7 @@ public class SenderActivity extends AppCompatActivity {
setGotify(senderModel, false);
break;
default:
Toast.makeText(SenderActivity.this, R.string.invalid_sender, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_sender, 3000);
SenderUtil.delSender(senderModel.getId());
initSenders();
adapter.del(senderModels);
@ -186,7 +186,7 @@ public class SenderActivity extends AppCompatActivity {
SenderUtil.delSender(senderModels.get(position).getId());
initSenders();
adapter.del(senderModels);
Toast.makeText(getBaseContext(), R.string.delete_sender_toast, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.delete_sender_toast);
});
builder.setNeutralButton(R.string.clone, (dialog, which) -> {
@ -229,7 +229,7 @@ public class SenderActivity extends AppCompatActivity {
setGotify(senderModel, true);
break;
default:
Toast.makeText(SenderActivity.this, R.string.invalid_sender, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_sender, 3000);
SenderUtil.delSender(senderModel.getId());
initSenders();
adapter.del(senderModels);
@ -307,7 +307,7 @@ public class SenderActivity extends AppCompatActivity {
setGotify(null, false);
break;
default:
Toast.makeText(SenderActivity.this, R.string.not_supported, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.not_supported, 3000);
break;
}
});
@ -442,11 +442,11 @@ public class SenderActivity extends AppCompatActivity {
Boolean atAll = switchDingdingAtAll.isChecked();
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
if (CommonUtil.checkUrl(token, true)) {
Toast.makeText(SenderActivity.this, R.string.invalid_token, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_token, 3000);
return;
}
@ -484,7 +484,7 @@ public class SenderActivity extends AppCompatActivity {
buttonDingdingTest.setOnClickListener(view -> {
String token = editTextDingdingToken.getText().trim();
if (CommonUtil.checkUrl(token, true)) {
Toast.makeText(SenderActivity.this, R.string.invalid_token, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_token, 3000);
return;
}
@ -495,7 +495,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderDingdingMsg.sendMsg(0, handler, null, token, secret, atMobiles, atAll, smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -558,7 +558,7 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextEmailName.getText().toString().trim();
int senderStatus = switchEmailEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
@ -576,7 +576,7 @@ public class SenderActivity extends AppCompatActivity {
String nickname = editTextEmailNickname.getText().toString().trim();
if (nickname.isEmpty()) nickname = "SmsForwarder";
if (host.isEmpty() || port.isEmpty() || fromEmail.isEmpty() || pwd.isEmpty() || toEmail.isEmpty()) {
Toast.makeText(SenderActivity.this, R.string.invalid_email, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_email, 3000);
return;
}
@ -627,7 +627,7 @@ public class SenderActivity extends AppCompatActivity {
if (nickname.isEmpty()) nickname = "SmsForwarder";
if (host.isEmpty() || port.isEmpty() || fromEmail.isEmpty() || pwd.isEmpty() || toEmail.isEmpty()) {
Toast.makeText(SenderActivity.this, R.string.invalid_email, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_email, 3000);
return;
}
@ -635,7 +635,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderMailMsg.sendEmail(0, handler, protocol, host, port, ssl, fromEmail, nickname, pwd, toEmail, smsVo.getTitleForSend(title), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -723,14 +723,14 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextBarkName.getText().toString().trim();
int senderStatus = switchBarkEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
//推送地址
String barkServer = editTextBarkServer.getText().trim();
if (!CommonUtil.checkUrl(barkServer, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_bark_server, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_bark_server, 3000);
return;
}
@ -785,11 +785,11 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderBarkMsg.sendMsg(0, handler, null, barkSettingVoNew, smsVo.getTitleForSend(title), smsVo.getSmsVoForSend(), getString(R.string.test_group_name));
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
} else {
Toast.makeText(SenderActivity.this, R.string.invalid_bark_server, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_bark_server, 3000);
}
});
@ -871,7 +871,7 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextWebNotifyName.getText().toString().trim();
int senderStatus = switchWebNotifyEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
@ -881,7 +881,7 @@ public class SenderActivity extends AppCompatActivity {
String webParams = editTextWebNotifyWebParams.getText().toString().trim();
if (!CommonUtil.checkUrl(webServer, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_webserver, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webserver, 3000);
return;
}
@ -921,7 +921,7 @@ public class SenderActivity extends AppCompatActivity {
String webParams = editTextWebNotifyWebParams.getText().toString().trim();
if (!CommonUtil.checkUrl(webServer, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_webserver, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webserver, 3000);
return;
}
@ -929,7 +929,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderWebNotifyMsg.sendMsg(0, handler, null, webServer, webParams, secret, method, smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -976,13 +976,13 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextQYWXGroupRobotName.getText().toString().trim();
int senderStatus = switchQYWXGroupRobotEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
String webHook = editTextQYWXGroupRobotWebHook.getText().trim();
if (!CommonUtil.checkUrl(webHook, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_webhook, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
return;
}
@ -1020,7 +1020,7 @@ public class SenderActivity extends AppCompatActivity {
buttonQyWxGroupRobotTest.setOnClickListener(view -> {
String webHook = editTextQYWXGroupRobotWebHook.getText().trim();
if (!CommonUtil.checkUrl(webHook, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_webhook, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
return;
}
@ -1028,7 +1028,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderQyWxGroupRobotMsg.sendMsg(0, handler, null, webHook, smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -1093,13 +1093,13 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextQYWXAppName.getText().toString().trim();
int senderStatus = switchQYWXAppEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
String toUser = editTextQYWXAppToUser.getText().toString().trim();
if (toUser.isEmpty()) {
Toast.makeText(SenderActivity.this, R.string.invalid_at_mobiles, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_at_mobiles, 3000);
editTextQYWXAppToUser.setFocusable(true);
editTextQYWXAppToUser.requestFocus();
return;
@ -1112,7 +1112,7 @@ public class SenderActivity extends AppCompatActivity {
editTextQYWXAppToUser.getText().toString().trim(),
switchQYWXAppAtAll.isChecked());
if (!QYWXAppSettingVoNew.checkParms()) {
Toast.makeText(SenderActivity.this, R.string.invalid_webcom_app_parm, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webcom_app_parm, 3000);
return;
}
@ -1154,11 +1154,11 @@ public class SenderActivity extends AppCompatActivity {
editTextQYWXAppToUser.getText().toString().trim(),
switchQYWXAppAtAll.isChecked());
if (!QYWXAppSettingVoNew.checkParms()) {
Toast.makeText(SenderActivity.this, R.string.invalid_webcom_app_parm, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webcom_app_parm, 3000);
return;
}
if (QYWXAppSettingVoNew.getToUser().isEmpty()) {
Toast.makeText(SenderActivity.this, R.string.invalid_at_mobiles, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_at_mobiles, 3000);
return;
}
@ -1166,7 +1166,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderQyWxAppMsg.sendMsg(0, handler, null, senderModel, QYWXAppSettingVoNew, smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -1211,13 +1211,13 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextServerChanName.getText().toString().trim();
int senderStatus = switchServerChanEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
String serverChanServer = editTextServerChanSendKey.getText().trim();
if (TextUtils.isEmpty(serverChanServer)) {
Toast.makeText(SenderActivity.this, R.string.invalid_sendkey, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_sendkey, 3000);
return;
}
ServerChanSettingVo serverChanSettingVoNew = new ServerChanSettingVo(serverChanServer);
@ -1255,7 +1255,7 @@ public class SenderActivity extends AppCompatActivity {
buttonServerChanTest.setOnClickListener(view -> {
String serverChanServer = editTextServerChanSendKey.getText().trim();
if (TextUtils.isEmpty(serverChanServer)) {
Toast.makeText(SenderActivity.this, R.string.invalid_sendkey, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_sendkey, 3000);
return;
}
@ -1263,7 +1263,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderServerChanMsg.sendMsg(0, handler, null, serverChanServer, smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -1363,14 +1363,14 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextTelegramName.getText().toString().trim();
int senderStatus = switchTelegramEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
String apiToken = editTextTelegramApiToken.getText().trim();
String chatId = editTextTelegramChatId.getText().toString().trim();
if (apiToken.isEmpty() || chatId.isEmpty()) {
Toast.makeText(SenderActivity.this, R.string.invalid_apiToken_or_chatId, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_apiToken_or_chatId, 3000);
return;
}
@ -1378,7 +1378,7 @@ public class SenderActivity extends AppCompatActivity {
String proxyHost = editTextProxyHost.getText().toString().trim();
String proxyPort = editTextProxyPort.getText().toString().trim();
if (proxyTypeId != R.id.btnProxyNone && (TextUtils.isEmpty(proxyHost) || TextUtils.isEmpty(proxyPort))) {
Toast.makeText(SenderActivity.this, R.string.invalid_host_or_port, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_host_or_port, 3000);
return;
}
@ -1386,7 +1386,7 @@ public class SenderActivity extends AppCompatActivity {
String proxyUsername = editTextProxyUsername.getText().toString().trim();
String proxyPassword = editTextProxyPassword.getText().trim();
if (proxyAuthenticator && TextUtils.isEmpty(proxyUsername) && TextUtils.isEmpty(proxyPassword)) {
Toast.makeText(SenderActivity.this, R.string.invalid_username_or_password, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_username_or_password, 3000);
return;
}
@ -1427,7 +1427,7 @@ public class SenderActivity extends AppCompatActivity {
String apiToken = editTextTelegramApiToken.getText().trim();
String chatId = editTextTelegramChatId.getText().toString().trim();
if (apiToken.isEmpty() || chatId.isEmpty()) {
Toast.makeText(SenderActivity.this, R.string.invalid_apiToken_or_chatId, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_apiToken_or_chatId, 3000);
return;
}
@ -1435,7 +1435,7 @@ public class SenderActivity extends AppCompatActivity {
String proxyHost = editTextProxyHost.getText().toString().trim();
String proxyPort = editTextProxyPort.getText().toString().trim();
if (proxyTypeId != R.id.btnProxyNone && (TextUtils.isEmpty(proxyHost) || TextUtils.isEmpty(proxyPort))) {
Toast.makeText(SenderActivity.this, R.string.invalid_host_or_port, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_host_or_port, 3000);
return;
}
@ -1443,7 +1443,7 @@ public class SenderActivity extends AppCompatActivity {
String proxyUsername = editTextProxyUsername.getText().toString().trim();
String proxyPassword = editTextProxyPassword.getText().trim();
if (proxyAuthenticator && TextUtils.isEmpty(proxyUsername) && TextUtils.isEmpty(proxyPassword)) {
Toast.makeText(SenderActivity.this, R.string.invalid_username_or_password, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_username_or_password, 3000);
return;
}
@ -1454,7 +1454,7 @@ public class SenderActivity extends AppCompatActivity {
TelegramSettingVo telegramSettingVoNew = new TelegramSettingVo(apiToken, chatId, proxyTypeId, proxyHost, proxyPort, proxyAuthenticator, proxyUsername, proxyPassword, method);
SenderTelegramMsg.sendMsg(0, handler, null, telegramSettingVoNew, smsVo.getMobile(), smsVo.getSmsVoForSend(), telegramSettingVoNew.getMethod());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -1505,14 +1505,14 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextSmsName.getText().toString().trim();
int senderStatus = switchSmsEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
Boolean onlyNoNetwork = switchSmsOnlyNoNetwork.isChecked();
String mobiles = editTextSmsMobiles.getText().toString().trim();
if (TextUtils.isEmpty(mobiles)) {
Toast.makeText(SenderActivity.this, R.string.invalid_phone_num, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_phone_num, 3000);
return;
}
@ -1561,7 +1561,7 @@ public class SenderActivity extends AppCompatActivity {
Boolean onlyNoNetwork = switchSmsOnlyNoNetwork.isChecked();
String mobiles = editTextSmsMobiles.getText().toString().trim();
if (TextUtils.isEmpty(mobiles)) {
Toast.makeText(SenderActivity.this, R.string.invalid_phone_num, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_phone_num, 3000);
return;
}
@ -1569,7 +1569,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderSmsMsg.sendMsg(0, handler, simSlot, mobiles, onlyNoNetwork, smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -1616,14 +1616,14 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextFeishuName.getText().toString().trim();
int senderStatus = switchFeishuEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
String webHook = editTextFeishuWebhook.getText().toString().trim();
String secret = editTextFeishuSecret.getText().trim();
if (!CommonUtil.checkUrl(webHook, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_webhook, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
return;
}
@ -1662,7 +1662,7 @@ public class SenderActivity extends AppCompatActivity {
String webHook = editTextFeishuWebhook.getText().toString().trim();
String secret = editTextFeishuSecret.getText().trim();
if (!CommonUtil.checkUrl(webHook, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_webhook, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
return;
}
@ -1670,7 +1670,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderFeishuMsg.sendMsg(0, handler, null, webHook, secret, smsVo.getMobile(), new Date(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -1730,7 +1730,7 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextPushPlusName.getText().toString().trim();
int senderStatus = switchPushPlusEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
@ -1745,7 +1745,7 @@ public class SenderActivity extends AppCompatActivity {
editTextPushPlusTitle.getText().toString().trim()
);
if (TextUtils.isEmpty(pushPlusSettingVoNew.getToken())) {
Toast.makeText(SenderActivity.this, R.string.invalid_token, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_token, 3000);
return;
}
@ -1797,7 +1797,7 @@ public class SenderActivity extends AppCompatActivity {
);
if (TextUtils.isEmpty(pushPlusSettingVoNew.getToken())) {
Toast.makeText(SenderActivity.this, R.string.invalid_token, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_token, 3000);
return;
}
@ -1805,7 +1805,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderPushPlusMsg.sendMsg(0, handler, null, pushPlusSettingVoNew, smsVo.getTitleForSend(title), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}
});
@ -1884,13 +1884,13 @@ public class SenderActivity extends AppCompatActivity {
String senderName = editTextGotifyName.getText().toString().trim();
int senderStatus = switchGotifyEnable.isChecked() ? STATUS_ON : STATUS_OFF;
if (TextUtils.isEmpty(senderName)) {
Toast.makeText(SenderActivity.this, R.string.invalid_name, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_name, 3000);
return;
}
String webServer = editTextGotifyWebServer.getText().trim();
if (!CommonUtil.checkUrl(webServer, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_webserver, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webserver, 3000);
return;
}
@ -1934,7 +1934,7 @@ public class SenderActivity extends AppCompatActivity {
buttonGotifyTest.setOnClickListener(view -> {
String webServer = editTextGotifyWebServer.getText().trim();
if (!CommonUtil.checkUrl(webServer, false)) {
Toast.makeText(SenderActivity.this, R.string.invalid_webserver, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_webserver, 3000);
return;
}
@ -1949,7 +1949,7 @@ public class SenderActivity extends AppCompatActivity {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderGotifyMsg.sendMsg(0, handler, null, gotifySettingVoNew, smsVo.getTitleForSend(title), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();
}

View File

@ -22,7 +22,6 @@ import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Switch;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
@ -31,6 +30,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.receiver.RebootBroadcastReceiver;
import com.idormy.sms.forwarder.sender.HttpServer;
import com.idormy.sms.forwarder.sender.SenderUtil;
@ -153,9 +153,9 @@ public class SettingActivity extends AppCompatActivity {
@Override
public void onGranted(List<String> permissions, boolean all) {
if (all) {
Toast.makeText(getBaseContext(), R.string.toast_granted_all, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_granted_all);
} else {
Toast.makeText(getBaseContext(), R.string.toast_granted_part, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_granted_part);
}
SettingUtil.switchEnableSms(true);
}
@ -163,11 +163,11 @@ public class SettingActivity extends AppCompatActivity {
@Override
public void onDenied(List<String> permissions, boolean never) {
if (never) {
Toast.makeText(getBaseContext(), R.string.toast_denied_never, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_denied_never);
// 如果是被永久拒绝就跳转到应用权限系统设置页面
XXPermissions.startPermissionActivity(SettingActivity.this, permissions);
} else {
Toast.makeText(getBaseContext(), R.string.toast_denied, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_denied);
}
SettingUtil.switchEnableSms(false);
}
@ -188,7 +188,7 @@ public class SettingActivity extends AppCompatActivity {
switch_enable_phone.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked && !SettingUtil.getSwitchCallType1() && !SettingUtil.getSwitchCallType2() && !SettingUtil.getSwitchCallType3()) {
Toast.makeText(context, R.string.enable_phone_fw_tips, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.enable_phone_fw_tips);
SettingUtil.switchEnablePhone(false);
return;
}
@ -212,9 +212,9 @@ public class SettingActivity extends AppCompatActivity {
@Override
public void onGranted(List<String> permissions, boolean all) {
if (all) {
Toast.makeText(getBaseContext(), R.string.toast_granted_all, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_granted_all);
} else {
Toast.makeText(getBaseContext(), R.string.toast_granted_part, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_granted_part);
}
SettingUtil.switchEnableSms(true);
}
@ -222,11 +222,11 @@ public class SettingActivity extends AppCompatActivity {
@Override
public void onDenied(List<String> permissions, boolean never) {
if (never) {
Toast.makeText(getBaseContext(), R.string.toast_denied_never, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_denied_never);
// 如果是被永久拒绝就跳转到应用权限系统设置页面
XXPermissions.startPermissionActivity(SettingActivity.this, permissions);
} else {
Toast.makeText(getBaseContext(), R.string.toast_denied, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.toast_denied);
}
SettingUtil.switchEnableSms(false);
}
@ -239,7 +239,7 @@ public class SettingActivity extends AppCompatActivity {
check_box_call_type_1.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingUtil.switchCallType1(isChecked);
if (!isChecked && !SettingUtil.getSwitchCallType1() && !SettingUtil.getSwitchCallType2() && !SettingUtil.getSwitchCallType3()) {
Toast.makeText(context, R.string.enable_phone_fw_tips, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.enable_phone_fw_tips);
SettingUtil.switchEnablePhone(false);
}
});
@ -247,7 +247,7 @@ public class SettingActivity extends AppCompatActivity {
check_box_call_type_2.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingUtil.switchCallType2(isChecked);
if (!isChecked && !SettingUtil.getSwitchCallType1() && !SettingUtil.getSwitchCallType2() && !SettingUtil.getSwitchCallType3()) {
Toast.makeText(context, R.string.enable_phone_fw_tips, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.enable_phone_fw_tips);
SettingUtil.switchEnablePhone(false);
}
});
@ -255,7 +255,7 @@ public class SettingActivity extends AppCompatActivity {
check_box_call_type_3.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingUtil.switchCallType3(isChecked);
if (!isChecked && !SettingUtil.getSwitchCallType1() && !SettingUtil.getSwitchCallType2() && !SettingUtil.getSwitchCallType3()) {
Toast.makeText(context, R.string.enable_phone_fw_tips, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.enable_phone_fw_tips);
SettingUtil.switchEnablePhone(false);
}
});
@ -275,10 +275,10 @@ public class SettingActivity extends AppCompatActivity {
if (isChecked) {
if (!CommonUtil.isNotificationListenerServiceEnabled(this)) {
CommonUtil.openNotificationAccess(this);
Toast.makeText(this, R.string.tips_notification_listener, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.tips_notification_listener, 3000);
return;
} else {
Toast.makeText(this, R.string.notification_service_is_on, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.notification_service_is_on, 3000);
CommonUtil.toggleNotificationListenerService(this);
}
}
@ -298,7 +298,7 @@ public class SettingActivity extends AppCompatActivity {
if (!CommonUtil.isNotificationListenerServiceEnabled(this)) {
CommonUtil.openNotificationAccess(this);
} else {
Toast.makeText(this, R.string.notification_listener_service_enabled, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.notification_listener_service_enabled);
CommonUtil.toggleNotificationListenerService(this);
}
}
@ -308,11 +308,11 @@ public class SettingActivity extends AppCompatActivity {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CommonUtil.NOTIFICATION_REQUEST_CODE) {
if (CommonUtil.isNotificationListenerServiceEnabled(this)) {
Toast.makeText(this, R.string.notification_listener_service_enabled, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.notification_listener_service_enabled);
CommonUtil.toggleNotificationListenerService(this);
SettingUtil.switchEnableAppNotify(true);
} else {
Toast.makeText(this, R.string.notification_listener_service_disabled, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.notification_listener_service_disabled);
SettingUtil.switchEnableAppNotify(false);
}
@ -416,7 +416,7 @@ public class SettingActivity extends AppCompatActivity {
cb_battery_level_alarm_once.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingUtil.switchBatteryLevelAlarmOnce(isChecked);
if (isChecked && 0 == SettingUtil.getBatteryLevelAlarmMin() && 0 == SettingUtil.getBatteryLevelAlarmMax()) {
Toast.makeText(context, R.string.tips_battery_level_alarm_once, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.tips_battery_level_alarm_once);
SettingUtil.switchEnablePhone(false);
}
});
@ -600,7 +600,7 @@ public class SettingActivity extends AppCompatActivity {
}
}
if (!has) {
Toast.makeText(context, R.string.tips_compatible_solution, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.tips_compatible_solution);
try {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@ -627,10 +627,10 @@ public class SettingActivity extends AppCompatActivity {
if (isChecked && !isIgnoreBatteryOptimization) {
KeepAliveUtils.ignoreBatteryOptimization(this);
} else if (isChecked) {
Toast.makeText(this, R.string.isIgnored, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.isIgnored);
switch_battery_setting.setChecked(isIgnoreBatteryOptimization);
} else {
Toast.makeText(this, R.string.isIgnored2, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.isIgnored2);
switch_battery_setting.setChecked(isIgnoreBatteryOptimization);
}
});

View File

@ -3,8 +3,8 @@ package com.idormy.sms.forwarder.sender;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.R;
import com.idormy.sms.forwarder.model.vo.SmsHubVo;
import com.idormy.sms.forwarder.receiver.BaseServlet;
@ -52,13 +52,13 @@ public class HttpServer {
public synchronized static boolean update() {
//非WiFi网络下不可启用
if (NetUtil.NETWORK_WIFI != NetUtil.getNetWorkStatus()) {
Toast.makeText(context, R.string.no_wifi_network, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.no_wifi_network);
if (asRunning()) stop();
return false;
}
long l = System.currentTimeMillis();
if (l - ts < 3000 && asRunning()) {
Toast.makeText(context, R.string.tips_wait_3_seconds, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.tips_wait_3_seconds);
return false;
}
if (asRunning().equals(SettingUtil.getSwitchEnableHttpServer())) {
@ -68,10 +68,10 @@ public class HttpServer {
SmsHubVo.getDevInfoMap(true);
start();
ts = System.currentTimeMillis();
Toast.makeText(context, R.string.server_has_started, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.server_has_started);
} else {
stop();
Toast.makeText(context, R.string.server_has_stopped, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.server_has_stopped);
}
return true;
}

View File

@ -3,12 +3,12 @@ package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.hjq.toast.ToastUtils;
import java.io.IOException;
import java.net.URLEncoder;
@ -92,7 +92,7 @@ public class HttpUtil {
public static void Toast(String Tag, String data) {
Log.i(Tag, data);
try {
Toast.makeText(HttpUtil.context, Tag + "-" + data, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(Tag + "-" + data, 3000);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -9,10 +9,10 @@ import android.net.Uri;
import android.os.Build;
import android.os.PowerManager;
import android.provider.Settings;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.R;
public class KeepAliveUtils {
@ -38,7 +38,7 @@ public class KeepAliveUtils {
if (resolveInfo != null) {
activity.startActivity(intent);
} else {
Toast.makeText(activity, R.string.unsupport, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.unsupport);
}
}
}

View File

@ -6,8 +6,8 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.widget.Toast;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.R;
public class NetUtil {
@ -42,17 +42,17 @@ public class NetUtil {
//判断是否是wifi
if (activeNetworkInfo.getType() == (ConnectivityManager.TYPE_WIFI)) {
//返回无线网络
Toast.makeText(context, R.string.on_wireless_network, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.on_wireless_network);
return NETWORK_WIFI;
//判断是否移动网络
} else if (activeNetworkInfo.getType() == (ConnectivityManager.TYPE_MOBILE)) {
Toast.makeText(context, R.string.on_mobile_network, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.on_mobile_network);
//返回移动网络
return NETWORK_MOBILE;
}
} else {
//没有网络
Toast.makeText(context, R.string.no_network, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.no_network);
return NETWORK_NONE;
}
//默认返回 没有网络

View File

@ -10,8 +10,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.hjq.toast.ToastUtils;
import com.idormy.sms.forwarder.R;
import java.util.regex.Pattern;
@ -58,7 +58,7 @@ public class IPEditText extends LinearLayout {
ip1 = ip1.substring(0, lenIp1 - 1);
Edit1.setText(ip1);
Edit1.setSelection(ip1.length());
Toast.makeText(context, R.string.invalid_ip, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_ip, 3000);
return;
}
//非空输入 . 跳到下一个输入框
@ -94,7 +94,7 @@ public class IPEditText extends LinearLayout {
ip2 = ip2.substring(0, lenIp2 - 1);
Edit2.setText(ip2);
Edit2.setSelection(ip2.length());
Toast.makeText(context, R.string.invalid_ip, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_ip, 3000);
return;
}
//非空输入 . 跳到下一个输入框
@ -131,7 +131,7 @@ public class IPEditText extends LinearLayout {
ip3 = ip3.substring(0, lenIp3 - 1);
Edit3.setText(ip3);
Edit3.setSelection(ip3.length());
Toast.makeText(context, R.string.invalid_ip, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_ip, 3000);
return;
}
//非空输入 . 跳到下一个输入框
@ -168,7 +168,7 @@ public class IPEditText extends LinearLayout {
ip4 = ip4.substring(0, lenIp4 - 1);
Edit4.setText(ip4);
Edit4.setSelection(ip4.length());
Toast.makeText(context, R.string.invalid_ip, Toast.LENGTH_LONG).show();
ToastUtils.delayedShow(R.string.invalid_ip, 3000);
}
}