Skip to content

Commit

Permalink
tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
hussienalrubaye committed Sep 27, 2016
1 parent 75f1edd commit 351f1e0
Show file tree
Hide file tree
Showing 47 changed files with 1,121 additions and 17 deletions.
64 changes: 64 additions & 0 deletions FindMyPhone Assets/snaped_code.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,69 @@ public static String FormatPhoneNumber(String Oldnmber){

//**************************************************************

list my tracking
mDatabase.child("FindMyPhoneUsers").child(SettingSaved.PhoneNumber).child("Finders").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

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

list.clear();
if (td == null) //no one allow you to find him
{
list.add(new ListItem("NoTicket", "no_desc", R.drawable.dmap));
listv.setAdapter(new UserListAdapter(list));

return;
}
// List<Object> values = td.values();


// get all contact to list
ArrayList<ListItem> list_contact = new ArrayList<ListItem>();
Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
list_contact.add(new ListItem(name, ManagmentOperations.FormatPhoneNumber(phoneNumber), R.drawable.cover));


}


// if the name is save chane his text
// case who find me
String tinfo;
for ( String Numbers : td.keySet()) {
for (ListItem cs : list_contact) {

//IsFound = SettingSaved.WhoIFindIN.get(cs.Detals); // for case who i could find list
if (cs.PhoneNumber.length() > 0)
if (Numbers.contains(cs.PhoneNumber)) {
list.add(new ListItem(cs.UserName, cs.PhoneNumber, R.drawable.dmap));
break;
}

}

}
// add new one
// list.add(new ListItem("Loading", "no_desc", R.drawable.dmap));

//ask for add users to track you
// if (list.size()==0 && IsDisplayMessage==false) {
// IsDisplayMessage=true;
// ShowNoUsers();

// }
}

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


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.

4 changes: 3 additions & 1 deletion MyTracker/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
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.firebase:firebase-database:9.6.1'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-core:9.6.0'
}
apply plugin: 'com.google.gms.google-services'
21 changes: 21 additions & 0 deletions MyTracker/app/src/debug/res/values/google_maps_api.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
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
You can also add your credentials to an existing key, using this line:
76:A0:7B:52:24:16:38:F1:0F:B6:D3:CF:8F:6B:85:5F:92:91:69:DC;com.alrubaye.mytracker
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
AIzaSyDe4-wGUN_xq-YjfW_6SNRDAlV0DbaYtGU
</string>
</resources>
28 changes: 28 additions & 0 deletions MyTracker/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alrubaye.mytracker">

<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<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>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -15,6 +23,26 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Login" >

</activity>
<activity android:name=".MyTrackers" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps"></activity>
<service android:name=".MyServie"></service>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.alrubaye.mytracker;

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

public class AdapterItems
{

public String UserName;
public String PhoneNumber;
//for news details
AdapterItems( String UserName,String PhoneNumber)
{
this. UserName=UserName;
this. PhoneNumber=PhoneNumber;
}
}
94 changes: 94 additions & 0 deletions MyTracker/app/src/main/java/com/alrubaye/mytracker/GlobalInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.alrubaye.mytracker;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

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

public class GlobalInfo {
public static String PhoneNumber="";
public static Map<String,String> MyTrackers=new HashMap<>();

public static void UpdatesInfo(String UserPhone){
DateFormat df= new SimpleDateFormat("yyyy/MM/dd HH:MM:ss");
Date date= new Date();
DatabaseReference mDatabase= FirebaseDatabase.getInstance().getReference();
mDatabase.child("Users").child(UserPhone).
child("Updates").setValue(df.format(date).toString());
}

public static String FormatPhoneNumber(String Oldnmber){
try{
String numberOnly= Oldnmber.replaceAll("[^0-9]", "");
if(Oldnmber.charAt(0)=='+') numberOnly="+" +numberOnly ;
if (numberOnly.length()>=10)
numberOnly=numberOnly.substring(numberOnly.length()-10,numberOnly.length());
return(numberOnly);
}
catch (Exception ex){
return(" ");
}
}


Context context;
SharedPreferences ShredRef;
public GlobalInfo(Context context){
this.context=context;
ShredRef=context.getSharedPreferences("myRef",Context.MODE_PRIVATE);
}

void SaveData(){
String MyTrackersList="" ;
for (Map.Entry m:GlobalInfo.MyTrackers.entrySet()){
if (MyTrackersList.length()==0)
MyTrackersList=m.getKey() + "%" + m.getValue();
else
MyTrackersList+= m.getKey() + "%" + m.getValue();

}

if (MyTrackersList.length()==0)
MyTrackersList="empty";


SharedPreferences.Editor editor=ShredRef.edit();
editor.putString("MyTrackers",MyTrackersList);
editor.putString("PhoneNumber",PhoneNumber);
editor.commit();
}

void LoadData(){
MyTrackers.clear();
String PhoneNumber= ShredRef.getString("PhoneNumber","empty");
String MyTrackersList= ShredRef.getString("MyTrackersList","empty");
if (!MyTrackersList.equals("empty")){
String[] users=MyTrackersList.split("%");
for (int i=0;i<users.length;i=i+2){
MyTrackers.put(users[i],users[i+1]);
}
}


if (PhoneNumber.equals("empty")){

Intent intent=new Intent(context, Login.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}

}

}
26 changes: 26 additions & 0 deletions MyTracker/app/src/main/java/com/alrubaye/mytracker/Login.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.alrubaye.mytracker;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Login extends AppCompatActivity {
EditText EDTNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
EDTNumber=(EditText)findViewById(R.id.EDTNumber);
}

public void BuNext(View view) {

GlobalInfo.PhoneNumber=GlobalInfo.FormatPhoneNumber(EDTNumber.getText().toString());
GlobalInfo.UpdatesInfo(GlobalInfo.PhoneNumber);
finish();
Intent intent=new Intent(this, MyTrackers.class);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,80 @@
package com.alrubaye.mytracker;

import android.*;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

GlobalInfo globalInfo= new GlobalInfo(this);
globalInfo.LoadData();
CheckUserPermsions();
}

void CheckUserPermsions(){
if ( Build.VERSION.SDK_INT >= 23){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED ){
requestPermissions(new String[]{
android.Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION },
REQUEST_CODE_ASK_PERMISSIONS);
return ;
}
}

StartServices();

}
//get acces to location permsion
final private int REQUEST_CODE_ASK_PERMISSIONS = 123;



@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_ASK_PERMISSIONS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
StartServices();
} else {
// Permission Denied
Toast.makeText( this,"your message" , Toast.LENGTH_SHORT)
.show();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}

void StartServices(){

//start location track
if (!TrackLocation.isRunning){
TrackLocation trackLocation = new TrackLocation();
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

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


}
}
Loading

0 comments on commit 351f1e0

Please sign in to comment.