MainActivity.java
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.example.ksi.refrigerator;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.Image;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import java.lang.reflect.Array;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
ArrayList<Item> itemList = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0; i<3; i++)
{
Item temp = new Item();
temp.name = "사과";
temp.date = new Date();
itemList.add(temp);
}
}
public void showExpdate(View view){
Intent intent = new Intent(this,Main4Activity.class);
ArrayList<Item> ExpdateItem = new ArrayList();
for(int i=0; i<itemList.size();i++)
{
Date today = new Date();
long dif = today.getTime()-itemList.get(i).date.getTime();
dif = dif/(24*60*60*1000);
//유통기한 3일 남은것까지 보여주기
if(dif < 4){
ExpdateItem.add(itemList.get(i));
}
}
intent.putExtra("item",ExpdateItem);
startActivity(intent);
}
public void addItem(View view){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(intent.resolveActivity(getPackageManager())!=null) {
startActivityForResult(intent, 1);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode, resultCode, data);
Bitmap img;
if(requestCode == 1 && resultCode == RESULT_OK)
{
Bundle extras = data.getExtras();
img = (Bitmap) extras.get("data");
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("barcode",img);
startActivityForResult(intent, 2);
}
else if(requestCode == 2 && resultCode == RESULT_OK)
{
Toast.makeText(this,"성공!",Toast.LENGTH_LONG).show();
Item item = (Item)data.getSerializableExtra("item2");
itemList.add(item);
TableRow row = new TableRow(this);
ImageView photo = new ImageView(this);
photo.setBackgroundColor(0xFF00FF00);
Glide.with(this)
.load(item.image)
.override(200,200)
.into(photo);
photo.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
row.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.WRAP_CONTENT,
TableLayout.LayoutParams.WRAP_CONTENT));
row.addView(photo);
TableLayout table = (TableLayout)findViewById(R.id.refri);
table.addView(row);
}
}
}