|
|
@@ -1,84 +1,183 @@
|
|
|
package com.usai.apex;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.InputStreamReader;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
+import com.usai.util.Network;
|
|
|
import com.usai.util.commonUtil;
|
|
|
|
|
|
-import android.content.res.AssetManager;
|
|
|
+import android.animation.Animator;
|
|
|
+import android.animation.AnimatorListenerAdapter;
|
|
|
+import android.os.AsyncTask;
|
|
|
+import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
+import android.text.Html;
|
|
|
import android.util.Log;
|
|
|
import android.util.SparseIntArray;
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.View.OnClickListener;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.webkit.WebView;
|
|
|
+import android.widget.Button;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.RelativeLayout;
|
|
|
+import android.widget.ScrollView;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
-public class DetailFragment extends Fragment implements OnClickListener
|
|
|
+public class DetailFragment extends Fragment implements OnClickListener /*
|
|
|
+ * ,
|
|
|
+ * OnGestureListener
|
|
|
+ */
|
|
|
{
|
|
|
- LinearLayout ll_root;
|
|
|
- String mimeType = "text/html";
|
|
|
-
|
|
|
- SparseIntArray control = new SparseIntArray() ;
|
|
|
-// HashMap<Integer, Integer> control = new HashMap<Integer, Integer>() ;
|
|
|
+ /* private GestureDetector mGestureDetector; */
|
|
|
+ @Override
|
|
|
+ public void onCreate(Bundle savedInstanceState)
|
|
|
+ {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
- Bundle savedInstanceState)
|
|
|
+ public void onDestroyView()
|
|
|
{
|
|
|
- View view = inflater.inflate(R.layout.detail_fragment, null);
|
|
|
+ Log.d("DetailFragment", "onDestroyView()");
|
|
|
+ super.onDestroyView();
|
|
|
+ }
|
|
|
|
|
|
- ll_root = (LinearLayout) view.findViewById(R.id.ll_root);
|
|
|
+ public String get_content()
|
|
|
+ {
|
|
|
+ return fragment_content;
|
|
|
+ }
|
|
|
|
|
|
- // TextView tv= new TextView(getActivity());
|
|
|
- // tv.setText("test12345");
|
|
|
- //
|
|
|
- // ll_root.addView(tv);
|
|
|
+ LinearLayout ll_root;
|
|
|
+ ScrollView sl_root;
|
|
|
+ String mimeType = "text/html";
|
|
|
+ private SearchTask m_task = null;
|
|
|
+ SparseIntArray control = new SparseIntArray();
|
|
|
+ // private TextView mStatusMessageView;
|
|
|
+ private View mStatusView;
|
|
|
+ String fragment_content = null;
|
|
|
|
|
|
- String jstr = null;
|
|
|
- AssetManager am = null;
|
|
|
- am = getActivity().getAssets();
|
|
|
- try
|
|
|
+ public void requestdata()
|
|
|
+ {
|
|
|
+
|
|
|
+ if (m_task != null)
|
|
|
{
|
|
|
- String TAG = "DetailFragment fake json";
|
|
|
- InputStream is = am.open("detail.json");
|
|
|
-
|
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(is,
|
|
|
- "utf-8"), 8);
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- String line = null;
|
|
|
- while ((line = br.readLine()) != null)
|
|
|
- {
|
|
|
- sb.append(line + "\n");
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (fragment_content != null)
|
|
|
+ return;
|
|
|
+ // mStatusMessageView.setText("Loading");
|
|
|
+ showProgress(true);
|
|
|
+ m_task = new SearchTask();
|
|
|
+ m_task.execute();
|
|
|
|
|
|
- Log.d(TAG, "Response: content begin");
|
|
|
- Log.d(TAG, sb.toString());
|
|
|
- Log.d(TAG, "Response: content end");
|
|
|
+ }
|
|
|
|
|
|
- if (sb.length() <= 0)
|
|
|
- {
|
|
|
+ private void showProgress(final boolean show)
|
|
|
+ {
|
|
|
+ // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
|
|
|
+ // for very easy animations. If available, use these APIs to fade-in
|
|
|
+ // the progress spinner.
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
|
|
|
+ {
|
|
|
+ int shortAnimTime = getResources().getInteger(
|
|
|
+ android.R.integer.config_shortAnimTime);
|
|
|
|
|
|
- jstr = null;
|
|
|
- }
|
|
|
- jstr = sb.toString();
|
|
|
+ mStatusView.setVisibility(View.VISIBLE);
|
|
|
+ mStatusView.animate().setDuration(shortAnimTime)
|
|
|
+ .alpha(show ? 1 : 0)
|
|
|
+ .setListener(new AnimatorListenerAdapter()
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public void onAnimationEnd(Animator animation)
|
|
|
+ {
|
|
|
+ mStatusView.setVisibility(show ? View.VISIBLE
|
|
|
+ : View.INVISIBLE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ ll_root.setVisibility(View.VISIBLE);
|
|
|
+ ll_root.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
|
|
|
+ .setListener(new AnimatorListenerAdapter()
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public void onAnimationEnd(Animator animation)
|
|
|
+ {
|
|
|
+ ll_root.setVisibility(show ? View.INVISIBLE
|
|
|
+ : View.VISIBLE);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- catch (IOException e)
|
|
|
+ else
|
|
|
{
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
+ // The ViewPropertyAnimator APIs are not available, so simply show
|
|
|
+ // and hide the relevant UI components.
|
|
|
+ mStatusView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
|
|
+ ll_root.setVisibility(show ? View.INVISIBLE : View.VISIBLE);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- init(jstr, inflater);
|
|
|
+ @Override
|
|
|
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
+ Bundle savedInstanceState)
|
|
|
+ {
|
|
|
+ /* mGestureDetector = new GestureDetector(this); */
|
|
|
+ View view = inflater.inflate(R.layout.detail_fragment, null);
|
|
|
+ sl_root = (ScrollView) view.findViewById(R.id.sl_root);
|
|
|
+ /*
|
|
|
+ * sl_root.setOnTouchListener(new View.OnTouchListener() {
|
|
|
+ *
|
|
|
+ * @Override public boolean onTouch(View v, MotionEvent event) { return
|
|
|
+ * mGestureDetector.onTouchEvent(event); } });
|
|
|
+ */
|
|
|
+ ll_root = (LinearLayout) view.findViewById(R.id.ll_root);
|
|
|
+ mStatusView = view.findViewById(R.id.status);
|
|
|
+ // TextView tv= new TextView(getActivity());
|
|
|
+ // tv.setText("test12345");
|
|
|
+ //
|
|
|
+ // ll_root.addView(tv);
|
|
|
+
|
|
|
+ // String jstr = null;
|
|
|
+ // AssetManager am = null;
|
|
|
+ // am = getActivity().getAssets();
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // String TAG = "DetailFragment fake json";
|
|
|
+ // InputStream is = am.open("detail.json");
|
|
|
+ //
|
|
|
+ // BufferedReader br = new BufferedReader(new InputStreamReader(is,
|
|
|
+ // "utf-8"), 8);
|
|
|
+ // StringBuilder sb = new StringBuilder();
|
|
|
+ // String line = null;
|
|
|
+ // while ((line = br.readLine()) != null)
|
|
|
+ // {
|
|
|
+ // sb.append(line + "\n");
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // Log.d(TAG, "Response: content begin");
|
|
|
+ // Log.d(TAG, sb.toString());
|
|
|
+ // Log.d(TAG, "Response: content end");
|
|
|
+ //
|
|
|
+ // if (sb.length() <= 0)
|
|
|
+ // {
|
|
|
+ //
|
|
|
+ // jstr = null;
|
|
|
+ // }
|
|
|
+ // jstr = sb.toString();
|
|
|
+ // }
|
|
|
+ // catch (IOException e)
|
|
|
+ // {
|
|
|
+ // // TODO Auto-generated catch block
|
|
|
+ // e.printStackTrace();
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // init(jstr, inflater);
|
|
|
// String url = "<a href='http://www.google.com'>A1401330351H.pdf</a>";
|
|
|
|
|
|
// String
|
|
|
@@ -96,16 +195,41 @@ public class DetailFragment extends Fragment implements OnClickListener
|
|
|
//
|
|
|
// wv = (WebView) view.findViewById(R.id.webView1);
|
|
|
// wv.loadData(url1, mimeType, null);
|
|
|
+ LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_refresh);
|
|
|
+ Button btn_refresh = (Button) ll.findViewById(R.id.btn_refresh);
|
|
|
+ btn_refresh.setOnClickListener(new View.OnClickListener()
|
|
|
+ {
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onClick(View v)
|
|
|
+ {
|
|
|
+ LinearLayout ll = (LinearLayout) ll_root
|
|
|
+ .findViewById(R.id.ll_refresh);
|
|
|
+ ll.setVisibility(View.GONE);
|
|
|
+
|
|
|
+ requestdata();
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ requestdata();
|
|
|
return view;
|
|
|
}
|
|
|
|
|
|
void init(String jstr, LayoutInflater inflater)
|
|
|
{
|
|
|
+ String TAG = "init@DetailFragment";
|
|
|
+ Log.d(TAG, jstr);
|
|
|
try
|
|
|
{
|
|
|
JSONObject jsonObj = new JSONObject(jstr);
|
|
|
int group_count = jsonObj.getInt("count");
|
|
|
+ if (group_count == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ TextView tv_empty = (TextView) ll_root
|
|
|
+ .findViewById(R.id.tv_empty);
|
|
|
+ tv_empty.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
for (int i = 0; i < group_count; i++)
|
|
|
{
|
|
|
// String key = (String) it.next();
|
|
|
@@ -114,14 +238,14 @@ public class DetailFragment extends Fragment implements OnClickListener
|
|
|
JSONObject groupobj = jsonObj.getJSONObject("group" + i);
|
|
|
View v = inflater.inflate(R.layout.group_tag, null);
|
|
|
v.setOnClickListener(this);
|
|
|
-
|
|
|
+
|
|
|
TextView tvgroup = (TextView) v.findViewById(R.id.tv_group);
|
|
|
String group_name = groupobj.getString("_name");
|
|
|
tvgroup.setText(group_name);
|
|
|
v.setId(commonUtil.generateViewId());
|
|
|
ll_root.addView(v);
|
|
|
String grouptype = groupobj.getString("_type");
|
|
|
-// groupobj.remove("_type");
|
|
|
+ // groupobj.remove("_type");
|
|
|
if (grouptype.equals("mapping"))
|
|
|
{
|
|
|
LinearLayout mappingview = (LinearLayout) inflater.inflate(
|
|
|
@@ -130,12 +254,12 @@ public class DetailFragment extends Fragment implements OnClickListener
|
|
|
control.put(v.getId(), mappingview.getId());
|
|
|
ll_root.addView(mappingview);
|
|
|
|
|
|
- int map_count = groupobj.getInt("_count");
|
|
|
- for(int j=0;j<map_count;j++)
|
|
|
+ int map_count = groupobj.getInt("count");
|
|
|
+ for (int j = 0; j < map_count; j++)
|
|
|
{
|
|
|
-// String keygroup = (String) itgroup.next();
|
|
|
- JSONObject itemobj= groupobj.getJSONObject("item"+j);
|
|
|
- String key = (String)itemobj.keys().next();
|
|
|
+ // String keygroup = (String) itgroup.next();
|
|
|
+ JSONObject itemobj = groupobj.getJSONObject("item" + j);
|
|
|
+ String key = (String) itemobj.keys().next();
|
|
|
String val = itemobj.getString(key);
|
|
|
LinearLayout mappingitem = (LinearLayout) inflater
|
|
|
.inflate(R.layout.keymapping_item, null);
|
|
|
@@ -145,16 +269,16 @@ public class DetailFragment extends Fragment implements OnClickListener
|
|
|
// tvkey.setBackgroundResource(R.drawable.detail_item);
|
|
|
TextView tvval = (TextView) mappingitem
|
|
|
.findViewById(R.id.tv_value);
|
|
|
- tvval.setText(val);
|
|
|
+ tvval.setText(Html.fromHtml(val));
|
|
|
// tvval.setBackgroundResource(R.drawable.detail_item);
|
|
|
- mappingview.addView(mappingitem);
|
|
|
+ mappingview.addView(mappingitem);
|
|
|
}
|
|
|
-// Iterator itgroup = groupobj.keys();
|
|
|
-// while (itgroup.hasNext())
|
|
|
-// {
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
+ // Iterator itgroup = groupobj.keys();
|
|
|
+ // while (itgroup.hasNext())
|
|
|
+ // {
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // }
|
|
|
}
|
|
|
else
|
|
|
if (grouptype.equals("table"))
|
|
|
@@ -164,10 +288,28 @@ public class DetailFragment extends Fragment implements OnClickListener
|
|
|
|
|
|
wv = (WebView) inflater.inflate(R.layout.web_content,
|
|
|
null);
|
|
|
+
|
|
|
+ wv.getSettings().setDefaultTextEncodingName("UTF-8");
|
|
|
wv.setId(commonUtil.generateViewId());
|
|
|
control.put(v.getId(), wv.getId());
|
|
|
wv.loadData(content, mimeType, null);
|
|
|
+
|
|
|
+ // wv.setOnTouchListener(new OnTouchListener()
|
|
|
+ // {
|
|
|
+ // @Override
|
|
|
+ // public boolean onTouch(View v, MotionEvent event)
|
|
|
+ // {
|
|
|
+ //
|
|
|
+ // if (event.getAction() == MotionEvent.ACTION_UP)
|
|
|
+ // sl_root.requestDisallowInterceptTouchEvent(false);
|
|
|
+ // else
|
|
|
+ // sl_root.requestDisallowInterceptTouchEvent(true);
|
|
|
+ //
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // });
|
|
|
ll_root.addView(wv);
|
|
|
+ Log.d("table content", content);
|
|
|
|
|
|
}
|
|
|
if (grouptype.equals("list"))
|
|
|
@@ -177,7 +319,7 @@ public class DetailFragment extends Fragment implements OnClickListener
|
|
|
listview.setId(commonUtil.generateViewId());
|
|
|
control.put(v.getId(), listview.getId());
|
|
|
ll_root.addView(listview);
|
|
|
- long list_count = groupobj.getInt("_count");
|
|
|
+ long list_count = groupobj.getInt("count");
|
|
|
for (int j = 0; j < list_count; j++)
|
|
|
{
|
|
|
RelativeLayout listitem = (RelativeLayout) inflater
|
|
|
@@ -185,19 +327,19 @@ public class DetailFragment extends Fragment implements OnClickListener
|
|
|
|
|
|
TextView tvitem = (TextView) listitem
|
|
|
.findViewById(R.id.tv_item);
|
|
|
- String val=groupobj.getString("line"+j);
|
|
|
+ String val = groupobj.getString("line" + j);
|
|
|
tvitem.setText(val);
|
|
|
// tvitem.setBackgroundResource(R.drawable.detail_item);
|
|
|
listitem.removeView(tvitem);
|
|
|
|
|
|
listview.addView(tvitem);
|
|
|
}
|
|
|
-// Iterator itgroup = groupobj.keys();
|
|
|
-// while (itgroup.hasNext())
|
|
|
-// {
|
|
|
-// String keygroup = (String) itgroup.next();
|
|
|
-//
|
|
|
-// }
|
|
|
+ // Iterator itgroup = groupobj.keys();
|
|
|
+ // while (itgroup.hasNext())
|
|
|
+ // {
|
|
|
+ // String keygroup = (String) itgroup.next();
|
|
|
+ //
|
|
|
+ // }
|
|
|
}
|
|
|
// String value = obj.getString(key);
|
|
|
// JSONArray array = obj.getJSONArray(key);
|
|
|
@@ -229,6 +371,146 @@ public class DetailFragment extends Fragment implements OnClickListener
|
|
|
view.setVisibility(View.GONE);
|
|
|
else
|
|
|
view.setVisibility(View.VISIBLE);
|
|
|
-
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ class SearchTask extends AsyncTask<Void, Void, Boolean>
|
|
|
+ {
|
|
|
+ int errorcode;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Boolean doInBackground(Void... params)
|
|
|
+ {
|
|
|
+ if (!Network.NetworkIsAvailable())
|
|
|
+
|
|
|
+ {
|
|
|
+ errorcode = Network.RESULT_NET_NOTAVAILABLE;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String jstr = Network.get_detail(getArguments());
|
|
|
+ if (jstr == null || jstr.length() <= 0)
|
|
|
+ {
|
|
|
+ // Log.d(TAG, "json is wrong");
|
|
|
+
|
|
|
+ errorcode = Network.RESULT_NET_ERROR;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ fragment_content = jstr;
|
|
|
+ errorcode = Network.RESULT_TRUE;
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPostExecute(Boolean success)
|
|
|
+ {
|
|
|
+ Log.i("onPostExecute", "entry");
|
|
|
+ m_task = null;
|
|
|
+ showProgress(false);
|
|
|
+
|
|
|
+ switch (errorcode)
|
|
|
+ {
|
|
|
+ case Network.RESULT_NET_NOTAVAILABLE:
|
|
|
+ {
|
|
|
+ Toast toast = Toast.makeText(
|
|
|
+ ApexTrackingApplication.get_instance(),
|
|
|
+ getText(R.string.msg_connection_none),
|
|
|
+ Toast.LENGTH_LONG);
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+ toast.show();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case Network.RESULT_NET_ERROR:
|
|
|
+ {
|
|
|
+ Toast toast = Toast.makeText(
|
|
|
+ ApexTrackingApplication.get_instance(),
|
|
|
+ getText(R.string.msg_net_error), Toast.LENGTH_LONG);
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+ toast.show();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case Network.RESULT_ERROR:
|
|
|
+ // case Network.RESULT_RESPONSE_NULL:
|
|
|
+ {
|
|
|
+ Toast toast = Toast.makeText(
|
|
|
+ ApexTrackingApplication.get_instance(),
|
|
|
+ getText(R.string.msg_net_resulterror),
|
|
|
+ Toast.LENGTH_LONG);
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+ toast.show();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (success)
|
|
|
+ {
|
|
|
+
|
|
|
+ init(fragment_content, getActivity().getLayoutInflater());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LinearLayout ll = (LinearLayout) ll_root.findViewById(R.id.ll_refresh);
|
|
|
+ ll.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ super.onPostExecute(success);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCancelled()
|
|
|
+ {
|
|
|
+ m_task = null;
|
|
|
+ showProgress(false);
|
|
|
+ }
|
|
|
}
|
|
|
+ //
|
|
|
+ // @Override
|
|
|
+ // public boolean onDown(MotionEvent e)
|
|
|
+ // {
|
|
|
+ // // TODO Auto-generated method stub
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @Override
|
|
|
+ // public void onShowPress(MotionEvent e)
|
|
|
+ // {
|
|
|
+ // // TODO Auto-generated method stub
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @Override
|
|
|
+ // public boolean onSingleTapUp(MotionEvent e)
|
|
|
+ // {
|
|
|
+ // // TODO Auto-generated method stub
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @Override
|
|
|
+ // public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
|
|
|
+ // float distanceY)
|
|
|
+ // {
|
|
|
+ // Log.e("onScroll",".................");
|
|
|
+ // Log.d("onScroll","dx:"+(e1.getX()-e2.getX()));
|
|
|
+ // Log.d("onScroll","dy:"+(e1.getY()-e2.getY()));
|
|
|
+ //
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @Override
|
|
|
+ // public void onLongPress(MotionEvent e)
|
|
|
+ // {
|
|
|
+ // // TODO Auto-generated method stub
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @Override
|
|
|
+ // public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
|
|
|
+ // float velocityY)
|
|
|
+ // {
|
|
|
+ // Log.e("onFling",".................");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
}
|