Преглед изворни кода

1.修改Android Apex Mobile导入依赖RAUtil,替换AES、Network实现。

Pen Li пре 7 година
родитељ
комит
2fd0846052
25 измењених фајлова са 1831 додато и 777 уклоњено
  1. 4 4
      ApexDrivers/RAUtilsLibrary/build.gradle
  2. 2 2
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/preview/RAPDFPreviewActivity.java
  3. 5 8
      ApexDrivers/apexmobile/build.gradle
  4. BIN
      ApexDrivers/apexmobile/libs/bcprov-jdk15on-157.jar
  5. BIN
      ApexDrivers/apexmobile/libs/core-2.3.0.jar
  6. BIN
      ApexDrivers/apexmobile/libs/httpmime-4.1.1.jar
  7. 4 2
      ApexDrivers/apexmobile/src/main/AndroidManifest.xml
  8. 1 3
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/SearchListActivity.java
  9. 590 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultActivity.java
  10. 176 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultAdapter.java
  11. 497 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultPresenter.java
  12. 53 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/cell/ApexResultAdditionView.java
  13. 70 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/cell/ApexResultDocumentCell.java
  14. 165 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/cell/ApexResultShipCell.java
  15. 49 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/model/ApexResultBaseModel.java
  16. 36 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/model/ApexResultDocumentModel.java
  17. 113 0
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/model/ApexResultShipModel.java
  18. 39 135
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/pdf/PDFPreviewActivity.java
  19. 1 1
      ApexDrivers/apexmobile/src/main/java/com/usai/apex/saved/SavedSearchFragment.java
  20. 3 213
      ApexDrivers/apexmobile/src/main/java/com/usai/util/AES.java
  21. 11 397
      ApexDrivers/apexmobile/src/main/java/com/usai/util/Network.java
  22. 1 1
      ApexDrivers/apexmobile/src/main/res/layout/activity_apex_result.xml
  23. 2 2
      ApexDrivers/apexmobile/src/main/res/layout/apex_result_addition_view.xml
  24. 4 4
      ApexDrivers/apexmobile/src/main/res/layout/apex_result_document_cell.xml
  25. 5 5
      ApexDrivers/apexmobile/src/main/res/layout/apex_result_ship_cell.xml

+ 4 - 4
ApexDrivers/RAUtilsLibrary/build.gradle

@@ -49,11 +49,11 @@ dependencies {
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'com.android.support.test:runner:1.0.2'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
-    implementation files('libs/bcprov-jdk15on-157.jar')
-    implementation files('libs/httpmime-4.1.1.jar')
+    api files('libs/bcprov-jdk15on-157.jar')
+    api files('libs/httpmime-4.1.1.jar')
     api 'com.google.android.gms:play-services-location:16.0.0'
-    implementation files('libs/core-2.3.0.jar')
-    implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
+    api files('libs/core-2.3.0.jar')
+    api 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
 }
 
 

+ 2 - 2
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/preview/RAPDFPreviewActivity.java

@@ -205,13 +205,13 @@ public class RAPDFPreviewActivity extends AppCompatActivity implements OnPageCha
     }
 
     @Override
-    protected void onDestroy()
+    public void onDestroy()
     {
         super.onDestroy();
     }
 
     @Override
-    protected void onCreate(Bundle savedInstanceState) {
+    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.pdf_preview_activity);
 

+ 5 - 8
ApexDrivers/apexmobile/build.gradle

@@ -44,22 +44,19 @@ android {
 
 dependencies {
     //    compile 'com.android.support:support-v4:19.1.0'
-
-    implementation files('libs/bcprov-jdk15on-157.jar')
     api 'com.android.support:appcompat-v7:26.1.0'
     api 'com.android.support:support-v4:26.1.0'
     api 'com.android.support.constraint:constraint-layout:1.1.3'
     api 'com.android.support:design:26.1.0'
     //    compile 'com.android.support:recyclerview-v7:26.1.0'
-//    compile 'com.google.android.gms:play-services:11.0.4'
-    api 'com.google.android.gms:play-services-maps:11.4.2'
-    api 'com.google.android.gms:play-services-location:11.4.2'
+    //    compile 'com.google.android.gms:play-services:11.0.4'
+    api 'com.google.android.gms:play-services-maps:16.0.0'
+    //    api 'com.google.android.gms:play-services-location:11.4.2'
     //    compile files('libs/baidumapapi_base_v3_7_1.jar')
     //    compile files('libs/baidumapapi_map_v3_7_1.jar')
-    implementation files('libs/httpmime-4.1.1.jar')
-    implementation files('libs/core-2.3.0.jar')
-    api 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
+    //    api 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
     implementation files('libs/BaiduLBS_Android.jar')
+    implementation project(path: ':RAUtilsLibrary')
 }
 android {
     useLibrary 'org.apache.http.legacy'

BIN
ApexDrivers/apexmobile/libs/bcprov-jdk15on-157.jar


BIN
ApexDrivers/apexmobile/libs/core-2.3.0.jar


BIN
ApexDrivers/apexmobile/libs/httpmime-4.1.1.jar


+ 4 - 2
ApexDrivers/apexmobile/src/main/AndroidManifest.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:tools="http://schemas.android.com/tools"
           package="com.usai.apex"
           android:versionCode="17"
           android:versionName="A180723"> <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
@@ -98,7 +99,8 @@
         android:icon="@drawable/ic_launcher"
         android:label="@string/app_name"
         android:screenOrientation="portrait"
-        android:theme="@style/FixedActionbarTheme">
+        android:theme="@style/FixedActionbarTheme"
+        tools:replace="android:theme">
         <provider
             android:name="android.support.v4.content.FileProvider"
             android:authorities="com.usai.apex.fileprovider"
@@ -346,7 +348,7 @@
             android:name=".mainframe.NewDetailActivity"
             android:screenOrientation="portrait"
             android:theme="@style/DetailActionbarTheme"/>
-        <activity android:name=".apexResult.ApexResultActivity"
+        <activity android:name=".apexresult.ApexResultActivity"
                   android:theme="@style/ResultActionbarTheme">
         </activity>
 

+ 1 - 3
ApexDrivers/apexmobile/src/main/java/com/usai/apex/SearchListActivity.java

@@ -12,7 +12,6 @@ import android.os.Bundle;
 import android.support.constraint.ConstraintLayout;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.SearchView;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.TextUtils;
@@ -36,8 +35,7 @@ import android.widget.LinearLayout;
 import android.widget.Spinner;
 import android.widget.TextView;
 
-import com.usai.apex.Result.AMResultActivity;
-import com.usai.apex.apexResult.ApexResultActivity;
+import com.usai.apex.apexresult.ApexResultActivity;
 import com.usai.util.Network;
 import com.usai.util.dbUtil;
 

+ 590 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultActivity.java

@@ -0,0 +1,590 @@
+package com.usai.apex.apexresult;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.graphics.Color;
+import android.support.v4.widget.SwipeRefreshLayout;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.Gravity;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AbsListView;
+import android.widget.AdapterView;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import com.usai.apex.ApexTrackingApplication;
+import com.usai.apex.CustomizeFieldsActivity;
+import com.usai.apex.R;
+import com.usai.apex.actionSheet.ActionSheet;
+import com.usai.apex.mainframe.NewDetailActivity;
+import com.usai.apex.pdf.PDFPreviewActivity;
+import com.usai.util.Network;
+import com.usai.util.commonUtil;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.Iterator;
+
+
+public class ApexResultActivity extends AppCompatActivity implements ApexResultPresenter.ApexResultProtocol {
+
+    // region Build
+
+    private static final String ParametersKey = "Apex_Result_Parameters_Key";
+
+    public static void startResultActivity(Activity activity, Bundle params) {
+
+        if (activity != null) {
+
+            Intent intent = new Intent(activity, ApexResultActivity.class);
+            if (params != null) {
+                intent.putExtra(ParametersKey, params);
+            }
+            activity.startActivity(intent);
+        }
+
+    }
+
+    // endregion
+
+    // region Request Code
+
+    private static class RequestCode {
+
+        static final int Field_Setting = 1010;
+    }
+
+    // endregion
+
+    // region Property
+
+    private Context mCtx = this;
+
+    private ListView mListView;
+    private SwipeRefreshLayout mRefreshLayout;
+    private ProgressBar mProgressBar;
+    private TextView mListFooterView;
+
+    private ScrollListener mScrollListener;
+
+    private ApexResultPresenter mPresenter;
+    private ApexResultAdapter mAdapter;
+    private Bundle mParams;
+
+    // endregion
+
+    // region Override
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_apex_result);
+
+        //
+        if (savedInstanceState != null) {
+            mParams = savedInstanceState.getBundle(ParametersKey);
+        } else {
+            mParams = getIntent().getBundleExtra(ParametersKey);
+        }
+        if (mParams == null) {
+            mParams = new Bundle();
+        }
+
+        setup();
+
+        if (savedInstanceState != null) {
+            mPresenter.onRestoreInstanceState(savedInstanceState);
+        } else {
+            mPresenter.loadData();
+        }
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+
+        if (item.getItemId() == android.R.id.home) {
+            finish();
+            return  true;
+        } else if (item.getItemId() == R.id.apex_result_menu) {
+            menuItemClick();
+            return true;
+        }
+
+        return super.onOptionsItemSelected(item);
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        getMenuInflater().inflate(R.menu.apex_result_menu, menu);
+        return true;
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+
+        outState.putBundle(ParametersKey, mParams);
+        mPresenter.onSaveInstanceState(outState);
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+
+        if (requestCode == RequestCode.Field_Setting) {
+            mPresenter.dirty = true;
+            loadData();
+        }
+    }
+
+    // endregion
+
+    // region Setting
+
+    private void setup() {
+
+        mPresenter = new ApexResultPresenter(this, mParams);
+        mAdapter = new ApexResultAdapter(mCtx, mPresenter);
+
+        setupActionBar();
+        setupRefreshLayout();
+        setupListView();
+
+        mProgressBar = findViewById(R.id.apex_result_progress_bar);
+    }
+
+    private void setupListView() {
+
+        mListView = findViewById(R.id.apex_result_list_view);
+        mListView.setAdapter(mAdapter);
+
+        setupListFooterView();
+        AbsListView.LayoutParams footerLayoutParams = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
+        mListFooterView.setLayoutParams(footerLayoutParams);
+        mListView.addFooterView(mListFooterView);
+
+        mScrollListener = new ScrollListener();
+        mListView.setOnScrollListener(mScrollListener);
+
+        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                clickItemCell(view, position);
+            }
+        });
+    }
+
+    private void setupListFooterView() {
+        mListFooterView = new TextView(mCtx);
+        mListFooterView.setBackgroundColor(Color.WHITE);
+        mListFooterView.setGravity(Gravity.CENTER);
+        mListFooterView.setText("loading more...");
+        mListFooterView.setTextSize(commonUtil.sp2px(mCtx,8));
+        mListFooterView.setVisibility(View.INVISIBLE);
+    }
+
+    private void setupRefreshLayout() {
+
+        mRefreshLayout = findViewById(R.id.apex_result_refresh_layout);
+        mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+            @Override
+            public void onRefresh() {
+                refresh();
+            }
+        });
+    }
+
+
+    private void setupActionBar() {
+
+        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
+        if(actionBar != null){
+            actionBar.setHomeButtonEnabled(true);
+            actionBar.setDisplayHomeAsUpEnabled(true);
+        }
+    }
+
+    // endregion
+
+    // region Action
+    private void loadData() {
+        mPresenter.loadData();
+    }
+
+    private void refresh() {
+        mPresenter.refreshData();
+    }
+
+    private void loadMore() {
+        mPresenter.loadMoreData();
+    }
+
+    private void clickItemCell(View cell, int position) {
+
+        handleRowAction(position);
+    }
+
+    // endregion
+
+    // region ProgressBar
+
+    public void showProgressBar() {
+        mProgressBar.setVisibility(View.VISIBLE);
+    }
+
+    public void dismissProgressBar() {
+        mProgressBar.setVisibility(View.GONE);
+    }
+
+    // endregion
+
+    // region Alert
+
+    private void showAlertMessage(String msg) {
+        new AlertDialog.Builder(mCtx)
+                .setTitle("Warning")
+                .setMessage(msg)
+                .setPositiveButton("OK",null)
+                .show();
+    }
+
+    // endregion
+
+    // region Presenter Delegate
+    @Override
+    public void onStartLoading() {
+        isLoading = true;
+        showProgressBar();
+    }
+
+    @Override
+    public void onStopLoading() {
+        if (mRefreshLayout.isRefreshing()) {
+            mRefreshLayout.setRefreshing(false);
+        }
+        mListFooterView.setVisibility(View.INVISIBLE);
+        dismissProgressBar();
+
+        isLoading = false;
+    }
+
+    @Override
+    public void onSuccess(String title) {
+        setTitle(title);
+        mAdapter.notifyDataSetChanged();
+    }
+
+    @Override
+    public void onFailed(String errMsg) {
+        if (errMsg == null) {
+            errMsg = "Sorry, something is wrong.";
+        }
+        showAlertMessage(errMsg);
+    }
+
+    @Override
+    public void onNoMoreData() {
+        showAlertMessage("No More Data");
+    }
+
+    @Override
+    public void onDownloadFile(String path, Bundle params) {
+
+        String email = params.getString("email");
+        String email_subject = params.getString("email_subject");
+        String email_content = params.getString("email_content");
+
+        previewPDF(path, email, email_subject, email_content);
+    }
+    // endregion
+
+    // region Menu Action
+
+    private void menuItemClick() {
+
+        ActionSheet actionSheet = new ActionSheet(mCtx);
+
+        actionSheet.addAction("Setting", ActionSheet.ActionType.ActionTypeDefault, new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                showFieldsSetting();
+            }
+        });
+
+        actionSheet.addAction("Save", ActionSheet.ActionType.ActionTypeDefault, new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                saveSearchParameters();
+            }
+        });
+
+        actionSheet.addAction("Cancel", ActionSheet.ActionType.ACtionTypeCancel, new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+
+            }
+        });
+
+        actionSheet.show();
+
+    }
+
+    private void saveSearchParameters() {
+
+        final View edit = new EditText(mCtx);
+        new android.app.AlertDialog.Builder(mCtx)
+                .setIconAttribute(android.R.attr.alertDialogIcon)
+                .setTitle(R.string.str_createname)
+                .setView(edit)
+                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog, int whichButton) {
+
+                                String name = ((EditText) edit).getText().toString();
+                                if(TextUtils.isEmpty(name))
+                                {
+                                    new android.app.AlertDialog.Builder(mCtx)
+                                            .setTitle("Warning")
+                                            .setMessage("Name can not be empty.")
+                                            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                                                @Override
+                                                public void onClick(DialogInterface dialog, int which) {
+
+                                                }
+                                            })
+                                            .show();
+                                    return;
+                                }
+
+                                mPresenter.saveSearchParametersWithName(getIntent().toUri(0), name);
+
+                            }
+                        })
+                .setNegativeButton(android.R.string.cancel, null)
+                .create()
+                .show();
+
+    }
+
+    private void showFieldsSetting() {
+
+        Intent intent = new Intent();
+        intent.setClass(this, CustomizeFieldsActivity.class);
+        intent.putExtra("user", ApexTrackingApplication.get_user());
+        intent.putExtra("function_name", mParams.getString("module_name"));
+        intent.putExtra("behavior", Network.BEHAVIOR_RESULT);
+        startActivityForResult(intent,RequestCode.Field_Setting);
+    }
+
+    // endregion
+
+    // region Scroll Listener
+
+    private boolean isLoading = false;
+    private class ScrollListener implements AbsListView.OnScrollListener {
+
+        private int last_index, total_index;
+
+        @Override
+        public void onScrollStateChanged(AbsListView view, int scrollState) {
+            if (last_index == total_index && (scrollState == SCROLL_STATE_IDLE)) {
+                if (!isLoading) {
+
+                    mListFooterView.setVisibility(View.VISIBLE);
+                    loadMore();
+                }
+            }
+        }
+
+        @Override
+        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+            last_index = firstVisibleItem + visibleItemCount;
+            total_index = totalItemCount;
+        }
+    }
+
+    // endregion
+
+    // region Row Action
+
+    private Bundle paramsForIndex(int position, JSONObject action) {
+
+        JSONArray parameters = mPresenter.rowActionParametersForIndex(position);
+        Bundle params = new Bundle();
+        JSONObject actionParams = action.optJSONObject("params");
+        if (actionParams != null) {
+
+            Iterator<String> keys = actionParams.keys();
+            while (keys.hasNext()) {
+                String key = keys.next();
+                try {
+
+                    int idx = actionParams.getInt(key);
+                    String value = parameters.getString(idx);
+                    params.putString(key, value);
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+        return params;
+    }
+
+    private void handleRowAction(int position) {
+
+        JSONArray rowActions = mPresenter.getRowActions();
+        if (rowActions != null) {
+
+            if (rowActions.length() == 1) {
+
+                JSONObject action = rowActions.optJSONObject(0);
+                if (action != null) {
+
+                    Bundle params = paramsForIndex(position, action);
+                    String module = action.optString("module");
+                    if (module != null) {
+                        if (module.equals("quick_look")) {
+
+                            showQuickLookForActionWithParams(action, params);
+
+                        } else if (module.equals("detail")) {
+
+                            showDetailForActionWithParams(action, params);
+                        }
+                    }
+                }
+
+            } else {
+
+                ActionSheet actionSheet = new ActionSheet(mCtx);
+
+                for (int i = 0; i < rowActions.length(); i++) {
+
+                    try {
+
+                        final JSONObject json = rowActions.getJSONObject(i);
+                        final Bundle params = paramsForIndex(position, json);
+
+                        String title = json.getString("title");
+                        final String module = json.getString("module");
+
+                        actionSheet.addAction(title, ActionSheet.ActionType.ActionTypeDefault, new View.OnClickListener() {
+                            @Override
+                            public void onClick(View v) {
+
+                                if (module.equals("quick_look")) {
+
+                                    showQuickLookForActionWithParams(json, params);
+
+                                } else if (module.equals("detail")) {
+
+                                    showDetailForActionWithParams(json, params);
+                                }
+
+                            }
+                        });
+
+                    } catch (JSONException e) {
+                        e.printStackTrace();
+                    }
+
+                } // for
+
+                actionSheet.addAction("Cancel", ActionSheet.ActionType.ACtionTypeCancel, new View.OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+
+                    }
+                });
+
+                actionSheet.show();
+
+            }
+        }
+    }
+
+    private void showQuickLookForActionWithParams(JSONObject action, Bundle params) {
+
+        try {
+
+            String url = action.getString("url");
+            mPresenter.downloadFile(url, params);
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void showDetailForActionWithParams(JSONObject action, Bundle params) {
+
+        String module_name = mPresenter.getParams().getString("module_name");
+        String detail_id = params.getString("id");
+        JSONArray actions = mPresenter.getActions();
+        if (actions == null) {
+            actions = new JSONArray();
+        }
+
+        Intent intent = new Intent(mCtx, NewDetailActivity.class);
+        intent.putExtra("function_name", module_name);
+        intent.putExtra("actions_count", actions.length());
+        intent.putExtra("_id",detail_id);
+
+        for (int i = 0; i < actions.length(); i++) {
+            try {
+                String name = actions.getString(i);
+                intent.putExtra("action" + i, name);
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+        }
+
+        startActivity(intent);
+    }
+
+    // endregion
+
+    // region PDF
+
+    private void previewPDF(String file,String email,String subject,String content) {
+
+        Intent myIntent = new Intent(mCtx, PDFPreviewActivity.class);
+        myIntent.putExtra("file",file);
+        myIntent.putExtra("iscache",true);
+
+        try {
+            JSONObject json = new JSONObject();
+
+            if (email != null) {
+                json.put("email",email);
+            }
+            if (subject != null) {
+                json.put("subject",subject);
+            }
+            if (content != null) {
+                json.put("content",content);
+            }
+            myIntent.putExtra("email",json.toString());
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+
+        startActivity(myIntent);
+    }
+
+    // endregion
+}

+ 176 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultAdapter.java

@@ -0,0 +1,176 @@
+package com.usai.apex.apexresult;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+
+import com.usai.apex.apexresult.cell.ApexResultDocumentCell;
+import com.usai.apex.apexresult.cell.ApexResultShipCell;
+import com.usai.apex.apexresult.model.ApexResultBaseModel;
+import com.usai.apex.apexresult.model.ApexResultDocumentModel;
+import com.usai.apex.apexresult.model.ApexResultShipModel;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+
+public class ApexResultAdapter extends BaseAdapter {
+
+    // region DataSource
+    public static interface ApexResultAdapterDataSource {
+
+        int numberOfResultItem();
+        ApexResultBaseModel resultModelForIndex(int index);
+    }
+    // endregion
+
+    // region Initial
+    private WeakReference<Context> mWeakContext;
+    private WeakReference<ApexResultAdapterDataSource> mWeakDataSource;
+
+    public ApexResultAdapter(Context context, ApexResultAdapterDataSource dataSource) {
+        if (context == null) {
+            mWeakContext = null;
+        } else {
+            mWeakContext = new WeakReference<>(context);
+        }
+
+        if (dataSource == null) {
+            mWeakDataSource = null;
+        } else {
+            mWeakDataSource = new WeakReference<>(dataSource);
+        }
+    }
+    // endregion
+
+    // region Getter
+
+    private Context getContext() {
+        if (mWeakContext == null) {
+            return null;
+        }
+        return mWeakContext.get();
+    }
+
+    private ApexResultAdapterDataSource getDataSource() {
+        if (mWeakDataSource == null) {
+            return null;
+        }
+        return mWeakDataSource.get();
+    }
+
+    // endregion
+
+    // region Override
+
+    @Override
+    public int getCount() {
+        ApexResultAdapterDataSource dataSource = getDataSource();
+        if (dataSource != null) {
+            return dataSource.numberOfResultItem();
+        }
+        return 0;
+    }
+
+    @Override
+    public Object getItem(int position) {
+        ApexResultAdapterDataSource dataSource = getDataSource();
+        if (dataSource != null) {
+            return dataSource.resultModelForIndex(position);
+        }
+        return null;
+    }
+
+    @Override
+    public boolean hasStableIds() {
+        return true;
+    }
+
+    @Override
+    public long getItemId(int position) {
+        return position;
+    }
+
+    @Override
+    public int getViewTypeCount() {
+        return 2;
+    }
+
+    @Override
+    public int getItemViewType(int position) {
+        ApexResultBaseModel model = (ApexResultBaseModel)getItem(position);
+        return model.type;
+    }
+
+    @Override
+    public View getView(int position, View convertView, ViewGroup parent) {
+
+        Context context = getContext();
+        if (context != null) {
+
+            ApexResultBaseModel model = (ApexResultBaseModel)getItem(position);
+            if (model.type == ApexResultBaseModel.ApexResultType.APEX_RESULT_TYPE_SHIP.ordinal()) {
+
+                ApexResultShipModel shipModel = (ApexResultShipModel)model;
+                ApexResultShipCell cell = dequeueShipCell(context, convertView);
+                cell.prepareReuse();
+                cell.setTitle(shipModel.title).setDetail(shipModel.detail).setIcon(shipModel.icon).setPort(shipModel.port).setTime(shipModel.date).setDescription(shipModel.desc);
+                cell.setTransportStage(shipModel.transport_stage);
+
+                ArrayList<ApexResultShipModel.ApexResultAddition> additions = shipModel.getAddition();
+                if (additions != null && additions.size() > 0) {
+                    for (ApexResultShipModel.ApexResultAddition addition : additions) {
+                        cell.addAddition(addition.name, addition.value);
+                    }
+                }
+
+                return cell;
+
+            } else if (model.type == ApexResultBaseModel.ApexResultType.APEX_RESULT_TYPE_DOCUMENT.ordinal()) {
+
+                ApexResultDocumentModel documentModel = (ApexResultDocumentModel)model;
+                ApexResultDocumentCell cell = dequeueDocumentCell(context, convertView);
+                cell.prepareReuse();
+                cell.setFileName(documentModel.fileName).setFileType(documentModel.fileType).setFileDescription(documentModel.fileDesc);
+
+                return cell;
+            }
+
+            return new View(context);
+        }
+        return null;
+    }
+
+    // endregion
+
+    // region Configure Cell
+
+    private ApexResultShipCell dequeueShipCell(Context context, View convertView) {
+
+        ApexResultShipCell cell = null;
+
+        if (convertView == null) {
+            cell = ApexResultShipCell.makeShipCell(context);
+        } else {
+            cell = (ApexResultShipCell)convertView;
+        }
+
+        return cell;
+    }
+
+    private ApexResultDocumentCell dequeueDocumentCell(Context context, View convertView) {
+
+        ApexResultDocumentCell cell = null;
+
+        if (convertView == null) {
+            cell = ApexResultDocumentCell.makeDocumentCell(context);
+        } else {
+            cell = (ApexResultDocumentCell)convertView;
+        }
+
+        return cell;
+    }
+
+    // endregion
+
+}

+ 497 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultPresenter.java

@@ -0,0 +1,497 @@
+package com.usai.apex.apexresult;
+
+import android.os.Bundle;
+import android.text.TextUtils;
+
+import com.usai.apex.ApexTrackingApplication;
+import com.usai.apex.apexresult.model.ApexResultBaseModel;
+import com.usai.apex.apexresult.model.ApexResultDocumentModel;
+import com.usai.apex.apexresult.model.ApexResultShipModel;
+import com.usai.apex.operationQueue.OperationQueue;
+import com.usai.util.Network;
+import com.usai.util.RAUtil;
+
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+
+public class ApexResultPresenter implements ApexResultAdapter.ApexResultAdapterDataSource {
+
+    // region Protocol
+    public static interface ApexResultProtocol {
+
+        void onStartLoading();
+        void onStopLoading();
+        void onSuccess(String title);
+        void onFailed(String errMsg);
+        void onNoMoreData();
+        void onDownloadFile(String path, Bundle params);
+
+    }
+    // endregion
+
+    // region Enum
+
+    private enum ApexResultFetchDataType {
+        APEX_RESULT_FETCH_DATA_TYPE_INITIAL,
+        APEX_RESULT_FETCH_DATA_TYPE_REFRESH,
+        APEX_RESULT_FETCH_DATA_TYPE_LOAD_MORE
+    }
+
+    // endregion
+
+    // region Initial
+
+    private WeakReference<ApexResultProtocol> mWeakDelegate;
+    private Bundle mParams;
+    private String mFields;
+    private int offset = 0;
+    private static final int detal = 20;
+    private ArrayList<ApexResultBaseModel> mDataArray;
+    private JSONArray rowActions;
+    private JSONArray actions;
+    public boolean dirty = true;
+
+    public ApexResultPresenter(ApexResultProtocol delegate, Bundle params) {
+        if (delegate == null) {
+            mWeakDelegate = null;
+        } else {
+            mWeakDelegate = new WeakReference<>(delegate);
+        }
+        if (params == null) {
+            mParams = new Bundle();
+        } else {
+            mParams = params;
+        }
+
+        if (mParams.containsKey("columns")) {
+
+            dirty = false;
+        } else {
+            dirty = true;
+        }
+    }
+    // endregion
+
+    // region Save Instance
+
+    private static final String Data_Array_Key = "Data_Array_Key";
+    private static final String Offset_Key = "Offset_Key";
+    private static final String Row_Actions_key = "Row_Actions_Key";
+    private static final String Actions_Key = "Actions_Key";
+    private static final String Dirty_Key = "Dirty_Key";
+    private static final String Display_Fields_Key = "Display_Fields_Key";
+
+    public void onSaveInstanceState(Bundle outState) {
+        if (outState != null) {
+
+            outState.putInt(Offset_Key, offset);
+
+            String dataStr = prepareSaveData();
+            if (dataStr != null) {
+                outState.putString(Data_Array_Key, dataStr);
+            }
+
+            if (rowActions != null) {
+                outState.putString(Row_Actions_key, rowActions.toString());
+            }
+
+            if (actions != null) {
+                outState.putString(Actions_Key, actions.toString());
+            }
+
+            outState.putBoolean(Dirty_Key, dirty);
+            if (mFields != null) {
+                outState.putString(Display_Fields_Key, mFields);
+            }
+        }
+    }
+
+    public void onRestoreInstanceState(Bundle savedInstanceState) {
+        if (savedInstanceState != null) {
+
+            offset = savedInstanceState.getInt(Offset_Key);
+
+            String dataStr = savedInstanceState.getString(Data_Array_Key);
+            prepareRestoreData(dataStr);
+
+            try {
+                String js = savedInstanceState.getString(Row_Actions_key);
+                if (js != null) {
+                    rowActions = new JSONArray(js);
+                }
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+
+            try {
+                String js = savedInstanceState.getString(Actions_Key);
+                if (js != null) {
+                    actions = new JSONArray(js);
+                }
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+
+            mFields = savedInstanceState.getString(Display_Fields_Key);
+            dirty = savedInstanceState.getBoolean(Dirty_Key);
+        }
+    }
+
+    private String prepareSaveData() {
+
+        if (mDataArray != null) {
+
+            JSONArray jsonArray = new JSONArray();
+
+            for (ApexResultBaseModel model : mDataArray) {
+                JSONObject item = model.toJson();
+                jsonArray.put(item);
+            }
+
+            return jsonArray.toString();
+        }
+
+        return null;
+    }
+
+    private void prepareRestoreData(String jsonStr) {
+
+        if (jsonStr != null) {
+
+            try {
+
+                JSONArray jsonArray = new JSONArray(jsonStr);
+
+                ArrayList<ApexResultBaseModel> models = new ArrayList<>();
+                for (int i = 0; i < jsonArray.length(); i++) {
+                    JSONObject item = jsonArray.optJSONObject(i);
+                    if (item != null) {
+                        ApexResultBaseModel model = makeModel(item);
+                        if (model != null) {
+                            models.add(model);
+                        }
+                    }
+                }
+                mDataArray = models;
+
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+
+        }
+    }
+
+    // endregion
+
+    // region Getter
+
+    private ApexResultProtocol getDelegate() {
+        if (mWeakDelegate == null) {
+            return null;
+        }
+        return mWeakDelegate.get();
+    }
+
+    public int dataCount() {
+        if (mDataArray == null) {
+            return 0;
+        }
+        return mDataArray.size();
+    }
+
+    public ApexResultBaseModel modelAtIndex(int index) {
+        if (index >= dataCount()) {
+            return null;
+        }
+        return mDataArray.get(index);
+    }
+
+    public JSONArray rowActionParametersForIndex(int position) {
+        ApexResultBaseModel model = modelAtIndex(position);
+        if (model != null) {
+            return model.rowActionParameters;
+        }
+        return null;
+    }
+
+    public JSONArray getRowActions() {
+        return rowActions;
+    }
+
+    public JSONArray getActions() {
+        return actions;
+    }
+
+    public Bundle getParams() {
+        return mParams;
+    }
+
+    // endregion
+
+    // region DataSource
+
+    @Override
+    public int numberOfResultItem() {
+        return dataCount();
+    }
+
+    @Override
+    public ApexResultBaseModel resultModelForIndex(int index) {
+        return modelAtIndex(index);
+    }
+
+    // endregion
+
+    // region Private
+
+    private ApexResultBaseModel makeModel(JSONObject item) {
+        if (item != null) {
+            int type = item.optInt("type", -1);
+            if (type == ApexResultBaseModel.ApexResultType.APEX_RESULT_TYPE_SHIP.ordinal()) {
+
+                ApexResultShipModel model = new ApexResultShipModel();
+                model.setValuesForKeysWithJSON(item);
+                return model;
+            } else if (type == ApexResultBaseModel.ApexResultType.APEX_RESULT_TYPE_DOCUMENT.ordinal()) {
+
+                ApexResultDocumentModel model = new ApexResultDocumentModel();
+                model.setValuesForKeysWithJSON(item);
+                return model;
+            }
+        }
+        return null;
+    }
+
+    // endregion
+
+    // region Data
+
+    private void loadData(final ApexResultFetchDataType option) {
+
+        if (getDelegate() != null) {
+            getDelegate().onStartLoading();
+        }
+
+        if (mFields == null) {
+            mFields = "";
+        }
+
+
+        OperationQueue.sharedQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
+            @Override
+            public Object operationDoInBackground() {
+
+                Bundle params = (Bundle) mParams.clone();
+                params.putInt("offset", offset);
+                params.putInt("limit", detal);
+                params.putString("columns", mFields);
+                JSONObject json = Network.fetchResult(params);
+
+                return json;
+            }
+        }, new OperationQueue.OperationCompletionCallBack() {
+            @Override
+            public void operationCompletion(Object object) {
+
+                JSONObject json = (JSONObject)object;
+                int result = Network.RESULT_FALSE;
+                if (json != null) {
+                    result = json.optInt("result", Network.RESULT_FALSE);
+                }
+
+                if (getDelegate() != null) {
+                    getDelegate().onStopLoading();
+                }
+
+                if (result == Network.RESULT_TRUE) {
+
+                    ArrayList<ApexResultBaseModel> models = new ArrayList<>();
+                    if (option == ApexResultFetchDataType.APEX_RESULT_FETCH_DATA_TYPE_LOAD_MORE && mDataArray != null && mDataArray.size() > 0) {
+                        models.addAll(mDataArray);
+                    }
+
+                    int loadCount = 0;
+                    JSONArray items = json.optJSONArray("items");
+                    if (items != null) {
+                        loadCount = items.length();
+
+                        for (int i = 0; i < loadCount; i++) {
+                            JSONObject item = items.optJSONObject(i);
+                            if (item != null) {
+
+                                ApexResultBaseModel model = makeModel(item);
+                                if (model != null) {
+                                    models.add(model);
+                                }
+                            }
+                        }
+                    }
+
+                    offset = models.size();
+                    String title = json.optString("title");
+                    rowActions = json.optJSONArray("row_actions");
+                    actions = json.optJSONArray("actions");
+
+                    mDataArray = models;
+                    if (getDelegate() != null) {
+                        getDelegate().onSuccess(title);
+                        if (loadCount < detal) {
+                            getDelegate().onNoMoreData();
+                        }
+                    }
+
+                } else {
+
+                    String msg = "Sorry, something is wrong.";
+                    if (json != null) {
+                        json.optString("err_msg", "Sorry, something is wrong.");
+                    }
+
+                    if (getDelegate() != null) {
+                        getDelegate().onFailed(msg);
+                    }
+                }
+
+            }
+        },null);
+
+    }
+
+    public void loadData() {
+
+        if (dirty) {
+            dirty = false;
+            String module_name = mParams.getString("module_name");
+            String fields = Network.getDisplayFieldsForFunction(module_name);
+            mFields = fields;
+        }
+
+        offset = 0;
+        loadData(ApexResultFetchDataType.APEX_RESULT_FETCH_DATA_TYPE_INITIAL);
+    }
+
+    public void refreshData() {
+
+        offset = 0;
+        loadData(ApexResultFetchDataType.APEX_RESULT_FETCH_DATA_TYPE_REFRESH);
+    }
+
+    public void loadMoreData() {
+        loadData(ApexResultFetchDataType.APEX_RESULT_FETCH_DATA_TYPE_LOAD_MORE);
+    }
+
+    // endregion
+
+    // region Save Search Parameter
+
+    public void saveSearchParametersWithName(final String  intentStr, final String name) {
+
+        if (getDelegate() != null) {
+            getDelegate().onStartLoading();
+        }
+
+        JSONObject json = RAUtil.Bundle2Json(mParams);
+        if (mFields != null) {
+            try {
+                json.put("columns", mFields);
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+        }
+
+
+        final String paramStr = json.toString();
+        final String module_name = mParams.getString("module_name");
+
+        OperationQueue.sharedQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
+            @Override
+            public Object operationDoInBackground() {
+                return Network.saveSearchParametersForModuleWithName(intentStr, paramStr, module_name, name);
+            }
+        }, new OperationQueue.OperationCompletionCallBack() {
+            @Override
+            public void operationCompletion(Object object) {
+
+                if (getDelegate() != null) {
+
+                    getDelegate().onStopLoading();
+
+                    JSONObject json = (JSONObject)object;
+
+                    int result = Network.RESULT_FALSE;
+                    String msg = "Sorry, something is wrong.";
+                    if (json != null) {
+
+                        result = json.optInt("result", Network.RESULT_FALSE);
+                        if (result != Network.RESULT_TRUE) {
+                            String err_msg = json.optString("err_msg");
+                            if (!TextUtils.isEmpty(err_msg)) {
+                                msg = err_msg;
+                            }
+                        }
+                    } // json
+
+                    if (result != Network.RESULT_TRUE) {
+                        getDelegate().onFailed(msg);
+                    }
+
+                } // != null
+
+
+
+            }
+        }, null);
+    }
+
+    // endregion
+
+    // region Download
+
+    public void downloadFile(final String url, final Bundle params) {
+
+        if (getDelegate() != null) {
+            getDelegate().onStartLoading();
+        }
+
+        OperationQueue.sharedQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
+            @Override
+            public Object operationDoInBackground() {
+
+                String cacheDir = ApexTrackingApplication.getInstance().getExternalCacheDir().getAbsolutePath();
+
+                final File downloadFile = Network.downloadFile(params, url, cacheDir);
+
+                return downloadFile;
+            }
+        }, new OperationQueue.OperationCompletionCallBack() {
+            @Override
+            public void operationCompletion(Object object) {
+
+                if (getDelegate() != null) {
+
+                    getDelegate().onStopLoading();
+
+                    File file = (File)object;
+                    if (file == null) {
+
+                        getDelegate().onFailed("Sorry, something is wrong.");
+
+                    } else {
+                        getDelegate().onDownloadFile(file.getAbsolutePath(), params);
+                    }
+
+                }
+
+            }
+        }, null);
+
+    }
+
+    // endregion
+}

+ 53 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/cell/ApexResultAdditionView.java

@@ -0,0 +1,53 @@
+package com.usai.apex.apexresult.cell;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.usai.apex.R;
+
+public class ApexResultAdditionView extends RelativeLayout {
+
+    public static ApexResultAdditionView makeAdditionView(Context context) {
+
+        ApexResultAdditionView additionView = (ApexResultAdditionView) LayoutInflater.from(context).inflate(R.layout.apex_result_addition_view, null);
+        additionView.init();
+        return additionView;
+    }
+
+    private TextView titleTv, valueTv;
+
+    public ApexResultAdditionView(Context context) {
+        super(context);
+    }
+
+    public ApexResultAdditionView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public ApexResultAdditionView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    private void init() {
+        titleTv = findViewById(R.id.apex_result_addition_title_tv);
+        valueTv = findViewById(R.id.apex_result_addition_value_tv);
+        prepareReuse();
+    }
+
+    private void prepareReuse() {
+        titleTv.setText("");
+        valueTv.setText("");
+    }
+
+    public void setTitle(String title) {
+        titleTv.setText(title);
+    }
+
+    public void setValue(String value) {
+        valueTv.setText(value);
+    }
+
+}

+ 70 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/cell/ApexResultDocumentCell.java

@@ -0,0 +1,70 @@
+package com.usai.apex.apexresult.cell;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.usai.apex.R;
+
+
+public class ApexResultDocumentCell extends RelativeLayout {
+
+    public static ApexResultDocumentCell makeDocumentCell(Context context) {
+
+        ApexResultDocumentCell cell = (ApexResultDocumentCell) LayoutInflater.from(context).inflate(R.layout.apex_result_document_cell, null);
+        cell.init();
+
+        return cell;
+    }
+
+
+    private ImageView fileIconView;
+    private TextView fileNameTv, fileTypeTv, fileDescTv;
+
+    private void init() {
+
+        fileIconView = findViewById(R.id.apex_result_document_icon_view);
+        fileNameTv = findViewById(R.id.apex_result_document_file_name_tv);
+        fileTypeTv = findViewById(R.id.apex_result_document_file_type_tv);
+        fileDescTv = findViewById(R.id.apex_result_document_file_desc_tv);
+
+        prepareReuse();
+    }
+
+    public ApexResultDocumentCell(Context context) {
+        super(context);
+    }
+
+    public ApexResultDocumentCell(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public ApexResultDocumentCell(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    public void prepareReuse() {
+        fileNameTv.setText("");
+        fileTypeTv.setText("");
+        fileDescTv.setText("");
+    }
+
+    public ApexResultDocumentCell setFileName(String name) {
+        fileNameTv.setText(name);
+        return this;
+    }
+
+    public ApexResultDocumentCell setFileType(String type) {
+        fileTypeTv.setText(type);
+        return this;
+    }
+
+    public ApexResultDocumentCell setFileDescription(String description) {
+        fileDescTv.setText(description);
+        return this;
+    }
+
+}

+ 165 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/cell/ApexResultShipCell.java

@@ -0,0 +1,165 @@
+package com.usai.apex.apexresult.cell;
+
+import android.content.Context;
+import android.support.annotation.Nullable;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.usai.apex.ApexTrackingApplication;
+import com.usai.apex.R;
+import com.usai.apex.mainframe.TrackingImageView;
+
+import java.util.ArrayList;
+
+public class ApexResultShipCell extends LinearLayout {
+
+    // region initial
+    public static ApexResultShipCell makeShipCell(Context context) {
+        ApexResultShipCell cell = (ApexResultShipCell) LayoutInflater.from(context).inflate(R.layout.apex_result_ship_cell, null);
+        cell.init();
+
+        return cell;
+    }
+
+    private TextView titleTv, dateTv, descTv, detailTv, portTv;
+    private TrackingImageView statusIv;
+    private View stageView;
+    private LinearLayout additionLayout;
+
+    private ArrayList<ApexResultAdditionView> additionArray = new ArrayList<>();
+    private int additionCount = 0;
+
+    public ApexResultShipCell(Context context) {
+        super(context);
+    }
+
+    public ApexResultShipCell(Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public ApexResultShipCell(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    private void init() {
+
+        titleTv = findViewById(R.id.tv_title);
+        dateTv = findViewById(R.id.tv_time);
+        descTv = findViewById(R.id.tv_description);
+        detailTv = findViewById(R.id.tv_detail);
+        portTv = findViewById(R.id.tv_port);
+        statusIv = findViewById(R.id.iv_status);
+        stageView = findViewById(R.id.v_transport_stage);
+        additionLayout = findViewById(R.id.apex_result_ship_addition_view);
+
+        prepareReuse();
+    }
+
+    public void prepareReuse() {
+
+        titleTv.setText("");
+        dateTv.setText("");
+        descTv.setText("");
+        detailTv.setText("");
+        portTv.setText("");
+        statusIv.setImageDrawable(null);
+        setTransportStage(0);
+        clearAdditionView();
+    }
+
+    public void setTransportStage(int stage) {
+        switch(stage)
+        {
+            case 0:
+                stageView.setBackground(ApexTrackingApplication.getInstance().getResources().getDrawable(R.drawable.list_corner_transport_stage_bg_0));
+                break;
+            case 1:
+                stageView.setBackground(ApexTrackingApplication.getInstance().getResources().getDrawable(R.drawable.list_corner_transport_stage_bg_1));
+                break;
+            case 2:
+                stageView.setBackground(ApexTrackingApplication.getInstance().getResources().getDrawable(R.drawable.list_corner_transport_stage_bg_2));
+                break;
+            case 3:
+                stageView.setBackground(ApexTrackingApplication.getInstance().getResources().getDrawable(R.drawable.list_corner_transport_stage_bg_3));
+                break;
+            default:
+                stageView.setBackground(ApexTrackingApplication.getInstance().getResources().getDrawable(R.drawable.list_corner_transport_stage_bg_0));
+                break;
+
+        }
+    }
+
+    // endregion
+
+    // region set
+
+    public ApexResultShipCell setTitle(String title) {
+        titleTv.setText(title);
+        return this;
+    }
+
+    public ApexResultShipCell setDetail(String detail) {
+        detailTv.setText(detail);
+        return this;
+    }
+
+    public ApexResultShipCell setIcon(String icon) {
+        if (icon != null) {
+            int resourceId = getContext().getResources().getIdentifier(icon, "drawable", getContext().getPackageName());
+            statusIv.setImageResource(resourceId);
+        } else {
+            statusIv.setImageDrawable(null);
+        }
+        return this;
+    }
+
+    public ApexResultShipCell setPort(String port) {
+        portTv.setText(port);
+        return this;
+    }
+
+    public ApexResultShipCell setTime(String time) {
+        dateTv.setText(time);
+        return this;
+    }
+
+    public ApexResultShipCell setDescription(String description) {
+        descTv.setText(description);
+        return this;
+    }
+
+    public void addAddition(String name, String value) {
+
+        ApexResultAdditionView additionView;
+        if (additionCount >= additionArray.size()) {
+
+            additionView = ApexResultAdditionView.makeAdditionView(getContext());
+            additionArray.add(additionView);
+
+        } else {
+            additionView = additionArray.get(additionCount);
+        }
+        additionCount++;
+
+        additionView.setTitle(name);
+        additionView.setValue(value);
+
+        LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
+        additionLayout.addView(additionView, layoutParams);
+    }
+
+    // endregion
+
+    // region Private
+
+    private void clearAdditionView() {
+        additionLayout.removeAllViews();
+        additionCount = 0;
+    }
+
+    // endregion
+}

+ 49 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/model/ApexResultBaseModel.java

@@ -0,0 +1,49 @@
+package com.usai.apex.apexresult.model;
+
+import android.os.Parcel;
+
+import com.usai.apex.base.BaseObject;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class ApexResultBaseModel extends BaseObject {
+
+    protected ApexResultBaseModel(Parcel in) {
+        type = in.readInt();
+        String jsonStr = in.readString();
+        try {
+            rowActionParameters = new JSONArray(jsonStr);
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public ApexResultBaseModel() {
+
+    }
+
+    public JSONObject toJson() {
+        JSONObject json = new JSONObject();
+        try {
+            json.put("type", type);
+            if (rowActionParameters != null) {
+                json.put("rowActionParameters", rowActionParameters);
+            }
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+        return json;
+    }
+
+    public static enum ApexResultType {
+        APEX_RESULT_TYPE_SHIP,
+        APEX_RESULT_TYPE_DOCUMENT
+    }
+
+    public int type;
+    public JSONArray rowActionParameters;
+}

+ 36 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/model/ApexResultDocumentModel.java

@@ -0,0 +1,36 @@
+package com.usai.apex.apexresult.model;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class ApexResultDocumentModel extends ApexResultBaseModel {
+
+    public String fileName;
+    public String fileType;
+    public String fileDesc;
+
+    public ApexResultDocumentModel() {
+
+    }
+
+    @Override
+    public JSONObject toJson() {
+        JSONObject json = super.toJson();
+
+        try {
+            if (fileName != null) {
+                json.put("fileName", fileName);
+            }
+            if (fileType != null) {
+                json.put("fileType", fileType);
+            }
+            if (fileDesc != null) {
+                json.put("fileDesc", fileDesc);
+            }
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+        return json;
+    }
+}

+ 113 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/model/ApexResultShipModel.java

@@ -0,0 +1,113 @@
+package com.usai.apex.apexresult.model;
+
+import com.usai.apex.base.BaseObject;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+
+public class ApexResultShipModel extends ApexResultBaseModel {
+
+    // region Addition
+    public static class ApexResultAddition extends BaseObject{
+        public String name;
+        public String value;
+
+        private ApexResultAddition() {
+
+        }
+    }
+    // endregion
+
+    // region Model
+    public String title;
+    public String icon;
+    public String desc;
+    public String detail;
+    public String date;
+    public String port;
+    public int transport_stage;
+
+    public Object addition; // 使用Object对象,便于baseObject赋值
+    private ArrayList<ApexResultAddition> additions;
+
+    public ApexResultShipModel() {
+
+    }
+
+    public void setAddition(Object obj) {
+        this.addition = obj;
+        if (obj != null && obj instanceof JSONArray) {
+
+            JSONArray addition = (JSONArray) obj;
+            if (addition != null && addition.length() > 0) {
+
+                this.additions = new ArrayList<>();
+                for (int i = 0; i < addition.length(); i++) {
+                    JSONObject additionItem = addition.optJSONObject(i);
+                    if (additionItem != null) {
+
+                        ApexResultAddition additionModel = new ApexResultAddition();
+                        additionModel.setValuesForKeysWithJSON(additionItem);
+                        this.additions.add(additionModel);
+                    }
+                }
+
+            } else {
+                this.additions = null;
+            }
+
+        } else {
+            this.additions = null;
+        }
+
+
+
+    }
+
+    public ArrayList<ApexResultAddition> getAddition() {
+        return additions;
+    }
+    // endregion
+
+
+    @Override
+    public JSONObject toJson() {
+        JSONObject json = super.toJson();
+
+        try {
+
+            if (title != null) {
+                json.put("title", title);
+            }
+            if (icon != null) {
+                json.put("icon", icon);
+            }
+            if (desc != null) {
+                json.put("desc", desc);
+            }
+            if (detail != null) {
+                json.put("detail", detail);
+            }
+            if (date != null) {
+                json.put("date", date);
+            }
+            if (port != null) {
+                json.put("port", port);
+            }
+
+            json.put("transport_stage", transport_stage);
+
+            if (addition != null) {
+                json.put("addition", addition);
+            }
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+        return json;
+    }
+}

+ 39 - 135
ApexDrivers/apexmobile/src/main/java/com/usai/apex/pdf/PDFPreviewActivity.java

@@ -1,16 +1,16 @@
 package com.usai.apex.pdf;
 
+import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.PackageManager;
-import android.graphics.Color;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.v4.content.FileProvider;
+
 import android.support.v7.app.ActionBar;
-import android.support.v7.app.AppCompatActivity;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -19,32 +19,19 @@ import android.view.MenuItem;
 import android.view.View;
 import android.widget.TextView;
 
-import com.github.barteksc.pdfviewer.PDFView;
-import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
-import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
-import com.github.barteksc.pdfviewer.listener.OnPageErrorListener;
-import com.github.barteksc.pdfviewer.util.FitPolicy;
-import com.shockwave.pdfium.PdfDocument;
 import com.usai.apex.ApexTrackingApplication;
 import com.usai.apex.R;
+import com.usai.redant.rautils.preview.RAPDFPreviewActivity;
 import com.usai.util.RAUtil;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import java.io.File;
-import java.util.List;
 
-public class PDFPreviewActivity extends AppCompatActivity implements OnPageChangeListener, OnLoadCompleteListener,
-        OnPageErrorListener {
+public class PDFPreviewActivity extends RAPDFPreviewActivity {
+
 
-    boolean iscachefile;
-    private static final String TAG = PDFPreviewActivity.class.getSimpleName();
-//    String pdfFileName;
-    PDFView pdfView;
-//    @NonConfigurationInstance
-    Integer pageNumber = 0;
-//    public static final String SAMPLE_FILE = "sample.pdf";
 
 
 
@@ -198,44 +185,16 @@ public class PDFPreviewActivity extends AppCompatActivity implements OnPageChang
         String path=getIntent().getStringExtra("file");
         String title=new File(path).getName();
         TextView mtitleview= mActionBarView.findViewById(R.id.title);
-//        String title = mParams.getString("title");
         mtitleview.setText(title);
         setTitle(title);
-//
-//        mActionBarView.setBackgroundColor(Color.YELLOW);
-//        titleview.setBackgroundColor(Color.BLUE);
+
         ActionBar actionBar = getSupportActionBar();
         actionBar.setCustomView(mActionBarView, lp);
-//        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
-//        actionBar.setDisplayShowCustomEnabled(true);
-        actionBar.setDisplayHomeAsUpEnabled(true);
 
+        actionBar.setDisplayHomeAsUpEnabled(true);
 
-//        actionBar.setIcon(getNumberDrawable());
-//        actionBar.setDisplayShowHomeEnabled(true);
         actionBar.setDisplayShowTitleEnabled(true);
     }
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        switch (item.getItemId()) {
-
-            case android.R.id.home:
-                finish();
-                break;
-            case R.id.action_save:
-                SavePDF();
-                break;
-            case R.id.action_open:
-                openFile();
-                break;
-            case R.id.action_send:
-                shareFile();
-                break;
-
-            default: break;
-        }
-        return super.onOptionsItemSelected(item);
-    }
 
     private void SavePDF()
     {
@@ -286,6 +245,30 @@ public class PDFPreviewActivity extends AppCompatActivity implements OnPageChang
         builder.create().show();
 
     }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+
+            case android.R.id.home:
+                finish();
+                break;
+            case R.id.action_save:
+                SavePDF();
+                break;
+            case R.id.action_open:
+                openFile();
+                break;
+            case R.id.action_send:
+                shareFile();
+                break;
+
+            default: break;
+        }
+
+        return super.onOptionsItemSelected(item);
+    }
+
     @Override
     public boolean onCreateOptionsMenu(Menu menu)
     {
@@ -297,105 +280,26 @@ public class PDFPreviewActivity extends AppCompatActivity implements OnPageChang
             getMenuInflater().inflate(R.menu.pdf_saved_preview, menu);
         return true;
     }
+
     @Override
-    protected void onDestroy()
-    {
+    public void onDestroy() {
+        super.onDestroy();
 
         if(iscachefile) {
             String file = getIntent().getStringExtra("file");
             new File(file).delete();
         }
-        super.onDestroy();
     }
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_pdf_preview);
 
-        setCustomActionBar();
-        pdfView = findViewById(R.id.pdfView);
-        pdfView.setBackgroundColor(Color.LTGRAY);
-        pdfView.setPadding(10,10,10,10);
-
-        String file=getIntent().getStringExtra("file");
-        iscachefile = getIntent().getBooleanExtra("iscache",false);
-//        pdfFileName = assetFileName;
-        pdfView.fromFile(new File(file))
-//        pdfView.fromAsset(SAMPLE_FILE)
-                .defaultPage(pageNumber)
-                .onPageChange(this)
-                .enableAnnotationRendering(true)
-                .onLoad(this)
-//                .scrollHandle(new DefaultScrollHandle(this))
-
-                .spacing(10) // in dp
-                .onPageError(this)
-                .pageFitPolicy(FitPolicy.BOTH)
-                .load();
-
-        /*
-        pdfView.fromAsset(SAMPLE_FILE)
-//                .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
-                .enableSwipe(true) // allows to block changing pages using swipe
-                .swipeHorizontal(false)
-                .enableDoubletap(true)
-                .defaultPage(0)
-                // allows to draw something on the current page, usually visible in the middle of the screen
-//                .onDraw(this)
-                // allows to draw something on all pages, separately for every page. Called only for visible pages
-//                .onDrawAll(onDrawListener)
-                .onLoad(this) // called after document is loaded and starts to be rendered
-                .onPageChange(this)
-//                .onPageScroll(onPageScrollListener)
-//                .onError(onErrorListener)
-                .onPageError(this)
-//                .onRender(onRenderListener) // called after document is rendered for the first time
-                // called on single tap, return true if handled, false to toggle scroll handle visibility
-//                .onTap(onTapListener)
-                .enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
-                .password(null)
-                .scrollHandle(null)
-                .enableAntialiasing(true) // improve rendering a little bit on low-res screens
-                // spacing between pages in dp. To define spacing color, set view background
-                .spacing(0)
-//                .linkHandler(DefaultLinkHandler)
-                .pageFitPolicy(FitPolicy.WIDTH)
-                .load();*/
-    }
+    private boolean iscachefile = false;
 
     @Override
-    public void loadComplete(int nbPages) {
-        PdfDocument.Meta meta = pdfView.getDocumentMeta();
-        Log.e(TAG, "title = " + meta.getTitle());
-        Log.e(TAG, "author = " + meta.getAuthor());
-        Log.e(TAG, "subject = " + meta.getSubject());
-        Log.e(TAG, "keywords = " + meta.getKeywords());
-        Log.e(TAG, "creator = " + meta.getCreator());
-        Log.e(TAG, "producer = " + meta.getProducer());
-        Log.e(TAG, "creationDate = " + meta.getCreationDate());
-        Log.e(TAG, "modDate = " + meta.getModDate());
-
-        printBookmarksTree(pdfView.getTableOfContents(), "-");
-    }
-
-    @Override
-    public void onPageChanged(int page, int pageCount) {
-
-    }
+    public void onCreate(Bundle savedInstanceState) {
 
-    @Override
-    public void onPageError(int page, Throwable t) {
+        iscachefile = getIntent().getBooleanExtra("iscache",false);
 
+        super.onCreate(savedInstanceState);
+        setCustomActionBar();
     }
 
-    public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
-        for (PdfDocument.Bookmark b : tree) {
-
-            Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));
-
-            if (b.hasChildren()) {
-                printBookmarksTree(b.getChildren(), sep + "-");
-            }
-        }
-    }
 }

+ 1 - 1
ApexDrivers/apexmobile/src/main/java/com/usai/apex/saved/SavedSearchFragment.java

@@ -20,7 +20,7 @@ import android.widget.TextView;
 
 import com.usai.apex.ApexTrackingApplication;
 import com.usai.apex.R;
-import com.usai.apex.apexResult.ApexResultActivity;
+import com.usai.apex.apexresult.ApexResultActivity;
 import com.usai.apex.swipemenulistview.BaseSwipListAdapter;
 import com.usai.apex.swipemenulistview.SwipeMenu;
 import com.usai.apex.swipemenulistview.SwipeMenuCreator;

+ 3 - 213
ApexDrivers/apexmobile/src/main/java/com/usai/util/AES.java

@@ -1,26 +1,7 @@
 package com.usai.util;
 
-import android.util.Base64;
-import android.util.Log;
 
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Security;
-import java.util.Arrays;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-
-import static android.content.ContentValues.TAG;
+import com.usai.redant.rautils.utils.AESUtil;
 
 /**
  * Created by ray on 07/06/2017.
@@ -37,206 +18,15 @@ import static android.content.ContentValues.TAG;
  */
 
 public class AES {
-    // 算法名称
-    final static String KEY_ALGORITHM = "AES";
-    // 加解密算法/模式/填充方式
-    final static String algorithmStr = "AES/CBC/PKCS7Padding";
-    //
-//    private Key key;
-//    private Cipher cipher;
-//    boolean isInited = false;
 
-    static byte[] iv = new byte[16];//{ 0x30, 0x31, 0x30, 0x32, 0x30, 0x33, 0x30, 0x34, 0x30, 0x35, 0x30, 0x36, 0x30, 0x37, 0x30, 0x38 };
-//    private static void init(byte[] keyBytes) {
-//
-//        // 如果密钥不足16位,那么就补足.  这个if 中的内容很重要
-//        int base = 16;
-//        if (keyBytes.length % base != 0) {
-//            int groups = keyBytes.length / base + (keyBytes.length % base != 0 ? 1 : 0);
-//            byte[] temp = new byte[groups * base];
-//            Arrays.fill(temp, (byte) 0);
-//            System.arraycopy(keyBytes, 0, temp, 0, keyBytes.length);
-//            keyBytes = temp;
-//        }
-//        // 初始化
-//        Security.addProvider(new BouncyCastleProvider());
-//        // 转化成JAVA的密钥格式
-//        key = new SecretKeySpec(keyBytes, KEY_ALGORITHM);
-//        try {
-//            // 初始化cipher
-//            cipher = Cipher.getInstance(algorithmStr, "BC");
-//        } catch (NoSuchAlgorithmException e) {
-//            // TODO Auto-generated catch block
-//            e.printStackTrace();
-//        } catch (NoSuchPaddingException e) {
-//            // TODO Auto-generated catch block
-//            e.printStackTrace();
-//        } catch (NoSuchProviderException e) {
-//            // TODO Auto-generated catch block
-//            e.printStackTrace();
-//        }
-//    }
-
-    private static String toHex(byte[] buf)
-    {
-        if (buf == null)
-            return "";
-        StringBuffer result = new StringBuffer(2 * buf.length);
-        for (int i = 0; i < buf.length; i++)
-        {
-            appendHex(result, buf[i]);
-        }
-        return result.toString();
-    }
-    private static void appendHex(StringBuffer sb, byte b)
-    {
-        sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
-    }
-    private final static String HEX = "0123456789ABCDEF";
 
     public static String encrypt(String key, String content)
     {
-        byte[] result=encrypt(content.getBytes(),key.getBytes());
-        Log.d(TAG, "encrypt: "+toHex(result));
-        return Base64.encodeToString(result, Base64.DEFAULT);
+        return AESUtil.encrypt128(key, content);
     }
 
     public static String decrypt(String key, String content)
     {
-        byte[] buffer = Base64.decode(content, Base64.DEFAULT);
-
-        byte[] result = decrypt(buffer,key.getBytes());
-
-        return new String(result);
-    }
-
-    /**
-     * 加密方法
-     *
-     * @param content
-     *            要加密的字符串
-     * @param keyBytes
-     *            加密密钥
-     * @return
-     */
-    private static byte[] encrypt(byte[] content, byte[] keyBytes) {
-        byte[] encryptedText = null;
-//        init(keyBytes);
-
-     Key key;
-     Cipher cipher;
-        // 如果密钥不足16位,那么就补足.  这个if 中的内容很重要
-        int base = 16;
-        if (keyBytes.length % base != 0) {
-            int groups = keyBytes.length / base + (keyBytes.length % base != 0 ? 1 : 0);
-            byte[] temp = new byte[groups * base];
-            Arrays.fill(temp, (byte) 0);
-            System.arraycopy(keyBytes, 0, temp, 0, keyBytes.length);
-            keyBytes = temp;
-        }
-        // 初始化
-        Security.addProvider(new BouncyCastleProvider());
-        // 转化成JAVA的密钥格式
-        key = new SecretKeySpec(keyBytes, KEY_ALGORITHM);
-        try {
-            // 初始化cipher
-            cipher = Cipher.getInstance(algorithmStr, "BC");
-
-
-            cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
-            encryptedText = cipher.doFinal(content);
-
-        } catch (NoSuchAlgorithmException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (NoSuchPaddingException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (NoSuchProviderException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (BadPaddingException e) {
-            e.printStackTrace();
-        } catch (InvalidKeyException e) {
-            e.printStackTrace();
-        } catch (IllegalBlockSizeException e) {
-            e.printStackTrace();
-        } catch (InvalidAlgorithmParameterException e) {
-            e.printStackTrace();
-        }
-
-
-//        System.out.println("IV:" + new String(iv));
-//        try {
-//
-//        } catch (Exception e) {
-//            // TODO Auto-generated catch block
-//            e.printStackTrace();
-//        }
-        return encryptedText;
+        return AESUtil.decrypt128(key, content);
     }
-    /**
-     * 解密方法
-     *
-     * @param encryptedData
-     *            要解密的字符串
-     * @param keyBytes
-     *            解密密钥
-     * @return
-     */
-    private static byte[] decrypt(byte[] encryptedData, byte[] keyBytes) {
-        byte[] encryptedText = null;
-//        init(keyBytes);
-
-        Key key;
-        Cipher cipher;
-                // 如果密钥不足16位,那么就补足.  这个if 中的内容很重要
-        int base = 16;
-        if (keyBytes.length % base != 0) {
-            int groups = keyBytes.length / base + (keyBytes.length % base != 0 ? 1 : 0);
-            byte[] temp = new byte[groups * base];
-            Arrays.fill(temp, (byte) 0);
-            System.arraycopy(keyBytes, 0, temp, 0, keyBytes.length);
-            keyBytes = temp;
-        }
-        // 初始化
-        Security.addProvider(new BouncyCastleProvider());
-        // 转化成JAVA的密钥格式
-        key = new SecretKeySpec(keyBytes, KEY_ALGORITHM);
-        try {
-            // 初始化cipher
-            cipher = Cipher.getInstance(algorithmStr, "BC");
-            cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
-            encryptedText = cipher.doFinal(encryptedData);
-        } catch (NoSuchAlgorithmException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (NoSuchPaddingException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (NoSuchProviderException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (BadPaddingException e) {
-            e.printStackTrace();
-        } catch (InvalidKeyException e) {
-            e.printStackTrace();
-        } catch (IllegalBlockSizeException e) {
-            e.printStackTrace();
-        } catch (InvalidAlgorithmParameterException e) {
-            e.printStackTrace();
-        }
-
-//        System.out.println("IV:" + new String(iv));
-//        try {
-//
-//        } catch (Exception e) {
-//            // TODO Auto-generated catch block
-//            e.printStackTrace();
-//        }
-
-        return encryptedText;
-    }
-
-
 }

+ 11 - 397
ApexDrivers/apexmobile/src/main/java/com/usai/util/Network.java

@@ -22,42 +22,22 @@ import java.security.UnrecoverableKeyException;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.UUID;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
 
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.HttpVersion;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.ConnectTimeoutException;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
 import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.MultipartEntity;
-import org.apache.http.entity.mime.content.StringBody;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.HTTP;
+
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+
 import com.usai.apex.ApexTrackingApplication;
-import com.usai.apex.CustomizeFieldsActivity.fieldedit;
-import com.usai.apex.R;
+
 
 import android.content.Context;
 import android.content.SharedPreferences.Editor;
@@ -65,7 +45,6 @@ import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.database.Cursor;
-import android.database.SQLException;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteStatement;
 import android.net.ConnectivityManager;
@@ -152,37 +131,7 @@ public class Network
 
 	
 
-	private static HttpClient getNewHttpClient()
-	{
-		try
-		{
-			KeyStore trustStore = KeyStore.getInstance(KeyStore
-					.getDefaultType());
-			trustStore.load(null, null);
-
-			SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
-			sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
-
-			HttpParams params = new BasicHttpParams();
-			HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
-			HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
-			HttpConnectionParams.setConnectionTimeout(params, REQUEST_TIMEOUT);
-			HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT);
-			SchemeRegistry registry = new SchemeRegistry();
-			registry.register(new Scheme("http", PlainSocketFactory
-					.getSocketFactory(), 80));
-			registry.register(new Scheme("https", sf, 443));
-
-			ClientConnectionManager ccm = new ThreadSafeClientConnManager(
-					params, registry);
 
-			return new DefaultHttpClient(ccm, params);
-		}
-		catch (Exception e)
-		{
-			return new DefaultHttpClient();
-		}
-	}
 
 	public static String get_marketnews(String id, int limit)
 	{
@@ -211,11 +160,9 @@ public class Network
 
 	public static String get_servicelocation()
 	{
-		String TAG = "net_dbg@get_servicelocation";
 
 		if (!Network.NetworkIsAvailable())
 		{
-			Log.d(TAG, "network not available!");
 			return null; // network not available
 		}
 
@@ -227,7 +174,6 @@ public class Network
 		String jstr = getJson(Network.URL_LOCATIONS, parms);
 		if (jstr == null || jstr.length() <= 0)
 		{
-			Log.d(TAG, "json is wrong");
 			return null;
 		}
 		return jstr;
@@ -236,11 +182,9 @@ public class Network
 
 	public static String get_announcements(String id, int limit)
 	{
-		String TAG = "net_dbg@get_announcements";
 
 		if (!Network.NetworkIsAvailable())
 		{
-			Log.d(TAG, "network not available!");
 			return null; // network not available
 		}
 
@@ -252,7 +196,6 @@ public class Network
 		String jstr = getJson(Network.URL_ANNOUNCEMENTS, parms);
 		if (jstr == null || jstr.length() <= 0)
 		{
-			Log.d(TAG, "json is wrong");
 			return null;
 		}
 		return jstr;
@@ -401,166 +344,8 @@ public class Network
 
 	public static String getJson(String url, Bundle parms)
 	{
-		String TAG = "net_dbg@GetJson";
-		Log.d(TAG, "entry");
-
 		prepare_addtional_params(parms);
-//		parms.putString("sessionid", ApexTrackingApplication.get_sessionid());
-
-		// if (true)
-		// return fakegetJson(url);
-		try
-		{
-			// BasicHttpParams httpParams = new BasicHttpParams();
-			// HttpConnectionParams.setConnectionTimeout(httpParams,
-			// REQUEST_TIMEOUT);
-			// HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
-			HttpClient client = getNewHttpClient();// new
-													// DefaultHttpClient(httpParams);
-			HttpPost post = new HttpPost(url);
-			MultipartEntity reqEntity = new MultipartEntity(
-					HttpMultipartMode.BROWSER_COMPATIBLE);
-
-			Set<String> keys = parms.keySet();
-			Log.d(TAG, "================parms============");
-			for (String key : keys)
-			{
-				if (key.contains("_file"))
-				{
-					;
-				}
-				else
-					reqEntity.addPart(key, new StringBody(parms.get(key)
-							.toString()));
-				Log.d(TAG, "key=" + key + "    val="
-						+ parms.get(key).toString());
-			}
-			Log.d(TAG, "================parms============");
-
-			post.setEntity(reqEntity);
-			HttpResponse response = client.execute(post);
-			int statucode = response.getStatusLine().getStatusCode();
-			if (statucode == HttpStatus.SC_OK)
-			{
-				HttpEntity resEntity = response.getEntity();
-				if (resEntity != null)
-				{
-					Log.d(TAG,
-							"Response: content len==>"
-									+ resEntity.getContentLength());
-					InputStream is = resEntity.getContent();
-					try
-					{
-
-						BufferedReader br = new BufferedReader(
-								new InputStreamReader(is, "utf-8"), 8);
-						StringBuilder sb = new StringBuilder();
-						String line = null;
-						while ((line = br.readLine()) != null)
-						{
-							sb.append(line + "\n");
-						}
-
-						Log.d(TAG, "Response: content begin");
-						Log.d(TAG, sb.toString());
-						Log.d(TAG, "Response: content end");
-
-						if (sb.length() <= 0)
-						{
-
-							return null;
-						}
-						return sb.toString();
-
-					}
-					catch (Exception e)
-					{
-						Log.e(TAG, e.toString());
-						return null;
-						// TODO: handle exception
-					}
-					finally
-					{
-						is.close();
-
-					}
-
-				}
-				else
-				{
-					/*
-					 * resEntity is null
-					 */
-					Log.d(TAG, "RESPONSE ENTITY IS NULL");
-					return null;
-				}
-
-			}
-			else
-			{
-				/*
-				 * Http error; out put error code;
-				 */
-				Log.d(TAG, "HTTP " + statucode);
-
-				HttpEntity resEntity = response.getEntity();
-				if (resEntity != null)
-				{
-
-					InputStream is = resEntity.getContent();
-					try
-					{
-
-						BufferedReader br = new BufferedReader(
-								new InputStreamReader(is, "utf-8"), 8);
-						StringBuilder sb = new StringBuilder();
-						String line = null;
-						while ((line = br.readLine()) != null)
-						{
-							sb.append(line + "\n");
-						}
-
-						Log.d(TAG, "Response: content begin");
-						Log.d(TAG, sb.toString());
-						Log.d(TAG, "Response: content end");
-						return null;
-					}
-					catch (Exception e)
-					{
-						Log.e(TAG, e.toString());
-						return null;
-						// TODO: handle exception
-					}
-					finally
-					{
-						is.close();
-
-					}
-
-				}
-				else
-				{
-					/*
-					 * resEntity is null
-					 */
-					Log.e(TAG, "RESPONSE ENTITY IS NULL");
-					return null;
-				}
-			}
-
-		}
-		catch (ConnectTimeoutException e)
-		{
-			Log.d(TAG, "request time out");
-			return null;
-
-		}
-		catch (Exception e)
-		{
-			Log.d(TAG, e.toString());
-			return null;
-		}
-
+		return com.usai.redant.rautils.utils.Network.getJson(url, parms, REQUEST_TIMEOUT);
 	}
 
 	public static int get_recordcount(Bundle parms)
@@ -1377,50 +1162,7 @@ public class Network
 
 	public static boolean NetworkIsAvailable()// Context context)
 	{
-		String TAG = "net_dbg@CheckNetwork";
-		ConnectivityManager connManager = (ConnectivityManager) ApexTrackingApplication
-				.get_instance().getSystemService(Context.CONNECTIVITY_SERVICE);
-		// .getSystemService(Context.CONNECTIVITY_SERVICE);
-
-		NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
-		if (networkInfo == null)
-		{
-			Log.d(TAG, "can not get Active NetworkInfo!");
-			// dbgUtil.Log(Log.DEBUG, "Current Network info",
-			// "can not get Active NetworkInfo!");
-			return false;
-		}
-		NetworkInfo.State netState = networkInfo.getState();
-		if (netState != NetworkInfo.State.CONNECTED)
-		{
-			Log.d(TAG, "not Connected!State=" + netState);
-			// dbgUtil.Log(Log.DEBUG, "Current Network info",
-			// "not Connected!State=" + netState);
-			return false;
-		}
-		// int iconntype = -1;
-		// iconntype = networkInfo.getType();
-
-		// boolean bUseMobileNetwork = context.getSharedPreferences(
-		// "PhoneAsstPref", 0).getBoolean("UseMobileNetwork", false);
-		//
-		// if (bUseMobileNetwork == false
-		// && iconntype != ConnectivityManager.TYPE_WIFI && iconntype != 9/*
-		// earthnet */)
-		// {
-		// Log.d(TAG,);
-		// dbgUtil.Log(Log.DEBUG, "Current Network info",
-		// "not allowed!Connection type=" + networkInfo.getTypeName());
-		// return false;
-		// }
-		boolean bavailable = networkInfo.isAvailable();
-		String strtype = networkInfo.getTypeName();
-
-		Log.d(TAG, " type = " + strtype + " abailable = " + bavailable
-				+ " state " + netState);
-		// dbgUtil.Log(Log.INFO, "Current Network info", " type = " + strtype
-		// + " abailable = " + bavailable + " state " + netState);
-		return bavailable;
+		return com.usai.redant.rautils.utils.Network.isNetworkAvailable(ApexTrackingApplication.get_instance());
 	}
 
 //	public static class SSLSocketFactoryEx extends SSLSocketFactory
@@ -1561,138 +1303,10 @@ public class Network
 			return sslContext.getSocketFactory().createSocket();
 		}
 	}
-	private static String createPostParameters(Bundle parms) throws UnsupportedEncodingException {
-		StringBuilder result = new StringBuilder();
-		boolean first = true;
-		for(String key : parms.keySet()){
-			if (first)
-				first = false;
-			else
-				result.append("&");
-
-			result.append(URLEncoder.encode(key, "UTF-8"));
-			result.append("=");
-			result.append(URLEncoder.encode(parms.get(key).toString(), "UTF-8"));
-		}
-
-		return result.toString();
-	}
-
-	//读取响应头
-	public static JSONObject getResponseHeader(HttpURLConnection conn) {
-		Map<String, List<String>> responseHeaderMap = conn.getHeaderFields();
-		int size = responseHeaderMap.size();
-		try {
-			JSONObject responseHeader = new JSONObject();
-			for(int i = 0; i < size; i++){
-				String responseHeaderKey = conn.getHeaderFieldKey(i);
-				String responseHeaderValue = conn.getHeaderField(i);
-				if (responseHeaderKey != null && !responseHeaderKey.isEmpty() && responseHeaderValue != null) {
-					responseHeader.put(responseHeaderKey,responseHeaderValue);
-				}
-			}
-			return responseHeader;
-		} catch (JSONException e) {
-			e.printStackTrace();
-			return null;
-		}
-	}
-
-	public static String getResponsesuggestedFilename(JSONObject response) {
-
-		if (response == null) {
-			return null;
-		}
-
-		try {
-			String key = "Content-Disposition";
-			String content_disposition = response.getString(key);
-			if (content_disposition != null) {
-				String[] components = content_disposition.split(";");
-				if (components[1] != null) {
-					String fileName = components[1].split("=")[1];
-					fileName = fileName.replace("\"","");
-					return fileName;
-				}
-			}
-
-		} catch (JSONException e) {
-			e.printStackTrace();
-		}
-
-
-		return null;
-	}
 
 	public static File downloadFile(Bundle params, String download_url,String dir) {
-
-		if (params == null) {
-			params = new Bundle();
-		}
-
 		prepare_addtional_params(params);
-		HttpURLConnection connection = null;
-
-		File returnFile = null;
-		try {
-
-			String fileName = UUID.randomUUID().toString();
-			if (dir == null) {
-				dir = Environment.getExternalStorageDirectory() + File.separator + "download";
-			}
-
-			if (RAUtil.isFileExist(fileName,dir)) {
-				returnFile = new File(dir + File.separator + fileName);
-			} else {
-				// 创建一个URL对象
-				URL url=new URL(download_url);
-				// 创建一个HTTP链接
-				connection=(HttpURLConnection)url.openConnection();
-				connection.setRequestMethod("POST");
-
-				// 拼参数
-				if (params != null && params.keySet().size() > 0) {
-					OutputStream os = connection.getOutputStream();
-					BufferedWriter writer = new BufferedWriter(
-							new OutputStreamWriter(os, "UTF-8"));
-					writer.write(createPostParameters(params));
-
-					writer.flush();
-					writer.close();
-					os.close();
-				}
-
-				// 获取响应
-				JSONObject responseHeader = getResponseHeader(connection);
-				String suggestedFileName = getResponsesuggestedFilename(responseHeader);
-				Log.d("Download", "download_query: " + suggestedFileName);
-				if (suggestedFileName != null && !suggestedFileName.isEmpty()) {
-					fileName = suggestedFileName;
-				}
-
-				// 使用IO流获取数据
-				InputStream inputStream=connection.getInputStream();
-				// 写文件
-				File downloadFile = RAUtil.write2SDFromInput(fileName,dir,inputStream);
-
-				if (downloadFile == null) {
-					returnFile = null;
-				} else {
-					returnFile = downloadFile;
-				}
-			}
-
-		} catch (IOException e) {
-			e.printStackTrace();
-		} finally {
-			if (connection != null) {
-				connection.disconnect();
-			}
-		}
-
-
-
-		return returnFile;
+		return com.usai.redant.rautils.utils.Network.downloadFile(params, download_url, dir);
 	}
 
 	public static File download_query(String download_url,String path) {
@@ -1929,20 +1543,20 @@ public class Network
 
 		params.putString("action","handset_search");
 
-		String url = "http://192.168.1.150:8080/MyWeb/SearchBooking";
+		String url = "http://192.168.1.151:8080/MyWeb/SearchBooking";
 
 		String module_name = params.getString("module_name");
 		if (module_name.equals("Ocean Booking")) {
 
 		} else if (module_name.equals("Ocean B/L info.")) {
 
-			url = "http://192.168.1.150:8080/MyWeb/SearchBL";
+			url = "http://192.168.1.151:8080/MyWeb/SearchBL";
 		} else if (module_name.equals("Container detail")) {
 
-			url = "http://192.168.1.150:8080/MyWeb/SearchContainer";
+			url = "http://192.168.1.151:8080/MyWeb/SearchContainer";
 		} else if (module_name.equals("Download Document")) {
 
-			url = "http://192.168.1.150:8080/MyWeb/SearchDoc";
+			url = "http://192.168.1.151:8080/MyWeb/SearchDoc";
 		}
 
 		try {

+ 1 - 1
ApexDrivers/apexmobile/src/main/res/layout/activity_apex_result.xml

@@ -5,7 +5,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    tools:context=".apexResult.ApexResultActivity">
+    tools:context=".apexresult.ApexResultActivity">
 
     <android.support.v4.widget.SwipeRefreshLayout
         android:id="@+id/apex_result_refresh_layout"

+ 2 - 2
ApexDrivers/apexmobile/src/main/res/layout/apex_result_addition_view.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<com.usai.apex.apexResult.cell.ApexResultAdditionView
+<com.usai.apex.apexresult.cell.ApexResultAdditionView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
@@ -26,4 +26,4 @@
         android:text="FU YAMA TRADing"
         />
 
-</com.usai.apex.apexResult.cell.ApexResultAdditionView>
+</com.usai.apex.apexresult.cell.ApexResultAdditionView>

+ 4 - 4
ApexDrivers/apexmobile/src/main/res/layout/apex_result_document_cell.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
-<com.usai.apex.apexResult.cell.ApexResultDocumentCell xmlns:android="http://schemas.android.com/apk/res/android"
-                android:layout_width="match_parent"
-                android:layout_height="90dp">
+<com.usai.apex.apexresult.cell.ApexResultDocumentCell xmlns:android="http://schemas.android.com/apk/res/android"
+                                                      android:layout_width="match_parent"
+                                                      android:layout_height="90dp">
 
 
     <RelativeLayout
@@ -66,4 +66,4 @@
 
     </RelativeLayout>
 
-</com.usai.apex.apexResult.cell.ApexResultDocumentCell>
+</com.usai.apex.apexresult.cell.ApexResultDocumentCell>

+ 5 - 5
ApexDrivers/apexmobile/src/main/res/layout/apex_result_ship_cell.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
-<com.usai.apex.apexResult.cell.ApexResultShipCell xmlns:android="http://schemas.android.com/apk/res/android"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-    android:orientation="vertical"
+<com.usai.apex.apexresult.cell.ApexResultShipCell xmlns:android="http://schemas.android.com/apk/res/android"
+                                                  android:layout_width="match_parent"
+                                                  android:layout_height="wrap_content"
+                                                  android:orientation="vertical"
     >
 
     <RelativeLayout
@@ -154,4 +154,4 @@
 
 
 
-</com.usai.apex.apexResult.cell.ApexResultShipCell>
+</com.usai.apex.apexresult.cell.ApexResultShipCell>