|
|
@@ -1,42 +1,233 @@
|
|
|
package com.usai.apex;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.util.HashMap;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import com.usai.util.commonUtil;
|
|
|
+
|
|
|
+import android.content.res.AssetManager;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
-import android.text.Html;
|
|
|
-import android.text.method.LinkMovementMethod;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
+import android.view.View.OnClickListener;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.webkit.WebView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
-public class DetailFragment extends Fragment
|
|
|
+public class DetailFragment extends Fragment implements OnClickListener
|
|
|
{
|
|
|
+ LinearLayout ll_root;
|
|
|
+ String mimeType = "text/html";
|
|
|
+
|
|
|
+ HashMap<Integer, Integer> control = new HashMap<Integer, Integer>() ;
|
|
|
|
|
|
@Override
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
Bundle savedInstanceState)
|
|
|
{
|
|
|
View view = inflater.inflate(R.layout.detail_fragment, null);
|
|
|
- String url = "<a href='http://www.google.com'>A1401330351H.pdf</a>";
|
|
|
-
|
|
|
-
|
|
|
- String url1="<table border=1><tr><th>Test A</th><th>Test b</th></tr><tr><td>a</td><td>b</td></tr></table>";
|
|
|
- TextView t2 = (TextView) view.findViewById(R.id.text2);
|
|
|
- t2.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
- TextView t1 = (TextView) view.findViewById(R.id.textView1);
|
|
|
-
|
|
|
- t1.setText(Html.fromHtml(url1));
|
|
|
- t1.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
-
|
|
|
-
|
|
|
- final String mimeType = "text/html";
|
|
|
- WebView wv;
|
|
|
-
|
|
|
- wv = (WebView) view.findViewById(R.id.webView1);
|
|
|
- wv.loadData(url1, mimeType, null);
|
|
|
+
|
|
|
+ ll_root = (LinearLayout) view.findViewById(R.id.ll_root);
|
|
|
+
|
|
|
+ // 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
|
|
|
+ // url1="<table border=1><tr><th>Test A</th><th>Test b</th></tr><tr><td>a</td><td>b</td></tr></table>";
|
|
|
+ // TextView t2 = (TextView) view.findViewById(R.id.text2);
|
|
|
+ // t2.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
+ // TextView t1 = (TextView) view.findViewById(R.id.textView1);
|
|
|
+ //
|
|
|
+ // t1.setText(Html.fromHtml(url1));
|
|
|
+ // t1.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // final
|
|
|
+ // WebView wv;
|
|
|
+ //
|
|
|
+ // wv = (WebView) view.findViewById(R.id.webView1);
|
|
|
+ // wv.loadData(url1, mimeType, null);
|
|
|
|
|
|
return view;
|
|
|
}
|
|
|
|
|
|
+ void init(String jstr, LayoutInflater inflater)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ JSONObject jsonObj = new JSONObject(jstr);
|
|
|
+ int group_count = jsonObj.getInt("count");
|
|
|
+ for (int i = 0; i < group_count; i++)
|
|
|
+ {
|
|
|
+ // String key = (String) it.next();
|
|
|
+ // if (key.equals("result"))
|
|
|
+ // continue;
|
|
|
+ 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");
|
|
|
+ if (grouptype.equals("mapping"))
|
|
|
+ {
|
|
|
+ LinearLayout mappingview = (LinearLayout) inflater.inflate(
|
|
|
+ R.layout.key_mapping, null);
|
|
|
+ mappingview.setId(commonUtil.generateViewId());
|
|
|
+ control.put(v.getId(), mappingview.getId());
|
|
|
+ ll_root.addView(mappingview);
|
|
|
+
|
|
|
+ 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 val = itemobj.getString(key);
|
|
|
+ LinearLayout mappingitem = (LinearLayout) inflater
|
|
|
+ .inflate(R.layout.keymapping_item, null);
|
|
|
+ TextView tvkey = (TextView) mappingitem
|
|
|
+ .findViewById(R.id.tv_key);
|
|
|
+ tvkey.setText(key);
|
|
|
+ // tvkey.setBackgroundResource(R.drawable.detail_item);
|
|
|
+ TextView tvval = (TextView) mappingitem
|
|
|
+ .findViewById(R.id.tv_value);
|
|
|
+ tvval.setText(val);
|
|
|
+ // tvval.setBackgroundResource(R.drawable.detail_item);
|
|
|
+ mappingview.addView(mappingitem);
|
|
|
+ }
|
|
|
+// Iterator itgroup = groupobj.keys();
|
|
|
+// while (itgroup.hasNext())
|
|
|
+// {
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ if (grouptype.equals("table"))
|
|
|
+ {
|
|
|
+ String content = groupobj.getString("content");
|
|
|
+ WebView wv;
|
|
|
+
|
|
|
+ wv = (WebView) inflater.inflate(R.layout.web_content,
|
|
|
+ null);
|
|
|
+ wv.setId(commonUtil.generateViewId());
|
|
|
+ control.put(v.getId(), wv.getId());
|
|
|
+ wv.loadData(content, mimeType, null);
|
|
|
+ ll_root.addView(wv);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (grouptype.equals("list"))
|
|
|
+ {
|
|
|
+ LinearLayout listview = (LinearLayout) inflater.inflate(
|
|
|
+ R.layout.list_content, null);
|
|
|
+ listview.setId(commonUtil.generateViewId());
|
|
|
+ control.put(v.getId(), listview.getId());
|
|
|
+ ll_root.addView(listview);
|
|
|
+ long list_count = groupobj.getInt("_count");
|
|
|
+ for (int j = 0; j < list_count; j++)
|
|
|
+ {
|
|
|
+ RelativeLayout listitem = (RelativeLayout) inflater
|
|
|
+ .inflate(R.layout.list_item, null);
|
|
|
+
|
|
|
+ TextView tvitem = (TextView) listitem
|
|
|
+ .findViewById(R.id.tv_item);
|
|
|
+ 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();
|
|
|
+//
|
|
|
+// }
|
|
|
+ }
|
|
|
+ // String value = obj.getString(key);
|
|
|
+ // JSONArray array = obj.getJSONArray(key);
|
|
|
+ // for(int i=0;i<array.length();i++){
|
|
|
+ // JSONObject jsonobject = array.getJSONObject(i);
|
|
|
+ // jsonobject.put("name", key);
|
|
|
+ // jsonobject.put("exp", key+"="+jsonobject.getString("value"));
|
|
|
+ // newArray.put(jsonobject);
|
|
|
+
|
|
|
+ }
|
|
|
+ // Iterator it = jsonObj.keys();
|
|
|
+ // while (it.hasNext())
|
|
|
+ // {
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ catch (JSONException e)
|
|
|
+ {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v)
|
|
|
+ {
|
|
|
+ View view = ll_root.findViewById(control.get(v.getId()));
|
|
|
+ if (view.getVisibility() == View.VISIBLE)
|
|
|
+ view.setVisibility(View.GONE);
|
|
|
+ else
|
|
|
+ view.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ }
|
|
|
}
|