예제 #1
0
        /// <summary>
        /// Method for loading the image asynchronously
        /// </summary>
        /// <param name="data"></param>
        /// <param name="url"></param>
        private async void LoadImage(Intent data)
        {
            try
            {
                // Call BitmapMaker to draw the selected image into a resampled bitmap
                Bitmap result = await BitmapMaker.CreateBitmapImage(240, 240, mUserPic.Width, mUserPic.Height, data, this);

                if (result != null)
                {
                    mUserImg = result;
                }
            }
            catch
            {
                string error = "There was a problem trying to load the image.";
                AlertGenerator.ShowError(error, this);
            }

            mUserPic.SetImageBitmap(mUserImg); // Set the bitmap into the userPic imageView
        }
예제 #2
0
        /// <summary>
        /// Method for loading the image asynchronously
        /// </summary>
        /// <param name="data"></param>
        /// <param name="url"></param>
        private async void LoadImage(Intent data, string url)
        {
            mPuzzlePanel.RemoveView(mPicBoxWhole);
            mLayoutMessage.Visibility  = ViewStates.Gone;
            mLayoutProgress.Visibility = ViewStates.Visible;
            sTvProgress.Text           = "0%";
            GC.Collect(); // Must call Garbage Collector

            try
            {
                // Call BitmapMaker to draw the selected image into a resampled bitmap
                if (url == null)
                {
                    mImage = await BitmapMaker.CreateBitmapImage(640, 360, mPuzzlePanel.Width, mPuzzlePanel.Height - 2, data, this);

                    sCurrentLvl   = LVL_1_NUM;
                    mBtnPlay.Text = "Play";
                    Drawable img = ContextCompat.GetDrawable(this, Resource.Drawable.ic_play_white);
                    mBtnPlay.SetCompoundDrawablesWithIntrinsicBounds(img, null, null, null); // Set button icon
                }
                else
                {
                    // Check for network availability
                    if (ConnectionChecker.IsNetworkAvailable(this))
                    {
                        Bitmap result = await BitmapMaker.CreateBitmapImage(640, 360, mPuzzlePanel.Width, mPuzzlePanel.Height - 2, url, sTvProgress, this);

                        if (result != null)
                        {
                            mImage        = result;
                            sCurrentLvl   = LVL_1_NUM;
                            mBtnPlay.Text = "Play";
                            Drawable img = ContextCompat.GetDrawable(this, Resource.Drawable.ic_play_white);
                            mBtnPlay.SetCompoundDrawablesWithIntrinsicBounds(img, null, null, null); // Set button icon
                        }
                        else
                        {
                            string error = "Couldn't load the image. Please check the URL.";
                            AlertGenerator.ShowError(error, this);
                        }
                    }
                    else
                    {
                        string error = "Device is not connected to a network.";
                        AlertGenerator.ShowError(error, this);
                    }
                }
            }
            catch
            {
                string error = "There was a problem trying to load the image.";
                AlertGenerator.ShowError(error, this);
            }

            mPuzzlePanel.AddView(mPicBoxWhole);  // Add picBoxWhole to puzzlePanel
            mPicBoxWhole.SetImageBitmap(mImage); // Set the bitmap into the picBoxWhole imageView

            mLayoutProgress.Visibility = ViewStates.Gone;
            mLayoutMessage.Visibility  = ViewStates.Visible;

            if (mImage != null)
            {
                // Make btnPlay clickable
                mBtnPlay.Enabled = true;
                mBtnPlay.SetBackgroundResource(Resource.Drawable.btn_accent_style);
            }
        }