Search in sources :

Example 21 with ViewGroup

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;
}
Also used : TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) TabWidget(android.widget.TabWidget) ScrollView(android.widget.ScrollView) View(android.view.View)

Example 22 with ViewGroup

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;
}
Also used : TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) ScrollView(android.widget.ScrollView) View(android.view.View)

Example 23 with ViewGroup

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;
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) EmptyViewMethodAccessor(com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor)

Example 24 with ViewGroup

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);
    }
}
Also used : ViewGroup(android.view.ViewGroup) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ListView(android.widget.ListView)

Example 25 with ViewGroup

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));
}
Also used : ViewGroup(android.view.ViewGroup)

Aggregations

ViewGroup (android.view.ViewGroup)2280 View (android.view.View)1268 TextView (android.widget.TextView)439 ImageView (android.widget.ImageView)279 ArrayList (java.util.ArrayList)198 ViewParent (android.view.ViewParent)184 ListView (android.widget.ListView)156 Paint (android.graphics.Paint)125 FrameLayout (android.widget.FrameLayout)121 LayoutInflater (android.view.LayoutInflater)115 AdapterView (android.widget.AdapterView)115 LinearLayout (android.widget.LinearLayout)110 AbsListView (android.widget.AbsListView)106 Animator (android.animation.Animator)94 Drawable (android.graphics.drawable.Drawable)93 RecyclerView (android.support.v7.widget.RecyclerView)91 AnimatedView (carbon.animation.AnimatedView)88 ComponentView (carbon.component.ComponentView)88 RippleView (carbon.drawable.ripple.RippleView)88 ShadowView (carbon.shadow.ShadowView)88