秒验使用adapter自定义UI示例
一、设置AdapterClass
SecVerify.setAdapterClass(MyLoginAdapter.class);
二、MyLoginAdapter内容
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.mob.secverify.ui.component.LoginAdapter;
/**
* 使用Adapter的方式修改授权页面ui,通过修改授权页面的控件属性,达到修改目的
* <p>
* * todo 需要注意以下内容
* * 1、在结束当前授权页面时需要调用SecVerify.finishOAuthPage();来结束,否则会影响下次进入
* * 2、在点击登录之后,不论登录成功或者失败,需要SecVerify.finishOAuthPage();结束当前页面, 否则会影响电信授权页面的回调导致页面无法结束
* * 3、设置脱敏手机号需要在onResume中设置,onCreate中可能还未拿到这个脱敏手机号
*/
public class MyLoginAdapter extends LoginAdapter {
private Activity activity;
private ViewGroup vgBody;
private LinearLayout vgContainer;
private RelativeLayout rlTitle;
private Button btnLogin;
private TextView tvSecurityPhone;
private TextView tvOwnPhone;
private TextView tvAgreement;
private CheckBox cbAgreement;
private View contentView;
//可用于判断展示运营商隐私协议
private String operator;
private String url;
@Override
public void onCreate() {
super.onCreate();
//获取授权页面原有控件
init();
}
private void init() {
vgBody = getBodyView();
vgContainer = (LinearLayout) getContainerView();
activity = getActivity();
rlTitle = getTitlelayout();
btnLogin = getLoginBtn();
tvSecurityPhone = getSecurityPhoneText();
cbAgreement = getAgreementCheckbox();
operator = getOperatorName();
//隐藏 授权页面原有内容
vgBody.setVisibility(View.GONE);
rlTitle.setVisibility(View.GONE);
//获取自己的View
contentView = View.inflate(activity, R.layout.sec_diy, null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
//添加自己的View到授权页面上,注意不要使用Activity来设置
vgContainer.addView(contentView, params);
tvSecurityPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(activity, "asdadasd" + tvSecurityPhone.getText(), Toast.LENGTH_SHORT).show();
}
});
// RxBus.getInstance().toObserverable(Object.class)
// .subscribe(new Action1<Object>() {
// @Override
// public void call(Object studentEvent) {
// Toast.makeText(activity, "我是adapter里的toast", Toast.LENGTH_SHORT).show();
// }
// });
}
@Override
public void onResume() {
super.onResume();
Toast.makeText(activity, "手机号" + tvSecurityPhone.getText(), Toast.LENGTH_SHORT).show();
TextView phone = contentView.findViewById(R.id.phone);
phone.setText(getSecurityPhoneText().getText());
contentView.findViewById(R.id.login_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//点击自己登录按钮时需要将默认的复选框设置为选中,并且点击原有的授权页面登录按钮
cbAgreement.setChecked(true);
btnLogin.performClick();
}
});
}
public MyLoginAdapter() {
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(activity, "我关闭了", Toast.LENGTH_SHORT).show();
}
}
三、其他
1、获取脱敏手机号
在onResume方法中使用getSecurityPhoneText().getText()获取
2、添加转场动画
可以在使用adapter的同时,设置UIsetting的动画设置
UiSettings uiSettings = new UiSettings.Builder()
.setTranslateAnim(true)
.build();
SecVerify.setUiSettings(uiSettings);
SecVerify.setAdapterClass(MyLoginAdapter.class);
这样在调用秒验登录接口时,就会加上从左往右平移动画了,其他的动画可以看官网