protected internal override void onCreate(android.os.Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			android.os.Bundle extras = getIntent().getExtras();
			if (extras == null)
			{
				finish();
				return;
			}
			mNumDeletes = extras.getLong("numDeletes");
			mAccount = (android.accounts.Account)extras.getParcelable("account");
			mAuthority = extras.getString("authority");
			mProvider = extras.getString("provider");
			// the order of these must match up with the constants for position used in onItemClick
			java.lang.CharSequence[] options = new java.lang.CharSequence[] { getResources().
				getText([email protected][email protected]_really_delete), getResources().getText(
				[email protected][email protected]_undo_deletes), getResources().getText([email protected]
				[email protected]_do_nothing) };
			android.widget.ListAdapter adapter = new android.widget.ArrayAdapter<java.lang.CharSequence
				>(this, android.R.layout.simple_list_item_1, android.R.id.text1, options);
			android.widget.ListView listView = new android.widget.ListView(this);
			listView.setAdapter(adapter);
			listView.setItemsCanFocus(true);
			listView.setOnItemClickListener(this);
			android.widget.TextView textView = new android.widget.TextView(this);
			java.lang.CharSequence tooManyDeletesDescFormat = getResources().getText([email protected]
				[email protected]_too_many_deletes_desc);
			textView.setText(java.lang.CharSequenceProxy.Wrap(string.Format(tooManyDeletesDescFormat
				.ToString(), mNumDeletes, mProvider, mAccount.name)));
			android.widget.LinearLayout ll = new android.widget.LinearLayout(this);
			ll.setOrientation(android.widget.LinearLayout.VERTICAL);
			android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
				(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams
				.WRAP_CONTENT, 0);
			ll.addView(textView, lp);
			ll.addView(listView, lp);
			// TODO: consider displaying the icon of the account type
			//        AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
			//        for (AuthenticatorDescription desc : descs) {
			//            if (desc.type.equals(mAccount.type)) {
			//                try {
			//                    final Context authContext = createPackageContext(desc.packageName, 0);
			//                    ImageView imageView = new ImageView(this);
			//                    imageView.setImageDrawable(authContext.getResources().getDrawable(desc.iconId));
			//                    ll.addView(imageView, lp);
			//                } catch (PackageManager.NameNotFoundException e) {
			//                }
			//                break;
			//            }
			//        }
			setContentView(ll);
		}
Exemplo n.º 2
0
        private bool setupTitle(android.widget.LinearLayout topPanel)
        {
            bool hasTitle = true;

            if (mCustomTitleView != null)
            {
                // Add the custom title view directly to the topPanel layout
                android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
                                                                  (android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams
                                                                  .WRAP_CONTENT);
                topPanel.addView(mCustomTitleView, 0, lp);
                // Hide the title template
                android.view.View titleTemplate = mWindow.findViewById([email protected]_template
                                                                       );
                titleTemplate.setVisibility(android.view.View.GONE);
            }
            else
            {
                bool hasTextTitle = !android.text.TextUtils.isEmpty(mTitle);
                mIconView = (android.widget.ImageView)mWindow.findViewById([email protected]
                                                                           .icon);
                if (hasTextTitle)
                {
                    mTitleView = (android.widget.TextView)mWindow.findViewById([email protected]
                                                                               .alertTitle);
                    mTitleView.setText(mTitle);
                    if (mIconId > 0)
                    {
                        mIconView.setImageResource(mIconId);
                    }
                    else
                    {
                        if (mIcon != null)
                        {
                            mIconView.setImageDrawable(mIcon);
                        }
                        else
                        {
                            if (mIconId == 0)
                            {
                                mTitleView.setPadding(mIconView.getPaddingLeft(), mIconView.getPaddingTop(), mIconView
                                                      .getPaddingRight(), mIconView.getPaddingBottom());
                                mIconView.setVisibility(android.view.View.GONE);
                            }
                        }
                    }
                }
                else
                {
                    // Hide the title template
                    android.view.View titleTemplate = mWindow.findViewById([email protected]_template
                                                                           );
                    titleTemplate.setVisibility(android.view.View.GONE);
                    mIconView.setVisibility(android.view.View.GONE);
                    topPanel.setVisibility(android.view.View.GONE);
                    hasTitle = false;
                }
            }
            return(hasTitle);
        }
 protected internal override void onCreate(android.os.Bundle savedInstanceState)
 {
     base.onCreate(savedInstanceState);
     android.os.Bundle extras = getIntent().getExtras();
     if (extras == null)
     {
         finish();
         return;
     }
     mNumDeletes = extras.getLong("numDeletes");
     mAccount    = (android.accounts.Account)extras.getParcelable("account");
     mAuthority  = extras.getString("authority");
     mProvider   = extras.getString("provider");
     // the order of these must match up with the constants for position used in onItemClick
     java.lang.CharSequence[] options = new java.lang.CharSequence[] { getResources().
                                                                       getText([email protected][email protected]_really_delete), getResources().getText(
                                                                           [email protected][email protected]_undo_deletes), getResources().getText([email protected]
                                                                                                                                                  [email protected]_do_nothing) };
     android.widget.ListAdapter adapter = new android.widget.ArrayAdapter <java.lang.CharSequence
                                                                           >(this, android.R.layout.simple_list_item_1, android.R.id.text1, options);
     android.widget.ListView listView = new android.widget.ListView(this);
     listView.setAdapter(adapter);
     listView.setItemsCanFocus(true);
     listView.setOnItemClickListener(this);
     android.widget.TextView textView = new android.widget.TextView(this);
     java.lang.CharSequence  tooManyDeletesDescFormat = getResources().getText([email protected]
                                                                               [email protected]_too_many_deletes_desc);
     textView.setText(java.lang.CharSequenceProxy.Wrap(string.Format(tooManyDeletesDescFormat
                                                                     .ToString(), mNumDeletes, mProvider, mAccount.name)));
     android.widget.LinearLayout ll = new android.widget.LinearLayout(this);
     ll.setOrientation(android.widget.LinearLayout.VERTICAL);
     android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
                                                       (android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams
                                                       .WRAP_CONTENT, 0);
     ll.addView(textView, lp);
     ll.addView(listView, lp);
     // TODO: consider displaying the icon of the account type
     //        AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
     //        for (AuthenticatorDescription desc : descs) {
     //            if (desc.type.equals(mAccount.type)) {
     //                try {
     //                    final Context authContext = createPackageContext(desc.packageName, 0);
     //                    ImageView imageView = new ImageView(this);
     //                    imageView.setImageDrawable(authContext.getResources().getDrawable(desc.iconId));
     //                    ll.addView(imageView, lp);
     //                } catch (PackageManager.NameNotFoundException e) {
     //                }
     //                break;
     //            }
     //        }
     setContentView(ll);
 }
Exemplo n.º 4
0
 protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec
                                            )
 {
     if (mIconView != null && mPreserveIconSpacing)
     {
         // Enforce minimum icon spacing
         android.view.ViewGroup.LayoutParams      lp     = getLayoutParams();
         android.widget.LinearLayout.LayoutParams iconLp = (android.widget.LinearLayout.LayoutParams
                                                            )mIconView.getLayoutParams();
         if (lp.height > 0 && iconLp.width <= 0)
         {
             iconLp.width = lp.height;
         }
     }
     base.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Exemplo n.º 5
0
 public override void addView(android.view.View child)
 {
     if (child.getLayoutParams() == null)
     {
         android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
                                                           (0, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
         lp.setMargins(0, 0, 0, 0);
         child.setLayoutParams(lp);
     }
     // Ensure you can navigate to the tab with the keyboard, and you can touch it
     child.setFocusable(true);
     child.setClickable(true);
     base.addView(child);
     // TODO: detect this via geometry with a tabwidget listener rather
     // than potentially interfere with the view's listener
     child.setOnClickListener(new android.widget.TabWidget.TabClickListener(this, getTabCount
                                                                                () - 1));
     child.setOnFocusChangeListener(this);
 }
Exemplo n.º 6
0
 private void centerButton(android.widget.Button button)
 {
     android.widget.LinearLayout.LayoutParams @params = (android.widget.LinearLayout.LayoutParams
                                                         )button.getLayoutParams();
     @params.gravity = android.view.Gravity.CENTER_HORIZONTAL;
     @params.weight  = 0.5f;
     button.setLayoutParams(@params);
     android.view.View leftSpacer = mWindow.findViewById([email protected]
                                                         );
     if (leftSpacer != null)
     {
         leftSpacer.setVisibility(android.view.View.VISIBLE);
     }
     android.view.View rightSpacer = mWindow.findViewById([email protected]
                                                          );
     if (rightSpacer != null)
     {
         rightSpacer.setVisibility(android.view.View.VISIBLE);
     }
 }
Exemplo n.º 7
0
        protected internal override void applyTransformation(float interpolatedTime, Transformation t)
        {
            float        height = (mToHeight - mFromHeight) * interpolatedTime + mFromHeight;
            float        width  = (mToWidth - mFromWidth) * interpolatedTime + mFromWidth;
            LayoutParams p      = (LayoutParams)mView.LayoutParams;

            p.height = (int)height;
            p.width  = (int)width;
            this.endCondition(width, height);
            if (width == 0 && this.mToWidth == 0)
            {
                p.height = 0;
            }
            if (height == 0 && this.mToHeight == 0)
            {
                p.width = 0;
            }
            mView.requestLayout();
            mView.invalidate();
        }
Exemplo n.º 8
0
		/// <summary>
		/// <p>Builds the popup window's content and returns the height the popup
		/// should have.
		/// </summary>
		/// <remarks>
		/// <p>Builds the popup window's content and returns the height the popup
		/// should have. Returns -1 when the content already exists.</p>
		/// </remarks>
		/// <returns>the content's height or -1 if content already exists</returns>
		private int buildDropDown()
		{
			android.view.ViewGroup dropDownView;
			int otherHeights = 0;
			if (mDropDownList == null)
			{
				android.content.Context context = mContext;
				mShowDropDownRunnable = new _Runnable_976(this);
				mDropDownList = new android.widget.ListPopupWindow.DropDownListView(context, !mModal
					);
				if (mDropDownListHighlight != null)
				{
					mDropDownList.setSelector(mDropDownListHighlight);
				}
				mDropDownList.setAdapter(mAdapter);
				mDropDownList.setOnItemClickListener(mItemClickListener);
				mDropDownList.setFocusable(true);
				mDropDownList.setFocusableInTouchMode(true);
				mDropDownList.setOnItemSelectedListener(new _OnItemSelectedListener_994(this));
				mDropDownList.setOnScrollListener(mScrollListener);
				if (mItemSelectedListener != null)
				{
					mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
				}
				dropDownView = mDropDownList;
				android.view.View hintView = mPromptView;
				if (hintView != null)
				{
					// if an hint has been specified, we accomodate more space for it and
					// add a text view in the drop down menu, at the bottom of the list
					android.widget.LinearLayout hintContainer = new android.widget.LinearLayout(context
						);
					hintContainer.setOrientation(android.widget.LinearLayout.VERTICAL);
					android.widget.LinearLayout.LayoutParams hintParams = new android.widget.LinearLayout
						.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f);
					switch (mPromptPosition)
					{
						case POSITION_PROMPT_BELOW:
						{
							hintContainer.addView(dropDownView, hintParams);
							hintContainer.addView(hintView);
							break;
						}

						case POSITION_PROMPT_ABOVE:
						{
							hintContainer.addView(hintView);
							hintContainer.addView(dropDownView, hintParams);
							break;
						}

						default:
						{
							android.util.Log.e(TAG, "Invalid hint position " + mPromptPosition);
							break;
						}
					}
					// measure the hint's height to find how much more vertical space
					// we need to add to the drop down's height
					int widthSpec = android.view.View.MeasureSpec.makeMeasureSpec(mDropDownWidth, android.view.View
						.MeasureSpec.AT_MOST);
					int heightSpec = android.view.View.MeasureSpec.UNSPECIFIED;
					hintView.measure(widthSpec, heightSpec);
					hintParams = (android.widget.LinearLayout.LayoutParams)hintView.getLayoutParams();
					otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
					dropDownView = hintContainer;
				}
				mPopup.setContentView(dropDownView);
			}
			else
			{
				dropDownView = (android.view.ViewGroup)mPopup.getContentView();
				android.view.View view = mPromptView;
				if (view != null)
				{
					android.widget.LinearLayout.LayoutParams hintParams = (android.widget.LinearLayout
						.LayoutParams)view.getLayoutParams();
					otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
				}
			}
			// getMaxAvailableHeight() subtracts the padding, so we put it back
			// to get the available height for the whole window
			int padding = 0;
			android.graphics.drawable.Drawable background = mPopup.getBackground();
			if (background != null)
			{
				background.getPadding(mTempRect);
				padding = mTempRect.top + mTempRect.bottom;
				// If we don't have an explicit vertical offset, determine one from the window
				// background so that content will line up.
				if (!mDropDownVerticalOffsetSet)
				{
					mDropDownVerticalOffset = -mTempRect.top;
				}
			}
			// Max height available on the screen for a popup.
			bool ignoreBottomDecorations = mPopup.getInputMethodMode() == android.widget.PopupWindow
				.INPUT_METHOD_NOT_NEEDED;
			int maxHeight = mPopup.getMaxAvailableHeight(getAnchorView(), mDropDownVerticalOffset
				, ignoreBottomDecorations);
			if (mDropDownAlwaysVisible || mDropDownHeight == android.view.ViewGroup.LayoutParams
				.MATCH_PARENT)
			{
				return maxHeight + padding;
			}
			int listContent = mDropDownList.measureHeightOfChildren(android.view.View.MeasureSpec
				.UNSPECIFIED, 0, android.widget.ListView.NO_POSITION, maxHeight - otherHeights, 
				-1);
			// add padding only if the list has items in it, that way we don't show
			// the popup if it is not needed
			if (listContent > 0)
			{
				otherHeights += padding;
			}
			return listContent + otherHeights;
		}
Exemplo n.º 9
0
		public override void addView(android.view.View child)
		{
			if (child.getLayoutParams() == null)
			{
				android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
					(0, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
				lp.setMargins(0, 0, 0, 0);
				child.setLayoutParams(lp);
			}
			// Ensure you can navigate to the tab with the keyboard, and you can touch it
			child.setFocusable(true);
			child.setClickable(true);
			base.addView(child);
			// TODO: detect this via geometry with a tabwidget listener rather
			// than potentially interfere with the view's listener
			child.setOnClickListener(new android.widget.TabWidget.TabClickListener(this, getTabCount
				() - 1));
			child.setOnFocusChangeListener(this);
		}
 public virtual void update()
 {
     android.app.ActionBar.Tab tab    = this.mTab;
     android.view.View         custom = tab.getCustomView();
     if (custom != null)
     {
         this.addView(custom);
         this.mCustomView = custom;
         if (this.mTextView != null)
         {
             this.mTextView.setVisibility(android.view.View.GONE);
         }
         if (this.mIconView != null)
         {
             this.mIconView.setVisibility(android.view.View.GONE);
             this.mIconView.setImageDrawable(null);
         }
     }
     else
     {
         if (this.mCustomView != null)
         {
             this.removeView(this.mCustomView);
             this.mCustomView = null;
         }
         android.graphics.drawable.Drawable icon = tab.getIcon();
         java.lang.CharSequence             text = tab.getText();
         if (icon != null)
         {
             if (this.mIconView == null)
             {
                 android.widget.ImageView iconView = new android.widget.ImageView(this.getContext(
                                                                                      ));
                 android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
                                                                   (android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams
                                                                   .WRAP_CONTENT);
                 lp.gravity = android.view.Gravity.CENTER_VERTICAL;
                 iconView.setLayoutParams(lp);
                 this.addView(iconView, 0);
                 this.mIconView = iconView;
             }
             this.mIconView.setImageDrawable(icon);
             this.mIconView.setVisibility(android.view.View.VISIBLE);
         }
         else
         {
             if (this.mIconView != null)
             {
                 this.mIconView.setVisibility(android.view.View.GONE);
                 this.mIconView.setImageDrawable(null);
             }
         }
         if (text != null)
         {
             if (this.mTextView == null)
             {
                 android.widget.TextView textView = new android.widget.TextView(this.getContext(),
                                                                                null, [email protected]);
                 textView.setEllipsize(android.text.TextUtils.TruncateAt.END);
                 android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
                                                                   (android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams
                                                                   .WRAP_CONTENT);
                 lp.gravity = android.view.Gravity.CENTER_VERTICAL;
                 textView.setLayoutParams(lp);
                 this.addView(textView);
                 this.mTextView = textView;
             }
             this.mTextView.setText(text);
             this.mTextView.setVisibility(android.view.View.VISIBLE);
         }
         else
         {
             if (this.mTextView != null)
             {
                 this.mTextView.setVisibility(android.view.View.GONE);
                 this.mTextView.setText(null);
             }
         }
         if (this.mIconView != null)
         {
             this.mIconView.setContentDescription(tab.getContentDescription());
         }
     }
 }
        // can we send a zip file?
        public static void Invoke(int index, Action<string> y, int frames = 4)
        {
            #region log
            var st = new Stopwatch();
            st.Start();
            Action<string> log =
                x =>
                {
                    var z = (st.Elapsed + " " + x);

                    Console.WriteLine(z);
                    y(z);
                };
            #endregion

            log("getting ready...");

            var DIRECTORY_DCIM = global::android.os.Environment.DIRECTORY_DCIM;

            var path = global::android.os.Environment.getExternalStoragePublicDirectory(DIRECTORY_DCIM).getAbsolutePath();
            path += "/Camera";

            //var n = DateTime.Now;
            //var f = new java.io.File(path + "/shot" + n.Ticks + ".jpg");

            var camera = default(android.hardware.Camera);
            var surface = default(SurfaceView);

            try
            {
                // PreviewCallbackWithBuffer { cc = 0, Length = 1048576 }
                // W/CameraService(   84): CameraService::connect X (pid 2117) rejected (existing client).

                log("android.hardware.Camera.open... " + new { index });

                camera = android.hardware.Camera.open(index);

                log("android.hardware.Camera.open... done ");

                var PreviewFormat = ImageFormat.UNKNOWN;

                #region setParameters
                var p = camera.getParameters();

                // The size of the buffer must match the values described above.
                // Gets the supported preview formats. NV21 is always supported.

                // http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getSupportedPreviewFormats()

                #region SupportedPictureFormat

                foreach (int SupportedPictureFormat in p.getSupportedPictureFormats().AsEnumerable())
                {
                    Console.WriteLine(new { SupportedPictureFormat });
                }

                //p.getSupportedPictureFormats().With(
                //     pformats =>
                //     {
                //         for (int i = 0; i < pformats.size(); i++)
                //         {
                //             var SupportedPictureFormat = (int)pformats.get(i);

                //             Console.WriteLine(new { SupportedPictureFormat });
                //         }
                //     }
                // );
                #endregion



                #region SupportedPreviewFormat

                foreach (int SupportedPreviewFormat in p.getSupportedPreviewFormats().AsEnumerable())
                {

                    if (SupportedPreviewFormat == ImageFormat.NV21)
                        PreviewFormat = SupportedPreviewFormat;
                    else if (PreviewFormat == ImageFormat.UNKNOWN)
                        PreviewFormat = SupportedPreviewFormat;

                    log("" + new { SupportedPreviewFormat });

                    Console.WriteLine(new { SupportedPreviewFormat });
                }
                //p.getSupportedPreviewFormats().With(
                //    pformats =>
                //    {
                //        for (int i = 0; i < pformats.size(); i++)
                //        {
                //            var SupportedPreviewFormat = (int)pformats.get(i);


                //            if (SupportedPreviewFormat == ImageFormat.NV21)
                //                PreviewFormat = SupportedPreviewFormat;
                //            else if (PreviewFormat == ImageFormat.UNKNOWN)
                //                PreviewFormat = SupportedPreviewFormat;

                //            log("" + new { SupportedPreviewFormat });
                //        }
                //    }
                //);
                #endregion


                //p.setPictureFormat(ImageFormat.YV12);

                p.setPreviewFormat(PreviewFormat);


                //D/DOMX    (  127): ERROR: failed check:(eError == OMX_ErrorNone) || (eError == OMX_ErrorNoMore) - returning error: 0x80001005 - Error returned from OMX API in ducati
                //E/CameraHAL(  127): Error while configuring rotation 0x80001005
                // http://questiontrack.com/galaxy-nexus-specificaly-camera-startpreview-failed-993603.html
                // http://stackoverflow.com/questions/16839869/orientation-error-causing-crash

                ////p.setRotation(0);

                #region getSupportedPreviewSizes
                //var s = p.getSupportedPreviewSizes();

                var min = default(android.hardware.Camera.Size);

                //for (int i = 0; i < s.size(); i++)
                foreach (android.hardware.Camera.Size size in p.getSupportedPreviewSizes().AsEnumerable())
                {
                    //var size = (android.hardware.Camera.Size)s.get(i);

                    //                I/System.Console( 6058): before takePicture { f = /mnt/sdcard/Pictures/shot.jpg }
                    //I/System.Console( 6058): { size = android.hardware.Camera$Size@4fde180 }

                    var SupportedPreviewSize = new { size.width, size.height };
                    log("" + new { SupportedPreviewSize });

                    if (min == null)
                        min = size;
                    else if (min.width > size.width)
                        min = size;

                }


                #endregion
                p.setPreviewSize(min.width, min.height);

                //For formats besides YV12, the size of the buffer is determined by multiplying the
                // preview image width, height, and bytes per pixel. The width and height can be read 
                // from getPreviewSize(). Bytes per pixel can be computed from getBitsPerPixel(int) / 8, 
                // using the image format from getPreviewFormat().

                //p.setPictureSize(min.width, min.height);


                // I/System.Console( 2860): { width = 640, height = 480, bytesperpixel = 0, buffersize = 0 }
                // the number of bits per pixel of the given format or -1 if the format doesn't exist or is not supported.
                //var bytesperpixel = (ImageFormat.getBitsPerPixel(ImageFormat.NV21) / 8);

                // http://stackoverflow.com/questions/13703596/mediacodec-and-camera-colorspaces-dont-match
                // https://code.google.com/p/android/issues/detail?id=37655

                var bitsperpixel = (ImageFormat.getBitsPerPixel(PreviewFormat));
                var buffersize = min.width * min.height / 8 * bitsperpixel;

                // 12
                // http://www.fourcc.org/yuv.php

                //var buffersize = 460800;

                log("" + new { min.width, min.height, bitsperpixel, buffersize });


                #region setFocusMode
                var focusModes = p.getSupportedFocusModes();
                var NextFocus = android.hardware.Camera.Parameters.FOCUS_MODE_FIXED;

                for (int i = 0; i < focusModes.size(); i++)
                {
                    var focusMode = (string)focusModes.get(i);

                    if (focusMode == android.hardware.Camera.Parameters.FOCUS_MODE_INFINITY)
                        NextFocus = android.hardware.Camera.Parameters.FOCUS_MODE_INFINITY;

                    System.Console.WriteLine(new { focusMode });
                }

                p.setFocusMode(NextFocus);
                #endregion

                camera.setParameters(p);
                #endregion


                // preview layout size: 736/1216
                buffersize = 1843200;

                // E/Camera-JNI( 3148): Manually set buffer was too small! Expected 460800 bytes, but got 307200!
                camera.addCallbackBuffer(new sbyte[buffersize]);
                camera.addCallbackBuffer(new sbyte[buffersize]);
                camera.addCallbackBuffer(new sbyte[buffersize]);
                camera.addCallbackBuffer(new sbyte[buffersize]);
                camera.addCallbackBuffer(new sbyte[buffersize]);

                var a = new EventWaitHandle(false, EventResetMode.ManualReset);

                // Task.ContinueWith
                // await

                (ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext as Activity).StartNew(
                    aa =>
                    {
                        log("at runOnUiThread...");


                        // solve issue with callback not being called: release the camera and try again. It usually works.
                        //To solve issue with rotation 0x80001005: restart app / service

                        // http://stackoverflow.com/questions/13546788/camera-takepicture-not-working-on-my-jb-gb-froyo-phones
                        aa.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


                        #region setErrorCallback
                        camera.setErrorCallback(
                           new XErrorCallback
                           {
                               yield = (err, c) =>
                               {
                                   log("" + new { err });
                               }

                           }
                       );
                        #endregion

                        surface = new SurfaceView(ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext);

                        var holder = surface.getHolder();

                        // http://developer.android.com/reference/android/view/SurfaceHolder.html#SURFACE_TYPE_PUSH_BUFFERS
                        var SURFACE_TYPE_PUSH_BUFFERS = 0x00000003;
                        holder.setType(SURFACE_TYPE_PUSH_BUFFERS);




                        log("setPreviewCallbackWithBuffer");

                        var cc = 0;

                        //E/CameraHardwareSec(   84): int android::CameraHardwareSec::previewThread(): mSkipFrame(3) > 0
                        //E/CameraHardwareSec(   84): int android::CameraHardwareSec::previewThread(): mSkipFrame(2) > 0
                        //E/CameraHardwareSec(   84): int android::CameraHardwareSec::previewThread(): mSkipFrame(1) > 0

                        // http://stackoverflow.com/questions/16878042/camera-not-working-in-google-nexus-tablet

                        #region camera.PreviewCallbackWithBuffer
                        camera.PreviewCallbackWithBuffer(
                            (rawdata, c) =>
                            {
                                if (surface == null)
                                {
                                    // W/CameraHardwareSec(   84): virtual android::status_t android::CameraHardwareSec::cancelPicture() : not supported, just returning NO_ERROR
                                    return;
                                }

                                //                                                                   10080.0ms PreviewCallbackWithBuffer enter { cc = 58, Length = 460800 }
                                //10119.0ms PreviewCallbackWithBuffer compressToJpeg done { cc = 58, Elapsed = 39.0ms }
                                //10174.0ms PreviewCallbackWithBuffer ToBase64String done { cc = 58, Elapsed = 94.0ms }

                                var xcc = cc;

                                log("PreviewCallbackWithBuffer enter " + new { xcc, rawdata.Length });

                                // failed to flush { Length = 14619 }
                                //new Thread(
                                //    delegate()
                                {
                                    if (surface == null)
                                    {
                                        // W/CameraHardwareSec(   84): virtual android::status_t android::CameraHardwareSec::cancelPicture() : not supported, just returning NO_ERROR
                                        return;
                                    }

                                    var cst = new Stopwatch();
                                    cst.Start();

                                    // http://stackoverflow.com/questions/3426614/android-converting-from-nv21-preview-format-on-nexus-one-to-jpeg
                                    // http://developer.android.com/reference/android/graphics/YuvImage.html

                                    //Caused by: java.lang.IllegalArgumentException: only support ImageFormat.NV21 and ImageFormat.YUY2 for now
                                    //at android.graphics.YuvImage.<init>(YuvImage.java:82)


                                    // https://code.google.com/p/android/issues/detail?id=823
                                    // https://code.google.com/p/android-source-browsing/source/browse/graphics/java/android/graphics/YuvImage.java?repo=platform--frameworks--base&name=android-cts-4.1_r1
                                    var yuv = new YuvImage(
                                        rawdata,
                                        PreviewFormat,
                                        min.width,
                                        min.height,
                                        null
                                    );

                                    var m = new java.io.ByteArrayOutputStream();

                                    yuv.compressToJpeg(
                                        new Rect(0, 0, min.width, min.height),
                                        20,
                                        m);

                                    var data = (byte[])(object)m.toByteArray();

                                    log("PreviewCallbackWithBuffer compressToJpeg done " + new { xcc, cst.Elapsed });


                                    Console.WriteLine("compressToJpeg "
                                        + new { data.Length }
                                    );

                                    var src = "data:image/jpg;base64," +
                                            Convert.ToBase64String(
                                                data
                                            );

                                    log("PreviewCallbackWithBuffer ToBase64String done " + new { xcc, cst.Elapsed });

                                    y(src);


                                    //PreviewCallbackWithBuffer { cc = 0, Length = 1048576 }

                                    if (surface == null)
                                    {
                                        // W/CameraHardwareSec(   84): virtual android::status_t android::CameraHardwareSec::cancelPicture() : not supported, just returning NO_ERROR
                                        return;
                                    }

                                    //camera.addCallbackBuffer();
                                    camera.addCallbackBuffer(new sbyte[buffersize]);

                                    log("PreviewCallbackWithBuffer exit " + new { xcc, cst.Elapsed });


                                    if (xcc == frames)
                                    {

                                        //dummy.setVisibility(View.GONE);
                                        //dummy = null;

                                        // Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

                                        aa.StartNew(
                                                delegate
                                                {
                                                    if (surface != null)
                                                    {
                                                        surface.setVisibility(View.GONE);
                                                        surface = null;

                                                    }

                                                    a.Set();
                                                }
                                        );
                                    }
                                }
                                //).Start();

                                cc++;


                            }
                        );
                        #endregion


                        #region holder.surfaceChanged
                        holder.surfaceChanged(
                            delegate
                            {
                                log("surfaceChanged?");
                            }
                        );
                        #endregion

                        #region holder.surfaceCreated
                        holder.surfaceCreated(
                            delegate
                            {
                                log("surfaceCreated!");

                                // http://stackoverflow.com/questions/12098298/android-camera-app-passed-null-surface
                                // http://stackoverflow.com/questions/16945524/app-passed-null-surface-while-taking-a-picture-without-a-surfaceview

                                //  app passed NULL surface
                                log("before setPreviewDisplay, delay");

                                Thread.Sleep(400);

                                // https://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/camera/CameraManager.java
                                // http://stackoverflow.com/questions/16945524/app-passed-null-surface-while-taking-a-picture-without-a-surfaceview

                                // http://stackoverflow.com/questions/4852740/surfaceview-getholder-not-returning-surfaceholder

                                log("before setPreviewDisplay " + new { holder });
                                // inside surface changed?

                                //if (surface == 0)
                                //{
                                //    LOGE("app passed NULL surface");
                                //    return NO_INIT;
                                //}

                                // https://android.googlesource.com/platform/frameworks/native/+/a6938bab1f6fa76ae98ebbe44f4e534e05fa0993/libs/ui/Camera.cpp
                                camera.setTryPreviewDisplay(holder);
                                log("after setPreviewDisplay");


                                log("startPreview, delay");
                                Thread.Sleep(200);
                                log("startPreview");

                                camera.startPreview();
                                log("after startPreview");
                            }
                        );
                        #endregion


                        #region addContentView
                        //surface.setBackgroundColor(Color.argb(0x0F, 255, 0, 0));

                        var pp = new android.widget.LinearLayout.LayoutParams(
                            android.widget.LinearLayout.LayoutParams.FILL_PARENT,
                            android.widget.LinearLayout.LayoutParams.FILL_PARENT
                            );
                        //pp.setMargins(64, 64, 64, 64);

                        aa.addContentView(surface, pp);
                        #endregion





                    }
                );

                a.WaitOne();

                log("PreviewCallbackWithBuffer done");

            }
            catch (Exception ex)
            {
                log("error: " + new { ex.Message, ex.StackTrace });

                throw new Exception("", ex);
            }
            finally
            {
                log("finally");
                // using
                if (camera != null)
                {
                    camera.stopPreview();
                    camera.release();
                    camera = null;
                }


            }
        }
Exemplo n.º 12
0
			public virtual void update()
			{
				android.app.ActionBar.Tab tab = this.mTab;
				android.view.View custom = tab.getCustomView();
				if (custom != null)
				{
					this.addView(custom);
					this.mCustomView = custom;
					if (this.mTextView != null)
					{
						this.mTextView.setVisibility(android.view.View.GONE);
					}
					if (this.mIconView != null)
					{
						this.mIconView.setVisibility(android.view.View.GONE);
						this.mIconView.setImageDrawable(null);
					}
				}
				else
				{
					if (this.mCustomView != null)
					{
						this.removeView(this.mCustomView);
						this.mCustomView = null;
					}
					android.graphics.drawable.Drawable icon = tab.getIcon();
					java.lang.CharSequence text = tab.getText();
					if (icon != null)
					{
						if (this.mIconView == null)
						{
							android.widget.ImageView iconView = new android.widget.ImageView(this.getContext(
								));
							android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
								(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams
								.WRAP_CONTENT);
							lp.gravity = android.view.Gravity.CENTER_VERTICAL;
							iconView.setLayoutParams(lp);
							this.addView(iconView, 0);
							this.mIconView = iconView;
						}
						this.mIconView.setImageDrawable(icon);
						this.mIconView.setVisibility(android.view.View.VISIBLE);
					}
					else
					{
						if (this.mIconView != null)
						{
							this.mIconView.setVisibility(android.view.View.GONE);
							this.mIconView.setImageDrawable(null);
						}
					}
					if (text != null)
					{
						if (this.mTextView == null)
						{
							android.widget.TextView textView = new android.widget.TextView(this.getContext(), 
								null, [email protected]);
							textView.setEllipsize(android.text.TextUtils.TruncateAt.END);
							android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
								(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams
								.WRAP_CONTENT);
							lp.gravity = android.view.Gravity.CENTER_VERTICAL;
							textView.setLayoutParams(lp);
							this.addView(textView);
							this.mTextView = textView;
						}
						this.mTextView.setText(text);
						this.mTextView.setVisibility(android.view.View.VISIBLE);
					}
					else
					{
						if (this.mTextView != null)
						{
							this.mTextView.setVisibility(android.view.View.GONE);
							this.mTextView.setText(null);
						}
					}
					if (this.mIconView != null)
					{
						this.mIconView.setContentDescription(tab.getContentDescription());
					}
				}
			}