public void SetUp(int fragmentId, DrawerLayout drawerLayout)
        {
            try
            {
                mFragmentContainerView = Activity.FindViewById(fragmentId);

                mDrawerLayout = drawerLayout;

                mDrawerLayout.SetDrawerShadow(MyTrap.Droid.Resource.Drawable.drawer_shadow, GravityCompat.Start);

                ActionBar actionBar = GetActionBar();

                actionBar.SetDisplayHomeAsUpEnabled(true);
                actionBar.SetHomeButtonEnabled(true);

                mDrawerToggle = new MyActionBarDrawerToggle(Activity, mDrawerLayout, MyTrap.Droid.Resource.Drawable.side_menu, MyTrap.Droid.Resource.String.navigation_drawer_open, MyTrap.Droid.Resource.String.navigation_drawer_close);

                ((MyActionBarDrawerToggle)mDrawerToggle).owner = this;

                var myRunnable = new MyRunnablePost();
                myRunnable.owner = this;

                mDrawerLayout.Post(myRunnable);

                mDrawerLayout.SetDrawerListener(mDrawerToggle);
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        private void SelectItem(int position)
        {
            try
            {
                mCurrentSelectedPosition = position;

                if (mDrawerListView != null)
                {
                    mDrawerListView.SetItemChecked(position, true);
                }

                if (mDrawerLayout != null)
                {
                    mDrawerLayout.CloseDrawer(mFragmentContainerView);
                }

                if (mCallbacks != null)
                {
                    mCallbacks.OnNavigationDrawerItemSelected(position);
                }
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 3
0
        public async void OnLocationChanged(Location location)
        {
            try
            {
                if (location != null && location.Latitude != 0)
                {
                    PositionApiRequest position = new PositionApiRequest();

                    position.Latitude  = (float)location.Latitude;
                    position.Longitude = (float)location.Longitude;

                    if (location.Time > 0)
                    {
                        var date = new DateTime(1970, 1, 1, 0, 0, 0);

                        date = date.AddMilliseconds(location.Time);

                        position.Date = date;
                    }
                    else
                    {
                        position.Date = DateTime.UtcNow;
                    }

                    AppStatus.Platform = EPlatform.ANDROID;

                    await SendPosition(position);
                }
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            try
            {
                mDrawerListView = (ListView)inflater.Inflate(MyTrap.Droid.Resource.Layout.fragment_navigation_drawer, container, false);

                var myAdapterOnClickListener = new MyViewOnClickListener();
                myAdapterOnClickListener.owner = this;

                mDrawerListView.OnItemClickListener = myAdapterOnClickListener;

                ArrayAdapter adapter = new ArrayAdapter(GetActionBar().ThemedContext, Android.Resource.Layout.SimpleListItemActivated1, new string[] {
                    Resources.GetString(MyTrap.Droid.Resource.String.home_left_menu),
                    Resources.GetString(MyTrap.Droid.Resource.String.arm_left_menu),
                    Resources.GetString(MyTrap.Droid.Resource.String.shop_left_menu),
                    Resources.GetString(MyTrap.Droid.Resource.String.traps_armed_left_menu),
                });

                mDrawerListView.SetAdapter(adapter);

                mDrawerListView.SetItemChecked(mCurrentSelectedPosition, true);
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }

            return(mDrawerListView);
        }
Exemplo n.º 5
0
        private async void LoginWithFacebook(Profile profile, string email)
        {
            try
            {
                StartLoading();

                UserApiRequest user = new UserApiRequest();

                user.Name              = profile.Name.ToString();
                user.RegisterType      = (int)ERegisterType.FACEBOOK;
                user.RegisterProfileId = profile.Id.ToString();
                user.Email             = email;

                user.ProfilePicture     = new ImageApiRequest();
                user.ProfilePicture.Url = profile.GetProfilePictureUri(200, 200).ToString();

                var response = await UserApiService.Login(user);

                if (ResponseValidator.Validate(response, this))
                {
                    AppStatus.UserLogged = response;
                    CheckUserLogged();
                }
                else
                {
                    StopLoading();
                }
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 6
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            try
            {
                if (AppStatus.UserLogged == null)
                {
                    MyTrapBDConfig.Initialize();

                    AppStatus.UserLogged = UserApiService.GetUserLogged();
                }

                if (AppStatus.UserLogged != null)
                {
                    Token = AppStatus.UserLogged.Token;

                    apiClient = new GoogleApiClient.Builder(Context, this, this).AddApi(LocationServices.API).Build();

                    locRequest = new LocationRequest();

                    apiClient.Connect();

                    IsStarted = true;
                }
                else
                {
                    StopSelf();
                }
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }

            return(StartCommandResult.Sticky);
        }
Exemplo n.º 7
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = null;

            try
            {
                view = inflater.Inflate(Resource.Layout.fragment_home, container, false);

                InitializeViews(view);

                CrashManager.Register(Activity);
                MetricsManager.Register(Activity, Activity.Application);

                HomeActivity homeActivity = (HomeActivity)Activity;

                if (homeActivity.firstOpen)
                {
                    RequestProfile(true);
                    homeActivity.firstOpen = false;
                }
                else
                {
                    RequestProfile(false);
                }
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }

            return(view);
        }
Exemplo n.º 8
0
        private void LoadProductPrices(List <Product> productsLoaded)
        {
            try
            {
                foreach (var itemGoogle in productsLoaded)
                {
                    foreach (var item in availableTraps)
                    {
                        if (item.KeyGoogle == itemGoogle.ProductId)
                        {
                            item.Price = itemGoogle.Price;
                            break;
                        }
                    }
                }

                TrapItemShopListAdapter adapter = new TrapItemShopListAdapter(Activity.ApplicationContext, availableTraps, this);

                list_traps_to_buy.SetAdapter(adapter);
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 9
0
        private async void SendArmedTrap()
        {
            try
            {
                progressDialog = ProgressDialog.Show(Activity, Resources.GetString(MyTrap.Droid.Resource.String.loading), Resources.GetString(MyTrap.Droid.Resource.String.arming_trap));

                ArmedTrapApiRequest armedTrap = new ArmedTrapApiRequest();

                armedTrap.NameKey   = selectedTrap.NameKey;
                armedTrap.Latitude  = (float)lastLocation.Latitude;
                armedTrap.Longitude = (float)lastLocation.Longitude;

                var response = await TrapApiService.Arm(armedTrap);

                if (ResponseValidator.Validate(response, Activity))
                {
                    ShowAlertArmedTrapSuccessfuly();
                }

                progressDialog.Cancel();
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            try
            {
                SetContentView(MyTrap.Droid.Resource.Layout.activity_home);

                mNavigationDrawerFragment = (NavigationDrawerFragment)FragmentManager.FindFragmentById(MyTrap.Droid.Resource.Id.navigation_drawer);

                mTitle = Title;

                mDrawerLayout = FindViewById <DrawerLayout>(MyTrap.Droid.Resource.Id.drawer_layout);

                mNavigationDrawerFragment.SetUp(MyTrap.Droid.Resource.Id.navigation_drawer, mDrawerLayout);

                if (Intent.Extras != null && Intent.Extras.GetBoolean("showNotification"))
                {
                    showNotification = true;
                }

                ActionBar.SetCustomView(MyTrap.Droid.Resource.Layout.action_bar);

                ActionBar.SetDisplayShowTitleEnabled(false);
                ActionBar.SetDisplayShowCustomEnabled(true);

                SendBroadcast(new Intent("RESTART_SERVICE"));
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 11
0
        private void SelectTrap(string trapKey)
        {
            try
            {
                UnselectTraps();

                foreach (UserTrapApiResult trapUser in userAvailableTraps)
                {
                    if (trapUser.NameKey.Equals(trapKey))
                    {
                        selectedTrap = trapUser;

                        foreach (ButtonChooseTrap btn in buttonsForChoose)
                        {
                            if (btn.TrapKey.Equals(trapKey))
                            {
                                var imageResourceName = "trap_" + btn.TrapKey.ToLower() + "_selected_icon";

                                var resourceId = Resources.GetIdentifier(imageResourceName, "drawable", Activity.PackageName);

                                btn.SetBackgroundResource(resourceId);
                            }
                        }

                        break;
                    }
                }

                UpdateRegionMap();
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 12
0
 public void ArmTrap()
 {
     try
     {
         if (lastLocation != null && selectedTrap != null)
         {
             new AlertDialog.Builder(Activity)
             .SetIcon(Android.Resource.Drawable.IcDialogAlert)
             .SetTitle(MyTrap.Droid.Resource.String.arm_trap_title_alert)
             .SetMessage(MyTrap.Droid.Resource.String.msg_confirm_arm_trap)
             .SetPositiveButton(MyTrap.Droid.Resource.String.yes, new MyDialogClickListener(this))
             .SetNegativeButton(MyTrap.Droid.Resource.String.no, new MyDialogClickListener(this))
             .Show();
         }
         else if (lastLocation == null)
         {
             //Nao foi possivel obter localizacao
         }
         else if (selectedTrap == null)
         {
             //Selecione uma trapa
         }
     }
     catch (Exception exception)
     {
         InsightsUtils.LogException(exception);
     }
 }
Exemplo n.º 13
0
        private async void LoadTraps()
        {
            try
            {
                var response = await PurchaseApiService.ListAvailableTraps();

                if (response != null)
                {
                    availableTraps = response;

                    LoadGooglePrices();
                }
                else
                {
                    progressDialog.Cancel();

                    HomeActivity homeActivity = (HomeActivity)Activity;
                    homeActivity.OnSectionAttached(HomeActivity.HOME_MENU_INDEX, true);
                }

                if (!AppStatus.UserLogged.ContainsTraps())
                {
                    lbl_title_my_traps.Visibility = ViewStates.Gone;
                }
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 14
0
        public void UpdateRegionMap()
        {
            try
            {
                if (selectedTrap != null)
                {
                    if (circle != null)
                    {
                        circle.Remove();
                    }

                    LatLng position = new LatLng(lastLocation.Latitude, lastLocation.Longitude);

                    int fillColor = int.Parse("80f15f4b", System.Globalization.NumberStyles.HexNumber);

                    CircleOptions circleOptions = new CircleOptions();

                    circleOptions.InvokeCenter(position);
                    //circleOptions.InvokeRadius(selectedTrap.Trap.Meters);
                    circleOptions.InvokeFillColor(fillColor);
                    circleOptions.InvokeStrokeWidth(3);

                    circle = googleMap.AddCircle(circleOptions);
                }
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 15
0
        private void InitializeComponents()
        {
            try
            {
                progress_bar = FindViewById <ProgressBar>(Resource.Id.progress_bar_login);

                btn_login_facebook = FindViewById <Button>(Resource.Id.btn_login_facebook);

                btn_login_facebook.SetOnClickListener(this);

                FacebookSdk.SdkInitialize(ApplicationContext);

                callbackManager = CallbackManagerFactory.Create();

                graphCallback = new GraphJSONObjectCallback
                {
                    HandleSuccess = email =>
                    {
                        LoginWithFacebook(Profile.CurrentProfile, email);
                    }
                };

                loginCallback = new FacebookCallback <LoginResult>
                {
                    HandleSuccess = loginResult =>
                    {
                        var request = GraphRequest.NewMeRequest(loginResult.AccessToken, graphCallback);

                        Bundle parameters = new Bundle();

                        parameters.PutString("fields", "id, name, email");

                        request.Parameters = parameters;

                        request.ExecuteAsync();
                    },
                    HandleCancel = () =>
                    {
                        StopLoading();
                    },
                    HandleError = loginError =>
                    {
                        StopLoading();
                    }
                };

                Xamarin.Facebook.Login.LoginManager.Instance.RegisterCallback(callbackManager, loginCallback);

                CheckUserLogged();
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 16
0
        private void LoadGooglePrices()
        {
            try
            {
                var ids = new List <string>();

                foreach (var item in availableTraps)
                {
                    ids.Add(item.KeyGoogle);
                }

                _serviceConnection.OnConnected += async() =>
                {
                    products = await _serviceConnection.BillingHandler.QueryInventoryAsync(ids, Xamarin.InAppBilling.ItemType.Product);

                    _serviceConnection.BillingHandler.OnProductPurchased += BillingHandler_OnProductPurchased;

                    _serviceConnection.BillingHandler.OnProductPurchasedError += BillingHandler_OnProductPurchasedError;

                    _serviceConnection.BillingHandler.OnUserCanceled += BillingHandler_OnUserCanceled;

                    LoadProductPrices(products.ToList());

                    var purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);

                    if (purchases != null)
                    {
                        foreach (var purchase in purchases)
                        {
                            var intent = await InsertIntent(purchase.ProductId);

                            var result = await RegisterPurchase(intent);

                            if (result)
                            {
                                _serviceConnection.BillingHandler.ConsumePurchase(purchase);
                            }
                            else
                            {
                                InvalidateBuyIntent(intent);
                            }
                        }
                    }

                    progressDialog.Cancel();
                };

                _serviceConnection.Connect();
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            try
            {
                base.OnActivityCreated(savedInstanceState);

                SetHasOptionsMenu(true);
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
        {
            try
            {
                base.OnConfigurationChanged(newConfig);

                mDrawerToggle.OnConfigurationChanged(newConfig);
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        public override void OnSaveInstanceState(Bundle outState)
        {
            try
            {
                base.OnSaveInstanceState(outState);

                outState.PutInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        public override void OnDetach()
        {
            try
            {
                base.OnDetach();

                mCallbacks = null;
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        public override void OnAttach(Activity activity)
        {
            try
            {
                base.OnAttach(activity);

                mCallbacks = (NavigationDrawerCallbacks)activity;
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        private void InitializeViews(View view, Bundle savedInstanceState)
        {
            try
            {
                mapFrag = (MapFragment)FragmentManager.FindFragmentById(MyTrap.Droid.Resource.Id.map_traps_armed);

                mapFrag.GetMapAsync(new MyOnMapReadyCallback(this));
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 23
0
        protected override void OnDestroy()
        {
            try
            {
                SendBroadcast(new Intent("RESTART_SERVICE"));

                base.OnDestroy();
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 24
0
 private void RegisterGoogleMessage()
 {
     try
     {
         Gcm.Client.GcmClient.CheckDevice(this);
         Gcm.Client.GcmClient.CheckManifest(this);
         Gcm.Client.GcmClient.Register(this, GcmBroadcastReceiver.SENDER_IDS);
     }
     catch (Exception exception)
     {
         InsightsUtils.LogException(exception);
     }
 }
        public override View GetView(int position, View view, ViewGroup parent)
        {
            try
            {
                if (view == null)
                {
                    view = mInflater.Inflate(Resource.Layout.trap_to_buy_list_item, null);
                }

                AvailableTrapApiResult item = itens[position];

                TextView txt_qty_item_buy   = view.FindViewById <TextView>(Resource.Id.txt_qty_item_buy);
                TextView txt_value_item_buy = view.FindViewById <TextView>(Resource.Id.txt_value_item_buy);

                Button btn_trap_item_buy = view.FindViewById <Button>(Resource.Id.btn_trap_item_buy);

                ImageView img_trap_item_buy = view.FindViewById <ImageView>(Resource.Id.img_trap_item_buy);

                if (item.NameKey.Equals(ETrap.BEAR))
                {
                    img_trap_item_buy.SetImageDrawable(view.Context.Resources.GetDrawable(Resource.Drawable.trap_bear_trap_selected_icon));
                }
                else if (item.NameKey.Equals(ETrap.MINE))
                {
                    img_trap_item_buy.SetImageDrawable(view.Context.Resources.GetDrawable(Resource.Drawable.trap_mine_trap_selected_icon));
                }
                else if (item.NameKey.Equals(ETrap.PIT))
                {
                    img_trap_item_buy.SetImageDrawable(view.Context.Resources.GetDrawable(Resource.Drawable.trap_pit_trap_selected_icon));
                }
                else if (item.NameKey.Equals(ETrap.DOGS))
                {
                    img_trap_item_buy.SetImageDrawable(view.Context.Resources.GetDrawable(Resource.Drawable.trap_dogs_trap_selected_icon));
                }
                else
                {
                    return(null);
                }

                btn_trap_item_buy.SetOnClickListener(new MyImageBuyClickListener(item, shopFragment));

                txt_qty_item_buy.Text   = item.Amount.ToString() + "x";
                txt_value_item_buy.Text = item.Price;
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }

            return(view);
        }
Exemplo n.º 26
0
 public void OnNavigationDrawerItemSelected(int position)
 {
     try
     {
         if (!IsFinishing)
         {
             FragmentManager.BeginTransaction().Replace(MyTrap.Droid.Resource.Id.container, PlaceholderFragment.newInstance(position + 1)).Commit();
         }
     }
     catch (Exception exception)
     {
         InsightsUtils.LogException(exception);
     }
 }
Exemplo n.º 27
0
 protected override void OnRegistered(Context context, string registrationId)
 {
     try
     {
         if (!string.IsNullOrEmpty(registrationId))
         {
             AppStatus.AppRegistration = registrationId;
         }
     }
     catch (Exception exception)
     {
         InsightsUtils.LogException(exception);
     }
 }
Exemplo n.º 28
0
        protected override void OnMessage(Context context, Intent intent)
        {
            try
            {
                string show = intent.Extras.GetString("show");

                if (show == "1")
                {
                    string message = intent.Extras.GetString("message");

                    bool   owner  = intent.Extras.GetString("owner") == "1" ? true : false;
                    string points = intent.Extras.GetString("points");

                    string ownerValue = "";

                    if (owner)
                    {
                        ownerValue = "owner";
                    }

                    int notificationId = NotificationID.GetNewId();

                    Intent notificationIntent = new Intent(context, typeof(HomeActivity));

                    notificationIntent.PutExtras(intent.Extras);

                    notificationIntent.PutExtra("showNotification", true);
                    notificationIntent.PutExtra("owner", ownerValue);

                    PendingIntent pIntent = PendingIntent.GetActivity(context, notificationId, notificationIntent, 0);

                    Notification notification = new Notification.Builder(context)
                                                .SetContentTitle(context.Resources.GetString(MyTrap.Droid.Resource.String.new_trap_notification))
                                                .SetContentText(message)
                                                .SetContentIntent(pIntent)
                                                .SetSmallIcon(MyTrap.Droid.Resource.Drawable.ic_launcher)
                                                .SetAutoCancel(true)
                                                .Build();

                    NotificationManager notificationManager = (NotificationManager)context.GetSystemService(NotificationService);

                    notificationManager.Notify(notificationId, notification);
                }
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 29
0
        private async void StartTracking()
        {
            try
            {
                locRequest.SetPriority(LocationRequest.PriorityLowPower);
                locRequest.SetFastestInterval(LOCATION_FASTEST_INTERVAL);
                locRequest.SetInterval(LOCATION_INTERVAL);

                await LocationServices.FusedLocationApi.RequestLocationUpdates(apiClient, locRequest, this);
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Exemplo n.º 30
0
        public async Task <bool> RegisterPurchase(BuyIntentApiRequest intent)
        {
            bool result = false;

            try
            {
                result = await PurchaseApiService.RegisterPurchase(intent);
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }

            return(result);
        }