-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivityBackup23.6-predzmenougui.txt
163 lines (143 loc) · 5.08 KB
/
ActivityBackup23.6-predzmenougui.txt
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.example.phoneblocker;
import java.lang.reflect.Method;
import java.util.HashSet;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.media.AudioManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
import android.os.Vibrator;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.android.internal.telephony.ITelephony;
public class MainBlockActivity extends Activity implements BindableWithCommunicator{
Communicator com = new Communicator(this);
Boolean enabled = true;
ServiceConnection mConnection;
CallBlockService mService;
boolean mBound = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_block);
/* Button bt = (Button) findViewById(R.id.toggleButton1);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (enabled){
com.StopBlocking();
enabled = false;
} else {
com.StartBlocking();
enabled = true;
}
}
*/
mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
CallBlockService.CallBlockServiceBinder binder = (CallBlockService.CallBlockServiceBinder) service;
mService = binder.getService();
mBound = true;
int j = mService.GetStats();
Log.i("STATS", " "+j);
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
mBound = false;
}
};
HashSet<String> data = new HashSet<String>();
data.add("+421944254415");
startService(new Intent(this, CallBlockService.class));
// Intent intent = new Intent(this, CallBlockService.class);
// final boolean control = bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
/* Runnable runnable = new Runnable() {
@Override
public void run() {
int i = 0;
while (!control && i < 101){
SystemClock.sleep(100);
Log.i("BINDER IN ACTIVITY", "Still false");
i++;
}
if(!control){
Log.i("BINDER IN ACTIVITY", "FAILED");
}else{
SystemClock.sleep(3000);
int j = mService.GetStats();
Log.i("STATS", " "+j);
}
}
};
runnable.run();*/
com.SetNumbersBlockList(data);
final Communicator.StatObject obj = com.GetStats();
Runnable runnable = new Runnable() {
@Override
public void run() {
int i = 0;
while (!obj.valueSet && i < 400){
SystemClock.sleep(100);
i++;
}
if(!obj.valueSet){
Log.i("BINDER IN ACTIVITY", "VALUE FAILED");
}else{
int j = obj.stat;
Log.i("STATS", " "+j);
}
}
};
runnable.run();
// com.StartBlocking();
//--------
// something();
}
//TODO IMPORTANT v main activity MUSIA byt tieto dve metody. Pouziva ich communicator.
public boolean doBind(ServiceConnection con){
Intent intent = new Intent(this, CallBlockService.class);
Boolean tmp = bindService(intent, con, Context.BIND_AUTO_CREATE);
if (!tmp)Log.e("MainActivity ERROR", "bind unsuccessful.");
return tmp;
}
public void doUnbind(ServiceConnection con){
unbindService(con);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_block, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onDestroy(){
if (com.isBounded())com.Disconnect();
super.onDestroy();
}
}