use of android.view.ViewGroup in project Launcher3 by chislon.
the class FocusHelper method handlePagedViewGridLayoutWidgetKeyEvent.
/**
* Handles key events in a PageViewExtendedLayout containing PagedViewWidgets.
*/
static boolean handlePagedViewGridLayoutWidgetKeyEvent(PagedViewWidget w, int keyCode, KeyEvent e) {
final PagedViewGridLayout parent = (PagedViewGridLayout) w.getParent();
final PagedView container = (PagedView) parent.getParent();
final TabHost tabHost = findTabHostParent(container);
final TabWidget tabs = tabHost.getTabWidget();
final int widgetIndex = parent.indexOfChild(w);
final int widgetCount = parent.getChildCount();
final int pageIndex = ((PagedView) container).indexToPage(container.indexOfChild(parent));
final int pageCount = container.getChildCount();
final int cellCountX = parent.getCellCountX();
final int cellCountY = parent.getCellCountY();
final int x = widgetIndex % cellCountX;
final int y = widgetIndex / cellCountX;
final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
ViewGroup newParent = null;
// Now that we load items in the bg asynchronously, we can't just focus
// child siblings willy-nilly
View child = null;
boolean wasHandled = false;
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (handleKeyEvent) {
// Select the previous widget or the last widget on the previous page
if (widgetIndex > 0) {
parent.getChildAt(widgetIndex - 1).requestFocus();
} else {
if (pageIndex > 0) {
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
child = newParent.getChildAt(newParent.getChildCount() - 1);
if (child != null)
child.requestFocus();
}
}
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (handleKeyEvent) {
// Select the next widget or the first widget on the next page
if (widgetIndex < (widgetCount - 1)) {
parent.getChildAt(widgetIndex + 1).requestFocus();
} else {
if (pageIndex < (pageCount - 1)) {
newParent = getAppsCustomizePage(container, pageIndex + 1);
if (newParent != null) {
child = newParent.getChildAt(0);
if (child != null)
child.requestFocus();
}
}
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_UP:
if (handleKeyEvent) {
// Select the closest icon in the previous row, otherwise select the tab bar
if (y > 0) {
int newWidgetIndex = ((y - 1) * cellCountX) + x;
child = parent.getChildAt(newWidgetIndex);
if (child != null)
child.requestFocus();
} else {
tabs.requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
if (handleKeyEvent) {
// Select the closest icon in the previous row, otherwise do nothing
if (y < (cellCountY - 1)) {
int newWidgetIndex = Math.min(widgetCount - 1, ((y + 1) * cellCountX) + x);
child = parent.getChildAt(newWidgetIndex);
if (child != null)
child.requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
if (handleKeyEvent) {
// Simulate a click on the widget
View.OnClickListener clickListener = (View.OnClickListener) container;
clickListener.onClick(w);
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_PAGE_UP:
if (handleKeyEvent) {
// if there is no previous page
if (pageIndex > 0) {
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
child = newParent.getChildAt(0);
}
} else {
child = parent.getChildAt(0);
}
if (child != null)
child.requestFocus();
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_PAGE_DOWN:
if (handleKeyEvent) {
// if there is no next page
if (pageIndex < (pageCount - 1)) {
newParent = getAppsCustomizePage(container, pageIndex + 1);
if (newParent != null) {
child = newParent.getChildAt(0);
}
} else {
child = parent.getChildAt(widgetCount - 1);
}
if (child != null)
child.requestFocus();
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_MOVE_HOME:
if (handleKeyEvent) {
// Select the first item on this page
child = parent.getChildAt(0);
if (child != null)
child.requestFocus();
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_MOVE_END:
if (handleKeyEvent) {
// Select the last item on this page
parent.getChildAt(widgetCount - 1).requestFocus();
}
wasHandled = true;
break;
default:
break;
}
return wasHandled;
}
use of android.view.ViewGroup in project Launcher3 by chislon.
the class FocusHelper method handleAppsCustomizeTabKeyEvent.
/**
* Handles key events in a AppsCustomize tab between the last tab view and the shop button.
*/
static boolean handleAppsCustomizeTabKeyEvent(View v, int keyCode, KeyEvent e) {
final TabHost tabHost = findTabHostParent(v);
final ViewGroup contents = tabHost.getTabContentView();
final View shop = tabHost.findViewById(R.id.market_button);
final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
boolean wasHandled = false;
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (handleKeyEvent) {
// Select the shop button if we aren't on it
if (v != shop) {
shop.requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
if (handleKeyEvent) {
// Select the content view (down is handled by the tab key handler otherwise)
if (v == shop) {
contents.requestFocus();
wasHandled = true;
}
}
break;
default:
break;
}
return wasHandled;
}
use of android.view.ViewGroup in project Android-PullToRefresh by chrisbanes.
the class PullToRefreshAdapterViewBase method setEmptyView.
/**
* Sets the Empty View to be used by the Adapter View.
* <p/>
* We need it handle it ourselves so that we can Pull-to-Refresh when the
* Empty View is shown.
* <p/>
* Please note, you do <strong>not</strong> usually need to call this method
* yourself. Calling setEmptyView on the AdapterView will automatically call
* this method and set everything up. This includes when the Android
* Framework automatically sets the Empty View based on it's ID.
*
* @param newEmptyView - Empty View to be used
*/
public final void setEmptyView(View newEmptyView) {
FrameLayout refreshableViewWrapper = getRefreshableViewWrapper();
if (null != newEmptyView) {
// New view needs to be clickable so that Android recognizes it as a
// target for Touch Events
newEmptyView.setClickable(true);
ViewParent newEmptyViewParent = newEmptyView.getParent();
if (null != newEmptyViewParent && newEmptyViewParent instanceof ViewGroup) {
((ViewGroup) newEmptyViewParent).removeView(newEmptyView);
}
// We need to convert any LayoutParams so that it works in our
// FrameLayout
FrameLayout.LayoutParams lp = convertEmptyViewLayoutParams(newEmptyView.getLayoutParams());
if (null != lp) {
refreshableViewWrapper.addView(newEmptyView, lp);
} else {
refreshableViewWrapper.addView(newEmptyView);
}
}
if (mRefreshableView instanceof EmptyViewMethodAccessor) {
((EmptyViewMethodAccessor) mRefreshableView).setEmptyViewInternal(newEmptyView);
} else {
mRefreshableView.setEmptyView(newEmptyView);
}
mEmptyView = newEmptyView;
}
use of android.view.ViewGroup in project UltimateRecyclerView by cymcsg.
the class SwipeListView method recycle.
/**
* Recycle cell. This method should be called from getView in Adapter when use SWIPE_ACTION_CHOICE
*
* @param convertView parent view
* @param position position in list
*/
public void recycle(View convertView, int position) {
touchListener.reloadChoiceStateInView(convertView.findViewById(swipeFrontView), position);
touchListener.reloadSwipeStateInView(convertView.findViewById(swipeFrontView), position);
// cleaned.
for (int j = 0; j < ((ViewGroup) convertView).getChildCount(); ++j) {
View nextChild = ((ViewGroup) convertView).getChildAt(j);
nextChild.setPressed(false);
}
}
use of android.view.ViewGroup in project AndroidViewAnimations by daimajia.
the class ZoomInUpAnimator method prepare.
@Override
public void prepare(View target) {
ViewGroup parent = (ViewGroup) target.getParent();
int distance = parent.getHeight() - target.getTop();
getAnimatorAgent().playTogether(ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1), ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.475f, 1), ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.475f, 1), ObjectAnimator.ofFloat(target, "translationY", distance, -60, 0));
}
Aggregations