]> Softwares of Agnibho - solarcompass.git/blob - solarcompass/src/main/java/com/agnibho/android/solarcompass/LocationActivity.java
Initial commit
[solarcompass.git] / solarcompass / src / main / java / com / agnibho / android / solarcompass / LocationActivity.java
1 /**********************************************************************
2 * Title: Solar Compass
3 * Description: Android app for finding directions using the sun
4 * Author: Agnibho Mondal
5 * Website: http://code.agnibho.com/solarcompass
6 **********************************************************************
7 Copyright (c) 2016 Agnibho Mondal
8 All rights reserved
9 **********************************************************************
10 This file is part of Solar Compass.
11
12 Solar Compass is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 Solar Compass is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with Solar Compass. If not, see <http://www.gnu.org/licenses/>.
24 **********************************************************************/
25
26 package com.agnibho.android.solarcompass;
27
28 import android.os.Bundle;
29 import android.support.v7.app.AppCompatActivity;
30 import android.support.v7.widget.Toolbar;
31 import android.view.View;
32 import android.widget.Button;
33 import android.widget.TextView;
34 import android.widget.Toast;
35
36 public class LocationActivity extends AppCompatActivity {
37 LocationData location= LocationData.getInstance();
38
39 @Override
40 protected void onCreate(Bundle savedInstanceState) {
41 super.onCreate(savedInstanceState);
42 setContentView(R.layout.activity_location);
43 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
44 setSupportActionBar(toolbar);
45 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
46
47 /**
48 * Latitude
49 */
50 final TextView latText=(TextView)findViewById(R.id.editText);
51 if(location.isAvailable()) {
52 latText.setText(Double.toString(location.getLatitude()));
53 }
54 /**
55 * Longitude
56 */
57 final TextView lonText=(TextView)findViewById(R.id.editText2);
58 if(location.isAvailable()) {
59 lonText.setText(Double.toString(location.getLongitude()));
60 }
61 /**
62 * Button
63 */
64 Button setBtn=(Button)findViewById(R.id.button);
65 setBtn.setOnClickListener(new View.OnClickListener() {
66 @Override
67 public void onClick(View v) {
68 double lt = Double.parseDouble(latText.getText().toString());
69 double ln = Double.parseDouble(lonText.getText().toString());
70 if (lt >= -90 && lt <= 90){
71 if (ln >= -180 && ln <= 180){
72 location.setCoordinate(lt, ln);
73 finish();
74 }
75 else{
76 Toast.makeText(getApplicationContext(), "Invalid longitude", Toast.LENGTH_LONG).show();
77 lonText.setText("");
78 lonText.requestFocus();
79 }
80 } else {
81 Toast.makeText(getApplicationContext(), "Invalid longitude", Toast.LENGTH_LONG).show();
82 latText.setText("");
83 latText.requestFocus();
84 }
85 }
86 });
87 }
88 }