Ultra-SDP v1.0.0版本的 MD5 值为:5418115cd4b552c4cd79d6d68815af17
以下内容为反编译后的 ZtaMainActivity.java 源代码,内容仅作参考
package com.zta.android.activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.widget.PopupMenu;
import com.xuexiang.xutil.display.Colors;
import com.zta.android.R;
import com.zta.android.model.GatewayInfo;
import com.zta.android.model.LoginInfo;
import com.zta.android.model.ServerInfo;
import com.zta.android.viewmodel.MainViewModel;
import com.zta.util.Keys;
import com.zta.util.SharePrefrenceManager;
import com.zta.util.ZtaSDKManager;
import java.util.Iterator;
import java.util.regex.Pattern;
public class ZtaMainActivity extends BasicActivity implements View.OnClickListener {
private static final String TAG = ZtaMainActivity.class.getSimpleName();
private TextView currentTimeView;
private View iv_more;
private MainViewModel mainViewModel;
private PopupMenu more;
private ViewGroup server_ip_container;
private ViewGroup server_item_container;
private final int serverlifetime = 273;
private final int GoToUrlMessage = 274;
private final int GoTo4AApp = 275;
private final int GoToUrl = 276;
private Handler handler = new Handler(Looper.myLooper()) {
@Override
public void handleMessage(Message message) {
super.handleMessage(message);
switch (message.what) {
case 273:
int intValue = ((Integer) message.obj).intValue();
if (intValue <= 0) {
ZtaMainActivity.this.handler.removeMessages(273);
ZtaMainActivity.this.stopVpn();
return;
}
if (ZtaMainActivity.this.currentTimeView != null) {
TextView textView = ZtaMainActivity.this.currentTimeView;
textView.setText(intValue + "分钟");
}
Message obtain = Message.obtain();
obtain.obj = Integer.valueOf(intValue - 1);
obtain.what = 273;
sendMessageDelayed(obtain, 60000L);
return;
case 274:
Bundle data = message.getData();
String string = data.getString("accessToken");
int i = data.getInt("appid");
String str = null;
for (GatewayInfo gatewayInfo : ((LoginInfo) ZtaMainActivity.this.getIntent().getParcelableExtra("loginData")).getGateway()) {
Iterator<ServerInfo> it = gatewayInfo.getAllowed_servers().iterator();
while (true) {
if (it.hasNext()) {
ServerInfo next = it.next();
if (i == next.getAppid().intValue()) {
str = next.getUrl();
}
}
}
}
if (TextUtils.isEmpty(str)) {
Toast.makeText(ZtaMainActivity.this, "无跳转地址!", 0).show();
return;
} else if (str.indexOf("://") <= -1) {
if (ZtaMainActivity.this.isPkg(str)) {
ZtaMainActivity ztaMainActivity = ZtaMainActivity.this;
if (ztaMainActivity.checkAppInstalled(ztaMainActivity.getApplicationContext(), str)) {
Intent launchIntentForPackage = ZtaMainActivity.this.getPackageManager().getLaunchIntentForPackage(str);
launchIntentForPackage.putExtra(Keys.TOKEN, string);
ZtaMainActivity.this.startActivity(launchIntentForPackage);
return;
}
}
ZtaMainActivity ztaMainActivity2 = ZtaMainActivity.this;
Toast.makeText(ztaMainActivity2, "无法跳转到地址:" + str, 0).show();
return;
} else {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(str));
intent.addFlags(268435456);
try {
ZtaMainActivity.this.startActivityForResult(intent, -1);
return;
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(ZtaMainActivity.this, "没有匹配的APP,请下载安装", 0).show();
return;
}
}
case 275:
String string2 = SharePrefrenceManager.get().getString(Keys.ACCESS_TOKEN);
if (TextUtils.isEmpty(string2)) {
Toast.makeText(ZtaMainActivity.this, "无法获取到Token", 0).show();
return;
}
ZtaMainActivity ztaMainActivity3 = ZtaMainActivity.this;
if (ztaMainActivity3.checkAppInstalled(ztaMainActivity3.getApplicationContext(), "ultrapower.ultrasafe.new4a")) {
Intent launchIntentForPackage2 = ZtaMainActivity.this.getPackageManager().getLaunchIntentForPackage("ultrapower.ultrasafe.new4a");
Log.i(ZtaMainActivity.TAG, string2);
launchIntentForPackage2.putExtra(Keys.TOKEN, string2);
ZtaMainActivity.this.startActivity(launchIntentForPackage2);
return;
}
Toast.makeText(ZtaMainActivity.this, "请安装4A客户端", 0).show();
return;
case 276:
ZtaMainActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://www.baidu.com")));
return;
default:
return;
}
}
};
public boolean isPkg(String str) {
return Pattern.compile("^([a-zA-Z_][a-zA-Z0-9_]*)+([.][a-zA-Z_][a-zA-Z0-9_]*)+$").matcher(str).matches();
}
public boolean checkAppInstalled(Context context, String str) {
PackageInfo packageInfo;
if (str == null || str.isEmpty()) {
return false;
}
try {
packageInfo = context.getPackageManager().getPackageInfo(str, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
packageInfo = null;
}
return packageInfo != null;
}
@Override
public void onClick(View view) {
String string = SharePrefrenceManager.get().getString(Keys.QUICK_LOGIN_TOKEN);
String string2 = SharePrefrenceManager.get().getString(Keys.ACCESS_TOKEN);
Message message = new Message();
message.what = 274;
Bundle bundle = new Bundle();
bundle.putString("quickLoginToken", string);
bundle.putString("accessToken", string2);
bundle.putInt("appid", view.getId());
message.setData(bundle);
this.handler.sendMessage(message);
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_zta_main);
initView();
initData();
goToHome();
}
private void goToHome() {
String encode = Uri.encode(((LoginInfo) getIntent().getParcelableExtra("loginData")).getUrl(), "/:?&=");
Log.i(TAG, encode);
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri parse = Uri.parse(encode);
Log.i(TAG, parse.getPath());
intent.setData(parse);
startActivity(intent);
}
private void initView() {
this.server_item_container = (ViewGroup) findViewById(R.id.server_item_container);
this.server_ip_container = (ViewGroup) findViewById(R.id.server_ip_container);
this.iv_more = findViewById(R.id.iv_more);
findViewById(R.id.btn_loginout).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
ZtaMainActivity.this.lambda$initView$0$ZtaMainActivity(view);
}
});
findViewById(R.id.btn_4a_app).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
ZtaMainActivity.this.lambda$initView$1$ZtaMainActivity(view);
}
});
this.more = new PopupMenu(this, this.iv_more);
this.more.getMenuInflater().inflate(R.menu.pop_more, this.more.getMenu());
this.more.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public final boolean onMenuItemClick(MenuItem menuItem) {
return ZtaMainActivity.this.lambda$initView$2$ZtaMainActivity(menuItem);
}
});
this.iv_more.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
ZtaMainActivity.this.lambda$initView$3$ZtaMainActivity(view);
}
});
}
public void lambda$initView$0$ZtaMainActivity(View view) {
stopVpn();
}
public void lambda$initView$1$ZtaMainActivity(View view) {
Message message = new Message();
message.what = 276;
this.handler.sendMessage(message);
}
public boolean lambda$initView$2$ZtaMainActivity(MenuItem menuItem) {
int itemId = menuItem.getItemId();
if (itemId == R.id.change_psd) {
startActivity(new Intent(this, ForgetPasswordActivity.class));
return true;
} else if (itemId != R.id.goto_home) {
return true;
} else {
goToHome();
return true;
}
}
public void lambda$initView$3$ZtaMainActivity(View view) {
this.more.show();
}
private void initData() {
this.mainViewModel = new MainViewModel(getApplicationContext());
LoginInfo loginInfo = (LoginInfo) getIntent().getParcelableExtra("loginData");
initTimer(loginInfo.getLifetime());
startVpn(loginInfo);
initServerInfo(loginInfo);
}
private void initServerInfo(LoginInfo loginInfo) {
this.server_item_container.addView(initServerItemInfo("当前用户", SharePrefrenceManager.get().getString(Keys.USER_NAME)));
String usrID = loginInfo.getUsrID();
if (!TextUtils.isEmpty(usrID) && usrID.length() > 4) {
this.server_item_container.addView(initServerItemInfo("用户ID", usrID.substring(0, 4) + "******" + usrID.substring(usrID.length() - 4, usrID.length())));
}
View initServerItemInfo = initServerItemInfo("ID时效", loginInfo.getLifetime() + "分钟");
this.currentTimeView = (TextView) initServerItemInfo.findViewById(R.id.tv_serverInfo_msg);
this.server_item_container.addView(initServerItemInfo);
}
private View initServerItemInfo(String str, String str2) {
View inflate = LayoutInflater.from(this).inflate(R.layout.server_item, (ViewGroup) null);
((TextView) inflate.findViewById(R.id.tv_serverInfo_msg)).setText(str2);
((TextView) inflate.findViewById(R.id.tv_item_name)).setText(str);
return inflate;
}
private View initServerIpItemInfo(String str, String str2, String str3, String str4, Integer num, String str5) {
View inflate = LayoutInflater.from(this).inflate(R.layout.server_ip_item, (ViewGroup) null);
TextView textView = (TextView) inflate.findViewById(R.id.tv_appname);
TextView textView2 = (TextView) inflate.findViewById(R.id.tv_server_address);
if (!TextUtils.isEmpty(str)) {
if (!TextUtils.isEmpty(str5)) {
textView.setText(Html.fromHtml("<u>" + str + "</u>"));
textView.setTextColor(Colors.BLUE);
} else {
textView.setText(str);
}
}
if (!TextUtils.isEmpty(str2)) {
textView2.setText(str2);
}
TextView textView3 = (TextView) inflate.findViewById(R.id.tv_protocol);
if (!TextUtils.isEmpty(str3)) {
textView3.setText(str3);
}
TextView textView4 = (TextView) inflate.findViewById(R.id.tv_prot);
if (!TextUtils.isEmpty(str4)) {
textView4.setText(str4);
}
if (num != null) {
inflate.setId(num.intValue());
}
return inflate;
}
private void initServerIpList(LoginInfo loginInfo) {
this.server_ip_container.addView(initServerIpItemInfo("", "", "", "", null, null));
for (GatewayInfo gatewayInfo : loginInfo.getGateway()) {
for (ServerInfo serverInfo : gatewayInfo.getAllowed_servers()) {
String ip = serverInfo.getIp();
String name = serverInfo.getName();
String protocol = serverInfo.getProtocol();
View initServerIpItemInfo = initServerIpItemInfo(name, ip, protocol, serverInfo.getPort() + "", serverInfo.getAppid(), serverInfo.getUrl());
initServerIpItemInfo.setOnClickListener(this);
this.server_ip_container.addView(initServerIpItemInfo);
}
}
}
private void initTimer(int i) {
Message obtain = Message.obtain();
obtain.what = 273;
obtain.obj = Integer.valueOf(i);
this.handler.sendMessage(obtain);
}
@Override
public void onBackPressed() {
moveTaskToBack(true);
}
private void startVpn(LoginInfo loginInfo) {
ZtaSDKManager.getInstance().startVpn(this, loginInfo);
}
public void stopVpn() {
ZtaSDKManager.getInstance().stopVpn(this);
}
@Override
public void onActivityResult(int i, int i2, Intent intent) {
super.onActivityResult(i, i2, intent);
}
}