示例#1
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Sample);

            var imageView = FindViewById <ImageView>(Resource.Id.iv_photo);

            currentMatrixTextView = FindViewById <TextView>(Resource.Id.tv_current_matrix);

            var bitmap = await BitmapFactory.DecodeResourceAsync(Resources, Resource.Drawable.wallpaper);

            imageView.SetImageBitmap(bitmap);

            // The MAGIC happens here!
            attacher = new PhotoViewAttacher(imageView);

            // Lets attach some listeners, not required though!
            attacher.MatrixChange += (sender, e) =>
            {
                currentMatrixTextView.Text = e.Rect.ToString();
            };
            attacher.PhotoTap += (sender, e) =>
            {
                float xPercentage = e.X * 100f;
                float yPercentage = e.Y * 100f;
                ShowToast(string.Format("Photo Tap! X:{0:0.00} % Y:{1:0.00} % ID: {2}", xPercentage, yPercentage, e.View == null ? 0 : e.View.Id));
            };
        }
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (data != null)
            {
                bitmap = (Bitmap)data.Extras.Get("data");
                picture.SetImageBitmap(bitmap);

                strGuid = Guid.NewGuid().ToString();
                //myDictionary.Add(strGuid, bitmap);

                if (attacher == null)
                {
                    attacher = new PhotoViewAttacher(picture);
                }
                else
                {
                    attacher.Update();
                }
                //string temp = SaveToInternalStorage(bitmap);
            }
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);

            Activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;

            var view = inflater.Inflate(Resource.Layout.Fragment_ImageView, container, false);

            this.Dialog.SetCanceledOnTouchOutside(false);
            imgView = view.FindViewById <ImageView>(Resource.Id.img);

            PhotoViewAttacher photoView = new PhotoViewAttacher(imgView);

            photoView.Update();

            byte[] imgPassed = Arguments.GetByteArray("imagem");

            ByteHelper helper = new ByteHelper();

            imgPassedBitmap = helper.ByteArrayToImage(imgPassed);
            imgView.SetImageBitmap(imgPassedBitmap);
            return(view);
        }
 private void Initialize()
 {
     attacher = new PhotoViewAttacher(this);
     SetScaleType(ScaleType.Matrix);
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            _assets = this.Assets;
            var content = _assets.List("Cards");

            _cards            = new List <Card>();// = ArrayList<Card>
            _currentPlaneView = FindViewById <ImageView>(Resource.Id.imageView1);
            _transformButton  = FindViewById <ImageButton>(Resource.Id.imageButton1);
            _seasonButton     = FindViewById <ImageButton>(Resource.Id.imageButton2);
            _toolTipButton    = FindViewById <ImageButton>(Resource.Id.imageButton3);
            _gestureDetector  = new GestureDetector(this);

            if (_done == 1)
            {
                return;
            }

            string[] toolTips = new string[content.Length];

            using (System.IO.StreamReader sr = new System.IO.StreamReader(_assets.Open("Tooltip.txt")))
            {
                // Read the stream to a string, and write the string to the console.
                string line = sr.ReadToEnd();
                toolTips = line.Split('#');
            }

            System.Console.WriteLine("" + toolTips.Length + toolTips[0]);

            int k = 0;

            foreach (string c in content)
            {
                Card cur = Card.MyRegex(c);
                if (k < toolTips.Length)
                {
                    cur.SetToolTip(toolTips[k++]);
                }
                _cards.Add(cur);
            }

            int doOnce = 0;


            // get input stream
            System.IO.Stream ims = null;



            for (int i = 0; i < _cards.Count; i++)
            {
                //multiple a change of seasons
                ims = _assets.Open("Cards/" + _cards[i].Path);

                // load image as Drawable
                _cards[i].Bm = new BitmapDrawable(BitmapFactory.DecodeStream(ims));
                if (_cards[i].Name == "A Change of Seasons" && doOnce == 0)
                {
                    doOnce++;
                    _cards.Add(new Phenomenon(_cards[i], true));
                    _cards.Add(new Phenomenon(_cards[i], true));
                    _cards.Add(new Phenomenon(_cards[i], true));
                }
                //tie day and night
                if (_cards[i] is TransformingPlane)
                {
                    TransformingPlane c_T = (TransformingPlane)_cards[i];
                    for (int j = i + 1; j < _cards.Count; j++)
                    {
                        TransformingPlane d_T;
                        if (_cards[j].IsTransforming())
                        {
                            d_T          = (TransformingPlane)_cards[j];
                            ims          = _assets.Open("Cards/" + _cards[j].Path);
                            _cards[j].Bm = new BitmapDrawable(BitmapFactory.DecodeStream(ims));
                        }
                        else
                        {
                            continue;
                        }

                        if (c_T.SameId(d_T))
                        {
                            c_T.Link(d_T);
                            if (c_T.DorN)
                            {
                                _cards.Remove(_cards[j]);
                            }
                            else
                            {
                                _cards.Remove(_cards[i]);
                            }
                            continue;
                        }
                    }
                }
            }
            _cards = Randomize(_cards);


            // set image to ImageView

            _currentPlaneView.SetScaleType(ImageView.ScaleType.FitCenter);
            _currentPlane         = _cards[0];
            _currentPlane.visited = true;
            _currentPlaneView.SetImageDrawable(_currentPlane.Bm);
            _attacher = new PhotoViewAttacher(_currentPlaneView);

            _attacher.SingleFling += (sender, e) => {
                OnFling(e.P0, e.P1, e.P2, e.P3);
            };

            _attacher.Update();

            System.Random rnd = new System.Random();
            _currentSeason = rnd.Next(0, 4);

            _seasonButton.SetBackgroundColor(Color.Transparent);
            _transformButton.SetBackgroundColor(Color.Transparent);
            _toolTipButton.SetBackgroundColor(Color.Transparent);
            ChangeSeasons(_currentSeason);
            _seasonButton.Click += (sender, e) => {
                ChangeSeasons(_currentSeason);
            };


            if (_cards[_index].IsTransforming())
            {
                _transformButton.Visibility = ViewStates.Visible;
                _transformButton.SetImageResource(Resource.Drawable.d);
            }
            else
            {
                _transformButton.Visibility = ViewStates.Invisible;
            }

            if (_currentPlane.IsWonders())
            {
                _wondersCount = 1;
                _toolTipButton.SetImageResource(Resource.Drawable.tooltip_w_1);
            }
            else
            {
                _toolTipButton.SetImageResource(Resource.Drawable.tooltip_0);
            }


            _transformButton.Click += (sender, e) => {
                //Nuovo Current Plane
                _currentPlane = ((TransformingPlane)_currentPlane).ManageToggle();
                //Modifica icona del pulsante
                _transformButton.SetImageResource(((TransformingPlane)_currentPlane).DorN
                    ? Resource.Drawable.d
                    : Resource.Drawable.n);
                _currentPlaneView.SetImageDrawable(null);
                //Visualizzazione nuovo piano
                _currentPlaneView.SetImageDrawable(_currentPlane.Bm);
            };

            _toolTipButton.Click += (sender, e) => {
                _dialog = new Dialog(this);
                _dialog.SetContentView(Resource.Layout.secondlayout);

                string toolTip = _currentPlane.ToolTip;

                _dialog.SetTitle(toolTip.Substring(0, toolTip.IndexOf('@')));

                _dialog.SetCancelable(true);
                TextView text = _dialog.FindViewById <TextView>(Resource.Id.DialogView);
                text.Text = toolTip.Replace('@', ' ');
                //Button CloseButton = _dialog.FindViewById<Button>(Resource.Id.DialogButton);
                //CloseButton.Click += DialogButtonClick;

                _dialog.Show();
            };

            _done = 1;
            this.Window.AddFlags(WindowManagerFlags.KeepScreenOn);
        }
示例#6
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            _assets = this.Assets;
            var content = _assets.List("Cards");

            _cards             = new List <Card>();// = ArrayList<Card>
            _cards_indices     = new List <int>();
            _currentPlaneView  = FindViewById <ImageView>(Resource.Id.imageView1);
            _phenomenon_button = FindViewById <ImageButton>(Resource.Id.imageButton1);
            _upleft_button     = FindViewById <ImageButton>(Resource.Id.imageButton2);
            _downleft_button   = FindViewById <ImageButton>(Resource.Id.imageButton3);
            _menu_button       = FindViewById <ImageButton>(Resource.Id.imageButton4);

            _phenomenon_button.Visibility = ViewStates.Invisible;
            _upleft_button.Visibility     = ViewStates.Invisible;
            _downleft_button.Visibility   = ViewStates.Invisible;
            _menu_button.Visibility       = ViewStates.Invisible;

            _wild_effects = new List <string>();

            using (System.IO.StreamReader sr = new System.IO.StreamReader(_assets.Open("effetti.txt")))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    _wild_effects.Add(line);
                }
            }

            _gestureDetector = new GestureDetector(this);

            if (_done == 1)
            {
                return;
            }

            string[] toolTips = new string[content.Length];

            int ci = 0;

            foreach (string c in content)
            {
                Card cur = Card.MyRegex(c);
                _cards.Add(cur);
                _cards_indices.Add(ci++);
            }


            // get input stream
            System.IO.Stream ims = null;



            for (int i = 0; i < _cards.Count; i++)
            {
                //multiple a change of seasons
                ims = _assets.Open("Cards/" + _cards[i].Path);

                // load image as Drawable
                _cards[i].Bm = new BitmapDrawable(BitmapFactory.DecodeStream(ims));
            }


            if (ap.loadDeckList() == "")
            {
                _cards_indices = Randomize(_cards_indices);
            }
            else
            {
                _cards_indices.Clear();
                foreach (string card_index in ap.loadDeckList().Split(';'))
                {
                    _cards_indices.Add(Convert.ToInt32(card_index));
                }
                AlertDialog.Builder alertDiag = new AlertDialog.Builder(this);
                alertDiag.SetTitle("Restart Anew");
                alertDiag.SetMessage("Do you really want to reset the Planechase?");
                alertDiag.SetPositiveButton("Reset", (senderAlert, args) => { //TOCOMPLETE
                    _cards_indices.Clear();
                    int cid = 0;
                    foreach (var c in _cards)
                    {
                        _cards_indices.Add(cid++);
                    }
                    _cards_indices = Randomize(_cards_indices);
                    Toast.MakeText(this, "Done", ToastLength.Short).Show();
                });
                alertDiag.SetNegativeButton("Cancel", (senderAlert, args) => {
                    alertDiag.Dispose();
                });
                Dialog diag = alertDiag.Create();
                diag.Show();
            }


            _phenomenon_button.SetImageResource(Resource.Drawable.sorcerericon);

            // set image to ImageView

            _currentPlaneView.SetScaleType(ImageView.ScaleType.FitCenter);
            _currentPlane         = _cards[_cards_indices[0]];
            _currentPlane.visited = true;
            _currentPlaneView.SetImageDrawable(_currentPlane.Bm);
            _attacher = new PhotoViewAttacher(_currentPlaneView);

            _attacher.SingleFling += new EventHandler <SingleFlingEventArgs>(OnSingleFling);

            _attacher.Update();


            _done = 1;
            this.Window.AddFlags(WindowManagerFlags.KeepScreenOn);
        }