Kaynağa Gözat

1.修改Android RedAnt Mobile,完成KVDetail。

Pen Li 8 yıl önce
ebeveyn
işleme
2db6f0c850

+ 178 - 1
RedAnt Mobile/app/src/main/java/com/usai/redant/Detail/KVDetailActivity.java

@@ -4,9 +4,17 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.Intent;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseExpandableListAdapter;
+import android.widget.ExpandableListView;
+import android.widget.TextView;
 
 
+import com.usai.redant.CommonEditor.CommonEditorActivity;
 import com.usai.redant.redantmobile.R;
 import com.usai.redant.redantmobile.R;
 
 
+import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.json.JSONObject;
 
 
@@ -23,12 +31,19 @@ public class KVDetailActivity extends AppCompatActivity {
         return intent;
         return intent;
     }
     }
 
 
-    JSONObject mContent;
+    private JSONObject mContent;
+    private Context mContext;
+    private KVListAdapter adapter;
+    private ExpandableListView listView;
+
+
     @Override
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_kvdetail);
         setContentView(R.layout.activity_kvdetail);
 
 
+        mContext = this;
+
         String content_json_str = getIntent().getStringExtra("content");
         String content_json_str = getIntent().getStringExtra("content");
         if (content_json_str != null) {
         if (content_json_str != null) {
             try {
             try {
@@ -37,5 +52,167 @@ public class KVDetailActivity extends AppCompatActivity {
                 e.printStackTrace();
                 e.printStackTrace();
             }
             }
         }
         }
+
+        adapter = new KVListAdapter();
+        listView = (ExpandableListView) findViewById(R.id.kv_listView);
+        listView.setAdapter(adapter);
+        // 全部展开
+        for (int i = 0; i < adapter.getGroupCount(); i++) {
+            listView.expandGroup(i);
+        }
+    }
+
+
+    private class KVListAdapter extends BaseExpandableListAdapter {
+
+
+        int TypeCell = 0;
+        int TypeHeader = 1;
+
+        @Override
+        public int getGroupCount() {
+            if (mContent == null) {
+                return 0;
+            }
+            int count = mContent.optInt("count",0);
+            return count;
+        }
+
+        @Override
+        public int getChildrenCount(int i) {
+            JSONObject json = (JSONObject) getGroup(i);
+            if (json != null) {
+                JSONArray data = json.optJSONArray("data");
+                if (data != null) {
+                    return data.length();
+                }
+            }
+            return 0;
+        }
+
+        @Override
+        public Object getGroup(int i) {
+
+            JSONObject section = mContent.optJSONObject("section_" + i);
+
+            return section;
+        }
+
+        @Override
+        public Object getChild(int groupPosition, int childPosition) {
+            JSONObject json = (JSONObject) getGroup(groupPosition);
+            if (json != null) {
+                JSONArray data = json.optJSONArray("data");
+                if (data != null) {
+                    return data.opt(childPosition);
+                }
+            }
+            return null;
+        }
+
+        @Override
+        public int getChildTypeCount() {
+            return 2;
+        }
+
+        @Override
+        public int getChildType(int groupPosition, int childPosition) {
+            return TypeCell;
+        }
+
+        @Override
+        public long getGroupId(int i) {
+            return i;
+        }
+
+        @Override
+        public long getChildId(int i, int i1) {
+            return i * 1000 + i1;
+        }
+
+        @Override
+        public boolean hasStableIds() {
+            return true;
+        }
+
+        @Override
+        public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
+
+            HeaderHolder holder;
+
+            if (view == null) {
+
+                view = LayoutInflater.from(mContext).inflate(R.layout.kv_list_section_cell,null);
+                holder = new HeaderHolder(view);
+
+            } else {
+                holder = (HeaderHolder) view.getTag();
+            }
+
+            JSONObject json = (JSONObject)getGroup(i);
+            if (json != null) {
+                holder.titleLabel.setText(json.optString("title"));
+            } else {
+                holder.titleLabel.setText(null);
+            }
+
+            return view;
+        }
+
+        @Override
+        public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
+
+            CellHolder holder;
+            if (view == null) {
+
+                view = LayoutInflater.from(mContext).inflate(R.layout.kv_list_detail_cell,null);
+                holder = new CellHolder(view);
+
+            } else {
+
+                holder = (CellHolder) view.getTag();
+
+            }
+
+            JSONObject item = (JSONObject)getChild(i, i1);
+            if (item != null) {
+                String key = item.optString("key");
+                String val = item.optString("val");
+                if (val == null || val.equals("null")) {
+                    val = "";
+                }
+
+                holder.titleLabel.setText(key);
+                holder.valLabel.setText(val);
+            } else {
+                holder.titleLabel.setText(null);
+                holder.valLabel.setText(null);
+            }
+
+            return view;
+        }
+
+        @Override
+        public boolean isChildSelectable(int i, int i1) {
+            return false;
+        }
+
+
+        private class HeaderHolder {
+            TextView titleLabel;
+            HeaderHolder(View view) {
+                titleLabel = view.findViewById(R.id.kv_list_section_title_lb);
+                view.setTag(this);
+            }
+        }
+
+        private class CellHolder {
+            TextView titleLabel, valLabel;
+            CellHolder(View view) {
+                titleLabel = view.findViewById(R.id.detail_title_lb);
+                valLabel = view.findViewById(R.id.detail_val_lb);
+                view.setTag(this);
+            }
+        }
     }
     }
 }
 }

+ 48 - 2
RedAnt Mobile/app/src/main/java/com/usai/redant/Result/SearchResultActivity.java

@@ -5,6 +5,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager;
+import android.content.res.Resources;
 import android.database.DataSetObserver;
 import android.database.DataSetObserver;
 import android.graphics.Color;
 import android.graphics.Color;
 import android.net.Uri;
 import android.net.Uri;
@@ -42,6 +43,7 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.json.JSONObject;
 
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Iterator;
@@ -257,8 +259,48 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
         progressDialog.show();
         progressDialog.show();
     }
     }
 
 
+    JSONObject readRawFile(int id)
+    {
+        String content;
+        Resources resources=this.getResources();
+        InputStream is=null;
+        try{
+            is=resources.openRawResource(id);
+            byte buffer[]=new byte[is.available()];
+            is.read(buffer);
+            content=new String(buffer);
+            JSONObject json = new JSONObject(content);
+            return json;
+        }
+        catch(IOException e)
+        {
+            e.printStackTrace();
+        }
+        catch (JSONException e) {
+            e.printStackTrace();
+        }
+        finally
+        {
+            if(is!=null)
+            {
+                try{
+                    is.close();
+                }catch(IOException e)
+                {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return null;
+    }
+
     private void loadData() {
     private void loadData() {
 
 
+        resultData = readRawFile(R.raw.predef_query);
+        if (1 == 1) {
+            return;
+        }
+
         isLoading = true;
         isLoading = true;
 
 
         showProgressDialog(null,"Loading");
         showProgressDialog(null,"Loading");
@@ -984,14 +1026,18 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
             @Override
             @Override
             public void run() {
             public void run() {
 
 
-                final JSONObject json = Network.kv_detail(RAUtil.Json2Bundle(param));
+//                final JSONObject json = Network.kv_detail(RAUtil.Json2Bundle(param));
+                final JSONObject json = readRawFile(R.raw.kv);
 
 
                 runOnUiThread(new Runnable() {
                 runOnUiThread(new Runnable() {
                     @Override
                     @Override
                     public void run() {
                     public void run() {
                         progressDialog.dismiss();
                         progressDialog.dismiss();
 
 
-                        int result = json.optInt("result",0);
+                        int result = 0;
+                        if (json != null) {
+                            result = json.optInt("result",0);
+                        }
                         if (result == 2) {
                         if (result == 2) {
 
 
                             Intent intent = KVDetailActivity.build(mContext,json.toString());
                             Intent intent = KVDetailActivity.build(mContext,json.toString());

+ 16 - 2
RedAnt Mobile/app/src/main/res/layout/activity_kvdetail.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout
+<RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:tools="http://schemas.android.com/tools"
@@ -7,4 +7,18 @@
     android:layout_height="match_parent"
     android:layout_height="match_parent"
     tools:context="com.usai.redant.Detail.KVDetailActivity">
     tools:context="com.usai.redant.Detail.KVDetailActivity">
 
 
-</android.support.constraint.ConstraintLayout>
+
+
+    <ExpandableListView
+        android:id="@+id/kv_listView"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        >
+
+
+
+
+    </ExpandableListView>
+
+
+</RelativeLayout>

+ 29 - 0
RedAnt Mobile/app/src/main/res/layout/kv_list_detail_cell.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="horizontal"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent">
+
+    <TextView
+        android:id="@+id/detail_title_lb"
+        android:layout_width="150dp"
+        android:layout_height="match_parent"
+        android:textSize="20sp"
+        android:textColor="#000000"
+        android:gravity="start|center_vertical"
+        />
+    <View
+        android:layout_width="1dp"
+        android:layout_height="match_parent"
+        android:background="@color/dark_gray"
+        />
+    <TextView
+        android:id="@+id/detail_val_lb"
+        android:layout_width="0dp"
+        android:layout_weight="1"
+        android:layout_height="match_parent"
+        android:textSize="20sp"
+        android:textColor="#000000"
+        />
+
+</LinearLayout>

+ 17 - 0
RedAnt Mobile/app/src/main/res/layout/kv_list_section_cell.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="horizontal"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent">
+
+    <TextView
+        android:id="@+id/kv_list_section_title_lb"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:gravity="start|center_vertical"
+        android:textSize="20sp"
+        android:textColor="#ffffff"
+        android:background="#69C3F4"
+        />
+
+</LinearLayout>

+ 29 - 0
RedAnt Mobile/app/src/main/res/raw/kv.json

@@ -0,0 +1,29 @@
+{
+    "result": 2,
+    "count": 1,
+    "section_0": {
+        "title": "section title",
+        "data": [
+                 {
+                 "key": "abc",
+                 "val": "123"
+                 },
+                 {
+                 "key": "def",
+                 "val": "dddd \n abc"
+                 },
+                 {
+                 "key": "adfas",
+                 "val": "rfds fs dfaf erqfd ddd fjian fjdiao rnenqwiv hdf fhisab r q fhdiarehf fdan"
+                 },
+                 {
+                 "key": "bgfg",
+                 "val": "trs fds"
+                 },
+                 {
+                 "key": "hff",
+                 "val": "43"
+                 }
+                 ]
+    }
+}

+ 250 - 0
RedAnt Mobile/app/src/main/res/raw/predef_query.json

@@ -0,0 +1,250 @@
+{
+    "result": 2,
+    "menu": [
+             {
+             "title": "Export 1",
+             "action": "download",
+             "url": "xxx"
+             },
+             {
+             "title": "Export 2",
+             "action": "download",
+             "url": "xxx"
+             },
+             {
+             "title": "Save",
+             "action": "save"
+             }
+             ],
+    "row_action": [
+                   {
+                   "title": "demo title",
+                   "module0": "quick_look",
+                   "module": "kv_detail",
+                   "module1": "order_detail",
+                   "url": "http://1.1.1.1",
+                   "params": {
+                   "order#": 0
+                   }
+                   }
+                   ],
+    "data": {
+        "count": 17,
+        "item_0": [
+                   "<b></b>",
+                   "<b>def</b>",
+                   "$ 123.45",
+                   "43",
+                   "metal table with 4 chairs"
+                   ],
+        "item_1": [
+                   "2",
+                   "315318",
+                   "$ 99.49",
+                   "13",
+                   "WOOD table with 4 chairs"
+                   ],
+        "item_2": [
+                   "3",
+                   "7033566",
+                   "$ 13.45",
+                   "57",
+                   "bed"
+                   ],
+        "item_3": [
+                   "4",
+                   "8533-UVR",
+                   "$ 1123.45",
+                   "143",
+                   "<b>Desk</b> & chair UILongPressGestureRecognizer *longPress"
+                   ],
+        "item_4": [
+                   "1",
+                   "8533-UPK",
+                   "$ 123.45",
+                   "43",
+                   "metal table with 4 chairs"
+                   ],
+        "item_5": [
+                   "2",
+                   "315318",
+                   "$ 99.49",
+                   "13",
+                   "WOOD table with 4 chairs"
+                   ],
+        "item_6": [
+                   "3",
+                   "7033566",
+                   "$ 13.45",
+                   "57",
+                   "bed"
+                   ],
+        "item_7": [
+                   "4",
+                   "8533-UVR",
+                   "$ 1123.45",
+                   "143",
+                   "Desk & chair UILongPressGestureRecognizer *longPress"
+                   ],
+        "item_8": [
+                   "1",
+                   "8533-UPK",
+                   "$ 123.45",
+                   "43",
+                   "metal table with 4 chairs"
+                   ],
+        "item_9": [
+                   "2",
+                   "315318",
+                   "$ 99.49",
+                   "13",
+                   "WOOD table with 4 chairs"
+                   ],
+        "item_10": [
+                    "3",
+                    "7033566",
+                    "$ 13.45",
+                    "57",
+                    "bed"
+                    ],
+        "item_11": [
+                    "1",
+                    "8533-UPK",
+                    "$ 123.45",
+                    "43",
+                    "metal table with 4 chairs"
+                    ],
+        "item_12": [
+                    "2",
+                    "315318",
+                    "$ 99.49",
+                    "13",
+                    "WOOD table with 4 chairs"
+                    ],
+        "item_13": [
+                    "3",
+                    "7033566",
+                    "$ 13.45",
+                    "57",
+                    "bed"
+                    ],
+        "item_14": [
+                    "1",
+                    "8533-UPK",
+                    "$ 123.45",
+                    "43",
+                    "metal table with 4 chairs"
+                    ],
+        "item_15": [
+                    "2",
+                    "315318",
+                    "$ 99.49",
+                    "13",
+                    "WOOD table with 4 chairs"
+                    ],
+        "item_16": [
+                    "3",
+                    "7033566",
+                    "$ 13.45",
+                    "57",
+                    "bed"
+                    ]
+    },
+    "layout": {
+        "header": {
+            "width": 810,
+            "height": 44,
+            "margin_r": 10,
+            "margin_l": 10,
+            "margin_t": 10,
+            "margin_b": 10,
+            "bg_color": "0x123456",
+            "f_color": "0x987654",
+            "col": [
+                    {
+                    "width": 100,
+                    "name": "id",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    },
+                    {
+                    "width": 160,
+                    "name": "model",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    },
+                    {
+                    "width": 180,
+                    "name": "price",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    },
+                    {
+                    "width": 120,
+                    "name": "stock",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    },
+                    {
+                    "width": 250,
+                    "name": "description",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    }
+                    ]
+        },
+        "row": {
+            "height": 44,
+            "f_color": "0x654321",
+            "color_0": "0xffffff",
+            "color_1": "0x666666",
+            "val": [
+                    {
+                    "type": "image",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    },
+                    {
+                    "type": "text",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    },
+                    {
+                    "type": "text",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    },
+                    {
+                    "type": "text",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    },
+                    {
+                    "type": "text",
+                    "h_align": "center",
+                    "v_center": "center",
+                    "bg_color": "0x123456",
+                    "f_color": "0x654321"
+                    }
+                    ]
+        }
+    }
+}