Skip to content

Commit

Permalink
优化:统一使用吐司框架 ToastUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
pppscn committed Jan 30, 2022
1 parent e329308 commit bfdc0e4
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 140 deletions.
20 changes: 10 additions & 10 deletions app/src/main/java/com/idormy/sms/forwarder/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
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;
Expand All @@ -25,7 +25,6 @@

public class AboutActivity extends AppCompatActivity {

@SuppressWarnings("FieldCanBeLocal")
private final String TAG = "AboutActivity";

@Override
Expand All @@ -46,21 +45,21 @@ public void onCreate(Bundle savedInstanceState) {
@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);
}

@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);
}
Expand All @@ -78,20 +77,21 @@ public void onDenied(List<String> permissions, boolean never) {
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();
Expand All @@ -115,7 +115,7 @@ public void noNewVersion(Throwable throwable) {
} 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);
Expand All @@ -142,7 +142,7 @@ public void joinQQGroup(String key) {
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
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;

Expand All @@ -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);
Expand Down Expand Up @@ -91,7 +91,7 @@ protected void onStart() {
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);
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/idormy/sms/forwarder/CloneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -110,6 +110,7 @@ protected void onStart() {
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));
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/idormy/sms/forwarder/CrashHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
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;
Expand Down Expand Up @@ -99,7 +100,7 @@ private boolean handleException(Throwable ex) {
@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();
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/java/com/idormy/sms/forwarder/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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;
Expand All @@ -29,6 +28,7 @@
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;
Expand Down Expand Up @@ -171,21 +171,21 @@ protected void onStart() {
@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);
}

@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);
}
Expand Down Expand Up @@ -248,7 +248,7 @@ public void onDenied(List<String> permissions, boolean never) {
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()方法
Expand Down Expand Up @@ -293,15 +293,15 @@ protected void onResume() {
//省电优化设置为无限制
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);
}
}

//开启读取通知栏权限
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;
}

Expand Down Expand Up @@ -349,10 +349,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent 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);
} else {
Toast.makeText(this, R.string.notification_listener_service_disabled, Toast.LENGTH_SHORT).show();
ToastUtils.show(R.string.notification_listener_service_disabled);
}
}
}
Expand Down Expand Up @@ -411,7 +411,7 @@ public void logDetail(LogVo logVo) {
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();
});

Expand All @@ -424,7 +424,7 @@ public void logDetail(LogVo logVo) {
//对于发送失败的消息添加重发按钮
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();
});
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/com/idormy/sms/forwarder/RuleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
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;
Expand Down Expand Up @@ -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);
}
}
};
Expand Down Expand Up @@ -103,7 +103,7 @@ protected void onStart() {
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) -> {
Expand Down Expand Up @@ -216,7 +216,7 @@ private void setRule(final RuleModel ruleModel, final boolean isClone) {
}
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);
});

Expand Down Expand Up @@ -261,15 +261,15 @@ private void setRule(final RuleModel ruleModel, final boolean isClone) {
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;
}

//检查正则替换填写是否正确
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;
}

Expand Down Expand Up @@ -321,15 +321,15 @@ private void setRule(final RuleModel ruleModel, final boolean isClone) {
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;
}

//检查正则替换填写是否正确
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;
}

Expand Down Expand Up @@ -525,7 +525,7 @@ private void refreshSelectRadioGroupRuleFiledAction(int checkedRuleFiledId, fina
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()];
Expand All @@ -536,7 +536,7 @@ public void selectSender(final TextView showTv) {
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());
});
Expand Down Expand Up @@ -583,7 +583,7 @@ public void testRule(final RuleModel ruleModel, final Long senderId) {
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();// 显示对话框
Expand Down
Loading

0 comments on commit bfdc0e4

Please sign in to comment.