Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.ProductDetail);

            Bundle extras     = Intent.Extras;
            String actionText = extras.GetString(GameStoreConstants.ParamAction);

            EditText  name      = (EditText)FindViewById(Resource.Id.productname);
            EditText  price     = (EditText)FindViewById(Resource.Id.price);
            Button    loadImage = (Button)FindViewById(Resource.Id.loadimage);
            ImageView image     = (ImageView)FindViewById(Resource.Id.image);

            switch (actionText)
            {
            case GameStoreConstants.ParamActionAdd:
                mAction = DetailViewMode.Add;
                break;

            case GameStoreConstants.ParamActionEdit:
                mAction = DetailViewMode.Edit;
                break;

            default:
                break;
            }

            mProduct = new Product();
            if (mAction == DetailViewMode.Edit)
            {
                int id = extras.GetInt(GameStoreConstants.ParamId);
                mProduct = DatabaseHelper.Database.GetProduct(id);
                if (mProduct != null)
                {
                    name.Text  = mProduct.ProductName;
                    price.Text = Convert.ToString(mProduct.Price);
                    Bitmap bitmap = ImageHelper.BytesToBitmap(mProduct.Image);
                    image.SetImageBitmap(bitmap);
                    Drawable drawable = new BitmapDrawable(Resources, bitmap);
                    loadImage.Background = drawable;
                    loadImage.Text       = "";
                }
            }

            loadImage.Click += delegate
            {
                var imageIntent = new Intent();
                imageIntent.SetType("image/*");
                imageIntent.SetAction(Intent.ActionGetContent);
                StartActivityForResult(
                    Intent.CreateChooser(imageIntent, "Select photo"), 0);
                //Intent intent = new Intent(Intent.ActionPick, MediaStore.Images.Media.ExternalContentUri);
                //StartActivityForResult(intent, 0);
            };
        }
        private void Initialization()
        {
            // - (id)initWithFrame(CGRect)frame {
            // if ((this = [super initWithFrame:frame])) {
            var statusBarFrame = UIApplication.SharedApplication.StatusBarFrame;

            var newSize = new SizeF
                {
                    Height = (statusBarFrame.Size.Height == 2*StatusBarHeight)
                                 ? StatusBarHeight
                                 : statusBarFrame.Size.Height,
                    Width = _isIPhoneEmulationMode ? 320f : statusBarFrame.Size.Width
                };
            // only use height of 20px even is status bar is doubled
            // if we are on the iPad but in iPhone-Mode (non-universal-app) correct the width
            statusBarFrame.Size = newSize;

            // Place the window on the correct level and position
            WindowLevel = LevelStatusBar + 1f;
            Frame = statusBarFrame;
            Alpha = 0f;
            Hidden = false;

            // Default Small size: just show Activity Indicator
            SmallFrame = new RectangleF(statusBarFrame.Size.Width - WidthSmall, 0f, WidthSmall,
                                        statusBarFrame.Size.Height);

            // Default-values
            _animation = StatusBarOverlayAnimation.None;
            Active = false;
            HidesActivity = false;
            ForcedToHide = false;

            // the detail view that is shown when the user touches the status bar in animation mode "FallDown"
            DetailView = new UIView(_defaultDetailViewFrame)
                {
                    BackgroundColor = UIColor.Black,
                    Alpha = DetailViewAlpha,
                    AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
                };
            _detailViewMode = DetailViewMode.Custom;

            // add rounded corners to detail-view
            DetailView.Layer.MasksToBounds = true;
            DetailView.Layer.CornerRadius = 10f;
            DetailView.Layer.BorderWidth = 2.5f;
            // add shadow
            /*detailView_.layer.ShadowColor = [UIColor blackColor].CGColor;
             detailView_.layer.shadowOpacity = 1.0f;
             detailView_.layer.shadowRadius = 6.0f;
             detailView_.layer.shadowOffset = CGSizeMake(0, 3);*/

            // Detail Text label
            DetailTextView = new UITextView(new RectangleF(0, StatusBarHeight,
                                                           _defaultDetailViewFrame.Size.Width,
                                                           _defaultDetailViewFrame.Size.Height - StatusBarHeight))
                {
                    BackgroundColor = UIColor.Clear,
                    UserInteractionEnabled = false,
                    Hidden = DetailViewMode != DetailViewMode.DetailText
                };
            AddSubview(DetailTextView);

            // Message History
            MessageHistory = new List<string>();
            HistoryTableView = new UITableView(new RectangleF(0, StatusBarHeight,
                                                              _defaultDetailViewFrame.Size.Width,
                                                              _defaultDetailViewFrame.Size.Height - StatusBarHeight))
                {
                    DataSource = new DataSource(this),
                    Delegate = null,
                    RowHeight = HistoryTableRowHeight,
                    SeparatorStyle = UITableViewCellSeparatorStyle.None,
                    BackgroundColor = UIColor.Clear,
                    Opaque = false,
                    Hidden = DetailViewMode != DetailViewMode.History,
                    BackgroundView = null
                };

            // make table view-background transparent
            DetailView.AddSubview(HistoryTableView);
            AddSubview(DetailView);

            // Create view that stores all the content
            var backgroundFrame = BackgroundViewFrameForStatusBarInterfaceOrientation();
            BackgroundView = new UIView(backgroundFrame)
                {
                    ClipsToBounds = true,
                    AutoresizingMask = UIViewAutoresizing.FlexibleWidth
                };
            OldBackgroundViewFrame = BackgroundView.Frame;

            // Add gesture recognizers
            var tapGestureRecognizer = new UITapGestureRecognizer(ContentViewClicked);
            //UISwipeGestureRecognizer *upGestureRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(contentViewSwipedUp:)] autorelease];
            //UISwipeGestureRecognizer *downGestureRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(contentViewSwipedDown:)] autorelease];

            //upGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
            //downGestureRecognizer.direction = UISwipeGestureRecognizerDirectionDown;

            BackgroundView.AddGestureRecognizer(tapGestureRecognizer);

            //[detailView_ addGestureRecognizer:upGestureRecognizer];
            //[self addGestureRecognizer:downGestureRecognizer];

            // Images used as background when status bar style is Default
            DefaultStatusBarImage = UIImage.LoadFromData(MtStatusBarBackgroundImageData(false));
            DefaultStatusBarImageShrinked = UIImage.LoadFromData(MtStatusBarBackgroundImageData(true));

            // Background-Image of the Content View
            StatusBarBackgroundImageView = new UIImageView(BackgroundView.Frame)
                {
                    AutoresizingMask = UIViewAutoresizing.FlexibleWidth |
                                       UIViewAutoresizing.FlexibleHeight
                };
            AddSubviewToBackgroundView(StatusBarBackgroundImageView);

            // Activity Indicator
            ActivityIndicator =
                new UIActivityIndicatorView(new RectangleF(6f, 3f, BackgroundView.Frame.Size.Height - 6f,
                                                           BackgroundView.Frame.Size.Height - 6f))
                    {
                        ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray,
                        HidesWhenStopped = true,
                        //AutoresizingMask = UIViewAutoresizing.All,
                        Transform = CGAffineTransform.MakeScale(0.75f, 0.75f)
                    };

            /* iOS 5 doesn't correctly resize the activityIndicator. Bug?
            if (ActivityIndicator.RespondsToSelector(new Selector("setColor:")))
            {
                ActivityIndicator.Layer.SetValueForKey(new NSNumber(0.10F), new NSString(@"transform.scale"));
            }*/

            AddSubviewToBackgroundView(ActivityIndicator);

            // Finished-Label
            FinishedLabel =
                new UILabel(new RectangleF(4f, 1f, BackgroundView.Frame.Size.Height,
                                           BackgroundView.Frame.Size.Height - 1f))
                    {
                        ShadowOffset = new SizeF(0f, 1f),
                        BackgroundColor = UIColor.Clear,
                        Hidden = true,
                        Text = FinishedText,
                        TextAlignment = UITextAlignment.Center,
                        Font = UIFont.FromName(
                            @"HelveticaNeue-Bold",
                            FinishedFontSize),
                        AdjustsFontSizeToFitWidth = true
                    };

            AddSubviewToBackgroundView(FinishedLabel);

            // Status Label 1 is first visible
            StatusLabel1 =
                new UILabel(new RectangleF(30f, 0f, BackgroundView.Frame.Size.Width - 60f,
                                           BackgroundView.Frame.Size.Height - 1f))
                    {
                        BackgroundColor = UIColor.Clear,
                        ShadowOffset = new SizeF(0f, 1f),
                        Font = UIFont.BoldSystemFontOfSize(
                            StatusLabelSize),
                        TextAlignment = UITextAlignment.Center,
                        Lines = 1,
                        LineBreakMode = UILineBreakMode.TailTruncation,
                        AutoresizingMask = UIViewAutoresizing.FlexibleWidth
                    };

            AddSubviewToBackgroundView(StatusLabel1);

            // Status Label 2 is hidden
            StatusLabel2 =
                new UILabel(new RectangleF(30f, BackgroundView.Frame.Size.Height, BackgroundView.Frame.Size.Width - 60f,
                                           BackgroundView.Frame.Size.Height - 1f))
                    {
                        ShadowOffset = new SizeF(0f, 1f),
                        BackgroundColor = UIColor.Clear,
                        Font = UIFont.BoldSystemFontOfSize(
                            StatusLabelSize),
                        TextAlignment = UITextAlignment.Center,
                        Lines = 1,
                        LineBreakMode = UILineBreakMode.TailTruncation,
                        AutoresizingMask = UIViewAutoresizing.FlexibleWidth
                    };

            AddSubviewToBackgroundView(StatusLabel2);

            // the hidden status label at the beginning
            HiddenStatusLabel = StatusLabel2;

            _progress = 1.0;
            ProgressView = new UIImageView(StatusBarBackgroundImageView.Frame)
                {
                    Opaque = false,
                    Hidden = true,
                    Alpha = ProgressViewAlpha
                };
            AddSubviewToBackgroundView(ProgressView);

            MessageQueue = new List<IDictionary>();
            CanRemoveImmediateMessagesFromQueue = true;

            AddSubview(BackgroundView);

            // listen for changes of status bar frame
            NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("didChangeStatusBarFrame:"),
                                                           UIApplication.WillChangeStatusBarFrameNotification, null);
            NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("applicationDidBecomeActive:"),
                                                           UIApplication.DidBecomeActiveNotification, null);
            NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("applicationWillResignActive:"),
                                                           UIApplication.WillResignActiveNotification, null);
            // initial rotation, fixes the issue with a wrong bar appearance in landscape only mode
            RotateToStatusBarFrame(null);
        }