-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity3.java
More file actions
122 lines (95 loc) · 4.41 KB
/
MainActivity3.java
File metadata and controls
122 lines (95 loc) · 4.41 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
package com.example.bony.goti;
import android.media.MediaPlayer;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
public class MainActivity3 extends AppCompatActivity {
ImageView image;
Thread thread;
Handler handler=new Handler() ;
MediaPlayer mp;
final int imagesize[]=new int []{R.drawable.b1,R.drawable.b2,R.drawable.bb2,R.drawable.b5,R.drawable.b4,R.drawable.b10,R.drawable.b11,R.drawable.bb1,R.drawable.b6,R.drawable.b7,R.drawable.b8,R.drawable.b9,R.drawable.b12,R.drawable.b13,R.drawable.b14,R.drawable.b15,R.drawable.b16,R.drawable.b17,R.drawable.b18,R.drawable.b19,R.drawable.b21,R.drawable.b22,R.drawable.b23,R.drawable.b24,
R.drawable.b25,R.drawable.b26,R.drawable.b27,R.drawable.b28,R.drawable.b31,R.drawable.b33,R.drawable.b34,R.drawable.b35,R.drawable.b36,R.drawable.b37,R.drawable.b38,R.drawable.b39,R.drawable.b40,R.drawable.b42,R.drawable.b43,R.drawable.b44,R.drawable.b45,R.drawable.b46,R.drawable.b47,R.drawable.b49,R.drawable.b50,R.drawable.b51};
int counter=0,i=0,b=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
image = (ImageView) findViewById(R.id.imageView);
ImageButton button1 = (ImageButton) findViewById(R.id.button1);
ImageButton button2 = (ImageButton) findViewById(R.id.button2);
ImageButton button3 = (ImageButton) findViewById(R.id.button3);
mp= MediaPlayer.create(this, R.raw.sound);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(b==0) {
b=1;
mp.start();
thread = new Thread(new MainActivity3.Task());
thread.start();
}
else {
b = 0;
mp.pause();
}
}
});
button3.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
counter++;
if(counter ==imagesize.length){
counter=0;
}
image.setImageResource(imagesize[counter]);
}
}
);
button1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
counter--;
if(counter<0)
{
counter=imagesize.length-1;
}
image.setImageResource(imagesize[counter]);
}
}
);
}
class Task implements Runnable {
@Override
public void run() {
while (i <imagesize.length+1&&b==1) {
handler.post(new Runnable() {
@Override
public void run() {
if(i==imagesize.length) {
image.setImageResource(imagesize[0]);
b=0;
mp.pause();
mp.seekTo(0);
i=0;
}
else
image.setImageResource(imagesize[i]);
}
});
//bar.setProgress(i);
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
e.printStackTrace();
}
i=i+1;
}
}
}
}