private class PerformClick extends WindowRunnnable implements Runnable {
View mChild;
int mClickMotionPosition;
public void run() {
LOGE("PerformClick:::run()");
// The data has changed since we posted this action in the event queue,
// bail out before bad things happen
if (mDataChanged) return;
LOGE("PerformClick:::mClickMotionPosition::::" + mClickMotionPosition);
LOGE("PerformClick:::currentChildCount::::" + (getLastVisiblePosition() + 1));
if(mClickMotionPosition == (getLastVisiblePosition() + 1)) return;
if (mAdapter != null && mItemCount > 0 && mClickMotionPosition < mAdapter.getCount() && sameWindow()) {
performItemClick(mChild, mClickMotionPosition, getAdapter().getItemId(mClickMotionPosition));
}
}
}
private boolean performLongPress(final View child, final int longPressPosition, final long longPressId) {
boolean handled = false;
LOGE(":::::::::performLongPress:::::longPressPosition" + longPressPosition);
if(longPressPosition == (getLastVisiblePosition() + 1)) return false;
if (mOnItemLongClickListener != null) {
handled = mOnItemLongClickListener.onItemLongClick(AbsPageView.this, child, longPressPosition, longPressId);
}
if (!handled) {
mContextMenuInfo = createContextMenuInfo(child, longPressPosition, longPressId);
handled = super.showContextMenuForChild(AbsPageView.this);
}
if (handled) {
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}
return handled;
}
private void layoutNavigatorView() {
final View child = mNavigatorView;
int index = indexOfChild(mNavigatorView);
LOGE("::::::layoutNavigatorView:::::remove position:::" + index);
if (index > 0)
return;
//AbsPageView.LayoutParams p = (AbsPageView.LayoutParams)child.getLayoutParams();
ViewGroup.LayoutParams v = child.getLayoutParams();
AbsPageView.LayoutParams p = (v == null) ? null : new AbsPageView.LayoutParams(v);
if (p == null) {
p = new AbsPageView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
}
p.viewType = 0;
attachViewToParent(child, -1, p);
mNavigatorView.requestLayout();
boolean needToMeasure = child.isLayoutRequested();
final int widthSize = MeasureSpec.getSize(mWidthMeasureSpec);
final int heightSize = MeasureSpec.getSize(mHeightMeasureSpec);
//Update indicator info
//mNavigatorPageCurrent.setText(String.valueOf(mPageCurrent));
//mNavigatorPageCount.setText(String.valueOf(mPageCount));
String _pageCount = String.valueOf(mPageCount);
String _pageCurrent = String.valueOf(mPageCurrent);
mNavigatorInfo.setText(String.format(getResources().getString(R.string.page_info), _pageCurrent,_pageCount));
//mNavigatorInfo.setText("sssss");
if(mPageCount == 1){
mNavigatorPrevView.setImageResource(R.drawable.pre_disable);
mNavigatorNextView.setImageResource(R.drawable.next_disable);
}else{
if(mPageCurrent == 1){
mNavigatorPrevView.setImageResource(R.drawable.pre_disable);
}else{
mNavigatorPrevView.setImageResource(R.drawable.pre_act);
}
if(mPageCurrent == mPageCount){
mNavigatorNextView.setImageResource(R.drawable.next_disable);
}else{
mNavigatorNextView.setImageResource(R.drawable.next_act);
}
}
/*
if(mTurnNextPageMode == TURN_NEXT_PAGE_MODE_LTR || mTurnNextPageMode == TURN_NEXT_PAGE_MODE_RTL) {
mNavigatorPrevView.setImageResource(R.drawable.pageview_left);
mNavigatorNextView.setImageResource(R.drawable.pageview_right);
}
else {
mNavigatorPrevView.setImageResource(R.drawable.pageview_up);
mNavigatorNextView.setImageResource(R.drawable.pageview_down);
}
*/
//mNavigatorPrevView.setVisibility((mPageCurrent <= 1) ? View.INVISIBLE : View.VISIBLE);
//mNavigatorNextView.setVisibility((mPageCurrent >= mPageCount) ? View.INVISIBLE : View.VISIBLE);
LOGE(":::layoutNavigatorView:::needToMeasure::" +needToMeasure );
if (needToMeasure) {
int childHeightSpec = ViewGroup.getChildMeasureSpec(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height);
int childWidthSpec = ViewGroup.getChildMeasureSpec(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), 0, p.width);
child.measure(childWidthSpec, childHeightSpec);
} else {
cleanupLayoutState(child);
}
int w = widthSize;
int h = mNavigatorHeight;
final int childLeft = 0;
final int childTop = heightSize - mNavigatorHeight;
if (needToMeasure) {
final int childRight = childLeft + w;
final int childBottom = childTop + h;
child.layout(childLeft, childTop, childRight, childBottom);
} else {
child.offsetLeftAndRight(childLeft - child.getLeft());
child.offsetTopAndBottom(childTop - child.getTop());
}
}
public void onClick(View v) {
LOGE(":::::::::onClick:::::::::");
// button onclick to turn page
int viewId = v.getId();
switch(viewId){
case R.id.prevPage:
LOGE(":::::::::onClick::::::::prev");
fillGap(false);
break;
case R.id.nextPage:
LOGE(":::::::::onClick::::::::next");
fillGap(true);
break;
}
}
protected void onLayout(boolean changed, int l, int t, int r, int b) {
LOGE("onLayout:::changed("+changed+"), l("+l+"), t("+t+"), r("+r+"), b("+b+")");
super.onLayout(changed, l, t, r, b);
mInLayout = true;
layoutChildren();
if(mNavigatorDisplay){
layoutNavigatorView();
}
mInLayout = false;
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
LOGE("onMeasure:::");
if (mSelector == null) {
useDefaultSelector();
}
final Rect listPadding = mListPadding;
listPadding.left = mSelectionLeftPadding + mPaddingLeft;
listPadding.top = mSelectionTopPadding + mPaddingTop;
listPadding.right = mSelectionRightPadding + mPaddingRight;
listPadding.bottom = mSelectionBottomPadding + mPaddingBottom;
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
final int count = mItemCount;
if (count > 0) {
//It should show indicator, so computer it's height
//AbsPageView.LayoutParams p = (AbsPageView.LayoutParams)mNavigatorView.getLayoutParams();
ViewGroup.LayoutParams v = mNavigatorView.getLayoutParams();
AbsPageView.LayoutParams p = (v == null) ? null : new AbsPageView.LayoutParams(v);
if (p == null) {
p = new AbsPageView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
mNavigatorView.setLayoutParams(p);
}
p.viewType = 0;
int childHeightSpec = getChildMeasureSpec(MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.UNSPECIFIED), 0, p.height);
int childWidthSpec = getChildMeasureSpec(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.UNSPECIFIED), 0, p.width);
mNavigatorView.measure(childWidthSpec, childHeightSpec);
mNavigatorHeight = mNavigatorView.getMeasuredHeight();
}
else {
mNavigatorHeight = 0;
}
LOGE("onMeasure:::mNavigatorHeight="+mNavigatorHeight);
}
public int getExtendHeight()
{
if(mNavigatorDisplay){
return mNavigatorHeight;
}else{
return 0;
//return mScrollBarSize;
}
/*
if(mTurnNextPageMode == TURN_NEXT_PAGE_MODE_TTB || mTurnNextPageMode == TURN_NEXT_PAGE_MODE_BTT) {
return 0;
}
else {
return mScrollBarSize;
}
*/
}
private void initNavigatorView(Context context){
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mNavigatorView = inflater.inflate(R.layout.pageview_navigator, null);
//mNavigatorPageCurrent = (TextView)mNavigatorView.findViewById(R.id.pageCurrent);
//mNavigatorPageCount = (TextView)mNavigatorView.findViewById(R.id.pageCount);
//mNavigatorInfo = (TextView)mNavigatorView.findViewById(R.id.pageInfo);
mNavigatorPrevView = (ImageView)mNavigatorView.findViewById(R.id.prevPage);
mNavigatorNextView = (ImageView)mNavigatorView.findViewById(R.id.nextPage);
mNavigatorInfo = (TextView)mNavigatorView.findViewById(R.id.pageSplitor);
//splitor.setText("/");
// register listener
mNavigatorPrevView.setOnClickListener(this);
mNavigatorNextView.setOnClickListener(this);
}