-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
187 lines (165 loc) · 5.55 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
package com.my.jeremystevens.gml;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.util.*;
import java.text.*;
import android.app.Activity;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ProgressBar;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import java.text.DecimalFormat;
import android.Manifest;
import android.content.pm.PackageManager;
public class MainActivity extends Activity {
private LinearLayout linear1;
private LinearLayout linear2;
private LinearLayout linear3;
private LinearLayout linear9;
private TextView textview1;
private TextView textview2;
private TextView textview3;
private TextView textview4;
private TextView textview6;
private TextView textview7;
private ProgressBar progressbar1;
private LocationManager lman;
private LocationListener _lman_location_listener;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.main);
initialize(_savedInstanceState);
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {
requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, 1000);
}
else {
initializeLogic();
}
}
else {
initializeLogic();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1000) {
initializeLogic();
}
}
private void initialize(Bundle _savedInstanceState) {
linear1 = (LinearLayout) findViewById(R.id.linear1);
linear2 = (LinearLayout) findViewById(R.id.linear2);
linear3 = (LinearLayout) findViewById(R.id.linear3);
linear9 = (LinearLayout) findViewById(R.id.linear9);
textview1 = (TextView) findViewById(R.id.textview1);
textview2 = (TextView) findViewById(R.id.textview2);
textview3 = (TextView) findViewById(R.id.textview3);
textview4 = (TextView) findViewById(R.id.textview4);
textview6 = (TextView) findViewById(R.id.textview6);
textview7 = (TextView) findViewById(R.id.textview7);
progressbar1 = (ProgressBar) findViewById(R.id.progressbar1);
lman = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
_lman_location_listener = new LocationListener() {
@Override
public void onLocationChanged(Location _param1) {
final double _lat = _param1.getLatitude();
final double _lng = _param1.getLongitude();
final double _acc = _param1.getAccuracy();
if (Build.VERSION.SDK_INT >= 23) {if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
lman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, _lman_location_listener);
}
}
else {
lman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, _lman_location_listener);
}
textview2.setText(String.valueOf(_lat));
textview4.setText(String.valueOf(_lng));
textview7.setText(String.valueOf(_acc));
progressbar1.setIndeterminate(false);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onProviderDisabled(String provider) {}
};
}
private void initializeLogic() {
if (Build.VERSION.SDK_INT >= 23) {if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
lman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, _lman_location_listener);
}
}
else {
lman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, _lman_location_listener);
}
}
@Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
switch (_requestCode) {
default:
break;
}
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
public int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input){
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels(){
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels(){
return getResources().getDisplayMetrics().heightPixels;
}
}