TabHost in 1.5 problem

by EvgenyV » Wed, 29 Apr 2009 02:03:05 GMT


Sponsored Links
 i!

I have the problem since updated to 1.5. Some activity can be started
as independent activity.
In addition it can be hosted in TabHost.
tabHost.addTab(tabHost.newTabSpec("tabSettings")
.setIndicator(res.getString
(R.string.tab_settings_title),
res.getDrawable(R.drawable.settings_tab_40))
.setContent(new Intent(this, ViewSettings.class)));

When ViewSettings is starting as separate activity from some
CurrentActivity everything is OK.
Intent i = new IntentCurrentActivity ,
ConverterViewSettings.class);
CurrentActivity.startActivity(i);

But when the ViewSettings activity is starting on tab activation I got
StackOverflow exception.
The same code was OK in 1.1

There are stack trace:
04-28 17:30:26.954: ERROR/AndroidRuntime(12851): Uncaught handler:
thread main exiting due to uncaught exception
04-28 17:30:27.014: ERROR/AndroidRuntime(12851):
java.lang.StackOverflowError
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
java.util.concurrent.locks.ReentrantLock$NonfairSync.lock
(ReentrantLock.java:177)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:252)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
java.util.concurrent.CopyOnWriteArrayList.remove
(CopyOnWriteArrayList.java:384)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewTreeObserver.removeOnPreDrawListener
(ViewTreeObserver.java:377)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.widget.TextView.onDraw(TextView.java:3745)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.View.draw(View.java:5838)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.drawChild(ViewGroup.java:1486)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.View.draw(View.java:5841)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.drawChild(ViewGroup.java:1486)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.View.draw(View.java:5841)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.drawChild(ViewGroup.java:1486)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.View.draw(View.java:5841)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.drawChild(ViewGroup.java:1486)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.View.draw(View.java:5944)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.widget.FrameLayout.draw(FrameLayout.java:352)
04-28 17:30:27.014: ERROR/AndroidRuntime(12851): at
android.view.ViewG



Other Threads

1. Cannot take picture with surfaceview on nexus s

Hi,
I'm developping an application where the user can take a picture and then 
send it to the server. But unfortunally some pictures cannot be taken from 
the nexus s.
I try the same picture with HTC Tatto and Samsung Galaxy S and there are no 
probleme with these devices. It's generally picture from outside.

Here is my code:

private Preview mPreview;
private Camera camera;
 private byte[] pictureData;
 public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        mPreview = new Preview(this);
        mPreview.setOnClickListener(new OnClickListener() {
 @Override
public void onClick(View v) {
takePicture();
}
});
        setContentView(mPreview);
        
        
        LayoutInflater controlInflater = 
LayoutInflater.from(getBaseContext());
        View viewControl = 
controlInflater.inflate(R.layout.activity_edit_action_camera, null);
        LayoutParams layoutParamsControl
         = new LayoutParams(LayoutParams.FILL_PARENT,
         LayoutParams.FILL_PARENT);
        this.addContentView(viewControl, layoutParamsControl);
} 
 @Override
    protected void onResume() {
        super.onResume();
        camera = Camera.open();
        mPreview.setCamera(camera);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (camera != null) {
            mPreview.setCamera(null);
            camera.release();
            camera = null;
        }
}
    
 
    
    AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback(){
    @Override
    public void onAutoFocus(boolean success, Camera camera) {
    
    }
    };
    
    private void takePicture(){
    camera.takePicture(shutterCallback, rawCallback, jpegCallback);
    }


class Preview extends ViewGroup implements SurfaceHolder.Callback {
    private final String TAG = "Preview";

    SurfaceView mSurfaceView;
    SurfaceHolder mHolder;
    Size mPreviewSize;
    List<Size> mSupportedPreviewSizes;
    Camera mCamera;

    Preview(Context context) {
        super(context);

        mSurfaceView = new SurfaceView(context);
        addView(mSurfaceView);

        mHolder = mSurfaceView.getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

public void setCamera(Camera camera) {
        mCamera = camera;
        if (mCamera != null) {
            mSupportedPreviewSizes = 
mCamera.getParameters().getSupportedPreviewSizes();
            requestLayout();
        }
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int width = resolveSize(getSuggestedMinimumWidth(), 
widthMeasureSpec);
        final int height = resolveSize(getSuggestedMinimumHeight(), 
heightMeasureSpec);
        setMeasuredDimension(width, height);

        if (mSupportedPreviewSizes != null) {
            mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, 
width, height);
        }
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        if (changed && getChildCount() > 0) {
            final View child = getChildAt(0);

            final int width = r - l;
            final int height = b - t;

            int previewWidth = width;
            int previewHeight = height;
            if (mPreviewSize != null) {
                previewWidth = mPreviewSize.width;
                previewHeight = mPreviewSize.height;
            }

            // Center the child SurfaceView within the parent.
            if (width * previewHeight > height * previewWidth) {
                final int scaledChildWidth = previewWidth * height / 
previewHeight;
                child.layout((width - scaledChildWidth) / 2, 0,
                        (width + scaledChildWidth) / 2, height);
            } else {
                final int scaledChildHeight = previewHeight * width / 
previewWidth;
                child.layout(0, (height - scaledChildHeight) / 2,
                        width, (height + scaledChildHeight) / 2);
            }
        }
    }

    public void surfaceCreated(SurfaceHolder holder) {
        try {
            if (mCamera != null) {
                mCamera.setPreviewDisplay(holder);
                
                Camera.Parameters parameters = mCamera.getParameters();
                List<String> flashModes = 
parameters.getSupportedFlashModes();
                if (flashModes!=null &&flashModes.size() > 0)
                parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
                // Action mode take pictures of fast moving objects
                List<String> sceneModes = 
parameters.getSupportedSceneModes();
                if(sceneModes!=null && sceneModes.size()>0){
                if 
(sceneModes.contains(Camera.Parameters.SCENE_MODE_ACTION))
                    
parameters.setSceneMode(Camera.Parameters.SCENE_MODE_ACTION);
                    else
                    
parameters.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);
                }

                
                parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
                mCamera.autoFocus(myAutoFocusCallback);
                
                mCamera.setParameters(parameters);
            }
        } catch (IOException exception) {
            Log.e(TAG, "IOException caused by setPreviewDisplay()", 
exception);
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        if (mCamera != null) {
            mCamera.stopPreview();
        }
    }


    private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
        final double ASPECT_TOLERANCE = 0.1;
        double targetRatio = (double) w / h;
        if (sizes == null) return null;

        Size optimalSize = null;
        double minDiff = Double.MAX_VALUE;

        int targetHeight = h;

        // Try to find an size match aspect ratio and size
        for (Size size : sizes) {
            double ratio = (double) size.width / size.height;
            if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }

        // Cannot find the one match the aspect ratio, ignore the 
requirement
        if (optimalSize == null) {
            minDiff = Double.MAX_VALUE;
            for (Size size : sizes) {
                if (Math.abs(size.height - targetHeight) < minDiff) {
                    optimalSize = size;
                    minDiff = Math.abs(size.height - targetHeight);
                }
            }
        }
        return optimalSize;
    }
    
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int 
h) {
        Camera.Parameters parameters = mCamera.getParameters();
        if (mSupportedPreviewSizes != null) {
            mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, w, 
h);
        }
        parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
        parameters.setPictureSize(mPreviewSize.width, mPreviewSize.height);
        List<String> flashModes = parameters.getSupportedFlashModes();
        if (flashModes!=null && flashModes.size() > 0)
        parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
        requestLayout();
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        mCamera.autoFocus(myAutoFocusCallback);
        mCamera.setParameters(parameters);
        mCamera.startPreview();
    }

}

Is there anything in my code that's wrong or anything I forgot?
I already try to delete the sceneMode, the flashMode and the autoFocus but 
it still have the problem without them.

Thanks,
Sebastien

-- 

2. Need some help in retrieving the Starred Contacts

Hello everybody,

I am facing a problem when I am trying to access the Starred contacts.
Please help me in solving the problem.

*This Code is not Showing any exception*
When I am running the following code for on my android device the code is
working fine for the contacts i.e.,

   - The contacts that are manually added and
   - The contacts that are not manually added, but got added into my
   Contacts database due to *Syn <http://www.google.com/sync/android.html> *
   settings.

Thus, the ArrayList starListIds and starListIds are getting initialized
successfully, with the appropriate values.

*

**** Extracting and Storing the Starred Contacts into the lists
named starListIds and starListNames  BEGIN  ***/

*

*

ArrayList<String> starListNames = new ArrayList<String>();

*

*ArrayList<String> starListIds = new ArrayList<String>();*

*
   Cursor c = getContentResolver().query(Contacts.CONTENT_URI, null,
Contacts.STARRED + "=?", new String[] { "1" }, null);

 while (c.moveToNext()) {

StarListIds.add(c.getString(c.getColumnIndexOrThrow(RawContacts._ID)));
Log.i("Star-List", starListIds.get(blackListIds.size() - 1));
 name = c.getString(c.getColumnIndexOrThrow(Contacts.DISPLAY_NAME));
Log.i("Star-List", name);
 starListNames.add(name);

 }

*

*Exception is thrown only for the contacts that got into the database via.,
 Sync 
Contacts<http://googlemobile.blogspot.com/2008/10/google-on-android-gmail-and-contacts.html>
 settings.*
But, when I am trying to retrieve the Contacts using the Ids, present in the
ArrayList, starListIds,

   - *The exception is thrown, only for the Ids, that correspond to the
   Contacts that got added into the Contacts database via
Sync<http://googlemobile.blogspot.com/2008/10/google-on-android-gmail-and-contacts.html>
   *.

*05-14 20:47:41.337: ERROR/AndroidRuntime(32719): FATAL EXCEPTION: main*

*05-14 20:47:41.337: ERROR/AndroidRuntime(32719):
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a
size of 0*


   - *The Exception is not appearing for the contacts that are manually
   added into the database.*

 */**** Extracting the contact whose RawContacts._ID, is stored in the
array-list starListIds at a given position  ***/
*

*int position=2;*
*Cursor c1 = getContentResolver().query(*

*
 ContactsContract.CommonDataKinds.Phone.CONTENT_URI,*
* null,*
* ContactsContract.Data.RAW_CONTACT_ID + "=?"*
* + " AND "*
* + ContactsContract.Data.MIMETYPE + "='"*
* + Phone.CONTENT_ITEM_TYPE + "'",*
* new String[] { starListIds.get( position ) },*
* null); *

 *String id1=c1.getString(c1.getColumnIndex(Data.RAW_CONTACT_ID)); *

*
**
*

*
*
*
*

Regards,
Bikkanati Prabhakar.
E-Mail: prabhakar.9...@gmail.com
Blog:    http://LetsXploreIT.blogspot.com

-- 

3. Android 3.1 on the Motorola Xoom

4. 3d chair model using open gl

5. facebook and twitter

6. udev rules on Android device?

7. Looking for documentation on showing a value from a string-array in a TextView