Example on the use of TouchDelegate?

by Mariano Kamp » Mon, 09 Mar 2009 02:45:19 GMT


Sponsored Links
 Hi,

  is there anybody who used a TouchDelegate[1] and care to share some sample
code?

  I can't make heads and tails of the documentation. If there is no sample
code it would be great if someone could shed some light on the "actors" and
which one implements what for a simple sample, like one button should get a
bigger touch area in a layout?

Cheers,
Mariano

[1]  http://developer.android.com/reference/android/view/TouchDelegate.html 

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



Other Threads

1. Asynchronously loading proble

Dan U, you are right. It's the Toast which needs to be executed by an
UI handler(created in UI thread).

I made a Toast notification after I caught the InterruptedException,
but I forgot I was in a non-UI thread.
What a stupid mistake....

The solution is easy:
                         put the toast notification in a separate
runnable task
                         and post it to the UI thread with a handler created in 
UI thread

Here in the class LoadingTask2:

class LoadingTask2 implements Runnable{
                ...
                ...
                @Override
                public void run() {
                        try {
                                Thread.sleep(10000);
                                
remoteHandler.post(AsyncLoadingMgrSample.this.finishLoadingTask);
                        } catch (InterruptedException e) {
                                /*
                                 * Exception is thrown because:
                                 *
                                 * Toast has to be shown by an UI thread, or 
non-UI thread can't
create a toast
                                 */
//                              
Toast.makeText(AsyncLoadingMgrSample.this,"loading task
error",Toast.LENGTH_LONG).show();

                                /*
                                 * put the toast notification in a separate 
runnable task
                                 * and post it to the UI thread with a handler 
created in UI
thread
                                 */
                                
remoteHandler.post(AsyncLoadingMgrSample.this.cancelLodingTask);

                                Log.i("LoadingTask2:Run","loading task 
interrupted");
                        }

                }









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

2. Focused TextView color

Hello all,

I have a situation where I need to make a TextView focusable and
clickable for a dynamically generated activity (so I'm not using XML
in this case).  I've accomplished this with setClickable(true) and
setFocusable(true) and successfully capture onClick() for the
TextView.  However, when navigating through the interface with the D-
pad, and focus goes onto the TextView from the other controls, there
is no color change indication.  I assume this is because TextView is
not normally focusable.  Unfortunately, this would be confusing to a
user.

How can I mimic the focus color change of the other controls on my
TextView?  Do I need to capture onWindowFocusChanged() myself and then
adjust the color?  The key here is I want it to use the appropriate
color for the current theme and not set the color to a fixed value.

One thing I tried was this:

m_textviewTest.setTextColor(m_checkboxTest.getTextColors());

(m_textviewTest is the TextView and m_checkboxTest is another control
in the activity)
While this code changed the TextView's un-focused color to the
brighter white of checkbox text, focus still does not cause a change
it to the orange of the default theme.  I guess this makes sense,
though, because controls like checkbox and radiobuttons only change
the button's color when focused, and not the accompanying text.  There
seems to be very little information about ColorStateList and stateSets
so I don't know if I'm missing something there.

(Due to the design of this view, I could actually get away with just
making it clickable and not focusable so D-pad focus just skips by it,
but, unfortunately, even if it's clickable, if it's not also
focusable, the onClick() won't fire.)

Thanks for any assistance,
Greg
--~--~---------~--~----~------------~-------~--~----~

3. Showing Default text in EditText fields

4. Height adjustment bug with ImageSwitcher

5. Displaying data from the database in a Spinner

6. List of images

7. Need help in debugging null pointer exception