Search in sources :

Example 26 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project Hummingbird-for-Android by xiprox.

the class DividerItemDecoration method drawHorizontal.

public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 27 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project GitTest by xiaoxige.

the class TestItemDecoration method onDraw.

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);
    for (int i = 0; i < parent.getChildCount(); i++) {
        if (i == 0) {
            continue;
        }
        View childAt = parent.getChildAt(i);
        int top = childAt.getTop() - 4;
        int left = childAt.getPaddingLeft();
        int bottom = childAt.getTop();
        int right = parent.getWidth() - childAt.getPaddingRight();
        c.drawRect(left, top, right, bottom, paint);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Paint(android.graphics.Paint)

Example 28 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project collect by opendatakit.

the class MediaLayout method setAVT.

public void setAVT(FormIndex index, String selectionDesignator, TextView text, String audioURI, String imageURI, String videoURI, final String bigImageURI) {
    this.selectionDesignator = selectionDesignator;
    this.index = index;
    viewText = text;
    originalText = text.getText();
    viewText.setId(ViewIds.generateViewId());
    this.videoURI = videoURI;
    // Layout configurations for our elements in the relative layout
    RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams audioParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams videoParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    // First set up the audio button
    if (audioURI != null) {
        // An audio file is specified
        audioButton = new AudioButton(getContext(), this.index, this.selectionDesignator, audioURI, player);
        audioButton.setPadding(22, 12, 22, 12);
        audioButton.setBackgroundColor(Color.LTGRAY);
        audioButton.setOnClickListener(this);
        // random ID to be used by the
        audioButton.setId(ViewIds.generateViewId());
    // relative layout.
    } else {
    // No audio file specified, so ignore.
    }
    // Then set up the video button
    if (videoURI != null) {
        // An video file is specified
        videoButton = new AppCompatImageButton(getContext());
        Bitmap b = BitmapFactory.decodeResource(getContext().getResources(), android.R.drawable.ic_media_play);
        videoButton.setImageBitmap(b);
        videoButton.setPadding(22, 12, 22, 12);
        videoButton.setBackgroundColor(Color.LTGRAY);
        videoButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick", "playVideoPrompt" + MediaLayout.this.selectionDesignator, MediaLayout.this.index);
                MediaLayout.this.playVideo();
            }
        });
        videoButton.setId(ViewIds.generateViewId());
    } else {
    // No video file specified, so ignore.
    }
    // Now set up the image view
    String errorMsg = null;
    final int imageId = ViewIds.generateViewId();
    if (imageURI != null) {
        try {
            String imageFilename = ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
            final File imageFile = new File(imageFilename);
            if (imageFile.exists()) {
                DisplayMetrics metrics = context.getResources().getDisplayMetrics();
                int screenWidth = metrics.widthPixels;
                int screenHeight = metrics.heightPixels;
                Bitmap b = FileUtils.getBitmapScaledToDisplay(imageFile, screenHeight, screenWidth);
                if (b != null) {
                    imageView = new ImageView(getContext());
                    imageView.setPadding(2, 2, 2, 2);
                    imageView.setImageBitmap(b);
                    imageView.setId(imageId);
                    imageView.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            if (bigImageURI != null) {
                                Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick", "showImagePromptBigImage" + MediaLayout.this.selectionDesignator, MediaLayout.this.index);
                                try {
                                    File bigImage = new File(ReferenceManager.instance().DeriveReference(bigImageURI).getLocalURI());
                                    Intent i = new Intent("android.intent.action.VIEW");
                                    i.setDataAndType(Uri.fromFile(bigImage), "image/*");
                                    getContext().startActivity(i);
                                } catch (InvalidReferenceException e) {
                                    Timber.e(e, "Invalid image reference due to %s ", e.getMessage());
                                } catch (ActivityNotFoundException e) {
                                    Timber.d(e, "No Activity found to handle due to %s", e.getMessage());
                                    ToastUtils.showShortToast(getContext().getString(R.string.activity_not_found, getContext().getString(R.string.view_image)));
                                }
                            } else {
                                if (viewText instanceof RadioButton) {
                                    ((RadioButton) viewText).setChecked(true);
                                } else if (viewText instanceof CheckBox) {
                                    CheckBox checkbox = (CheckBox) viewText;
                                    checkbox.setChecked(!checkbox.isChecked());
                                }
                            }
                        }
                    });
                } else {
                    // Loading the image failed, so it's likely a bad file.
                    errorMsg = getContext().getString(R.string.file_invalid, imageFile);
                }
            } else {
                // We should have an image, but the file doesn't exist.
                errorMsg = getContext().getString(R.string.file_missing, imageFile);
            }
            if (errorMsg != null) {
                // errorMsg is only set when an error has occurred
                Timber.e(errorMsg);
                missingImage = new TextView(getContext());
                missingImage.setText(errorMsg);
                missingImage.setPadding(10, 10, 10, 10);
                missingImage.setId(imageId);
            }
        } catch (InvalidReferenceException e) {
            Timber.e(e, "Invalid image reference due to %s ", e.getMessage());
        }
    } else {
    // There's no imageURI listed, so just ignore it.
    }
    // e.g., for TextView that flag will be true
    boolean isNotAMultipleChoiceField = !RadioButton.class.isAssignableFrom(text.getClass()) && !CheckBox.class.isAssignableFrom(text.getClass());
    // Assumes LTR, TTB reading bias!
    if (viewText.getText().length() == 0 && (imageView != null || missingImage != null)) {
        // it will show a grey bar to the right of the image icon.
        if (imageView != null) {
            imageView.setScaleType(ScaleType.FIT_START);
        }
        // 
        // In this case, we have:
        // Text upper left; image upper, left edge aligned with text right edge;
        // audio upper right; video below audio on right.
        textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        if (isNotAMultipleChoiceField) {
            imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        } else {
            imageParams.addRule(RelativeLayout.RIGHT_OF, viewText.getId());
        }
        imageParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        if (audioButton != null && videoButton == null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
        } else if (audioButton == null && videoButton != null) {
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else if (audioButton != null && videoButton != null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.addRule(RelativeLayout.BELOW, audioButton.getId());
            videoParams.setMargins(0, 20, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else {
            // no need to bound it by the width of the parent...
            if (!isNotAMultipleChoiceField) {
                imageParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            }
        }
        imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    } else {
        // In this case, we want the image to be centered...
        if (imageView != null) {
            imageView.setScaleType(ScaleType.FIT_START);
        }
        // 
        // Text upper left; audio upper right; video below audio on right.
        // image below text, audio and video buttons; left-aligned with text.
        textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        if (audioButton != null && videoButton == null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
        } else if (audioButton == null && videoButton != null) {
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else if (audioButton != null && videoButton != null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 20, 11, 0);
            videoParams.addRule(RelativeLayout.BELOW, audioButton.getId());
        } else {
            textParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        }
        if (imageView != null || missingImage != null) {
            imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            imageParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            if (videoButton != null) {
                imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
            } else if (audioButton != null) {
                imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            }
            imageParams.addRule(RelativeLayout.BELOW, viewText.getId());
        } else {
            textParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        }
    }
    addView(viewText, textParams);
    if (audioButton != null) {
        addView(audioButton, audioParams);
    }
    if (videoButton != null) {
        addView(videoButton, videoParams);
    }
    if (imageView != null) {
        addView(imageView, imageParams);
    } else if (missingImage != null) {
        addView(missingImage, imageParams);
    }
}
Also used : Intent(android.content.Intent) AppCompatImageButton(android.support.v7.widget.AppCompatImageButton) RadioButton(android.widget.RadioButton) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) DisplayMetrics(android.util.DisplayMetrics) InvalidReferenceException(org.javarosa.core.reference.InvalidReferenceException) Bitmap(android.graphics.Bitmap) ActivityNotFoundException(android.content.ActivityNotFoundException) CheckBox(android.widget.CheckBox) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) File(java.io.File)

Example 29 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project android_frameworks_base by crdroidandroid.

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 30 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project LoadingBar by dengyuhan.

the class DividerGridItemDecoration method drawVertical.

public void drawVertical(Canvas c, RecyclerView parent) {
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int top = child.getTop() - params.topMargin;
        final int bottom = child.getBottom() + params.bottomMargin;
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

View (android.view.View)291 RecyclerView (android.support.v7.widget.RecyclerView)276 Paint (android.graphics.Paint)43 TextView (android.widget.TextView)36 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)22 ImageView (android.widget.ImageView)20 Rect (android.graphics.Rect)11 Intent (android.content.Intent)9 SuppressLint (android.annotation.SuppressLint)8 OnLayoutChangeListener (android.view.View.OnLayoutChangeListener)8 OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)8 ArrayList (java.util.ArrayList)8 AlertDialog (android.support.v7.app.AlertDialog)7 Toolbar (android.support.v7.widget.Toolbar)7 ViewGroup (android.view.ViewGroup)7 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 Button (android.widget.Button)6 Animator (android.animation.Animator)5 TargetApi (android.annotation.TargetApi)5 Activity (android.app.Activity)5