Skip to content
Snippets Groups Projects
Commit 210d8266 authored by Niharika K's avatar Niharika K
Browse files

Styling

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1218 additions and 0 deletions
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Help.iml" filepath="$PROJECT_DIR$/Help.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/help-master.iml" filepath="$PROJECT_DIR$/help-master.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
/build
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.nimal.help"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
}
apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
{
"project_info": {
"project_number": "530240925370",
"firebase_url": "https://help-1c955.firebaseio.com",
"project_id": "help-1c955",
"storage_bucket": "help-1c955.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:530240925370:android:42cd6510307aba93",
"android_client_info": {
"package_name": "com.example.nimal.help"
}
},
"oauth_client": [
{
"client_id": "530240925370-tel8td0ev46gm3o2mdkiejsn71ohrsr6.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBrQfhD_REsMGJ3K_n9E_JNVQwdkDrva-c"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Nimal\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.example.nimal.help;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.example.nimal.help", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nimal.help">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/saving_lives"
android:label="Saving Lives"
android:roundIcon="@drawable/saving_lives"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AddUser" />
<activity android:name=".Admin_login" />
<activity android:name=".Login1" />
<activity android:name=".Add_Hosp" />
<activity android:name=".Location" />
<activity android:name=".View_Hosp" />
<activity android:name=".Remove_Hosp" />
<activity android:name=".Edit_Hosp" />
<activity android:name=".User1" />
<activity android:name=".Help"></activity>
</application>
</manifest>
\ No newline at end of file
package com.example.nimal.help;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class AddUser extends AppCompatActivity implements View.OnClickListener {
private EditText e_mail, pass;
private Button b;
private ProgressDialog pd;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_user);
firebaseAuth = FirebaseAuth.getInstance();
pd = new ProgressDialog(this);
b = (Button) findViewById(R.id.button);
e_mail = (EditText)findViewById(R.id.editText2);
pass = (EditText)findViewById(R.id.editText3) ;
b.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == b) {
final String em = e_mail.getText().toString();
final String pa = pass.getText().toString();
if (TextUtils.isEmpty(em)) {
Toast.makeText(this, "Please Enter Your Email Id", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(pa)) {
Toast.makeText(this, "Please Enter A Password", Toast.LENGTH_SHORT).show();
return;
}
pd.setMessage("Registering User ...");
pd.setCancelable(false);
pd.show();
firebaseAuth.createUserWithEmailAndPassword(em, pa).
addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
pd.dismiss();
Toast.makeText(getApplicationContext(), "Registration Successful", Toast.LENGTH_SHORT).show();
}
else {
pd.dismiss();
Toast.makeText(getApplicationContext(), "Registration Failed", Toast.LENGTH_SHORT).show();
}
}
});
}
}
public void onBackPressed()
{
Intent i = new Intent(this,Login1.class);
startActivity(i);
}
}
package com.example.nimal.help;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class Add_Hosp extends AppCompatActivity implements View.OnClickListener {
private FirebaseAuth firebaseAuth;
private FirebaseUser firebaseUser;
private DatabaseReference databaseReference;
ProgressDialog progressDialog;
public static int COUNT ;
public static String str;
EditText hname, hcity, latitude, longitude, spec, phno;
EditText rb;
Button add;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add__hosp);
firebaseAuth = FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser() == null) {
Toast.makeText(this, "No User has loged in !!", Toast.LENGTH_SHORT).show();
}
firebaseUser = firebaseAuth.getCurrentUser();
databaseReference = FirebaseDatabase.getInstance().getReference();
hname = (EditText) findViewById(R.id.hname);
hcity = (EditText) findViewById(R.id.hcity);
latitude = (EditText) findViewById(R.id.latitude);
longitude = (EditText) findViewById(R.id.longitude);
spec = (EditText)findViewById(R.id.speciality);
phno = (EditText)findViewById(R.id.phno);
rb = (EditText)findViewById(R.id.Rating);
add = (Button)findViewById(R.id.add);
add.setOnClickListener(this);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
progressDialog.show();
databaseReference.child("Hospital").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
for(DataSnapshot data : dataSnapshot.getChildren())
{
str = data.getKey();
//Toast.makeText(Add_Hosp.this, str, Toast.LENGTH_SHORT).show();
COUNT = Integer.parseInt(str);
}
progressDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError)
{
Toast.makeText(getApplicationContext(), "Server is Busy..", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onClick(View v) {
if (v == add) {
String name, city, lat, lon, sp, ph,rating;
name = hname.getText().toString().trim();
city = hcity.getText().toString().trim();
lat = latitude.getText().toString().trim();
lon = longitude.getText().toString().trim();
sp = spec.getText().toString().trim();
ph = phno.getText().toString().trim();
rating = rb.getText().toString().trim();
//Toast.makeText(this, name, Toast.LENGTH_SHORT).show();
//Toast.makeText(this, city, Toast.LENGTH_SHORT).show();
//databaseReference.child("Hospital").child("Hospital Name").setValue(name);
COUNT = COUNT+1;
databaseReference.child("Hospital").child(String.valueOf(COUNT)).child("Name").setValue(name);
databaseReference.child("Hospital").child(String.valueOf(COUNT)).child("City").setValue(city);
databaseReference.child("Hospital").child(String.valueOf(COUNT)).child("Latitude").setValue(lat);
databaseReference.child("Hospital").child(String.valueOf(COUNT)).child("Longitude").setValue(lon);
databaseReference.child("Hospital").child(String.valueOf(COUNT)).child("Speciality").setValue(sp);
databaseReference.child("Hospital").child(String.valueOf(COUNT)).child("Phone").setValue(ph);
databaseReference.child("Hospital").child(String.valueOf(COUNT)).child("Rating").setValue(rating);
Toast.makeText(this, "Data Saved !!", Toast.LENGTH_SHORT).show();
}
}
public void onBackPressed()
{
Intent i = new Intent(Add_Hosp.this,Login1.class);
startActivity(i);
}
}
package com.example.nimal.help;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class Admin_login extends AppCompatActivity {
EditText ed1,ed2;
public ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
SharedPreferences sharedpreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_login);
firebaseAuth = FirebaseAuth.getInstance();
if(firebaseAuth.getCurrentUser() != null)
{
firebaseAuth.signOut();
}
progressDialog = new ProgressDialog(this);
}
public void signup(View view)
{
ed1 = (EditText) findViewById(R.id.Email);
ed2 = (EditText) findViewById(R.id.Password);
final String email = ed1.getText().toString();
final String password = ed2.getText().toString();
progressDialog.setMessage("Authenticating User!!!");
progressDialog.setCancelable(false);
progressDialog.show();
firebaseAuth.signInWithEmailAndPassword(email,password).
addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
progressDialog.dismiss();
nexting(email);
}
else
{
progressDialog.dismiss();
Toast.makeText(Admin_login.this, "Credentials wrong", Toast.LENGTH_SHORT).show();
}
}
});
}
public void nexting(String email)
{
sharedpreferences = getSharedPreferences("User_Name", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("Email",email);
editor.commit();
Intent i = new Intent(this,Login1.class);
startActivity(i);
}
}
package com.example.nimal.help;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class Edit_Hosp extends AppCompatActivity {
TextView tv;
EditText key,value,parent;
DatabaseReference databaseReference,db;
ProgressDialog progressDialog;
SharedPreferences sharedPreferences;
public static String srt,str;
public static int count;
public static StringBuffer sb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit__hosp);
tv = (TextView)findViewById(R.id.ShowDetails1);
key = (EditText)findViewById(R.id.Key);
value = (EditText)findViewById(R.id.Value);
parent = (EditText)findViewById(R.id.Parent);
//sharedPreferences = getSharedPreferences("Remove_Data", Context.MODE_PRIVATE);
databaseReference = FirebaseDatabase.getInstance().getReference();
progressDialog = new ProgressDialog(this);
//String str = sharedPreferences.getString("String",null);
//tv.setText(str);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
progressDialog.show();
databaseReference.child("Hospital").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
for(DataSnapshot data : dataSnapshot.getChildren())
{
srt = data.getKey();
//Toast.makeText(Add_Hosp.this, str, Toast.LENGTH_SHORT).show();
count = Integer.parseInt(srt);
}
progressDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError)
{
Toast.makeText(getApplicationContext(), "Server is Busy..", Toast.LENGTH_SHORT).show();
}
});
}
public void update(View view)
{
db = FirebaseDatabase.getInstance().getReference("https://help-1c955.firebaseio.com/Hospital");
final String parenting = key.getText().toString().trim();
final String keying = key.getText().toString().trim();
final String valueing = value.getText().toString().trim();
//Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
db.child(parenting).getRef().child(keying).setValue(valueing);
/* databaseReference.child("Hospital").child(parenting).child(keying).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot data: dataSnapshot.getChildren())
{
data.getRef().child(parenting).child(keying).setValue(valueing);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(), "Server is Busy..", Toast.LENGTH_SHORT).show();
}
});*/
}
public void read(View view)
{
sb = new StringBuffer();
for (int i = 0; i <= count; i++) {
databaseReference.child("Hospital").child(String.valueOf(i)).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) {
sb.append(data.getKey() + " : " + data.getValue().toString() + "\n");
}
sb.append("\n");
Toast.makeText(Edit_Hosp.this, sb, Toast.LENGTH_SHORT).show();
//view1.setText(sb.toString());
str = sb.toString();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(), "Server is Busy..", Toast.LENGTH_SHORT).show();
}
});
}
}
public void refresh(View view)
{
tv.setText(str);
}
public void onBackPressed()
{
Intent i = new Intent(this,Login1.class);
startActivity(i);
}
}
package com.example.nimal.help;
/**
* Created by Nimal on 23/04/2017.
*/
import android.Manifest;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
public class GPSTracker extends Service implements LocationListener {
private final Context mContext;
// flag for GPS status
boolean isGPSEnabled = false;
// flag for network status
boolean isNetworkEnabled = false;
boolean canGetLocation = false;
Location location; // location
double latitude; // latitude
double longitude; // longitude
// The minimum distance to change Updates in meters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
// The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute
// Declaring a Location Manager
protected LocationManager locationManager;
public GPSTracker(Context context) {
this.mContext = context;
getLocation();
}
public Location getLocation() {
if (Build.VERSION.SDK_INT >= 23 &&
ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
}
if (Build.VERSION.SDK_INT >= 23 &&
ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
}
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
// First get location from Network Provider
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
@Override
public void onLocationChanged(Location location)
{
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
public double getLatitude() {
if (location != null) {
latitude = location.getLatitude();
}
// return latitude
return latitude;
}
/**
* Function to get longitude
* */
public double getLongitude() {
if (location != null) {
longitude = location.getLongitude();
}
// return longitude
return longitude;
}
public boolean canGetLocation() {
return this.canGetLocation;
}
/**
* Function to show settings alert dialog
* */
public void showSettingsAlert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
// Setting Dialog Title
alertDialog.setTitle("GPS is settings");
// Setting Dialog Message
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
// Setting Icon to Dialog
//alertDialog.setIcon(R.drawable.delete);
// On pressing Settings button
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});
// on pressing cancel button
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
public void stopUsingGPS() {
if (locationManager != null) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
locationManager.removeUpdates(GPSTracker.this);
}
}
}
package com.example.nimal.help;
import android.app.ProgressDialog;
import android.content.Intent;
import android.media.Rating;
import android.net.Uri;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.math.*;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
public class Help extends AppCompatActivity {
private static final int REQUEST_CODE_PERMISSION = 2;
public static double latitude;
public static double longitude;
String mPermission = android.Manifest.permission.ACCESS_FINE_LOCATION;
GPSTracker gps;
EditText area,city;
ProgressDialog progressDialog;
TextView show;
static StringBuffer sb,sb1;
static String str,srt,phone,ar;
static int count,fun,nuf;
static double dist=1000000000,rand;
static double hi[] = new double[2] ;
static int round = 0;
DatabaseReference databaseReference;
Snackbar s;
CoordinatorLayout coordinatorLayout1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
databaseReference = FirebaseDatabase.getInstance().getReference();
area = (EditText)findViewById(R.id.Area);
show = (TextView)findViewById(R.id.ShowSugg);
coordinatorLayout1 = (CoordinatorLayout)findViewById(R.id.coordinatorLayout);
sb = new StringBuffer();
sb1 = new StringBuffer();
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
progressDialog.show();
databaseReference.child("Hospital").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
for(DataSnapshot data : dataSnapshot.getChildren())
{
srt = data.getKey();
//Toast.makeText(Add_Hosp.this, str, Toast.LENGTH_SHORT).show();
count = Integer.parseInt(srt);
}
progressDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError)
{
Toast.makeText(getApplicationContext(), "Server is Busy..", Toast.LENGTH_SHORT).show();
}
});
}
public void retreival(View view)
{
gps = new GPSTracker(Help.this);
// check if GPS enabled
if (gps.canGetLocation()) {
latitude = gps.getLatitude();
longitude = gps.getLongitude();
s = Snackbar.make(coordinatorLayout1,"Latitude : "+latitude+"\nLongitude : "+longitude,Snackbar.LENGTH_LONG)
.setAction("HIDE", new View.OnClickListener() {
@Override
public void onClick(View v) {
s.dismiss();
}
});
//Toast.makeText(this, latitude+" , "+longitude, Toast.LENGTH_SHORT).show();
s.show();
}
else
{
gps.showSettingsAlert();
}
for (int i = 0; i <= count; i++) {
databaseReference.child("Hospital").child(String.valueOf(i)).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) {
sb.append(data.getKey()+" : "+data.getValue().toString() + "\n");
round = 1;
}
if(round == 1) {
sb.append("\n");
round = 0;
}
//Toast.makeText(View_Hosp.this, sb, Toast.LENGTH_SHORT).show();
//view1.setText(sb.toString());
str = sb.toString();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(), "Server is Busy..", Toast.LENGTH_SHORT).show();
}
});
}
}
public void suggestion(View view)
{
String areas = area.getText().toString().trim();
String[] ss = str.split("\n\n");
int r=0;
for(int i=0;i<count;i++)
{
String ss1[] = ss[i].split("\n");
if(ss[i].contains(areas))
{
//sb1.append(ss[i]);
double r1 = lol(ss1[1]);
double r2 = lol(ss1[2]);
rand = Math.hypot(Math.abs(r1-latitude),Math.abs(r2-longitude));
if((rand < dist && (lol(ss1[5]))>4))
{
dist = rand;
hi[0] = dist;
fun = i;
ar = ss[1];
//show.setText(ss[i]);
}
else if(rand < dist && (lol(ss1[5]))<4)
{
dist = rand;
hi[1] = dist;
nuf = i;
ar = ss[1];
//show.setText(ss[i]);
}
else if(!ss[i].contains(ar))
{
dist = rand;
hi[0] = dist;
hi[1] = dist;
fun = i;
}
}
else
{
r = r+1;
}
}
// r=r-1;
if(r==count)
{
show.setText("Speciality Not found");
}
else {
if (Math.abs(hi[0] - hi[1]) < 1) {
phone = ss[fun];
show.setText(ss[fun]);
} else {
phone = ss[fun];
show.setText(ss[nuf]);
}
}
}
public double lol(String s)
{
String [] r = s.split(" : ");
double f = Double.parseDouble(r[1]);
return f;
}
public void newing(View view)
{
FloatingActionButton fab1 = (FloatingActionButton)findViewById(R.id.floatingActionButton2);
FloatingActionButton fab2 = (FloatingActionButton)findViewById(R.id.floatingActionButton3);
fab1.setVisibility(view.VISIBLE);
fab2.setVisibility(view.VISIBLE);
}
public void call(View view)
{
String[] number1 = phone.split("\n");
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+number1[4]));
startActivity(intent);
}
public void messaging(View view)
{
String[] number1 = phone.split("\n");
String[] number2 = number1[4].split(" : ");
Intent intentsms = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + number2[1] ) );
intentsms.putExtra( "Emergeny", "Bringing a patient" );
startActivity( intentsms );
//startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number1[4], "hello")));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment