Skip to content

Commit

Permalink
find my phone
Browse files Browse the repository at this point in the history
  • Loading branch information
hussienalrubaye committed Sep 27, 2016
1 parent a7a438c commit e2c47ed
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 13 deletions.
2 changes: 1 addition & 1 deletion FindMyPhone Assets/snaped_code.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void SaveData(){
if (MyTrackersList.length()==0)
MyTrackersList=m.getKey() + "%" + m.getValue();
else
MyTrackersList+= m.getKey() + "%" + m.getValue();
MyTrackersList =MyTrackersList+ "%" + m.getKey() + "%" + m.getValue();

}

Expand Down
2 changes: 1 addition & 1 deletion MyTracker/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MyTracker/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.google.android.gms:play-services-maps:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'
testCompile 'junit:junit:4.12'
}
Expand Down
12 changes: 11 additions & 1 deletion MyTracker/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/cover"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Expand Down Expand Up @@ -43,6 +45,14 @@
android:name=".MapsActivity"
android:label="@string/title_activity_maps"></activity>
<service android:name=".MyServie"></service>
<receiver android:name=".RunithOS">

<intent-filter android:priority="2147483647">
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>

</receiver>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static String FormatPhoneNumber(String Oldnmber){
}
}


Context context;
SharedPreferences ShredRef;
public GlobalInfo(Context context){
Expand All @@ -56,7 +55,7 @@ void SaveData(){
if (MyTrackersList.length()==0)
MyTrackersList=m.getKey() + "%" + m.getValue();
else
MyTrackersList+= m.getKey() + "%" + m.getValue();
MyTrackersList+= "%"+m.getKey() + "%" + m.getValue();

}

Expand All @@ -72,7 +71,7 @@ void SaveData(){

void LoadData(){
MyTrackers.clear();
PhoneNumber= ShredRef.getString("PhoneNumber","empty");
PhoneNumber= ShredRef.getString("PhoneNumber","empty");
String MyTrackersList= ShredRef.getString("MyTrackers","empty");
if (!MyTrackersList.equals("empty")){
String[] users=MyTrackersList.split("%");
Expand All @@ -91,4 +90,5 @@ void LoadData(){

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
Expand Down Expand Up @@ -49,8 +50,24 @@ protected void onCreate(Bundle savedInstanceState) {

myadapter=new MyCustomAdapter(listnewsData);
ListView lsNews=(ListView)findViewById(R.id.listView);
lsNews.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AdapterItems adapterItems=listnewsData.get(position);
GlobalInfo.UpdatesInfo(adapterItems.PhoneNumber);
Intent intent= new Intent(getApplicationContext(),MapsActivity.class);
intent.putExtra("PhoneNumber",adapterItems.PhoneNumber);
startActivity(intent);
}
});
lsNews.setAdapter(myadapter);//intisal with data
// Refesh();

}

@Override
public void onResume(){
super.onResume();
Refesh();
}

void Refesh(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.alrubaye.mytracker;

import android.database.Cursor;
import android.provider.ContactsContract;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

Expand All @@ -9,22 +11,64 @@
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
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;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
databaseReference= FirebaseDatabase.getInstance().getReference();
Bundle b=getIntent().getExtras();
LoadLocation(b.getString("PhoneNumber"));

}

void LoadLocation(String PhoneNumber){
databaseReference.child("Users").child(PhoneNumber).
child("Location").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

Map<String, Object> td = (HashMap<String, Object>) dataSnapshot.getValue();

double lat = Double.parseDouble(td.get("lat").toString());
double lag = Double.parseDouble(td.get("lag").toString());
/** Make sure that the map has been initialised **/
sydney = new LatLng(lat, lag);
LastDateOnline= td.get("LastOnlineDate").toString();
LoadMap();

}

@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
// Log.w(TAG, "Failed to read value.", error.toException());
}
});

}


void LoadMap(){
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}


/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
Expand All @@ -34,13 +78,15 @@ protected void onCreate(Bundle savedInstanceState) {
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
LatLng sydney ;
String LastDateOnline;
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

mMap.addMarker(new MarkerOptions().position(sydney).title("last online:"+ LastDateOnline));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,15));
}
}
34 changes: 34 additions & 0 deletions MyTracker/app/src/main/java/com/alrubaye/mytracker/RunithOS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.alrubaye.mytracker;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;

/**
* Created by hussienalrubaye on 9/26/16.
*/

public class RunithOS extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {

if (intent.getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")){
GlobalInfo globalInfo= new GlobalInfo(context);
globalInfo.LoadData();
//start location track
if (!TrackLocation.isRunning){
TrackLocation trackLocation = new TrackLocation();
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, trackLocation);
}
if (!MyServie.IsRunning){
Intent intent1=new Intent(context,MyServie.class);
context.startService(intent1);
}
}
}
}

0 comments on commit e2c47ed

Please sign in to comment.