-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.java
198 lines (129 loc) · 3.9 KB
/
MainActivity.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
package com.d_andaman;
import java.net.MalformedURLException;
import java.net.URL;
import com.d_andaman.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
private Button btnLogin;
//private Button btnLinkToRegister;
private EditText inputEmail;
//private EditText inputPassword;
private ProgressDialog pDialog;
private TextView status;
private Button menu;
private static int id;
private static String phone_no;
private URL url ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
hideSystemUI();
//fetch_weather();
//Get_weather.get_weather();
inputEmail = (EditText) findViewById(R.id.email);
//inputPassword = (EditText) findViewById(R.id.password);
btnLogin = (Button) findViewById(R.id.btnLogin);
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);
btnLogin.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String email = inputEmail.getText().toString().trim();
int internet;
if (!email.isEmpty()) {
if(email.length()==10){
internet=check_internet();
//int id=getid();
if(internet==1){
int id=1;
if(id!=0){
Intent i = new Intent(getApplicationContext(),
New_menu.class);
startActivity(i);
}else{login();}
}else{ Intent i = new Intent(getApplicationContext(),
Startpopup.class);
startActivity(i);
}
}else{Toast.makeText(getApplicationContext(),
"Please enter the correct phone number", Toast.LENGTH_SHORT).show(); }
}else {Toast.makeText(getApplicationContext(),
"Please enter the credentials!", Toast.LENGTH_SHORT).show(); }
}
});
try {
int w_id=1;
url = new URL("http:https://192.168.83.1/dand_api/weather.php?w_id="+w_id);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
private void fetch_weather() {
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
new Weather(getBaseContext()).execute(url);
}
else
{
status.setText("No network connection available.");
}
}
private int check_internet() {
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {return 1;}
else
{return 0;}
}
private void hideSystemUI() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE
);
}
public void login(){
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
String phone = inputEmail.getText().toString();
new Login(getBaseContext(),1).execute(phone);
}
else
{
//setid(-1);
//status.setText("No network connection available.");
}
}
public static void setid(int i){
id=i;
}
public static int getid(){
return id;
}
public static void setphone(String i){
phone_no=i;
}
public static String getphone(){
return phone_no;
}
}