-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
105 lines (93 loc) · 4.71 KB
/
MainActivity.java
File metadata and controls
105 lines (93 loc) · 4.71 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
package com.example.trippe;
import android.content.ClipData;
import android.content.Context;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import com.example.trippe.util.Utility;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.menu.MenuView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import android.database.sqlite.*;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
private static final int PERMISSION_REQUEST_CODE = 200;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO Remove this and implement a threaded query for web stuff
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
// No permissions lets request them
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.INTERNET},
this.PERMISSION_REQUEST_CODE);
Log.i("MainActivity", "Got INTERNET Permissions");
} else {
Log.i("MainActivity", "Already have INTERNET Permissions");
}
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) {
// No permissions lets request them
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_NETWORK_STATE},
this.PERMISSION_REQUEST_CODE);
Log.i("MainActivity", "Got ACCESS_NETWORK_STATE Permissions");
} else {
Log.i("MainActivity", "Already have ACCESS_NETWORK_STATE Permissions");
}
setContentView(R.layout.activity_main);
BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
//creating database when application starts
SQLiteDatabase trippeDatabase = null;
try {
trippeDatabase = openOrCreateDatabase("TrippeDatabase", MODE_PRIVATE, null);
//trippeDatabase.execSQL("DROP TABLE IF EXISTS Trips");
trippeDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + "Trips (" +
"tripId VARCHAR(255) NOT NULL, " +
"tripFlagIndicator INT(255) NOT NULL, " +
"destinationCity VARCHAR(255) NOT NULL, " +
"destinationState VARCHAR(255), " +
"destinationZipCode INT(255), " +
"destinationCountry VARCHAR(255) NOT NULL, " +
"startDate VARCHAR(255) NOT NULL, " +
"endDate VARCHAR(255) NOT NULL, " +
"milesAwayFromHome INT NOT NULL, " +
"timeZone VARCHAR(255) NOT NULL, " +
"currency VARCHAR(255) NOT NULL, " +
"languages VARCHAR(255) NOT NULL, " +
"PRIMARY KEY (tripId));");
trippeDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + "Events (" +
"eventId VARCHAR(255) NOT NULL, " +
"eventDate VARCHAR(255) NOT NULL, " +
"eventStartTime VARCHAR(255) NOT NULL, " +
"eventEndTime VARCHAR(255) NOT NULL, " +
"eventName VARCHAR(255) NOT NULL, " +
"eventLocation VARCHAR(255) NOT NULL, " +
"tripId VARCHAR(255) NOT NULL, " +
"PRIMARY KEY (eventId));");
} catch (Exception e) {
Log.d("Error: ", e.getMessage());
} finally {
trippeDatabase.close();
}
}
}