Search in sources :

Example 26 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project AndroidChromium by JackyAndroid.

the class NewTabPageRecyclerView method dismissItemWithAnimation.

/**
     * Animates the card being swiped to the right as if the user had dismissed it. Any changes to
     * the animation here should be reflected also in
     * {@link #updateViewStateForDismiss(float, ViewHolder)} and reset in
     * {@link CardViewHolder#onBindViewHolder()}.
     * @param suggestion The item to be dismissed.
     */
public void dismissItemWithAnimation(SnippetArticle suggestion) {
    // We need to recompute the position, as it might have changed.
    final int position = getNewTabPageAdapter().getSuggestionPosition(suggestion);
    if (position == RecyclerView.NO_POSITION) {
        // The item does not exist anymore, so ignore.
        return;
    }
    final View itemView = mLayoutManager.findViewByPosition(position);
    if (itemView == null) {
        // The view is not visible anymore, skip the animation.
        getNewTabPageAdapter().dismissItem(position);
        return;
    }
    final ViewHolder viewHolder = getChildViewHolder(itemView);
    if (!((NewTabPageViewHolder) viewHolder).isDismissable()) {
        // The item is not dismissable (anymore), so ignore.
        return;
    }
    AnimatorSet animation = new AnimatorSet();
    animation.playTogether(ObjectAnimator.ofFloat(itemView, View.ALPHA, 0f), ObjectAnimator.ofFloat(itemView, View.TRANSLATION_X, (float) itemView.getWidth()));
    animation.setDuration(DISMISS_ANIMATION_TIME_MS);
    animation.setInterpolator(DISMISS_INTERPOLATOR);
    animation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            NewTabPageRecyclerView.this.onItemDismissStarted(viewHolder);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            getNewTabPageAdapter().dismissItem(position);
            NewTabPageRecyclerView.this.onItemDismissFinished(viewHolder);
        }
    });
    animation.start();
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) SectionHeaderViewHolder(org.chromium.chrome.browser.ntp.snippets.SectionHeaderViewHolder) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 27 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project android_frameworks_base by DirtyUnicorns.

the class FocusManager method findTargetPosition.

/**
     * Finds the destination position where the focus should land for a given navigation event.
     *
     * @param view The view that received the event.
     * @param keyCode The key code for the event.
     * @param event
     * @return The adapter position of the destination item. Could be RecyclerView.NO_POSITION.
     */
private int findTargetPosition(View view, int keyCode, KeyEvent event) {
    switch(keyCode) {
        case KeyEvent.KEYCODE_MOVE_HOME:
            return 0;
        case KeyEvent.KEYCODE_MOVE_END:
            return mAdapter.getItemCount() - 1;
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_PAGE_DOWN:
            return findPagedTargetPosition(view, keyCode, event);
    }
    // Find a navigation target based on the arrow key that the user pressed.
    int searchDir = -1;
    switch(keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            searchDir = View.FOCUS_UP;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            searchDir = View.FOCUS_DOWN;
            break;
    }
    if (inGridMode()) {
        int currentPosition = mView.getChildAdapterPosition(view);
        // Left and right arrow keys only work in grid mode.
        switch(keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (currentPosition > 0) {
                    // Stop backward focus search at the first item, otherwise focus will wrap
                    // around to the last visible item.
                    searchDir = View.FOCUS_BACKWARD;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (currentPosition < mAdapter.getItemCount() - 1) {
                    // Stop forward focus search at the last item, otherwise focus will wrap
                    // around to the first visible item.
                    searchDir = View.FOCUS_FORWARD;
                }
                break;
        }
    }
    if (searchDir != -1) {
        // Focus search behaves badly if the parent RecyclerView is focused. However, focusable
        // shouldn't be unset on RecyclerView, otherwise focus isn't properly restored after
        // events that cause a UI rebuild (like rotating the device). Compromise: turn focusable
        // off while performing the focus search.
        // TODO: Revisit this when RV focus issues are resolved.
        mView.setFocusable(false);
        View targetView = view.focusSearch(searchDir);
        mView.setFocusable(true);
        // of the list.
        if (targetView != null) {
            // Ignore navigation targets that aren't items in the RecyclerView.
            if (targetView.getParent() == mView) {
                return mView.getChildAdapterPosition(targetView);
            }
        }
    }
    return RecyclerView.NO_POSITION;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 28 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project android_frameworks_base by DirtyUnicorns.

the class TileAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final Holder holder, int position) {
    if (holder.getItemViewType() == TYPE_DIVIDER) {
        holder.itemView.setVisibility(mTileDividerIndex < mTiles.size() - 1 ? View.VISIBLE : View.INVISIBLE);
        return;
    }
    if (holder.getItemViewType() == TYPE_EDIT) {
        ((TextView) holder.itemView.findViewById(android.R.id.title)).setText(mCurrentDrag != null ? R.string.drag_to_remove_tiles : R.string.drag_to_add_tiles);
        return;
    }
    if (holder.getItemViewType() == TYPE_ACCESSIBLE_DROP) {
        holder.mTileView.setClickable(true);
        holder.mTileView.setFocusable(true);
        holder.mTileView.setFocusableInTouchMode(true);
        holder.mTileView.setVisibility(View.VISIBLE);
        holder.mTileView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
        holder.mTileView.setContentDescription(mContext.getString(R.string.accessibility_qs_edit_position_label, position + 1));
        holder.mTileView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                selectPosition(holder.getAdapterPosition(), v);
            }
        });
        if (mNeedsFocus) {
            // Wait for this to get laid out then set its focus.
            // Ensure that tile gets laid out so we get the callback.
            holder.mTileView.requestLayout();
            holder.mTileView.addOnLayoutChangeListener(new OnLayoutChangeListener() {

                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    holder.mTileView.removeOnLayoutChangeListener(this);
                    holder.mTileView.requestFocus();
                }
            });
            mNeedsFocus = false;
        }
        return;
    }
    TileInfo info = mTiles.get(position);
    if (position > mEditIndex) {
        info.state.contentDescription = mContext.getString(R.string.accessibility_qs_edit_add_tile_label, info.state.label);
    } else if (mAccessibilityMoving) {
        info.state.contentDescription = mContext.getString(R.string.accessibility_qs_edit_position_label, position + 1);
    } else {
        info.state.contentDescription = mContext.getString(R.string.accessibility_qs_edit_tile_label, position + 1, info.state.label);
    }
    holder.mTileView.onStateChanged(info.state);
    holder.mTileView.setAppLabel(info.appLabel);
    holder.mTileView.setShowAppLabel(position > mEditIndex && !info.isSystem);
    if (mAccessibilityManager.isTouchExplorationEnabled()) {
        final boolean selectable = !mAccessibilityMoving || position < mEditIndex;
        holder.mTileView.setClickable(selectable);
        holder.mTileView.setFocusable(selectable);
        holder.mTileView.setImportantForAccessibility(selectable ? View.IMPORTANT_FOR_ACCESSIBILITY_YES : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
        if (selectable) {
            holder.mTileView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    int position = holder.getAdapterPosition();
                    if (mAccessibilityMoving) {
                        selectPosition(position, v);
                    } else {
                        if (position < mEditIndex) {
                            showAccessibilityDialog(position, v);
                        } else {
                            startAccessibleDrag(position);
                        }
                    }
                }
            });
        }
    }
}
Also used : TileInfo(com.android.systemui.qs.customize.TileQueryHelper.TileInfo) OnLayoutChangeListener(android.view.View.OnLayoutChangeListener) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) QSIconView(com.android.systemui.qs.QSIconView)

Example 29 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project Shuttle by timusus.

the class DataCastManager method onApplicationConnected.

@Override
public void onApplicationConnected(ApplicationMetadata appMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
    LOGD(TAG, "onApplicationConnected() reached with sessionId: " + sessionId);
    // saving session for future retrieval; we only save the last session info
    mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SESSION_ID, sessionId);
    if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
        // we have tried to reconnect and successfully launched the app, so
        // it is time to select the route and make the cast icon happy :-)
        List<RouteInfo> routes = mMediaRouter.getRoutes();
        if (routes != null) {
            String routeId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_ROUTE_ID);
            boolean found = false;
            for (RouteInfo routeInfo : routes) {
                if (routeId.equals(routeInfo.getId())) {
                    // found the right route
                    LOGD(TAG, "Found the correct route during reconnection attempt");
                    found = true;
                    mReconnectionStatus = RECONNECTION_STATUS_FINALIZED;
                    mMediaRouter.selectRoute(routeInfo);
                    break;
                }
            }
            if (!found) {
                // we were hoping to have the route that we wanted, but we
                // didn't so we deselect the device
                onDeviceSelected(null, /* CastDevice */
                null);
                mReconnectionStatus = RECONNECTION_STATUS_INACTIVE;
                return;
            }
        }
    }
    // registering namespaces, if any
    try {
        attachDataChannels();
        mSessionId = sessionId;
        for (DataCastConsumer consumer : mDataConsumers) {
            consumer.onApplicationConnected(appMetadata, applicationStatus, sessionId, wasLaunched);
        }
    } catch (IllegalStateException | IOException e) {
        LOGE(TAG, "Failed to attach namespaces", e);
    }
}
Also used : IOException(java.io.IOException) RouteInfo(android.support.v7.media.MediaRouter.RouteInfo) DataCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.DataCastConsumer)

Example 30 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project Shuttle by timusus.

the class VideoCastManager method onApplicationConnected.

@Override
protected void onApplicationConnected(ApplicationMetadata appMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
    LOGD(TAG, "onApplicationConnected() reached with sessionId: " + sessionId + ", and mReconnectionStatus=" + mReconnectionStatus);
    mApplicationErrorCode = NO_APPLICATION_ERROR;
    if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
        // we have tried to reconnect and successfully launched the app, so
        // it is time to select the route and make the cast icon happy :-)
        List<RouteInfo> routes = mMediaRouter.getRoutes();
        if (routes != null) {
            String routeId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_ROUTE_ID);
            for (RouteInfo routeInfo : routes) {
                if (routeId.equals(routeInfo.getId())) {
                    // found the right route
                    LOGD(TAG, "Found the correct route during reconnection attempt");
                    mReconnectionStatus = RECONNECTION_STATUS_FINALIZED;
                    mMediaRouter.selectRoute(routeInfo);
                    break;
                }
            }
        }
    }
    startNotificationService();
    try {
        attachDataChannel();
        attachMediaChannel();
        mSessionId = sessionId;
        // saving device for future retrieval; we only save the last session info
        mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SESSION_ID, mSessionId);
        mRemoteMediaPlayer.requestStatus(mApiClient).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

            @Override
            public void onResult(MediaChannelResult result) {
                if (!result.getStatus().isSuccess()) {
                    onFailed(R.string.ccl_failed_status_request, result.getStatus().getStatusCode());
                }
            }
        });
        for (VideoCastConsumer consumer : mVideoConsumers) {
            consumer.onApplicationConnected(appMetadata, mSessionId, wasLaunched);
        }
    } catch (TransientNetworkDisconnectionException e) {
        LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
        onFailed(R.string.ccl_failed_no_connection_trans, NO_STATUS_CODE);
    } catch (NoConnectionException e) {
        LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
        onFailed(R.string.ccl_failed_no_connection, NO_STATUS_CODE);
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) RouteInfo(android.support.v7.media.MediaRouter.RouteInfo)

Aggregations

View (android.view.View)315 RecyclerView (android.support.v7.widget.RecyclerView)294 Paint (android.graphics.Paint)47 TextView (android.widget.TextView)46 ImageView (android.widget.ImageView)29 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)27 ViewGroup (android.view.ViewGroup)15 Intent (android.content.Intent)13 Rect (android.graphics.Rect)12 Preference (android.support.v7.preference.Preference)12 GridLayoutManager (android.support.v7.widget.GridLayoutManager)11 SuppressLint (android.annotation.SuppressLint)10 AlertDialog (android.support.v7.app.AlertDialog)10 Bundle (android.os.Bundle)9 Bitmap (android.graphics.Bitmap)8 OnLayoutChangeListener (android.view.View.OnLayoutChangeListener)8 Button (android.widget.Button)8 PreferenceScreen (android.support.v7.preference.PreferenceScreen)7 ArrayList (java.util.ArrayList)7 Animator (android.animation.Animator)6