master
parent
da227ac250
commit
06b52153ce
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 380 KiB |
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
package com.test.weapon;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.test.weapon", appContext.getPackageName());
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,43 @@
|
||||
package com.test.weapon.Adapter;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
|
||||
import com.test.weapon.R;
|
||||
import com.test.weapon.bean.GetWeaponList;
|
||||
import com.test.weapon.util.AppData;
|
||||
import com.test.weapon.util.SmartImageView;
|
||||
|
||||
public class ChooseProductAdapter extends BaseQuickAdapter<GetWeaponList, BaseViewHolder> {
|
||||
|
||||
|
||||
public ChooseProductAdapter(int layoutResId) {
|
||||
super(layoutResId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(@NonNull BaseViewHolder baseViewHolder, GetWeaponList data) {
|
||||
baseViewHolder.setText(R.id.tv_maybe_like_name,data.getName());
|
||||
baseViewHolder.getView(R.id.choose_cb);
|
||||
CheckBox checkBox = baseViewHolder.getView(R.id.choose_cb);
|
||||
checkBox.setChecked(data.isChoose());
|
||||
SmartImageView siv_maybe_like=baseViewHolder.getView(R.id.siv_maybe_like);
|
||||
|
||||
siv_maybe_like.setImageUrl(AppData.PicAddress+data.getImgPath(), new SmartImageView.onCompleteListener() {
|
||||
@Override
|
||||
public void onSuccess(Bitmap bitmap) {
|
||||
System.out.println("----------------------success");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
System.out.println("----------------------failed");
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.test.weapon;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.hjq.http.EasyConfig;
|
||||
import com.hjq.http.config.IRequestInterceptor;
|
||||
import com.hjq.http.config.IRequestServer;
|
||||
import com.hjq.http.model.HttpHeaders;
|
||||
import com.hjq.http.model.HttpParams;
|
||||
import com.hjq.http.request.HttpRequest;
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.test.weapon.http.ReleaseServer;
|
||||
import com.test.weapon.http.RequestHandler;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
|
||||
public class AppApplication extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Toaster.init(this);
|
||||
|
||||
|
||||
// 网络请求框架初始化
|
||||
IRequestServer server;
|
||||
server = new ReleaseServer();
|
||||
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.build();
|
||||
|
||||
EasyConfig.with(okHttpClient)
|
||||
// 是否打印日志
|
||||
.setLogEnabled(BuildConfig.DEBUG)
|
||||
// 设置服务器配置(必须设置)
|
||||
.setServer(server)
|
||||
// 设置请求处理策略(必须设置)
|
||||
.setHandler(new RequestHandler(this))
|
||||
// 设置请求参数拦截器
|
||||
.setInterceptor(new IRequestInterceptor() {
|
||||
@Override
|
||||
public void interceptArguments(@NonNull HttpRequest<?> httpRequest,
|
||||
@NonNull HttpParams params,
|
||||
@NonNull HttpHeaders headers) {
|
||||
}
|
||||
})
|
||||
|
||||
// 设置请求重试次数
|
||||
.setRetryCount(1)
|
||||
// 设置请求重试时间
|
||||
.setRetryTime(2000)
|
||||
|
||||
.into();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.test.weapon;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.hjq.http.listener.OnHttpListener;
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.test.weapon.http.HttpData;
|
||||
|
||||
|
||||
public class BaseFragment extends Fragment implements OnHttpListener<Object> {
|
||||
@Override
|
||||
public void onSucceed(Object result) {
|
||||
if (result instanceof HttpData) {
|
||||
Toaster.show(((HttpData<?>) result).getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(Exception e) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package com.test.weapon;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
|
||||
import com.chad.library.adapter.base.listener.OnItemClickListener;
|
||||
import com.hjq.http.EasyHttp;
|
||||
import com.hjq.http.body.JsonBody;
|
||||
import com.hjq.http.listener.HttpCallback;
|
||||
import com.hjq.http.listener.OnHttpListener;
|
||||
import com.test.weapon.Adapter.ChooseProductAdapter;
|
||||
import com.test.weapon.Adapter.SearchProductAdapter;
|
||||
import com.test.weapon.api.GetWeaponApi;
|
||||
import com.test.weapon.bean.GetWeaponList;
|
||||
import com.test.weapon.http.HttpData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
public class ChooseActivity extends AppCompatActivity {
|
||||
|
||||
private RecyclerView rvSearch;
|
||||
private List<GetWeaponList> dataSearch;
|
||||
private ChooseProductAdapter adapter;
|
||||
private TextView choose_success;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_choose);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView(){
|
||||
findViewById(R.id.img_close).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
rvSearch=findViewById(R.id.rv_search);
|
||||
choose_success=findViewById(R.id.choose_success);
|
||||
adapter = new ChooseProductAdapter(R.layout.item_choose_products);
|
||||
rvSearch.setLayoutManager(new LinearLayoutManager(ChooseActivity.this));
|
||||
rvSearch.setAdapter(adapter);
|
||||
adapter.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
||||
for (int i=0;i<dataSearch.size();i++){
|
||||
dataSearch.get(i).setChoose(false);
|
||||
}
|
||||
dataSearch.get(position).setChoose(!dataSearch.get(position).isChoose());
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
choose_success.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean isHaveChoose=false;
|
||||
|
||||
for (int i=0;i<dataSearch.size();i++){
|
||||
if (dataSearch.get(i).isChoose()){
|
||||
GetWeaponList data=dataSearch.get(i);
|
||||
Intent intent=new Intent();
|
||||
intent.putExtra("data",data);
|
||||
setResult(RESULT_OK,intent);
|
||||
finish();
|
||||
isHaveChoose=true;
|
||||
}
|
||||
|
||||
}
|
||||
if (!isHaveChoose){
|
||||
Toasty.info(ChooseActivity.this,"请选择一个武器作对比").show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
initData();
|
||||
}
|
||||
private void initData(){
|
||||
dataSearch= new ArrayList<>();
|
||||
Map<String ,String> map=new HashMap<>();
|
||||
map.put("pageNo","1");
|
||||
map.put("pageSize","10");
|
||||
EasyHttp.post(this)
|
||||
.api(new GetWeaponApi()
|
||||
)
|
||||
.body(new JsonBody(map))
|
||||
.request(new HttpCallback<HttpData<List<GetWeaponList>>>(new OnHttpListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public void onSucceed(Object o) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(Exception e) {
|
||||
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
public void onSucceed(HttpData<List<GetWeaponList>> result) {
|
||||
dataSearch.addAll(result.getData());
|
||||
adapter.addData(dataSearch);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.test.weapon;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
private EditText etUserName;
|
||||
private EditText etPassword;
|
||||
private Button btnLogin;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
ImmersionBar.with(this)
|
||||
.statusBarDarkFont(true, 0.2f) //原理:如果当前设备支持状态栏字体变色,会设置状态栏字体为黑色,如果当前设备不支持状态栏字体变色,会使当前状态栏加上透明度,否则不执行透明度
|
||||
.init();
|
||||
etUserName=(EditText) findViewById(R.id.et_userName);
|
||||
etPassword=(EditText) findViewById(R.id.et_password);
|
||||
btnLogin=(Button) findViewById(R.id.btn_login);
|
||||
btnLogin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
login();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*/
|
||||
private void login(){
|
||||
String userName=etUserName.getText().toString().trim();
|
||||
String password=etPassword.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(userName)){
|
||||
Toasty.info(LoginActivity.this, "请输入用户名", Toast.LENGTH_SHORT, true).show();
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(password)){
|
||||
Toasty.info(LoginActivity.this, "请输入密码", Toast.LENGTH_SHORT, true).show();
|
||||
return;
|
||||
}
|
||||
Toasty.success(LoginActivity.this, "登录成功!", Toast.LENGTH_SHORT, true).show();
|
||||
startActivity(new Intent(LoginActivity.this,MainActivity.class));
|
||||
finish();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.test.weapon.api;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.hjq.http.annotation.HttpHeader;
|
||||
import com.hjq.http.annotation.HttpRename;
|
||||
import com.hjq.http.config.IRequestApi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GetWarningApi implements IRequestApi {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getApi() {
|
||||
return "/weaponry/weaponry/getLocationWarningPageList";
|
||||
}
|
||||
|
||||
|
||||
@HttpHeader
|
||||
@HttpRename("Content-Type")
|
||||
private String contentType = "application/json;charset=utf-8";
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
package com.test.weapon.api;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.hjq.http.annotation.HttpHeader;
|
||||
import com.hjq.http.annotation.HttpRename;
|
||||
import com.hjq.http.config.IRequestApi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GetWeaponApi implements IRequestApi {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getApi() {
|
||||
return "/weaponry/weaponry/getPageList";
|
||||
}
|
||||
@HttpRename("pageNo")
|
||||
private String pageNo;
|
||||
|
||||
public GetWeaponApi setPageNo(String pageNo) {
|
||||
this.pageNo = pageNo;
|
||||
return this;
|
||||
}
|
||||
@HttpRename("pageSize")
|
||||
private String pageSize;
|
||||
|
||||
@HttpHeader
|
||||
@HttpRename("Content-Type")
|
||||
private String contentType = "application/json;charset=utf-8";
|
||||
|
||||
public GetWeaponApi setPageSize(String pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final static class Bean {
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
private List<DataDTO> data;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public List<DataDTO> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<DataDTO> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static class DataDTO {
|
||||
private String id;
|
||||
private String name;
|
||||
private String imgPath;
|
||||
private String cartridgeCapacity;
|
||||
private String bulletCaliber;
|
||||
private String effectiveRange;
|
||||
private String totalInventory;
|
||||
private String lockInventory;
|
||||
private String isLend;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getImgPath() {
|
||||
return imgPath;
|
||||
}
|
||||
|
||||
public void setImgPath(String imgPath) {
|
||||
this.imgPath = imgPath;
|
||||
}
|
||||
|
||||
public String getCartridgeCapacity() {
|
||||
return cartridgeCapacity;
|
||||
}
|
||||
|
||||
public void setCartridgeCapacity(String cartridgeCapacity) {
|
||||
this.cartridgeCapacity = cartridgeCapacity;
|
||||
}
|
||||
|
||||
public String getBulletCaliber() {
|
||||
return bulletCaliber;
|
||||
}
|
||||
|
||||
public void setBulletCaliber(String bulletCaliber) {
|
||||
this.bulletCaliber = bulletCaliber;
|
||||
}
|
||||
|
||||
public String getEffectiveRange() {
|
||||
return effectiveRange;
|
||||
}
|
||||
|
||||
public void setEffectiveRange(String effectiveRange) {
|
||||
this.effectiveRange = effectiveRange;
|
||||
}
|
||||
|
||||
public String getTotalInventory() {
|
||||
return totalInventory;
|
||||
}
|
||||
|
||||
public void setTotalInventory(String totalInventory) {
|
||||
this.totalInventory = totalInventory;
|
||||
}
|
||||
|
||||
public String getLockInventory() {
|
||||
return lockInventory;
|
||||
}
|
||||
|
||||
public void setLockInventory(String lockInventory) {
|
||||
this.lockInventory = lockInventory;
|
||||
}
|
||||
|
||||
public String getIsLend() {
|
||||
return isLend;
|
||||
}
|
||||
|
||||
public void setIsLend(String isLend) {
|
||||
this.isLend = isLend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.test.weapon.api;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.hjq.http.annotation.HttpHeader;
|
||||
import com.hjq.http.annotation.HttpRename;
|
||||
import com.hjq.http.config.IRequestApi;
|
||||
|
||||
/**
|
||||
* Created on 2023/3/24
|
||||
*/
|
||||
public class LendWeaponApi implements IRequestApi {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getApi() {
|
||||
return "/weaponry/weaponryLend/save";
|
||||
}
|
||||
@HttpHeader
|
||||
@HttpRename("Content-Type")
|
||||
private String contentType = "application/json;charset=utf-8";
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.test.weapon.api;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.hjq.http.annotation.HttpHeader;
|
||||
import com.hjq.http.annotation.HttpRename;
|
||||
import com.hjq.http.config.IRequestApi;
|
||||
|
||||
/**
|
||||
* Created on 2023/3/24
|
||||
*/
|
||||
public class ReturnWeaponApi implements IRequestApi {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getApi() {
|
||||
return "/weaponry/weaponryReturnRecord/save?";
|
||||
}
|
||||
@HttpRename("lendRecordId")
|
||||
private String lendRecordId;
|
||||
|
||||
public ReturnWeaponApi setLendRecordId(String lendRecordId) {
|
||||
this.lendRecordId = lendRecordId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@HttpHeader
|
||||
@HttpRename("Content-Type")
|
||||
private String contentType = "application/json;charset=utf-8";
|
||||
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
package com.test.weapon.api;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.hjq.http.config.IRequestApi;
|
||||
|
||||
/**
|
||||
* Created on 2023/3/24
|
||||
*/
|
||||
public class ReturnWeaponListApi implements IRequestApi {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getApi() {
|
||||
return "/weaponry/weaponryLend/getPageList";
|
||||
}
|
||||
public final static class Bean{
|
||||
|
||||
private String id;
|
||||
private String weaponryId;
|
||||
private String weaponryName;
|
||||
private Integer num;
|
||||
private Long returnTime;
|
||||
private Integer returnStatus;
|
||||
private WeaponryDTO weaponry;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getWeaponryId() {
|
||||
return weaponryId;
|
||||
}
|
||||
|
||||
public void setWeaponryId(String weaponryId) {
|
||||
this.weaponryId = weaponryId;
|
||||
}
|
||||
|
||||
public String getWeaponryName() {
|
||||
return weaponryName;
|
||||
}
|
||||
|
||||
public void setWeaponryName(String weaponryName) {
|
||||
this.weaponryName = weaponryName;
|
||||
}
|
||||
|
||||
public Integer getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(Integer num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public Long getReturnTime() {
|
||||
return returnTime;
|
||||
}
|
||||
|
||||
public void setReturnTime(Long returnTime) {
|
||||
this.returnTime = returnTime;
|
||||
}
|
||||
|
||||
public Integer getReturnStatus() {
|
||||
return returnStatus;
|
||||
}
|
||||
|
||||
public void setReturnStatus(Integer returnStatus) {
|
||||
this.returnStatus = returnStatus;
|
||||
}
|
||||
|
||||
public WeaponryDTO getWeaponry() {
|
||||
return weaponry;
|
||||
}
|
||||
|
||||
public void setWeaponry(WeaponryDTO weaponry) {
|
||||
this.weaponry = weaponry;
|
||||
}
|
||||
|
||||
public static class WeaponryDTO {
|
||||
private String id;
|
||||
private String name;
|
||||
private String imgPath;
|
||||
private String cartridgeCapacity;
|
||||
private String bulletCaliber;
|
||||
private String effectiveRange;
|
||||
private String totalInventory;
|
||||
private String lockInventory;
|
||||
private String isLend;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getImgPath() {
|
||||
return imgPath;
|
||||
}
|
||||
|
||||
public void setImgPath(String imgPath) {
|
||||
this.imgPath = imgPath;
|
||||
}
|
||||
|
||||
public String getCartridgeCapacity() {
|
||||
return cartridgeCapacity;
|
||||
}
|
||||
|
||||
public void setCartridgeCapacity(String cartridgeCapacity) {
|
||||
this.cartridgeCapacity = cartridgeCapacity;
|
||||
}
|
||||
|
||||
public String getBulletCaliber() {
|
||||
return bulletCaliber;
|
||||
}
|
||||
|
||||
public void setBulletCaliber(String bulletCaliber) {
|
||||
this.bulletCaliber = bulletCaliber;
|
||||
}
|
||||
|
||||
public String getEffectiveRange() {
|
||||
return effectiveRange;
|
||||
}
|
||||
|
||||
public void setEffectiveRange(String effectiveRange) {
|
||||
this.effectiveRange = effectiveRange;
|
||||
}
|
||||
|
||||
public String getTotalInventory() {
|
||||
return totalInventory;
|
||||
}
|
||||
|
||||
public void setTotalInventory(String totalInventory) {
|
||||
this.totalInventory = totalInventory;
|
||||
}
|
||||
|
||||
public String getLockInventory() {
|
||||
return lockInventory;
|
||||
}
|
||||
|
||||
public void setLockInventory(String lockInventory) {
|
||||
this.lockInventory = lockInventory;
|
||||
}
|
||||
|
||||
public String getIsLend() {
|
||||
return isLend;
|
||||
}
|
||||
|
||||
public void setIsLend(String isLend) {
|
||||
this.isLend = isLend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,182 @@
|
||||
package com.test.weapon.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created on 2023/3/23
|
||||
*/
|
||||
public class GetWeaponList implements Serializable {
|
||||
|
||||
private boolean isChoose=false;
|
||||
private Object pageNo;
|
||||
|
||||
public boolean isChoose() {
|
||||
return isChoose;
|
||||
}
|
||||
|
||||
public void setChoose(boolean choose) {
|
||||
isChoose = choose;
|
||||
}
|
||||
|
||||
private Object pageSize;
|
||||
private String id;
|
||||
private Long createTime;
|
||||
private Long updateTime;
|
||||
private Object updateTimeEnd;
|
||||
private Object operator;
|
||||
private Object remark;
|
||||
private String name;
|
||||
private String imgPath;
|
||||
private Integer cartridgeCapacity;
|
||||
private Double bulletCaliber;
|
||||
private Integer effectiveRange;
|
||||
private Integer totalInventory;
|
||||
private Integer lockInventory;
|
||||
private Integer status;
|
||||
private Integer isLend;
|
||||
private Object lockInventoryStart;
|
||||
|
||||
public Object getPageNo() {
|
||||
return pageNo;
|
||||
}
|
||||
|
||||
public void setPageNo(Object pageNo) {
|
||||
this.pageNo = pageNo;
|
||||
}
|
||||
|
||||
public Object getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Object pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Long getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Long updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public Object getUpdateTimeEnd() {
|
||||
return updateTimeEnd;
|
||||
}
|
||||
|
||||
public void setUpdateTimeEnd(Object updateTimeEnd) {
|
||||
this.updateTimeEnd = updateTimeEnd;
|
||||
}
|
||||
|
||||
public Object getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
public void setOperator(Object operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public Object getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(Object remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getImgPath() {
|
||||
return imgPath;
|
||||
}
|
||||
|
||||
public void setImgPath(String imgPath) {
|
||||
this.imgPath = imgPath;
|
||||
}
|
||||
|
||||
public Integer getCartridgeCapacity() {
|
||||
return cartridgeCapacity;
|
||||
}
|
||||
|
||||
public void setCartridgeCapacity(Integer cartridgeCapacity) {
|
||||
this.cartridgeCapacity = cartridgeCapacity;
|
||||
}
|
||||
|
||||
public Double getBulletCaliber() {
|
||||
return bulletCaliber;
|
||||
}
|
||||
|
||||
public void setBulletCaliber(Double bulletCaliber) {
|
||||
this.bulletCaliber = bulletCaliber;
|
||||
}
|
||||
|
||||
public Integer getEffectiveRange() {
|
||||
return effectiveRange;
|
||||
}
|
||||
|
||||
public void setEffectiveRange(Integer effectiveRange) {
|
||||
this.effectiveRange = effectiveRange;
|
||||
}
|
||||
|
||||
public Integer getTotalInventory() {
|
||||
return totalInventory;
|
||||
}
|
||||
|
||||
public void setTotalInventory(Integer totalInventory) {
|
||||
this.totalInventory = totalInventory;
|
||||
}
|
||||
|
||||
public Integer getLockInventory() {
|
||||
return lockInventory;
|
||||
}
|
||||
|
||||
public void setLockInventory(Integer lockInventory) {
|
||||
this.lockInventory = lockInventory;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getIsLend() {
|
||||
return isLend;
|
||||
}
|
||||
|
||||
public void setIsLend(Integer isLend) {
|
||||
this.isLend = isLend;
|
||||
}
|
||||
|
||||
public Object getLockInventoryStart() {
|
||||
return lockInventoryStart;
|
||||
}
|
||||
|
||||
public void setLockInventoryStart(Object lockInventoryStart) {
|
||||
this.lockInventoryStart = lockInventoryStart;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.test.weapon.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.hjq.http.EasyHttp;
|
||||
import com.hjq.http.body.JsonBody;
|
||||
import com.hjq.http.listener.HttpCallback;
|
||||
import com.test.weapon.Adapter.LocationAlarmAdapter;
|
||||
import com.test.weapon.BaseFragment;
|
||||
import com.test.weapon.R;
|
||||
import com.test.weapon.api.GetWarningApi;
|
||||
import com.test.weapon.api.GetWeaponApi;
|
||||
import com.test.weapon.bean.GetWeaponList;
|
||||
import com.test.weapon.http.HttpData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 定位报警
|
||||
*/
|
||||
public class LocationAlarmFragment extends BaseFragment {
|
||||
private RecyclerView rvLocation;
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_location_alarm, container, false);
|
||||
rvLocation = view.findViewById(R.id.rv_location);
|
||||
initView();
|
||||
return view;
|
||||
}
|
||||
private void initView(){
|
||||
LocationAlarmAdapter adapter = new LocationAlarmAdapter(R.layout.location_alarm_layout);
|
||||
rvLocation.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
rvLocation.setAdapter(adapter);
|
||||
|
||||
Map<String ,String> map=new HashMap<>();
|
||||
map.put("pageNo","1");
|
||||
map.put("pageSize","10");
|
||||
|
||||
EasyHttp.post(this)
|
||||
.api(new GetWarningApi()
|
||||
)
|
||||
.body(new JsonBody(map))
|
||||
.request(new HttpCallback<HttpData<List<GetWeaponList>>>(this) {
|
||||
|
||||
@Override
|
||||
public void onSucceed(HttpData<List<GetWeaponList>> result) {
|
||||
adapter.addData(result.getData());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.test.weapon.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.test.weapon.BaseFragment;
|
||||
import com.test.weapon.R;
|
||||
import com.test.weapon.bean.GetWeaponList;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class TabDayFragment extends BaseFragment {
|
||||
TextView detail ;
|
||||
GetWeaponList bean;
|
||||
int position;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_day, container, false);
|
||||
detail=view.findViewById(R.id.detail_text);
|
||||
Bundle bundle=getArguments();
|
||||
position=bundle.getInt("index");
|
||||
bean= (GetWeaponList) bundle.getSerializable("data");
|
||||
initView();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
detail.setText(
|
||||
"枪弹数量:"+bean.getBulletCaliber()+"\n" +
|
||||
"入库数量:"+bean.getLockInventory()+"\n" +
|
||||
"使用数量:"+position+3+"\n" +
|
||||
"使用情况:正常\n" +
|
||||
"使用时间:"+getDateToString(bean.getUpdateTime())+"\n" +
|
||||
"使用目的:训练\n" +
|
||||
"使用情况:正常");
|
||||
}
|
||||
public static String getDateToString(long milSecond) {
|
||||
Date date = new Date(milSecond);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return format.format(date);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.test.weapon.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.test.weapon.BaseFragment;
|
||||
import com.test.weapon.R;
|
||||
import com.test.weapon.bean.GetWeaponList;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class TabMonthFragment extends BaseFragment {
|
||||
TextView detail ;
|
||||
GetWeaponList bean;
|
||||
int position;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_day, container, false);
|
||||
detail=view.findViewById(R.id.detail_text);
|
||||
Bundle bundle=getArguments();
|
||||
position=bundle.getInt("index");
|
||||
bean= (GetWeaponList) bundle.getSerializable("data");
|
||||
initView();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
detail.setText(
|
||||
"枪弹数量:"+bean.getBulletCaliber()+"\n" +
|
||||
"入库数量:"+bean.getLockInventory()+"\n" +
|
||||
"使用数量:"+position+30+"\n" +
|
||||
"使用情况:正常\n" +
|
||||
"使用时间:"+getDateToString(bean.getUpdateTime())+"\n" +
|
||||
"使用目的:训练\n" +
|
||||
"使用情况:正常");
|
||||
}
|
||||
public static String getDateToString(long milSecond) {
|
||||
Date date = new Date(milSecond);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return format.format(date);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.test.weapon.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.test.weapon.BaseFragment;
|
||||
import com.test.weapon.R;
|
||||
import com.test.weapon.bean.GetWeaponList;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class TabWeekFragment extends BaseFragment {
|
||||
TextView detail ;
|
||||
GetWeaponList bean;
|
||||
int position;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_day, container, false);
|
||||
detail=view.findViewById(R.id.detail_text);
|
||||
Bundle bundle=getArguments();
|
||||
position=bundle.getInt("index");
|
||||
bean= (GetWeaponList) bundle.getSerializable("data");
|
||||
initView();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
detail.setText(
|
||||
"枪弹数量:"+bean.getBulletCaliber()+"\n" +
|
||||
"入库数量:"+bean.getLockInventory()+"\n" +
|
||||
"使用数量:"+position+7+"\n" +
|
||||
"使用情况:正常\n" +
|
||||
"使用时间:"+getDateToString(bean.getUpdateTime())+"\n" +
|
||||
"使用目的:训练\n" +
|
||||
"使用情况:正常");
|
||||
}
|
||||
public static String getDateToString(long milSecond) {
|
||||
Date date = new Date(milSecond);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return format.format(date);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.test.weapon.http;
|
||||
|
||||
public class ErrorResponseCodeException extends Exception{
|
||||
public ErrorResponseCodeException(String message){
|
||||
super(message);//写的异常调用父类的方法,传给父类
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package com.test.weapon.http;
|
||||
|
||||
import okhttp3.Headers;
|
||||
|
||||
|
||||
public class HttpData<T> {
|
||||
|
||||
/** 请求头 */
|
||||
private Headers headers;
|
||||
|
||||
/** 返回码 */
|
||||
private int code;
|
||||
/** 提示语 */
|
||||
private String message;
|
||||
/** 数据 */
|
||||
private T data;
|
||||
|
||||
public void setHeaders(Headers headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public Headers getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否请求成功
|
||||
*/
|
||||
public boolean isRequestSuccess() {
|
||||
return code == 200;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否 Token 失效
|
||||
*/
|
||||
public boolean isTokenFailure() {
|
||||
return code == 1001;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.test.weapon.http;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.hjq.http.config.IRequestServer;
|
||||
import com.test.weapon.util.AppData;
|
||||
|
||||
/**
|
||||
* Created on 2023/3/23
|
||||
*/
|
||||
public class ReleaseServer implements IRequestServer {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getHost() {
|
||||
return AppData.ApiAddress;
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
package com.test.weapon.http;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.hjq.gson.factory.GsonFactory;
|
||||
import com.hjq.http.EasyLog;
|
||||
import com.hjq.http.config.IRequestHandler;
|
||||
import com.hjq.http.exception.CancelException;
|
||||
import com.hjq.http.exception.DataException;
|
||||
import com.hjq.http.exception.HttpException;
|
||||
import com.hjq.http.exception.NetworkException;
|
||||
import com.hjq.http.exception.NullBodyException;
|
||||
import com.hjq.http.exception.ResponseException;
|
||||
import com.hjq.http.exception.ServerException;
|
||||
import com.hjq.http.exception.TimeoutException;
|
||||
import com.hjq.http.request.HttpRequest;
|
||||
import com.test.weapon.R;
|
||||
;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
/**
|
||||
* Created on 2023/3/23
|
||||
*/
|
||||
public class RequestHandler implements IRequestHandler {
|
||||
private final Application mApplication;
|
||||
|
||||
public RequestHandler(Application application) {
|
||||
mApplication = application;
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public Object requestSuccess(@NonNull HttpRequest<?> httpRequest, @NonNull Response response, @NonNull Type type) throws Exception {
|
||||
if (Response.class.equals(type)) {
|
||||
return response;
|
||||
}
|
||||
|
||||
if (!response.isSuccessful()) {
|
||||
throw new ResponseException(String.format(mApplication.getString(R.string.http_response_error),
|
||||
response.code(), response.message()), response);
|
||||
}
|
||||
|
||||
if (Headers.class.equals(type)) {
|
||||
return response.headers();
|
||||
}
|
||||
|
||||
ResponseBody body = response.body();
|
||||
if (body == null) {
|
||||
throw new NullBodyException(mApplication.getString(R.string.http_response_null_body));
|
||||
}
|
||||
|
||||
if (ResponseBody.class.equals(type)) {
|
||||
return body;
|
||||
}
|
||||
|
||||
// 如果是用数组接收,判断一下是不是用 byte[] 类型进行接收的
|
||||
if(type instanceof GenericArrayType) {
|
||||
Type genericComponentType = ((GenericArrayType) type).getGenericComponentType();
|
||||
if (byte.class.equals(genericComponentType)) {
|
||||
return body.bytes();
|
||||
}
|
||||
}
|
||||
|
||||
if (InputStream.class.equals(type)) {
|
||||
return body.byteStream();
|
||||
}
|
||||
|
||||
if (Bitmap.class.equals(type)) {
|
||||
return BitmapFactory.decodeStream(body.byteStream());
|
||||
}
|
||||
|
||||
String text;
|
||||
try {
|
||||
text = body.string();
|
||||
} catch (IOException e) {
|
||||
// 返回结果读取异常
|
||||
throw new DataException(mApplication.getString(R.string.http_data_explain_error), e);
|
||||
}
|
||||
|
||||
// 打印这个 Json 或者文本
|
||||
EasyLog.printJson(httpRequest, text);
|
||||
|
||||
if (String.class.equals(type)) {
|
||||
return text;
|
||||
}
|
||||
|
||||
final Object result;
|
||||
// Gson sGson = new Gson();
|
||||
try {
|
||||
// result= sGson.fromJson(text,type);
|
||||
|
||||
result = GsonFactory.getSingletonGson().fromJson(text, type);
|
||||
} catch (JsonSyntaxException e) {
|
||||
// 返回结果读取异常
|
||||
throw new DataException(mApplication.getString(R.string.http_data_explain_error), e);
|
||||
}
|
||||
|
||||
if (result instanceof HttpData) {
|
||||
HttpData<?> model = (HttpData<?>) result;
|
||||
model.setHeaders(response.headers());
|
||||
|
||||
if (model.isRequestSuccess()) {
|
||||
// 代表执行成功
|
||||
return result;
|
||||
}
|
||||
|
||||
if (model.isTokenFailure()) {
|
||||
// 代表登录失效,需要重新登录
|
||||
throw new TokenException(mApplication.getString(R.string.http_token_error));
|
||||
}
|
||||
|
||||
// 代表执行失败
|
||||
throw new ResultException(model.getMessage(), model);
|
||||
}
|
||||
return result; }
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Exception requestFail(@NonNull HttpRequest<?> httpRequest, @NonNull Exception e) {
|
||||
if (e instanceof HttpException) {
|
||||
if (e instanceof TokenException) {
|
||||
// 登录信息失效,跳转到登录页
|
||||
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
if (e instanceof SocketTimeoutException) {
|
||||
return new TimeoutException(mApplication.getString(R.string.http_server_out_time), e);
|
||||
}
|
||||
|
||||
if (e instanceof UnknownHostException) {
|
||||
NetworkInfo info = ((ConnectivityManager) mApplication.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
|
||||
// 判断网络是否连接
|
||||
if (info != null && info.isConnected()) {
|
||||
// 有连接就是服务器的问题
|
||||
return new ServerException(mApplication.getString(R.string.http_server_error), e);
|
||||
}
|
||||
// 没有连接就是网络异常
|
||||
return new NetworkException(mApplication.getString(R.string.http_network_error), e);
|
||||
}
|
||||
|
||||
if (e instanceof IOException) {
|
||||
// 出现该异常的两种情况
|
||||
// 1. 调用 EasyHttp.cancel
|
||||
// 2. 网络请求被中断
|
||||
return new CancelException(mApplication.getString(R.string.http_request_cancel), e);
|
||||
}
|
||||
|
||||
return new HttpException(e.getMessage(), e);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.test.weapon.http;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.hjq.http.exception.HttpException;
|
||||
import com.test.weapon.http.HttpData;
|
||||
|
||||
/**
|
||||
* desc : 返回结果异常
|
||||
*/
|
||||
public final class ResultException extends HttpException {
|
||||
|
||||
private final HttpData<?> mData;
|
||||
|
||||
public ResultException(String message, HttpData<?> data) {
|
||||
super(message);
|
||||
mData = data;
|
||||
}
|
||||
|
||||
public ResultException(String message, Throwable cause, HttpData<?> data) {
|
||||
super(message, cause);
|
||||
mData = data;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public HttpData<?> getHttpData() {
|
||||
return mData;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.test.weapon.http;
|
||||
|
||||
import com.hjq.http.exception.HttpException;
|
||||
|
||||
/**
|
||||
* desc : Token 失效异常
|
||||
*/
|
||||
public final class TokenException extends HttpException {
|
||||
|
||||
public TokenException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TokenException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.test.weapon.util;
|
||||
|
||||
|
||||
public class AppData {
|
||||
public static String PicAddress="http://120.24.185.153:8088/file/";
|
||||
public static String ApiAddress="http://120.24.185.153:8088/";
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.test.weapon.util;
|
||||
|
||||
|
||||
import com.test.weapon.http.ErrorResponseCodeException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class HttpStreamOP implements ISource {
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream(String urlPath) throws IOException, ErrorResponseCodeException {
|
||||
|
||||
InputStream in = null;
|
||||
URL url = new URL(urlPath);
|
||||
HttpURLConnection connection =(HttpURLConnection) url.openConnection();
|
||||
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5000);
|
||||
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200){
|
||||
|
||||
in = connection.getInputStream();
|
||||
}else{
|
||||
throw new ErrorResponseCodeException("error code is"+code);
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.test.weapon.util;
|
||||
|
||||
|
||||
import com.test.weapon.http.ErrorResponseCodeException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface ISource {
|
||||
InputStream getInputStream(String path) throws IOException, ErrorResponseCodeException;
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.test.weapon.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
/**
|
||||
* Created by xhl
|
||||
* Created on 2023/6/21
|
||||
*/
|
||||
public class ViewPagerForScrollView extends ViewPager {
|
||||
private String Tag = "ViewPagerForScrollView";
|
||||
|
||||
public ViewPagerForScrollView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ViewPagerForScrollView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
addOnPageChangeListener(new OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int height = 0;
|
||||
if (getAdapter() != null) {
|
||||
int index = getCurrentItem();
|
||||
height = 0;
|
||||
View v = ((Fragment) getAdapter().instantiateItem(this, index)).getView();
|
||||
if (v != null) {
|
||||
v.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||
height = v.getMeasuredHeight();
|
||||
}
|
||||
} else {
|
||||
height = 0;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||
int h = child.getMeasuredHeight();
|
||||
if (h > height)
|
||||
height = h;
|
||||
}
|
||||
}
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.test.weapon;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package cn.pedant.SweetAlert;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Xml;
|
||||
import android.view.animation.*;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class OptAnimationLoader {
|
||||
|
||||
public static Animation loadAnimation(Context context, int id)
|
||||
throws Resources.NotFoundException {
|
||||
|
||||
XmlResourceParser parser = null;
|
||||
try {
|
||||
parser = context.getResources().getAnimation(id);
|
||||
return createAnimationFromXml(context, parser);
|
||||
} catch (XmlPullParserException ex) {
|
||||
Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" +
|
||||
Integer.toHexString(id));
|
||||
rnf.initCause(ex);
|
||||
throw rnf;
|
||||
} catch (IOException ex) {
|
||||
Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" +
|
||||
Integer.toHexString(id));
|
||||
rnf.initCause(ex);
|
||||
throw rnf;
|
||||
} finally {
|
||||
if (parser != null) parser.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static Animation createAnimationFromXml(Context c, XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException {
|
||||
|
||||
return createAnimationFromXml(c, parser, null, Xml.asAttributeSet(parser));
|
||||
}
|
||||
|
||||
private static Animation createAnimationFromXml(Context c, XmlPullParser parser,
|
||||
AnimationSet parent, AttributeSet attrs) throws XmlPullParserException, IOException {
|
||||
|
||||
Animation anim = null;
|
||||
|
||||
// Make sure we are on a start tag.
|
||||
int type;
|
||||
int depth = parser.getDepth();
|
||||
|
||||
while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
|
||||
&& type != XmlPullParser.END_DOCUMENT) {
|
||||
|
||||
if (type != XmlPullParser.START_TAG) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = parser.getName();
|
||||
|
||||
if (name.equals("set")) {
|
||||
anim = new AnimationSet(c, attrs);
|
||||
createAnimationFromXml(c, parser, (AnimationSet)anim, attrs);
|
||||
} else if (name.equals("alpha")) {
|
||||
anim = new AlphaAnimation(c, attrs);
|
||||
} else if (name.equals("scale")) {
|
||||
anim = new ScaleAnimation(c, attrs);
|
||||
} else if (name.equals("rotate")) {
|
||||
anim = new RotateAnimation(c, attrs);
|
||||
} else if (name.equals("translate")) {
|
||||
anim = new TranslateAnimation(c, attrs);
|
||||
} else {
|
||||
try {
|
||||
anim = (Animation) Class.forName(name).getConstructor(Context.class, AttributeSet.class).newInstance(c, attrs);
|
||||
} catch (Exception te) {
|
||||
throw new RuntimeException("Unknown animation name: " + parser.getName() + " error:" + te.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (parent != null) {
|
||||
parent.addAnimation(anim);
|
||||
}
|
||||
}
|
||||
|
||||
return anim;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
package cn.pedant.SweetAlert;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
|
||||
public class ProgressHelper {
|
||||
private ProgressWheel mProgressWheel;
|
||||
private boolean mToSpin;
|
||||
private float mSpinSpeed;
|
||||
private int mBarWidth;
|
||||
private int mBarColor;
|
||||
private int mRimWidth;
|
||||
private int mRimColor;
|
||||
private boolean mIsInstantProgress;
|
||||
private float mProgressVal;
|
||||
private int mCircleRadius;
|
||||
|
||||
public ProgressHelper(Context ctx) {
|
||||
mToSpin = true;
|
||||
mSpinSpeed = 0.75f;
|
||||
mBarWidth = ctx.getResources().getDimensionPixelSize(R.dimen.common_circle_width) + 1;
|
||||
mBarColor = ctx.getResources().getColor(R.color.success_stroke_color);
|
||||
mRimWidth = 0;
|
||||
mRimColor = 0x00000000;
|
||||
mIsInstantProgress = false;
|
||||
mProgressVal = -1;
|
||||
mCircleRadius = ctx.getResources().getDimensionPixelOffset(R.dimen.progress_circle_radius);
|
||||
}
|
||||
|
||||
public ProgressWheel getProgressWheel () {
|
||||
return mProgressWheel;
|
||||
}
|
||||
|
||||
public void setProgressWheel (ProgressWheel progressWheel) {
|
||||
mProgressWheel = progressWheel;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
private void updatePropsIfNeed () {
|
||||
if (mProgressWheel != null) {
|
||||
if (!mToSpin && mProgressWheel.isSpinning()) {
|
||||
mProgressWheel.stopSpinning();
|
||||
} else if (mToSpin && !mProgressWheel.isSpinning()) {
|
||||
mProgressWheel.spin();
|
||||
}
|
||||
if (mSpinSpeed != mProgressWheel.getSpinSpeed()) {
|
||||
mProgressWheel.setSpinSpeed(mSpinSpeed);
|
||||
}
|
||||
if (mBarWidth != mProgressWheel.getBarWidth()) {
|
||||
mProgressWheel.setBarWidth(mBarWidth);
|
||||
}
|
||||
if (mBarColor != mProgressWheel.getBarColor()) {
|
||||
mProgressWheel.setBarColor(mBarColor);
|
||||
}
|
||||
if (mRimWidth != mProgressWheel.getRimWidth()) {
|
||||
mProgressWheel.setRimWidth(mRimWidth);
|
||||
}
|
||||
if (mRimColor != mProgressWheel.getRimColor()) {
|
||||
mProgressWheel.setRimColor(mRimColor);
|
||||
}
|
||||
if (mProgressVal != mProgressWheel.getProgress()) {
|
||||
if (mIsInstantProgress) {
|
||||
mProgressWheel.setInstantProgress(mProgressVal);
|
||||
} else {
|
||||
mProgressWheel.setProgress(mProgressVal);
|
||||
}
|
||||
}
|
||||
if (mCircleRadius != mProgressWheel.getCircleRadius()) {
|
||||
mProgressWheel.setCircleRadius(mCircleRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCount() {
|
||||
if (mProgressWheel != null) {
|
||||
mProgressWheel.resetCount();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSpinning() {
|
||||
return mToSpin;
|
||||
}
|
||||
|
||||
public void spin() {
|
||||
mToSpin = true;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public void stopSpinning() {
|
||||
mToSpin = false;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public float getProgress() {
|
||||
return mProgressVal;
|
||||
}
|
||||
|
||||
public void setProgress(float progress) {
|
||||
mIsInstantProgress = false;
|
||||
mProgressVal = progress;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public void setInstantProgress(float progress) {
|
||||
mProgressVal = progress;
|
||||
mIsInstantProgress = true;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public int getCircleRadius() {
|
||||
return mCircleRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param circleRadius units using pixel
|
||||
* **/
|
||||
public void setCircleRadius(int circleRadius) {
|
||||
mCircleRadius = circleRadius;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public int getBarWidth() {
|
||||
return mBarWidth;
|
||||
}
|
||||
|
||||
public void setBarWidth(int barWidth) {
|
||||
mBarWidth = barWidth;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public int getBarColor() {
|
||||
return mBarColor;
|
||||
}
|
||||
|
||||
public void setBarColor(int barColor) {
|
||||
mBarColor = barColor;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public int getRimWidth() {
|
||||
return mRimWidth;
|
||||
}
|
||||
|
||||
public void setRimWidth(int rimWidth) {
|
||||
mRimWidth = rimWidth;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public int getRimColor() {
|
||||
return mRimColor;
|
||||
}
|
||||
|
||||
public void setRimColor(int rimColor) {
|
||||
mRimColor = rimColor;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
|
||||
public float getSpinSpeed() {
|
||||
return mSpinSpeed;
|
||||
}
|
||||
|
||||
public void setSpinSpeed(float spinSpeed) {
|
||||
mSpinSpeed = spinSpeed;
|
||||
updatePropsIfNeed();
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
package cn.pedant.SweetAlert;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Camera;
|
||||
import android.graphics.Matrix;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Transformation;
|
||||
|
||||
public class Rotate3dAnimation extends Animation {
|
||||
private int mPivotXType = ABSOLUTE;
|
||||
private int mPivotYType = ABSOLUTE;
|
||||
private float mPivotXValue = 0.0f;
|
||||
private float mPivotYValue = 0.0f;
|
||||
|
||||
private float mFromDegrees;
|
||||
private float mToDegrees;
|
||||
private float mPivotX;
|
||||
private float mPivotY;
|
||||
private Camera mCamera;
|
||||
private int mRollType;
|
||||
|
||||
public static final int ROLL_BY_X = 0;
|
||||
public static final int ROLL_BY_Y = 1;
|
||||
public static final int ROLL_BY_Z = 2;
|
||||
|
||||
protected static class Description {
|
||||
public int type;
|
||||
public float value;
|
||||
}
|
||||
|
||||
Description parseValue(TypedValue value) {
|
||||
Description d = new Description();
|
||||
if (value == null) {
|
||||
d.type = ABSOLUTE;
|
||||
d.value = 0;
|
||||
} else {
|
||||
if (value.type == TypedValue.TYPE_FRACTION) {
|
||||
d.type = (value.data & TypedValue.COMPLEX_UNIT_MASK) ==
|
||||
TypedValue.COMPLEX_UNIT_FRACTION_PARENT ?
|
||||
RELATIVE_TO_PARENT : RELATIVE_TO_SELF;
|
||||
d.value = TypedValue.complexToFloat(value.data);
|
||||
return d;
|
||||
} else if (value.type == TypedValue.TYPE_FLOAT) {
|
||||
d.type = ABSOLUTE;
|
||||
d.value = value.getFloat();
|
||||
return d;
|
||||
} else if (value.type >= TypedValue.TYPE_FIRST_INT &&
|
||||
value.type <= TypedValue.TYPE_LAST_INT) {
|
||||
d.type = ABSOLUTE;
|
||||
d.value = value.data;
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
d.type = ABSOLUTE;
|
||||
d.value = 0.0f;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public Rotate3dAnimation (Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Rotate3dAnimation);
|
||||
|
||||
mFromDegrees = a.getFloat(R.styleable.Rotate3dAnimation_fromDeg, 0.0f);
|
||||
mToDegrees = a.getFloat(R.styleable.Rotate3dAnimation_toDeg, 0.0f);
|
||||
mRollType = a.getInt(R.styleable.Rotate3dAnimation_rollType, ROLL_BY_X);
|
||||
Description d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotX));
|
||||
mPivotXType = d.type;
|
||||
mPivotXValue = d.value;
|
||||
|
||||
d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotY));
|
||||
mPivotYType = d.type;
|
||||
mPivotYValue = d.value;
|
||||
|
||||
a.recycle();
|
||||
|
||||
initializePivotPoint();
|
||||
}
|
||||
|
||||
public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees) {
|
||||
mRollType = rollType;
|
||||
mFromDegrees = fromDegrees;
|
||||
mToDegrees = toDegrees;
|
||||
mPivotX = 0.0f;
|
||||
mPivotY = 0.0f;
|
||||
}
|
||||
|
||||
public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees, float pivotX, float pivotY) {
|
||||
mRollType = rollType;
|
||||
mFromDegrees = fromDegrees;
|
||||
mToDegrees = toDegrees;
|
||||
|
||||
mPivotXType = ABSOLUTE;
|
||||
mPivotYType = ABSOLUTE;
|
||||
mPivotXValue = pivotX;
|
||||
mPivotYValue = pivotY;
|
||||
initializePivotPoint();
|
||||
}
|
||||
|
||||
public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) {
|
||||
mRollType = rollType;
|
||||
mFromDegrees = fromDegrees;
|
||||
mToDegrees = toDegrees;
|
||||
|
||||
mPivotXValue = pivotXValue;
|
||||
mPivotXType = pivotXType;
|
||||
mPivotYValue = pivotYValue;
|
||||
mPivotYType = pivotYType;
|
||||
initializePivotPoint();
|
||||
}
|
||||
|
||||
private void initializePivotPoint() {
|
||||
if (mPivotXType == ABSOLUTE) {
|
||||
mPivotX = mPivotXValue;
|
||||
}
|
||||
if (mPivotYType == ABSOLUTE) {
|
||||
mPivotY = mPivotYValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(int width, int height, int parentWidth, int parentHeight) {
|
||||
super.initialize(width, height, parentWidth, parentHeight);
|
||||
mCamera = new Camera();
|
||||
mPivotX = resolveSize(mPivotXType, mPivotXValue, width, parentWidth);
|
||||
mPivotY = resolveSize(mPivotYType, mPivotYValue, height, parentHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
final float fromDegrees = mFromDegrees;
|
||||
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
|
||||
|
||||
final Matrix matrix = t.getMatrix();
|
||||
|
||||
mCamera.save();
|
||||
switch (mRollType) {
|
||||
case ROLL_BY_X:
|
||||
mCamera.rotateX(degrees);
|
||||
break;
|
||||
case ROLL_BY_Y:
|
||||
mCamera.rotateY(degrees);
|
||||
break;
|
||||
case ROLL_BY_Z:
|
||||
mCamera.rotateZ(degrees);
|
||||
break;
|
||||
}
|
||||
mCamera.getMatrix(matrix);
|
||||
mCamera.restore();
|
||||
|
||||
matrix.preTranslate(-mPivotX, -mPivotY);
|
||||
matrix.postTranslate(mPivotX, mPivotY);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package cn.pedant.SweetAlert;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Transformation;
|
||||
|
||||
public class SuccessTickView extends View {
|
||||
private float mDensity = -1;
|
||||
private Paint mPaint;
|
||||
private final float CONST_RADIUS = dip2px(1.2f);
|
||||
private final float CONST_RECT_WEIGHT = dip2px(3);
|
||||
private final float CONST_LEFT_RECT_W = dip2px(15);
|
||||
private final float CONST_RIGHT_RECT_W = dip2px(25);
|
||||
private final float MIN_LEFT_RECT_W = dip2px(3.3f);
|
||||
private final float MAX_RIGHT_RECT_W = CONST_RIGHT_RECT_W + dip2px(6.7f);
|
||||
|
||||
private float mMaxLeftRectWidth;
|
||||
private float mLeftRectWidth;
|
||||
private float mRightRectWidth;
|
||||
private boolean mLeftRectGrowMode;
|
||||
|
||||
public SuccessTickView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public SuccessTickView(Context context, AttributeSet attrs){
|
||||
super(context,attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init () {
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(getResources().getColor(R.color.success_stroke_color));
|
||||
mLeftRectWidth = CONST_LEFT_RECT_W;
|
||||
mRightRectWidth = CONST_RIGHT_RECT_W;
|
||||
mLeftRectGrowMode = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
super.draw(canvas);
|
||||
int totalW = getWidth();
|
||||
int totalH = getHeight();
|
||||
// rotate canvas first
|
||||
canvas.rotate(45, totalW / 2, totalH / 2);
|
||||
|
||||
totalW /= 1.2;
|
||||
totalH /= 1.4;
|
||||
mMaxLeftRectWidth = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
|
||||
|
||||
RectF leftRect = new RectF();
|
||||
if (mLeftRectGrowMode) {
|
||||
leftRect.left = 0;
|
||||
leftRect.right = leftRect.left + mLeftRectWidth;
|
||||
leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
|
||||
leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
|
||||
} else {
|
||||
leftRect.right = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
|
||||
leftRect.left = leftRect.right - mLeftRectWidth;
|
||||
leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
|
||||
leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
|
||||
}
|
||||
|
||||
canvas.drawRoundRect(leftRect, CONST_RADIUS, CONST_RADIUS, mPaint);
|
||||
|
||||
RectF rightRect = new RectF();
|
||||
rightRect.bottom = (totalH + CONST_RIGHT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
|
||||
rightRect.left = (totalW + CONST_LEFT_RECT_W) / 2;
|
||||
rightRect.right = rightRect.left + CONST_RECT_WEIGHT;
|
||||
rightRect.top = rightRect.bottom - mRightRectWidth;
|
||||
canvas.drawRoundRect(rightRect, CONST_RADIUS, CONST_RADIUS, mPaint);
|
||||
}
|
||||
|
||||
public float dip2px(float dpValue) {
|
||||
if(mDensity == -1) {
|
||||
mDensity = getResources().getDisplayMetrics().density;
|
||||
}
|
||||
return dpValue * mDensity + 0.5f;
|
||||
}
|
||||
|
||||
public void startTickAnim () {
|
||||
// hide tick
|
||||
mLeftRectWidth = 0;
|
||||
mRightRectWidth = 0;
|
||||
invalidate();
|
||||
Animation tickAnim = new Animation() {
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
super.applyTransformation(interpolatedTime, t);
|
||||
if (0.54 < interpolatedTime && 0.7 >= interpolatedTime) { // grow left and right rect to right
|
||||
mLeftRectGrowMode = true;
|
||||
mLeftRectWidth = mMaxLeftRectWidth * ((interpolatedTime - 0.54f) / 0.16f);
|
||||
if (0.65 < interpolatedTime) {
|
||||
mRightRectWidth = MAX_RIGHT_RECT_W * ((interpolatedTime - 0.65f) / 0.19f);
|
||||
}
|
||||
invalidate();
|
||||
} else if (0.7 < interpolatedTime && 0.84 >= interpolatedTime) { // shorten left rect from right, still grow right rect
|
||||
mLeftRectGrowMode = false;
|
||||
mLeftRectWidth = mMaxLeftRectWidth * (1 - ((interpolatedTime - 0.7f) / 0.14f));
|
||||
mLeftRectWidth = mLeftRectWidth < MIN_LEFT_RECT_W ? MIN_LEFT_RECT_W : mLeftRectWidth;
|
||||
mRightRectWidth = MAX_RIGHT_RECT_W * ((interpolatedTime - 0.65f) / 0.19f);
|
||||
invalidate();
|
||||
} else if (0.84 < interpolatedTime && 1 >= interpolatedTime) { // restore left rect width, shorten right rect to const
|
||||
mLeftRectGrowMode = false;
|
||||
mLeftRectWidth = MIN_LEFT_RECT_W + (CONST_LEFT_RECT_W - MIN_LEFT_RECT_W) * ((interpolatedTime - 0.84f) / 0.16f);
|
||||
mRightRectWidth = CONST_RIGHT_RECT_W + (MAX_RIGHT_RECT_W - CONST_RIGHT_RECT_W) * (1 - ((interpolatedTime - 0.84f) / 0.16f));
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
};
|
||||
tickAnim.setDuration(750);
|
||||
tickAnim.setStartOffset(100);
|
||||
startAnimation(tickAnim);
|
||||
}
|
||||
}
|
@ -0,0 +1,382 @@
|
||||
package cn.pedant.SweetAlert;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.Transformation;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SweetAlertDialog extends Dialog implements View.OnClickListener {
|
||||
private View mDialogView;
|
||||
private AnimationSet mModalInAnim;
|
||||
private AnimationSet mModalOutAnim;
|
||||
private Animation mOverlayOutAnim;
|
||||
private Animation mErrorInAnim;
|
||||
private AnimationSet mErrorXInAnim;
|
||||
private AnimationSet mSuccessLayoutAnimSet;
|
||||
private Animation mSuccessBowAnim;
|
||||
private TextView mTitleTextView;
|
||||
private TextView mContentTextView;
|
||||
private String mTitleText;
|
||||
private String mContentText;
|
||||
private boolean mShowCancel;
|
||||
private boolean mShowContent;
|
||||
private String mCancelText;
|
||||
private String mConfirmText;
|
||||
private int mAlertType;
|
||||
private FrameLayout mErrorFrame;
|
||||
private FrameLayout mSuccessFrame;
|
||||
private FrameLayout mProgressFrame;
|
||||
private SuccessTickView mSuccessTick;
|
||||
private ImageView mErrorX;
|
||||
private View mSuccessLeftMask;
|
||||
private View mSuccessRightMask;
|
||||
private Drawable mCustomImgDrawable;
|
||||
private ImageView mCustomImage;
|
||||
private Button mConfirmButton;
|
||||
private Button mCancelButton;
|
||||
private ProgressHelper mProgressHelper;
|
||||
private FrameLayout mWarningFrame;
|
||||
private OnSweetClickListener mCancelClickListener;
|
||||
private OnSweetClickListener mConfirmClickListener;
|
||||
private boolean mCloseFromCancel;
|
||||
|
||||
public static final int NORMAL_TYPE = 0;
|
||||
public static final int ERROR_TYPE = 1;
|
||||
public static final int SUCCESS_TYPE = 2;
|
||||
public static final int WARNING_TYPE = 3;
|
||||
public static final int CUSTOM_IMAGE_TYPE = 4;
|
||||
public static final int PROGRESS_TYPE = 5;
|
||||
|
||||
public static interface OnSweetClickListener {
|
||||
public void onClick (SweetAlertDialog sweetAlertDialog);
|
||||
}
|
||||
|
||||
public SweetAlertDialog(Context context) {
|
||||
this(context, NORMAL_TYPE);
|
||||
}
|
||||
|
||||
public SweetAlertDialog(Context context, int alertType) {
|
||||
super(context, R.style.alert_dialog);
|
||||
setCancelable(true);
|
||||
setCanceledOnTouchOutside(false);
|
||||
mProgressHelper = new ProgressHelper(context);
|
||||
mAlertType = alertType;
|
||||
mErrorInAnim = OptAnimationLoader.loadAnimation(getContext(), R.anim.error_frame_in);
|
||||
mErrorXInAnim = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.error_x_in);
|
||||
// 2.3.x system don't support alpha-animation on layer-list drawable
|
||||
// remove it from animation set
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
List<Animation> childAnims = mErrorXInAnim.getAnimations();
|
||||
int idx = 0;
|
||||
for (;idx < childAnims.size();idx++) {
|
||||
if (childAnims.get(idx) instanceof AlphaAnimation) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idx < childAnims.size()) {
|
||||
childAnims.remove(idx);
|
||||
}
|
||||
}
|
||||
mSuccessBowAnim = OptAnimationLoader.loadAnimation(getContext(), R.anim.success_bow_roate);
|
||||
mSuccessLayoutAnimSet = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.success_mask_layout);
|
||||
mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_in);
|
||||
mModalOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_out);
|
||||
mModalOutAnim.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
mDialogView.setVisibility(View.GONE);
|
||||
mDialogView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mCloseFromCancel) {
|
||||
SweetAlertDialog.super.cancel();
|
||||
} else {
|
||||
SweetAlertDialog.super.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
|
||||
}
|
||||
});
|
||||
// dialog overlay fade out
|
||||
mOverlayOutAnim = new Animation() {
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
WindowManager.LayoutParams wlp = getWindow().getAttributes();
|
||||
wlp.alpha = 1 - interpolatedTime;
|
||||
getWindow().setAttributes(wlp);
|
||||
}
|
||||
};
|
||||
mOverlayOutAnim.setDuration(120);
|
||||
}
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.alert_dialog);
|
||||
|
||||
mDialogView = getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
mTitleTextView = (TextView)findViewById(R.id.title_text);
|
||||
mContentTextView = (TextView)findViewById(R.id.content_text);
|
||||
mErrorFrame = (FrameLayout)findViewById(R.id.error_frame);
|
||||
mErrorX = (ImageView)mErrorFrame.findViewById(R.id.error_x);
|
||||
mSuccessFrame = (FrameLayout)findViewById(R.id.success_frame);
|
||||
mProgressFrame = (FrameLayout)findViewById(R.id.progress_dialog);
|
||||
mSuccessTick = (SuccessTickView)mSuccessFrame.findViewById(R.id.success_tick);
|
||||
mSuccessLeftMask = mSuccessFrame.findViewById(R.id.mask_left);
|
||||
mSuccessRightMask = mSuccessFrame.findViewById(R.id.mask_right);
|
||||
mCustomImage = (ImageView)findViewById(R.id.custom_image);
|
||||
mWarningFrame = (FrameLayout)findViewById(R.id.warning_frame);
|
||||
mConfirmButton = (Button)findViewById(R.id.confirm_button);
|
||||
mCancelButton = (Button)findViewById(R.id.cancel_button);
|
||||
mProgressHelper.setProgressWheel((ProgressWheel)findViewById(R.id.progressWheel));
|
||||
mConfirmButton.setOnClickListener(this);
|
||||
mCancelButton.setOnClickListener(this);
|
||||
|
||||
setTitleText(mTitleText);
|
||||
setContentText(mContentText);
|
||||
setCancelText(mCancelText);
|
||||
setConfirmText(mConfirmText);
|
||||
changeAlertType(mAlertType, true);
|
||||
|
||||
}
|
||||
|
||||
private void restore () {
|
||||
mCustomImage.setVisibility(View.GONE);
|
||||
mErrorFrame.setVisibility(View.GONE);
|
||||
mSuccessFrame.setVisibility(View.GONE);
|
||||
mWarningFrame.setVisibility(View.GONE);
|
||||
mProgressFrame.setVisibility(View.GONE);
|
||||
mConfirmButton.setVisibility(View.VISIBLE);
|
||||
|
||||
mConfirmButton.setBackgroundResource(R.drawable.blue_button_background);
|
||||
mErrorFrame.clearAnimation();
|
||||
mErrorX.clearAnimation();
|
||||
mSuccessTick.clearAnimation();
|
||||
mSuccessLeftMask.clearAnimation();
|
||||
mSuccessRightMask.clearAnimation();
|
||||
}
|
||||
|
||||
private void playAnimation () {
|
||||
if (mAlertType == ERROR_TYPE) {
|
||||
mErrorFrame.startAnimation(mErrorInAnim);
|
||||
mErrorX.startAnimation(mErrorXInAnim);
|
||||
} else if (mAlertType == SUCCESS_TYPE) {
|
||||
mSuccessTick.startTickAnim();
|
||||
mSuccessRightMask.startAnimation(mSuccessBowAnim);
|
||||
}
|
||||
}
|
||||
|
||||
private void changeAlertType(int alertType, boolean fromCreate) {
|
||||
mAlertType = alertType;
|
||||
// call after created views
|
||||
if (mDialogView != null) {
|
||||
if (!fromCreate) {
|
||||
// restore all of views state before switching alert type
|
||||
restore();
|
||||
}
|
||||
switch (mAlertType) {
|
||||
case ERROR_TYPE:
|
||||
mErrorFrame.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case SUCCESS_TYPE:
|
||||
mSuccessFrame.setVisibility(View.VISIBLE);
|
||||
// initial rotate layout of success mask
|
||||
mSuccessLeftMask.startAnimation(mSuccessLayoutAnimSet.getAnimations().get(0));
|
||||
mSuccessRightMask.startAnimation(mSuccessLayoutAnimSet.getAnimations().get(1));
|
||||
break;
|
||||
case WARNING_TYPE:
|
||||
mConfirmButton.setBackgroundResource(R.drawable.red_button_background);
|
||||
mWarningFrame.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case CUSTOM_IMAGE_TYPE:
|
||||
setCustomImage(mCustomImgDrawable);
|
||||
break;
|
||||
case PROGRESS_TYPE:
|
||||
mProgressFrame.setVisibility(View.VISIBLE);
|
||||
mConfirmButton.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
if (!fromCreate) {
|
||||
playAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getAlerType () {
|
||||
return mAlertType;
|
||||
}
|
||||
|
||||
public void changeAlertType(int alertType) {
|
||||
changeAlertType(alertType, false);
|
||||
}
|
||||
|
||||
|
||||
public String getTitleText () {
|
||||
return mTitleText;
|
||||
}
|
||||
|
||||
public SweetAlertDialog setTitleText (String text) {
|
||||
mTitleText = text;
|
||||
if (mTitleTextView != null && mTitleText != null) {
|
||||
mTitleTextView.setText(mTitleText);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SweetAlertDialog setCustomImage (Drawable drawable) {
|
||||
mCustomImgDrawable = drawable;
|
||||
if (mCustomImage != null && mCustomImgDrawable != null) {
|
||||
mCustomImage.setVisibility(View.VISIBLE);
|
||||
mCustomImage.setImageDrawable(mCustomImgDrawable);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SweetAlertDialog setCustomImage (int resourceId) {
|
||||
return setCustomImage(getContext().getResources().getDrawable(resourceId));
|
||||
}
|
||||
|
||||
public String getContentText () {
|
||||
return mContentText;
|
||||
}
|
||||
|
||||
public SweetAlertDialog setContentText (String text) {
|
||||
mContentText = text;
|
||||
if (mContentTextView != null && mContentText != null) {
|
||||
showContentText(true);
|
||||
mContentTextView.setText(mContentText);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isShowCancelButton () {
|
||||
return mShowCancel;
|
||||
}
|
||||
|
||||
public SweetAlertDialog showCancelButton (boolean isShow) {
|
||||
mShowCancel = isShow;
|
||||
if (mCancelButton != null) {
|
||||
mCancelButton.setVisibility(mShowCancel ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isShowContentText () {
|
||||
return mShowContent;
|
||||
}
|
||||
|
||||
public SweetAlertDialog showContentText (boolean isShow) {
|
||||
mShowContent = isShow;
|
||||
if (mContentTextView != null) {
|
||||
mContentTextView.setVisibility(mShowContent ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCancelText () {
|
||||
return mCancelText;
|
||||
}
|
||||
|
||||
public SweetAlertDialog setCancelText (String text) {
|
||||
mCancelText = text;
|
||||
if (mCancelButton != null && mCancelText != null) {
|
||||
showCancelButton(true);
|
||||
mCancelButton.setText(mCancelText);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getConfirmText () {
|
||||
return mConfirmText;
|
||||
}
|
||||
|
||||
public SweetAlertDialog setConfirmText (String text) {
|
||||
mConfirmText = text;
|
||||
if (mConfirmButton != null && mConfirmText != null) {
|
||||
mConfirmButton.setText(mConfirmText);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SweetAlertDialog setCancelClickListener (OnSweetClickListener listener) {
|
||||
mCancelClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SweetAlertDialog setConfirmClickListener (OnSweetClickListener listener) {
|
||||
mConfirmClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void onStart() {
|
||||
mDialogView.startAnimation(mModalInAnim);
|
||||
playAnimation();
|
||||
}
|
||||
|
||||
/**
|
||||
* The real Dialog.cancel() will be invoked async-ly after the animation finishes.
|
||||
*/
|
||||
@Override
|
||||
public void cancel() {
|
||||
dismissWithAnimation(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The real Dialog.dismiss() will be invoked async-ly after the animation finishes.
|
||||
*/
|
||||
public void dismissWithAnimation() {
|
||||
dismissWithAnimation(false);
|
||||
}
|
||||
|
||||
private void dismissWithAnimation(boolean fromCancel) {
|
||||
mCloseFromCancel = fromCancel;
|
||||
mConfirmButton.startAnimation(mOverlayOutAnim);
|
||||
mDialogView.startAnimation(mModalOutAnim);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.cancel_button) {
|
||||
if (mCancelClickListener != null) {
|
||||
mCancelClickListener.onClick(SweetAlertDialog.this);
|
||||
} else {
|
||||
dismissWithAnimation();
|
||||
}
|
||||
} else if (v.getId() == R.id.confirm_button) {
|
||||
if (mConfirmClickListener != null) {
|
||||
mConfirmClickListener.onClick(SweetAlertDialog.this);
|
||||
} else {
|
||||
dismissWithAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ProgressHelper getProgressHelper () {
|
||||
return mProgressHelper;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue