-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpeningMenu.java
504 lines (442 loc) · 21.8 KB
/
OpeningMenu.java
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Twitter;
import javax.mail.*;
import java.nio.file.Files;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Timer;
import java.util.TimerTask;
import javax.mail.internet.MimeMessage;
//import javax.swing.JFrame;
//import javax.swing.JOptionPane;
//JFrame frame = new JFrame("JOptionPane showMessageDialog example");
//JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
/**
*
* @author Joel Gahr
*/
enum Providers{
VERIZON,
ATT,
TMOBILE,
SPRINT
}
public class OpeningMenu extends javax.swing.JFrame {
static class GlobalVars{
static String UserPhone = "";
static String UserTwitter = "";
static String RandoDingen = "Put You email password here";
static int UserProvider = 0;
static Path UserPresetsPath;
static boolean StartLoop = false;
static String OldTweetTime = "";
}
static int StringToDigit(String MyString){
int MyDigit = 0;
switch(MyString){
case "0":MyDigit = 0;break;
case "1":MyDigit = 1;break;
case "2":MyDigit = 2;break;
case "3":MyDigit = 3;break;
}
return(MyDigit);
}
static String GetProviderAddress()
{
String Address = "";
switch(GlobalVars.UserProvider)
{
case 0: Address = "@vtext.com";break;
case 1: Address = "@txt.att.net"; break;
case 2: Address = "@tmomail.net"; break;
case 3: Address = "@messaging.sprintpcs.com"; break;
}
return (Address);
}
class CheckAndUpdate extends TimerTask{
String UriStr = "";
@Override
public void run(){
if(GlobalVars.StartLoop == true){
//Send GET request to Twitter using A Bearer Token For authorization.
UriStr = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + GlobalVars.UserTwitter + "&count=1&trim_user=1";
String TwitStr = "";
try {
URL url = new URL(UriStr);
HttpURLConnection con;
try {
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", "Bearer " + "Put your bearer authorization string here");
Reader readit = new InputStreamReader(con.getInputStream());
int data = readit.read();
while(data != -1){
TwitStr = TwitStr + (char)data;
data = readit.read();
}
readit.close();
} catch (IOException ex) {
Logger.getLogger(OpeningMenu.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (MalformedURLException ex) {
Logger.getLogger(OpeningMenu.class.getName()).log(Level.SEVERE, null, ex);
}
boolean InQuotes = false;
String TitleString = "";
String NewTweetTime = "";
String TweetText = "";
for(int i = 0; i < TwitStr.length();++i){
if(TweetText.length() > 0 && NewTweetTime.length() > 0)
{
break;
}
else if (InQuotes)
{
if (TitleString.length() > 0 && TwitStr.charAt(i) == '"' && TwitStr.charAt(i - 1) != '\\')
{
switch (TitleString)
{
case "created_at":
{
//Write Next quote body to TimeString
for (int ITime = i + 3; ITime < TwitStr.length(); ++ITime)
{
if (TwitStr.charAt(ITime) == '"' && TwitStr.charAt(ITime - 1) != '\\')
{
i = ITime;
break;
}
else
NewTweetTime += TwitStr.charAt(ITime);
}
}
break;
case "text":
{
//Write next quote body to TweetContent
for (int ITime = i + 3; ITime < TwitStr.length(); ++ITime)
{
if (TwitStr.charAt(ITime) == '"' && TwitStr.charAt(ITime - 1) != '\\')
{
i = ITime;
break;
}
else
TweetText += TwitStr.charAt(ITime);
}
}
break;
default:
{
}
break;
}
TitleString = "";
InQuotes = false;
}
else
{
TitleString += TwitStr.charAt(i);
}
}
else if (TwitStr.charAt(i) == '"' && !InQuotes)
{
InQuotes = true;
}
}
if(!NewTweetTime.equals(GlobalVars.OldTweetTime)){
GlobalVars.OldTweetTime = NewTweetTime;
String[] TweetChunk = new String[5];
TweetChunk = NewTweetTime.split(" ",5);
//Send Text message via email containing time and body of the tweet.
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.ssl.enable", "true");
Session session = Session.getInstance(props, new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Put Your Email Address here", GlobalVars.RandoDingen);
}
});
session.setDebug(true);
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom("Put Your Email Address here");
msg.setRecipients(Message.RecipientType.TO,
GlobalVars.UserPhone + GetProviderAddress());
msg.setSubject(GlobalVars.UserTwitter);
msg.setSentDate(new Date());
msg.setText(TweetChunk[3] + ": " + TweetText);
Transport.send(msg,"Put Your Email Address here", GlobalVars.RandoDingen);
} catch (MessagingException mex) {
System.out.println("send failed, exception: " + mex);
}
}
int PressF = 69;
}
}
}
/**
* Creates new form OpeningMenu
*/
public OpeningMenu() {
initComponents();
double MinutesToWait = 0.1;
Timer CheckTimer = new Timer(true);
TimerTask TaskOfTheTimer = new CheckAndUpdate();
CheckTimer.schedule(TaskOfTheTimer, 0, (long)(1000*60*MinutesToWait));
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
lblPhone = new javax.swing.JLabel();
ButtonStart = new javax.swing.JButton();
txtTwitter = new javax.swing.JTextField();
comboProvider = new javax.swing.JComboBox<>();
lblTwitter1 = new javax.swing.JLabel();
lblProvider = new javax.swing.JLabel();
txtPhone = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("OpeningMenu");
setMaximumSize(getPreferredSize());
setMinimumSize(getPreferredSize());
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
lblPhone.setFont(new java.awt.Font("Liberation Mono", 1, 14)); // NOI18N
lblPhone.setText("Cell Phone Number:");
lblPhone.setToolTipText("");
ButtonStart.setFont(new java.awt.Font("Liberation Mono", 1, 18)); // NOI18N
ButtonStart.setText("Start");
ButtonStart.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
ButtonStartMouseClicked(evt);
}
});
ButtonStart.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonStartActionPerformed(evt);
}
});
txtTwitter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtTwitterActionPerformed(evt);
}
});
txtTwitter.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
txtTwitterPropertyChange(evt);
}
});
txtTwitter.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txtTwitterKeyTyped(evt);
}
});
comboProvider.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Verizon", "AT&T", "T-Mobile", "Sprint" }));
lblTwitter1.setFont(new java.awt.Font("Liberation Mono", 1, 14)); // NOI18N
lblTwitter1.setText("Twitter Handle : @");
lblTwitter1.setToolTipText("");
lblProvider.setFont(new java.awt.Font("Liberation Mono", 1, 14)); // NOI18N
lblProvider.setText("Service Provider:");
lblProvider.setToolTipText("");
txtPhone.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
txtPhonePropertyChange(evt);
}
});
txtPhone.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txtPhoneKeyTyped(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(85, 85, 85)
.addComponent(lblTwitter1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtTwitter, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(67, 67, 67)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblPhone)
.addComponent(lblProvider))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtPhone)
.addComponent(comboProvider, 0, 195, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(163, 163, 163)
.addComponent(ButtonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(86, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblTwitter1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtTwitter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblPhone, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblProvider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(comboProvider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(46, 46, 46)
.addComponent(ButtonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(54, 54, 54))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void txtTwitterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTwitterActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtTwitterActionPerformed
private void ButtonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonStartActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_ButtonStartActionPerformed
private void ButtonStartMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ButtonStartMouseClicked
// TODO add your handling code here:
if(GlobalVars.StartLoop == false){
GlobalVars.UserPhone = this.txtPhone.getText();
GlobalVars.UserTwitter = this.txtTwitter.getText();
GlobalVars.UserProvider = this.comboProvider.getSelectedIndex();
GlobalVars.StartLoop = true;
this.ButtonStart.setEnabled(false);
this.ButtonStart.setText("Running");
String PresetText = GlobalVars.UserPhone + " " + GlobalVars.UserTwitter + " " + GlobalVars.UserProvider;
CharSequence CharPreset = new StringBuilder(PresetText);
try {
Files.writeString(GlobalVars.UserPresetsPath, CharPreset);
} catch (IOException ex) {
Logger.getLogger(OpeningMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_ButtonStartMouseClicked
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
// TODO add your handling code here:
this.txtPhone.setText(GlobalVars.UserPhone);
this.txtTwitter.setText(GlobalVars.UserTwitter);
this.comboProvider.setSelectedIndex(GlobalVars.UserProvider);
}//GEN-LAST:event_formWindowOpened
private void txtPhonePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtPhonePropertyChange
// TODO add your handling code here:
}//GEN-LAST:event_txtPhonePropertyChange
private void txtTwitterPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtTwitterPropertyChange
// TODO add your handling code here:
}//GEN-LAST:event_txtTwitterPropertyChange
private void txtTwitterKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTwitterKeyTyped
// TODO add your handling code here:
if(GlobalVars.StartLoop == true){
this.ButtonStart.setEnabled(true);
this.ButtonStart.setText("Start");
GlobalVars.StartLoop = false;
}
}//GEN-LAST:event_txtTwitterKeyTyped
private void txtPhoneKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPhoneKeyTyped
// TODO add your handling code here:
if(GlobalVars.StartLoop == true){
this.ButtonStart.setEnabled(true);
this.ButtonStart.setText("Start");
GlobalVars.StartLoop = false;
}
}//GEN-LAST:event_txtPhoneKeyTyped
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(OpeningMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(OpeningMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(OpeningMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(OpeningMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//Read UserPresets.txt file
// Put values read from it into GlobalVars.
GlobalVars.UserPresetsPath = Paths.get("UserPresets.txt");
boolean UserPresetFileExists = Files.exists(GlobalVars.UserPresetsPath);
List<String> UserText = new ArrayList<>();
if(UserPresetFileExists){
try {
UserText = Files.readAllLines(GlobalVars.UserPresetsPath);
} catch (IOException ex) {
Logger.getLogger(OpeningMenu.class.getName()).log(Level.SEVERE, null, ex);
}
String UserPreset = UserText.get(0);
String[] UserChunks = UserPreset.split(" ");
GlobalVars.UserPhone = UserChunks[0];
GlobalVars.UserTwitter = UserChunks[1];
GlobalVars.UserProvider = StringToDigit(UserChunks[2]);
}
else{
//create file
try {
Files.createFile(GlobalVars.UserPresetsPath);
} catch (IOException ex) {
Logger.getLogger(OpeningMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new OpeningMenu().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton ButtonStart;
private javax.swing.JComboBox<String> comboProvider;
private javax.swing.JLabel lblPhone;
private javax.swing.JLabel lblProvider;
private javax.swing.JLabel lblTwitter1;
private javax.swing.JTextField txtPhone;
private javax.swing.JTextField txtTwitter;
// End of variables declaration//GEN-END:variables
}