Skip to content

Commit 351f1e0

Browse files
author
hussienalrubaye
committed
tracker
1 parent 75f1edd commit 351f1e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1121
-17
lines changed

FindMyPhone Assets/snaped_code.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,69 @@ public static String FormatPhoneNumber(String Oldnmber){
7676

7777
//**************************************************************
7878

79+
list my tracking
80+
mDatabase.child("FindMyPhoneUsers").child(SettingSaved.PhoneNumber).child("Finders").addValueEventListener(new ValueEventListener() {
81+
@Override
82+
public void onDataChange(DataSnapshot dataSnapshot) {
83+
84+
Map<String, Object> td = (HashMap<String, Object>) dataSnapshot.getValue();
85+
86+
list.clear();
87+
if (td == null) //no one allow you to find him
88+
{
89+
list.add(new ListItem("NoTicket", "no_desc", R.drawable.dmap));
90+
listv.setAdapter(new UserListAdapter(list));
91+
92+
return;
93+
}
94+
// List<Object> values = td.values();
95+
96+
97+
// get all contact to list
98+
ArrayList<ListItem> list_contact = new ArrayList<ListItem>();
99+
Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
100+
while (cursor.moveToNext()) {
101+
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
102+
103+
String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
104+
list_contact.add(new ListItem(name, ManagmentOperations.FormatPhoneNumber(phoneNumber), R.drawable.cover));
105+
106+
107+
}
108+
109+
110+
// if the name is save chane his text
111+
// case who find me
112+
String tinfo;
113+
for ( String Numbers : td.keySet()) {
114+
for (ListItem cs : list_contact) {
115+
116+
//IsFound = SettingSaved.WhoIFindIN.get(cs.Detals); // for case who i could find list
117+
if (cs.PhoneNumber.length() > 0)
118+
if (Numbers.contains(cs.PhoneNumber)) {
119+
list.add(new ListItem(cs.UserName, cs.PhoneNumber, R.drawable.dmap));
120+
break;
121+
}
122+
123+
}
124+
125+
}
126+
// add new one
127+
// list.add(new ListItem("Loading", "no_desc", R.drawable.dmap));
128+
129+
//ask for add users to track you
130+
// if (list.size()==0 && IsDisplayMessage==false) {
131+
// IsDisplayMessage=true;
132+
// ShowNoUsers();
133+
134+
// }
135+
}
136+
137+
@Override
138+
public void onCancelled(DatabaseError error) {
139+
// Failed to read value
140+
// Log.w(TAG, "Failed to read value.", error.toException());
141+
}
142+
});
79143

80144

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ dependencies {
2525
exclude group: 'com.android.support', module: 'support-annotations'
2626
})
2727
compile 'com.android.support:appcompat-v7:24.2.1'
28+
compile 'com.google.firebase:firebase-core:9.6.1'
29+
compile 'com.google.android.gms:play-services:9.6.1'
30+
compile 'com.google.firebase:firebase-database:9.6.1'
2831
testCompile 'junit:junit:4.12'
29-
compile 'com.google.firebase:firebase-core:9.6.0'
3032
}
3133
apply plugin: 'com.google.gms.google-services'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<resources>
2+
<!--
3+
TODO: Before you run your application, you need a Google Maps API key.
4+
5+
To get one, follow this link, follow the directions and press "Create" at the end:
6+
7+
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=76:A0:7B:52:24:16:38:F1:0F:B6:D3:CF:8F:6B:85:5F:92:91:69:DC%3Bcom.alrubaye.mytracker
8+
9+
You can also add your credentials to an existing key, using this line:
10+
76:A0:7B:52:24:16:38:F1:0F:B6:D3:CF:8F:6B:85:5F:92:91:69:DC;com.alrubaye.mytracker
11+
12+
Alternatively, follow the directions here:
13+
https://developers.google.com/maps/documentation/android/start#get-key
14+
15+
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
16+
string in this file.
17+
-->
18+
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
19+
AIzaSyDe4-wGUN_xq-YjfW_6SNRDAlV0DbaYtGU
20+
</string>
21+
</resources>

MyTracker/app/src/main/AndroidManifest.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.alrubaye.mytracker">
44

5+
<!--
6+
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
7+
Google Maps Android API v2, but you must specify either coarse or fine
8+
location permissions for the 'MyLocation' functionality.
9+
-->
10+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
11+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
12+
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
513
<application
614
android:allowBackup="true"
715
android:icon="@mipmap/ic_launcher"
@@ -15,6 +23,26 @@
1523
<category android:name="android.intent.category.LAUNCHER" />
1624
</intent-filter>
1725
</activity>
26+
<activity android:name=".Login" >
27+
28+
</activity>
29+
<activity android:name=".MyTrackers" />
30+
<!--
31+
The API key for Google Maps-based APIs is defined as a string resource.
32+
(See the file "res/values/google_maps_api.xml").
33+
Note that the API key is linked to the encryption key used to sign the APK.
34+
You need a different API key for each encryption key, including the release key that is used to
35+
sign the APK for publishing.
36+
You can define the keys for the debug and release targets in src/debug/ and src/release/.
37+
-->
38+
<meta-data
39+
android:name="com.google.android.geo.API_KEY"
40+
android:value="@string/google_maps_key" />
41+
42+
<activity
43+
android:name=".MapsActivity"
44+
android:label="@string/title_activity_maps"></activity>
45+
<service android:name=".MyServie"></service>
1846
</application>
1947

2048
</manifest>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.alrubaye.mytracker;
2+
3+
/**
4+
* Created by hussienalrubaye on 9/26/16.
5+
*/
6+
7+
public class AdapterItems
8+
{
9+
10+
public String UserName;
11+
public String PhoneNumber;
12+
//for news details
13+
AdapterItems( String UserName,String PhoneNumber)
14+
{
15+
this. UserName=UserName;
16+
this. PhoneNumber=PhoneNumber;
17+
}
18+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.alrubaye.mytracker;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.content.SharedPreferences;
6+
7+
import com.google.firebase.database.DatabaseReference;
8+
import com.google.firebase.database.FirebaseDatabase;
9+
10+
import java.text.DateFormat;
11+
import java.text.SimpleDateFormat;
12+
import java.util.Date;
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
16+
/**
17+
* Created by hussienalrubaye on 9/26/16.
18+
*/
19+
20+
public class GlobalInfo {
21+
public static String PhoneNumber="";
22+
public static Map<String,String> MyTrackers=new HashMap<>();
23+
24+
public static void UpdatesInfo(String UserPhone){
25+
DateFormat df= new SimpleDateFormat("yyyy/MM/dd HH:MM:ss");
26+
Date date= new Date();
27+
DatabaseReference mDatabase= FirebaseDatabase.getInstance().getReference();
28+
mDatabase.child("Users").child(UserPhone).
29+
child("Updates").setValue(df.format(date).toString());
30+
}
31+
32+
public static String FormatPhoneNumber(String Oldnmber){
33+
try{
34+
String numberOnly= Oldnmber.replaceAll("[^0-9]", "");
35+
if(Oldnmber.charAt(0)=='+') numberOnly="+" +numberOnly ;
36+
if (numberOnly.length()>=10)
37+
numberOnly=numberOnly.substring(numberOnly.length()-10,numberOnly.length());
38+
return(numberOnly);
39+
}
40+
catch (Exception ex){
41+
return(" ");
42+
}
43+
}
44+
45+
46+
Context context;
47+
SharedPreferences ShredRef;
48+
public GlobalInfo(Context context){
49+
this.context=context;
50+
ShredRef=context.getSharedPreferences("myRef",Context.MODE_PRIVATE);
51+
}
52+
53+
void SaveData(){
54+
String MyTrackersList="" ;
55+
for (Map.Entry m:GlobalInfo.MyTrackers.entrySet()){
56+
if (MyTrackersList.length()==0)
57+
MyTrackersList=m.getKey() + "%" + m.getValue();
58+
else
59+
MyTrackersList+= m.getKey() + "%" + m.getValue();
60+
61+
}
62+
63+
if (MyTrackersList.length()==0)
64+
MyTrackersList="empty";
65+
66+
67+
SharedPreferences.Editor editor=ShredRef.edit();
68+
editor.putString("MyTrackers",MyTrackersList);
69+
editor.putString("PhoneNumber",PhoneNumber);
70+
editor.commit();
71+
}
72+
73+
void LoadData(){
74+
MyTrackers.clear();
75+
String PhoneNumber= ShredRef.getString("PhoneNumber","empty");
76+
String MyTrackersList= ShredRef.getString("MyTrackersList","empty");
77+
if (!MyTrackersList.equals("empty")){
78+
String[] users=MyTrackersList.split("%");
79+
for (int i=0;i<users.length;i=i+2){
80+
MyTrackers.put(users[i],users[i+1]);
81+
}
82+
}
83+
84+
85+
if (PhoneNumber.equals("empty")){
86+
87+
Intent intent=new Intent(context, Login.class);
88+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
89+
context.startActivity(intent);
90+
}
91+
92+
}
93+
94+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.alrubaye.mytracker;
2+
3+
import android.content.Intent;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.EditText;
8+
9+
public class Login extends AppCompatActivity {
10+
EditText EDTNumber;
11+
@Override
12+
protected void onCreate(Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
setContentView(R.layout.activity_login);
15+
EDTNumber=(EditText)findViewById(R.id.EDTNumber);
16+
}
17+
18+
public void BuNext(View view) {
19+
20+
GlobalInfo.PhoneNumber=GlobalInfo.FormatPhoneNumber(EDTNumber.getText().toString());
21+
GlobalInfo.UpdatesInfo(GlobalInfo.PhoneNumber);
22+
finish();
23+
Intent intent=new Intent(this, MyTrackers.class);
24+
startActivity(intent);
25+
}
26+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,80 @@
11
package com.alrubaye.mytracker;
22

3+
import android.*;
4+
import android.Manifest;
5+
import android.content.Context;
6+
import android.content.Intent;
7+
import android.content.pm.PackageManager;
8+
import android.location.LocationManager;
9+
import android.os.Build;
10+
import android.support.v4.app.ActivityCompat;
311
import android.support.v7.app.AppCompatActivity;
412
import android.os.Bundle;
13+
import android.widget.Toast;
514

615
public class MainActivity extends AppCompatActivity {
716

817
@Override
918
protected void onCreate(Bundle savedInstanceState) {
1019
super.onCreate(savedInstanceState);
1120
setContentView(R.layout.activity_main);
21+
22+
GlobalInfo globalInfo= new GlobalInfo(this);
23+
globalInfo.LoadData();
24+
CheckUserPermsions();
25+
}
26+
27+
void CheckUserPermsions(){
28+
if ( Build.VERSION.SDK_INT >= 23){
29+
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
30+
PackageManager.PERMISSION_GRANTED ){
31+
requestPermissions(new String[]{
32+
android.Manifest.permission.ACCESS_FINE_LOCATION,
33+
Manifest.permission.ACCESS_COARSE_LOCATION },
34+
REQUEST_CODE_ASK_PERMISSIONS);
35+
return ;
36+
}
37+
}
38+
39+
StartServices();
40+
41+
}
42+
//get acces to location permsion
43+
final private int REQUEST_CODE_ASK_PERMISSIONS = 123;
44+
45+
46+
47+
@Override
48+
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
49+
switch (requestCode) {
50+
case REQUEST_CODE_ASK_PERMISSIONS:
51+
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
52+
StartServices();
53+
} else {
54+
// Permission Denied
55+
Toast.makeText( this,"your message" , Toast.LENGTH_SHORT)
56+
.show();
57+
}
58+
break;
59+
default:
60+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
61+
}
62+
}
63+
64+
void StartServices(){
65+
66+
//start location track
67+
if (!TrackLocation.isRunning){
68+
TrackLocation trackLocation = new TrackLocation();
69+
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
70+
71+
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, trackLocation);
72+
}
73+
if (!MyServie.IsRunning){
74+
Intent intent=new Intent(this,MyServie.class);
75+
startService(intent);
76+
}
77+
78+
1279
}
1380
}

0 commit comments

Comments
 (0)