/**
   * @Title: NetConnect @Description: TODO(获取后台数据,方式为GET)
   *
   * @param: @param uuid (前一个activity传过来的uuid)
   * @return: void
   * @throws
   */
  public void NetConnect(String uuid) {
    String mark = RsSharedUtil.getString(getApplicationContext(), "access_token");
    String url =
        AppConfig.URL_MESSAGE + "survey.json?" + "access_token=" + mark + "&surveyUuid=" + uuid;

    Log.v("1234567", "access_token=" + mark + "&surveyUuid=" + uuid);
    JsonArrayRequest array =
        new JsonArrayRequest(
            Method.GET,
            url,
            null,
            new Response.Listener<JSONArray>() {

              @Override
              public void onResponse(JSONArray response) {
                // TODO Auto-generated method stub
                if (response != null) {
                  ll_wutongzhi.setVisibility(View.GONE);
                }
                try {
                  tv_none.setVisibility(View.GONE);
                  Log.d("结构啊啊啊啊啊啊", response.toString());
                  JSONArray array = new JSONArray(response.toString());
                  al_announce_text.clear();
                  al_announce_date.clear();
                  for (int i = 0; i < array.length(); i++) {
                    JSONObject object = array.getJSONObject(i);
                    long createDate = object.getLong("date");
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    String beginDate = dateFormat.format(new Date(createDate)); // 获取时间

                    String uuid = object.getString("uuid");
                    boolean title = object.getBoolean("isRead");
                    String content = object.getString("content");

                    al_announce_text.add(content);
                    al_announce_date.add(beginDate);
                  }
                  putHashMap(array.length());
                } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                } finally {
                  //							progress.dismiss();
                  loadingDialog.dismissDialog();
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                // TODO Auto-generated method stub

                try {
                  switch (error.statuCode()) {
                    case 204:
                      tv_none.setVisibility(View.VISIBLE);
                      // Toast.makeText(InformActivity.this,
                      // R.string.lastest_204,
                      // Toast.LENGTH_SHORT).show();
                      break;
                  }
                } catch (Exception e) {
                  // Toast.makeText(InformActivity.this,
                  // R.string.other_error, Toast.LENGTH_SHORT)
                  // .show();
                } finally {
                  //							progress.dismiss();
                  loadingDialog.dismissDialog();
                }
              }
            });

    volleyRequestQueue.add(array);
  }
  private void getStock() {
    String url = AppConfig.URL_FUND + "portfolioStock/";

    // 计算当前是第几季度
    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH) + 1;
    // 季度
    int quarter = month / 3 + 1;

    // 设置股票投资明细的时间
    tv_time_stock.setText(year + "年第" + quarter + "季度");

    url += symbol + "/" + quarter + ".json?access_token=";
    url += RsSharedUtil.getString(getActivity(), "access_token");
    url += "&pageNo=" + pageIndex_stock + "&pageSize=" + pageSize_stock;
    Log.d("lele_url_stock", url);

    StringRequest stringRequest =
        new StringRequest(
            Request.Method.GET,
            url,
            null,
            new Response.Listener<String>() {

              @Override
              public void onResponse(String response) {
                if (response.equals("") || response.equals("[0]")) {
                  // ToastUtils.showToast(getActivity(), "没有数据");

                } else {
                  try {
                    JSONArray jsonArray = new JSONArray(response.toString());
                    Iterator<String> jIterator = null;
                    final ArrayList<HashMap<String, String>> datas =
                        new ArrayList<HashMap<String, String>>();
                    HashMap<String, String> data = null;

                    for (int i = 0; i < jsonArray.length(); i++) {
                      jIterator = jsonArray.getJSONObject(i).keys();
                      data = new HashMap<String, String>();
                      while (jIterator.hasNext()) {
                        String key = jIterator.next();
                        data.put(key, jsonArray.getJSONObject(i).getString(key));
                      }

                      datas.add(data);
                    }

                    StockAdapter adapter = new StockAdapter(getActivity(), datas);
                    lv_stock.setAdapter(adapter);

                  } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                try {
                  JSONObject jsonObject = new JSONObject(error.data());
                  Log.d("error_description", jsonObject.getString("description"));
                  ;

                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  Log.d("error_Exception", e.toString());
                }
              }
            });

    volleyRequestQueue.add(stringRequest);
  }
  /**
   * 关注/取消关注基金
   *
   * @param follow
   * @param symbol
   * @param iv
   */
  private void concern(
      final String follow,
      String symbol,
      final ImageView iv,
      final String[] state,
      final int position) {
    String url =
        AppConfig.URL_USER
            + "security.json?access_token="
            + RsSharedUtil.getString(getApplicationContext(), "access_token")
            + "&followType="
            + follow;
    JSONArray array = new JSONArray();
    JSONObject params = new JSONObject();
    try {
      params.put("symbol", symbol);
      params.put("type", "FUND");
      array.put(params);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    Log.d("params", params.toString());
    StringRequest stringRequest =
        new StringRequest(
            array,
            url,
            new Listener<String>() {

              @Override
              public void onResponse(String response) {
                if (follow.equals("true")) {
                  MyToast.makeText(getApplication(), "成功添加到自选基金", Toast.LENGTH_SHORT).show();
                  lv_foud_search_adapter.notifyDataSetChanged();
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                try {
                  JSONObject jsonObject = new JSONObject(error.data());
                  Log.d("error_description", jsonObject.getString("description"));

                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  Log.d("error_Exception", e.toString());
                }
                if (state[position].equals("false")) {
                  iv.setImageResource(R.drawable.btn_fs_selected);
                  state[position] = "true";
                  lv_foud_search_adapter.notifyDataSetChanged();
                } else {
                  iv.setImageResource(R.drawable.btn_fs_unselected);
                  state[position] = "false";
                  lv_foud_search_adapter.notifyDataSetChanged();
                }
              }
            });
    volleyRequestQueue.add(stringRequest);
    http.sHttpCache.clear();
  }
  /** 获取资产配置明细的后台数据 */
  private void getConfiguration() {
    String url = AppConfig.URL_FUND + "allocation.json?access_token=";
    url += RsSharedUtil.getString(getActivity(), "access_token");
    url += "&symbol=" + symbol;

    StringRequest stringRequest =
        new StringRequest(
            Request.Method.GET,
            url,
            null,
            new Response.Listener<String>() {

              @Override
              public void onResponse(String response) {

                if (response.equals("") || response.equals("[0]")) {
                  // ToastUtils.showToast(getActivity(),
                  // "No Content");
                } else {
                  try {
                    JSONObject jsonObject = new JSONObject(response);

                    Iterator<String> jIterator = null;
                    final ArrayList<HashMap<String, String>> datas =
                        new ArrayList<HashMap<String, String>>();
                    HashMap<String, String> data = new HashMap<String, String>();

                    jIterator = jsonObject.keys();
                    while (jIterator.hasNext()) {
                      String key = jIterator.next();
                      data.put(key, jsonObject.get(key).toString());
                    }

                    datas.add(data);

                    Log.d("liang_datas", datas.toString());

                    ConfigurationAdapter adapter = new ConfigurationAdapter(getActivity(), datas);
                    lv_configuration.setAdapter(adapter);

                  } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }

                Log.d("liang", "end");
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                try {
                  JSONObject jsonObject = new JSONObject(error.data());
                  Log.d("lele_error", jsonObject.getString("descriptin"));
                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  Log.d("error", error.toString());
                }
              }
            });

    volleyRequestQueue.add(stringRequest);
  }
  /**
   * 获取搜索的基金
   *
   * @param keyword
   * @param index
   * @param pageSize
   */
  private void getSearchFund(final String keyword, int pageIndex, int pageSize) {
    String url =
        AppConfig.URL_FUND
            + "search.json?access_token="
            + RsSharedUtil.getString(this, "access_token")
            + "&keyword="
            + keyword
            + "&pageIndex="
            + pageIndex
            + "&pageSize="
            + pageSize;
    // String url= AppConfig.URL
    // +
    // "api/v1.0/fund/search.json?access_token=d7abc947-6df0-4073-bc74-ba4b24c478b2&keyword=易方达&pageIndex=0&pageSize=5";
    Log.d("url", "url:" + url);

    http.send(
        HttpRequest.HttpMethod.GET,
        url,
        null,
        new RequestCallBack<String>() {

          @Override
          public void onFailure(HttpException arg0, String arg1) {
            // Toast.makeText(getApplicationContext(),
            // "网络不给力", Toast.LENGTH_LONG).show();
          }

          @Override
          public void onSuccess(ResponseInfo<String> arg0) {
            try {
              String response = arg0.result.toString();
              Log.d("获取数据", "keyword:" + keyword + response);
              // 如果没有数据
              if (response.equals("") || response.equals("[0]")) {
                try {
                  lv_foud_search_hashMaps.clear();
                  lv_foud_search_adapter.clear();
                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              } else {
                try {

                  JSONArray all = new JSONArray(response);
                  final ArrayList<HashMap<String, Object>> datas =
                      new ArrayList<HashMap<String, Object>>();
                  for (int i = 0; i < all.length(); i++) {
                    HashMap<String, Object> data = new HashMap<String, Object>();
                    Iterator<String> jsIterator;
                    try {
                      jsIterator = all.getJSONObject(i).keys();
                      while (jsIterator.hasNext()) {
                        String key = jsIterator.next();
                        data.put(key, all.getJSONObject(i).get(key).toString());
                      }
                    } catch (JSONException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    }
                    datas.add(data);
                  }
                  lv_foud_search_hashMaps.clear();
                  lv_foud_search_hashMaps = datas;

                  // 根据a-z进行排序源数据
                  Collections.sort(
                      lv_foud_search_hashMaps,
                      new Comparator<HashMap<String, Object>>() {

                        @Override
                        public int compare(
                            HashMap<String, Object> arg0, HashMap<String, Object> arg1) {
                          // TODO
                          // Auto-generated
                          // method stub
                          if (arg0.get("pyName").toString().charAt(0) > 'Z'
                              || arg0.get("pyName").toString().charAt(0) < 'A') {
                            return 1;
                          } else if (arg1.get("pyName").toString().charAt(0) > 'Z'
                              || arg1.get("pyName").toString().charAt(0) < 'A') {
                            return -1;
                          } else
                            return arg0.get("pyName")
                                .toString()
                                .compareTo(arg1.get("pyName").toString());
                        }
                      });

                  lv_foud_search_adapter =
                      new lvFoudSearchListAdapter(getApplicationContext(), lv_foud_search_hashMaps);
                  lv_foud_search_list1.setAdapter(lv_foud_search_adapter);
                  lv_foud_search_adapter.notifyDataSetChanged();
                } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        });
  }