daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

About swipe multiple rows simultaneously caused crashed to apps #173

Open jianhao1203 opened 9 years ago

jianhao1203 commented 9 years ago

06-18 17:12:12.848: E/AndroidRuntime(21573): FATAL EXCEPTION: main 06-18 17:12:12.848: E/AndroidRuntime(21573): java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(ViewDragHelper.java:1011) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:1111) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1827) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2181) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1924) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2181) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1924) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2181) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1924) 06-18 17:12:12.848: E/AndroidRuntime(21573): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1972) 06-18 17:12:12.848: E/AndroidRuntime(21573): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1420) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.app.Activity.dispatchTouchEvent(Activity.java:2409) 06-18 17:12:12.848: E/AndroidRuntime(21573): at com.pssb.cardsquare.HomePage.dispatchTouchEvent(HomePage.java:741) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268) 06-18 17:12:12.848: E/AndroidRuntime(21573): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1920) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.View.dispatchPointerEvent(View.java:7344) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3203) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3148) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4184) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4163) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4255) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:163) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4234) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4274) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.Choreographer.doCallbacks(Choreographer.java:555) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.Choreographer.doFrame(Choreographer.java:523) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.os.Handler.handleCallback(Handler.java:615) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.os.Handler.dispatchMessage(Handler.java:92) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.os.Looper.loop(Looper.java:137) 06-18 17:12:12.848: E/AndroidRuntime(21573): at android.app.ActivityThread.main(ActivityThread.java:4830) 06-18 17:12:12.848: E/AndroidRuntime(21573): at java.lang.reflect.Method.invokeNative(Native Method) 06-18 17:12:12.848: E/AndroidRuntime(21573): at java.lang.reflect.Method.invoke(Method.java:511) 06-18 17:12:12.848: E/AndroidRuntime(21573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 06-18 17:12:12.848: E/AndroidRuntime(21573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 06-18 17:12:12.848: E/AndroidRuntime(21573): at dalvik.system.NativeStart.main(Native Method)

Thanks author for this library, it helped me lot to do my project. However I found one issues is that when I try to swipe two or more rows together at the same time, it will produce this error(It is not happens every time when swipe multiple rows but it happens always ). So is there any solutions for this, sorry my Android programming skill still in beginner level and I hope everyone who saw this posts can give some help, thanks lot.

jianhao1203 commented 9 years ago

@daimajia can give me some suggestion about this issues? thanks

daimajia commented 9 years ago

Which version currently?

jianhao1203 commented 9 years ago

hi @daimajia u so fast reply, thanks~ which version do u means, the library? or android api? I I using AndroidSwipeLayout-v1.1.8 and my android version is 4.1.2. I found the issues is similar to #91

daimajia commented 9 years ago

@jianhao1203 How you ever tried the latest version v1.2.0?

jianhao1203 commented 9 years ago

@daimajia , actually i using v.1.1.8 is because I using Eclipse to develop my project, for v1.2.0, is it possible to implement with Eclipse as it is gradle file?

daimajia commented 9 years ago

Jar file can not support custom style file, so, it's difficult to support Eclipse in V1.2.0. So, using maven or gradle to manage your dependencies is a better idea.

jianhao1203 commented 9 years ago

@daimajia do u still support V1.1.8? can u help to have a look this issues for v1.1.8 as it is quite new for me to use gradle in v1.2.0....And may I ask that what actually caused this issues? or maybe I can changed in terms of behaviour to avoid this happen in apps?

jianhao1203 commented 9 years ago

Hi @daimajia , I managed to convert the v1.2.0 library from gradle to work in Eclipse based on http://stackoverflow.com/questions/20805715/importing-gradle-project-to-eclipse

However, after I use this new version library, my Item list cannot be displayed out, it showed empty and blank. By here I show my part of my Adapter class method:

        @Override
    public View generateView(int position, ViewGroup parent) {
        View v = LayoutInflater.from(activity).inflate(R.layout.new_card_item,
            null);
    v.setBackgroundResource(R.color.background);
    return v;
    }

         @Override
     public void fillValues(int position, View convertView) {
    final CardHolder holder;
    holder = new CardHolder();
    holder.llcardall = (LinearLayout) convertView
            .findViewById(R.id.llcardall);
    holder.trash = (TextView) convertView.findViewById(R.id.trash);
    holder.tvTitleCard = (TextView) convertView
            .findViewById(R.id.tvTitleCard);
    holder.tvTitleMerchant = (TextView) convertView
            .findViewById(R.id.tvTitleMerchant);
    holder.ivImageCard = (ImageView) convertView
            .findViewById(R.id.ivImageCard);
    holder.llcardall = (LinearLayout) convertView
            .findViewById(R.id.llcardall);
    holder.llcardallitem = (LinearLayout) convertView
            .findViewById(R.id.llcardallitem);
    convertView.setTag(holder);

    final SwipeLayout swipeLayout = (SwipeLayout) convertView
            .findViewById(getSwipeLayoutResourceId(position));
    swipeLayout.addSwipeListener(new SimpleSwipeListener() {

        @Override
        public void onOpen(SwipeLayout layout) {
        }

        @Override
        public void onClose(SwipeLayout layout) {
            // when the SurfaceView totally cover the BottomView.
        }

        @Override
        public void onUpdate(SwipeLayout layout, int leftOffset,
                int topOffset) {
            // you are swiping.
        }

        @Override
        public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
            // when user's hand released.
        }

        @Override
        public void onStartOpen(SwipeLayout layout) {
        }

        @Override
        public void onStartClose(SwipeLayout layout) {
        }
    });

    swipeLayout
            .setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
                @Override
                public void onDoubleClick(SwipeLayout layout,
                        boolean surface) {
                }
            });

    HashMap<String, String> cardList = new HashMap<String, String>();
    cardList = data.get(position);

    DisplayMetrics metrics = new DisplayMetrics();
    metrics = convertView.getResources().getDisplayMetrics();
    int displayWidth = 0;
    int finalWidth = 0;
    int finalHeight = 0;
    float tempWidth = 0;
    float tempHeight = 0;

    displayWidth = metrics.widthPixels;
    tempWidth = (int) (((double) displayWidth * (double) 3) / 10);
    tempHeight = (int) (((double) tempWidth / (double) 160) * 100);
    finalHeight = (int) ((float) tempHeight);
    finalWidth = (int) ((float) tempWidth);

    LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(
            finalWidth, finalHeight);
    holder.ivImageCard.setLayoutParams(parms);
    holder.ivImageCard.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

    ImageLoader.getInstance().displayImage(
            cardList.get("cardimg").toString(), holder.ivImageCard,
            options, new SimpleImageLoadingListener() {
                @Override
                public void onLoadingStarted(String imageUri, View view) {
                }

                @Override
                public void onLoadingFailed(String imageUri, View view,
                        FailReason failReason) {
                }

                @Override
                public void onLoadingComplete(String imageUri, View view,
                        Bitmap loadedImage) {
                    DisplayMetrics metrics = new DisplayMetrics();
                    metrics = view.getResources().getDisplayMetrics();
                    int displayWidth = 0;
                    int displayHeight = 0;
                    int finalWidth = 0;
                    int finalHeight = 0;
                    float tempWidth = 0;
                    float tempHeight = 0;

                    displayWidth = metrics.widthPixels;
                    tempWidth = (int) (((double) displayWidth * (double) 3) / 10);
                    tempHeight = (int) (((double) tempWidth / (double) 160) * 100);
                    finalHeight = (int) ((float) tempHeight);
                    finalWidth = (int) ((float) tempWidth);

                    holder.ivImageCard.setImageBitmap(getRoundedRectBitmap(
                            Bitmap.createScaledBitmap(loadedImage,
                                    finalWidth, finalHeight, false), 12,
                            finalHeight, finalWidth));
                }
            }, new ImageLoadingProgressListener() {
                @Override
                public void onProgressUpdate(String imageUri, View view,
                        int current, int total) {
                }
            });

    holder.tvTitleCard.setText(cardList.get("cardname"));
    holder.tvTitleCard.setTypeface(font1);
    holder.tvTitleCard.setTag(position);
    holder.llcardall.setTag(holder);
    holder.llcardallitem.setTag(holder);

    holder.tvTitleMerchant.setText(cardList.get("merchantname"));
    holder.tvTitleMerchant.setTypeface(font2);
    holder.tvTitleMerchant.setTag(holder);
    holder.ivImageCard.setTag(holder);
    holder.trash.setTag(holder);

    holder.ivImageCard.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            CardHolder holder1 = (CardHolder) v.getTag();
            HashMap<String, String> itemList = new HashMap<String, String>();
            int position = Integer.parseInt(holder1.tvTitleCard.getTag()
                    .toString());
            itemList = data.get(position);
            GlobalData.indicateViewCard = true;
            Intent i = new Intent(activity, CardView.class);
            // Log.e("CARDIMAGE", itemList.get("cardimg").toString());
            i.putExtra("cardImage", itemList.get("cardimg").toString());
            i.putExtra("memberid", itemList.get("membershipidentity")
                    .toString());
            i.putExtra("exp", itemList.get("expiry").toString());
            i.putExtra("merchantid", itemList.get("merchantid").toString());
            i.putExtra("merchantname", itemList.get("merchantname").toString());
            activity.startActivity(i);
            activity.overridePendingTransition(R.anim.in_from_right,
                    R.anim.out_to_left);

        }
    });

    holder.trash.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final CardHolder holder1 = (CardHolder) v.getTag();

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    activity);
            alertDialogBuilder.setTitle("Delete Card");
            alertDialogBuilder
                    .setMessage(
                            "Are you sure you want to delete this card?")
                    .setCancelable(false)
                    .setNegativeButton("Delete",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    swipeLayout.close();
                                    HashMap<String, String> itemList = new HashMap<String, String>();
                                    int position = Integer
                                            .parseInt(holder1.tvTitleCard
                                                    .getTag().toString());
                                    itemList = data.get(position);
                                    backupitemList = itemList;
                                    PostRemoveCard prc = new PostRemoveCard(
                                            ((HomePage) activity), token,
                                            itemList.get("id").toString(),
                                            myHandlerRemoveCard);
                                    prc.execute(new String[] { GlobalData.g_CardDeleteUrl });
                                    ShowProgressDialog("Delete Card");
                                }
                            })
                    .setPositiveButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    swipeLayout.close();
                                }
                            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();

        }
    });
}
jianhao1203 commented 9 years ago

Sorry to post such long code here, but I really hope can get some help from u @daimajia . There is no any error message or crash happen, when I debug there is data inside HashMap "CardList".