Esempio n. 1
0
        public UUID GetUniqueueId(Context context)
        {
            var _result = (UUID)null;

            try
            {
                var _android_id = Android.Provider.Settings.Secure.GetString(
                    context.ContentResolver, Android.Provider.Settings.Secure.AndroidId
                    );

                if (_android_id == null)
                {
                    var _telephony_id = "";

                    var _telephony_service = context.GetSystemService(Context.TelephonyService).JavaCast <TelephonyManager>();
                    if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                    {
                        // TODO: Some phones has more than 1 SIM card or may not have a SIM card inserted at all
                        _telephony_id = _telephony_service.GetMeid(0);
                    }
                    else
#pragma warning disable CS0618 // Type or member is obsolete
                    {
                        _telephony_id = _telephony_service.DeviceId;
                    }
#pragma warning restore CS0618 // Type or member is obsolete

                    if (_telephony_id != null)
                    {
                        _result = UUID.NameUUIDFromBytes(Encoding.UTF8.GetBytes(_telephony_id));
                    }
                    else
                    {
                        _result = UUID.RandomUUID();
                    }
                }
                else
                {
                    _result = UUID.NameUUIDFromBytes(Encoding.UTF8.GetBytes(_android_id));
                }
            }
            catch (Java.Lang.Exception ex)
            {
                Log.Error(this.GetType().Name, ex.Message);
            }

            return(_result);
        }
Esempio n. 2
0
        public DeviceUuidFactory(Context context)
        {
            if (uuid == null)
            {
                lock (_lock)
                {
                    if (uuid == null)
                    {
                        var prefs = context.GetSharedPreferences(PREFS_FILE, FileCreationMode.Private);
                        var id    = prefs.GetString(PREFS_DEVICE_ID, null);

                        if (!string.IsNullOrWhiteSpace(id))
                        {
                            // Use the ids previously computed and stored in the prefs file
                            uuid = UUID.FromString(id);
                        }
                        else
                        {
                            var androidId = Settings.Secure.GetString(context.ContentResolver, Settings.Secure.AndroidId);

                            // Use the Android ID unless it's broken, in which case fallback on deviceId,
                            // unless it's not available, then fallback on a random number which we store
                            // to a prefs file

                            if ("9774d56d682e549c" == androidId)
                            {
                                //Generate a new UUID rather than require READ_PHONE_STATE
                                var c = new Java.Lang.String(androidId);
                                uuid = UUID.NameUUIDFromBytes(c.GetBytes("utf8"));
                            }
                            else
                            {
                                uuid = UUID.RandomUUID();
                            }

                            prefs.Edit().PutString(PREFS_DEVICE_ID, uuid.ToString()).Apply();
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public UUID GetUniqueueId(Context context)
        {
            var _result = (UUID)null;

            try
            {
                var _android_id = Android.Provider.Settings.Secure.GetString(
                    context.ContentResolver, Android.Provider.Settings.Secure.AndroidId
                    );

                if (_android_id == null)
                {
                    var _telephony_service = context.GetSystemService(Context.TelephonyService).JavaCast <TelephonyManager>();

                    var _telephony_id = _telephony_service.DeviceId;
                    if (_telephony_id != null)
                    {
                        _result = UUID.NameUUIDFromBytes(Encoding.UTF8.GetBytes(_telephony_id));
                    }
                    else
                    {
                        _result = UUID.RandomUUID();
                    }
                }
                else
                {
                    _result = UUID.NameUUIDFromBytes(Encoding.UTF8.GetBytes(_android_id));
                }
            }
            catch (Java.Lang.Exception ex)
            {
                Log.Error(this.GetType().Name, ex.Message);
            }

            return(_result);
        }
Esempio n. 4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_login);

            // This MobileServiceClient has been configured to communicate with the Azure Mobile App and
            // Azure Gateway using the application url. You're all set to start working with your Mobile App!
            //Microsoft.WindowsAzure.MobileServices.MobileServiceClient eHealthHeartRateClient = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient("https://ehealthheartrate.azurewebsites.net");

            // Set our view from the "main" layout resource


            EditText etPassword = (EditText)FindViewById(Id.Password);
            EditText etUsername = (EditText)FindViewById(Id.Username);

            // TO DO: check how I can do this about Spinners

            Button blogin  = (Button)FindViewById(Id.Blogin);
            Button bsignup = (Button)FindViewById(Id.BSignUp);

            if (mClient == null)
            {
                AzureServiceAdapter.Initialize(this);
                mClient = AzureServiceAdapter.getInstance().getClient();
            }

            //IMobileServiceTable<Users> mTable = mClient.GetTable("Users", Users.class);  <-- as it was in java
            IMobileServiceTable <Users> mTable = mClient.GetTable <Users>();

            Toast.MakeText(this, "Welcome", ToastLength.Long).Show();


            // actions per button
            blogin.Click += async(sender, e) =>
            {
                Toast.MakeText(this, "login attempt as " + etUsername.Text.ToString(), ToastLength.Long).Show();
                try
                {
                    Users signinItem = await mTable.LookupAsync(UUID.NameUUIDFromBytes(Encoding.ASCII.GetBytes(etUsername.Text.ToString())).ToString());

                    System.Diagnostics.Debug.WriteLine("#########################################");
                    System.Diagnostics.Debug.WriteLine(signinItem);
                    System.Diagnostics.Debug.WriteLine("#########################################");
                    //Users item = ( Users )test_item;
                    //Debug.
                    if (signinItem != null)
                    {
                        if (signinItem.getpassword().Equals(etPassword.Text.ToString()))
                        {
                            current_username = signinItem.getusername();

                            Toast.MakeText(this, "Login Successfull", ToastLength.Long).Show();

                            Bundle itemBundle = new Bundle();
                            itemBundle.PutString("username", signinItem.getusername());
                            itemBundle.PutInt("age", Convert.ToInt32(signinItem.getdob()));
                            itemBundle.PutInt("height", signinItem.getheight());
                            itemBundle.PutInt("weight", signinItem.getweight());

                            var activity2 = new Intent(this, typeof(user_page));
                            activity2.PutExtra("currentUserBundle", itemBundle);
                            StartActivity(activity2);
                        }
                        else
                        {
                            current_username = "";
                            Toast.MakeText(this, "Login Failed, Invalid username or password", ToastLength.Long).Show();
                        }
                    }
                } catch (MobileServiceInvalidOperationException exp)
                {
                    if (exp.Message.Contains("The item does not exist"))
                    {
                        Toast.MakeText(this, "Username or Password are incorrect. Please try again.", ToastLength.Long).Show();
                        return;
                    }
                    else
                    {
                        Toast.MakeText(this, "Something went wrong :/ please try again!", ToastLength.Long).Show();
                    }
                }
            };

            // actions per button
            bsignup.Click += async(sender, e) =>
            {
                StartActivity(new Intent(this, typeof(SignUpActivity)));
            };
        }
Esempio n. 5
0
 public static UUID ToUUID(this RFCOMMPort port)
 {
     return(UUID.NameUUIDFromBytes(port));
 }
Esempio n. 6
0
        /*
         * @override
         * public string tostring()
         * {
         *  return new stringbuilder().append("\nuseritem:\n")
         *          .append(string.format("\tid         : %s\n", id.tostring()))
         *          .append(string.format("\tusername   : %s\n", username))
         *          .append(string.format("\tpassword   : %s\n", password))
         *          .append(string.format("\tfirst_name : %s\n", first_name))
         *          .append(string.format("\tlast_name  : %s\n", last_name))
         *          .append(string.format("\tsex        : %s\n", sex))
         *          .append(string.format("\tdob        : %s\n", dob))
         *          .append(string.format("\theight     : %d\n", height))
         *          .append(string.format("\tweight     : %d\n", weight))
         *          .append(string.format("\thealth_c   : %s\n", health_c))
         *          .append(string.format("\tmin_hr     : %d\n", min_hr))
         *          .append(string.format("\tmax_hr     : %d\n\n", max_hr))
         *          .tostring();
         * }
         */

        /*
         * @param id
         */
        public void setid()
        {
            //this.id = this.getusername() != "" ? UUID.NameUUIDFromBytes(Encoding.ASCII.GetBytes(getusername().ToString())) : UUID.RandomUUID();
            id = UUID.NameUUIDFromBytes(Encoding.ASCII.GetBytes(getusername().ToString())).ToString();
        }
Esempio n. 7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_signup);

            // This MobileServiceClient has been configured to communicate with the Azure Mobile App and
            // Azure Gateway using the application url. You're all set to start working with your Mobile App!
            //Microsoft.WindowsAzure.MobileServices.MobileServiceClient eHealthHeartRateClient = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient("https://ehealthheartrate.azurewebsites.net");

            // Set our view from the "main" layout resource

            EditText etFirstname            = (EditText)FindViewById(Id.etFirstName);
            EditText etLasttname            = (EditText)FindViewById(Id.etLastName);
            EditText etPassword             = (EditText)FindViewById(Id.etPassword);
            EditText etHeigth               = (EditText)FindViewById(Id.etHeight);
            EditText etWeigth               = (EditText)FindViewById(Id.etWeight);
            EditText etDob                  = (EditText)FindViewById(Id.etDob);
            EditText etUsername             = (EditText)FindViewById(Id.etUserName);
            EditText etDoctorName           = (EditText)FindViewById(Id.etDoctorName);
            Spinner  ganderSpinner          = (Spinner)FindViewById(Id.spinnerGnder);
            Spinner  healthConditionSpinner = (Spinner)FindViewById(Id.spinnerHealthCondiotion);

            // TODO: check how I can do this about Spinners
            string[]     data          = { "Female", "Male" };
            ArrayAdapter ganderAdapter = new ArrayAdapter(this,
                                                          Android.Resource.Layout.SimpleListItem1, data);

            ganderSpinner.Adapter = ganderAdapter;

            string[]     data1             = { "Healthy", "UnHealthy" };
            ArrayAdapter healthCondAdapter = new ArrayAdapter(this,
                                                              Android.Resource.Layout.SimpleListItem1, data1);

            healthConditionSpinner.Adapter = healthCondAdapter;

            Button bsignup = (Button)FindViewById(Id.Bsingnup);

            mClient = AzureServiceAdapter.getInstance().getClient();

            //IMobileServiceTable<Users> mTable = mClient.GetTable("Users", Users.class);  <-- as it was in java
            mTable = mClient.GetTable <Users>();
            Toast.MakeText(this, "Welcome", ToastLength.Long).Show();

            // actions per button
            bsignup.Click += async(sender, e) =>
            {
                if (!isInputValidate(etFirstname,
                                     etLasttname,
                                     etPassword,
                                     etHeigth,
                                     etWeigth,
                                     etDob,
                                     etUsername,
                                     etDoctorName))
                {
                    return;
                }
                //Newtonsoft.Json.Linq.JToken useritem;
                Users useritem;

                try
                {
                    // Checking out if username already exist in DB
                    useritem = await mTable.LookupAsync(UUID.NameUUIDFromBytes(Encoding.ASCII.GetBytes(etUsername.Text.ToString())).ToString());

                    // Getting to this line iff LookupAsync successfully finished
                    System.Diagnostics.Debug.WriteLine("Lookup requests return with success.");
                    etUsername.Error = "Username is already exists\n";
                    validInput       = false;
                    System.Diagnostics.Debug.WriteLine("User is already exists\n{0}\n", etUsername.Text.ToString());
                }
                // In case the user is valid (not exists in DB) we will create a new one
                catch (MobileServiceInvalidOperationException exp)
                {
                    if (exp.Message.Contains("The item does not exist"))
                    {
                        System.Diagnostics.Debug.WriteLine("Lookup requests return with failure.");
                        System.Diagnostics.Debug.WriteLine("The username is free, lts' send signup request!");

                        // SignUp Request
                        sendSignupReq(etFirstname,
                                      etLasttname,
                                      etPassword,
                                      etHeigth,
                                      etWeigth,
                                      etDob,
                                      etUsername,
                                      etDoctorName,
                                      ganderSpinner,
                                      healthConditionSpinner);

                        // Finaly Create a user Item
                        //Users item = json2UserItem(useritem);

                        // Enter prev_n, avg, deviation = 0 when creating the tables
                    }
                    else
                    {
                        Toast.MakeText(this, "Something went wrong :/ please try again!", ToastLength.Long).Show();
                    }
                }
            };
        }