package com.hefvcjm.expresshelper.activities;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import com.hefvcjm.expresshelper.R;
import com.hefvcjm.expresshelper.activities.nav_activities.AboutActivity;
import com.hefvcjm.expresshelper.activities.nav_activities.MeActivity;
import com.hefvcjm.expresshelper.activities.nav_activities.SecurityActivity;
import com.hefvcjm.expresshelper.activities.nav_activities.SettingActivity;
import com.hefvcjm.expresshelper.adapter.ExpressListAdapter;
import com.hefvcjm.expresshelper.express.ExpressInfos;
import com.hefvcjm.expresshelper.net.MyHttpClient;
import com.hefvcjm.expresshelper.staticinfos.StaticInfos;
import com.hefvcjm.expresshelper.storage.Storage;
import com.hefvcjm.expresshelper.user.UserInfos;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
import cn.jpush.android.api.JPushInterface;
/**
* 通过模板生成的DrawerLayout+NavigationView布局,也是最常见的APP展示方式
*/
public class DrawerLayout_OneActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
public static final int REQUESTCODE_STATE_CHAGED = 1;
private List<ExpressInfos> expressList = new ArrayList<ExpressInfos>();
private String url;
private String phone;
private ExpressListAdapter adapter;
private ListView lv_express_list;
private DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_express_list);
// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);
//
// DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
// ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
// this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
// drawer.setDrawerListener(toggle);
// toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
url = getResources().getString(R.string.str_server_url) + "/query/expresses";
Intent intent = getIntent();
phone = intent.getStringExtra("phone");
StaticInfos.setPhone(phone);
UserInfos.getInstance().setPhone(phone);
JPushInterface.setAlias(DrawerLayout_OneActivity.this, 0, phone);
registerMessageReceiver();
// Collections.sort(expressList);
adapter = new ExpressListAdapter(DrawerLayout_OneActivity.this, R.layout.item_list_express, expressList);
lv_express_list = (ListView) findViewById(R.id.lv_express_list);
lv_express_list.setAdapter(adapter);
synchronize_express(url, phone);
lv_express_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ExpressInfos expressInfos = expressList.get(position);
Intent intent = new Intent(DrawerLayout_OneActivity.this, ExpressDetailActivity.class);
intent.putExtra("express_detail", expressInfos.toString());
intent.putExtra("position", position);
Log.d("listview", expressInfos.toString());
startActivityForResult(intent, REQUESTCODE_STATE_CHAGED);
}
});
}
public void doClick(View view) {
switch (view.getId()) {
case R.id.iv_title_logo:
drawerLayout.openDrawer(Gravity.LEFT);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED,
Gravity.RIGHT);
break;
default:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUESTCODE_STATE_CHAGED:
try {
JSONObject json = new JSONObject(data.getStringExtra("result"));
if ((boolean) json.get("ischanged")) {
int position = (int) json.get("position");
if (position != -1) {
String state = json.getString("state");
int visibleFirstPosition = lv_express_list.getFirstVisiblePosition();
int visibleLastPosition = lv_express_list.getLastVisiblePosition();
if (position >= visibleFirstPosition && position <= visibleLastPosition) {
View view = lv_express_list.getChildAt(position - visibleFirstPosition);
ExpressListAdapter.ViewHolder holder = (ExpressListAdapter.ViewHolder) view.getTag();
holder.tv_express_state.setText(state);
if (state.equals(getResources().getString(R.string.str_state_receiving))) {
holder.tv_express_state.setTextColor(getResources().getColor(R.color.state_receiving));
holder.iv_state.setImageDrawable(getResources().getDrawable(R.drawable.receiving));
} else if (state.equals(getResources().getString(R.string.str_state_received))) {
holder.tv_express_state.setTextColor(getResources().getColor(R.color.state_received));
holder.iv_state.setImageDrawable(getResources().getDrawable(R.drawable.received));
} else if (state.equals(getResources().getString(R.string.str_state_refused))) {
holder.tv_express_state.setTextColor(getResources().getColor(R.color.state_refused));
holder.iv_state.setImageDrawable(getResources().getDrawable(R.drawable.refused));
}
ExpressInfos expressInfos = expressList.get(position);
expressInfos.setState(state);
expressList.set(position, expressInfos);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
break;
default:
break;
}
}
private void synchronize_express(final String url, String phone) {
try {
new MyHttpClient(url
, new JSONObject().put("Content-Type", "application/json;charset=utf-8")
, new JSONObject().put("phone", phone)
, new MyHttpClient.ResponseListener() {
@Override
public void onResponse(String body, J
毕业小助手
- 粉丝: 2765
- 资源: 5583
最新资源
- Matlab四旋翼无人机ADRC姿态控制器仿真,已调好,附带相关参考文献~ 无人机姿态模型,力矩方程,角运动方程 包含三个姿态角的数学模型,以及三个adrc控制器 简洁易懂,也可自行替其他控制器
- 新能源动力电池电芯支架组合压紧机sw21可编辑全套技术资料100%好用.zip
- 电镀生产线西门子博途PLC程序 酸洗纯化干燥线
- 【c#】基于C#开发的天蓝蓝(aikaobukao)考试管理系统_pgj.zip
- 【C#】基于C#+ASP.NetCore实现的在线考试系统,数据库操作使用EnityFrameworkCore框架_pgj.zip
- 【C语言】2019年南航计算机学院操作系统课程的实验代码-实验心得-上机考试练习-笔试复习笔记_pgj.zip
- 【go语言】《Go语言四十二章经》详细讲述Go语言规范与语法细节及开发中常见的误区_pgj.zip
- 车用驱动电机原理与控制基础-P144公式(6-50)
- 非线性磁链观测器Simulink仿真模型(2020b版本) 1. 该模型与先前发布的非线性磁链观测器代码一一对应,拥有仿真模型可以做到指导工程调试
- 【Golang设计模式】使用Golang泛型实现的设计模式(大话设计模式)_pgj.zip
- 【go语言】golang钉钉机器人客户端支持文本、链接、Markdown、ActionCard、FeedCard类型消息的发送_pgj.zip
- 【java】QQ官方机器人Java-JVM-kotlinSDKQQbotsdkqq机器人sdk_pgj.zip
- 【java】ssm+jsp+mysql+LD算法在线考试系统_pgj.zip
- 【java】分布式事务基于rabbitmq二阶段提交实现_pgj.zip
- 【java】基于java+SSM-考试系统_pgj.zip
- 【java】大三软工课设,在线考试系统后端部分_pgj.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈