DetailFragment.java 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  1. package com.usai.apex;
  2. import android.animation.Animator;
  3. import android.animation.AnimatorListenerAdapter;
  4. import android.app.AlertDialog;
  5. import android.app.ProgressDialog;
  6. import android.content.ClipboardManager;
  7. import android.content.Context;
  8. import android.content.DialogInterface;
  9. import android.content.Intent;
  10. import android.database.Cursor;
  11. import android.graphics.Bitmap;
  12. import android.graphics.Color;
  13. import android.net.Uri;
  14. import android.os.AsyncTask;
  15. import android.os.Build;
  16. import android.os.Bundle;
  17. import android.provider.ContactsContract;
  18. import android.support.constraint.ConstraintLayout;
  19. import android.support.v4.app.Fragment;
  20. import android.text.Editable;
  21. import android.text.Html;
  22. import android.text.TextWatcher;
  23. import android.util.Log;
  24. import android.util.SparseIntArray;
  25. import android.view.GestureDetector;
  26. import android.view.Gravity;
  27. import android.view.LayoutInflater;
  28. import android.view.MotionEvent;
  29. import android.view.View;
  30. import android.view.View.OnClickListener;
  31. import android.view.ViewGroup;
  32. import android.webkit.WebResourceRequest;
  33. import android.webkit.WebResourceResponse;
  34. import android.webkit.WebView;
  35. import android.webkit.WebViewClient;
  36. import android.widget.Button;
  37. import android.widget.EditText;
  38. import android.widget.ImageButton;
  39. import android.widget.ImageView;
  40. import android.widget.LinearLayout;
  41. import android.widget.RelativeLayout;
  42. import android.widget.ScrollView;
  43. import android.widget.TextView;
  44. import android.widget.Toast;
  45. import com.usai.apex.ShipMap.ShipMap;
  46. import com.usai.apex.mainframe.NewDetailActivity;
  47. import com.usai.apex.pdf.PDFPreviewActivity;
  48. import com.usai.util.Network;
  49. import com.usai.util.RAUtil;
  50. import com.usai.util.commonUtil;
  51. import org.apache.http.util.EncodingUtils;
  52. import org.json.JSONException;
  53. import org.json.JSONObject;
  54. import java.io.ByteArrayInputStream;
  55. import java.io.File;
  56. import java.io.InputStream;
  57. import java.util.regex.Pattern;
  58. public class DetailFragment extends Fragment implements OnClickListener, ShipMap.ShipMapListener /*
  59. * ,
  60. * OnGestureListener
  61. */
  62. {
  63. private static final int People_Pick_Code = 1357;
  64. private String copiedKey;
  65. private String copiedVal;
  66. private View touchedView;
  67. @Override
  68. public void shipMapTryToZoomIn(ShipMap shipMap, boolean zoomIn) {
  69. if (zoomIn) {
  70. LinearLayout.LayoutParams lfLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0);
  71. mDetailContainer.setLayoutParams(lfLayoutParams);
  72. } else {
  73. LinearLayout.LayoutParams lfLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,2.0f);
  74. mDetailContainer.setLayoutParams(lfLayoutParams);
  75. }
  76. mMapZoomIn = zoomIn;
  77. }
  78. private class GestureListener extends GestureDetector.SimpleOnGestureListener {
  79. @Override
  80. public boolean onDoubleTapEvent(MotionEvent e) {
  81. if (e.getAction() == MotionEvent.ACTION_UP) {
  82. if (touchedView == null) {
  83. ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
  84. cm.setText(copiedVal);
  85. Toast.makeText(mContext, "Copied " + copiedKey, Toast.LENGTH_LONG).show();
  86. } else {
  87. String type = (String) touchedView.getTag();
  88. if (type.equals("tracking")) {
  89. TextView tvgroup = (TextView) touchedView.findViewById(R.id.tv_group);
  90. if (tvgroup != null) {
  91. String val = tvgroup.getText().toString();
  92. ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
  93. cm.setText(val);
  94. Toast.makeText(mContext, "Copied " + val, Toast.LENGTH_LONG).show();
  95. }
  96. }
  97. }
  98. }
  99. copiedKey = null;
  100. copiedVal = null;
  101. touchedView = null;
  102. return false;
  103. }
  104. @Override
  105. public boolean onSingleTapConfirmed(MotionEvent e) {
  106. if (touchedView != null) {
  107. onClick(touchedView);
  108. }
  109. touchedView = null;
  110. return false;
  111. }
  112. }
  113. private static final int REQUEST_LOGINACTIVITY = 1;
  114. // DataFragment mdataFragment;
  115. Context mContext;
  116. ProgressDialog progressDialog;
  117. private GestureDetector detector;
  118. protected void showProgressDialog(final String title, final String msg) {
  119. getActivity().runOnUiThread(new Runnable() {
  120. @Override
  121. public void run() {
  122. try {
  123. progressDialog.setTitle(title);
  124. progressDialog.setMessage(msg);
  125. progressDialog.show();
  126. } catch (Exception e) {
  127. e.printStackTrace();
  128. }
  129. }
  130. });
  131. }
  132. /* private GestureDetector mGestureDetector; */
  133. @Override
  134. public void onCreate(Bundle savedInstanceState)
  135. {
  136. // TODO Auto-generated method stub
  137. super.onCreate(savedInstanceState);
  138. if (progressDialog == null) {
  139. progressDialog = new ProgressDialog(mContext);
  140. progressDialog.setCancelable(false);
  141. }
  142. if (detector == null) {
  143. detector = new GestureDetector(mContext, new GestureListener());
  144. }
  145. }
  146. // @Override
  147. // public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  148. // super.onActivityCreated(savedInstanceState);
  149. //
  150. // progressDialog = new ProgressDialog(mContext);
  151. // progressDialog.setCancelable(false);
  152. // }
  153. @Override
  154. public void onAttach(Context context) {
  155. super.onAttach(context);
  156. mContext = context;
  157. }
  158. @Override
  159. public void onDestroyView()
  160. {
  161. Log.d("DetailFragment", "onDestroyView()");
  162. super.onDestroyView();
  163. }
  164. // public String get_content()
  165. // {
  166. // return fragment_content;
  167. // }
  168. LinearLayout ll_root;
  169. ScrollView sl_root;
  170. String mimeType = "text/html";
  171. private SearchTask m_task = null;
  172. SparseIntArray control = new SparseIntArray();
  173. // private TextView mStatusMessageView;
  174. private View mStatusView;
  175. String fragment_content = null;
  176. public void requestdata()
  177. {
  178. if (m_task != null)
  179. {
  180. return;
  181. }
  182. if (fragment_content != null)
  183. {
  184. LayoutInflater inflater = (LayoutInflater) ApexTrackingApplication
  185. .get_instance().getSystemService(
  186. Context.LAYOUT_INFLATER_SERVICE);
  187. init(fragment_content, inflater);
  188. return;
  189. }
  190. // if (mdataFragment.get_result() != null) {
  191. // LayoutInflater inflater = (LayoutInflater) ApexTrackingApplication
  192. // .get_instance().getSystemService(
  193. // Context.LAYOUT_INFLATER_SERVICE);
  194. // init(mdataFragment.get_result(), inflater);
  195. // }
  196. // if (fragment_content != null)
  197. // return;
  198. // mStatusMessageView.setText("Loading");
  199. showProgress(true);
  200. m_task = new SearchTask();
  201. m_task.execute();
  202. }
  203. public void set_content(String content)
  204. {
  205. fragment_content = content;
  206. }
  207. private void showProgress(final boolean show)
  208. {
  209. // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
  210. // for very easy animations. If available, use these APIs to fade-in
  211. // the progress spinner.
  212. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
  213. {
  214. int shortAnimTime = ApexTrackingApplication.get_instance()
  215. .getResources()
  216. .getInteger(android.R.integer.config_shortAnimTime);
  217. mStatusView.setVisibility(View.VISIBLE);
  218. mStatusView.animate().setDuration(shortAnimTime)
  219. .alpha(show ? 1 : 0)
  220. .setListener(new AnimatorListenerAdapter()
  221. {
  222. @Override
  223. public void onAnimationEnd(Animator animation)
  224. {
  225. mStatusView.setVisibility(show ? View.VISIBLE
  226. : View.INVISIBLE);
  227. }
  228. });
  229. ll_root.setVisibility(View.VISIBLE);
  230. ll_root.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
  231. .setListener(new AnimatorListenerAdapter()
  232. {
  233. @Override
  234. public void onAnimationEnd(Animator animation)
  235. {
  236. ll_root.setVisibility(show ? View.INVISIBLE
  237. : View.VISIBLE);
  238. }
  239. });
  240. }
  241. else
  242. {
  243. // The ViewPropertyAnimator APIs are not available, so simply show
  244. // and hide the relevant UI components.
  245. mStatusView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
  246. ll_root.setVisibility(show ? View.INVISIBLE : View.VISIBLE);
  247. }
  248. }
  249. // @Override
  250. // public void onActivityCreated(Bundle savedInstanceState)
  251. // {
  252. // FragmentManager fm = getFragmentManager();
  253. //
  254. // // Check to see if we have retained the worker fragment.
  255. // mdataFragment = (DataFragment)fm.findFragmentByTag("work");
  256. //
  257. // // If not retained (or first time running), we need to create it.
  258. // if (mdataFragment == null) {
  259. // mdataFragment = new DataFragment();
  260. // // Tell it who it is working with.
  261. // mdataFragment.setTargetFragment(this, 0);
  262. // fm.beginTransaction().add(mdataFragment, "work").commit();
  263. // }
  264. // super.onActivityCreated(savedInstanceState);
  265. // }
  266. private ShipMap mTrackingMap;
  267. @Override
  268. public void onSaveInstanceState(Bundle outState) {
  269. super.onSaveInstanceState(outState);
  270. if (mContent != null) {
  271. outState.putString("content",mContent.toString());
  272. }
  273. outState.putInt("selectContactPosition",mSelectContactPosition);
  274. outState.putInt("selectTrackingPosition",mSelectTrackingPosition);
  275. outState.putInt("selectTrackingChild",mSelectTrackingChild);
  276. outState.putBoolean("mapZoomIn",mMapZoomIn);
  277. }
  278. private void configureMap(ShipMap map) {
  279. if (map == null) {
  280. return;
  281. }
  282. map.setShowCurrent(true);
  283. map.setShowDestination(true);
  284. map.setShowOrigin(true);
  285. map.setShowPor(true);
  286. map.setShowPoe(true);
  287. map.setShowPod(true);
  288. map.setShowPol(true);
  289. map.setShipMapListener(this);
  290. }
  291. private RelativeLayout mDetailContainer;
  292. private boolean mMapZoomIn = false;
  293. @Override
  294. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  295. Bundle savedInstanceState)
  296. {
  297. final Context context = getContext();
  298. /* mGestureDetector = new GestureDetector(this); */
  299. View view = null;
  300. if(this.getArguments().getString("action_type").equals("Tracing")||this.getArguments().getString("action_type").equals("Tracking")) {
  301. view = inflater.inflate(R.layout.detail_fragment_withmap, null);
  302. mTrackingMap = view.findViewById(R.id.tracking_map);
  303. configureMap(mTrackingMap);
  304. mDetailContainer = view.findViewById(R.id.detail_list_container);
  305. } else {
  306. view = inflater.inflate(R.layout.detail_fragment, null);
  307. mTrackingMap = null;
  308. }
  309. if (savedInstanceState != null) {
  310. fragment_content = savedInstanceState.getString("content");
  311. mSelectContactPosition = savedInstanceState.getInt("selectContactPosition");
  312. mSelectTrackingPosition = savedInstanceState.getInt("selectTrackingPosition");
  313. mSelectTrackingChild = savedInstanceState.getInt("selectTrackingChild");
  314. mMapZoomIn = savedInstanceState.getBoolean("mapZoomIn");
  315. }
  316. if (mTrackingMap != null) {
  317. mTrackingMap.setZoomIn(mMapZoomIn);
  318. }
  319. // if(this.getArguments().getString("action_type").equals("Tracing"))
  320. // {
  321. // LinearLayout ll1 = view.findViewById(R.id.detail_linear);
  322. //
  323. // ShipMap shipMap = new ShipMap(context);
  324. //// mShipMap = shipMap;
  325. //
  326. //
  327. // LinearLayout.LayoutParams mapLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,1.0f);
  328. // mapLayoutParams.setMargins(commonUtil.dp2px(context,5),commonUtil.dp2px(context,2),commonUtil.dp2px(context,5),commonUtil.dp2px(context,2));
  329. //
  330. // ll1.addView(shipMap,mapLayoutParams);
  331. //
  332. // }
  333. sl_root = (ScrollView) view.findViewById(R.id.sl_root);
  334. /*
  335. * sl_root.setOnTouchListener(new View.OnTouchListener() {
  336. *
  337. * @Override public boolean onTouch(View v, MotionEvent event) { return
  338. * mGestureDetector.onTouchEvent(event); } });
  339. */
  340. ll_root = (LinearLayout) view.findViewById(R.id.ll_root);
  341. mStatusView = view.findViewById(R.id.status);
  342. LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_refresh);
  343. Button btn_refresh = (Button) ll.findViewById(R.id.btn_refresh);
  344. btn_refresh.setOnClickListener(new View.OnClickListener()
  345. {
  346. @Override
  347. public void onClick(View v)
  348. {
  349. LinearLayout ll = (LinearLayout) ll_root
  350. .findViewById(R.id.ll_refresh);
  351. ll.setVisibility(View.GONE);
  352. requestdata();
  353. }
  354. });
  355. // FragmentManager fm = getFragmentManager();
  356. // List<Fragment> fragments = fm.getFragments();
  357. // if (fragments != null) {
  358. // Log.e("DetailFragment", "fragments count=" + fragments.size());
  359. // // for (int i = 0; i < fragments.size(); i++)
  360. // // Log.e("DetailFragment", "fragments name=" + fragments.size());
  361. //
  362. // }
  363. // // this.getFragmentManager();
  364. // String tag = getArguments().getString("module_name");
  365. // // Check to see if we have retained the worker fragment.
  366. // mdataFragment = (DataFragment) fm.findFragmentById(12345);
  367. //
  368. // // If not retained (or first time running), we need to create it.
  369. // if (mdataFragment == null) {
  370. // Log.e("dataFragment creaded ", "tag=data_" + tag);
  371. // mdataFragment = new DataFragment();
  372. // // Tell it who it is working with.
  373. // mdataFragment.setTargetFragment(this, 0);
  374. // fm.beginTransaction().add(12345,mdataFragment, "data+" +
  375. // tag).commit();
  376. // }
  377. requestdata();
  378. return view;
  379. }
  380. protected JSONObject loadfakecontent(int rawid)
  381. {
  382. String jstring = "";
  383. try
  384. {
  385. InputStream in = getResources().openRawResource(rawid);
  386. // 获取文件的字节数
  387. int lenght = in.available();
  388. // 创建byte数组
  389. byte[] buffer = new byte[lenght];
  390. // 将文件中的数据读到byte数组中
  391. in.read(buffer);
  392. jstring = EncodingUtils.getString(buffer, "UTF-8");
  393. JSONObject jsobj = new JSONObject(jstring);
  394. return jsobj;
  395. // JSONObject objrecords = jsobj.getJSONObject("records");
  396. }
  397. catch (Exception e)
  398. {
  399. e.printStackTrace();
  400. }
  401. return null;
  402. }
  403. public JSONObject mContent;
  404. private int mSelectContactPosition = -1;
  405. private int mSelectTrackingPosition = -1;
  406. private int mSelectTrackingChild = -1;
  407. private View mSelectedTrackingCell = null;
  408. private void selectLocation(View view,int group,int child,JSONObject location) {
  409. if (mSelectedTrackingCell != null) {
  410. mSelectedTrackingCell.setBackgroundColor(Color.WHITE);
  411. }
  412. mSelectTrackingPosition = group;
  413. mSelectTrackingChild = child;
  414. mSelectedTrackingCell = view;
  415. if (mSelectedTrackingCell != null) {
  416. mSelectedTrackingCell.setBackgroundColor(Color.LTGRAY);
  417. }
  418. if (mTrackingMap != null && location != null) {
  419. mTrackingMap.showShipAnnotation(location);
  420. }
  421. }
  422. void init(String jstr, LayoutInflater inflater)
  423. {
  424. // LayoutInflater inflater = (LayoutInflater) ApexTrackingApplication
  425. // .get_instance().getSystemService(
  426. // Context.LAYOUT_INFLATER_SERVICE);
  427. inflater=getActivity().getLayoutInflater();
  428. String TAG = "init@DetailFragment";
  429. Log.d(TAG, jstr);
  430. try
  431. {
  432. JSONObject jsonObj = new JSONObject(jstr);
  433. int group_count = jsonObj.getInt("count");
  434. // if (getArguments().getString("action_type").equals("Detail")) {
  435. // JSONObject commObj = loadfakecontent(R.raw.fake_comm);
  436. // jsonObj.put("group" + group_count++,commObj);
  437. // jsonObj.put("count",group_count);
  438. // }
  439. mContent = jsonObj;
  440. if (group_count == 0)
  441. {
  442. TextView tv_empty = (TextView) ll_root
  443. .findViewById(R.id.tv_empty);
  444. tv_empty.setVisibility(View.VISIBLE);
  445. NewDetailActivity activity = (NewDetailActivity) getActivity();
  446. int tabCount = activity.getTabCount();
  447. if(tabCount==1)
  448. {
  449. new AlertDialog.Builder(getContext())
  450. .setTitle("Warning")
  451. .setCancelable(false)
  452. .setMessage("No Search Result.")
  453. .setPositiveButton("Back", new DialogInterface.OnClickListener() {
  454. @Override
  455. public void onClick(DialogInterface dialog, int which) {
  456. getActivity().finish();
  457. // checkAllPermission();
  458. // if (finalRequest)
  459. // checkAllPermission();
  460. // else
  461. // finish();
  462. }
  463. })
  464. // .setNegativeButton("No", new DialogInterface.OnClickListener() {
  465. // @Override
  466. // public void onClick(DialogInterface dialog, int which) {
  467. // finish();
  468. // }
  469. // })
  470. .show();
  471. }
  472. }
  473. for (int i = 0; i < group_count; i++)
  474. {
  475. // String key = (String) it.next();
  476. // if (key.equals("result"))
  477. // continue;
  478. final JSONObject groupobj = jsonObj.getJSONObject("group" + i);
  479. View v = inflater.inflate(R.layout.group_tag, null);
  480. // v.setOnClickListener(this);
  481. TextView tvgroup = (TextView) v.findViewById(R.id.tv_group);
  482. String group_name = groupobj.getString("_name");
  483. tvgroup.setText(group_name);
  484. v.setId(commonUtil.generateViewId());
  485. ll_root.addView(v);
  486. String grouptype = groupobj.getString("_type");
  487. v.setTag(grouptype);
  488. v.setOnTouchListener(new View.OnTouchListener() {
  489. @Override
  490. public boolean onTouch(View view, MotionEvent motionEvent) {
  491. touchedView = view;
  492. detector.onTouchEvent(motionEvent);
  493. return true;
  494. }
  495. });
  496. // groupobj.remove("_type");
  497. if (grouptype.equals("mapping"))
  498. {
  499. LinearLayout mappingview = (LinearLayout) inflater.inflate(
  500. R.layout.key_mapping, null);
  501. mappingview.setId(commonUtil.generateViewId());
  502. control.put(v.getId(), mappingview.getId());
  503. ll_root.addView(mappingview);
  504. int map_count = groupobj.getInt("count");
  505. for (int j = 0; j < map_count; j++)
  506. {
  507. // String keygroup = (String) itgroup.next();
  508. JSONObject itemobj = groupobj.getJSONObject("item" + j);
  509. final String key = (String) itemobj.keys().next();
  510. final String val = itemobj.getString(key);
  511. LinearLayout mappingitem = (LinearLayout) inflater
  512. .inflate(R.layout.keymapping_item, null);
  513. TextView tvkey = (TextView) mappingitem
  514. .findViewById(R.id.tv_key);
  515. tvkey.setText(key);
  516. // tvkey.setBackgroundResource(R.drawable.detail_item);
  517. TextView tvval = (TextView) mappingitem
  518. .findViewById(R.id.tv_value);
  519. tvval.setText(Html.fromHtml(val));
  520. // tvval.setBackgroundResource(R.drawable.detail_item);
  521. tvval.setOnTouchListener(new View.OnTouchListener() {
  522. @Override
  523. public boolean onTouch(View view, MotionEvent motionEvent) {
  524. copiedKey = key;
  525. copiedVal = val;
  526. detector.onTouchEvent(motionEvent);
  527. return true;
  528. }
  529. });
  530. mappingview.addView(mappingitem);
  531. }
  532. // Iterator itgroup = groupobj.keys();
  533. // while (itgroup.hasNext())
  534. // {
  535. //
  536. //
  537. // }
  538. }
  539. else if (grouptype.equals("table"))
  540. {
  541. String content = groupobj.getString("content");
  542. WebView wv;
  543. wv = (WebView) inflater.inflate(R.layout.web_content, null);
  544. wv.getSettings().setDefaultTextEncodingName("UTF-8");
  545. wv.setId(commonUtil.generateViewId());
  546. wv.setWebViewClient(new MyWebViewClient());
  547. // wv.setDownloadListener(new DownloadListener()
  548. // {
  549. //
  550. // @Override
  551. // public void onDownloadStart(String url,
  552. // String userAgent, String contentDisposition,
  553. // String mimetype, long contentLength)
  554. // {
  555. // if(!commonUtil.localdirExist())
  556. // {
  557. //
  558. // new AlertDialog.Builder(getActivity())
  559. // .setIconAttribute(android.R.attr.alertDialogIcon)
  560. // .setTitle(R.string.str_localdir_error)
  561. // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
  562. // public void onClick(DialogInterface dialog, int whichButton) {
  563. //
  564. // /* User clicked OK so do some stuff */
  565. // }
  566. // })
  567. // .create().show();
  568. // return;
  569. // }
  570. //// String filename = contentDisposition.replace("attachment;filename=\"", "");
  571. //// filename = filename.replace("\"", "");
  572. ////
  573. //// Log.d("WebView", "Download Action");
  574. //// Log.d("tag", "url=" + url);
  575. //// // Log.i("tag", "userAgent="+userAgent);
  576. //// // Log.i("tag",
  577. //// // "contentDisposition="+contentDisposition);
  578. //// // Log.i("tag", "mimetype="+mimetype);
  579. //// // Log.i("tag", "contentLength="+contentLength);
  580. //// // Uri uri = Uri.parse(url);
  581. //// // Intent intent = new Intent(Intent.ACTION_VIEW,
  582. //// // uri);
  583. //// // startActivity(intent);
  584. ////
  585. //// final DownloadManager downloadManager = (DownloadManager) ApexTrackingApplication
  586. //// .get_instance().getSystemService(
  587. //// Context.DOWNLOAD_SERVICE);
  588. ////
  589. //// Uri uri = Uri.parse(url);
  590. //// final Request request = new Request(uri);
  591. ////
  592. //// // 设置允许使用的网络类型,这里是移动网络和wifi都可以
  593. //// request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE
  594. //// | DownloadManager.Request.NETWORK_WIFI);
  595. ////
  596. ////
  597. ////
  598. //// request.setDestinationInExternalPublicDir("Apex Mobile",filename);
  599. ////
  600. //// // 禁止发出通知,既后台下载,如果要使用这一句必须声明一个权限:android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
  601. //// // request.setShowRunningNotification(false);
  602. ////
  603. //// // 不显示下载界面
  604. //// request.setVisibleInDownloadsUi(false);
  605. //// request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
  606. ////
  607. //// /*
  608. //// * 设置下载后文件存放的位置,如果sdcard不可用,那么设置这个将报错,
  609. //// * 因此最好不设置如果sdcard可用,下载后的文件 在/mnt/sdcard/Android/
  610. //// * data/packageName/files目录下面
  611. //// * ,如果sdcard不可用,设置了下面这个将报错,不设置,下载后的文件在/cache这个 目录下面
  612. //// */
  613. //// // request.setDestinationInExternalFilesDir(this,
  614. //// // null, "tar.apk");
  615. ////
  616. ////// getActivity();
  617. //// AlertDialog.Builder builder = new Builder(
  618. //// getActivity());
  619. //// builder.setMessage(getString(R.string.str_downloadmessage));
  620. ////
  621. //// builder.setTitle(getString(R.string.str_confirmdownload));
  622. ////
  623. //// builder.setPositiveButton(
  624. //// getString(R.string.str_download),
  625. //// new Dialog.OnClickListener()
  626. //// {
  627. ////
  628. //// @Override
  629. //// public void onClick(
  630. //// DialogInterface dialog,
  631. //// int which)
  632. //// {
  633. //// downloadManager.enqueue(request);
  634. //// dialog.dismiss();
  635. ////
  636. //// }
  637. //// });
  638. ////
  639. //// builder.setNegativeButton(
  640. //// getString(R.string.str_cancel),
  641. //// new Dialog.OnClickListener()
  642. //// {
  643. ////
  644. //// @Override
  645. //// public void onClick(
  646. //// DialogInterface dialog,
  647. //// int which)
  648. //// {
  649. //// dialog.dismiss();
  650. //// }
  651. //// });
  652. ////
  653. //// builder.create().show();
  654. //
  655. // }
  656. //
  657. // });
  658. wv.setTag(i);
  659. control.put(v.getId(), wv.getId());
  660. wv.loadData(content, mimeType, null);
  661. // wv.setOnTouchListener(new OnTouchListener()
  662. // {
  663. // @Override
  664. // public boolean onTouch(View v, MotionEvent event)
  665. // {
  666. //
  667. // if (event.getAction() == MotionEvent.ACTION_UP)
  668. // sl_root.requestDisallowInterceptTouchEvent(false);
  669. // else
  670. // sl_root.requestDisallowInterceptTouchEvent(true);
  671. //
  672. // return false;
  673. // }
  674. // });
  675. ll_root.addView(wv);
  676. Log.d("table content", content);
  677. }
  678. if (grouptype.equals("tracking"))
  679. {
  680. LinearLayout listview = (LinearLayout) inflater.inflate(
  681. R.layout.list_content, null);
  682. listview.setId(commonUtil.generateViewId());
  683. ViewGroup.LayoutParams lp=listview.getLayoutParams();
  684. control.put(v.getId(), listview.getId());
  685. ll_root.addView(listview);
  686. long list_count = groupobj.getInt("count");
  687. for (int j = 0; j < list_count; j++)
  688. {
  689. final JSONObject itemobj = groupobj.getJSONObject("item" + j);
  690. ConstraintLayout listitem = (ConstraintLayout) inflater
  691. .inflate(R.layout.detail_tracking_cell, null);
  692. ImageView icon = (ImageView) listitem
  693. .findViewById(R.id.iv_thumb);
  694. String iconname = itemobj.getString("icon");
  695. int rid = commonUtil.iconName2Rid(getActivity(),iconname);
  696. icon.setImageResource(rid);
  697. if(j!=0)
  698. {
  699. icon.setColorFilter(Color.GRAY);
  700. // ColorMatrix matrix = new ColorMatrix();
  701. // matrix.setSaturation(0);
  702. // ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
  703. // icon..image.setColorFilter(filter);
  704. }
  705. TextView tvitem = (TextView) listitem
  706. .findViewById(R.id.tv_title);
  707. String val = itemobj.getString("msg");
  708. tvitem.setText(val);
  709. // tvitem.setBackgroundResource(R.drawable.detail_item);
  710. // listitem.removeView(tvitem);
  711. int px=commonUtil.dp2px(getActivity(),56);
  712. listitem.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, px, 1));
  713. listview.addView(listitem);
  714. // ViewGroup.LayoutParams lp1=listitem.getLayoutParams();
  715. final int selectIndex = i;
  716. final int child = j;
  717. final JSONObject location = groupobj.optJSONObject("location");
  718. listitem.setOnClickListener(new OnClickListener() {
  719. @Override
  720. public void onClick(View v) {
  721. // if (mTrackingMap != null) {
  722. // JSONObject location = groupobj.optJSONObject("location");
  723. // if (location != null) {
  724. // mTrackingMap.showShipAnnotation(location);
  725. // }
  726. // mSelectTrackingPosition = selectIndex;
  727. // }
  728. selectLocation(v,selectIndex,child,location);
  729. }
  730. });
  731. if (mSelectTrackingPosition == -1) {
  732. mSelectTrackingPosition = selectIndex;
  733. }
  734. if (mSelectTrackingChild == -1) {
  735. mSelectTrackingChild = 0;
  736. }
  737. if (mSelectTrackingPosition == selectIndex && mSelectTrackingChild == child) {
  738. // if (mTrackingMap != null) {
  739. // JSONObject location = groupobj.optJSONObject("location");
  740. // if (location != null) {
  741. // mTrackingMap.showShipAnnotation(location);
  742. // }
  743. // }
  744. selectLocation(listitem,selectIndex,child,location);
  745. }
  746. }
  747. }
  748. if (grouptype.equals("list"))
  749. {
  750. LinearLayout listview = (LinearLayout) inflater.inflate(
  751. R.layout.list_content, null);
  752. listview.setId(commonUtil.generateViewId());
  753. control.put(v.getId(), listview.getId());
  754. ll_root.addView(listview);
  755. long list_count = groupobj.getInt("count");
  756. for (int j = 0; j < list_count; j++)
  757. {
  758. RelativeLayout listitem = (RelativeLayout) inflater
  759. .inflate(R.layout.list_item, null);
  760. TextView tvitem = (TextView) listitem
  761. .findViewById(R.id.tv_item);
  762. String val = groupobj.getString("line" + j);
  763. tvitem.setText(val);
  764. // tvitem.setBackgroundResource(R.drawable.detail_item);
  765. listitem.removeView(tvitem);
  766. listview.addView(tvitem);
  767. }
  768. // Iterator itgroup = groupobj.keys();
  769. // while (itgroup.hasNext())
  770. // {
  771. // String keygroup = (String) itgroup.next();
  772. //
  773. // }
  774. }
  775. if (grouptype.equals("communication"))
  776. {
  777. LinearLayout listview = (LinearLayout) inflater.inflate(
  778. R.layout.list_content, null);
  779. listview.setId(commonUtil.generateViewId());
  780. control.put(v.getId(), listview.getId());
  781. ll_root.addView(listview);
  782. // 添加收件人和cc
  783. ConstraintLayout commu_header = (ConstraintLayout) inflater
  784. .inflate(R.layout.commu_item_header, null);
  785. TextView toTv = commu_header.findViewById(R.id.comm_to_tv);
  786. EditText ccTv = commu_header.findViewById(R.id.comm_cc_tv);
  787. ImageButton contactBtn = commu_header.findViewById(R.id.comm_contact_btn);
  788. ccTv.setTag("group_" + i + "_cc");
  789. String to = groupobj.optString("receipt");
  790. String cc = groupobj.optString("cc");
  791. toTv.setText(to);
  792. ccTv.setText(cc);
  793. TextFieldTextWatcher ccWatcher = new TextFieldTextWatcher(getContext(),ccTv,i,0);
  794. ccTv.addTextChangedListener(ccWatcher);
  795. final int selectIndex = i;
  796. contactBtn.setOnClickListener(new OnClickListener() {
  797. @Override
  798. public void onClick(View v) {
  799. mSelectContactPosition = selectIndex;
  800. Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
  801. startActivityForResult(intent, People_Pick_Code);
  802. }
  803. });
  804. listview.addView(commu_header);
  805. long list_count = groupobj.getInt("count");
  806. for (int j = 0; j < list_count; j++)
  807. {
  808. ConstraintLayout msgitem = (ConstraintLayout) inflater
  809. .inflate(R.layout.commu_item_msg, null);
  810. JSONObject msgObj = groupobj.getJSONObject("item" + j);
  811. String sender = msgObj.optString("Sender");
  812. String msg = msgObj.optString("msg");
  813. String time = msgObj.optString("mst_time");
  814. final String email_url = msgObj.optString("email_url");
  815. TextView senderTv = msgitem.findViewById(R.id.comm_sender_tv);
  816. TextView msgTv = msgitem.findViewById(R.id.comm_msg_tv);
  817. TextView timeTv = msgitem.findViewById(R.id.comm_time_tv);
  818. Button sendBtn = msgitem.findViewById(R.id.comm_send_msg_btn);
  819. senderTv.setText(sender);
  820. // msgTv.setText(msg);
  821. msgTv.setText(Html.fromHtml(msg));
  822. timeTv.setText(time);
  823. sendBtn.setOnClickListener(new OnClickListener() {
  824. @Override
  825. public void onClick(View v) {
  826. Uri content_url = Uri.parse(email_url);
  827. Intent intent = new Intent(Intent.ACTION_VIEW,content_url);
  828. // Intent intent = new Intent();
  829. // intent.setAction("android.intent.action.VIEW");
  830. // intent.setData(content_url);
  831. startActivity(intent);
  832. }
  833. });
  834. if (email_url == null || email_url.length() == 0) {
  835. sendBtn.setVisibility(View.INVISIBLE);
  836. }
  837. listview.addView(msgitem);
  838. }
  839. //添加 消息输入和发送
  840. ConstraintLayout commu_footer = (ConstraintLayout) inflater
  841. .inflate(R.layout.commu_item_footer, null);
  842. EditText editTv = commu_footer.findViewById(R.id.comm_edit_tv);
  843. Button sendEmailBtn = commu_footer.findViewById(R.id.comm_send_email_btn);
  844. TextFieldTextWatcher editWatcher = new TextFieldTextWatcher(getContext(),editTv,i,1);
  845. editTv.addTextChangedListener(editWatcher);
  846. String edit_content = groupobj.optString("edit_content");
  847. editTv.setText(edit_content);
  848. final int groupIndex = i;
  849. sendEmailBtn.setOnClickListener(new OnClickListener() {
  850. @Override
  851. public void onClick(View v) {
  852. JSONObject commGroup = getGroup(groupIndex);
  853. final String cc = commGroup.optString("cc");
  854. final String content = commGroup.optString("edit_content");
  855. if (content == null || content.length() == 0) {
  856. new AlertDialog.Builder(mContext)
  857. .setTitle("Warning")
  858. .setMessage("The communication message that will be sent is blank")
  859. .setPositiveButton("Ok",null)
  860. .show();
  861. return;
  862. }
  863. if (cc != null && cc.length() > 0) {
  864. // 校验邮箱地址
  865. String[] ccArr = cc.split(";");
  866. for (int k = 0; k < ccArr.length; k++) {
  867. String ccStr = ccArr[k];
  868. if (ccStr.length() > 0) {
  869. boolean isEmail = validateEmail(ccStr);
  870. if (!isEmail) {
  871. new AlertDialog.Builder(mContext)
  872. .setTitle("Warning")
  873. .setMessage("The communication cc is not right")
  874. .setPositiveButton("Ok",null)
  875. .show();
  876. return;
  877. }
  878. }
  879. }
  880. }
  881. // send
  882. final ProgressDialog pd = new ProgressDialog(mContext);
  883. pd.setTitle(null);
  884. pd.setMessage("send email");
  885. pd.setCancelable(false);
  886. pd.show();
  887. final String serialNo = commGroup.optString("serial_no");
  888. new Thread(new Runnable() {
  889. @Override
  890. public void run() {
  891. final JSONObject response = Network.sendEmail(content,cc,serialNo);
  892. getActivity().runOnUiThread(new Runnable() {
  893. @Override
  894. public void run() {
  895. pd.dismiss();
  896. boolean showAlert = false;
  897. String msg = null;
  898. if (response != null) {
  899. int result = response.optInt("result",Network.RESULT_FALSE);
  900. if (result != Network.RESULT_TRUE) {
  901. showAlert = true;
  902. msg = response.optString("err_msg");
  903. }
  904. } else {
  905. showAlert = true;
  906. }
  907. if (msg == null) {
  908. msg = "Sorry,something wrong";
  909. }
  910. if (showAlert) {
  911. new AlertDialog.Builder(mContext)
  912. .setTitle(null)
  913. .setMessage(msg)
  914. .setPositiveButton("Ok",null)
  915. .show();
  916. }
  917. }
  918. });
  919. }
  920. }).start();
  921. }
  922. });
  923. listview.addView(commu_footer);
  924. listview.forceLayout();
  925. }
  926. // String value = obj.getString(key);
  927. // JSONArray array = obj.getJSONArray(key);
  928. // for(int i=0;i<array.length();i++){
  929. // JSONObject jsonobject = array.getJSONObject(i);
  930. // jsonobject.put("name", key);
  931. // jsonobject.put("exp", key+"="+jsonobject.getString("value"));
  932. // newArray.put(jsonobject);
  933. }
  934. // Iterator it = jsonObj.keys();
  935. // while (it.hasNext())
  936. // {
  937. //
  938. // }
  939. }
  940. catch (JSONException e)
  941. {
  942. // TODO Auto-generated catch block
  943. e.printStackTrace();
  944. }
  945. }
  946. private JSONObject getGroup(int group) {
  947. if (mContent != null) {
  948. JSONObject groupobj = mContent.optJSONObject("group" + group);
  949. return groupobj;
  950. }
  951. return null;
  952. }
  953. private boolean validateEmail(String email) {
  954. String emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
  955. return Pattern.matches(emailRegex,email);
  956. }
  957. @Override
  958. public void onClick(View v)
  959. {
  960. View view = ll_root.findViewById(control.get(v.getId()));
  961. ImageView expand_iv = v.findViewById(R.id.group_expand_indicator);
  962. if (view.getVisibility() == View.VISIBLE) {
  963. expand_iv.setImageResource(R.drawable.ic_expand_less);
  964. view.setVisibility(View.GONE);
  965. }
  966. else {
  967. expand_iv.setImageResource(R.drawable.ic_expand_more);
  968. view.setVisibility(View.VISIBLE);
  969. }
  970. }
  971. @Override
  972. public void onDestroy()
  973. {
  974. if (m_task != null)
  975. m_task.cancel(true);
  976. super.onDestroy();
  977. }
  978. @Override
  979. public void onActivityResult(int requestCode, int resultCode, Intent data)
  980. {
  981. // ((NewDetailActivity) getActivity()).showlogin = false;
  982. super.onActivityResult(requestCode, resultCode, data);
  983. if (requestCode == People_Pick_Code && data != null) {
  984. Uri contactData = data.getData();
  985. if (contactData == null) {
  986. return;
  987. }
  988. Cursor c = mContext.getContentResolver().query(contactData, null, null, null, null);
  989. if (c.moveToFirst()) {
  990. String contactId = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
  991. Cursor cursor = mContext.getContentResolver().query(
  992. ContactsContract.CommonDataKinds.Email.CONTENT_URI,
  993. new String[]{ContactsContract.CommonDataKinds.Email.DATA, ContactsContract.CommonDataKinds.Email.TYPE}, ContactsContract.Data.CONTACT_ID + "='" + contactId + "'", null, null);
  994. while(cursor.moveToNext()) {
  995. String email = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
  996. String emailType = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
  997. email = email.replace("\r\n",";");
  998. email = email.replace("\r",";");
  999. email = email.replace("\n",";");
  1000. String[] emailArr = email.split(";");
  1001. for (int i = 0; i < emailArr.length; i++) {
  1002. email = emailArr[i];
  1003. if (email.length() > 0) {
  1004. if (emailType != null && Integer.valueOf(emailType) == ContactsContract.CommonDataKinds.Email.TYPE_WORK) {
  1005. appendContactEmail(email,mSelectContactPosition);
  1006. return;
  1007. }
  1008. }
  1009. }
  1010. }
  1011. }
  1012. mSelectContactPosition = -1;
  1013. }
  1014. }
  1015. @Override
  1016. public void onDetach()
  1017. {
  1018. if (m_task != null)
  1019. m_task.cancel(false);
  1020. super.onDetach();
  1021. }
  1022. class SearchTask extends AsyncTask<Void, Void, Boolean>
  1023. {
  1024. int errorcode;
  1025. @Override
  1026. protected Boolean doInBackground(Void... params)
  1027. {
  1028. Log.d("SearchTask", "doInBackground");
  1029. if (!Network.NetworkIsAvailable())
  1030. {
  1031. errorcode = Network.RESULT_NET_NOTAVAILABLE;
  1032. return false;
  1033. }
  1034. String jstr = Network.get_detail(getArguments());
  1035. if (jstr == null || jstr.length() <= 0)
  1036. {
  1037. // Log.d(TAG, "json is wrong");
  1038. errorcode = Network.RESULT_NET_ERROR;
  1039. return false;
  1040. }
  1041. // mdataFragment.put_result(jstr);
  1042. fragment_content = jstr;
  1043. NewDetailActivity activity = (NewDetailActivity) getActivity();
  1044. activity.save_content(getArguments().getString("action_type"), jstr);
  1045. errorcode = Network.RESULT_TRUE;
  1046. return true;
  1047. }
  1048. @Override
  1049. protected void onPostExecute(Boolean success)
  1050. {
  1051. Log.i("onPostExecute", "entry");
  1052. m_task = null;
  1053. showProgress(false);
  1054. // if (ApexTrackingApplication.get_authorization() == false)
  1055. // {
  1056. // if(((DetailActivity) getActivity()).showlogin == true)
  1057. // return;
  1058. // ((DetailActivity) getActivity()).showlogin = true;
  1059. // LinearLayout ll = (LinearLayout) ll_root
  1060. // .findViewById(R.id.ll_refresh);
  1061. // ll.setVisibility(View.VISIBLE);
  1062. // Toast toast = Toast.makeText(
  1063. // ApexTrackingApplication.get_instance(),
  1064. // getText(R.string.msg_net_passwordchangedremote) , Toast.LENGTH_LONG);
  1065. // toast.setGravity(Gravity.CENTER, 0, 0);
  1066. // toast.show();
  1067. // Intent i = new Intent();
  1068. // i.setClass(getActivity(), ApexActivity.class);
  1069. // startActivityForResult(i, REQUEST_LOGINACTIVITY);
  1070. // return;
  1071. // }
  1072. switch (errorcode)
  1073. {
  1074. case Network.RESULT_NET_NOTAVAILABLE:
  1075. {
  1076. Toast toast = Toast.makeText(
  1077. ApexTrackingApplication.get_instance(),
  1078. getText(R.string.msg_connection_none),
  1079. Toast.LENGTH_LONG);
  1080. toast.setGravity(Gravity.CENTER, 0, 0);
  1081. toast.show();
  1082. break;
  1083. }
  1084. case Network.RESULT_NET_ERROR:
  1085. {
  1086. Toast toast = Toast.makeText(
  1087. ApexTrackingApplication.get_instance(),
  1088. getText(R.string.msg_net_error), Toast.LENGTH_LONG);
  1089. toast.setGravity(Gravity.CENTER, 0, 0);
  1090. toast.show();
  1091. break;
  1092. }
  1093. case Network.RESULT_ERROR:
  1094. // case Network.RESULT_RESPONSE_NULL:
  1095. {
  1096. Toast toast = Toast.makeText(
  1097. ApexTrackingApplication.get_instance(),
  1098. getText(R.string.msg_net_resulterror) + ":"
  1099. + errorcode, Toast.LENGTH_LONG);
  1100. toast.setGravity(Gravity.CENTER, 0, 0);
  1101. toast.show();
  1102. break;
  1103. }
  1104. default:
  1105. break;
  1106. }
  1107. if (success)
  1108. {
  1109. LayoutInflater inflater = (LayoutInflater) ApexTrackingApplication
  1110. .get_instance().getSystemService(
  1111. Context.LAYOUT_INFLATER_SERVICE);
  1112. init(fragment_content, inflater/*
  1113. * getActivity().
  1114. * getLayoutInflater()
  1115. */);
  1116. }
  1117. else
  1118. {
  1119. LinearLayout ll = (LinearLayout) ll_root
  1120. .findViewById(R.id.ll_refresh);
  1121. ll.setVisibility(View.VISIBLE);
  1122. }
  1123. super.onPostExecute(success);
  1124. }
  1125. @Override
  1126. protected void onCancelled()
  1127. {
  1128. m_task = null;
  1129. showProgress(false);
  1130. }
  1131. }
  1132. private void showQuickLook(final String url) {
  1133. showProgressDialog("Please wait","Downloading...");
  1134. new Thread(new Runnable() {
  1135. @Override
  1136. public void run() {
  1137. String cacheDir = ApexTrackingApplication.getInstance().getExternalCacheDir().getAbsolutePath();//ApexTrackingApplication.getInstance().getDocumentDir();
  1138. final Bundle param = new Bundle();
  1139. // 下载文件
  1140. final File downloadFile = Network.downloadFile(param,url,cacheDir);
  1141. getActivity().runOnUiThread(new Runnable() {
  1142. @Override
  1143. public void run() {
  1144. progressDialog.dismiss();
  1145. if (downloadFile != null && downloadFile.exists()) {
  1146. String email = null,email_subject = null,email_content = null;
  1147. //此处需要新增保存文档的本地表
  1148. try {
  1149. email = mContent.getString("email");
  1150. email_subject = mContent.getString("email_subject");
  1151. email_content = mContent.getString("email_content");
  1152. } catch (JSONException e) {
  1153. e.printStackTrace();
  1154. }
  1155. // email=param.getString("email");
  1156. // email_subject=param.getString("email_subject");
  1157. // email_content=param.getString("email_content");
  1158. previewPDF(downloadFile.getAbsolutePath(),email,email_subject,email_content);
  1159. } else {
  1160. showAlert("Sorry,there is a wrong.");
  1161. }
  1162. }
  1163. });
  1164. }
  1165. }).start();
  1166. }
  1167. // public class DataFragment extends Fragment {
  1168. //
  1169. // String result = null;
  1170. //
  1171. // @Override
  1172. // public void onCreate(Bundle savedInstanceState) {
  1173. // setRetainInstance(true);
  1174. // super.onCreate(savedInstanceState);
  1175. // }
  1176. //
  1177. // public String get_result() {
  1178. // return result;
  1179. //
  1180. // }
  1181. //
  1182. // public void put_result(String s) {
  1183. // result = s;
  1184. // }
  1185. //
  1186. // }
  1187. public void showAlert(String msg) {
  1188. if (msg == null || msg.isEmpty()) {
  1189. return;
  1190. }
  1191. new android.support.v7.app.AlertDialog.Builder(mContext)
  1192. .setMessage(msg)
  1193. .show();
  1194. }
  1195. protected void previewPDF(String file,String email,String subject,String content) {
  1196. Intent myIntent = new Intent();
  1197. myIntent = new Intent(getActivity(), PDFPreviewActivity.class);
  1198. myIntent.putExtra("file",file);
  1199. myIntent.putExtra("iscache",true);
  1200. try {
  1201. JSONObject json = new JSONObject();
  1202. // email = "66666@qq.com";
  1203. // subject = "test subject";
  1204. // content = "test body";
  1205. if (email != null) {
  1206. json.put("email",email);
  1207. }
  1208. if (subject != null) {
  1209. json.put("subject",subject);
  1210. }
  1211. if (content != null) {
  1212. json.put("content",content);
  1213. }
  1214. myIntent.putExtra("email",json.toString());
  1215. } catch (JSONException e) {
  1216. e.printStackTrace();
  1217. }
  1218. startActivity(myIntent);
  1219. }
  1220. public void download(String url) {
  1221. final String download_url = url;
  1222. showQuickLook(url);
  1223. if(true)
  1224. return;
  1225. showProgressDialog("Please wait","Downloading...");
  1226. new Thread(new Runnable() {
  1227. @Override
  1228. public void run() {
  1229. // String cacheDir = ApexTrackingApplication.getInstance().getDocumentDir();
  1230. // 下载文件
  1231. final File downloadFile = Network.downloadFile(null,download_url,null);
  1232. getActivity().runOnUiThread(new Runnable() {
  1233. @Override
  1234. public void run() {
  1235. progressDialog.dismiss();
  1236. RAUtil.openFile(getActivity(),downloadFile);
  1237. }
  1238. });
  1239. }
  1240. }).start();
  1241. }
  1242. public class MyWebViewClient extends WebViewClient
  1243. {
  1244. // 如果页面中链接,如果希望点击链接继续在当前browser中响应,
  1245. // 而不是新开Android的系统browser中响应该链接,必须覆盖 webview的WebViewClient对象。
  1246. public boolean shouldOverviewUrlLoading(WebView view, String url)
  1247. {
  1248. Log.d("Web Client", "shouldOverviewUrlLoading: " + url);
  1249. // L.i("shouldOverviewUrlLoading");
  1250. view.loadUrl(url);
  1251. return true;
  1252. }
  1253. @Override
  1254. public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
  1255. Log.d("Web Client", "shouldOverrideUrlLoading: " + request);
  1256. return super.shouldOverrideUrlLoading(view, request);
  1257. }
  1258. public void onPageStarted(WebView view, String url, Bitmap favicon)
  1259. {
  1260. // L.i("onPageStarted");
  1261. // showProgress();
  1262. Log.d("Web Client", "onPageStarted: ");
  1263. }
  1264. public void onPageFinished(WebView view, String url)
  1265. {
  1266. // L.i("onPageFinished");
  1267. // closeProgress();
  1268. Log.d("Web Client", "onPageFinished: ");
  1269. }
  1270. public void onReceivedError(WebView view, int errorCode,
  1271. String description, String failingUrl)
  1272. {
  1273. // L.i("onReceivedError");
  1274. // closeProgress();
  1275. Log.d("Web Client", "onReceivedError: ");
  1276. }
  1277. @Override
  1278. public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
  1279. Log.d("Web Client", "shouldInterceptRequest: " + url);
  1280. if (url.startsWith("http") && url.contains("action_type=download_doc")) {
  1281. download(url);
  1282. String content = contentOfWebView(view);
  1283. WebResourceResponse response = new WebResourceResponse("text/html",
  1284. "utf-8",
  1285. new ByteArrayInputStream(content.getBytes()));
  1286. return response;
  1287. } else {
  1288. return super.shouldInterceptRequest(view,url);
  1289. }
  1290. }
  1291. String contentOfWebView(WebView webView) {
  1292. int i = (int)webView.getTag();
  1293. try {
  1294. JSONObject groupobj = mContent.getJSONObject("group" + i);
  1295. String content = groupobj.getString("content");
  1296. return content;
  1297. } catch (JSONException e) {
  1298. e.printStackTrace();
  1299. }
  1300. return null;
  1301. }
  1302. // @Override
  1303. // public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
  1304. // Log.d("Web Client", "shouldInterceptRequest: " + request);
  1305. //
  1306. // if (request.getUrl().toString().contains("action_type=download_doc")) {
  1307. // return null;
  1308. // } else {
  1309. // return super.shouldInterceptRequest(view,request);
  1310. // }
  1311. //
  1312. //
  1313. // }
  1314. }
  1315. private void appendContactEmail(String email,int group) {
  1316. try {
  1317. String groupKey = "group" + group;
  1318. JSONObject groupObj = mContent.getJSONObject(groupKey);
  1319. String groupType = groupObj.getString("_type");
  1320. if (groupType.equals("communication")) {
  1321. String oldCC = groupObj.optString("cc");
  1322. if (oldCC == null || oldCC.length() == 0) {
  1323. oldCC = email + ";";
  1324. } else {
  1325. if (oldCC.substring(oldCC.length() - 1).equals(";")) {
  1326. oldCC = oldCC + email + ";";
  1327. } else {
  1328. oldCC = oldCC + ";" + email + ";";
  1329. }
  1330. }
  1331. commContentChange(oldCC,group,0);
  1332. EditText ccTv = ll_root.findViewWithTag("group_" + group + "_cc");
  1333. if (ccTv != null) {
  1334. ccTv.setText(oldCC);
  1335. ccTv.requestFocus();
  1336. ccTv.setSelection(oldCC.length());
  1337. }
  1338. }
  1339. } catch (JSONException e) {
  1340. e.printStackTrace();
  1341. }
  1342. }
  1343. private void commContentChange(String content,int group,int child) {
  1344. try {
  1345. String groupKey = "group" + group;
  1346. JSONObject groupObj = mContent.getJSONObject(groupKey);
  1347. String groupType = groupObj.getString("_type");
  1348. if (groupType.equals("communication")) {
  1349. if (child == 0) {
  1350. groupObj.put("cc",content);
  1351. } else if (child == 1) {
  1352. groupObj.put("edit_content",content);
  1353. }
  1354. mContent.put(groupKey,groupObj);
  1355. }
  1356. } catch (JSONException e) {
  1357. e.printStackTrace();
  1358. }
  1359. }
  1360. public class TextFieldTextWatcher implements TextWatcher {
  1361. Context mCtx;
  1362. int group;
  1363. int child;
  1364. EditText textView;
  1365. public TextFieldTextWatcher(Context ctx,EditText textView,int group,int child) {
  1366. this.mCtx = ctx;
  1367. this.textView = textView;
  1368. this.group = group;
  1369. this.child = child;
  1370. }
  1371. String origin_text;
  1372. String string;
  1373. int start_position;
  1374. int change_length; // 修改原文长度
  1375. int new_string_length;
  1376. /**
  1377. * s 改变前的内容
  1378. * start 增加内容前光标位置,删除内容后光标位置 (起始位置)
  1379. * count 选中s中的内容长度(发生改变的原内容长度),未选中为0
  1380. * after 新添加的内容长度,删除为0
  1381. * */
  1382. @Override
  1383. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  1384. // Log.d("TextChange", "before Text Changed: " + s + " Start: " + start + " Count: " + count + " After: " + after);
  1385. origin_text = s.toString();
  1386. start_position = start;
  1387. change_length = count;
  1388. new_string_length = after;
  1389. }
  1390. /**
  1391. * s 改变后的内容
  1392. * start 增加内容前光标位置,删除内容后光标位置 (起始位置)
  1393. * before 选中s中的内容长度(发生改变的原内容长度),未选中为0
  1394. * count 增加内容长度,删除内容为0
  1395. * */
  1396. @Override
  1397. public void onTextChanged(CharSequence s, int start, int before, int count) {
  1398. // Log.d("TextChange", "on Text Changed: " + s + " Start: " + start + " Before: " + before + " Count: " + count);
  1399. }
  1400. @Override
  1401. public void afterTextChanged(Editable s) {
  1402. commContentChange(s.toString(),group,child);
  1403. }
  1404. }
  1405. }