-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
219 lines (163 loc) · 6.38 KB
/
Copy pathMainActivity.java
File metadata and controls
219 lines (163 loc) · 6.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package com.medantechno.arduinobluetooth;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothHealthCallback;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.Toast;
import java.util.List;
import java.util.Locale;
public class MainActivity extends AppCompatActivity{
Button button1,button2,button3;
private TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this,ListCommand.class);
startActivity(i);
}
});
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this,BTSetting.class);
startActivity(i);
}
});
button3 = (Button) findViewById(R.id.button3);
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this,BTSetting.class);
startActivity(i);
}
});
tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
if(i != TextToSpeech.ERROR)
{
tts.setLanguage(Locale.US);
speakOut("Wellcome My Boss...");
}
}
});
speakOut("Wellcome Boss...");
BluetoothAdapter myBluetooth = BluetoothAdapter.getDefaultAdapter();
if(myBluetooth == null)
{
//Show a mensag. that the device has no bluetooth adapter
Toast.makeText(getApplicationContext(), "Bluetooth Device Not Available", Toast.LENGTH_LONG).show();
//finish apk
finish();
}
else if(!myBluetooth.isEnabled())
{
//Ask to the user turn the bluetooth on
Intent turnBTon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnBTon,1);
}
DatabaseHandler db = new DatabaseHandler(this);
/**
* CRUD Operations
* */
// Inserting Contacts
//Log.d("Insert: ", "Inserting ..");
//db.addContact(new Command("Ravi", "9100000000"));
//db.addContact(new Command("Srinivas", "9199999999"));
//db.addContact(new Command("Tommy", "9522222222"));
//db.addContact(new Command("Karthik", "9533333333"));
//db.addContact(new Command("Dulo", "085200000"));
// Reading all contacts
Log.d("Reading: ", "Reading all contacts..");
List<Command> contacts = db.getAllContacts();
for (Command cn : contacts) {
String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Phone: " + cn.getCodenya();
// Writing Contacts to log
Log.d("Name: ", log);
}
}
/*text to suara *****************************************/
@Override
public void onDestroy()
{
if(tts !=null)
{
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
private void speakOut(String text)
{
tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);
}
/*text to suara *****************************************/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
speakOut("Database Setting");
Intent i = new Intent(MainActivity.this, ListCommand.class);
startActivity(i);
}
if(id==R.id.menu_mic)
{
speakOut("Mic Setting...");
Intent i = new Intent(MainActivity.this, JendelaMic.class);
startActivity(i);
}
if(id==R.id.menu_bt)
{
speakOut("Bluetooth setting");
Intent i = new Intent(MainActivity.this, BTSetting.class);
//Intent i = new Intent(MainActivity.this, BluetoothActivity.class);
startActivity(i);
}
if(id == R.id.menu_exit)
{
speakOut("Exit boss?");
this.finish();
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
return super.onOptionsItemSelected(item);
}
}