Skip to content

Commit e2c47ed

Browse files
author
hussienalrubaye
committed
find my phone
1 parent a7a438c commit e2c47ed

File tree

8 files changed

+120
-13
lines changed

8 files changed

+120
-13
lines changed

FindMyPhone Assets/snaped_code.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void SaveData(){
147147
if (MyTrackersList.length()==0)
148148
MyTrackersList=m.getKey() + "%" + m.getValue();
149149
else
150-
MyTrackersList+= m.getKey() + "%" + m.getValue();
150+
MyTrackersList =MyTrackersList+ "%" + m.getKey() + "%" + m.getValue();
151151

152152
}
153153

MyTracker/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MyTracker/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626
})
2727
compile 'com.android.support:appcompat-v7:24.2.1'
2828
compile 'com.google.firebase:firebase-core:9.6.1'
29-
compile 'com.google.android.gms:play-services:9.6.1'
29+
compile 'com.google.android.gms:play-services-maps:9.6.1'
3030
compile 'com.google.firebase:firebase-database:9.6.1'
3131
testCompile 'junit:junit:4.12'
3232
}

MyTracker/app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
1111
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
1212
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
13+
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
14+
1315
<application
1416
android:allowBackup="true"
15-
android:icon="@mipmap/ic_launcher"
17+
android:icon="@drawable/cover"
1618
android:label="@string/app_name"
1719
android:supportsRtl="true"
1820
android:theme="@style/AppTheme">
@@ -43,6 +45,14 @@
4345
android:name=".MapsActivity"
4446
android:label="@string/title_activity_maps"></activity>
4547
<service android:name=".MyServie"></service>
48+
<receiver android:name=".RunithOS">
49+
50+
<intent-filter android:priority="2147483647">
51+
<action android:name="android.intent.action.BOOT_COMPLETED"/>
52+
<category android:name="android.intent.category.DEFAULT"></category>
53+
</intent-filter>
54+
55+
</receiver>
4656
</application>
4757

4858
</manifest>

MyTracker/app/src/main/java/com/alrubaye/mytracker/GlobalInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public static String FormatPhoneNumber(String Oldnmber){
4242
}
4343
}
4444

45-
4645
Context context;
4746
SharedPreferences ShredRef;
4847
public GlobalInfo(Context context){
@@ -56,7 +55,7 @@ void SaveData(){
5655
if (MyTrackersList.length()==0)
5756
MyTrackersList=m.getKey() + "%" + m.getValue();
5857
else
59-
MyTrackersList+= m.getKey() + "%" + m.getValue();
58+
MyTrackersList+= "%"+m.getKey() + "%" + m.getValue();
6059

6160
}
6261

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

7372
void LoadData(){
7473
MyTrackers.clear();
75-
PhoneNumber= ShredRef.getString("PhoneNumber","empty");
74+
PhoneNumber= ShredRef.getString("PhoneNumber","empty");
7675
String MyTrackersList= ShredRef.getString("MyTrackers","empty");
7776
if (!MyTrackersList.equals("empty")){
7877
String[] users=MyTrackersList.split("%");
@@ -91,4 +90,5 @@ void LoadData(){
9190

9291
}
9392

93+
9494
}

MyTracker/app/src/main/java/com/alrubaye/mytracker/MainActivity.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.view.MenuItem;
1919
import android.view.View;
2020
import android.view.ViewGroup;
21+
import android.widget.AdapterView;
2122
import android.widget.BaseAdapter;
2223
import android.widget.ListView;
2324
import android.widget.TextView;
@@ -49,8 +50,24 @@ protected void onCreate(Bundle savedInstanceState) {
4950

5051
myadapter=new MyCustomAdapter(listnewsData);
5152
ListView lsNews=(ListView)findViewById(R.id.listView);
53+
lsNews.setOnItemClickListener(new AdapterView.OnItemClickListener() {
54+
@Override
55+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
56+
AdapterItems adapterItems=listnewsData.get(position);
57+
GlobalInfo.UpdatesInfo(adapterItems.PhoneNumber);
58+
Intent intent= new Intent(getApplicationContext(),MapsActivity.class);
59+
intent.putExtra("PhoneNumber",adapterItems.PhoneNumber);
60+
startActivity(intent);
61+
}
62+
});
5263
lsNews.setAdapter(myadapter);//intisal with data
53-
// Refesh();
64+
65+
}
66+
67+
@Override
68+
public void onResume(){
69+
super.onResume();
70+
Refesh();
5471
}
5572

5673
void Refesh(){
Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.alrubaye.mytracker;
22

3+
import android.database.Cursor;
4+
import android.provider.ContactsContract;
35
import android.support.v4.app.FragmentActivity;
46
import android.os.Bundle;
57

@@ -9,22 +11,64 @@
911
import com.google.android.gms.maps.SupportMapFragment;
1012
import com.google.android.gms.maps.model.LatLng;
1113
import com.google.android.gms.maps.model.MarkerOptions;
14+
import com.google.firebase.database.DataSnapshot;
15+
import com.google.firebase.database.DatabaseError;
16+
import com.google.firebase.database.DatabaseReference;
17+
import com.google.firebase.database.FirebaseDatabase;
18+
import com.google.firebase.database.ValueEventListener;
19+
20+
import java.util.ArrayList;
21+
import java.util.HashMap;
22+
import java.util.Map;
1223

1324
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
1425

1526
private GoogleMap mMap;
16-
27+
DatabaseReference databaseReference;
1728
@Override
1829
protected void onCreate(Bundle savedInstanceState) {
1930
super.onCreate(savedInstanceState);
2031
setContentView(R.layout.activity_maps);
32+
databaseReference= FirebaseDatabase.getInstance().getReference();
33+
Bundle b=getIntent().getExtras();
34+
LoadLocation(b.getString("PhoneNumber"));
35+
36+
}
37+
38+
void LoadLocation(String PhoneNumber){
39+
databaseReference.child("Users").child(PhoneNumber).
40+
child("Location").addValueEventListener(new ValueEventListener() {
41+
@Override
42+
public void onDataChange(DataSnapshot dataSnapshot) {
43+
44+
Map<String, Object> td = (HashMap<String, Object>) dataSnapshot.getValue();
45+
46+
double lat = Double.parseDouble(td.get("lat").toString());
47+
double lag = Double.parseDouble(td.get("lag").toString());
48+
/** Make sure that the map has been initialised **/
49+
sydney = new LatLng(lat, lag);
50+
LastDateOnline= td.get("LastOnlineDate").toString();
51+
LoadMap();
52+
53+
}
54+
55+
@Override
56+
public void onCancelled(DatabaseError error) {
57+
// Failed to read value
58+
// Log.w(TAG, "Failed to read value.", error.toException());
59+
}
60+
});
61+
62+
}
63+
64+
65+
void LoadMap(){
2166
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
2267
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
2368
.findFragmentById(R.id.map);
2469
mapFragment.getMapAsync(this);
2570
}
2671

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

4187
// Add a marker in Sydney and move the camera
42-
LatLng sydney = new LatLng(-34, 151);
43-
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
44-
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
88+
89+
mMap.addMarker(new MarkerOptions().position(sydney).title("last online:"+ LastDateOnline));
90+
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,15));
4591
}
4692
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.alrubaye.mytracker;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.location.LocationManager;
7+
8+
/**
9+
* Created by hussienalrubaye on 9/26/16.
10+
*/
11+
12+
public class RunithOS extends BroadcastReceiver {
13+
14+
15+
@Override
16+
public void onReceive(Context context, Intent intent) {
17+
18+
if (intent.getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")){
19+
GlobalInfo globalInfo= new GlobalInfo(context);
20+
globalInfo.LoadData();
21+
//start location track
22+
if (!TrackLocation.isRunning){
23+
TrackLocation trackLocation = new TrackLocation();
24+
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
25+
26+
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, trackLocation);
27+
}
28+
if (!MyServie.IsRunning){
29+
Intent intent1=new Intent(context,MyServie.class);
30+
context.startService(intent1);
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)