动画跳转到详情MVP

布局

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="zhuyuanyuan.bwei.com.yuekaomoni.MainActivity">

    <ImageView
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:id="@+id/image_view"
        android:src="@mipmap/ic_launcher_round"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>


activity_XiangQing.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="zhuyuanyuan.bwei.com.yuekaomoni.XiangqingActivity">
<TextView
    android:id="@+id/xq_sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="商品详情"
    android:textSize="22dp"
    android:layout_gravity="center"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/xq_yuanjia"
    android:layout_toEndOf="@+id/xq_yuanjia"
    android:layout_marginLeft="82dp"
    android:layout_marginStart="82dp" />
    <TextView
        android:layout_below="@+id/xq_sp"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000"
        android:id="@+id/xq_t"
        />
    <ImageView
        android:layout_below="@+id/xq_t"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:id="@+id/xq_img"
        android:src="@mipmap/ic_launcher_round"
        />
    <TextView
        android:layout_below="@+id/xq_img"
        android:text="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:id="@+id/xq_title"
        android:layout_marginTop="10dp"
        />
    <TextView
        android:layout_below="@+id/xq_title"
        android:text="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/xq_yuanjia"
        android:textColor="#000"
        android:textSize="20dp"
        android:layout_marginTop="10dp"
        />
    <TextView
        android:layout_below="@id/xq_yuanjia"
        android:text="1"
        android:layout_marginTop="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/xq_price"
        android:textColor="#f00"
        android:textSize="20dp"
        />
    <LinearLayout
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="购物车"
            android:layout_weight="1"
            android:id="@+id/gouwuche"
            />
        <Button
            android:id="@+id/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="加入购物车"
            android:layout_weight="1"
            />
    </LinearLayout>
</RelativeLayout>


MainActivity类


public class MainActivity extends AppCompatActivity {
    private ImageView img;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img = (ImageView) findViewById(R.id.image_view);

      zuhe();


    }

    public void zuhe() {

        ObjectAnimator y = ObjectAnimator.ofFloat(img, "Y", 500, 500, 800, 800);

        ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 0.0f, 1);

        ObjectAnimator rotationX = ObjectAnimator.ofFloat(img, "rotationX", 0, 360);
        ObjectAnimator rotationY = ObjectAnimator.ofFloat(img, "rotationY", 0, 360);

        ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", 0.5f, 2);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(img, "scaleY", 0.5f, 2);

        //组合
        AnimatorSet animatorSet = new AnimatorSet();

        //放到一起
        animatorSet.play(y).with(alpha).with(rotationX).with(rotationY).with(scaleX).with(scaleY);

        animatorSet.setDuration(3000);
        animatorSet.start();

        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {
                //动画结束跳转页面
                Intent intent=new Intent(MainActivity.this,XiangqingActivity.class);
                startActivity(intent);
                finish();
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });
    }
}
XiangqingActivity类

public class XiangqingActivity extends AppCompatActivity implements IXQAcvity{


    private XQpresenter xQpresente;
    private  String url="https://www.zhaoapi.cn/product/getProductDetail";
    private ImageView img;
    private TextView title;
    private TextView yuanjia;
    private TextView price;
    private Button gouwuche;
    private Button add;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiangqing);

        img = (ImageView) findViewById(R.id.xq_img);
        title = (TextView) findViewById(R.id.xq_title);
        yuanjia = (TextView) findViewById(R.id.xq_yuanjia);
        price = (TextView) findViewById(R.id.xq_price);
        gouwuche = (Button) findViewById(R.id.gouwuche);
        add = (Button) findViewById(R.id.add);


        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> params=new HashMap<String, String>();
                params.put("Uid","3690");
                params.put("Pid","84");
                OkHttp3Util_03.doPost("https://www.zhaoapi.cn/product/addCart", params, new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {

                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        final String json = response.body().string();
                     runOnUiThread(new Runnable() {
                         @Override
                         public void run() {
                             Gson gson=new Gson();
                             Add add = gson.fromJson(json, Add.class);
                             String code = add.getCode();
                             if(code.equals("0")){
                                 Toast.makeText(XiangqingActivity.this,add.getMsg(),Toast.LENGTH_SHORT).show();
                             }else {
                                 Toast.makeText(XiangqingActivity.this,add.getMsg(),Toast.LENGTH_SHORT).show();
                             }

                         }
                     });



                    }
                });
            }
        });


        gouwuche.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(XiangqingActivity.this,GouWucheActivity.class);
                startActivity(intent);
            }
        });



        //中间者

        xQpresente = new XQpresenter(this);

        xQpresente.getCartData(url);

    }



    @Override
    public void onSuccess(final XiangQing xiangQing) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                XiangQing.DataBean data = xiangQing.getData();
               title.setText(data.getTitle());
                yuanjia.setText(""+data.getBargainPrice());
                price.setText(""+ data.getPrice());
                String[] split = data.getImages().split("\\|");
                Log.e("aaaa",data.getImages());
                Glide.with(XiangqingActivity.this).load(split[0]).into(img);
            }
        });
    }

    @Override
    public void onError(String s) {

    }
}

model层

XQmodel类


public class XQmodel {
    private final XQpre XQpre;

    public XQmodel(XQpre XQpre) {

        this.XQpre=XQpre;
    }

    public void getCartData(String url) {
        Map<String, String> params=new HashMap<>();

        params.put("pid","71");

        OkHttp3Util_03.doPost(url, params, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {

                      if (response.isSuccessful()){
                          String json = response.body().string();



                          XiangQing xiangQing = new Gson().fromJson(json, XiangQing.class);

                             //回传数据
                          XQpre.onSuccess(xiangQing);

                      }
            }
        });
    }
}

presnter层

 

XQpre接口
public interface XQpre {

    void onSuccess(XiangQing xiangQing);
    void onError(String s);
}
 XQpresenter类

public class XQpresenter implements XQpre { private final XQmodel xQmodel; private final IXQAcvity IXQAcvity; public XQpresenter(IXQAcvity IXQAcvity) { this.IXQAcvity=IXQAcvity; xQmodel = new XQmodel(this); } public void getCartData(String url) { xQmodel.getCartData(url); } @Override public void onSuccess(XiangQing xiangQing) { IXQAcvity.onSuccess(xiangQing); } @Override public void onError(String s) { }}
IXQAcvity接口


public interface IXQAcvity {

    void onSuccess(XiangQing xiangQing);
    void onError(String s);
}

详情Bean类

XiangQing

public class XiangQing {

    /**
     * msg :
     * seller : {"description":"我是商家15","icon":"http://120.27.23.105/images/icon.png","name":"商家15","productNums":999,"score":5,"sellerid":15}
     * code : 0
     * data : {"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":0,"pid":71,"price":32999,"pscid":40,"salenum":4242,"sellerid":15,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP213英寸Bar i5/8G/256G"}
     */

    private String msg;
    private SellerBean seller;
    private String code;
    private DataBean data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public SellerBean getSeller() {
        return seller;
    }

    public void setSeller(SellerBean seller) {
        this.seller = seller;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public DataBean getData() {
        return data;
    }

    public void setData(DataBean data) {
        this.data = data;
    }

    public static class SellerBean {
        /**
         * description : 我是商家15
         * icon : http://120.27.23.105/images/icon.png
         * name : 商家15
         * productNums : 999
         * score : 5.0
         * sellerid : 15
         */

        private String description;
        private String icon;
        private String name;
        private int productNums;
        private double score;
        private int sellerid;

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getIcon() {
            return icon;
        }

        public void setIcon(String icon) {
            this.icon = icon;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getProductNums() {
            return productNums;
        }

        public void setProductNums(int productNums) {
            this.productNums = productNums;
        }

        public double getScore() {
            return score;
        }

        public void setScore(double score) {
            this.score = score;
        }

        public int getSellerid() {
            return sellerid;
        }

        public void setSellerid(int sellerid) {
            this.sellerid = sellerid;
        }
    }

    public static class DataBean {
        /**
         * bargainPrice : 11800.0
         * createtime : 2017-10-03T23:53:28
         * detailUrl : https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1
         * images : https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg
         * itemtype : 0
         * pid : 71
         * price : 32999.0
         * pscid : 40
         * salenum : 4242
         * sellerid : 15
         * subhead : 购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)
         * title : 全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP213英寸Bar i5/8G/256G
         */

        private double bargainPrice;
        private String createtime;
        private String detailUrl;
        private String images;
        private int itemtype;
        private int pid;
        private double price;
        private int pscid;
        private int salenum;
        private int sellerid;
        private String subhead;
        private String title;

        public double getBargainPrice() {
            return bargainPrice;
        }

        public void setBargainPrice(double bargainPrice) {
            this.bargainPrice = bargainPrice;
        }

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }

        public String getDetailUrl() {
            return detailUrl;
        }

        public void setDetailUrl(String detailUrl) {
            this.detailUrl = detailUrl;
        }

        public String getImages() {
            return images;
        }

        public void setImages(String images) {
            this.images = images;
        }

        public int getItemtype() {
            return itemtype;
        }

        public void setItemtype(int itemtype) {
            this.itemtype = itemtype;
        }

        public int getPid() {
            return pid;
        }

        public void setPid(int pid) {
            this.pid = pid;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public int getPscid() {
            return pscid;
        }

        public void setPscid(int pscid) {
            this.pscid = pscid;
        }

        public int getSalenum() {
            return salenum;
        }

        public void setSalenum(int salenum) {
            this.salenum = salenum;
        }

        public int getSellerid() {
            return sellerid;
        }

        public void setSellerid(int sellerid) {
            this.sellerid = sellerid;
        }

        public String getSubhead() {
            return subhead;
        }

        public void setSubhead(String subhead) {
            this.subhead = subhead;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }
    }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值