-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
132 lines (110 loc) · 4.38 KB
/
Copy pathMainActivity.java
File metadata and controls
132 lines (110 loc) · 4.38 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.example.recipe;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
// 이미지를 배열에 넣음
int[] ImageTop = {R.drawable.fridge_top_open, R.drawable.fridge_top_close};
int[] ImageBottom = {R.drawable.fridge_bottom_open, R.drawable.fridge_bottom_close};
ImageView top;
ImageView bottom;
ImageButton meat;
ImageButton egg;
ImageButton kimchi;
ImageButton dumpling;
ImageButton ice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
// 냉장고
top = (ImageView) findViewById(R.id.fridge_top);
bottom = (ImageView) findViewById(R.id.fridge_bottom);
meat = (ImageButton) findViewById(R.id.meat);
egg = (ImageButton) findViewById(R.id.egg);
kimchi = (ImageButton) findViewById(R.id.kimchi);
dumpling = (ImageButton) findViewById(R.id.dumpling);
ice = (ImageButton) findViewById(R.id.ice);
//menu로 넘어가기
ice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),ice_menu.class);
startActivity(intent);
}
});
meat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),meat_menu.class);
startActivity(intent);
}
});
kimchi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),kimchi_menu.class);
startActivity(intent);
}
});
egg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),egg_menu.class);
startActivity(intent);
}
});
dumpling.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),dumpling_menu.class);
startActivity(intent);
}
});
// 이미지를 폴더에 있는 이미지로 셋팅
top.setImageResource(R.drawable.fridge_top_close);
bottom.setImageResource(R.drawable.fridge_bottom_close);
top.setOnClickListener(new MyListener());
bottom.setOnClickListener(new MyListener());
}
class MyListener implements View.OnClickListener {
int i = 0;
int j = 0;
int lengthTop = ImageTop.length;
int lengthBottom = ImageBottom.length;
@Override
public void onClick(View view) {
if (view.getId() == R.id.fridge_top) {
top.setImageResource(ImageTop[i]);
if(i==0){
dumpling.setVisibility(View.VISIBLE); //문열때 재료버튼
ice.setVisibility(View.VISIBLE);
} else if (i==1) {
dumpling.setVisibility(View.GONE);
ice.setVisibility(View.GONE);
}
i += 1;
if (i == ImageTop.length) i = 0;
} else if (view.getId() == R.id.fridge_bottom) {
bottom.setImageResource(ImageBottom[j]);
if(j==0){
meat.setVisibility(View.VISIBLE); //문열때 재료버튼
egg.setVisibility(View.VISIBLE);
kimchi.setVisibility(View.VISIBLE);
} else if (j==1) {
meat.setVisibility(View.GONE);
egg.setVisibility(View.GONE);
kimchi.setVisibility(View.GONE);
}
j += 1;
if (j == ImageBottom.length) j = 0;
}
}
}
}