Mainactivity主页面
package com.example.week3.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.example.week3.Bean.LoginBean;
import com.example.week3.Activity.IMain.IMainloginactivity;
import com.example.week3.R;
import com.example.week3.presenter.Mainloginpresenter;
import com.example.week3.uitl.Api;
public class MainActivity extends AppCompatActivity implements IMainloginactivity {
private EditText name;
private EditText pass;
private Mainloginpresenter mainloginpresenter;
private int page=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (EditText) findViewById(R.id.name);
pass = (EditText) findViewById(R.id.pass);
//创建中间者
mainloginpresenter = new Mainloginpresenter(this);
}
//登录
public void login(View view) {
String sname = name.getText().toString();
String password = pass.getText().toString();
mainloginpresenter.getlogin(Api.login,sname,password);
}
//接收数据
@Override
public void login(final LoginBean loginBean) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String msg = loginBean.getMsg();
if(msg.equals("登录成功")){
Intent intent = new Intent(MainActivity.this,Mainzhanshi.class);
startActivity(intent);
Toast.makeText(MainActivity.this, loginBean.getMsg(), Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(MainActivity.this, loginBean.getMsg(), Toast.LENGTH_SHORT).show();
}
}
});
}
//注册
public void zhuce(View view) {
startActivity(new Intent(MainActivity.this,Mainzhuce.class));
}
}
放大的类
package com.example.week3.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.example.week3.R;
import com.example.week3.uitl.ZoomImageView;
import java.util.ArrayList;
public class Mainfangda extends AppCompatActivity {
private ViewPager viewPager;
private ArrayList<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainfangda);
viewPager = (ViewPager) findViewById(R.id.view_pager);
list = getIntent().getStringArrayListExtra("list");
if (list != null) {
viewPager.setAdapter(new PagerAdapter() {
@Override
public Object instantiateItem(ViewGroup container, int position) {
ZoomImageView imageView = new ZoomImageView(Mainfangda.this);
Glide.with(Mainfangda.this).load(list.get(position)).into(imageView);
container.addView(imageView);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public int getCount() {
return list.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
});
}
}
}
详情页面
package com.example.week3.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.week3.Bean.XqBean;
import com.example.week3.Grile.Grile;
import com.example.week3.R;
import com.example.week3.uitl.OkHttp3Util;
import com.google.gson.Gson;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
public class Mainxiangqing extends AppCompatActivity {
private TextView title;
private TextView price;
private TextView price2;
private Banner banner;
private int pid;
List<String> list = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainxiangqing);
title = (TextView) findViewById(R.id.title);
price = (TextView) findViewById(R.id.price);
price2 = (TextView) findViewById(R.id.price2);
banner = (Banner) findViewById(R.id.banner);
Intent intent = getIntent();
pid = intent.getIntExtra("pid", 0);
banner.setOnBannerListener(new OnBannerListener() {
@Override
public void OnBannerClick(int position) {
Intent intent1 = new Intent(Mainxiangqing.this,Mainfangda.class);
intent1.putStringArrayListExtra("list", (ArrayList<String>) list);
startActivity(intent1);
}
});
//获取详情数据get请求
OkHttp3Util.doGet("https://www.zhaoapi.cn/product/getProductDetail?pid="+ pid, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if(response.isSuccessful()){
final String json = response.body().string();
XqBean xqBean = new Gson().fromJson(json, XqBean.class);
String images = xqBean.getData().getImages();
final String name = xqBean.getData().getTitle();
final double sprice = xqBean.getData().getPrice();
final double bargainPrice = xqBean.getData().getBargainPrice();
// Log.d("?????","aaaa"+images);
String[] split = images.split("\\|");
for(String string:split){
list.add(string);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
//详情页面轮播
banner.setImageLoader(new Grile());
banner.setDelayTime(3000);
banner.isAutoPlay(false);
banner.setImages(list);
banner.start();
//详情标题,价钱
title.setText(name);
price.setText("原价"+sprice+"");
price2.setText("优惠价"+bargainPrice+"");
}
});
}
}
});
}
}
展示页面
package com.example.week3.Activity;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import com.example.week3.Activity.IMain.IMainsearchactivity;
import com.example.week3.Adapter.SearchgrupAdapter;
import com.example.week3.Adapter.SearchlistAdapter;
import com.example.week3.Bean.SearchBean;
import com.example.week3.R;
import com.example.week3.dianji_jiekou.OnItemClickListner;
import com.example.week3.presenter.IMainloginpresenter.IMainsearchpresenter;
import com.example.week3.presenter.Miansearchpresenter;
import com.example.week3.uitl.Api;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.ArrayList;
import java.util.List;
public class Mainzhanshi extends AppCompatActivity implements IMainsearchactivity {
private EditText search;
private CheckBox checkBox;
private XRecyclerView xRecyclerView;
private Miansearchpresenter miansearchpresenter;
private List<SearchBean.DataBean> data = new ArrayList<>();
boolean flag =false;
private SearchlistAdapter listview;
private SearchgrupAdapter gv;
private int page=1;
private String searchname;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainzhanshi);
search = (EditText) findViewById(R.id.searchname);
checkBox = (CheckBox) findViewById(R.id.ck);
xRecyclerView = (XRecyclerView) findViewById(R.id.xrv);
//创建中间者
miansearchpresenter = new Miansearchpresenter(this);
}
//点击搜索
public void search(View view) {
searchname = search.getText().toString();
miansearchpresenter.getsearch(Api.search, searchname,page);
}
//接收数据
@Override
public void search(final SearchBean searchBean) {
runOnUiThread(new Runnable() {
@Override
public void run() {
data = searchBean.getData();
Log.d("TAG","斌哥"+searchBean);
Toast.makeText(Mainzhanshi.this, searchBean.getMsg(), Toast.LENGTH_SHORT).show();
//展示数据
listview();
//判断checkbok
checkBox.setChecked(flag);
if(checkBox.isChecked()){
group();
gv.notifyDataSetChanged();
}
else{
listview();
listview.notifyDataSetChanged();
}
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(flag){
listview();
checkBox.setChecked(false);
flag = checkBox.isChecked();
}
else{
group();
checkBox.setChecked(true);
flag = checkBox.isChecked();
}
}
});
xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
data.clear();
miansearchpresenter.getsearch(Api.search, searchname,1);
xRecyclerView.refreshComplete();
}
},2000);
}
@Override
public void onLoadMore() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
page++;
miansearchpresenter.getsearch(Api.search, searchname,page);
xRecyclerView.loadMoreComplete();
}
},2000);
}
});
}
});
}
public void listview(){
xRecyclerView.setLayoutManager(new LinearLayoutManager(Mainzhanshi.this,LinearLayoutManager.VERTICAL,false));
listview = new SearchlistAdapter(data,Mainzhanshi.this);
xRecyclerView.setAdapter(listview);
listview.setOnitemClickListner(new OnItemClickListner() {
@Override
public void OnItemClick(int position) {
SearchBean.DataBean dataBean = data.get(position);
int pid = dataBean.getPid();
Intent intent = new Intent(Mainzhanshi.this,Mainxiangqing.class);
intent.putExtra("pid",pid);
startActivity(intent);
}
});
}
public void group(){
xRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, GridLayoutManager.VERTICAL));
gv = new SearchgrupAdapter(data,Mainzhanshi.this);
xRecyclerView.setAdapter(gv);
gv.setOnitemClickListner(new OnItemClickListner() {
@Override
public void OnItemClick(int position) {
SearchBean.DataBean dataBean = data.get(position);
int pid = dataBean.getPid();
Intent intent = new Intent(Mainzhanshi.this,Mainxiangqing.class);
intent.putExtra("pid",pid);
startActivity(intent);
}
});
}
}
注册页面
package com.example.week3.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.example.week3.Activity.IMain.IMainzhuceactivity;
import com.example.week3.Bean.ZhuceBean;
import com.example.week3.R;
import com.example.week3.presenter.Mainzhucepresenter;
import com.example.week3.uitl.Api;
public class Mainzhuce extends AppCompatActivity implements IMainzhuceactivity {
private EditText sname;
private EditText pwd;
private Mainzhucepresenter mainzhucepresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainzhuce);
sname = (EditText) findViewById(R.id.sname);
pwd = (EditText) findViewById(R.id.pwd);
//创建中间者
mainzhucepresenter = new Mainzhucepresenter(this);
}
//注册
public void zhuc(View view) {
String name = sname.getText().toString();
String pass = pwd.getText().toString();
mainzhucepresenter.getzhuce(Api.zhuce,name,pass);
}
@Override
public void zhuce(final ZhuceBean zhuceBean) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String msg = zhuceBean.getMsg();
if(msg.equals("注册成功")){
startActivity(new Intent(Mainzhuce.this,MainActivity.class));
finish();
Toast.makeText(Mainzhuce.this, zhuceBean.getMsg(), Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Mainzhuce.this, zhuceBean.getMsg(), Toast.LENGTH_SHORT).show();
}
}
});
}
}
登录接口
package com.example.week3.Activity.IMain;
import com.example.week3.Bean.LoginBean;
/**
* Created by huoxuebin on 2018/1/18.
*/
public interface IMainloginactivity {
void login(LoginBean loginBean);
}
查询接口
package com.example.week3.Activity.IMain;
import com.example.week3.Bean.SearchBean;
/**
* Created by huoxuebin on 2018/1/18.
*/
public interface IMainsearchactivity {
void search(SearchBean searchBean);
}
注册接口
package com.example.week3.Activity.IMain;
import com.example.week3.Bean.ZhuceBean;
/**
* Created by huoxuebin on 2018/1/18.
*/
public interface IMainzhuceactivity {
void zhuce(ZhuceBean zhuceBean);
}
SearchgrupAdapter适配器
package com.example.week3.Adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.example.week3.Bean.SearchBean;
import com.example.week3.R;
import com.example.week3.dianji_jiekou.OnItemClickListner;
import com.example.week3.holder.Holder;
import java.util.List;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class SearchgrupAdapter extends RecyclerView.Adapter<Holder> {
List<SearchBean.DataBean> data;;
Context context;
private OnItemClickListner onitemClickListner;
public SearchgrupAdapter(List<SearchBean.DataBean> data, Context context) {
this.data = data;
this.context = context;
}
@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.search_group, parent, false);
Holder holder = new Holder(view);
return holder;
}
@Override
public void onBindViewHolder(Holder holder, final int position) {
final SearchBean.DataBean dataBean = data.get(position);
String images = dataBean.getImages();
String[] split = images.split("\\|");
Glide.with(context).load(split[0]).into(holder.img);
holder.title.setText(dataBean.getTitle());
holder.price.setText("原价" + dataBean.getPrice() + "");
holder.zhoukou.setText("折扣价" + dataBean.getBargainPrice() + "");
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onitemClickListner.OnItemClick(position);
}
});
}
@Override
public int getItemCount() {
return data.size();
}
public void setOnitemClickListner(OnItemClickListner onitemClickListner){
this.onitemClickListner =onitemClickListner;
}
}
SearchlistAdapter适配器
package com.example.week3.Adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.example.week3.Bean.SearchBean;
import com.example.week3.R;
import com.example.week3.dianji_jiekou.OnItemClickListner;
import com.example.week3.holder.Holder;
import java.util.List;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class SearchlistAdapter extends RecyclerView.Adapter<Holder> {
List<SearchBean.DataBean> data;;
Context context;
private OnItemClickListner onitemClickListner;
public SearchlistAdapter(List<SearchBean.DataBean> data, Context context) {
this.data = data;
this.context = context;
}
@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.search_listview, parent, false);
Holder holder = new Holder(view);
return holder;
}
@Override
public void onBindViewHolder(Holder holder, final int position) {
SearchBean.DataBean dataBean = data.get(position);
String images = dataBean.getImages();
String[] split = images.split("\\|");
Glide.with(context).load(split[0]).into(holder.img);
holder.title.setText(dataBean.getTitle());
holder.price.setText("原价"+dataBean.getPrice()+"");
holder.zhoukou.setText("折扣价"+dataBean.getBargainPrice()+"");
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onitemClickListner.OnItemClick(position);
}
});
}
@Override
public int getItemCount() {
return data.size();
}
public void setOnitemClickListner(OnItemClickListner onitemClickListner){
this.onitemClickListner =onitemClickListner;
}
}
点击的接口OnItemClickListner
package com.example.week3.dianji_jiekou;
/**
* Created by huoxuebin on 2018/1/9.
*/
public interface OnItemClickListner {
void OnItemClick(int position);
}
Holder类
package com.example.week3.holder;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.week3.R;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class Holder extends RecyclerView.ViewHolder {
public ImageView img;
public TextView price;
public TextView title;
public TextView zhoukou;
public Holder(View itemView) {
super(itemView);
img = itemView.findViewById(R.id.search_img);
price = itemView.findViewById(R.id.search_price);
title =itemView.findViewById(R.id.search_title);
zhoukou = itemView.findViewById(R.id.search_zhekouprice);
}
}
登录的model
package com.example.week3.model;
import com.example.week3.Bean.LoginBean;
import com.example.week3.presenter.IMainloginpresenter.IMainloginpresenter;
import com.example.week3.presenter.Mainloginpresenter;
import com.example.week3.uitl.OkHttp3Util;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class Mainloginmodel {
private IMainloginpresenter iMainloginpresenter;
public Mainloginmodel(IMainloginpresenter iMainloginpresenter) {
this.iMainloginpresenter =iMainloginpresenter;
}
public void getlogin(String login, String sname, String password) {
Map<String, String> params = new HashMap<>();
params.put("mobile",sname);
params.put("password",password);
OkHttp3Util.doPost(login, 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();
LoginBean loginBean = new Gson().fromJson(json, LoginBean.class);
iMainloginpresenter.login(loginBean);
}
}
});
}
}
查询的model
package com.example.week3.model;
import com.example.week3.Bean.SearchBean;
import com.example.week3.presenter.IMainloginpresenter.IMainsearchpresenter;
import com.example.week3.presenter.Miansearchpresenter;
import com.example.week3.uitl.OkHttp3Util;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class Mainsearchmodel {
private IMainsearchpresenter iMainsearchpresenter;
public Mainsearchmodel(IMainsearchpresenter iMainsearchpresenter) {
this.iMainsearchpresenter =iMainsearchpresenter;
}
public void getsearch(String search, String searchname, int page) {
Map<String, String> params = new HashMap<>();
params.put("keywords",searchname);
params.put("page", String.valueOf(page));
OkHttp3Util.doPost(search, 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();
SearchBean searchBean = new Gson().fromJson(json, SearchBean.class);
iMainsearchpresenter.search(searchBean);
}
}
});
}
}
注册的model
package com.example.week3.model;
import com.example.week3.Bean.ZhuceBean;
import com.example.week3.presenter.IMainloginpresenter.IMainzhucepresenter;
import com.example.week3.presenter.Mainzhucepresenter;
import com.example.week3.uitl.OkHttp3Util;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class Mainzhucemodel {
private IMainzhucepresenter iMainzhucepresenter;
public Mainzhucemodel(IMainzhucepresenter iMainzhucepresenter) {
this.iMainzhucepresenter= iMainzhucepresenter;
}
public void getzhuce(String zhuce, String name, String pass) {
Map<String, String> params = new HashMap<>();
params.put("mobile",name);
params.put("password",pass);
OkHttp3Util.doPost(zhuce, 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();
ZhuceBean zhuceBean = new Gson().fromJson(json, ZhuceBean.class);
iMainzhucepresenter.zhuce(zhuceBean);
}
}
});
}
}
登录的中间者
package com.example.week3.presenter;
import com.example.week3.Bean.LoginBean;
import com.example.week3.Activity.IMain.IMainloginactivity;
import com.example.week3.model.Mainloginmodel;
import com.example.week3.presenter.IMainloginpresenter.IMainloginpresenter;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class Mainloginpresenter implements IMainloginpresenter {
private Mainloginmodel mainloginmodel;
private IMainloginactivity iMainloginactivity;
public Mainloginpresenter(IMainloginactivity iMainloginactivity) {
this.iMainloginactivity=iMainloginactivity;
mainloginmodel = new Mainloginmodel(this);
}
public void getlogin(String login, String sname, String password) {
mainloginmodel.getlogin(login,sname,password);
}
@Override
public void login(LoginBean loginBean) {
iMainloginactivity.login(loginBean);
}
}
注册的中间者
package com.example.week3.presenter;
import com.example.week3.Activity.IMain.IMainzhuceactivity;
import com.example.week3.Activity.Mainzhuce;
import com.example.week3.Bean.ZhuceBean;
import com.example.week3.model.Mainzhucemodel;
import com.example.week3.presenter.IMainloginpresenter.IMainzhucepresenter;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class Mainzhucepresenter implements IMainzhucepresenter {
private Mainzhucemodel mainzhucemodel;
private IMainzhuceactivity iMainzhuceactivity;
public Mainzhucepresenter(IMainzhuceactivity iMainzhuceactivity) {
this.iMainzhuceactivity =iMainzhuceactivity;
mainzhucemodel = new Mainzhucemodel(this);
}
public void getzhuce(String zhuce, String name, String pass) {
mainzhucemodel.getzhuce(zhuce,name,pass);
}
@Override
public void zhuce(ZhuceBean zhuceBean) {
iMainzhuceactivity.zhuce(zhuceBean);
}
}
查询的中间者
package com.example.week3.presenter;
import com.example.week3.Activity.IMain.IMainsearchactivity;
import com.example.week3.Activity.Mainzhanshi;
import com.example.week3.Bean.SearchBean;
import com.example.week3.model.Mainsearchmodel;
import com.example.week3.presenter.IMainloginpresenter.IMainsearchpresenter;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class Miansearchpresenter implements IMainsearchpresenter{
private IMainsearchactivity iMainsearchactivity;
private Mainsearchmodel mainsearchmodel;
public Miansearchpresenter(IMainsearchactivity iMainsearchactivity) {
this.iMainsearchactivity=iMainsearchactivity;
mainsearchmodel = new Mainsearchmodel(this);
}
public void getsearch(String search, String searchname, int page) {
mainsearchmodel.getsearch(search,searchname,page);
}
@Override
public void search(SearchBean searchBean) {
iMainsearchactivity.search(searchBean);
}
}
登录的接口
package com.example.week3.presenter.IMainloginpresenter;
import com.example.week3.Bean.LoginBean;
/**
* Created by huoxuebin on 2018/1/18.
*/
public interface IMainloginpresenter {
void login(LoginBean loginBean);
}
查询的接口
package com.example.week3.presenter.IMainloginpresenter;
import com.example.week3.Bean.SearchBean;
/**
* Created by huoxuebin on 2018/1/18.
*/
public interface IMainsearchpresenter {
void search(SearchBean searchBean);
}
注册的接口
package com.example.week3.presenter.IMainloginpresenter;
import com.example.week3.Bean.ZhuceBean;
/**
* Created by huoxuebin on 2018/1/18.
*/
public interface IMainzhucepresenter {
void zhuce(ZhuceBean zhuceBean);
}
API类
package com.example.week3.uitl;
/**
* Created by huoxuebin on 2018/1/18.
*/
public class Api {
//登录接口
public static String login ="https://www.zhaoapi.cn/user/login?";
//注册
public static String zhuce ="https://www.zhaoapi.cn/user/reg?";
//关键词搜索
public static String search ="https://www.zhaoapi.cn/product/searchProducts?";
}
缩放的工具类
package com.example.week3.uitl;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.OnScaleGestureListener;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ImageView;
/**
* Created by Dash on 2018/1/17.
*/
@SuppressLint("AppCompatCustomView")
public class ZoomImageView extends ImageView implements OnGlobalLayoutListener, OnScaleGestureListener, OnTouchListener {
private boolean mOnce;
/**
* 初始化时缩放的值
*/
private float mInitScale;
/**
* 双击放大值到达的值
*/
private float mMidScale;
/**
* 放大的最大值
*/
private float mMaxScale;
private Matrix mScaleMatrix;
/**
* 捕获用户多指触控时缩放的比例
*/
private ScaleGestureDetector mScaleGestureDetector;
// **********自由移动的变量***********
/**
* 记录上一次多点触控的数量
*/
private int mLastPointerCount;
private float mLastX;
private float mLastY;
private int mTouchSlop;
private boolean isCanDrag;
private boolean isCheckLeftAndRight;
private boolean isCheckTopAndBottom;
// *********双击放大与缩小*********
private GestureDetector mGestureDetector;
private boolean isAutoScale;
public ZoomImageView(Context context) {
this(context, null);
}
public ZoomImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ZoomImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// init
mScaleMatrix = new Matrix();
setScaleType(ScaleType.MATRIX);
setOnTouchListener(this);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mScaleGestureDetector = new ScaleGestureDetector(context, this);
mGestureDetector = new GestureDetector(context,
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
if (isAutoScale) {
return true;
}
float x = e.getX();
float y = e.getY();
if (getScale() < mMidScale) {
postDelayed(new AutoScaleRunnable(mMidScale, x, y), 16);
isAutoScale = true;
} else {
postDelayed(new AutoScaleRunnable(mInitScale, x, y), 16);
isAutoScale = true;
}
return true;
}
});
}
/**
* 自动放大与缩小
*
* @author zhangyan@lzt.com.cn
*
*/
private class AutoScaleRunnable implements Runnable {
/**
* 缩放的目标值
*/
private float mTargetScale;
// 缩放的中心点
private float x;
private float y;
private final float BIGGER = 1.07f;
private final float SMALL = 0.93f;
private float tmpScale;
/**
* @param mTargetScale
* @param x
* @param y
*/
public AutoScaleRunnable(float mTargetScale, float x, float y) {
this.mTargetScale = mTargetScale;
this.x = x;
this.y = y;
if (getScale() < mTargetScale) {
tmpScale = BIGGER;
}
if (getScale() > mTargetScale) {
tmpScale = SMALL;
}
}
@Override
public void run() {
//进行缩放
mScaleMatrix.postScale(tmpScale, tmpScale, x, y);
checkBorderAndCenterWhenScale();
setImageMatrix(mScaleMatrix);
float currentScale = getScale();
if ((tmpScale >1.0f && currentScale <mTargetScale) ||(tmpScale<1.0f &¤tScale>mTargetScale)) {
//这个方法是重新调用run()方法
postDelayed(this, 16);
}else{
//设置为我们的目标值
float scale = mTargetScale/currentScale;
mScaleMatrix.postScale(scale, scale, x, y);
checkBorderAndCenterWhenScale();
setImageMatrix(mScaleMatrix);
isAutoScale = false;
}
}
}
/**
* 获取ImageView加载完成的图片
*/
@Override
public void onGlobalLayout() {
if (!mOnce) {
// 得到控件的宽和高
int width = getWidth();
int height = getHeight();
// 得到我们的图片,以及宽和高
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
int dh = drawable.getIntrinsicHeight();
int dw = drawable.getIntrinsicWidth();
float scale = 0.5f;
// 图片的宽度大于控件的宽度,图片的高度小于空间的高度,我们将其缩小
if (dw > width && dh < height) {
scale = width * 1.0f / dw;
}
// 图片的宽度小于控件的宽度,图片的高度大于空间的高度,我们将其缩小
if (dh > height && dw < width) {
scale = height * 1.0f / dh;
}
// 缩小值
if (dw > width && dh > height) {
scale = Math.min(width * 1.0f / dw, height * 1.0f / dh);
}
// 放大值
if (dw < width && dh < height) {
scale = Math.min(width * 1.0f / dw, height * 1.0f / dh);
}
/**
* 得到了初始化时缩放的比例
*/
mInitScale = scale;
mMaxScale = mInitScale * 4;
mMidScale = mInitScale * 2;
// 将图片移动至控件的中间
int dx = getWidth() / 2 - dw / 2;
int dy = getHeight() / 2 - dh / 2;
mScaleMatrix.postTranslate(dx, dy);
mScaleMatrix.postScale(mInitScale, mInitScale, width / 2,
height / 2);
setImageMatrix(mScaleMatrix);
mOnce = true;
}
}
/**
* 注册OnGlobalLayoutListener这个接口
*/
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
getViewTreeObserver().addOnGlobalLayoutListener(this);
}
/**
* 取消OnGlobalLayoutListener这个接口
*/
@SuppressWarnings("deprecation")
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
/**
* 获取当前图片的缩放值
*
* @return
*/
public float getScale() {
float[] values = new float[9];
mScaleMatrix.getValues(values);
return values[Matrix.MSCALE_X];
}
// 缩放区间时initScale maxScale
@Override
public boolean onScale(ScaleGestureDetector detector) {
float scale = getScale();
float scaleFactor = detector.getScaleFactor();
if (getDrawable() == null) {
return true;
}
// 缩放范围的控制
if ((scale < mMaxScale && scaleFactor > 1.0f)
|| (scale > mInitScale && scaleFactor < 1.0f)) {
if (scale * scaleFactor < mInitScale) {
scaleFactor = mInitScale / scale;
}
if (scale * scaleFactor > mMaxScale) {
scale = mMaxScale / scale;
}
// 缩放
mScaleMatrix.postScale(scaleFactor, scaleFactor,
detector.getFocusX(), detector.getFocusY());
checkBorderAndCenterWhenScale();
setImageMatrix(mScaleMatrix);
}
return true;
}
/**
* 获得图片放大缩小以后的宽和高,以及left,right,top,bottom
*
* @return
*/
private RectF getMatrixRectF() {
Matrix matrix = mScaleMatrix;
RectF rectF = new RectF();
Drawable d = getDrawable();
if (d != null) {
rectF.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
matrix.mapRect(rectF);
}
return rectF;
}
/**
* 在缩放的时候进行边界以及我们的位置的控制
*/
private void checkBorderAndCenterWhenScale() {
RectF rectF = getMatrixRectF();
float deltaX = 0;
float deltaY = 0;
int width = getWidth();
int height = getHeight();
// 缩放时进行边界检测,防止出现白边
if (rectF.width() >= width) {
if (rectF.left > 0) {
deltaX = -rectF.left;
}
if (rectF.right < width) {
deltaX = width - rectF.right;
}
}
if (rectF.height() >= height) {
if (rectF.top > 0) {
deltaY = -rectF.top;
}
if (rectF.bottom < height) {
deltaY = height - rectF.bottom;
}
}
/**
* 如果宽度或高度小于空间的宽或者高,则让其居中
*/
if (rectF.width() < width) {
deltaX = width / 2f - rectF.right + rectF.width() / 2f;
}
if (rectF.height() < height) {
deltaY = height / 2f - rectF.bottom + rectF.height() / 2f;
}
mScaleMatrix.postTranslate(deltaX, deltaY);
}
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)) {
return true;
}
mScaleGestureDetector.onTouchEvent(event);
float x = 0;
float y = 0;
// 拿到多点触控的数量
int pointerCount = event.getPointerCount();
for (int i = 0; i < pointerCount; i++) {
x += event.getX(i);
y += event.getY(i);
}
x /= pointerCount;
y /= pointerCount;
if (mLastPointerCount != pointerCount) {
isCanDrag = false;
mLastX = x;
mLastY = y;
}
mLastPointerCount = pointerCount;
RectF rectF = getMatrixRectF();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (rectF.width()>getWidth() +0.01|| rectF.height()>getHeight()+0.01) {
if(getParent() instanceof ViewPager)
getParent().requestDisallowInterceptTouchEvent(true);
}
break;
case MotionEvent.ACTION_MOVE:
if (rectF.width()>getWidth()+0.01 || rectF.height()>getHeight()+0.01) {
if(getParent() instanceof ViewPager){
Log.e("---","----+++");
getParent().requestDisallowInterceptTouchEvent(true);
}
}
float dx = x - mLastX;
float dy = y - mLastY;
if (!isCanDrag) {
isCanDrag = isMoveAction(dx, dy);
}
if (isCanDrag) {
if (getDrawable() != null) {
isCheckLeftAndRight = isCheckTopAndBottom = true;
// 如果宽度小于控件宽度,不允许横向移动
if (rectF.width() < getWidth()) {
isCheckLeftAndRight = false;
dx = 0;
}
// 如果高度小于控件高度,不允许纵向移动
if (rectF.height() < getHeight()) {
isCheckTopAndBottom = false;
dy = 0;
}
mScaleMatrix.postTranslate(dx, dy);
checkBorderWhenTranslate();
setImageMatrix(mScaleMatrix);
}
}
mLastX = x;
mLastY = y;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mLastPointerCount = 0;
break;
default:
break;
}
return true;
}
/**
* 当移动时进行边界检查
*/
private void checkBorderWhenTranslate() {
RectF rectF = getMatrixRectF();
float deltaX = 0;
float deltaY = 0;
int width = getWidth();
int heigth = getHeight();
if (rectF.top > 0 && isCheckTopAndBottom) {
deltaY = -rectF.top;
}
if (rectF.bottom < heigth && isCheckTopAndBottom) {
deltaY = heigth - rectF.bottom;
}
if (rectF.left > 0 && isCheckLeftAndRight) {
deltaX = -rectF.left;
}
if (rectF.right < width && isCheckLeftAndRight) {
deltaX = width - rectF.right;
}
mScaleMatrix.postTranslate(deltaX, deltaY);
}
/**
* 判断是否是move
*
* @param dx
* @param dy
* @return
*/
private boolean isMoveAction(float dx, float dy) {
return Math.sqrt(dx * dx + dy * dy) > mTouchSlop;
}
}
OK的工具类
package com.example.week3.uitl;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
* Created by huoxuebin on 2018/1/13.
*/
public class OkHttp3Util {
/**
* 懒汉 安全 加同步
* 私有的静态成员变量 只声明不创建
* 私有的构造方法
* 提供返回实例的静态方法
*/
private static OkHttpClient okHttpClient = null;
private OkHttp3Util() {
}
public static OkHttpClient getInstance() {
if (okHttpClient == null) {
//加同步安全
synchronized (OkHttp3Util.class) {
if (okHttpClient == null) {
//okhttp可以缓存数据....指定缓存路径
File sdcache = new File(Environment.getExternalStorageDirectory(), "cache");
//指定缓存大小
int cacheSize = 10 * 1024 * 1024;
okHttpClient = new OkHttpClient.Builder()//构建器
.connectTimeout(15, TimeUnit.SECONDS)//连接超时
.writeTimeout(20, TimeUnit.SECONDS)//写入超时
.readTimeout(20, TimeUnit.SECONDS)//读取超时
//.addInterceptor(new CommonParamsInterceptor())//添加的是应用拦截器...公共参数
//.addNetworkInterceptor(new CacheInterceptor())//添加的网络拦截器
.cache(new Cache(sdcache.getAbsoluteFile(), cacheSize))//设置缓存
.build();
}
}
}
return okHttpClient;
}
/**
* get请求
* 参数1 url
* 参数2 回调Callback
*/
public static void doGet(String oldUrl, Callback callback) {
//要添加的公共参数...map
Map<String,String> map = new HashMap<>();
map.put("source","android");
StringBuilder stringBuilder = new StringBuilder();//创建一个stringBuilder
stringBuilder.append(oldUrl);
if (oldUrl.contains("?")){
//?在最后面....2类型
if (oldUrl.indexOf("?") == oldUrl.length()-1){
}else {
//3类型...拼接上&
stringBuilder.append("&");
}
}else {
//不包含? 属于1类型,,,先拼接上?号
stringBuilder.append("?");
}
//添加公共参数....
for (Map.Entry<String,String> entry: map.entrySet()) {
//拼接
stringBuilder.append(entry.getKey())
.append("=")
.append(entry.getValue())
.append("&");
}
//删掉最后一个&符号
if (stringBuilder.indexOf("&") != -1){
stringBuilder.deleteCharAt(stringBuilder.lastIndexOf("&"));
}
String newUrl = stringBuilder.toString();//新的路径
//创建OkHttpClient请求对象
OkHttpClient okHttpClient = getInstance();
//创建Request
Request request = new Request.Builder().url(newUrl).build();
//得到Call对象
Call call = okHttpClient.newCall(request);
//执行异步请求
call.enqueue(callback);
}
/**
* post请求
* 参数1 url
* 参数2 Map<String, String> params post请求的时候给服务器传的数据
* add..("","")
* add()
*/
public static void doPost(String url, Map<String, String> params, Callback callback) {
//要添加的公共参数...map
Map<String,String> map = new HashMap<>();
map.put("source","android");
//创建OkHttpClient请求对象
OkHttpClient okHttpClient = getInstance();
//3.x版本post请求换成FormBody 封装键值对参数
FormBody.Builder builder = new FormBody.Builder();
//遍历集合
for (String key : params.keySet()) {
builder.add(key, params.get(key));
}
//添加公共参数
for (Map.Entry<String,String> entry: map.entrySet()) {
builder.add(entry.getKey(),entry.getValue());
}
//创建Request
Request request = new Request.Builder().url(url).post(builder.build()).build();
Call call = okHttpClient.newCall(request);
call.enqueue(callback);
}
/**
* post请求上传文件....包括图片....流的形式传任意文件...
* 参数1 url
* file表示上传的文件
* fileName....文件的名字,,例如aaa.jpg
* params ....传递除了file文件 其他的参数放到map集合
*
*/
public static void uploadFile(String url, File file, String fileName,Map<String,String> params) {
//创建OkHttpClient请求对象
OkHttpClient okHttpClient = getInstance();
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
//参数
if (params != null){
for (String key : params.keySet()){
builder.addFormDataPart(key,params.get(key));
}
}
//文件...参数name指的是请求路径中所接受的参数...如果路径接收参数键值是fileeeee,此处应该改变
builder.addFormDataPart("file",fileName,RequestBody.create(MediaType.parse("application/octet-stream"),file));
//构建
MultipartBody multipartBody = builder.build();
//创建Request
Request request = new Request.Builder().url(url).post(multipartBody).build();
//得到Call
Call call = okHttpClient.newCall(request);
//执行请求
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("upload",e.getLocalizedMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
//上传成功回调 目前不需要处理
if (response.isSuccessful()){
String s = response.body().string();
Log.e("upload","上传--"+s);
}
}
});
}
/**
* Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"}
* 参数一:请求Url
* 参数二:请求的JSON
* 参数三:请求回调
*/
public static void doPostJson(String url, String jsonParams, Callback callback) {
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonParams);
Request request = new Request.Builder().url(url).post(requestBody).build();
Call call = getInstance().newCall(request);
call.enqueue(callback);
}
/**
* 下载文件 以流的形式把apk写入的指定文件 得到file后进行安装
* 参数er:请求Url
* 参数san:保存文件的文件夹....download
*/
public static void download(final Activity context, final String url, final String saveDir) {
Request request = new Request.Builder().url(url).build();
Call call = getInstance().newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
//com.orhanobut.logger.Logger.e(e.getLocalizedMessage());
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
InputStream is = null;
byte[] buf = new byte[2048];
int len = 0;
FileOutputStream fos = null;
try {
is = response.body().byteStream();//以字节流的形式拿回响应实体内容
//apk保存路径
final String fileDir = isExistDir(saveDir);
//文件
File file = new File(fileDir, getNameFromUrl(url));
fos = new FileOutputStream(file);
while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.flush();
context.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "下载成功:" + fileDir + "," + getNameFromUrl(url), Toast.LENGTH_SHORT).show();
}
});
//apk下载完成后 调用系统的安装方法
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
context.startActivity(intent);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) is.close();
if (fos != null) fos.close();
}
}
});
}
/**
* 判断下载目录是否存在......并返回绝对路径
*
* @param saveDir
* @return
* @throws IOException
*/
public static String isExistDir(String saveDir) throws IOException {
// 下载位置
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File downloadFile = new File(Environment.getExternalStorageDirectory(), saveDir);
if (!downloadFile.mkdirs()) {
downloadFile.createNewFile();
}
String savePath = downloadFile.getAbsolutePath();
Log.e("savePath", savePath);
return savePath;
}
return null;
}
/**
* @param url
* @return 从下载连接中解析出文件名
*/
private static String getNameFromUrl(String url) {
return url.substring(url.lastIndexOf("/") + 1);
}
/**
* 公共参数拦截器
*/
private static class CommonParamsInterceptor implements Interceptor{
//拦截的方法
@Override
public Response intercept(Chain chain) throws IOException {
//获取到请求
Request request = chain.request();
//获取请求的方式
String method = request.method();
//获取请求的路径
String oldUrl = request.url().toString();
Log.e("---拦截器",request.url()+"---"+request.method()+"--"+request.header("User-agent"));
//要添加的公共参数...map
Map<String,String> map = new HashMap<>();
map.put("source","android");
if ("GET".equals(method)){
// 1.http://www.baoidu.com/login --------? key=value&key=value
// 2.http://www.baoidu.com/login? --------- key=value&key=value
// 3.http://www.baoidu.com/login?mobile=11111 -----&key=value&key=value
StringBuilder stringBuilder = new StringBuilder();//创建一个stringBuilder
stringBuilder.append(oldUrl);
if (oldUrl.contains("?")){
//?在最后面....2类型
if (oldUrl.indexOf("?") == oldUrl.length()-1){
}else {
//3类型...拼接上&
stringBuilder.append("&");
}
}else {
//不包含? 属于1类型,,,先拼接上?号
stringBuilder.append("?");
}
//添加公共参数....
for (Map.Entry<String,String> entry: map.entrySet()) {
//拼接
stringBuilder.append(entry.getKey())
.append("=")
.append(entry.getValue())
.append("&");
}
//删掉最后一个&符号
if (stringBuilder.indexOf("&") != -1){
stringBuilder.deleteCharAt(stringBuilder.lastIndexOf("&"));
}
String newUrl = stringBuilder.toString();//新的路径
//拿着新的路径重新构建请求
request = request.newBuilder()
.url(newUrl)
.build();
}else if ("POST".equals(method)){
//先获取到老的请求的实体内容
RequestBody oldRequestBody = request.body();//....之前的请求参数,,,需要放到新的请求实体内容中去
//如果请求调用的是上面doPost方法
if (oldRequestBody instanceof FormBody){
FormBody oldBody = (FormBody) oldRequestBody;
//构建一个新的请求实体内容
FormBody.Builder builder = new FormBody.Builder();
//1.添加老的参数
for (int i=0;i<oldBody.size();i++){
builder.add(oldBody.name(i),oldBody.value(i));
}
//2.添加公共参数
for (Map.Entry<String,String> entry:map.entrySet()) {
builder.add(entry.getKey(),entry.getValue());
}
FormBody newBody = builder.build();//新的请求实体内容
//构建一个新的请求
request = request.newBuilder()
.url(oldUrl)
.post(newBody)
.build();
}
}
Response response = chain.proceed(request);
return response;
}
}
/**
* 网络缓存的拦截器......注意在这里更改cache-control头是很危险的,一般客户端不进行更改,,,,服务器端直接指定
*
* 没网络取缓存的时候,一般都是在数据库或者sharedPerfernce中取出来的
*
*
*
*/
/*private static class CacheInterceptor implements Interceptor{
@Override
public Response intercept(Chain chain) throws IOException {
//老的响应
Response oldResponse = chain.proceed(chain.request());
*//*if (NetUtils.isNetworkConnected(DashApplication.getAppContext())){
int maxAge = 120; // 在线缓存在2分钟内可读取
return oldResponse.newBuilder()
.removeHeader("Pragma")
.removeHeader("Cache-Control")
.header("Cache-Control", "public, max-age=" + maxAge)
.build();
}else {
int maxStale = 60 * 60 * 24 * 14; // 离线时缓存保存2周
return oldResponse.newBuilder()
.removeHeader("Pragma")
.removeHeader("Cache-Control")
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
.build();
}*//*
}
}*/
}
主页面的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
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="com.example.week3.Activity.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:textSize="25dp"
android:text="登录"/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="输入名字"
/>
<EditText
android:id="@+id/pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="输入密码"
/>
<Button
android:onClick="login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录"/>
<Button
android:onClick="zhuce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册"/>
</LinearLayout>
放大的HTML
<?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="com.example.week3.Activity.Mainfangda">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/view_pager"
android:layout_centerInParent="true"
></android.support.v4.view.ViewPager>
</RelativeLayout>
详情的布局
<?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="com.example.week3.Activity.Mainxiangqing">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#f89"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:text="<"
android:textSize="25dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="商品详情"
android:textSize="25dp"
/>
</RelativeLayout>
<com.youth.banner.Banner
android:layout_width="match_parent"
android:layout_height="350dp"
android:id="@+id/banner">
</com.youth.banner.Banner>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="111"
/>
<TextView
android:id="@+id/price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="111"
android:layout_marginTop="5dp"
/>
<TextView
android:id="@+id/price2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="111"
android:textColor="#f00"
android:layout_marginTop="5dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="添加购物车"
android:textColor="#f89"
/>
</LinearLayout>
展示的布局
<?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:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.example.week3.Activity.Mainzhanshi">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp">
<TextView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="搜索商品"/>
<CheckBox
android:id="@+id/ck"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:button="@null"
android:background="@drawable/select_check"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
/>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#d9d9d9"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<EditText
android:id="@+id/searchname"
android:layout_width="0dp"
android:layout_weight="8"
android:layout_height="wrap_content"
android:hint="输入关键词"
/>
<Button
android:onClick="search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="搜索"
/>
</LinearLayout>
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/xrv"></com.jcodecraeer.xrecyclerview.XRecyclerView>
</LinearLayout>
注册的布局
<?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="com.example.week3.Activity.Mainzhuce">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:textSize="25dp"
android:text="注册"/>
<EditText
android:id="@+id/sname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="输入名字"
/>
<EditText
android:id="@+id/pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="输入密码"
/>
<Button
android:onClick="zhuc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册"/>
</LinearLayout>
查询的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/search_img"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:id="@+id/search_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="dsfsdfsdfdsf"/>
<TextView
android:id="@+id/search_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="sdfsdfsdf"/>
<TextView
android:id="@+id/search_zhekouprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="dfsfsdfsdg"
android:textColor="#f00"/>
</LinearLayout>
查询的listview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/search_img"
android:src="@mipmap/ic_launcher"
android:layout_width="100dp"
android:layout_height="100dp" />
<LinearLayout
android:id="@+id/lin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/search_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/search_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11"
android:layout_marginTop="20dp"
/>
<TextView
android:id="@+id/search_zhekouprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11"
android:textColor="#f00"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
所需要添加的依赖
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "27.0.0"
defaultConfig {
applicationId "com.example.week3"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.youth.banner:banner:1.4.9'
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
compile 'com.jcodecraeer:xrecyclerview:1.3.2'
testCompile 'junit:junit:4.12'
}