1 Star 0 Fork 0

Gehj/popwindow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
PopWin_downShelf_goods.java 9.43 KB
一键复制 编辑 原始数据 按行查看 历史
Gehj 提交于 2021-03-03 10:41 . Initial commit
/*
* Copyright (c) 2020. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
* Vestibulum commodo. Ut rhoncus gravida arcu.
*/
package com.shide.businessuser.UI;
import android.app.Activity;
import android.content.Context;
import android.nfc.Tag;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.shide.businessuser.R;
import com.shide.businessuser.Utils.FuctionUtils;
import com.shide.businessuser.Utils.LogUtil;
import com.shide.businessuser.Utils.MessageEvent;
import com.shide.businessuser.http.GlobleURL;
import com.shide.businessuser.http.GsonUtils;
import com.shide.businessuser.http.OkhttpUtils;
import com.shide.businessuser.http.ParJson;
import com.shide.businessuser.http.entity.ErrorInfo;
import com.shide.businessuser.http.entity.Product;
import com.shide.businessuser.http.entity.exchargeInfo;
import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.Response;
public class PopWin_downShelf_goods extends PopupWindow {
private Button btnSure;
private Button btnCancel;
private Context mContext;
private Button btn_back_scan;
private Product product;
private Button btnDeleteGoods;
private Button btnDownShelf;
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public PopWin_downShelf_goods(Context context) {
super(context);
mContext = context;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(R.layout.popwin_down_shelf_product, null);
// 设置SelectPicPopupWindow的View
this.setContentView(view);
PopWinUtils.setBasicStyle(context,this);
initView(view);
}
private void initView(View view) {
btnDeleteGoods = (Button) view.findViewById(R.id.btn_deleteGoods);
btnDownShelf = (Button) view.findViewById(R.id.btn_down_shelf);
ImageView img_cancel= view.findViewById(R.id.imageView_cancel);
img_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
btnDeleteGoods.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteGoods();
}
});
btnDownShelf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
downGoods();
}
});
}
/**
* 显示popupWindow
* @param parent
*/
public void showPopupWindow(View parent) {
if (!this.isShowing()) {
this.showAtLocation(parent, Gravity.CENTER, 0, 0);
} else {
this.dismiss();
}
}
private void downGoods() {
if (product != null) {
FormBody.Builder builder = new FormBody.Builder();
builder.add("id", product.getId());
builder.add("shelf", "2");
OkhttpUtils.post_token_Json(GlobleURL.UpOrDownShelf, builder, new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtil.e("PopWin_downShelf_goods",e.getMessage());
Toast.makeText(mContext, "请检查网络", Toast.LENGTH_SHORT).show();
dismiss();
}
});
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
String json = response.body().string();
Boolean error = ParJson.isError(json);
if (response.code() == 401){
FuctionUtils.BackLogin(response,mContext);
return;
}
if (error) {
ErrorInfo errorData = ParJson.getErrorData(json);
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtil.e("pop_downshelf",errorData.getMessage());
// Toast.makeText(mContext, errorData.getMessage(), Toast.LENGTH_SHORT).show();
// FuctionUtils.BackLogin(response,mContext);
dismiss();
}
});
}else{
exchargeInfo ei = GsonUtils.JsonToObject(json, exchargeInfo.class);
if (ei != null) {
if (ei.getCode().equals("200")){
MessageEvent messageEvent = new MessageEvent();
messageEvent.setCode(MessageEvent.UP_DOWN_GOODS);
EventBus.getDefault().post(messageEvent);
handler.sendEmptyMessage(0);
}
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, ei.getMsg(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
});
}
}
private void deleteGoods(){
if (product != null) {
HttpUrl.Builder urlBuilder = HttpUrl.parse(GlobleURL.DeletGoods).newBuilder();
urlBuilder.addQueryParameter("id",product.getId());
OkhttpUtils.delete(urlBuilder, new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtil.e("PopWin_downShelf_goods.this",e.getMessage());
Toast.makeText(mContext, "请检查网络", Toast.LENGTH_SHORT).show();
dismiss();
}
});
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
String json = response.body().string();
Boolean error = ParJson.isError(json);
if (response.code() == 401){
FuctionUtils.BackLogin(response,mContext);
return;
}
if (error) {
ErrorInfo errorData = ParJson.getErrorData(json);
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtil.e("pop_downshelf",errorData.getMessage());
//Toast.makeText(mContext, errorData.getMessage(), Toast.LENGTH_SHORT).show();
//FuctionUtils.BackLogin(response,mContext);
dismiss();
}
});
}else{
exchargeInfo ei = GsonUtils.JsonToObject(json, exchargeInfo.class);
if (ei != null) {
if (ei.getCode().equals("200")){
MessageEvent messageEvent = new MessageEvent();
messageEvent.setCode(MessageEvent.UP_DOWN_GOODS);
EventBus.getDefault().post(messageEvent);
handler.sendEmptyMessage(0);
}
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, ei.getMsg(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
});
}
}
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what == 0){
dismiss();
}
}
};
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hjmayun/popwindow.git
[email protected]:hjmayun/popwindow.git
hjmayun
popwindow
popwindow
master

搜索帮助