How to fix hit area after scaling

by Jonathan » Wed, 12 May 2010 03:52:59 GMT


Sponsored Links
 I am scaling the canvas of a linear layout on draw, but this throws
off all the hit areas of my views inside of this layout. They respond
as if there was no scaling taking place. What do I have to do to get
themselves to re-register their hit areas?

Thanks

Jonathan

--



How to fix hit area after scaling

by Jason Tomlinson » Wed, 12 May 2010 20:55:13 GMT


 You need to scale your hit areas to match the canvas scaling.  If you
zoom in 2x on the canvas your hit area is now twice the size likewise
if you zoomed out 2x then your hit area is half the size.




>


Sponsored Links


How to fix hit area after scaling

by Jonathan » Thu, 13 May 2010 02:03:29 GMT


 Right, thats what I am trying to figure out how to do. I currently
don't know how to separate a hit area from an actual view.

It would make sense to me if there was some function needed to be
called that would then figure out the new bounds of the views and
change their hit areas appropriately. I am calling invalidate on the
parent layout, but that doesn't seem to do anything to the views
themselves. I'll try calling it on each child and see if that makes a
difference.




> >



How to fix hit area after scaling

by Jonathan » Thu, 13 May 2010 07:12:20 GMT


 Just in case anybody else wants to accomplish this, all you have to do
is override your child view's getHitRect method to account for your
parent view's scale transformation.

I'm not sure why the base view class doesn't do this automatically,
but I'm sure there is a reason.





> > >



Other Threads

1. Strange issue - AutoCompleteTextView does not show results - CursorAdapter

Hi,

      I have been trying to get my head around this issue, but can't
figure out. I have an AutoCompleteTextView which I am populating from
a custom adapter that extends CursorAdapter. The data source for the
cursor adapter is a table(columns : name and _id) in my database. I
have put debug statements in every method in My Custom Adapter class
that extends CursorAdapter, but none of the methods that I have
overridden like newView(), convertToString(), bindView() get called,
EXCEPT runQueryOnBackgroundThread() which gets called as I type my
input into the text view. Here is my code for your reference :

Inner Class :

    private class myCursorAdapter extends CursorAdapter
    {
          Context context = null;
          private int columnIndex;

                        public myCursorAdapter(Context context, Cursor c, int 
col) {
                                super(context, c);
                                this.columnIndex = col;
                        }

            @Override
            public void bindView(View view, Context context, Cursor
cursor) {
                Log.d("MainActivity", " bindView:"+cursor.getString
(columnIndex));
                ((TextView) view).setText(cursor.getString
(columnIndex));
            }

            @Override
            public String convertToString(Cursor cursor) {
                Log.d("MainActivity", " convertToString:"+cursor.getString
(columnIndex));
                return cursor.getString(columnIndex);
            }

            @Override
            public View newView(Context context, Cursor cursor,
ViewGroup parent)
            {
                Log.d("MainActivity", "
newView:*************************");
                final LayoutInflater inflater = LayoutInflater.from
(context);
                final TextView view = (TextView) inflater.inflate(
                        android.R.layout.simple_dropdown_item_1line,
parent, false);
                return view;
            }

            @Override
            public Cursor runQueryOnBackgroundThread(CharSequence
constraint)
            {
                Log.d("MainActivity","runQueryOnBackgroundThread");
                    if (constraint != null){
                        return MainActivity.this.getItemsAsCursor
(constraint.toString());
                    }else{
                        return MainActivity.this.getItemsAsCursor("All");
                    }
            }
    }

This is how I instantiate and set the adapter (From a class that
extends ListActivity) :

        Cursor cursor = getItemsAsCursor("All");
        myCursorAdapter adapter = new myCursorAdapter
(this.getApplicationContext(), cursor, 0);
        AutoCompleteTextView textView = (AutoCompleteTextView) findViewById
(R.id.edit);
        textView.setThreshold(2);
        textView.setAdapter(adapter);

Am I doing something wrong? Any help is highly appreciated.

Thanks
--~--~---------~--~----~------------~-------~--~----~

2. Android Unit Tests - VerifyError

I am tying to run AndroidTests.apk but I am receiving VerifyErrors.
Please Advise



I installed AndroidTests.apk using adb install.

Command Line Output:

$ adb shell am instrument -w com.android.unit_tests/
android.test.InstrumentationTestRunner
INSTRUMENTATION_RESULT: shortMsg=com.android.unit_tests.AppCacheTest
INSTRUMENTATION_RESULT: longMsg=java.lang.VerifyError:
com.android.unit_tests.AppCacheTest
INSTRUMENTATION_CODE: 0



LogCat Output:

D/AndroidRuntime(  270):
D/AndroidRuntime(  270): >>>>>>>>>>>>>> AndroidRuntime START
<<<<<<<<<<<<<<
D/AndroidRuntime(  270): CheckJNI is OFF
D/AndroidRuntime(  270): --- registering native functions ---
D/ActivityManager(   54): Uninstalling process com.android.unit_tests
I/ActivityManager(   54): Start proc com.android.unit_tests for added
application com.android.unit_tests: pid=276 uid=10025 gids={3003}
D/dalvikvm(  276): GC freed 5340 objects / 386784 bytes in 133ms
D/dalvikvm(  276): GC freed 7860 objects / 630784 bytes in 131ms
I/TraceTest(  276): Loading trace_test native library...
W/TraceTest(  276): Could not load trace_test native library
W/dalvikvm(  276): VFY: unable to resolve interface method 131:
Landroid/content/pm/IPackageManager;.freeStorageAndNotify (JLandroid/
content/pm/IPackageDataObserver;)V
W/dalvikvm(  276): VFY:  rejecting opcode 0x72 at 0x0015
W/dalvikvm(  276): VFY:  rejected Lcom/android/unit_tests/
AppCacheTest;.invokePMFreeApplicationCache (J)Z
W/dalvikvm(  276): Verifier rejected class Lcom/android/unit_tests/
AppCacheTest;
D/AndroidRuntime(  276): Shutting down VM
W/dalvikvm(  276): threadid=3: thread exiting with uncaught exception
(group=0x4000fe68)
E/AndroidRuntime(  276): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(  276): java.lang.VerifyError:
com.android.unit_tests.AppCacheTest
E/AndroidRuntime(  276):        at java.lang.Class.getDeclaredConstructors
(Native Method)
E/AndroidRuntime(  276):        at java.lang.Class.getConstructors
(Class.java:414)
E/AndroidRuntime(  276):        at android.test.suitebuilder.TestGrouping
$TestCasePredicate.hasValidConstructor(TestGrouping.java:226)
E/AndroidRuntime(  276):        at android.test.suitebuilder.TestGrouping
$TestCasePredicate.apply(TestGrouping.java:215)
E/AndroidRuntime(  276):        at android.test.suitebuilder.TestGrouping
$TestCasePredicate.apply(TestGrouping.java:211)
E/AndroidRuntime(  276):        at
android.test.suitebuilder.TestGrouping.select(TestGrouping.java:170)
E/AndroidRuntime(  276):        at
android.test.suitebuilder.TestGrouping.selectTestClasses
(TestGrouping.java:160)
E/AndroidRuntime(  276):        at
android.test.suitebuilder.TestGrouping.testCaseClassesInPackage
(TestGrouping.java:154)
E/AndroidRuntime(  276):        at
android.test.suitebuilder.TestGrouping.addPackagesRecursive
(TestGrouping.java:115)
E/AndroidRuntime(  276):        at
android.test.suitebuilder.TestSuiteBuilder.includePackages
(TestSuiteBuilder.java:109)
E/AndroidRuntime(  276):        at
android.test.InstrumentationTestRunner.onCreate
(InstrumentationTestRunner.java:257)
E/AndroidRuntime(  276):        at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:
3392)
E/AndroidRuntime(  276):        at android.app.ActivityThread.access$2500
(ActivityThread.java:112)
E/AndroidRuntime(  276):        at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1617)
E/AndroidRuntime(  276):        at android.os.Handler.dispatchMessage
(Handler.java:88)
E/AndroidRuntime(  276):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  276):        at android.app.ActivityThread.main
(ActivityThread.java:3739)
E/AndroidRuntime(  276):        at java.lang.reflect.Method.invokeNative
(Native Method)
E/AndroidRuntime(  276):        at java.lang.reflect.Method.invoke
(Method.java:515)
E/AndroidRuntime(  276):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:739)
E/AndroidRuntime(  276):        at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:497)
E/AndroidRuntime(  276):        at dalvik.system.NativeStart.main(Native
Method)
I/Process (   54): Sending signal. PID: 276 SIG: 3
I/dalvikvm(  276): threadid=7: reacting to signal 3
W/ActivityManager(   54): Error in app com.android.unit_tests running
instrumentation ComponentInfo{com.android.unit_tests/
android.test.InstrumentationTestRunner}:
W/ActivityManager(   54):   com.android.unit_tests.AppCacheTest
W/ActivityManager(   54):   java.lang.VerifyError:
com.android.unit_tests.AppCacheTest
D/ActivityManager(   54): Uninstalling process com.android.unit_tests
D/ActivityManager(   54): Force removing process ProcessRecord
{43164a28 276:com.android.unit_tests/10025} (com.android.unit_tests/
10025)

--~--~---------~--~----~------------~-------~--~----~

3. SDK 1.5 Error

4. Chat w/ Android App Developer Pixelpipe on Friday 2pm PST

5. How to get text at touch points

6. Question about ExpandableList and SimpleExpandableListAdapter

7. Phone call recorder