package com.example.m.zhoukao3.views;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import com.example.m.zhoukao3.R;
import com.example.m.zhoukao3.models.DingBean;
import com.example.m.zhoukao3.models.ModeImpl;
import com.example.m.zhoukao3.presenter.PresenterImpl;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.List;
public class MainActivity extends AppCompatActivity implements IMainView,View.OnClickListener {
private XRecyclerView xRecyclerView;
private PresenterImpl presenter;
private ImageView imageView;
private String[] item = new String[]{"已支付","待支付","已取消"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化也没
initViews();
//调用
presenter = new PresenterImpl();
presenter.showDataToView(new ModeImpl(), this);
}
private void initViews() {
xRecyclerView = findViewById(R.id.xRecylerView);
//设置
xRecyclerView.setLayoutManager(new LinearLayoutManager(this));
xRecyclerView.addItemDecoration(new MyDecoration(this, MyDecoration.VERTICAL_LIST));
//设置
xRecyclerView.setPullRefreshEnabled(true);//下拉刷新
xRecyclerView.setLoadingMoreEnabled(true);//上拉加载
xRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);//样式
xRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.Pacman);
//监听
xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
//调用presenter里面的刷新方法
presenter.showNewDataToView(new ModeImpl(), MainActivity.this);
}
@Override
public void onLoadMore() {
//调用presenter里面的加载更多方法
}
});
//pop
imageView = findViewById(R.id.image);
imageView.setOnClickListener(this);
}
//IMainView的展示所有数据的回调方法
@Override
public void showAllData(List<DingBean.DataBean> list) {
//设置适配器
MyAdapter myAdapter = new MyAdapter(MainActivity.this, list, this);
xRecyclerView.setAdapter(myAdapter);
}
private static final String TAG = "MainActivity";
//下拉刷新
@Override
public void showNewData(List<DingBean.DataBean> list) {
Log.d(TAG, "xiala--------" + list);
//设置适配器
MyAdapter myAdapter = new MyAdapter(MainActivity.this, list, this);
xRecyclerView.setAdapter(myAdapter);
//让进度条缩回去
xRecyclerView.refreshComplete();
}
//取消,需要调用两次网络请求
@Override
public void showQuXiaoData() {
Log.d(TAG, "取消成功-----");
Toast.makeText(MainActivity.this, "取消成功", Toast.LENGTH_SHORT).show();
presenter.showDataToView(new ModeImpl(), this);
}
//取消失败
@Override
public void showQuXiaoError() {
Toast.makeText(MainActivity.this, "取消失败", Toast.LENGTH_SHORT).show();
}
//点击事件
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.image:
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.pop_item,null);
//设置view里面的数据
ListView listView = view.findViewById(R.id.listView);
listView.setAdapter(new BaseAdapter() {
@Override
public int getCount() {
return item.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = new TextView(MainActivity.this);
textView.setText(item[position]);
textView.setTextSize(20);
return textView;
}
});
PopupWindow popupWindow = new PopupWindow(view, 200, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(imageView,0,10);
break;
}
}
}
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import com.example.m.zhoukao3.R;
import com.example.m.zhoukao3.models.DingBean;
import com.example.m.zhoukao3.models.ModeImpl;
import com.example.m.zhoukao3.presenter.PresenterImpl;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.List;
public class MainActivity extends AppCompatActivity implements IMainView,View.OnClickListener {
private XRecyclerView xRecyclerView;
private PresenterImpl presenter;
private ImageView imageView;
private String[] item = new String[]{"已支付","待支付","已取消"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化也没
initViews();
//调用
presenter = new PresenterImpl();
presenter.showDataToView(new ModeImpl(), this);
}
private void initViews() {
xRecyclerView = findViewById(R.id.xRecylerView);
//设置
xRecyclerView.setLayoutManager(new LinearLayoutManager(this));
xRecyclerView.addItemDecoration(new MyDecoration(this, MyDecoration.VERTICAL_LIST));
//设置
xRecyclerView.setPullRefreshEnabled(true);//下拉刷新
xRecyclerView.setLoadingMoreEnabled(true);//上拉加载
xRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);//样式
xRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.Pacman);
//监听
xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
//调用presenter里面的刷新方法
presenter.showNewDataToView(new ModeImpl(), MainActivity.this);
}
@Override
public void onLoadMore() {
//调用presenter里面的加载更多方法
}
});
//pop
imageView = findViewById(R.id.image);
imageView.setOnClickListener(this);
}
//IMainView的展示所有数据的回调方法
@Override
public void showAllData(List<DingBean.DataBean> list) {
//设置适配器
MyAdapter myAdapter = new MyAdapter(MainActivity.this, list, this);
xRecyclerView.setAdapter(myAdapter);
}
private static final String TAG = "MainActivity";
//下拉刷新
@Override
public void showNewData(List<DingBean.DataBean> list) {
Log.d(TAG, "xiala--------" + list);
//设置适配器
MyAdapter myAdapter = new MyAdapter(MainActivity.this, list, this);
xRecyclerView.setAdapter(myAdapter);
//让进度条缩回去
xRecyclerView.refreshComplete();
}
//取消,需要调用两次网络请求
@Override
public void showQuXiaoData() {
Log.d(TAG, "取消成功-----");
Toast.makeText(MainActivity.this, "取消成功", Toast.LENGTH_SHORT).show();
presenter.showDataToView(new ModeImpl(), this);
}
//取消失败
@Override
public void showQuXiaoError() {
Toast.makeText(MainActivity.this, "取消失败", Toast.LENGTH_SHORT).show();
}
//点击事件
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.image:
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.pop_item,null);
//设置view里面的数据
ListView listView = view.findViewById(R.id.listView);
listView.setAdapter(new BaseAdapter() {
@Override
public int getCount() {
return item.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = new TextView(MainActivity.this);
textView.setText(item[position]);
textView.setTextSize(20);
return textView;
}
});
PopupWindow popupWindow = new PopupWindow(view, 200, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(imageView,0,10);
break;
}
}
}