|
|
@@ -1,188 +1,71 @@
|
|
|
package com.usai.apex.mainframe;
|
|
|
|
|
|
|
|
|
-import android.app.Activity;
|
|
|
-import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
-import android.text.TextUtils;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
-import android.widget.ListView;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
-import com.usai.apex.DetailActivity;
|
|
|
import com.usai.apex.R;
|
|
|
-import com.usai.util.Network;
|
|
|
-import com.usai.util.dbUtil;
|
|
|
-
|
|
|
-import org.json.JSONArray;
|
|
|
-import org.json.JSONException;
|
|
|
-import org.json.JSONObject;
|
|
|
-
|
|
|
+import com.usai.apex.SegmentView;
|
|
|
|
|
|
/**
|
|
|
* A simple {@link Fragment} subclass.
|
|
|
*/
|
|
|
-public class HomeFragment extends TrackingListFragment {
|
|
|
+public class HomeFragment extends Fragment {
|
|
|
|
|
|
+ private SegmentView mSegmentView;
|
|
|
|
|
|
+ private KPIFragment kpiFragment;
|
|
|
+ private RecentFragment recentFragment;
|
|
|
public HomeFragment() {
|
|
|
// Required empty public constructor
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onActivityCreated(Bundle savedInstanceState)
|
|
|
- {
|
|
|
- super.onActivityCreated(savedInstanceState);
|
|
|
-
|
|
|
-// setupAdapter();
|
|
|
-// customize_style();
|
|
|
-
|
|
|
- // this.getListView().setBackgroundColor(Color.WHITE);
|
|
|
- if (searchresult.get_count() == 0) {
|
|
|
- requestdata();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
- protected void requestData() {
|
|
|
-
|
|
|
- requestdata();
|
|
|
- }
|
|
|
-
|
|
|
- private void requestdata()
|
|
|
- {
|
|
|
- if (isLoading) {
|
|
|
- if (mSwipeRefresh.isRefreshing()) {
|
|
|
- mSwipeRefresh.setRefreshing(false);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- isLoading = true;
|
|
|
- showProgressDialog(null,"Loading...");
|
|
|
- new Thread(new Runnable() {
|
|
|
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
+ Bundle savedInstanceState) {
|
|
|
+ // Inflate the layout for this fragment
|
|
|
+ View v= inflater.inflate(R.layout.fragment_home, container, false);
|
|
|
+
|
|
|
+ kpiFragment = new KPIFragment();
|
|
|
+ recentFragment = new RecentFragment();
|
|
|
+ getActivity().getSupportFragmentManager().beginTransaction()
|
|
|
+ .add(R.id.container, recentFragment).commit();
|
|
|
+ getActivity().getSupportFragmentManager().beginTransaction()
|
|
|
+ .add(R.id.container, kpiFragment).hide(kpiFragment).commit();
|
|
|
+ mSegmentView = v.findViewById(R.id.segmentview);
|
|
|
+
|
|
|
+ mSegmentView.setSegmentText("Recent",0);
|
|
|
+ mSegmentView.setSegmentText("KPI",1);
|
|
|
+
|
|
|
+ mSegmentView.setOnSegmentViewClickListener(new SegmentView.onSegmentViewClickListener() {
|
|
|
@Override
|
|
|
- public void run() {
|
|
|
-
|
|
|
- final JSONObject jsobj = Network.request_home();
|
|
|
-
|
|
|
- ((Activity)mContext).runOnUiThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
-
|
|
|
- progressDialog.dismiss();
|
|
|
- if (mSwipeRefresh.isRefreshing()) {
|
|
|
- mSwipeRefresh.setRefreshing(false);
|
|
|
- }
|
|
|
-
|
|
|
- if (jsobj != null) {
|
|
|
-
|
|
|
- try {
|
|
|
- int result = jsobj.getInt("result");
|
|
|
- if (result == Network.RESULT_TRUE) {
|
|
|
-
|
|
|
- searchresult.clear();
|
|
|
- JSONArray datalist = jsobj.getJSONArray("container_list");
|
|
|
- int count = datalist.length();
|
|
|
- searchresult.add_records(datalist.toString(), count);
|
|
|
-
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
- } else {
|
|
|
- String msg = jsobj.getString("err_msg");
|
|
|
- showAlert(msg);
|
|
|
- }
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- showAlert("Sorry,there is some wrong");
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- showAlert("Sorry,there is some wrong");
|
|
|
- }
|
|
|
- isLoading = false;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }).start();
|
|
|
-
|
|
|
-//
|
|
|
-// JSONObject jsobj = loadfakecontent(R.raw.fake_container_list);
|
|
|
-// // if (searchresult.get_fieldscount() == 0)
|
|
|
-// // {
|
|
|
-// // JSONObject objfields = jsobj.getJSONObject("fields");
|
|
|
-// // if (objfields != null)
|
|
|
-// // searchresult.init_fields(objfields.toString());
|
|
|
-// // }
|
|
|
-//
|
|
|
-//
|
|
|
-// try {
|
|
|
-// JSONArray datalist = jsobj.getJSONArray("container_list");
|
|
|
-// int count = datalist.length();
|
|
|
-// searchresult.add_records(datalist.toString(), count);
|
|
|
-//
|
|
|
-// } catch (JSONException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-//
|
|
|
-//// int count = jsobj.getInt("total");
|
|
|
-////
|
|
|
-//// if (count < limit)
|
|
|
-//// bfinish = true;
|
|
|
-//// JSONObject objrecords = jsobj.getJSONObject("records");
|
|
|
-//// if (objrecords != null)
|
|
|
-//// searchresult.add_records(objrecords.toString(), count);
|
|
|
-//// errorcode = Network.RESULT_TRUE;
|
|
|
-//
|
|
|
-// adapter.notifyDataSetChanged();
|
|
|
- }
|
|
|
+ public void onSegmentViewClick(View view, int postion) {
|
|
|
+ switch (postion) {
|
|
|
+ case 0:
|
|
|
+ Toast.makeText(getActivity(), "left" + postion,
|
|
|
+ Toast.LENGTH_SHORT).show();
|
|
|
+ getActivity().getSupportFragmentManager().beginTransaction().show(recentFragment).hide(kpiFragment).commit();
|
|
|
|
|
|
- @Override
|
|
|
- protected View initHeaderView()
|
|
|
- {
|
|
|
|
|
|
- View headerView = LayoutInflater.from(getActivity()).inflate(R.layout.home_listheader, null);
|
|
|
- return headerView;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ Toast.makeText(getActivity(), "right" + postion,
|
|
|
+ Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onListItemClick(ListView l, View v, int position, long id) {
|
|
|
-
|
|
|
- //!!!!! listview 有header, position 需要-1
|
|
|
-
|
|
|
-
|
|
|
-// Log.d("FragmentList", "Item clicked: " + id);
|
|
|
-//
|
|
|
-// String title = (String) getData(jsonobj).get(position - 1).get("title");
|
|
|
-
|
|
|
- position = position - 1;
|
|
|
- if (position < 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- String cargo_criterion = (String) searchresult.getData().get(position).get("hbol");
|
|
|
-
|
|
|
- String serial_no = (String) searchresult.getData().get(position).get("serial_no");
|
|
|
-if(TextUtils.isEmpty(serial_no))
|
|
|
- serial_no = "dumb";
|
|
|
- Intent intent = new Intent();
|
|
|
- intent.setClass(getContext(), DetailActivity.class);
|
|
|
-
|
|
|
- intent.putExtra("action0", "Tracking");
|
|
|
- intent.putExtra("function_name", "Cargo Tracking");
|
|
|
-
|
|
|
- intent.putExtra("cargo_criterion", cargo_criterion);
|
|
|
- intent.putExtra("actions_count", 1);
|
|
|
- intent.putExtra("_id", serial_no);
|
|
|
-
|
|
|
-
|
|
|
- intent.putExtra("criterion_type", 0);
|
|
|
- String h_field = "h_bol";
|
|
|
-
|
|
|
- dbUtil.savehistory(h_field, cargo_criterion);
|
|
|
-
|
|
|
- startActivity(intent);
|
|
|
|
|
|
+ getActivity().getSupportFragmentManager().beginTransaction().show(kpiFragment).hide(recentFragment).commit();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return v;
|
|
|
}
|
|
|
+
|
|
|
}
|