17
+    private ArrayList<Photo> photos;
18
+    private GridView gridView;
19
+    private LayoutInflater inflater;
20
+    private int height;
21
+
22
+    public TestPhotoGridAdapter(MyTestActivity context, GridView gridView) {
23
+        cameraActivity = context;
24
+        this.gridView = gridView;
25
+        photos = new ArrayList<>();
26
+        inflater = LayoutInflater.from(context);
27
+        int screenW = context.getResources().getDisplayMetrics().widthPixels;
28
+        height = (int) (screenW - 4 * 3 * context.getResources().getDisplayMetrics().density) / 3;
29
+    }
30
+
31
+    @Override
32
+    public int getCount() {
33
+        return photos.size();
34
+    }
35
+
36
+    @Override
37
+    public Object getItem(int position) {
38
+        return photos.get(position);
39
+    }
40
+
41
+    @Override
42
+    public long getItemId(int position) {
43
+        return position;
44
+    }
45
+
46
+    public void addPhoto(final Photo photo) {
47
+        gridView.post(new Runnable() {
48
+            @Override
49
+            public void run() {
50
+                photos.add(0, photo);
51
+                notifyDataSetChanged();
52
+            }
53
+        });
54
+    }
55
+
56
+    public void updatePhoto(final Photo newPhoto) {
57
+        gridView.post(new Runnable() {
58
+            @Override
59
+            public void run() {
60
+                for(int k = 0; k < photos.size();k++){
61
+                    if(photos.get(k).handle == newPhoto.handle){
62
+                        photos.get(k).captureTime = newPhoto.captureTime;
63
+                        photos.get(k).thumb = newPhoto.thumb;
64
+                        photos.get(k).origin = newPhoto.origin;
65
+                        photos.get(k).fileName = newPhoto.fileName;
66
+                        break;
67
+                    }
68
+                }
69
+                notifyDataSetChanged();
70
+            }
71
+        });
72
+    }
73
+
74
+    public void addPhotos(final int[] handles){
75
+        gridView.post(new Runnable() {
76
+            @Override
77
+            public void run() {
78
+                ArrayList<Photo> tmp = new ArrayList<>();
79
+                for(int k =0;k<handles.length;k++){
80
+                    Photo photo = new Photo();
81
+                    photo.handle = handles[k];
82
+                    tmp.add(photo);
83
+                }
84
+                photos.addAll(tmp);
85
+                notifyDataSetChanged();
86
+            }
87
+        });
88
+    }
89
+
90
+    public void clear() {
91
+        gridView.post(new Runnable() {
92
+            @Override
93
+            public void run() {
94
+                photos.clear();
95
+                notifyDataSetChanged();
96
+            }
97
+        });
98
+    }
99
+
100
+    @Override
101
+    public View getView(int position, View convertView, ViewGroup parent) {
102
+        ViewHolder holder;
103
+        if (convertView == null) {
104
+            convertView = inflater.inflate(R.layout.item_grid_photo, null);
105
+            holder = new ViewHolder();
106
+            holder.photo = (ImageView) convertView.findViewById(R.id.iv_photo);
107
+            convertView.setTag(holder);
108
+        } else {
109
+            holder = (ViewHolder) convertView.getTag();
110
+        }
111
+        holder.photo.getLayoutParams().height = height;
112
+        Photo photo = photos.get(position);
113
+        if (photo.thumb != null) {
114
+            holder.photo.setImageBitmap(photo.thumb);
115
+        } else if (photo.origin != null) {
116
+            holder.photo.setImageBitmap(photo.origin);
117
+        } else if(photo.handle >0 && !photo.isSync){
118
+            photo.isSync = true;
119
+            cameraActivity.retrieveImageInfo(photo.handle);
120
+        }
121
+        return convertView;
122
+    }
123
+
124
+    final class ViewHolder {
125
+        public ImageView photo;
126
+    }
127
+}

+ 33 - 14
app/src/main/res/layout/activity_my_test.xml

@@ -1,7 +1,8 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
-    android:orientation="vertical" android:layout_width="match_parent"
4
-    android:layout_height="match_parent">
3
+    android:layout_width="match_parent"
4
+    android:layout_height="match_parent"
5
+    android:orientation="vertical">
5 6
 
6 7
     <Button
7 8
         android:id="@+id/btn_get_devece_info"
@@ -9,13 +10,14 @@
9 10
         android:layout_height="48dp"
10 11
         android:layout_margin="4dp"
11 12
         android:gravity="center"
12
-        android:text="获取设备信息"/>
13
+        android:text="获取设备信息" />
13 14
 
14 15
     <ListView
15 16
         android:id="@+id/list_info"
16 17
         android:layout_width="match_parent"
17
-        android:divider="@android:color/transparent"
18
-        android:layout_height="200dp" />
18
+        android:layout_height="200dp"
19
+        android:divider="@android:color/transparent" />
20
+
19 21
     <LinearLayout
20 22
         android:layout_width="match_parent"
21 23
         android:layout_height="48dp"
@@ -24,25 +26,42 @@
24 26
         <Button
25 27
             android:id="@+id/btn_capture_photo"
26 28
             android:layout_width="0dp"
27
-            android:layout_weight="1"
28 29
             android:layout_height="match_parent"
30
+            android:layout_weight="1"
29 31
             android:gravity="center"
30
-            android:text="拍摄"/>
32
+            android:text="拍摄模式" />
31 33
 
32 34
         <Button
33 35
             android:id="@+id/btn_get_photos"
34 36
             android:layout_width="0dp"
35
-            android:layout_weight="1"
36 37
             android:layout_height="match_parent"
38
+            android:layout_weight="1"
37 39
             android:gravity="center"
38
-            android:text="获取相机SD卡照片"/>
40
+            android:text="浏览模式" />
39 41
     </LinearLayout>
40 42
 
41
-
42
-    <ImageView
43
-        android:id="@+id/iv_latest_photo"
43
+    <RelativeLayout
44 44
         android:layout_width="match_parent"
45
-        android:layout_height="match_parent"
46
-        android:scaleType="centerCrop"/>
45
+        android:layout_height="match_parent">
46
+
47
+
48
+        <GridView
49
+            android:id="@+id/gridview_photos"
50
+            android:layout_width="match_parent"
51
+            android:layout_height="match_parent"
52
+            android:cacheColorHint="@android:color/transparent"
53
+            android:horizontalSpacing="4dp"
54
+            android:listSelector="@android:color/transparent"
55
+            android:numColumns="3"
56
+            android:verticalSpacing="4dp"
57
+            />
58
+
59
+        <ImageView
60
+            android:id="@+id/iv_latest_photo"
61
+            android:layout_width="match_parent"
62
+            android:layout_height="match_parent"
63
+            android:visibility="gone"
64
+            android:scaleType="fitCenter" />
65
+    </RelativeLayout>
47 66
 
48 67
 </LinearLayout>

+ 13 - 0
app/src/main/res/layout/item_grid_photo.xml

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    android:layout_width="match_parent"
4
+    android:layout_height="match_parent">
5
+
6
+    <ImageView
7
+        android:id="@+id/iv_photo"
8
+        android:layout_width="match_parent"
9
+        android:layout_height="match_parent"
10
+        android:background="#e2e2e2"
11
+        android:scaleType="centerCrop" />
12
+
13
+</RelativeLayout>

app/src/main/res/layout/item_test_info.xml → app/src/main/res/layout/item_test_log_info.xml


kodo - Gogs: Go Git Service

Keine Beschreibung

Brightcells: 8b7c49ddb9 add app to add page user_agreement/contact_us vor 10 Jahren
..
__init__.py 8b7c49ddb9 add app to add page user_agreement/contact_us vor 10 Jahren