forked from hussien89aa/AndroidTutorialForBeginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hussienalrubaye
committed
Sep 27, 2016
1 parent
75f1edd
commit 351f1e0
Showing
47 changed files
with
1,121 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
MyTracker/app/src/main/java/com/alrubaye/mytracker/AdapterItems.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
94
MyTracker/app/src/main/java/com/alrubaye/mytracker/GlobalInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
MyTracker/app/src/main/java/com/alrubaye/mytracker/Login.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
MyTracker/app/src/main/java/com/alrubaye/mytracker/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.