修改令牌展示方式
This commit is contained in:
@@ -2,11 +2,15 @@ package com.mogo.cloud;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.mogo.cloud.network.NetworkActivity;
|
||||
import com.mogo.cloud.passport.IMoGoTokenCallback;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@@ -14,15 +18,32 @@ public class MainActivity extends AppCompatActivity {
|
||||
private Button btnJumpNetWorkPort;
|
||||
private Button btnJumpRealTime;
|
||||
|
||||
private TextView tvSn;
|
||||
private TextView tvToken;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
tvSn = findViewById(R.id.tvSn);
|
||||
tvToken = findViewById(R.id.tvToken);
|
||||
|
||||
initPassportInfo();
|
||||
|
||||
btnJumpPassPort = findViewById(R.id.btnJumpPassPort);
|
||||
btnJumpPassPort.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(MainActivity.this, PassPortActivity.class);
|
||||
startActivity(intent);
|
||||
MoGoAiCloudClient.getInstance().refreshToken(new IMoGoTokenCallback() {
|
||||
@Override
|
||||
public void onTokenGot(String token, String sn) {
|
||||
initPassportInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int code, String msg) {
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
btnJumpNetWorkPort = findViewById(R.id.btnJumpNetWorkPort);
|
||||
@@ -37,4 +58,21 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化令牌信息
|
||||
*/
|
||||
private void initPassportInfo() {
|
||||
String sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
|
||||
String token = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getToken();
|
||||
|
||||
if (TextUtils.isEmpty(sn)) {
|
||||
sn = "获取失败,请重试";
|
||||
}
|
||||
if (TextUtils.isEmpty(token)) {
|
||||
token = "获取失败,请重试";
|
||||
}
|
||||
tvSn.setText("SN:" + sn);
|
||||
tvToken.setText("Token:" + token);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.mogo.cloud;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.mogo.cloud.network.NetworkActivity;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
|
||||
/**
|
||||
* 鉴权sdk测试页面
|
||||
*/
|
||||
public class PassPortActivity extends AppCompatActivity {
|
||||
|
||||
private Button btnRefreshToken;
|
||||
private TextView tvSn;
|
||||
private TextView tvToken;
|
||||
|
||||
private Button btnJumpToNet;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_pass_port_actvity);
|
||||
|
||||
btnRefreshToken = findViewById(R.id.btnRefreshToken);
|
||||
tvSn = findViewById(R.id.tvSn);
|
||||
tvToken = findViewById(R.id.tvToken);
|
||||
btnJumpToNet = findViewById(R.id.btnJumpToNet);
|
||||
|
||||
btnRefreshToken.setOnClickListener(v -> {
|
||||
tvSn.setText("SN:" + MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
|
||||
tvToken.setText("Token:" + MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getToken());
|
||||
});
|
||||
|
||||
btnJumpToNet.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(this, NetworkActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,27 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="SN:"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvToken"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="Token:"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJumpPassPort"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="跳转PassPort测试" />
|
||||
android:text="刷新令牌" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJumpNetWorkPort"
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".PassPortActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnRefreshToken"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="刷新令牌" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="SN:"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvToken"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Token:"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJumpToNet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="跳转到网络测试" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -86,6 +86,11 @@ public class MoGoAiCloudClient {
|
||||
Log.i(TAG, "║ SN:" + result.sn);
|
||||
Log.i(TAG, "║ Token:" + result.token);
|
||||
Log.i(TAG, "═════════════════════════════════════");
|
||||
|
||||
// 本地存储
|
||||
SpStorage.setSn(result.sn);
|
||||
SpStorage.setToken(result.token);
|
||||
|
||||
if (tokenCallback != null) {
|
||||
tokenCallback.onTokenGot(result.token, result.sn);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.mogo.cloud.passport;
|
||||
|
||||
import com.mogo.utils.storage.SharedPrefsMgr;
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
* @since 2021-01-28
|
||||
* <p>
|
||||
* sp 公共缓存区域
|
||||
*/
|
||||
public class SpStorage {
|
||||
|
||||
public static String getToken() {
|
||||
return SharedPrefsMgr.getInstance(MoGoAiCloudClient.getInstance().getContext()).getString("token");
|
||||
}
|
||||
|
||||
public static void setToken(String token) {
|
||||
SharedPrefsMgr.getInstance(MoGoAiCloudClient.getInstance().getContext()).putString("token", token);
|
||||
}
|
||||
|
||||
public static String getSn() {
|
||||
return SharedPrefsMgr.getInstance(MoGoAiCloudClient.getInstance().getContext()).getString("sn");
|
||||
}
|
||||
|
||||
public static void setSn(String sn) {
|
||||
SharedPrefsMgr.getInstance(MoGoAiCloudClient.getInstance().getContext()).putString("sn", sn);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user