二级购物车流失布局6.0权限

//Retrofit加Rxjava加ok的工具类
public class RxjavaUtils {

    //单例
    private static RxjavaUtils rxjavaUtils;

    private RxjavaUtils(){

    }


    public static RxjavaUtils getInstence(){
        if(rxjavaUtils==null){
            synchronized (RxjavaUtils.class){
                if(rxjavaUtils==null){
                    rxjavaUtils=new RxjavaUtils();
                }
            }
        }
        return rxjavaUtils;
    }

    //ok封装请求头
    private static OkHttpClient okHttpClient;

    public static synchronized OkHttpClient getOkHttpClient(){
        //拦截器
        HttpLoggingInterceptor httpLoggingInterceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
            @Override
            public void log(String message) {
                Log.d("拦截",message);
            }
        });
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        if(okHttpClient==null){
            okHttpClient=new OkHttpClient.Builder()
                         .addInterceptor(httpLoggingInterceptor)
                         .addInterceptor(new Interceptor() {
                             @Override
                             public Response intercept(Chain chain) throws IOException {
                                 Request build = chain.request().newBuilder()
                                         .addHeader("userId", "")
                                         .addHeader("sessionId", "")
                                         .build();

                                 return chain.proceed(build);
                             }
                         })
                         .build();
        }
        return okHttpClient;
    }
    //retrofit
    public static Retrofit getRetrofit(String url){
        Retrofit retrofit = new Retrofit.Builder()
                .client(getOkHttpClient())
                .baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        return retrofit;
    }
    //动态代理
    public <T>T getServie(String url,Class<T> service){
        Retrofit retrofit = getRetrofit(url);
        T t = retrofit.create(service);
        return t;
    }
}

购车车的fragment


public class ShoppingFragment extends BaseFragment implements ShoppingView {
    @BindView(R.id.rlv)
    RecyclerView rlv;
    @BindView(R.id.qx)
    CheckBox qx;
    @BindView(R.id.price)
    TextView price;
    @BindView(R.id.jiesuan)
    Button jiesuan;
    Unbinder unbinder;
    private ShoppingPresenter shoppingPresenter;

    @Override
    protected int setContentView() {
        return R.layout.shopping_fragment;
    }

    @Override
    protected void initView(View view) {
        unbinder = ButterKnife.bind(this, view);
        rlv.setLayoutManager(new LinearLayoutManager(getActivity()));


    }

    @Override
    protected void lazyData() {
        Log.d("xxx", "ShoppingFragment");
        //mvp
        shoppingPresenter = new ShoppingPresenter(this);
        shoppingPresenter.related();
        shoppingPresenter.attachView(this);

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        shoppingPresenter.dettachView();
    }

    //购物车数据
    @Override
    public void getShoppingSerch(final ArrayList<ShoppingJson.Datas> data) {
        final MyShppingPresentAdapter myShppingPresentAdapter = new MyShppingPresentAdapter(getActivity(), data);
        rlv.setAdapter(myShppingPresentAdapter);
        //点击全选及全不选及价格
        qx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i<data.size(); i++) {
                    //将最外层复选框的值赋值给商家
                    data.get(i).setCb_parent(qx.isChecked());
                    for (int j = 0; j <data.get(i).getList().size(); j++) {
                        //将最外层复选框的值赋值给商品
                        data.get(i).getList().get(j).setCb_child(qx.isChecked());
                    }
                }
                myShppingPresentAdapter.notifyDataSetChanged();
                //价格
                zongmoney(data);
            }
        });

        myShppingPresentAdapter.setBool(new MyShppingPresentAdapter.Bool() {
            @Override
            public void getdate() {
                boolean da=true;
                for (int i = 0; i<data.size(); i++) {
                    //将商家的状态给变量
                    da= da&data.get(i).isCb_parent();
                    for (int j = 0; j <data.get(i).getList().size(); j++) {
                        //将商品的状态给变量
                        da= da&data.get(i).getList().get(j).isCb_child();
                    }
                }
                qx.setChecked(da);
                //价格
                zongmoney(data);
            }
        });





    }


    //总价
    private void zongmoney(ArrayList<ShoppingJson.Datas> data) {
        double zong=0;
        for (int i = 0; i<data.size(); i++) {
            for (int j = 0; j <data.get(i).getList().size(); j++) {
                if (data.get(i).getList().get(j).isCb_child()){
                    //价格乘以数量    数量的值为集合中自己添的字段
                    int count = data.get(i).getList().get(j).getNum();
                    String price = data.get(i).getList().get(j).getPrice();
                    Float aFloat = Float.valueOf(price);
                    double i1 = aFloat*count;
                    zong+=i1;
                }
            }
        }
        price.setText(zong+"");
    }




}

父适配器

public class MyShppingPresentAdapter extends RecyclerView.Adapter<MyShppingPresentAdapter.MyViewHoder> {

    private Context context;
    private ArrayList<ShoppingJson.Datas> data;
    private MyShppingChildAdapter myShppingChildAdapter;
    private ArrayList<ShoppingJson.Datas.Shopping> list;


    public MyShppingPresentAdapter(Context context, ArrayList<ShoppingJson.Datas> data) {
        this.context = context;
        this.data = data;
    }


    @NonNull
    @Override
    public MyViewHoder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = View.inflate(context, R.layout.shopping_parent, null);
        MyViewHoder myViewHoder = new MyViewHoder(inflate);

        return myViewHoder;
    }









    @Override
    public void onBindViewHolder(@NonNull final MyViewHoder myViewHoder, final int i) {
        //设置父的复选框
        myViewHoder.cb_parent.setChecked(data.get(i).isCb_parent());

        myViewHoder.name.setText(data.get(i).getSellerName());
        myViewHoder.rvl.setLayoutManager(new LinearLayoutManager(context));
        //数据
        list = data.get(i).getList();
        myShppingChildAdapter = new MyShppingChildAdapter(context,list);
        myViewHoder.rvl.setAdapter(myShppingChildAdapter);


        //商家控制商品
        myViewHoder.cb_parent.setOnClickListener(null);
        myViewHoder.cb_parent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int j = 0; j<data.get(i).getList().size(); j++) {
                    data.get(i).getList().get(j).setCb_child(myViewHoder.cb_parent.isChecked());
                }
                data.get(i).setCb_parent(myViewHoder.cb_parent.isChecked());
                notifyDataSetChanged();
                //商家接口回调状态
                bool.getdate();
            }
        });

        //反选   商品的接口回调方法中

        myShppingChildAdapter.setBooll(new MyShppingChildAdapter.Booll() {
            @Override
            public void getdate() {
                boolean da=true;
                for (int j = 0; j <data.get(i).getList().size(); j++) {
                    da=da&data.get(i).getList().get(j).isCb_child();
                }
                data.get(i).setCb_parent(da);
                myShppingChildAdapter.notifyDataSetChanged();
                notifyDataSetChanged();
                //商家接口回调状态
                bool.getdate();
            }

        });





    }

    @Override
    public int getItemCount() {
        return data.size();
    }




    //商家的接口回调
    public interface Bool{
        void getdate();
    }

    private Bool bool;

    public void setBool(Bool bool) {
        this.bool = bool;
    }

    class MyViewHoder extends RecyclerView.ViewHolder {

        private final CheckBox cb_parent;
        private final TextView name;
        private final RecyclerView rvl;

        public MyViewHoder(@NonNull View itemView) {
            super(itemView);
            cb_parent = itemView.findViewById(R.id.cb_parent);
            name = itemView.findViewById(R.id.name);
            rvl = itemView.findViewById(R.id.rvl);


        }
    }
}

子适配器

public class MyShppingChildAdapter extends RecyclerView.Adapter<MyShppingChildAdapter.MyViewHoder> {

    private Context context;
    ArrayList<ShoppingJson.Datas.Shopping> list;


    public MyShppingChildAdapter(Context context, ArrayList<ShoppingJson.Datas.Shopping> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHoder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = View.inflate(context, R.layout.shopping_child, null);
        MyViewHoder myViewHoder = new MyViewHoder(inflate);

        return myViewHoder;
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHoder myViewHoder, final int i) {

        //设置子状态
        myViewHoder.cb_child.setChecked(list.get(i).isCb_child());
        myViewHoder.img.setImageURI(list.get(i).getImages());
        myViewHoder.name.setText(list.get(i).getTitle());
        myViewHoder.price.setText(list.get(i).getPrice() + "");


        //商家控制商品
        myViewHoder.cb_child.setOnCheckedChangeListener(null);
        myViewHoder.cb_child.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                list.get(i).setCb_child(myViewHoder.cb_child.isChecked());
                //商品的接口回调
                booll.getdate();
            }
        });
        //自定义加减器中的方法构造传参  设置中间的值
        myViewHoder.jiajianqi.setnumbre(list.get(i).getNum());
        //加减器的数量设置bean类中定义的count
        myViewHoder.jiajianqi.setOnGetNums(new JiaJianQi.OnGetNums() {
            @Override
            public void getNum(int num) {
                list.get(i).setNum(num);
                //商品的接口回调
                booll.getdate();

            }
        });



    }







    //商家的接口回调
    public interface Booll{
        void getdate();
    }

    private Booll booll;


    public void setBooll(Booll booll) {
        this.booll = booll;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    class MyViewHoder extends RecyclerView.ViewHolder {


        private final CheckBox cb_child;
        private final SimpleDraweeView img;
        private final TextView name;
        private final TextView price;
        private final JiaJianQi jiajianqi;


        public MyViewHoder(@NonNull View itemView) {
            super(itemView);
            cb_child = itemView.findViewById(R.id.cb_child);
            img = itemView.findViewById(R.id.img);
            name = itemView.findViewById(R.id.name);
            price = itemView.findViewById(R.id.price);
            jiajianqi = itemView.findViewById(R.id.jiajianqi);


        }
    }
}

流失布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".activity.LiuActivity">

    <com.bwei.crq.custom.Serch
        android:id="@+id/serch"
        android:layout_width="match_parent"
        android:layout_height="50dp"></com.bwei.crq.custom.Serch>

    <com.bwei.crq.custom.Zidingyi
        android:id="@+id/zidingyi"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></com.bwei.crq.custom.Zidingyi>


</LinearLayout>

流失布局的LiuActivity

public class LiuActivity extends AppCompatActivity {

    @BindView(R.id.serch)
    Serch serch;
    @BindView(R.id.zidingyi)
    Zidingyi zidingyi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_liu);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        String name = intent.getExtras().getString("name");
        serch.setOnGetSerchListener(new Serch.OnGetSerchListener() {
            @Override
            public void getSerchData(String s) {
                final ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT);
                Toast.makeText(LiuActivity.this, s, Toast.LENGTH_SHORT).show();
                //手动new一个自己想到的控件
                final Button  button = new Button(LiuActivity.this);
                //设置值
                button.setText(s);
                zidingyi.addView(button,params);

            }
        });
        //S 为输入框的值
        final ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT);
        //手动new一个自己想到的控件
        final Button button = new Button(LiuActivity.this);
        //设置值
        button.setText(name);
        //添加
        zidingyi.addView(button,params);
        //流逝布局中的点击事件



    }
}

public class Zidingyi extends ViewGroup {
    public Zidingyi(Context context) {
        super(context);
    }

    public Zidingyi(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public Zidingyi(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        measureChildren(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean b, int i, int i1, int i2, int i3) {
        int witth = getWidth();
        int low = 0;//定义常量
        int diswith = 18;//定义行间距
        for (int j = 0; j < getChildCount(); j++) {
            View child = getChildAt(j);
            int width = child.getMeasuredWidth();
            int height = child.getMeasuredHeight();
            if (diswith + width > witth) {
                low++;
                diswith = 18;
            }
            child.layout(diswith, low * height, diswith + width, height * (low + 1));
            diswith += width;

        }
    }
 }

6.0权限

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.viewpage)
    ViewPager viewpage;
    @BindView(R.id.rb1)
    RadioButton rb1;
    @BindView(R.id.rb2)
    RadioButton rb2;
    @BindView(R.id.rb3)
    RadioButton rb3;
    @BindView(R.id.rg)
    RadioGroup rg;
    private Unbinder bind;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bind = ButterKnife.bind(this);

        //集合
        final ArrayList<Fragment> fragments = new ArrayList<>();
        HomeFragment homeFragment = new HomeFragment();
        ShoppingFragment shoppingFragment = new ShoppingFragment();
        MyFragment myFragment = new MyFragment();
        fragments.add(homeFragment);
        fragments.add(shoppingFragment);
        fragments.add(myFragment);

        //适配器
        viewpage.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                return fragments.get(i);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });


        //默认选中
        rg.check(rg.getChildAt(0).getId());


        //点击按钮切换
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rb1:
                        viewpage.setCurrentItem(0);
                        break;
                    case R.id.rb2:
                        viewpage.setCurrentItem(1);

                        break;
                    case R.id.rb3:
                        viewpage.setCurrentItem(2);

                        break;
                }
            }
        });


        //滑动页面切换
        viewpage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                rg.check(rg.getChildAt(i).getId());
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
        applypermission();


    }

    //6.0权限
    public void applypermission(){
        //判断版本
        if (Build.VERSION.SDK_INT>=23){
            //检查权限是否已经开通
            int checkSelfPermission = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA);

            if (checkSelfPermission != PackageManager.PERMISSION_GRANTED){
                //未开通
                Log.i("xxx","动态申请");
                //参数分别是当前活动,权限字符串数组,requestcode
                ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CAMERA},1);
            }
        }else {
            Log.i("xxx","版本不高无需授权");
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        //grantResults数组与权限字符串数组对应,里面存放权限申请结果
        if (grantResults[0]==PackageManager.PERMISSION_GRANTED){
            Toast.makeText(this, "已授权", Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(this, "授权失败", Toast.LENGTH_SHORT).show();
        }
    }




}

public class MyFragment extends BaseFragment {


    @BindView(R.id.img)
    ImageView img;
    Unbinder unbinder;

    @Override
    protected int setContentView() {
        return R.layout.my_fragment;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this, view);


    }

    @Override
    protected void lazyData() {
        Log.d("xxx", "MyFragment");
        //   1.图标旋转的开启和复位

        img.animate().setDuration(500).rotation(180).start();

        img.animate().setDuration(500).rotation(0).start();//旋转0度是复位

        //  2.设置popupwindow
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(Build.VERSION.SDK_INT>=23){
                            String[] mPermissionList = new String[]{Manifest.permission.CAMERA};
                            ActivityCompat.requestPermissions(getActivity(),mPermissionList,123);
                        }
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setTitle("提示");
                        builder.setMessage("开启吗?");
                        builder.setPositiveButton("相机", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                intent.addCategory("android.intent.category.DEFAULT");
                                startActivityForResult(intent, 1);
                            }
                        });
                        builder.setNegativeButton("相册", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(Intent.ACTION_PICK);
                                intent.setType("image/*");
                                startActivityForResult(intent, 2);
                            }
                        });
                        builder.show();



 
                    }
                });


            }
        });
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==1){
            Parcelable data1 = data.getParcelableExtra("data");
            img.setImageBitmap((Bitmap) data1);
        }

        if (requestCode==2){
            Uri data1 = data.getData();
            img.setImageURI(data1);
        }
    }

webview

   //商品详情
        //支持javascript
        webView.getSettings().setJavaScriptEnabled(true);
        // 设置可以支持缩放
        webView.getSettings().setSupportZoom(true);
        // 设置出现缩放工具
        webView.getSettings().setBuiltInZoomControls(true);
        //扩大比例的缩放
        webView.getSettings().setUseWideViewPort(true);
        //自适应屏幕
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.loadData(result.getDetails(), "Text/html", "UTF-8");
        webView.setWebChromeClient(new WebChromeClient());
        webView.setWebViewClient(new WebViewClient());
  • 1
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值