Search in sources :

Example 61 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project PocketMaps by junjunguo.

the class MainActivity method addDeleteItemHandler.

public static void addDeleteItemHandler(final Context context, final RecyclerView recView, final OnItemClickListener l) {
    // swipe left or right to remove an item
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ITEM_TOUCH_HELPER_LEFT | ITEM_TOUCH_HELPER_RIGHT) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(final RecyclerView.ViewHolder viewHolder, int swipeDir) {
            AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
            builder1.setMessage(R.string.delete_msg);
            builder1.setCancelable(true);
            builder1.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    // Remove swiped item from list and notify the RecyclerView
                    l.onItemClick(null, viewHolder.itemView, viewHolder.getAdapterPosition(), viewHolder.getItemId());
                }
            });
            builder1.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    int vhPos = viewHolder.getAdapterPosition();
                    recView.getAdapter().notifyItemRemoved(vhPos);
                    recView.getAdapter().notifyItemInserted(vhPos);
                }
            });
            AlertDialog alert11 = builder1.create();
            alert11.show();
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recView);
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) RecyclerView(android.support.v7.widget.RecyclerView)

Example 62 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project sbt-android by scala-android.

the class DividerItemDecoration method drawVertical.

public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = (int) (parent.getPaddingLeft() + (rtl ? 0 : paddingStart));
    final int right = (int) (parent.getWidth() - parent.getPaddingRight() + (rtl ? paddingStart : 0));
    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.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + divider.getIntrinsicHeight();
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 63 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project sbt-android by scala-android.

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 + Math.round(ViewCompat.getTranslationX(child));
        final int right = left + divider.getIntrinsicHeight();
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 64 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project sbt-android by scala-android.

the class HomeActivity method setNoFiltersEmptyTextVisibility.

private void setNoFiltersEmptyTextVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noFiltersEmptyText == null) {
            // create the no filters empty text
            ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters);
            noFiltersEmptyText = (TextView) stub.inflate();
            String emptyText = getString(R.string.no_filters_selected);
            int filterPlaceholderStart = emptyText.indexOf('\u08B4');
            int altMethodStart = filterPlaceholderStart + 3;
            SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
            // show an image of the filter icon
            ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE), filterPlaceholderStart, filterPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            // make the alt method (swipe from right) less prominent and italic
            ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            noFiltersEmptyText.setText(ssb);
            noFiltersEmptyText.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    drawer.openDrawer(GravityCompat.END);
                }
            });
        }
        noFiltersEmptyText.setVisibility(visibility);
    } else if (noFiltersEmptyText != null) {
        noFiltersEmptyText.setVisibility(visibility);
    }
}
Also used : ViewStub(android.view.ViewStub) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ActionMenuView(android.widget.ActionMenuView) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 65 with RIGHT

use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project MVPFrames by RockyQu.

the class BlurEngine method blur.

/**
 * 将所给Bitmap完成模糊后添加到View中
 *
 * @param bkg
 * @param view
 */
private void blur(Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    // define layout params to the previous imageView in order to match its parent
    blurredBackgroundLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    // overlay used to build scaled preview and blur background
    Bitmap overlay = null;
    // evaluate top offset due to status bar
    int statusBarHeight = 0;
    if ((activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0) {
        // not in fullscreen mode
        statusBarHeight = getStatusBarHeight();
    }
    // on content bellow the status.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && isStatusBarTranslucent()) {
        statusBarHeight = 0;
    }
    final int topOffset = statusBarHeight;
    // evaluate bottom or right offset due to navigation bar.
    int bottomOffset = 0;
    int rightOffset = 0;
    final int navBarSize = getNavigationBarOffset();
    bottomOffset = navBarSize;
    // add offset to the source boundaries since we don't want to blur actionBar pixels
    Rect srcRect = new Rect(0, topOffset, bkg.getWidth() - rightOffset, bkg.getHeight() - bottomOffset);
    // in order to keep the same ratio as the one which will be used for rendering, also
    // add the offset to the overlay.
    double height = Math.ceil((view.getHeight() - topOffset - bottomOffset) / blurDegree);
    double width = Math.ceil(((view.getWidth() - rightOffset) * height / (view.getHeight() - topOffset - bottomOffset)));
    // Render script doesn't work with RGB_565
    if (switchEngine) {
        overlay = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
    } else {
        overlay = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.RGB_565);
    }
    try {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || activity instanceof AppCompatActivity) {
            // add offset as top margin since actionBar height must also considered when we display
            // the blurred background. Don't want to draw on the actionBar.
            blurredBackgroundLayoutParams.setMargins(0, 0, 0, 0);
            blurredBackgroundLayoutParams.gravity = Gravity.TOP;
        }
    } catch (NoClassDefFoundError e) {
        // no dependency to appcompat, that means no additional top offset due to actionBar.
        blurredBackgroundLayoutParams.setMargins(0, 0, 0, 0);
    }
    // scale and draw background view on the canvas overlay
    Canvas canvas = new Canvas(overlay);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    // build drawing destination boundaries
    final RectF destRect = new RectF(0, 0, overlay.getWidth(), overlay.getHeight());
    // draw background from source area in source background to the destination area on the overlay
    canvas.drawBitmap(bkg, srcRect, destRect, paint);
    // apply fast blur on overlay
    if (switchEngine) {
        overlay = BlurRenderScriptHelper.doBlur(overlay, blurRadius, true, activity);
    } else {
        overlay = BlurFastHelper.doBlur(overlay, blurRadius, true);
    }
    if (debugMode) {
        String blurTime = (System.currentTimeMillis() - startMs) + " ms";
        Rect bounds = new Rect();
        Canvas canvas1 = new Canvas(overlay);
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
        paint.setTextSize(20.0f);
        paint.getTextBounds(blurTime, 0, blurTime.length(), bounds);
        canvas1.drawText(blurTime, 2, bounds.height(), paint);
    }
    // set bitmap in an image view for final rendering
    blurredBackgroundView = new ImageView(activity);
    blurredBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    blurredBackgroundView.setImageDrawable(new BitmapDrawable(activity.getResources(), overlay));
}
Also used : Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) AppCompatActivity(android.support.v7.app.AppCompatActivity) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView)

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