コード例 #1
0
ファイル: MainActivity.cs プロジェクト: yellow444/FattyFood
        protected override void OnCreate(Bundle savedInstanceState)
        {
            /*
             * string [] user = LoginAuth.CachedUserData (this).Result;
             * string _provider = user [0];
             * string _mytoken = user [1];
             */
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);

            App.MyName = prefs.GetString("name", "DEFAULT");
            if ((string.IsNullOrWhiteSpace(App.MyName)) || (App.MyName == "DEFAULT"))
            {
                Intent intent = new Intent(this, typeof(LoginAuth));
                intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
                StartActivity(intent);
                base.OnCreate(savedInstanceState);
                Finish();
                return;
            }
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.VmPolicy         policy  = builder.DetectActivityLeaks().PenaltyLog().Build();
            StrictMode.SetVmPolicy(policy);
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            Button openPhoto = FindViewById <Button>(Resource.Id.openPhoto);

            openPhoto.Click += OpenPhoto_Click;
            Button SendF = FindViewById <Button>(Resource.Id.SendF);

            SendF.Click += SendF_Click;
            Button openCamera = FindViewById <Button>(Resource.Id.openCamera);

            openCamera.Click += TakeAPicture;
            mRecyclerView     = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            mPhotoAlbum       = new PhotoAlbum();
            ScreenWidth       = Resources.DisplayMetrics.WidthPixels;
            ScreenHeight      = Resources.DisplayMetrics.HeightPixels;

            /*
             * while ( !( CheckSelfPermission (storageWritePermission) == ( int )Permission.Granted) )
             * {
             *  RunOnUiThread ( ( )=>{
             *      RequestPermissions (new string [] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage }, REQUEST_EXTERNAL_STORAGE);
             *  });
             * }
             */
            if (CheckSelfPermission(storageWritePermission) == (int)Permission.Granted)
            {
                if (IsThereAnAppToTakePictures())
                {
                    CreateDirectoryForPictures();
                    mPhotoAlbum.SetPhotoAlbum(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures) + "/CameraAppDemo");
                    mLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false);
                    mRecyclerView.SetLayoutManager(mLayoutManager);
                    mAdapter            = new PhotoAlbumAdapter(this, mPhotoAlbum);
                    mAdapter.ItemClick += OnItemClick;
                    mRecyclerView.SetAdapter(mAdapter);
                }
            }
            else
            {
                RequestPermissions(new string[] { Manifest.Permission.WriteExternalStorage }, REQUEST_EXTERNAL_STORAGE_READ);
            }

            /*
             * while (!( (CheckSelfPermission (cameraPermission) == ( int )Permission.Granted)&& (CheckSelfPermission (storageReadPermission) == ( int )Permission.Granted && CheckSelfPermission (storageWritePermission) == ( int )Permission.Granted) ))
             */
            /*
             *  while ( !( (CheckSelfPermission (storageReadPermission) == ( int )Permission.Granted)) )
             *  {
             *  RequestPermissions (new string [] {   Manifest.Permission.ReadExternalStorage}, REQUEST_EXTERNAL_STORAGE);
             * }
             */
            /*
             * while ( !((CheckSelfPermission (storageWritePermission) == ( int )Permission.Granted)) )
             * {
             *  RequestPermissions (new string [] { Manifest.Permission.Camera, Manifest.Permission.WriteExternalStorage }, REQUEST_EXTERNAL_STORAGE);
             * }
             */
            //Manifest.Permission.Camera, Manifest.Permission.WriteExternalStorage

            /*
             * while ( !(CheckSelfPermission (ReadPhoneState) == ( int )Permission.Granted) )
             * {
             *  RequestPermissions (new string [] { Manifest.Permission.ReadPhoneState }, READ_PHONE_STATE);
             * }
             * while ( !(CheckSelfPermission (storageReadPermission) == ( int )Permission.Granted && CheckSelfPermission (storageWritePermission) == ( int )Permission.Granted) )
             * {
             *  RequestPermissions (new string [] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage }, REQUEST_EXTERNAL_STORAGE);
             * }
             */
            myActivity = this;
            string str = "";

            for (int i = 0; i < App.MyName.Length; i++)
            {
                if (!char.IsLetterOrDigit(App.MyName[i]) && App.MyName[i] != '_')
                {
                    str = str + '_';
                }
                else
                {
                    str = str + App.MyName[i];
                }
            }
            App.MyName = str;
            Toast.MakeText(this, "Hello " + App.MyName, ToastLength.Long).Show();
        }
コード例 #2
0
ファイル: MainActivity.cs プロジェクト: yellow444/FattyFood
 private void SendF_Click(object sender, EventArgs e)
 {
     mPhotoAlbum.SetPhotoAlbum(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures) + "/CameraAppDemo");
     SendFiles();
 }