Ejemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            lastFragments = new List <Android.App.Fragment>();
            description   = DataManager.GetInstance().Description();

            SetContentView(Resource.Layout.activity_main);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;

            DrawerLayout drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);

            ActionBarDrawerToggle toggle = new Android.Support.V7.App.ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);

            drawer.AddDrawerListener(toggle);
            toggle.SyncState();


            var detailsFrag = DescriptionFragment.NewInstance();

            if (currentFragment == null)
            {
                currentFragment = detailsFrag;
            }
            ChangeFragment(currentFragment);

            NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);

            navigationView.SetNavigationItemSelectedListener(this);
        }
Ejemplo n.º 2
0
        public bool OnNavigationItemSelected(IMenuItem item)
        {
            int  id = item.ItemId;
            bool startNewActivity = false;

            Android.App.Fragment fragment = null;
            switch (id)
            {
            case Resource.Id.nav_home:
                fragment = DescriptionFragment.NewInstance();
                break;

            case Resource.Id.nav_training:
                fragment = new ListActivitiesFragment <Training>();
                break;

            case Resource.Id.nav_adresse:
                Intent newIntentMaps = null;
                if (isAppInstalled(this, "com.android.maps") || isAppInstalled(this, "com.google.android.gms.maps"))
                {
                    newIntentMaps = new Intent(Intent.ActionView, Android.Net.Uri.Parse("geo:" + description.Lat + "," + description.Long + "?q=" + description.Adress));
                }
                else
                {
                    newIntentMaps = new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://www.google.com/maps/place/" + description.Adress + "/@" + description.Lat + "," + description.Long));
                }
                StartActivity(newIntentMaps);
                break;

            case Resource.Id.nav_project:
                fragment = new ListActivitiesFragment <Project>();
                break;

            case Resource.Id.nav_persoproject:
                fragment = new ListActivitiesFragment <PersonalProject>();
                break;

            case Resource.Id.nav_facebook:
                Intent newIntent = null;
                try
                {
                    if (isAppInstalled(this, "com.facebook.orca") || isAppInstalled(this, "com.facebook.katana") ||
                        isAppInstalled(this, "com.example.facebook") || isAppInstalled(this, "com.facebook.android"))
                    {
                        newIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("fb://page/jeremy.talabard"));
                    }
                    else
                    {
                        newIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(description.FbLink));
                    }
                }
                catch { newIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(description.FbLink)); }
                StartActivity(newIntent);
                break;

            case Resource.Id.nav_hobie:
                fragment = new ListActivitiesFragment <Hobie>();
                break;

            case Resource.Id.nav_job:
                fragment = new ListActivitiesFragment <Job>();
                break;

            case Resource.Id.nav_linkedin:
                try
                {
                    Intent linkedinIntent = new Intent(Intent.ActionView);
                    linkedinIntent.SetData(Android.Net.Uri.Parse(description.LinkedinLink));
                    linkedinIntent.SetPackage("com.linkedin.android");
                    StartActivity(linkedinIntent);
                }
                catch
                {
                    StartActivity(new Intent(Intent.ActionView,
                                             Android.Net.Uri.Parse(description.LinkedinLink)));
                }
                break;

            case Resource.Id.nav_knowledges:
                fragment = new KnowledgeFragment();
                break;

            case Resource.Id.nav_phone:
                if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.CallPhone) == (int)Permission.Granted)
                {
                    Intent phone = new Intent(Intent.ActionCall,
                                              Android.Net.Uri.Parse(string.Format("tel:{0}", description.Phone)));
                    StartActivity(phone);
                }
                else
                {
                    Android.Support.V4.App.ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.CallPhone }, 5);
                }

                break;

            case Resource.Id.nav_openinbrowser:
                var uri    = Android.Net.Uri.Parse("http://www.talabard-jeremy.fr.cr");
                var intent = new Intent(Intent.ActionView, uri);
                StartActivity(intent);
                break;

            case Resource.Id.nav_mail:
                SendMail();
                break;

            default:
                break;
            }

            if (fragment != null && !startNewActivity)
            {
                ChangeFragment(fragment);
                if (!lastFragments.Contains(currentFragment))
                {
                    lastFragments.Add(currentFragment);
                }
                currentFragment = fragment;
            }

            DrawerLayout drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);

            drawer.CloseDrawer(GravityCompat.Start);
            return(true);
        }