com.app.jdy.ui.MyOrderActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.app.jdy.ui.MyOrderActivity.java

Source

/**
 * Copyright (c) 2015
 *
 * Licensed under the UCG License, Version 1.0 (the "License");
 */
package com.app.jdy.ui;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.app.jdy.R;
import com.app.jdy.adapter.BankAdapter;
import com.app.jdy.adapter.FaceValueAdapter;
import com.app.jdy.adapter.MyOrderAdapter;
import com.app.jdy.entity.BankCard;
import com.app.jdy.entity.FaceValue;
import com.app.jdy.entity.MyOrder;
import com.app.jdy.utils.ChineseMoneyUtils;
import com.app.jdy.utils.Constants;
import com.app.jdy.utils.HttpUtils;
import com.app.jdy.utils.URLs;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * description :?avtivity
 * 
 * @version 1.0
 * @author zhoufeng
 * @createtime : 2015-1-24 ?8:56:14
 * 
 *             ?:    --------------- -------------------
 *             ----------------------------------- zhoufeng 2015-1-24 ?8:56:14
 * 
 */
public class MyOrderActivity extends Activity implements OnClickListener {
    /**
     * 
     */
    private ImageView back_img;
    /**
     * 
     */
    private TextView title;
    /**
     * list
     */
    private ListView my_order_list;
    /**
     * handler
     */
    private Handler handler;
    /**
     * ID?
     */
    private String ID;
    /**
     * ???
     */
    private ArrayList<NameValuePair> params;
    /**
     * ?
     */
    private List<MyOrder> list;
    /**
     * ?json?
     */
    private String dataJson;
    /**
     * ??
     */
    private MyOrderAdapter myOrderAdapter;
    /**
     * ??
     */
    private TextView my_order_sum;
    /**
     * ???
     */
    private ImageView right_img;
    /**
     * 
     */
    private TextView my_order_sum_yuan;

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

        initView();

        handler = new Handler() {
            public void handleMessage(Message msg) {
                switch (msg.what) {
                case 0:
                    Toast.makeText(MyOrderActivity.this, Constants.NO_INTENT_TIPS, Toast.LENGTH_SHORT).show();
                    break;
                case 1:
                    list = new ArrayList<MyOrder>();
                    try {
                        JSONObject jsonObject = new JSONObject(dataJson);
                        if (jsonObject.getString("sum").equals("null")) {
                            my_order_sum.setText("0");
                            my_order_sum_yuan.setText("");
                        } else {
                            my_order_sum
                                    .setText(ChineseMoneyUtils.numWithDigitArray(jsonObject.getDouble("sum"))[0]);
                            my_order_sum_yuan
                                    .setText(ChineseMoneyUtils.numWithDigitArray(jsonObject.getDouble("sum"))[1]);
                        }
                        JSONArray jsonArray = jsonObject.getJSONArray("data");

                        for (int i = 0; i < jsonArray.length(); i++) {

                            MyOrder myOrder = new MyOrder();
                            myOrder.setTime(jsonArray.getJSONObject(i).getString("create_time"));
                            myOrder.setName(jsonArray.getJSONObject(i).getString("name"));
                            myOrder.setMoney(jsonArray.getJSONObject(i).getString("investTotal"));
                            list.add(myOrder);
                        }
                        myOrderAdapter = new MyOrderAdapter(MyOrderActivity.this, R.layout.my_order_item, list);
                        my_order_list.setAdapter(myOrderAdapter);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    break;
                default:
                    break;
                }
            }
        };

        getData();

    }

    public void initView() {
        back_img = (ImageView) findViewById(R.id.back_img);
        back_img.setOnClickListener(this);
        title = (TextView) findViewById(R.id.title_tv);
        title.setText("?");
        right_img = (ImageView) findViewById(R.id.right_img);
        right_img.setImageResource(R.drawable.feedback);
        right_img.setVisibility(View.VISIBLE);
        right_img.setOnClickListener(this);
        SharedPreferences userPreferences = getSharedPreferences("umeng_general_config", Context.MODE_PRIVATE);
        ID = userPreferences.getString("ID", "").trim();

        my_order_list = (ListView) findViewById(R.id.my_order_list);
        my_order_sum = (TextView) findViewById(R.id.my_order_sum);
        my_order_sum_yuan = (TextView) findViewById(R.id.my_order_sum_yuan);

    }

    public void getData() {
        params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("memberId", ID));
        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                Message msg = new Message();
                dataJson = HttpUtils.request(params, URLs.MY_ORDER);
                if (dataJson.length() != 0 && !dataJson.equals("0x110")) {
                    msg.what = 1;
                } else {
                    msg.what = 0;
                }
                handler.sendMessage(msg);
            }
        });
        thread.start();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.back_img:
            finish();
            break;
        case R.id.right_img:
            Intent intent = new Intent(MyOrderActivity.this, OrderFeedBackActivity.class);
            startActivity(intent);
            break;
        default:
            break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("SplashScreen");
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("SplashScreen");
        MobclickAgent.onPause(this);
    }
}