2016-06-18 10 views
0

onClickを押すと、現在のImageViewを保存するにはどうすればよいですか? イムは、現在の行の横にある画像ではなく、現在の実際の画像で保存されている問題..onClickのときに現在の画像ビューを保存するにはどうすればよいですか?

public class MainActivity extends Activity implements SwipeView.OnCardSwipedListener { 

     // Declaring variables 
     private final static int CARDS_MAX_ELEMENTS = 5; 
     private FrameLayout contentLayout; 
     private SwipeView mSwipeView; 
     private View addCardc41; 
     private Firebase mRef; 
     public ImageView imageLogo; 
     public ImageView imageview; 
     private static final String TAG = "MyActivity"; 

     // Creating array of meals, getting them from the drawable folder 
     private int[] meals = { 
       R.drawable.a, 
       R.drawable.b, 
       R.drawable.c, 
       R.drawable.d, 
       R.drawable.e, 
       R.drawable.f, 
       R.drawable.g, 
       R.drawable.h, 
       R.drawable.i, 
       R.drawable.j 
     }; 

     // Declaring a counter for the next method 
      private int count = 0; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_swipe_view_demo); 
     contentLayout = (FrameLayout) findViewById(R.id.contentLayout); 
     imageLogo = (ImageView) findViewById(R.id.imageView3); 
     imageview = (ImageView) findViewById(R.id.imageView); 

     // Add the swipe view 
     mSwipeView = new SwipeView(this, R.id.imgSwipeLike, R.id.imgSwipeNope, 
       this); 
     contentLayout.addView(mSwipeView); 


     // Adding the cards initially with the maximum limits of cards. 
     for (int i = 0; i < CARDS_MAX_ELEMENTS; i++) { 
      addCard(i); 
     } 

    } 

    /** 
    * On clicked view. 
    * 
    * @param clickedView 
    *   the clicked view 
    */ 
    public void onClickedView(View clickedView) { 
     switch (clickedView.getId()) { 
      case R.id.imgDisLike: { 
       mSwipeView.dislikeCard(); 
       break; 
      } 

      case R.id.imgLike: { 
       mSwipeView.likeCard(); 
       break; 
      } 
     } 
    } 

    @Override 
    public void onLikes() { 
     imageview.setDrawingCacheEnabled(true); //Add this line. 
     imageview.buildDrawingCache(); 
     Bitmap bm=imageview.getDrawingCache(); 

     OutputStream fOut = null; 
     Uri outputFileUri; 
     try { 
      File root = new File(Environment.getExternalStorageDirectory() 
        + File.separator + "folder_name" + File.separator); 
      root.mkdirs(); 
      File sdImageMainDirectory = new File(root, "myPicName.jpg"); 
      outputFileUri = Uri.fromFile(sdImageMainDirectory); 
      fOut = new FileOutputStream(sdImageMainDirectory); 
      MediaScannerConnection.scanFile(this, new String[] { sdImageMainDirectory.getAbsolutePath() }, null, null); 

     } catch (Exception e) { 
      Toast.makeText(this, "Error occured. Please try again later.", 
        Toast.LENGTH_SHORT).show(); 
     } 
     try { 
      bm.compress(Bitmap.CompressFormat.PNG, 100, fOut); 
      fOut.flush(); 
      fOut.close(); 
     } catch (Exception e){} 
     System.out.println("An Card removed"); 
     // Add a card if you needed after any previous card swiped 
     addCard(0); 
    } 

    @Override 
    public void onDisLikes() { 
     System.out.println("An Card removed"); 
     // Add a card if you needed after any previous card swiped 
     addCard(0); 
    } 

    @Override 
    public void onSingleTap() { 

    } 
    /** 
    * Adds the card to the swipe. 
    */ 

    private void addCard(int position) { 
     final View cardView = LayoutInflater.from(this).inflate(
       R.layout.item_swipe_view, null); 
     final ImageView imgMeal = (ImageView) cardView 
       .findViewById(R.id.imgMeals); 
     imgMeal.setImageResource(meals[count]); 
     count++; 
     if (count == meals.length) { 
      count = 0; 
     } 
     // Add a card to the swipe view.. 
     mSwipeView.addCard(cardView, position); 

     // Create OnClickListener for the CookBookActivity 
     // Declare Button for the Cookbook 
     Button btn = (Button) findViewById(R.id.button3); 
     btn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       startActivity(new Intent(MainActivity.this, CookbookActivity.class)); 
      } 
     }); 

     // Check Authentication 
     mRef = new Firebase(Constants.FIREBASE_URL); 
     if (mRef.getAuth() == null) { 
      loadLoginView(); 
     } 
    } 

    private void loadLoginView() { 
     Intent intent = new Intent(this, LoginActivity.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     startActivity(intent); 
    } 


} 

私は図書館onLike保存するための

マイコードを持ちますスワイプ

// 
// credits to IntelliJ IDEA 
// (powered by Fernflower decompiler) 

    package com.rk.lib.view; 

    import android.content.Context; 
    import android.os.Handler; 
    import android.os.Build.VERSION; 
    import android.view.GestureDetector; 
    import android.view.MotionEvent; 
    import android.view.View; 
    import android.view.GestureDetector.SimpleOnGestureListener; 
    import android.view.View.OnTouchListener; 
    import android.view.animation.AlphaAnimation; 
    import android.widget.FrameLayout; 
    import android.widget.LinearLayout; 
    import android.widget.FrameLayout.LayoutParams; 

    public class SwipeView extends FrameLayout { 
     private View mFocusedView; 
     private View mFocusedViewLike; 
     private View mFocusedViewNope; 
     private int mFocusedViewWidth; 
     private float mPreviousAlpha = 0.0F; 
     private Integer mLikeResource = Integer.valueOf(0); 
     private Integer mNopeResource = Integer.valueOf(0); 
     private static final int MAX_ELEMENTS = 3; 
     private static final long DELAY_SCROLL_RUNNABLE = 1L; 
     private static final int SCROLL_LENGTH = 5; 
     private int mScrolledPixelsX; 
     private int mScrolledPixelsY; 
     private int mNeedToScrollX; 
     private int mNeedToScrollY; 
     private int mTotalScrolledX; 
     private int mTotalScrolledY; 
     private int mScrollLengthX = 5; 
     private int mScrollLengthY = 5; 
     private boolean enableTouchSwipe = true; 
     private Context mContext; 
     private SwipeView.ScrollMode mScrollModeX; 
     private SwipeView.ScrollMode mScrollModeY; 
     private SwipeView.ScrollDirection mScrollDirection; 
     private int[] paddingX; 
     private int[] paddingYTop; 
     private int[] paddingYBottom; 
     private SwipeView.OnCardSwipedListener mOnCardSwipedListener; 
     private Handler mScrollHandler; 
     private Runnable mScrollRunnable; 
     private final SimpleOnGestureListener simpleOnGestureListener; 

     public SwipeView(Context context, Integer likeResource, Integer nopeResource, SwipeView.OnCardSwipedListener cardSwipeListener) { 
      super(context); 
      this.mScrollModeX = SwipeView.ScrollMode.NONE; 
      this.mScrollModeY = SwipeView.ScrollMode.NONE; 
      this.mScrollDirection = SwipeView.ScrollDirection.NONE; 
      this.paddingX = new int[]{0, 10, 20}; 
      this.paddingYTop = new int[]{0, 10, 20}; 
      this.paddingYBottom = new int[]{20, 10, 0}; 
      this.mScrollHandler = new Handler(); 
      this.mScrollRunnable = new Runnable() { 
       public void run() { 
        boolean scrollX; 
        boolean scrollY; 
        int scrollX1; 
        int scrollY1; 
        if(SwipeView.this.mScrollDirection == SwipeView.ScrollDirection.OUT) { 
         if(SwipeView.this.mNeedToScrollX <= 0 && SwipeView.this.mNeedToScrollY <= 0) { 
          SwipeView.this.mScrollHandler.removeCallbacks(SwipeView.this.mScrollRunnable); 
          SwipeView.this.removeView(SwipeView.this.mFocusedView); 
          if(SwipeView.this.mScrollModeX == SwipeView.ScrollMode.LEFT) { 
           SwipeView.this.mOnCardSwipedListener.onLikes(); 
          } else if(SwipeView.this.mScrollModeX == SwipeView.ScrollMode.RIGHT) { 
           SwipeView.this.mOnCardSwipedListener.onDisLikes(); 
          } 

          SwipeView.this.alignCardsPadding(); 
         } else { 
          if(SwipeView.this.mNeedToScrollX < SwipeView.this.mScrollLengthX) { 
           SwipeView.this.mScrollLengthX = SwipeView.this.mNeedToScrollX; 
           SwipeView.this.mNeedToScrollX = 0; 
          } else { 
           SwipeView.this.mNeedToScrollX = SwipeView.this.mNeedToScrollX - SwipeView.this.mScrollLengthX; 
          } 

          if(SwipeView.this.mNeedToScrollY < SwipeView.this.mScrollLengthY) { 
           SwipeView.this.mScrollLengthY = SwipeView.this.mNeedToScrollY; 
           SwipeView.this.mNeedToScrollY = 0; 
          } else { 
           SwipeView.this.mNeedToScrollY = SwipeView.this.mNeedToScrollY - SwipeView.this.mScrollLengthY; 
          } 

          scrollX = false; 
          scrollY = false; 
          if(SwipeView.this.mScrollModeX == SwipeView.ScrollMode.LEFT) { 
           scrollX1 = -SwipeView.this.mScrollLengthX; 
          } else { 
           scrollX1 = SwipeView.this.mScrollLengthX; 
          } 

          if(SwipeView.this.mScrollModeY == SwipeView.ScrollMode.TOP) { 
           scrollY1 = -SwipeView.this.mScrollLengthY; 
          } else { 
           scrollY1 = SwipeView.this.mScrollLengthY; 
          } 

          SwipeView.this.mFocusedView.scrollBy(scrollX1, scrollY1); 
          SwipeView.this.mScrollHandler.postDelayed(SwipeView.this.mScrollRunnable, 1L); 
         } 
        } else if(SwipeView.this.mScrollDirection == SwipeView.ScrollDirection.IN) { 
         if(SwipeView.this.mTotalScrolledX <= 0 && SwipeView.this.mTotalScrolledY <= 0) { 
          SwipeView.this.mScrollHandler.removeCallbacks(SwipeView.this.mScrollRunnable); 
          SwipeView.this.mScrollDirection = SwipeView.ScrollDirection.NONE; 
         } else { 
          if(SwipeView.this.mTotalScrolledX < SwipeView.this.mScrollLengthX) { 
           SwipeView.this.mScrollLengthX = SwipeView.this.mTotalScrolledX; 
           SwipeView.this.mTotalScrolledX = 0; 
          } else { 
           SwipeView.this.mTotalScrolledX = SwipeView.this.mTotalScrolledX - SwipeView.this.mScrollLengthX; 
          } 

          if(SwipeView.this.mTotalScrolledY < SwipeView.this.mScrollLengthY) { 
           SwipeView.this.mScrollLengthY = SwipeView.this.mTotalScrolledY; 
           SwipeView.this.mTotalScrolledY = 0; 
          } else { 
           SwipeView.this.mTotalScrolledY = SwipeView.this.mTotalScrolledY - SwipeView.this.mScrollLengthY; 
          } 

          scrollX = false; 
          scrollY = false; 
          if(SwipeView.this.mScrollModeX == SwipeView.ScrollMode.LEFT) { 
           scrollX1 = SwipeView.this.mScrollLengthX; 
          } else { 
           scrollX1 = -SwipeView.this.mScrollLengthX; 
          } 

          if(SwipeView.this.mScrollModeY == SwipeView.ScrollMode.TOP) { 
           scrollY1 = -SwipeView.this.mScrollLengthY; 
          } else { 
           scrollY1 = SwipeView.this.mScrollLengthY; 
          } 

          SwipeView.this.mFocusedView.scrollBy(scrollX1, scrollY1); 
          SwipeView.this.mScrollHandler.postDelayed(SwipeView.this.mScrollRunnable, 1L); 
         } 
        } 

       } 
      }; 
      this.simpleOnGestureListener = new SimpleOnGestureListener() { 
       public boolean onSingleTapConfirmed(MotionEvent e) { 
        SwipeView.this.mOnCardSwipedListener.onSingleTap(); 
        return super.onSingleTapConfirmed(e); 
       } 

       public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 
        if(SwipeView.this.mFocusedView != null) { 
         SwipeView.this.mScrolledPixelsX = SwipeView.this.mScrolledPixelsX + (int)distanceX; 
         SwipeView.this.mScrolledPixelsY = SwipeView.this.mScrolledPixelsY + (int)distanceY; 
         SwipeView.this.mFocusedView.scrollBy((int)distanceX, (int)distanceY); 
         float alpha = (float)SwipeView.this.mScrolledPixelsX/(float)SwipeView.this.mFocusedViewWidth; 
         if(alpha > 0.0F) { 
          SwipeView.this.mFocusedViewNope.setVisibility(0); 
          SwipeView.this.mFocusedViewLike.setVisibility(8); 
          SwipeView.setAlpha(SwipeView.this.mFocusedViewNope, SwipeView.this.mPreviousAlpha, alpha); 
          SwipeView.this.mPreviousAlpha = alpha; 
         } else { 
          SwipeView.this.mFocusedViewNope.setVisibility(8); 
          SwipeView.this.mFocusedViewLike.setVisibility(0); 
          SwipeView.setAlpha(SwipeView.this.mFocusedViewLike, SwipeView.this.mPreviousAlpha, -alpha); 
          SwipeView.this.mPreviousAlpha = -alpha; 
         } 
        } 

        return true; 
       } 
      }; 
      this.mContext = context; 
      this.mLikeResource = likeResource; 
      this.mNopeResource = nopeResource; 
      this.mOnCardSwipedListener = cardSwipeListener; 
      float density = this.getResources().getDisplayMetrics().density; 

      for(int gestureDetector = 0; gestureDetector < this.paddingX.length; ++gestureDetector) { 
       this.paddingX[gestureDetector] = (int)((float)this.paddingX[gestureDetector] * density); 
       this.paddingYTop[gestureDetector] = (int)((float)this.paddingYTop[gestureDetector] * density); 
       this.paddingYBottom[gestureDetector] = (int)((float)this.paddingYBottom[gestureDetector] * density); 
      } 

      final GestureDetector var7 = new GestureDetector(this.mContext, this.simpleOnGestureListener); 
      this.setOnTouchListener(new OnTouchListener() { 
       public boolean onTouch(View v, MotionEvent event) { 
        if(SwipeView.this.getChildCount() > 0) { 
         if(SwipeView.this.mScrollDirection != SwipeView.ScrollDirection.NONE) { 
          return false; 
         } else if(!SwipeView.this.enableTouchSwipe) { 
          return false; 
         } else { 
          var7.onTouchEvent(event); 
          switch(event.getAction()) { 
          case 0: 
           if(SwipeView.this.getChildCount() > 0) { 
            SwipeView.this.mFocusedView = SwipeView.this.getChildAt(SwipeView.this.getChildCount() - 1); 
            SwipeView.this.mFocusedViewLike = SwipeView.this.mFocusedView.findViewById(SwipeView.this.mLikeResource.intValue()); 
            SwipeView.this.mFocusedViewNope = SwipeView.this.mFocusedView.findViewById(SwipeView.this.mNopeResource.intValue()); 
            SwipeView.this.mFocusedViewWidth = SwipeView.this.mFocusedView.getWidth(); 
            SwipeView.this.mFocusedView.setPadding(SwipeView.this.paddingX[0], 0, SwipeView.this.paddingX[0], 0); 
           } 

           SwipeView.this.resetScrollingValues(); 
           break; 
          case 1: 
           SwipeView.this.alignCardsPadding(); 
           if(SwipeView.this.mScrolledPixelsX < 0) { 
            SwipeView.this.mScrollModeX = SwipeView.ScrollMode.LEFT; 
            SwipeView.this.mTotalScrolledX = -SwipeView.this.mScrolledPixelsX; 
           } else { 
            SwipeView.this.mScrollModeX = SwipeView.ScrollMode.RIGHT; 
            SwipeView.this.mTotalScrolledX = SwipeView.this.mScrolledPixelsX; 
           } 

           if(SwipeView.this.mScrolledPixelsY < 0) { 
            SwipeView.this.mScrollModeY = SwipeView.ScrollMode.BOTTOM; 
            SwipeView.this.mTotalScrolledY = -SwipeView.this.mScrolledPixelsY; 
           } else { 
            SwipeView.this.mScrollModeY = SwipeView.ScrollMode.TOP; 
            SwipeView.this.mTotalScrolledY = SwipeView.this.mScrolledPixelsY; 
           } 

           SwipeView.this.detectSwipe(); 
          } 

          return true; 
         } 
        } else { 
         return false; 
        } 
       } 
      }); 
     } 

     public void addCard(View view, int position) { 
      if(this.getChildCount() <= 3 && position < 3) { 
       LinearLayout viewLayout = new LinearLayout(this.mContext); 
       viewLayout.setLayoutParams(new LayoutParams(-1, -1)); 
       view.setLayoutParams(new LayoutParams(-1, -1)); 
       viewLayout.addView(view); 
       viewLayout.setPadding(this.paddingX[position], this.paddingYTop[position], this.paddingX[position], this.paddingYBottom[position]); 
       this.addView(viewLayout, 0); 
      } 

     } 

     public void removeFocusedCard() { 
      this.removeView(this.mFocusedView); 
      this.alignCardsPadding(); 
     } 

     private void alignCardsPadding() { 
      int i = 0; 

      for(int j = this.getChildCount() - 1; j >= 0; --j) { 
       this.getChildAt(j).setPadding(this.paddingX[i], this.paddingYTop[i], this.paddingX[i], this.paddingYBottom[i]); 
       ++i; 
      } 

      this.mScrollDirection = SwipeView.ScrollDirection.NONE; 
     } 

     private void resetScrollingValues() { 
      this.mPreviousAlpha = 0.0F; 
      this.mNeedToScrollX = 0; 
      this.mScrolledPixelsX = 0; 
      this.mTotalScrolledX = 0; 
      this.mNeedToScrollY = 0; 
      this.mScrolledPixelsY = 0; 
      this.mTotalScrolledY = 0; 
      this.mScrollLengthX = 5; 
      this.mScrollLengthY = 5; 
      this.mScrollModeX = SwipeView.ScrollMode.NONE; 
      this.mScrollModeY = SwipeView.ScrollMode.NONE; 
     } 

     public void resetFocuedView() { 
      if(this.getChildCount() > 0) { 
       View mFocusedView = this.getChildAt(this.getChildCount() - 1); 
       View mFocusedViewLike = mFocusedView.findViewById(this.mLikeResource.intValue()); 
       View mFocusedViewNope = mFocusedView.findViewById(this.mNopeResource.intValue()); 
       setAlpha(mFocusedViewLike, 0.0F, 0.0F); 
       setAlpha(mFocusedViewNope, 0.0F, 0.0F); 
       mFocusedView.scrollTo(0, 0); 
      } 

     } 

     private void detectSwipe() { 
      int imageHalf = this.mFocusedView.getWidth()/2; 
      this.mNeedToScrollX = this.mFocusedView.getWidth() - this.mTotalScrolledX; 
      if(this.mScrollDirection == SwipeView.ScrollDirection.NONE) { 
       if(this.mNeedToScrollX < imageHalf) { 
        this.mScrollDirection = SwipeView.ScrollDirection.OUT; 
       } else { 
        this.mScrollDirection = SwipeView.ScrollDirection.IN; 
        setAlpha(this.mFocusedViewLike, 0.0F, 0.0F); 
        setAlpha(this.mFocusedViewNope, 0.0F, 0.0F); 
       } 
      } 

      this.mScrollHandler.post(this.mScrollRunnable); 
     } 

     public void likeCard() { 
      if(this.getChildCount() > 0) { 
       this.mFocusedView = this.getChildAt(this.getChildCount() - 1); 
       this.mFocusedViewLike = this.mFocusedView.findViewById(this.mLikeResource.intValue()); 
       this.mFocusedViewNope = this.mFocusedView.findViewById(this.mNopeResource.intValue()); 
       if(this.mScrollDirection != SwipeView.ScrollDirection.NONE) { 
        return; 
       } 

       this.resetScrollingValues(); 
       this.mScrollDirection = SwipeView.ScrollDirection.OUT; 
       this.mScrollModeX = SwipeView.ScrollMode.LEFT; 
       this.mFocusedViewLike.setVisibility(0); 
       setAlpha(this.mFocusedViewLike, 0.0F, 1.0F); 
       this.detectSwipe(); 
      } 

     } 

     public void dislikeCard() { 
      if(this.getChildCount() > 0) { 
       this.mFocusedView = this.getChildAt(this.getChildCount() - 1); 
       this.mFocusedViewLike = this.mFocusedView.findViewById(this.mLikeResource.intValue()); 
       this.mFocusedViewNope = this.mFocusedView.findViewById(this.mNopeResource.intValue()); 
       if(this.mScrollDirection != SwipeView.ScrollDirection.NONE) { 
        return; 
       } 

       this.resetScrollingValues(); 
       this.mScrollDirection = SwipeView.ScrollDirection.OUT; 
       this.mScrollModeX = SwipeView.ScrollMode.RIGHT; 
       this.mFocusedViewNope.setVisibility(0); 
       setAlpha(this.mFocusedViewNope, 0.0F, 1.0F); 
       this.detectSwipe(); 
      } 

     } 

     public void setTouchable(boolean touchable) { 
      this.enableTouchSwipe = touchable; 
     } 

     public static void setAlpha(View view, float fromAlpha, float toAlpha) { 
      if(VERSION.SDK_INT < 11) { 
       AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha); 
       alphaAnimation.setDuration(0L); 
       alphaAnimation.setFillAfter(true); 
       view.startAnimation(alphaAnimation); 
      } else { 
       view.setAlpha(toAlpha); 
      } 

     } 

     public interface OnCardSwipedListener { 
      void onLikes(); 

      void onDisLikes(); 

      void onSingleTap(); 
     } 

     private static enum ScrollDirection { 
      IN, 
      OUT, 
      NONE; 

      private ScrollDirection() { 
      } 
     } 

     private static enum ScrollMode { 
      LEFT, 
      RIGHT, 
      TOP, 
      BOTTOM, 
      NONE; 

      private ScrollMode() { 
      } 
     } 
    } 

試み#3 のためにこれを使用しています

FrameLayout view = (FrameLayout)findViewById(R.id.contentLayout); 
view.setDrawingCacheEnabled(true); 
view.buildDrawingCache(); 
Bitmap bitmap = view.getDrawingCache(); 
+0

こんにちはカレン、私が表示しようとしている 画像は「contentLayout」です。私は新しいフォルダ内のcontentLayoutの中にイメージを置いて、保存されたイメージが新しい名前を取得し続けるようにforループを追加しました。 pic + i(増分値)+ .png。 –

+0

onLikesは10種類の画像に使用されます。画像が好きであるか右にスワイプされている場合、画像は自分のSDカードにpic- + i + .pngの名前で保存されます すべての画像が異なる名前になり、1を超える保存が可能です画像。 (私もタイムスタンプでこれを試して、それは正常に動作します)。 もっとコードを表示しますが、実際に表示されている画像(保存したい画像)ではなく、表示される画像が保存されるようなものを押した場合を除き、すべて正常に機能します –

+0

あなたのコードを誤解して申し訳ありません。私は今理解し、私の長年の無関係なコメントを削除しました!より多くのコードを投稿してくれてありがとうございました。私の答えを見て、それが助けてくれたらお知らせください:) –

答えて

0

私はあなたが保存しようとしている画像が原因ライブラリコードにonSwipe時に除去なっていると信じて:私が試したが、私は同じ結果を得続ける(私がやっていること以下のコメントを読んで、コード。あなたがコードをに移動する前に、のonLikeが呼び出される必要があると思います。

あなたはまた、むしろここに指名手配ImageViewのよりも、全体のレイアウトのキャッシュからビットマップを取得しようとしている:

bm=contentLayout.getDrawingCache(); 

ビューとして現在のカードビューを取得したいと思います、そして、あなたのコードの私の理解から、期待されるビットマップを含むあなたの実際のImageViewののIDはR.id.imgMealsですので、私のライン交換をお勧め:

bm=contentLayout.getDrawingCache(); 

のWi次番目:

ImageView imageView = (ImageView) cardView.findViewById(R.id.imgMeals); 
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); 
Bitmap bm = drawable.getBitmap(); 

移動私は//ここをマークしているとあなたは、それを持っているところから、以下のコードのすべての !!コードの次の部分に(または、新しいメソッドに移動して、ここでメソッドを呼び出す方がよい)。

// If the imageview of like is clicked 
case R.id.imgLike: { 
    // HERE!! 

    // The imageview in the contentlayout will be swiped to the right 
    mSwipeView.likeCard(); 
    break; 
} 

これは私にはコードですが、私は上記の言及の変更を含む移動:

View cardView = mSwipeView.getChildAt(mSwipeView.getChildCount() - 1); 
    ImageView imageView = (ImageView) cardView.findViewById(R.id.imgMeals); 
    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); 
    Bitmap bm = drawable.getBitmap(); 

    OutputStream fOut = null; 
    try { 
     // Save on my sd card 
     File root = new File(Environment.getExternalStorageDirectory() 
       // Making a folder name Food Inspiration 
       + File.separator + "Food Inspiration" + File.separator); 
     root.mkdirs(); 
     File sdImageMainDirectory = null; 

     // Loop for having a different name for every image 
     int i = 0; 
     do { 
      sdImageMainDirectory = new File(root, "pic-" + i + ".png"); 
      i++; 
     } while (sdImageMainDirectory.exists()); 
     fOut = new FileOutputStream(sdImageMainDirectory); 

     // Updates the gallery of your phone with the folder and the "liked" images in it 
     MediaScannerConnection.scanFile(this, new String[] { sdImageMainDirectory.getAbsolutePath() }, null, null); 

     // If something goes wrong 
    } catch (Exception e) { 
     Toast.makeText(this, "Error occured. Please try again later.", 
       Toast.LENGTH_SHORT).show(); 
    } 
    // Compresses the actual bitmap image 
    try { 
     bm.compress(Bitmap.CompressFormat.PNG, 100, fOut); 
     fOut.flush(); 
     fOut.close(); 
    } catch (Exception e){} 
+0

私はあなたのコードを実装しようとしました。しかし、カードビューは、 ImageView imageView =(ImageView)cardView.findViewById(R.id.imgMeals); が赤く表示されます。これは初期化されていないためですか?もしそうなら、私はこれをどのように初期化すべきですか? –

+0

申し分なく、 はい、本当にライブラリを使用しています。私は図書館で自分の投稿を更新しました。 onLikesまたはaddCardを検索すると、その動作を確認できます。 ご不明な点がありましたら、できるだけ早く返信いたします:) –

+0

申し訳ありません! 私はベストを尽くします!あなたの時間と労力に感謝します:) 私は私が試したもので戻ってきます、そして、もし私が正しい方向に向かっているかどうかを私に教えてください。 –

関連する問題