[android-developers] Difference between invalidate and requestLayout for Viewgroup

2012-01-12 Thread harvinder
It is my understanding is that when invalidate() is  called on ViewGroup 
derived class  onDraw gets called. However, when requestLayout is called 
onMeasure and onLayout gets called.

Is my understanding correct?

Truly
harvinder

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How to implement scrolling for custom layout?

2012-01-14 Thread harvinder
I am trying to develop a custom ViewGroup to implement sort of a gantt 
chart with vertical and horizontal scrolling.

So I went about the job and implemented following view

I find following issues with this code.

[1] when onScroll is called I see some flicker and not been able 
to successfully use _scroller.startScroll 
[2] while scrolling onMeasure and onLayout rely on _scroller to get the 
correct scrolling positions, however since there is some delay between 
onMeasure and onLayout, _scroller would provide different values for 
_scroller.getCurrX() and_scroller.getCurrY()in both the functions.So 
measure and layout may easily go out of sync.

How do I solve these two issues? For two I can think of implementing 
onMeasure and onLayout in the same method say in onLayout or in onLayout 
use the scroller position that is measured in onMeasure.

For [1] if I use view's scrollBy, I see there is no flickers but it calls 
invalidate internally and onMeasure and onLayout will not be called and my 
view will not get a layout refresh.

Any help would be greatly appreciated. 


package com.example.android.layout;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.widget.Scroller;

public class CustomView extends ViewGroup implements OnGestureListener {

private GestureDetector gestureScanner;

private Scroller _scroller;
private int _viewPortX, _viewPortY;
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
gestureScanner = new GestureDetector(this);
_scroller = new Scroller(this.getContext());

}


@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// add a child view from adapter (if view is not already present and
// needs to be shown)
// remove unwanted views
// called measure on children
// call setMeasuredDimension((widthMeasureSpec), (heightMeasureSpec));
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// Layout children here
// ...

if (_scroller.computeScrollOffset()) {
scrollNow(_scroller.getCurrX(), _scroller.getCurrY());

/* This is necessary to request layout while in layout loop */
post(new Runnable() {
public void run() {
requestLayout();
}
});
}
}

@Override
public boolean onTouchEvent(MotionEvent me) {
return gestureScanner.onTouchEvent(me);
}

public void scrollNow(float x, float y) {
_viewPortX = (int) x;
_viewPortY = (int) y;
requestLayout();
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float 
velocityX,float velocityY) {
_scroller.fling(_viewPortX, _viewPortY, (int) velocityX, (int) velocityY,
0, _maxX, 0, _maxY);
requestLayout();

return true;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {

// doing this and not reliying on scroller, and no call to 
_scroller.startScroll
int scrollToX = _viewPortX - (int) distanceX;
scrollToX = Math.min(scrollToX, _maxX);
scrollToX = Math.max(scrollToX, 0);

int scrollToY = _viewPortY - (int) distanceY;
scrollToY = Math.min(scrollToY, _maxY);
scrollToY = Math.max(scrollToY, 0);

scrollNow(scrollToX, scrollToY);

return true;
}

@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return true;
}

@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
 }

@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}


@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
 }

}
 

Thanks
harvinder

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to implement scrolling for custom layout?

2012-01-15 Thread harvinder
@ pskink

The CustomView may have hundreds of children and it is not appropriate to 
create all the views and keep in the memory. So when the scrolling starts, 
to get the latest position displayed (with correct views) on the screen, I 
get the latest scroll position in onMeasure and onLayout and set the 
children appropriately.


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to implement scrolling for custom layout?

2012-01-15 Thread harvinder
well there are hundreds of view and I trust keeping *hundreds* of view in 
memory is not the wise thing to do. I believe the listview implementation 
in the android may also be reusing the views.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How to get LayoutParams after inflating the view

2012-01-17 Thread harvinder
I have following code in my Adapter's getView(...) function

View
 getView(int position, 
View
 convertView, 
ViewGroup
 parent) 
{
if ( convertView == null) {
view = 
LayoutInflater.from(getContext()).inflate(R.layout.program_item, null);
}
LayoutParams params = 
view.getLayoutParams
();
}

params is always null. 
Any idea what am doing wrong?

The intent is too change the width of the view based on the data (position) 
in adapter and keep the height as defined in the xml (program_item.xml).

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to implement scrolling for custom layout?

2012-01-19 Thread harvinder
I have looked into the listview and abslistview classes of android.

Scrolling in not initiating a call on onMeasure or onLayout, but only 
invalidate. 
For some reason I am not been able to debug these classes (can put 
breakpoint only in abslistview but not listview).

Where does children laid out when scrolling starts (layoutChildren is not 
getting called by a call to invalidate)? 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] ViewPager MotionEvent changes between onInterceptTouchEvent and onTouchEvent

2012-01-26 Thread harvinder
Setup:
I am using a custom ViewGroup withing ViewPager(horizontal scroll) . custom 
viewgroup provides vertical scrolling and has implemented OnGestureListener 
with the help of GestureDetector.

I am using android.support.v4.view (revision 6) with android 4.03

+ViewPager (horizontal scrolling)
   + CustomView (vertical scrolling)
  - TextView
  - TextView
   + CustomView
  - TextView
  - TextView

Problem:
Sometime when I am scrolling horizontally ViewPager fails to move to the 
next Page(my custom viewgroup)

What I found to be the reason is that whenever it fails to move I get a 
different event in onTouchEvent of ViewPager than the one intercepted in 
onInterceptTouchEvent of ViewPager. ACTION_MOVE(in  
onInterceptTouchEvent  ) is sent back as ACTION_UP(in onTouchEvent ) and 
hence no scrolling happens. I am not able to understand how and why 
ACTION_MOVE is getting changed to ACTION_UP. Could it be something to do 
with what I do in my custom ViewGroup?

thanks
harvinder

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Is there a way to link SearchViewCompat and Activity.onSearchRequested() i.e. search (hard)button

2012-01-30 Thread harvinder
I am trying to have a actionbar with a searchview widget for API < 11 and 
was able to get it through ActionBarCompat and SearchViewCompat (v4 rev 6).

However, I am still struggling to find a way to link onSearchRequested(), 
i.e user pressing the search button and invoking search dialog at the top, 
with SearchViewCompat.

Any idea if it is doable? 

thanks
harvinder 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] onInterceptTouchEvent and Gesture detector

2012-02-17 Thread harvinder
The View:
I have a Custom ViewGroup that handles gestures from users. I am overriding 
onTouchEvent

@Override
public boolean onTouchEvent(MotionEvent me)
{
return _gestureDetector.onTouchEvent(me);
}
It also have some other views as its children.


Problem:
I am correctly able to handle all the gestures in my Custom ViewGroup. 
Hoever, if I add a click listener on any of the children, gesture detection 
stops.

I understand that I am suppose to play with onInterceptTouchEvent method. 
However, it seems like I have to handle raw events in this method, which 
make me very uncomfortable given that GestureDetector handles all these low 
level events.


I would like to not intercept the click event and pass that on to the 
children but handle the rest using gesture detector.

thanks
harvinder

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en