1 /**********************************************************************
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
9 **********************************************************************
10 This file is part of Solar Compass.
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.
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.
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 **********************************************************************/
26 package com
.agnibho
.android
.solarcompass
;
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
;
36 public class LocationActivity
extends AppCompatActivity
{
37 LocationData location
= LocationData
.getInstance();
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);
50 final TextView latText
=(TextView
)findViewById(R
.id
.editText
);
51 if(location
.isAvailable()) {
52 latText
.setText(Double
.toString(location
.getLatitude()));
57 final TextView lonText
=(TextView
)findViewById(R
.id
.editText2
);
58 if(location
.isAvailable()) {
59 lonText
.setText(Double
.toString(location
.getLongitude()));
64 Button setBtn
=(Button
)findViewById(R
.id
.button
);
65 setBtn
.setOnClickListener(new View
.OnClickListener() {
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
);
76 Toast
.makeText(getApplicationContext(), "Invalid longitude", Toast
.LENGTH_LONG
).show();
78 lonText
.requestFocus();
81 Toast
.makeText(getApplicationContext(), "Invalid longitude", Toast
.LENGTH_LONG
).show();
83 latText
.requestFocus();