DetailFragment.java 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  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. String backup_port=this.mContent.optString("backup_port");
  420. mTrackingMap.showShipAnnotation(location,backup_port);
  421. }
  422. }
  423. void init(String jstr, LayoutInflater inflater)
  424. {
  425. // LayoutInflater inflater = (LayoutInflater) ApexTrackingApplication
  426. // .get_instance().getSystemService(
  427. // Context.LAYOUT_INFLATER_SERVICE);
  428. inflater=getActivity().getLayoutInflater();
  429. String TAG = "init@DetailFragment";
  430. Log.d(TAG, jstr);
  431. try
  432. {
  433. JSONObject jsonObj = new JSONObject(jstr);
  434. int group_count = jsonObj.getInt("count");
  435. // if (getArguments().getString("action_type").equals("Detail")) {
  436. // JSONObject commObj = loadfakecontent(R.raw.fake_comm);
  437. // jsonObj.put("group" + group_count++,commObj);
  438. // jsonObj.put("count",group_count);
  439. // }
  440. mContent = jsonObj;
  441. if (group_count == 0)
  442. {
  443. TextView tv_empty = (TextView) ll_root
  444. .findViewById(R.id.tv_empty);
  445. tv_empty.setVisibility(View.VISIBLE);
  446. NewDetailActivity activity = (NewDetailActivity) getActivity();
  447. int tabCount = activity.getTabCount();
  448. if(tabCount==1)
  449. {
  450. new AlertDialog.Builder(getContext())
  451. .setTitle("Warning")
  452. .setCancelable(false)
  453. .setMessage("No Search Result.")
  454. .setPositiveButton("Back", new DialogInterface.OnClickListener() {
  455. @Override
  456. public void onClick(DialogInterface dialog, int which) {
  457. getActivity().finish();
  458. // checkAllPermission();
  459. // if (finalRequest)
  460. // checkAllPermission();
  461. // else
  462. // finish();
  463. }
  464. })
  465. // .setNegativeButton("No", new DialogInterface.OnClickListener() {
  466. // @Override
  467. // public void onClick(DialogInterface dialog, int which) {
  468. // finish();
  469. // }
  470. // })
  471. .show();
  472. }
  473. }
  474. for (int i = 0; i < group_count; i++)
  475. {
  476. // String key = (String) it.next();
  477. // if (key.equals("result"))
  478. // continue;
  479. final JSONObject groupobj = jsonObj.getJSONObject("group" + i);
  480. View v = inflater.inflate(R.layout.group_tag, null);
  481. // v.setOnClickListener(this);
  482. TextView tvgroup = (TextView) v.findViewById(R.id.tv_group);
  483. String group_name = groupobj.getString("_name");
  484. tvgroup.setText(group_name);
  485. v.setId(commonUtil.generateViewId());
  486. ll_root.addView(v);
  487. String grouptype = groupobj.getString("_type");
  488. v.setTag(grouptype);
  489. v.setOnTouchListener(new View.OnTouchListener() {
  490. @Override
  491. public boolean onTouch(View view, MotionEvent motionEvent) {
  492. touchedView = view;
  493. detector.onTouchEvent(motionEvent);
  494. return true;
  495. }
  496. });
  497. // groupobj.remove("_type");
  498. if (grouptype.equals("mapping"))
  499. {
  500. LinearLayout mappingview = (LinearLayout) inflater.inflate(
  501. R.layout.key_mapping, null);
  502. mappingview.setId(commonUtil.generateViewId());
  503. control.put(v.getId(), mappingview.getId());
  504. ll_root.addView(mappingview);
  505. int map_count = groupobj.getInt("count");
  506. for (int j = 0; j < map_count; j++)
  507. {
  508. // String keygroup = (String) itgroup.next();
  509. JSONObject itemobj = groupobj.getJSONObject("item" + j);
  510. final String key = (String) itemobj.keys().next();
  511. final String val = itemobj.getString(key);
  512. LinearLayout mappingitem = (LinearLayout) inflater
  513. .inflate(R.layout.keymapping_item, null);
  514. TextView tvkey = (TextView) mappingitem
  515. .findViewById(R.id.tv_key);
  516. tvkey.setText(key);
  517. // tvkey.setBackgroundResource(R.drawable.detail_item);
  518. TextView tvval = (TextView) mappingitem
  519. .findViewById(R.id.tv_value);
  520. tvval.setText(Html.fromHtml(val));
  521. // tvval.setBackgroundResource(R.drawable.detail_item);
  522. tvval.setOnTouchListener(new View.OnTouchListener() {
  523. @Override
  524. public boolean onTouch(View view, MotionEvent motionEvent) {
  525. copiedKey = key;
  526. copiedVal = val;
  527. detector.onTouchEvent(motionEvent);
  528. return true;
  529. }
  530. });
  531. mappingview.addView(mappingitem);
  532. }
  533. // Iterator itgroup = groupobj.keys();
  534. // while (itgroup.hasNext())
  535. // {
  536. //
  537. //
  538. // }
  539. }
  540. else if (grouptype.equals("table"))
  541. {
  542. String content = groupobj.getString("content");
  543. WebView wv;
  544. wv = (WebView) inflater.inflate(R.layout.web_content, null);
  545. wv.getSettings().setDefaultTextEncodingName("UTF-8");
  546. wv.setId(commonUtil.generateViewId());
  547. wv.setWebViewClient(new MyWebViewClient());
  548. // wv.setDownloadListener(new DownloadListener()
  549. // {
  550. //
  551. // @Override
  552. // public void onDownloadStart(String url,
  553. // String userAgent, String contentDisposition,
  554. // String mimetype, long contentLength)
  555. // {
  556. // if(!commonUtil.localdirExist())
  557. // {
  558. //
  559. // new AlertDialog.Builder(getActivity())
  560. // .setIconAttribute(android.R.attr.alertDialogIcon)
  561. // .setTitle(R.string.str_localdir_error)
  562. // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
  563. // public void onClick(DialogInterface dialog, int whichButton) {
  564. //
  565. // /* User clicked OK so do some stuff */
  566. // }
  567. // })
  568. // .create().show();
  569. // return;
  570. // }
  571. //// String filename = contentDisposition.replace("attachment;filename=\"", "");
  572. //// filename = filename.replace("\"", "");
  573. ////
  574. //// Log.d("WebView", "Download Action");
  575. //// Log.d("tag", "url=" + url);
  576. //// // Log.i("tag", "userAgent="+userAgent);
  577. //// // Log.i("tag",
  578. //// // "contentDisposition="+contentDisposition);
  579. //// // Log.i("tag", "mimetype="+mimetype);
  580. //// // Log.i("tag", "contentLength="+contentLength);
  581. //// // Uri uri = Uri.parse(url);
  582. //// // Intent intent = new Intent(Intent.ACTION_VIEW,
  583. //// // uri);
  584. //// // startActivity(intent);
  585. ////
  586. //// final DownloadManager downloadManager = (DownloadManager) ApexTrackingApplication
  587. //// .get_instance().getSystemService(
  588. //// Context.DOWNLOAD_SERVICE);
  589. ////
  590. //// Uri uri = Uri.parse(url);
  591. //// final Request request = new Request(uri);
  592. ////
  593. //// // 设置允许使用的网络类型,这里是移动网络和wifi都可以
  594. //// request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE
  595. //// | DownloadManager.Request.NETWORK_WIFI);
  596. ////
  597. ////
  598. ////
  599. //// request.setDestinationInExternalPublicDir("Apex Mobile",filename);
  600. ////
  601. //// // 禁止发出通知,既后台下载,如果要使用这一句必须声明一个权限:android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
  602. //// // request.setShowRunningNotification(false);
  603. ////
  604. //// // 不显示下载界面
  605. //// request.setVisibleInDownloadsUi(false);
  606. //// request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
  607. ////
  608. //// /*
  609. //// * 设置下载后文件存放的位置,如果sdcard不可用,那么设置这个将报错,
  610. //// * 因此最好不设置如果sdcard可用,下载后的文件 在/mnt/sdcard/Android/
  611. //// * data/packageName/files目录下面
  612. //// * ,如果sdcard不可用,设置了下面这个将报错,不设置,下载后的文件在/cache这个 目录下面
  613. //// */
  614. //// // request.setDestinationInExternalFilesDir(this,
  615. //// // null, "tar.apk");
  616. ////
  617. ////// getActivity();
  618. //// AlertDialog.Builder builder = new Builder(
  619. //// getActivity());
  620. //// builder.setMessage(getString(R.string.str_downloadmessage));
  621. ////
  622. //// builder.setTitle(getString(R.string.str_confirmdownload));
  623. ////
  624. //// builder.setPositiveButton(
  625. //// getString(R.string.str_download),
  626. //// new Dialog.OnClickListener()
  627. //// {
  628. ////
  629. //// @Override
  630. //// public void onClick(
  631. //// DialogInterface dialog,
  632. //// int which)
  633. //// {
  634. //// downloadManager.enqueue(request);
  635. //// dialog.dismiss();
  636. ////
  637. //// }
  638. //// });
  639. ////
  640. //// builder.setNegativeButton(
  641. //// getString(R.string.str_cancel),
  642. //// new Dialog.OnClickListener()
  643. //// {
  644. ////
  645. //// @Override
  646. //// public void onClick(
  647. //// DialogInterface dialog,
  648. //// int which)
  649. //// {
  650. //// dialog.dismiss();
  651. //// }
  652. //// });
  653. ////
  654. //// builder.create().show();
  655. //
  656. // }
  657. //
  658. // });
  659. wv.setTag(i);
  660. control.put(v.getId(), wv.getId());
  661. wv.loadData(content, mimeType, null);
  662. // wv.setOnTouchListener(new OnTouchListener()
  663. // {
  664. // @Override
  665. // public boolean onTouch(View v, MotionEvent event)
  666. // {
  667. //
  668. // if (event.getAction() == MotionEvent.ACTION_UP)
  669. // sl_root.requestDisallowInterceptTouchEvent(false);
  670. // else
  671. // sl_root.requestDisallowInterceptTouchEvent(true);
  672. //
  673. // return false;
  674. // }
  675. // });
  676. ll_root.addView(wv);
  677. Log.d("table content", content);
  678. }
  679. if (grouptype.equals("tracking"))
  680. {
  681. LinearLayout listview = (LinearLayout) inflater.inflate(
  682. R.layout.list_content, null);
  683. listview.setId(commonUtil.generateViewId());
  684. ViewGroup.LayoutParams lp=listview.getLayoutParams();
  685. control.put(v.getId(), listview.getId());
  686. ll_root.addView(listview);
  687. long list_count = groupobj.getInt("count");
  688. for (int j = 0; j < list_count; j++)
  689. {
  690. final JSONObject itemobj = groupobj.getJSONObject("item" + j);
  691. ConstraintLayout listitem = (ConstraintLayout) inflater
  692. .inflate(R.layout.detail_tracking_cell, null);
  693. ImageView icon = (ImageView) listitem
  694. .findViewById(R.id.iv_thumb);
  695. String iconname = itemobj.getString("icon");
  696. int rid = commonUtil.iconName2Rid(getActivity(),iconname);
  697. icon.setImageResource(rid);
  698. if(j!=0)
  699. {
  700. icon.setColorFilter(Color.GRAY);
  701. // ColorMatrix matrix = new ColorMatrix();
  702. // matrix.setSaturation(0);
  703. // ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
  704. // icon..image.setColorFilter(filter);
  705. }
  706. TextView tvitem = (TextView) listitem
  707. .findViewById(R.id.tv_title);
  708. String val = itemobj.getString("msg");
  709. tvitem.setText(val);
  710. // tvitem.setBackgroundResource(R.drawable.detail_item);
  711. // listitem.removeView(tvitem);
  712. int px=commonUtil.dp2px(getActivity(),56);
  713. listitem.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, px, 1));
  714. listview.addView(listitem);
  715. // ViewGroup.LayoutParams lp1=listitem.getLayoutParams();
  716. final int selectIndex = i;
  717. final int child = j;
  718. final JSONObject location = groupobj.optJSONObject("location");
  719. listitem.setOnClickListener(new OnClickListener() {
  720. @Override
  721. public void onClick(View v) {
  722. // if (mTrackingMap != null) {
  723. // JSONObject location = groupobj.optJSONObject("location");
  724. // if (location != null) {
  725. // mTrackingMap.showShipAnnotation(location);
  726. // }
  727. // mSelectTrackingPosition = selectIndex;
  728. // }
  729. selectLocation(v,selectIndex,child,location);
  730. }
  731. });
  732. if (mSelectTrackingPosition == -1) {
  733. mSelectTrackingPosition = selectIndex;
  734. }
  735. if (mSelectTrackingChild == -1) {
  736. mSelectTrackingChild = 0;
  737. }
  738. if (mSelectTrackingPosition == selectIndex && mSelectTrackingChild == child) {
  739. // if (mTrackingMap != null) {
  740. // JSONObject location = groupobj.optJSONObject("location");
  741. // if (location != null) {
  742. // mTrackingMap.showShipAnnotation(location);
  743. // }
  744. // }
  745. selectLocation(listitem,selectIndex,child,location);
  746. }
  747. }
  748. }
  749. if (grouptype.equals("list"))
  750. {
  751. LinearLayout listview = (LinearLayout) inflater.inflate(
  752. R.layout.list_content, null);
  753. listview.setId(commonUtil.generateViewId());
  754. control.put(v.getId(), listview.getId());
  755. ll_root.addView(listview);
  756. long list_count = groupobj.getInt("count");
  757. for (int j = 0; j < list_count; j++)
  758. {
  759. RelativeLayout listitem = (RelativeLayout) inflater
  760. .inflate(R.layout.list_item, null);
  761. TextView tvitem = (TextView) listitem
  762. .findViewById(R.id.tv_item);
  763. String val = groupobj.getString("line" + j);
  764. tvitem.setText(val);
  765. // tvitem.setBackgroundResource(R.drawable.detail_item);
  766. listitem.removeView(tvitem);
  767. listview.addView(tvitem);
  768. }
  769. // Iterator itgroup = groupobj.keys();
  770. // while (itgroup.hasNext())
  771. // {
  772. // String keygroup = (String) itgroup.next();
  773. //
  774. // }
  775. }
  776. if (grouptype.equals("communication"))
  777. {
  778. LinearLayout listview = (LinearLayout) inflater.inflate(
  779. R.layout.list_content, null);
  780. listview.setId(commonUtil.generateViewId());
  781. control.put(v.getId(), listview.getId());
  782. ll_root.addView(listview);
  783. // 添加收件人和cc
  784. ConstraintLayout commu_header = (ConstraintLayout) inflater
  785. .inflate(R.layout.commu_item_header, null);
  786. TextView toTv = commu_header.findViewById(R.id.comm_to_tv);
  787. EditText ccTv = commu_header.findViewById(R.id.comm_cc_tv);
  788. ImageButton contactBtn = commu_header.findViewById(R.id.comm_contact_btn);
  789. ccTv.setTag("group_" + i + "_cc");
  790. String to = groupobj.optString("receipt");
  791. String cc = groupobj.optString("cc");
  792. toTv.setText(to);
  793. ccTv.setText(cc);
  794. TextFieldTextWatcher ccWatcher = new TextFieldTextWatcher(getContext(),ccTv,i,0);
  795. ccTv.addTextChangedListener(ccWatcher);
  796. final int selectIndex = i;
  797. contactBtn.setOnClickListener(new OnClickListener() {
  798. @Override
  799. public void onClick(View v) {
  800. mSelectContactPosition = selectIndex;
  801. Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
  802. startActivityForResult(intent, People_Pick_Code);
  803. }
  804. });
  805. listview.addView(commu_header);
  806. long list_count = groupobj.getInt("count");
  807. for (int j = 0; j < list_count; j++)
  808. {
  809. ConstraintLayout msgitem = (ConstraintLayout) inflater
  810. .inflate(R.layout.commu_item_msg, null);
  811. JSONObject msgObj = groupobj.getJSONObject("item" + j);
  812. String sender = msgObj.optString("Sender");
  813. String msg = msgObj.optString("msg");
  814. String time = msgObj.optString("mst_time");
  815. final String email_url = msgObj.optString("email_url");
  816. TextView senderTv = msgitem.findViewById(R.id.comm_sender_tv);
  817. TextView msgTv = msgitem.findViewById(R.id.comm_msg_tv);
  818. TextView timeTv = msgitem.findViewById(R.id.comm_time_tv);
  819. Button sendBtn = msgitem.findViewById(R.id.comm_send_msg_btn);
  820. senderTv.setText(sender);
  821. // msgTv.setText(msg);
  822. msgTv.setText(Html.fromHtml(msg));
  823. timeTv.setText(time);
  824. sendBtn.setOnClickListener(new OnClickListener() {
  825. @Override
  826. public void onClick(View v) {
  827. Uri content_url = Uri.parse(email_url);
  828. Intent intent = new Intent(Intent.ACTION_VIEW,content_url);
  829. // Intent intent = new Intent();
  830. // intent.setAction("android.intent.action.VIEW");
  831. // intent.setData(content_url);
  832. startActivity(intent);
  833. }
  834. });
  835. if (email_url == null || email_url.length() == 0) {
  836. sendBtn.setVisibility(View.INVISIBLE);
  837. }
  838. listview.addView(msgitem);
  839. }
  840. //添加 消息输入和发送
  841. ConstraintLayout commu_footer = (ConstraintLayout) inflater
  842. .inflate(R.layout.commu_item_footer, null);
  843. EditText editTv = commu_footer.findViewById(R.id.comm_edit_tv);
  844. Button sendEmailBtn = commu_footer.findViewById(R.id.comm_send_email_btn);
  845. TextFieldTextWatcher editWatcher = new TextFieldTextWatcher(getContext(),editTv,i,1);
  846. editTv.addTextChangedListener(editWatcher);
  847. String edit_content = groupobj.optString("edit_content");
  848. editTv.setText(edit_content);
  849. final int groupIndex = i;
  850. sendEmailBtn.setOnClickListener(new OnClickListener() {
  851. @Override
  852. public void onClick(View v) {
  853. JSONObject commGroup = getGroup(groupIndex);
  854. final String cc = commGroup.optString("cc");
  855. final String content = commGroup.optString("edit_content");
  856. if (content == null || content.length() == 0) {
  857. new AlertDialog.Builder(mContext)
  858. .setTitle("Warning")
  859. .setMessage("The communication message that will be sent is blank")
  860. .setPositiveButton("Ok",null)
  861. .show();
  862. return;
  863. }
  864. if (cc != null && cc.length() > 0) {
  865. // 校验邮箱地址
  866. String[] ccArr = cc.split(";");
  867. for (int k = 0; k < ccArr.length; k++) {
  868. String ccStr = ccArr[k];
  869. if (ccStr.length() > 0) {
  870. boolean isEmail = validateEmail(ccStr);
  871. if (!isEmail) {
  872. new AlertDialog.Builder(mContext)
  873. .setTitle("Warning")
  874. .setMessage("The communication cc is not right")
  875. .setPositiveButton("Ok",null)
  876. .show();
  877. return;
  878. }
  879. }
  880. }
  881. }
  882. // send
  883. final ProgressDialog pd = new ProgressDialog(mContext);
  884. pd.setTitle(null);
  885. pd.setMessage("send email");
  886. pd.setCancelable(false);
  887. pd.show();
  888. final String serialNo = commGroup.optString("serial_no");
  889. new Thread(new Runnable() {
  890. @Override
  891. public void run() {
  892. final JSONObject response = Network.sendEmail(content,cc,serialNo);
  893. getActivity().runOnUiThread(new Runnable() {
  894. @Override
  895. public void run() {
  896. pd.dismiss();
  897. boolean showAlert = false;
  898. String msg = null;
  899. if (response != null) {
  900. int result = response.optInt("result",Network.RESULT_FALSE);
  901. if (result != Network.RESULT_TRUE) {
  902. showAlert = true;
  903. msg = response.optString("err_msg");
  904. }
  905. } else {
  906. showAlert = true;
  907. }
  908. if (msg == null) {
  909. msg = "Sorry,something wrong";
  910. }
  911. if (showAlert) {
  912. new AlertDialog.Builder(mContext)
  913. .setTitle(null)
  914. .setMessage(msg)
  915. .setPositiveButton("Ok",null)
  916. .show();
  917. }
  918. }
  919. });
  920. }
  921. }).start();
  922. }
  923. });
  924. listview.addView(commu_footer);
  925. listview.forceLayout();
  926. }
  927. // String value = obj.getString(key);
  928. // JSONArray array = obj.getJSONArray(key);
  929. // for(int i=0;i<array.length();i++){
  930. // JSONObject jsonobject = array.getJSONObject(i);
  931. // jsonobject.put("name", key);
  932. // jsonobject.put("exp", key+"="+jsonobject.getString("value"));
  933. // newArray.put(jsonobject);
  934. }
  935. // Iterator it = jsonObj.keys();
  936. // while (it.hasNext())
  937. // {
  938. //
  939. // }
  940. }
  941. catch (JSONException e)
  942. {
  943. // TODO Auto-generated catch block
  944. e.printStackTrace();
  945. }
  946. }
  947. private JSONObject getGroup(int group) {
  948. if (mContent != null) {
  949. JSONObject groupobj = mContent.optJSONObject("group" + group);
  950. return groupobj;
  951. }
  952. return null;
  953. }
  954. private boolean validateEmail(String email) {
  955. String emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
  956. return Pattern.matches(emailRegex,email);
  957. }
  958. @Override
  959. public void onClick(View v)
  960. {
  961. View view = ll_root.findViewById(control.get(v.getId()));
  962. ImageView expand_iv = v.findViewById(R.id.group_expand_indicator);
  963. if (view.getVisibility() == View.VISIBLE) {
  964. expand_iv.setImageResource(R.drawable.ic_expand_less);
  965. view.setVisibility(View.GONE);
  966. }
  967. else {
  968. expand_iv.setImageResource(R.drawable.ic_expand_more);
  969. view.setVisibility(View.VISIBLE);
  970. }
  971. }
  972. @Override
  973. public void onDestroy()
  974. {
  975. if (m_task != null)
  976. m_task.cancel(true);
  977. super.onDestroy();
  978. }
  979. @Override
  980. public void onActivityResult(int requestCode, int resultCode, Intent data)
  981. {
  982. // ((NewDetailActivity) getActivity()).showlogin = false;
  983. super.onActivityResult(requestCode, resultCode, data);
  984. if (requestCode == People_Pick_Code && data != null) {
  985. Uri contactData = data.getData();
  986. if (contactData == null) {
  987. return;
  988. }
  989. Cursor c = mContext.getContentResolver().query(contactData, null, null, null, null);
  990. if (c.moveToFirst()) {
  991. String contactId = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
  992. Cursor cursor = mContext.getContentResolver().query(
  993. ContactsContract.CommonDataKinds.Email.CONTENT_URI,
  994. new String[]{ContactsContract.CommonDataKinds.Email.DATA, ContactsContract.CommonDataKinds.Email.TYPE}, ContactsContract.Data.CONTACT_ID + "='" + contactId + "'", null, null);
  995. while(cursor.moveToNext()) {
  996. String email = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
  997. String emailType = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
  998. email = email.replace("\r\n",";");
  999. email = email.replace("\r",";");
  1000. email = email.replace("\n",";");
  1001. String[] emailArr = email.split(";");
  1002. for (int i = 0; i < emailArr.length; i++) {
  1003. email = emailArr[i];
  1004. if (email.length() > 0) {
  1005. if (emailType != null && Integer.valueOf(emailType) == ContactsContract.CommonDataKinds.Email.TYPE_WORK) {
  1006. appendContactEmail(email,mSelectContactPosition);
  1007. return;
  1008. }
  1009. }
  1010. }
  1011. }
  1012. }
  1013. mSelectContactPosition = -1;
  1014. }
  1015. }
  1016. @Override
  1017. public void onDetach()
  1018. {
  1019. if (m_task != null)
  1020. m_task.cancel(false);
  1021. super.onDetach();
  1022. }
  1023. class SearchTask extends AsyncTask<Void, Void, Boolean>
  1024. {
  1025. int errorcode;
  1026. @Override
  1027. protected Boolean doInBackground(Void... params)
  1028. {
  1029. Log.d("SearchTask", "doInBackground");
  1030. if (!Network.NetworkIsAvailable())
  1031. {
  1032. errorcode = Network.RESULT_NET_NOTAVAILABLE;
  1033. return false;
  1034. }
  1035. String jstr = Network.get_detail(getArguments());
  1036. if (jstr == null || jstr.length() <= 0)
  1037. {
  1038. // Log.d(TAG, "json is wrong");
  1039. errorcode = Network.RESULT_NET_ERROR;
  1040. return false;
  1041. }
  1042. // mdataFragment.put_result(jstr);
  1043. fragment_content = jstr;
  1044. NewDetailActivity activity = (NewDetailActivity) getActivity();
  1045. activity.save_content(getArguments().getString("action_type"), jstr);
  1046. errorcode = Network.RESULT_TRUE;
  1047. return true;
  1048. }
  1049. @Override
  1050. protected void onPostExecute(Boolean success)
  1051. {
  1052. Log.i("onPostExecute", "entry");
  1053. m_task = null;
  1054. showProgress(false);
  1055. // if (ApexTrackingApplication.get_authorization() == false)
  1056. // {
  1057. // if(((DetailActivity) getActivity()).showlogin == true)
  1058. // return;
  1059. // ((DetailActivity) getActivity()).showlogin = true;
  1060. // LinearLayout ll = (LinearLayout) ll_root
  1061. // .findViewById(R.id.ll_refresh);
  1062. // ll.setVisibility(View.VISIBLE);
  1063. // Toast toast = Toast.makeText(
  1064. // ApexTrackingApplication.get_instance(),
  1065. // getText(R.string.msg_net_passwordchangedremote) , Toast.LENGTH_LONG);
  1066. // toast.setGravity(Gravity.CENTER, 0, 0);
  1067. // toast.show();
  1068. // Intent i = new Intent();
  1069. // i.setClass(getActivity(), ApexActivity.class);
  1070. // startActivityForResult(i, REQUEST_LOGINACTIVITY);
  1071. // return;
  1072. // }
  1073. switch (errorcode)
  1074. {
  1075. case Network.RESULT_NET_NOTAVAILABLE:
  1076. {
  1077. Toast toast = Toast.makeText(
  1078. ApexTrackingApplication.get_instance(),
  1079. getText(R.string.msg_connection_none),
  1080. Toast.LENGTH_LONG);
  1081. toast.setGravity(Gravity.CENTER, 0, 0);
  1082. toast.show();
  1083. break;
  1084. }
  1085. case Network.RESULT_NET_ERROR:
  1086. {
  1087. Toast toast = Toast.makeText(
  1088. ApexTrackingApplication.get_instance(),
  1089. getText(R.string.msg_net_error), Toast.LENGTH_LONG);
  1090. toast.setGravity(Gravity.CENTER, 0, 0);
  1091. toast.show();
  1092. break;
  1093. }
  1094. case Network.RESULT_ERROR:
  1095. // case Network.RESULT_RESPONSE_NULL:
  1096. {
  1097. Toast toast = Toast.makeText(
  1098. ApexTrackingApplication.get_instance(),
  1099. getText(R.string.msg_net_resulterror) + ":"
  1100. + errorcode, Toast.LENGTH_LONG);
  1101. toast.setGravity(Gravity.CENTER, 0, 0);
  1102. toast.show();
  1103. break;
  1104. }
  1105. default:
  1106. break;
  1107. }
  1108. if (success)
  1109. {
  1110. LayoutInflater inflater = (LayoutInflater) ApexTrackingApplication
  1111. .get_instance().getSystemService(
  1112. Context.LAYOUT_INFLATER_SERVICE);
  1113. init(fragment_content, inflater/*
  1114. * getActivity().
  1115. * getLayoutInflater()
  1116. */);
  1117. }
  1118. else
  1119. {
  1120. LinearLayout ll = (LinearLayout) ll_root
  1121. .findViewById(R.id.ll_refresh);
  1122. ll.setVisibility(View.VISIBLE);
  1123. }
  1124. super.onPostExecute(success);
  1125. }
  1126. @Override
  1127. protected void onCancelled()
  1128. {
  1129. m_task = null;
  1130. showProgress(false);
  1131. }
  1132. }
  1133. private void showQuickLook(final String url) {
  1134. showProgressDialog("Please wait","Downloading...");
  1135. new Thread(new Runnable() {
  1136. @Override
  1137. public void run() {
  1138. String cacheDir = ApexTrackingApplication.getInstance().getExternalCacheDir().getAbsolutePath();//ApexTrackingApplication.getInstance().getDocumentDir();
  1139. final Bundle param = new Bundle();
  1140. // 下载文件
  1141. final File downloadFile = Network.downloadFile(param,url,cacheDir);
  1142. getActivity().runOnUiThread(new Runnable() {
  1143. @Override
  1144. public void run() {
  1145. progressDialog.dismiss();
  1146. if (downloadFile != null && downloadFile.exists()) {
  1147. String email = null,email_subject = null,email_content = null;
  1148. //此处需要新增保存文档的本地表
  1149. try {
  1150. email = mContent.getString("email");
  1151. email_subject = mContent.getString("email_subject");
  1152. email_content = mContent.getString("email_content");
  1153. } catch (JSONException e) {
  1154. e.printStackTrace();
  1155. }
  1156. // email=param.getString("email");
  1157. // email_subject=param.getString("email_subject");
  1158. // email_content=param.getString("email_content");
  1159. previewPDF(downloadFile.getAbsolutePath(),email,email_subject,email_content);
  1160. } else {
  1161. showAlert("Sorry,there is a wrong.");
  1162. }
  1163. }
  1164. });
  1165. }
  1166. }).start();
  1167. }
  1168. // public class DataFragment extends Fragment {
  1169. //
  1170. // String result = null;
  1171. //
  1172. // @Override
  1173. // public void onCreate(Bundle savedInstanceState) {
  1174. // setRetainInstance(true);
  1175. // super.onCreate(savedInstanceState);
  1176. // }
  1177. //
  1178. // public String get_result() {
  1179. // return result;
  1180. //
  1181. // }
  1182. //
  1183. // public void put_result(String s) {
  1184. // result = s;
  1185. // }
  1186. //
  1187. // }
  1188. public void showAlert(String msg) {
  1189. if (msg == null || msg.isEmpty()) {
  1190. return;
  1191. }
  1192. new android.support.v7.app.AlertDialog.Builder(mContext)
  1193. .setMessage(msg)
  1194. .show();
  1195. }
  1196. protected void previewPDF(String file,String email,String subject,String content) {
  1197. Intent myIntent = new Intent();
  1198. myIntent = new Intent(getActivity(), PDFPreviewActivity.class);
  1199. myIntent.putExtra("file",file);
  1200. myIntent.putExtra("iscache",true);
  1201. try {
  1202. JSONObject json = new JSONObject();
  1203. // email = "66666@qq.com";
  1204. // subject = "test subject";
  1205. // content = "test body";
  1206. if (email != null) {
  1207. json.put("email",email);
  1208. }
  1209. if (subject != null) {
  1210. json.put("subject",subject);
  1211. }
  1212. if (content != null) {
  1213. json.put("content",content);
  1214. }
  1215. myIntent.putExtra("email",json.toString());
  1216. } catch (JSONException e) {
  1217. e.printStackTrace();
  1218. }
  1219. startActivity(myIntent);
  1220. }
  1221. public void download(String url) {
  1222. final String download_url = url;
  1223. showQuickLook(url);
  1224. if(true)
  1225. return;
  1226. showProgressDialog("Please wait","Downloading...");
  1227. new Thread(new Runnable() {
  1228. @Override
  1229. public void run() {
  1230. // String cacheDir = ApexTrackingApplication.getInstance().getDocumentDir();
  1231. // 下载文件
  1232. final File downloadFile = Network.downloadFile(null,download_url,null);
  1233. getActivity().runOnUiThread(new Runnable() {
  1234. @Override
  1235. public void run() {
  1236. progressDialog.dismiss();
  1237. RAUtil.openFile(getActivity(),downloadFile);
  1238. }
  1239. });
  1240. }
  1241. }).start();
  1242. }
  1243. public class MyWebViewClient extends WebViewClient
  1244. {
  1245. // 如果页面中链接,如果希望点击链接继续在当前browser中响应,
  1246. // 而不是新开Android的系统browser中响应该链接,必须覆盖 webview的WebViewClient对象。
  1247. public boolean shouldOverviewUrlLoading(WebView view, String url)
  1248. {
  1249. Log.d("Web Client", "shouldOverviewUrlLoading: " + url);
  1250. // L.i("shouldOverviewUrlLoading");
  1251. view.loadUrl(url);
  1252. return true;
  1253. }
  1254. @Override
  1255. public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
  1256. Log.d("Web Client", "shouldOverrideUrlLoading: " + request);
  1257. return super.shouldOverrideUrlLoading(view, request);
  1258. }
  1259. public void onPageStarted(WebView view, String url, Bitmap favicon)
  1260. {
  1261. // L.i("onPageStarted");
  1262. // showProgress();
  1263. Log.d("Web Client", "onPageStarted: ");
  1264. }
  1265. public void onPageFinished(WebView view, String url)
  1266. {
  1267. // L.i("onPageFinished");
  1268. // closeProgress();
  1269. Log.d("Web Client", "onPageFinished: ");
  1270. }
  1271. public void onReceivedError(WebView view, int errorCode,
  1272. String description, String failingUrl)
  1273. {
  1274. // L.i("onReceivedError");
  1275. // closeProgress();
  1276. Log.d("Web Client", "onReceivedError: ");
  1277. }
  1278. @Override
  1279. public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
  1280. Log.d("Web Client", "shouldInterceptRequest: " + url);
  1281. if (url.startsWith("http") && url.contains("action_type=download_doc")) {
  1282. download(url);
  1283. String content = contentOfWebView(view);
  1284. WebResourceResponse response = new WebResourceResponse("text/html",
  1285. "utf-8",
  1286. new ByteArrayInputStream(content.getBytes()));
  1287. return response;
  1288. } else {
  1289. return super.shouldInterceptRequest(view,url);
  1290. }
  1291. }
  1292. String contentOfWebView(WebView webView) {
  1293. int i = (int)webView.getTag();
  1294. try {
  1295. JSONObject groupobj = mContent.getJSONObject("group" + i);
  1296. String content = groupobj.getString("content");
  1297. return content;
  1298. } catch (JSONException e) {
  1299. e.printStackTrace();
  1300. }
  1301. return null;
  1302. }
  1303. // @Override
  1304. // public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
  1305. // Log.d("Web Client", "shouldInterceptRequest: " + request);
  1306. //
  1307. // if (request.getUrl().toString().contains("action_type=download_doc")) {
  1308. // return null;
  1309. // } else {
  1310. // return super.shouldInterceptRequest(view,request);
  1311. // }
  1312. //
  1313. //
  1314. // }
  1315. }
  1316. private void appendContactEmail(String email,int group) {
  1317. try {
  1318. String groupKey = "group" + group;
  1319. JSONObject groupObj = mContent.getJSONObject(groupKey);
  1320. String groupType = groupObj.getString("_type");
  1321. if (groupType.equals("communication")) {
  1322. String oldCC = groupObj.optString("cc");
  1323. if (oldCC == null || oldCC.length() == 0) {
  1324. oldCC = email + ";";
  1325. } else {
  1326. if (oldCC.substring(oldCC.length() - 1).equals(";")) {
  1327. oldCC = oldCC + email + ";";
  1328. } else {
  1329. oldCC = oldCC + ";" + email + ";";
  1330. }
  1331. }
  1332. commContentChange(oldCC,group,0);
  1333. EditText ccTv = ll_root.findViewWithTag("group_" + group + "_cc");
  1334. if (ccTv != null) {
  1335. ccTv.setText(oldCC);
  1336. ccTv.requestFocus();
  1337. ccTv.setSelection(oldCC.length());
  1338. }
  1339. }
  1340. } catch (JSONException e) {
  1341. e.printStackTrace();
  1342. }
  1343. }
  1344. private void commContentChange(String content,int group,int child) {
  1345. try {
  1346. String groupKey = "group" + group;
  1347. JSONObject groupObj = mContent.getJSONObject(groupKey);
  1348. String groupType = groupObj.getString("_type");
  1349. if (groupType.equals("communication")) {
  1350. if (child == 0) {
  1351. groupObj.put("cc",content);
  1352. } else if (child == 1) {
  1353. groupObj.put("edit_content",content);
  1354. }
  1355. mContent.put(groupKey,groupObj);
  1356. }
  1357. } catch (JSONException e) {
  1358. e.printStackTrace();
  1359. }
  1360. }
  1361. public class TextFieldTextWatcher implements TextWatcher {
  1362. Context mCtx;
  1363. int group;
  1364. int child;
  1365. EditText textView;
  1366. public TextFieldTextWatcher(Context ctx,EditText textView,int group,int child) {
  1367. this.mCtx = ctx;
  1368. this.textView = textView;
  1369. this.group = group;
  1370. this.child = child;
  1371. }
  1372. String origin_text;
  1373. String string;
  1374. int start_position;
  1375. int change_length; // 修改原文长度
  1376. int new_string_length;
  1377. /**
  1378. * s 改变前的内容
  1379. * start 增加内容前光标位置,删除内容后光标位置 (起始位置)
  1380. * count 选中s中的内容长度(发生改变的原内容长度),未选中为0
  1381. * after 新添加的内容长度,删除为0
  1382. * */
  1383. @Override
  1384. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  1385. // Log.d("TextChange", "before Text Changed: " + s + " Start: " + start + " Count: " + count + " After: " + after);
  1386. origin_text = s.toString();
  1387. start_position = start;
  1388. change_length = count;
  1389. new_string_length = after;
  1390. }
  1391. /**
  1392. * s 改变后的内容
  1393. * start 增加内容前光标位置,删除内容后光标位置 (起始位置)
  1394. * before 选中s中的内容长度(发生改变的原内容长度),未选中为0
  1395. * count 增加内容长度,删除内容为0
  1396. * */
  1397. @Override
  1398. public void onTextChanged(CharSequence s, int start, int before, int count) {
  1399. // Log.d("TextChange", "on Text Changed: " + s + " Start: " + start + " Before: " + before + " Count: " + count);
  1400. }
  1401. @Override
  1402. public void afterTextChanged(Editable s) {
  1403. commContentChange(s.toString(),group,child);
  1404. }
  1405. }
  1406. }