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 3069056 commit a7a438c
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 12 deletions.
47 changes: 47 additions & 0 deletions FindMyPhone Assets/snaped_code.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,53 @@ public void onCancelled(DatabaseError error) {
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
//Global file
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();
PhoneNumber= ShredRef.getString("PhoneNumber","empty");
String MyTrackersList= ShredRef.getString("MyTrackers","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);
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,67 @@ protected void onCreate(Bundle savedInstanceState) {
myadapter=new MyCustomAdapter(listnewsData);
ListView lsNews=(ListView)findViewById(R.id.listView);
lsNews.setAdapter(myadapter);//intisal with data
Refesh();
// Refesh();
}

void Refesh(){
listnewsData.clear();

databaseReference.child("Users").child(GlobalInfo.PhoneNumber).
child("Finders").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

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

listnewsData.clear();
if (td == null) //no one allow you to find him
{
listnewsData.add(new AdapterItems("NoTicket", "no_desc"));
myadapter.notifyDataSetChanged();
return;
}
// List<Object> values = td.values();


// get all contact to list
ArrayList<AdapterItems> list_contact = new ArrayList<AdapterItems>();
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 AdapterItems( name,GlobalInfo.FormatPhoneNumber(phoneNumber)
));


}


// if the name is save chane his text
// case who find me
String tinfo;
for ( String Numbers : td.keySet()) {
for (AdapterItems 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)) {
listnewsData.add(new AdapterItems(cs.UserName, cs.PhoneNumber));
break;
}

}

}
myadapter.notifyDataSetChanged();
}

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



Expand Down Expand Up @@ -165,19 +220,25 @@ public long getItemId(int position) {
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = getLayoutInflater();
View myView = mInflater.inflate(R.layout.single_row_conact, null);

final AdapterItems s = listnewsDataAdpater.get(position);
final AdapterItems s = listnewsDataAdpater.get(position);
if (s.UserName.equals("NoTicket")) {
View myView = mInflater.inflate(R.layout.news_ticket_no_news, null);

return myView;

TextView tv_user_name=( TextView)myView.findViewById(R.id.tv_user_name);
tv_user_name.setText(s.UserName);
TextView tv_phone=( TextView)myView.findViewById(R.id.tv_phone);
tv_phone.setText(s.PhoneNumber);
} else {
View myView = mInflater.inflate(R.layout.single_row_conact, null);

return myView;
TextView tv_user_name = (TextView) myView.findViewById(R.id.tv_user_name);
tv_user_name.setText(s.UserName);
TextView tv_phone = (TextView) myView.findViewById(R.id.tv_phone);
tv_phone.setText(s.PhoneNumber);

return myView;
}
}

}
Expand Down

0 comments on commit a7a438c

Please sign in to comment.