From 6c838ee785f8a6295a22bc760ac6757598322b45 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Sun, 2 Oct 2016 11:50:44 -0400 Subject: [PATCH 01/29] service --- Service.java | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Service.java diff --git a/Service.java b/Service.java new file mode 100644 index 000000000000..e4eac22282a6 --- /dev/null +++ b/Service.java @@ -0,0 +1,76 @@ + + +/** + * Created by hussienalrubaye on 10/1/16. + */ + +public class LocationService extends Service +{ + + @Override + public void onCreate() + { + super.onCreate(); + + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) + { + + + return START_NOT_STICKY; + } + + @Override + public IBinder onBind(Intent intent) + { + return null; + } + + + + + + + @Override + public void onDestroy() { + // handler.removeCallbacks(sendUpdatesToUI); + super.onDestroy(); + // Log.v("STOP_SERVICE", "DONE"); + + } + + + + + + +} + +//Start service + + Intent callReceiverIntent = new Intent("com.domain.name.servicename"); + callReceiverIntent.putExtras(new Intent(context.getApplicationContext(), LocationService.class)); + context. startService(callReceiverIntent); + +// + //Stop service + + Intent callReceiverIntent = new Intent("com.domain.name.servicename"); + callReceiverIntent.putExtras(new Intent(context.getApplicationContext(), LocationService.class)); + context. stopService(callReceiverIntent); + +//Config service Mainfest.xml + /* + + + + + + + + */ + + + From 9377dbee0d93b3df1ad3e7d3a44c541acd414304 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Sun, 2 Oct 2016 11:52:20 -0400 Subject: [PATCH 02/29] GoogleApiClient --- GoogleApiClient.java | 140 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 GoogleApiClient.java diff --git a/GoogleApiClient.java b/GoogleApiClient.java new file mode 100644 index 000000000000..640d1766494a --- /dev/null +++ b/GoogleApiClient.java @@ -0,0 +1,140 @@ + public class MyLocationListener + implements GoogleApiClient.ConnectionCallbacks, + GoogleApiClient.OnConnectionFailedListener, com.google.android.gms.location.LocationListener + { + private final String TAG = "LOC_RECURRING_SAMPLE"; + + // Constants that define how often location updates will be delivered + private final long LOC_UPDATE_INTERVAL = 10000; // 10s in milliseconds + private final long LOC_FASTEST_UPDATE = 5000; // 5s in milliseconds + + protected GoogleApiClient mGoogleApiClient; + protected LocationRequest mLocRequest; + public Location mCurLocation; + + Context context; + public MyLocationListener( Context context) { + this.context=context; + mCurLocation = null; + + // build the Play Services client object + mGoogleApiClient = new GoogleApiClient.Builder(context) + .addConnectionCallbacks(this) + .addOnConnectionFailedListener(this) + .addApi(LocationServices.API) + .build(); + mLocRequest=new LocationRequest(); + mLocRequest.setInterval(LOC_UPDATE_INTERVAL); + mLocRequest.setFastestInterval(LOC_FASTEST_UPDATE); + mLocRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); + // TODO: create the LocationRequest we'll use for location updates + onStart(); + } + + + public void startLocationUpdates() { + // TODO: start the location updates + + LocationServices.FusedLocationApi.requestLocationUpdates( + mGoogleApiClient,mLocRequest,this); + + + } + + public void stopLocationUpdates() { + // TODO: stop the updates + + LocationServices.FusedLocationApi.removeLocationUpdates( + mGoogleApiClient, this); + + + } + + protected void updateUI() { + // take the lat and long of the current location object and add it to the list + if (mCurLocation != null) { + String lat = String.format("Lat: %f\n", mCurLocation.getLatitude()); + String lon = String.format("Lon: %f\n", mCurLocation.getLongitude()); + + + } + } + + protected void initializeUI() { + // start by getting the last known location as a starting point + if (mCurLocation == null) { + mCurLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); + + updateUI(); + + + } + + + } + + /** + * Called to handle the button clicks in the view + */ + + public void onClick(int id ) { + switch (id){ + case 1: + startLocationUpdates(); + break; + case 0: + stopLocationUpdates(); + break; + } + } + + /** + * Called by Play Services when the user's location changes + */ + @Override + public void onLocationChanged(Location loc) { + mCurLocation = loc; + LocationService.location=loc; + updateUI(); + } + + + + + + + /** + * Google Play Services Lifecycle methods + */ + @Override + public void onConnected(Bundle connectionHint) { + + initializeUI(); + startLocationUpdates(); + } + + @Override + public void onConnectionFailed(ConnectionResult result) { + Log.d(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode()); + } + + @Override + public void onConnectionSuspended(int cause) { + Log.d(TAG, "Connection was suspended for some reason"); + mGoogleApiClient.connect(); + } + + /** + * Activity lifecycle events + */ + public void onStart() { + + mGoogleApiClient.connect(); + } + + public void onStop() { + mGoogleApiClient.disconnect(); + + } + + } \ No newline at end of file From 33e9cb13dfcbb9e4e7a04b2f608697a1791f7639 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Sun, 2 Oct 2016 11:53:18 -0400 Subject: [PATCH 03/29] GoogleApiClient --- Service.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Service.java b/Service.java index e4eac22282a6..031f6e4b3d4f 100644 --- a/Service.java +++ b/Service.java @@ -72,5 +72,7 @@ public void onDestroy() { */ + //start alert + From 78bc37a790cb0928e0a7a64f166bbd2195ce1c60 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Sun, 2 Oct 2016 12:00:44 -0400 Subject: [PATCH 04/29] GoogleApiClient --- AlarmManager.java | 6 +++- bindService.java | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 bindService.java diff --git a/AlarmManager.java b/AlarmManager.java index 2b80088d1fd5..4776f9e5d588 100644 --- a/AlarmManager.java +++ b/AlarmManager.java @@ -12,7 +12,11 @@ public void startAlert() { MESSAGE WHICH SHOULD BE SHOW ON RECEIVER OF ALARM"); PendingIntent pendingIntent = PendingIntent.getBroadcast( this.getApplicationContext(), - 234324243, intent, 0); + 234324243, intent, 0); +//start service + // PendingIntent pendingIntent = PendingIntent.getService( + this.getApplicationContext(), + 0, intent, 0); alarmManager.set(AlarmManager.RTC_WAKEUP, myAlarmDate.getTimeInMillis(),_myPendingIntent); /* Create Repeating Alarm Start After Each 2 Minutes diff --git a/bindService.java b/bindService.java new file mode 100644 index 000000000000..7778ae22f6b9 --- /dev/null +++ b/bindService.java @@ -0,0 +1,88 @@ +public class LocalService extends Service { + // Binder given to clients + private final IBinder mBinder = new LocalBinder(); + // Random number generator + private final Random mGenerator = new Random(); + + /** + * Class used for the client Binder. Because we know this service always + * runs in the same process as its clients, we don't need to deal with IPC. + */ + public class LocalBinder extends Binder { + LocalService getService() { + // Return this instance of LocalService so clients can call public methods + return LocalService.this; + } + } + + @Override + public IBinder onBind(Intent intent) { + return mBinder; + } + + /** method for clients */ + public int getRandomNumber() { + return mGenerator.nextInt(100); + } +} + +//start service + +public class BindingActivity extends Activity { + LocalService mService; + boolean mBound = false; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + } + + @Override + protected void onStart() { + super.onStart(); + // Bind to LocalService + Intent intent = new Intent(this, LocalService.class); + bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + } + + @Override + protected void onStop() { + super.onStop(); + // Unbind from the service + if (mBound) { + unbindService(mConnection); + mBound = false; + } + } + + /** Called when a button is clicked (the button in the layout file attaches to + * this method with the android:onClick attribute) */ + public void onButtonClick(View v) { + if (mBound) { + // Call a method from the LocalService. + // However, if this call were something that might hang, then this request should + // occur in a separate thread to avoid slowing down the activity performance. + int num = mService.getRandomNumber(); + Toast.makeText(this, "number: " + num, Toast.LENGTH_SHORT).show(); + } + } + + /** Defines callbacks for service binding, passed to bindService() */ + private ServiceConnection mConnection = new ServiceConnection() { + + @Override + public void onServiceConnected(ComponentName className, + IBinder service) { + // We've bound to LocalService, cast the IBinder and get LocalService instance + LocalBinder binder = (LocalBinder) service; + mService = binder.getService(); + mBound = true; + } + + @Override + public void onServiceDisconnected(ComponentName arg0) { + mBound = false; + } + }; +} \ No newline at end of file From 39651bd3bd5cdc3500d89028db40e7bfa9bd4450 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Mon, 3 Oct 2016 01:47:54 -0400 Subject: [PATCH 05/29] start with os --- MyTracker/app/src/main/AndroidManifest.xml | 15 ++-- .../com/alrubaye/mytracker/MainActivity.java | 7 +- .../java/com/alrubaye/mytracker/MyServie.java | 74 +++++++++++++++++-- .../java/com/alrubaye/mytracker/RunithOS.java | 34 --------- .../java/com/alrubaye/mytracker/StartOs.java | 24 ++++++ .../com/alrubaye/mytracker/TrackLocation.java | 40 ---------- 6 files changed, 99 insertions(+), 95 deletions(-) delete mode 100644 MyTracker/app/src/main/java/com/alrubaye/mytracker/RunithOS.java create mode 100644 MyTracker/app/src/main/java/com/alrubaye/mytracker/StartOs.java delete mode 100644 MyTracker/app/src/main/java/com/alrubaye/mytracker/TrackLocation.java diff --git a/MyTracker/app/src/main/AndroidManifest.xml b/MyTracker/app/src/main/AndroidManifest.xml index ad1fd286dabc..33c4adce57ba 100644 --- a/MyTracker/app/src/main/AndroidManifest.xml +++ b/MyTracker/app/src/main/AndroidManifest.xml @@ -11,7 +11,7 @@ - + - - - - - - + - + + + + + \ No newline at end of file diff --git a/MyTracker/app/src/main/java/com/alrubaye/mytracker/MainActivity.java b/MyTracker/app/src/main/java/com/alrubaye/mytracker/MainActivity.java index 5fdf8e5a7e9d..950ce687825d 100644 --- a/MyTracker/app/src/main/java/com/alrubaye/mytracker/MainActivity.java +++ b/MyTracker/app/src/main/java/com/alrubaye/mytracker/MainActivity.java @@ -175,14 +175,9 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in 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); + Intent intent=new Intent(getBaseContext(),MyServie.class); startService(intent); } diff --git a/MyTracker/app/src/main/java/com/alrubaye/mytracker/MyServie.java b/MyTracker/app/src/main/java/com/alrubaye/mytracker/MyServie.java index 73a316f0bc1f..9de0081a91a2 100644 --- a/MyTracker/app/src/main/java/com/alrubaye/mytracker/MyServie.java +++ b/MyTracker/app/src/main/java/com/alrubaye/mytracker/MyServie.java @@ -1,8 +1,15 @@ package com.alrubaye.mytracker; import android.app.IntentService; +import android.app.Service; +import android.content.Context; import android.content.Intent; import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Bundle; +import android.os.IBinder; +import android.support.annotation.Nullable; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; @@ -18,29 +25,50 @@ * Created by hussienalrubaye on 9/26/16. */ -public class MyServie extends IntentService { +public class MyServie extends Service { public static boolean IsRunning=false; DatabaseReference databaseReference; - public MyServie(){ - super("MyServie"); + public static Location location; + TrackLocation trackLocation; + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onCreate() + { + super.onCreate(); IsRunning=true; databaseReference= FirebaseDatabase.getInstance().getReference(); + } + @Override - protected void onHandleIntent(Intent intent) { + public int onStartCommand(Intent intent, int flags, int startId) + { + + GlobalInfo globalInfo= new GlobalInfo(this); + globalInfo.LoadData(); + trackLocation = new TrackLocation(); + LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); + + lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, trackLocation); databaseReference.child("Users").child(GlobalInfo.PhoneNumber). child("Updates").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { - Location location=TrackLocation.location; + + if (location==null)return; databaseReference.child("Users"). child(GlobalInfo.PhoneNumber).child("Location").child("lat") - .setValue(TrackLocation.location.getLatitude()); + .setValue( location.getLatitude()); databaseReference.child("Users"). child(GlobalInfo.PhoneNumber).child("Location").child("lag") - .setValue(TrackLocation.location.getLongitude()); + .setValue( location.getLongitude()); DateFormat df= new SimpleDateFormat("yyyy/MM/dd HH:MM:ss"); Date date= new Date(); @@ -55,5 +83,37 @@ public void onCancelled(DatabaseError databaseError) { } }); + return START_NOT_STICKY; + } + + public class TrackLocation implements LocationListener { + + + public boolean isRunning=false; + public TrackLocation(){ + isRunning=true; + location=new Location("not defined"); + location.setLatitude(0); + location.setLongitude(0); + } + @Override + public void onLocationChanged(Location location) { + MyServie.location=location; + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + + } + + @Override + public void onProviderEnabled(String provider) { + + } + + @Override + public void onProviderDisabled(String provider) { + + } } } diff --git a/MyTracker/app/src/main/java/com/alrubaye/mytracker/RunithOS.java b/MyTracker/app/src/main/java/com/alrubaye/mytracker/RunithOS.java deleted file mode 100644 index 50be5dbae642..000000000000 --- a/MyTracker/app/src/main/java/com/alrubaye/mytracker/RunithOS.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.alrubaye.mytracker; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.location.LocationManager; - -/** - * Created by hussienalrubaye on 9/26/16. - */ - -public class RunithOS extends BroadcastReceiver { - - - @Override - public void onReceive(Context context, Intent intent) { - - if (intent.getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")){ - GlobalInfo globalInfo= new GlobalInfo(context); - globalInfo.LoadData(); - //start location track - if (!TrackLocation.isRunning){ - TrackLocation trackLocation = new TrackLocation(); - LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); - - lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, trackLocation); - } - if (!MyServie.IsRunning){ - Intent intent1=new Intent(context,MyServie.class); - context.startService(intent1); - } - } - } -} diff --git a/MyTracker/app/src/main/java/com/alrubaye/mytracker/StartOs.java b/MyTracker/app/src/main/java/com/alrubaye/mytracker/StartOs.java new file mode 100644 index 000000000000..ebdf5baa19b0 --- /dev/null +++ b/MyTracker/app/src/main/java/com/alrubaye/mytracker/StartOs.java @@ -0,0 +1,24 @@ +package com.alrubaye.mytracker; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.location.LocationManager; + +/** + * Created by hussienalrubaye on 10/3/16. + */ + +public class StartOs extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + + if (intent.getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")){ + + + /// only when system start + Intent intentService=new Intent(context,MyServie.class); + context. startService(intentService); + } + } +} diff --git a/MyTracker/app/src/main/java/com/alrubaye/mytracker/TrackLocation.java b/MyTracker/app/src/main/java/com/alrubaye/mytracker/TrackLocation.java deleted file mode 100644 index 63f7e0445ea7..000000000000 --- a/MyTracker/app/src/main/java/com/alrubaye/mytracker/TrackLocation.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.alrubaye.mytracker; - -import android.location.Location; -import android.location.LocationListener; -import android.os.Bundle; - -/** - * Created by hussienalrubaye on 9/26/16. - */ - -public class TrackLocation implements LocationListener { - - public static Location location; - public static boolean isRunning=false; - public TrackLocation(){ - isRunning=true; - location=new Location("not defined"); - location.setLatitude(0); - location.setLongitude(0); - } - @Override - public void onLocationChanged(Location location) { - this.location=location; - } - - @Override - public void onStatusChanged(String provider, int status, Bundle extras) { - - } - - @Override - public void onProviderEnabled(String provider) { - - } - - @Override - public void onProviderDisabled(String provider) { - - } -} From dde62ab26a0ec45fedabf7f6d579e61976c5d277 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Mon, 3 Oct 2016 11:11:27 -0400 Subject: [PATCH 06/29] play services --- GooglePlayServices.java | 73 +++++++++++++++++++ .../com/alrubaye/mytracker/MapsActivity.java | 12 ++- 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 GooglePlayServices.java diff --git a/GooglePlayServices.java b/GooglePlayServices.java new file mode 100644 index 000000000000..27d605a3f1bf --- /dev/null +++ b/GooglePlayServices.java @@ -0,0 +1,73 @@ + public class GooglePlayServices + implements GoogleApiClient.ConnectionCallbacks, + GoogleApiClient.OnConnectionFailedListener + { + private final String TAG = "GooglePlayServices:"; + protected GoogleApiClient mGoogleApiClient; + + Context context; + public GooglePlayServices( Context context) { + this.context=context; + + // build the Play Services client object + mGoogleApiClient = new GoogleApiClient.Builder(context) + .addConnectionCallbacks(this) + .addOnConnectionFailedListener(this) + .addApi(LocationServices.API) + .build(); + + + } + + @Override + protected void onStart() { + super.onStart(); + Log.i(TAG, "onStart: Connecting to Google Play Services"); + + // Connect to Play Services + GoogleApiAvailability gAPI = GoogleApiAvailability.getInstance(); + int resultCode = gAPI.isGooglePlayServicesAvailable(this); + if (resultCode != ConnectionResult.SUCCESS) { + gAPI.getErrorDialog(this, resultCode, 1).show(); + } + else { + mGoogleApiClient.connect(); + } + } + + @Override + protected void onStop() { + super.onStop(); + if (mGoogleApiClient.isConnected()) { + Log.i(TAG, "onStop: Disconnecting from Google Play Services"); + mGoogleApiClient.disconnect(); + } + } + /** + * Google Play Services Lifecycle methods + */ + @Override + public void onConnected(Bundle connectionHint) { + Log.i(TAG, "onConnected: Is connected to Google Play Services"); + //TODO: we connected + + } + + @Override + public void onConnectionFailed(ConnectionResult result) { + //error result + Log.d(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode()); + } + + @Override + public void onConnectionSuspended(int cause) { + Log.d(TAG, "Connection was suspended for some reason"); + mGoogleApiClient.connect(); //reconnected + } + + + + } + + //TODO: Add play services in Grade + //compile 'com.google.android.gms:play-services:Version' \ No newline at end of file diff --git a/MyTracker/app/src/main/java/com/alrubaye/mytracker/MapsActivity.java b/MyTracker/app/src/main/java/com/alrubaye/mytracker/MapsActivity.java index b57ea87e7080..f2a7689d6d5f 100644 --- a/MyTracker/app/src/main/java/com/alrubaye/mytracker/MapsActivity.java +++ b/MyTracker/app/src/main/java/com/alrubaye/mytracker/MapsActivity.java @@ -4,6 +4,7 @@ import android.provider.ContactsContract; import android.support.v4.app.FragmentActivity; import android.os.Bundle; +import android.view.KeyEvent; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; @@ -25,24 +26,26 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback private GoogleMap mMap; DatabaseReference databaseReference; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); - databaseReference= FirebaseDatabase.getInstance().getReference(); Bundle b=getIntent().getExtras(); + databaseReference= FirebaseDatabase.getInstance().getReference(); LoadLocation(b.getString("PhoneNumber")); } void LoadLocation(String PhoneNumber){ + databaseReference.child("Users").child(PhoneNumber). child("Location").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Map td = (HashMap) dataSnapshot.getValue(); - + if (td==null)return; double lat = Double.parseDouble(td.get("lat").toString()); double lag = Double.parseDouble(td.get("lag").toString()); /** Make sure that the map has been initialised **/ @@ -89,4 +92,9 @@ public void onMapReady(GoogleMap googleMap) { mMap.addMarker(new MarkerOptions().position(sydney).title("last online:"+ LastDateOnline)); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,15)); } + + + + + } From 0fc1974889fc81bbdcb98c253742e0a58e195dd9 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Sun, 23 Oct 2016 19:39:03 -0400 Subject: [PATCH 07/29] firebase auth --- Firebase_PlayServices_auth.java | 201 ++++++++++++++++++++++++++++++++ Firebase_auth.java | 160 +++++++++++++++++++++++++ 2 files changed, 361 insertions(+) create mode 100644 Firebase_PlayServices_auth.java create mode 100644 Firebase_auth.java diff --git a/Firebase_PlayServices_auth.java b/Firebase_PlayServices_auth.java new file mode 100644 index 000000000000..24fc62582f4c --- /dev/null +++ b/Firebase_PlayServices_auth.java @@ -0,0 +1,201 @@ +// login firebase with play services +//1-- add to gradle + compile 'com.google.firebase:firebase-auth:9.6.1' + compile 'com.google.android.gms:play-services-auth:9.6.1' + + //1- extend + GoogleApiClient.OnConnectionFailedListener + //2 - define in public + + + private static final String TAG = "GoogleActivity"; + private static final int RC_SIGN_IN = 9001; + + // [START declare_auth] + private FirebaseAuth mAuth; + // [END declare_auth] + + // [START declare_auth_listener] + private FirebaseAuth.AuthStateListener mAuthListener; + // [END declare_auth_listener] + + private GoogleApiClient mGoogleApiClient; + + + //3- onCreate add + + + // [START config_signin] + // Configure Google Sign In + GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestIdToken(getString(R.string.default_web_client_id)) + .requestEmail() + .build(); + // [END config_signin] + + mGoogleApiClient = new GoogleApiClient.Builder(this) + .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) + .addApi(Auth.GOOGLE_SIGN_IN_API, gso) + .build(); + + // [START initialize_auth] + mAuth = FirebaseAuth.getInstance(); + // [END initialize_auth] + + // [START auth_state_listener] + mAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + FirebaseUser user = firebaseAuth.getCurrentUser(); + if (user != null) { + // User is signed in + Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); + } else { + // User is signed out + Log.d(TAG, "onAuthStateChanged:signed_out"); + } + // [START_EXCLUDE] + updateUI(user); + // [END_EXCLUDE] + } + }; + // [END auth_state_listener] + +//4 deine this methods + // [START on_start_add_listener] + @Override + public void onStart() { + super.onStart(); + mAuth.addAuthStateListener(mAuthListener); + } + // [END on_start_add_listener] + + // [START on_stop_remove_listener] + @Override + public void onStop() { + super.onStop(); + if (mAuthListener != null) { + mAuth.removeAuthStateListener(mAuthListener); + } + } + // [END on_stop_remove_listener] + + // [START onactivityresult] + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); + if (requestCode == RC_SIGN_IN) { + GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); + if (result.isSuccess()) { + // Google Sign In was successful, authenticate with Firebase + GoogleSignInAccount account = result.getSignInAccount(); + firebaseAuthWithGoogle(account); + } else { + // Google Sign In failed, update UI appropriately + // [START_EXCLUDE] + updateUI(null); + // [END_EXCLUDE] + } + } + } + // [END onactivityresult] + + // [START auth_with_google] + private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { + Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); + // [START_EXCLUDE silent] + showProgressDialog(); + // [END_EXCLUDE] + + AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); + mAuth.signInWithCredential(credential) + .addOnCompleteListener(this, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); + + // If sign in fails, display a message to the user. If sign in succeeds + // the auth state listener will be notified and logic to handle the + // signed in user can be handled in the listener. + if (!task.isSuccessful()) { + Log.w(TAG, "signInWithCredential", task.getException()); + Toast.makeText(GoogleSignInActivity.this, "Authentication failed.", + Toast.LENGTH_SHORT).show(); + } + // [START_EXCLUDE] + hideProgressDialog(); + // [END_EXCLUDE] + } + }); + } + // [END auth_with_google] + + // [START signin] + private void signIn() { + Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); + startActivityForResult(signInIntent, RC_SIGN_IN); + } + // [END signin] + + private void signOut() { + // Firebase sign out + mAuth.signOut(); + + // Google sign out + Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback( + new ResultCallback() { + @Override + public void onResult(@NonNull Status status) { + updateUI(null); + } + }); + } + + + + private void updateUI(FirebaseUser user) { + hideProgressDialog(); + String Email=user.getEmail(); + String Uid= user.getUid(); + } + + @Override + public void onConnected(Bundle connectionHint) { + + Log.d(TAG, "onConnection is connected:" ); + } + @Override + public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { + // An unresolvable error has occurred and Google APIs (including Sign-In) will not + // be available. + Log.d(TAG, "onConnectionFailed:" + connectionResult); + Toast.makeText(this, "Google Play Services error.", Toast.LENGTH_SHORT).show(); + } + + + @VisibleForTesting + public ProgressDialog mProgressDialog; + + public void showProgressDialog() { + if (mProgressDialog == null) { + mProgressDialog = new ProgressDialog(this); + mProgressDialog.setMessage(getString(R.string.loading)); + mProgressDialog.setIndeterminate(true); + } + + mProgressDialog.show(); + } + + public void hideProgressDialog() { + if (mProgressDialog != null && mProgressDialog.isShowing()) { + mProgressDialog.dismiss(); + } + } + + @Override + public void onStop() { + super.onStop(); + hideProgressDialog(); + } diff --git a/Firebase_auth.java b/Firebase_auth.java new file mode 100644 index 000000000000..c71dcc4e7522 --- /dev/null +++ b/Firebase_auth.java @@ -0,0 +1,160 @@ +// Fire base sign in + +//add to grade +compile 'com.google.firebase:firebase-auth:9.6.1' + +//code + + +/** + * Activity to demonstrate anonymous login and account linking (with an email/password account). + */ + //1- define + private static final String TAG = "AnonymousAuth"; + + // [START declare_auth] + private FirebaseAuth mAuth; + // [END declare_auth] + + // [START declare_auth_listener] + private FirebaseAuth.AuthStateListener mAuthListener; + // [END declare_auth_listener] + + //2- initiailze OnCreate() + // [START initialize_auth] + mAuth = FirebaseAuth.getInstance(); + // [END initialize_auth] + + // [START auth_state_listener] + mAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + FirebaseUser user = firebaseAuth.getCurrentUser(); + if (user != null) { + // User is signed in + Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); + } else { + // User is signed out + Log.d(TAG, "onAuthStateChanged:signed_out"); + } + // [START_EXCLUDE] + updateUI(user); + // [END_EXCLUDE] + } + }; + // [END auth_state_listener] + private void updateUI(FirebaseUser user) { + hideProgressDialog(); + String Email=user.getEmail(); + String Uid= user.getUid(); + } + + // [START on_start_add_listener] + @Override + public void onStart() { + super.onStart(); + mAuth.addAuthStateListener(mAuthListener); + } + // [END on_start_add_listener] + + // [START on_stop_remove_listener] + @Override + public void onStop() { + super.onStop(); + if (mAuthListener != null) { + mAuth.removeAuthStateListener(mAuthListener); + } + } + // [END on_stop_remove_listener] + + private void signInAnonymously() { + showProgressDialog(); + // [START signin_anonymously] + mAuth.signInAnonymously() + .addOnCompleteListener(this, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful()); + + // If sign in fails, display a message to the user. If sign in succeeds + // the auth state listener will be notified and logic to handle the + // signed in user can be handled in the listener. + if (!task.isSuccessful()) { + Log.w(TAG, "signInAnonymously", task.getException()); + Toast.makeText(MainActivity.this, "Authentication failed.", + Toast.LENGTH_SHORT).show(); + } + + // [START_EXCLUDE] + hideProgressDialog(); + // [END_EXCLUDE] + } + }); + // [END signin_anonymously] + } + + private void signOut() { + mAuth.signOut(); + + } + + private void linkAccount() { + + + // Get email and password from form + String email = "User_Email"; + String password ="User_Password"; + + // Create EmailAuthCredential with email and password + AuthCredential credential = EmailAuthProvider.getCredential(email, password); + + // Link the anonymous user to the email credential + showProgressDialog(); + // [START link_credential] + mAuth.getCurrentUser().linkWithCredential(credential) + .addOnCompleteListener(this, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + Log.d(TAG, "linkWithCredential:onComplete:" + task.isSuccessful()); + + // If sign in fails, display a message to the user. If sign in succeeds + // the auth state listener will be notified and logic to handle the + // signed in user can be handled in the listener. + if (!task.isSuccessful()) { + Toast.makeText(MainActivity.this, "Authentication failed.", + Toast.LENGTH_SHORT).show(); + } + + // [START_EXCLUDE] + hideProgressDialog(); + // [END_EXCLUDE] + } + }); + // [END link_credential] + } + + + @VisibleForTesting + public ProgressDialog mProgressDialog; + + public void showProgressDialog() { + if (mProgressDialog == null) { + mProgressDialog = new ProgressDialog(this); + mProgressDialog.setMessage(getString(R.string.loading)); + mProgressDialog.setIndeterminate(true); + } + + mProgressDialog.show(); + } + + public void hideProgressDialog() { + if (mProgressDialog != null && mProgressDialog.isShowing()) { + mProgressDialog.dismiss(); + } + } + + @Override + public void onStop() { + super.onStop(); + hideProgressDialog(); + } \ No newline at end of file From 259dddd3638e2e712a05b1ce345b8d0eb6296fc6 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Tue, 1 Nov 2016 18:51:22 -0400 Subject: [PATCH 08/29] alarm --- AlarmManager.java | 52 ++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/AlarmManager.java b/AlarmManager.java index 4776f9e5d588..9e7b1180bc47 100644 --- a/AlarmManager.java +++ b/AlarmManager.java @@ -4,25 +4,27 @@ public void startAlert() { Calendar myAlarmDate = Calendar.getInstance(); myAlarmDate.setTimeInMillis(System.currentTimeMillis()); myAlarmDate.set(2012, 11, 25, 12, 00, 0); +//other way + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, Hour); + calendar.set(Calendar.MINUTE, Minute); + calendar.set(Calendar.SECOND, 0); - AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); - - Intent intent = new Intent(this, MyBroadcastReceiver.class); -intent.putExtra("MyMessage","HERE I AM PASSING THEPERTICULAR - MESSAGE WHICH SHOULD BE SHOW ON RECEIVER OF ALARM"); -PendingIntent pendingIntent = PendingIntent.getBroadcast( - this.getApplicationContext(), - 234324243, intent, 0); -//start service - // PendingIntent pendingIntent = PendingIntent.getService( - this.getApplicationContext(), - 0, intent, 0); -alarmManager.set(AlarmManager.RTC_WAKEUP, - myAlarmDate.getTimeInMillis(),_myPendingIntent); -/* Create Repeating Alarm Start After Each 2 Minutes - am.setRepeating(AlarmManager.ELAPSED_REALTIME,myAlarmDate.getTimeInMillis(), - 2*60*60,pendingIntent); - */ + //define Repeating Alarm Start After Each 2 Minutes + + + AlarmManager am = (AlarmManager)context.getSystemService (Context.ALARM_SERVICE); + Intent intent = new Intent(context, AlarmReceiver.class); + intent.setAction("com.quranonline.Broadcast"); + intent.putExtra("MyMessage",context.getResources().getString(R.string.msg_notify)); + PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT); + am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), + AlarmManager.INTERVAL_DAY , pi); +// Create one time Alarm Start After Each 2 Minutes +alarmManager.set(AlarmManager.RTC_WAKEUP, myAlarmDate.getTimeInMillis(),_myPendingIntent); + + } @@ -30,4 +32,16 @@ public void startAlert() { - */ \ No newline at end of file + */ + + /* run with os + //permission + + + //filters + + + + + + */ \ No newline at end of file From fee5bdc1a641f6abb36cabcff72a43f516ba4f65 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Tue, 1 Nov 2016 21:10:33 -0400 Subject: [PATCH 09/29] alarm --- Alaram App/.gitignore | 9 + Alaram App/.idea/compiler.xml | 22 +++ .../.idea/copyright/profiles_settings.xml | 3 + Alaram App/.idea/encodings.xml | 6 + Alaram App/.idea/gradle.xml | 19 +++ Alaram App/.idea/misc.xml | 49 ++++++ Alaram App/.idea/modules.xml | 9 + Alaram App/.idea/runConfigurations.xml | 12 ++ Alaram App/app/.gitignore | 1 + Alaram App/app/build.gradle | 30 ++++ Alaram App/app/proguard-rules.pro | 17 ++ .../alaram/ExampleInstrumentedTest.java | 26 +++ Alaram App/app/src/main/AndroidManifest.xml | 32 ++++ .../com/alrubaye/alaram/MainActivity.java | 32 ++++ .../java/com/alrubaye/alaram/MyReceiver.java | 28 +++ .../java/com/alrubaye/alaram/PopTime.java | 46 +++++ .../java/com/alrubaye/alaram/savedata.java | 51 ++++++ .../app/src/main/res/layout/activity_main.xml | 28 +++ .../app/src/main/res/layout/pop_time.xml | 24 +++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../app/src/main/res/values-w820dp/dimens.xml | 6 + Alaram App/app/src/main/res/values/colors.xml | 6 + Alaram App/app/src/main/res/values/dimens.xml | 5 + .../app/src/main/res/values/strings.xml | 3 + Alaram App/app/src/main/res/values/styles.xml | 11 ++ .../com/alrubaye/alaram/ExampleUnitTest.java | 17 ++ Alaram App/build.gradle | 23 +++ Alaram App/gradle.properties | 17 ++ Alaram App/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + Alaram App/gradlew | 160 ++++++++++++++++++ Alaram App/gradlew.bat | 90 ++++++++++ Alaram App/settings.gradle | 1 + 37 files changed, 789 insertions(+) create mode 100644 Alaram App/.gitignore create mode 100644 Alaram App/.idea/compiler.xml create mode 100644 Alaram App/.idea/copyright/profiles_settings.xml create mode 100644 Alaram App/.idea/encodings.xml create mode 100644 Alaram App/.idea/gradle.xml create mode 100644 Alaram App/.idea/misc.xml create mode 100644 Alaram App/.idea/modules.xml create mode 100644 Alaram App/.idea/runConfigurations.xml create mode 100644 Alaram App/app/.gitignore create mode 100644 Alaram App/app/build.gradle create mode 100644 Alaram App/app/proguard-rules.pro create mode 100644 Alaram App/app/src/androidTest/java/com/alrubaye/alaram/ExampleInstrumentedTest.java create mode 100644 Alaram App/app/src/main/AndroidManifest.xml create mode 100644 Alaram App/app/src/main/java/com/alrubaye/alaram/MainActivity.java create mode 100644 Alaram App/app/src/main/java/com/alrubaye/alaram/MyReceiver.java create mode 100644 Alaram App/app/src/main/java/com/alrubaye/alaram/PopTime.java create mode 100644 Alaram App/app/src/main/java/com/alrubaye/alaram/savedata.java create mode 100644 Alaram App/app/src/main/res/layout/activity_main.xml create mode 100644 Alaram App/app/src/main/res/layout/pop_time.xml create mode 100644 Alaram App/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Alaram App/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Alaram App/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Alaram App/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Alaram App/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 Alaram App/app/src/main/res/values-w820dp/dimens.xml create mode 100644 Alaram App/app/src/main/res/values/colors.xml create mode 100644 Alaram App/app/src/main/res/values/dimens.xml create mode 100644 Alaram App/app/src/main/res/values/strings.xml create mode 100644 Alaram App/app/src/main/res/values/styles.xml create mode 100644 Alaram App/app/src/test/java/com/alrubaye/alaram/ExampleUnitTest.java create mode 100644 Alaram App/build.gradle create mode 100644 Alaram App/gradle.properties create mode 100644 Alaram App/gradle/wrapper/gradle-wrapper.jar create mode 100644 Alaram App/gradle/wrapper/gradle-wrapper.properties create mode 100755 Alaram App/gradlew create mode 100644 Alaram App/gradlew.bat create mode 100644 Alaram App/settings.gradle diff --git a/Alaram App/.gitignore b/Alaram App/.gitignore new file mode 100644 index 000000000000..39fb081a42a8 --- /dev/null +++ b/Alaram App/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/Alaram App/.idea/compiler.xml b/Alaram App/.idea/compiler.xml new file mode 100644 index 000000000000..96cc43efa6a0 --- /dev/null +++ b/Alaram App/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Alaram App/.idea/copyright/profiles_settings.xml b/Alaram App/.idea/copyright/profiles_settings.xml new file mode 100644 index 000000000000..e7bedf3377d4 --- /dev/null +++ b/Alaram App/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Alaram App/.idea/encodings.xml b/Alaram App/.idea/encodings.xml new file mode 100644 index 000000000000..97626ba45445 --- /dev/null +++ b/Alaram App/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Alaram App/.idea/gradle.xml b/Alaram App/.idea/gradle.xml new file mode 100644 index 000000000000..0e23f8edad75 --- /dev/null +++ b/Alaram App/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/Alaram App/.idea/misc.xml b/Alaram App/.idea/misc.xml new file mode 100644 index 000000000000..84cfd6708077 --- /dev/null +++ b/Alaram App/.idea/misc.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Alaram App/.idea/modules.xml b/Alaram App/.idea/modules.xml new file mode 100644 index 000000000000..ab43d45610bc --- /dev/null +++ b/Alaram App/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Alaram App/.idea/runConfigurations.xml b/Alaram App/.idea/runConfigurations.xml new file mode 100644 index 000000000000..7f68460d8b38 --- /dev/null +++ b/Alaram App/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Alaram App/app/.gitignore b/Alaram App/app/.gitignore new file mode 100644 index 000000000000..796b96d1c402 --- /dev/null +++ b/Alaram App/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/Alaram App/app/build.gradle b/Alaram App/app/build.gradle new file mode 100644 index 000000000000..89474fa3659b --- /dev/null +++ b/Alaram App/app/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion "24.0.3" + defaultConfig { + applicationId "com.alrubaye.alaram" + minSdkVersion 15 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:24.2.1' + testCompile 'junit:junit:4.12' + compile 'com.frosquivel:magicaltakephoto:1.0' +} diff --git a/Alaram App/app/proguard-rules.pro b/Alaram App/app/proguard-rules.pro new file mode 100644 index 000000000000..c0625ce1e770 --- /dev/null +++ b/Alaram App/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/hussienalrubaye/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/Alaram App/app/src/androidTest/java/com/alrubaye/alaram/ExampleInstrumentedTest.java b/Alaram App/app/src/androidTest/java/com/alrubaye/alaram/ExampleInstrumentedTest.java new file mode 100644 index 000000000000..1dd8b1306a57 --- /dev/null +++ b/Alaram App/app/src/androidTest/java/com/alrubaye/alaram/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.alrubaye.alaram; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.alrubaye.alaram", appContext.getPackageName()); + } +} diff --git a/Alaram App/app/src/main/AndroidManifest.xml b/Alaram App/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..341ef3a766ba --- /dev/null +++ b/Alaram App/app/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Alaram App/app/src/main/java/com/alrubaye/alaram/MainActivity.java b/Alaram App/app/src/main/java/com/alrubaye/alaram/MainActivity.java new file mode 100644 index 000000000000..7df5dc418f76 --- /dev/null +++ b/Alaram App/app/src/main/java/com/alrubaye/alaram/MainActivity.java @@ -0,0 +1,32 @@ +package com.alrubaye.alaram; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +import java.util.Calendar; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + android.app.FragmentManager fm= getFragmentManager(); + PopTime popTime=new PopTime(); + popTime.show(fm,"Show fragment"); + } + + void SetTime(int Hour ,int Minute ){ + + + // /save dat + savedata savedata =new savedata(this); + savedata.Alarmset(Hour,Minute); + savedata.SaveData(Hour,Minute); + + } +} diff --git a/Alaram App/app/src/main/java/com/alrubaye/alaram/MyReceiver.java b/Alaram App/app/src/main/java/com/alrubaye/alaram/MyReceiver.java new file mode 100644 index 000000000000..364c2e932bdf --- /dev/null +++ b/Alaram App/app/src/main/java/com/alrubaye/alaram/MyReceiver.java @@ -0,0 +1,28 @@ +package com.alrubaye.alaram; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.widget.Toast; + +public class MyReceiver extends BroadcastReceiver { + public MyReceiver() { + } + + @Override + public void onReceive(Context context, Intent intent) { + + if (intent.getAction().equalsIgnoreCase("com.alraby.alam")){ + Bundle b=intent.getExtras(); + Toast.makeText(context,b.getString("MyMessage"),Toast.LENGTH_LONG).show(); + } + else if (intent.getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")){ + // restart + savedata savedata =new savedata(context); + savedata.LoadData(); + + + } + } +} diff --git a/Alaram App/app/src/main/java/com/alrubaye/alaram/PopTime.java b/Alaram App/app/src/main/java/com/alrubaye/alaram/PopTime.java new file mode 100644 index 000000000000..ddd78257f3c1 --- /dev/null +++ b/Alaram App/app/src/main/java/com/alrubaye/alaram/PopTime.java @@ -0,0 +1,46 @@ +package com.alrubaye.alaram; + +/** + * Created by hussienalrubaye on 10/31/16. + */ + +import android.app.DialogFragment; +import android.os.Build; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TimePicker; + +/** + * Created by hussienalrubaye on 10/9/16. + */ + +public class PopTime extends DialogFragment implements View.OnClickListener { + + View view; + TimePicker tp; + Button buDome; + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) + { + view=inflater.inflate(R.layout.pop_time,container,false); + tp=(TimePicker)view.findViewById(R.id.tp1); + buDome=(Button)view.findViewById(R.id.buDome); + buDome.setOnClickListener(this); + return view; + } + + + @Override + public void onClick(View v) { + this.dismiss(); + MainActivity ma=(MainActivity)getActivity(); + if ((int) Build.VERSION.SDK_INT >= 23) + ma.SetTime(tp.getHour(),tp.getMinute()); + else + ma.SetTime(tp.getCurrentHour(),tp.getCurrentMinute()); + } +} diff --git a/Alaram App/app/src/main/java/com/alrubaye/alaram/savedata.java b/Alaram App/app/src/main/java/com/alrubaye/alaram/savedata.java new file mode 100644 index 000000000000..fa5ba44ed95b --- /dev/null +++ b/Alaram App/app/src/main/java/com/alrubaye/alaram/savedata.java @@ -0,0 +1,51 @@ +package com.alrubaye.alaram; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; + +import java.util.Calendar; + +/** + * Created by hussienalrubaye on 11/1/16. + */ + +public class savedata { + SharedPreferences ShredRef; + Context context; + public savedata(Context context){ + this.context=context; + ShredRef=context.getSharedPreferences("myRef",Context.MODE_PRIVATE); + } + + public void SaveData(int hour,int minute){ + SharedPreferences.Editor editor=ShredRef.edit(); + editor.putInt("hour",hour); + editor.putInt("minute",minute); + editor.commit(); + } + + public void LoadData(){ + int Minute=ShredRef.getInt("minute",0); + int Hour=ShredRef.getInt("hour",0); + Alarmset(Hour,Minute); + + } + + void Alarmset(int Hour,int Minute){ + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, Hour); + calendar.set(Calendar.MINUTE, Minute); + calendar.set(Calendar.SECOND, 0); + AlarmManager am = (AlarmManager) context.getSystemService (Context.ALARM_SERVICE); + Intent intent = new Intent(context, MyReceiver.class); + intent.setAction("com.alraby.alam"); + intent.putExtra("MyMessage","hello from alarm"); + PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT); + am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), + AlarmManager.INTERVAL_DAY , pi); + } +} diff --git a/Alaram App/app/src/main/res/layout/activity_main.xml b/Alaram App/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000000..0378cbadbdf5 --- /dev/null +++ b/Alaram App/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,28 @@ + + + + + + + diff --git a/Alaram App/app/src/main/res/layout/pop_time.xml b/Alaram App/app/src/main/res/layout/pop_time.xml new file mode 100644 index 000000000000..ef20812efd40 --- /dev/null +++ b/Alaram App/app/src/main/res/layout/pop_time.xml @@ -0,0 +1,24 @@ + + + + + + + +