Ejemplo n.º 1
0
 public void onImageBitmapSet() {
   int imageWidth = mResultImageView.getDrawable().getIntrinsicWidth();
   int imageHeight = mResultImageView.getDrawable().getIntrinsicHeight();
   Matrix m = mResultImageView.getImageMatrix();
   RectF drawableRect = new RectF(0, 0, imageWidth, imageHeight);
   RectF viewRect =
       new RectF(
           0,
           0,
           ((View) mResultImageView.getParent()).getWidth(),
           ((View) mResultImageView.getParent()).getHeight());
   m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
   mResultImageView.setImageMatrix(m);
   mResultImageView.invalidate();
   mMatrix = m;
   Log.d(TAG, "init mMatrix: " + mMatrix.toString());
   Log.d(
       TAG,
       "init, imagehview: " + mResultImageView.getDrawable().toString() + " w: " + imageWidth);
   Log.d(TAG, "init, imageheight: " + imageHeight + " w: " + imageWidth);
   Log.d(
       TAG,
       "init, viewheight: "
           + ((View) mResultImageView.getParent()).getHeight()
           + " w: "
           + ((View) mResultImageView.getParent()).getWidth());
   if (progressDialog != null) {
     progressDialog.dismiss();
   }
 }
Ejemplo n.º 2
0
 @Override
 protected void onPreExecute() {
   if (imageViewReference != null) {
     ImageView imageView = imageViewReference.get();
     if (imageView != null
         && imageView.getParent() != null
         && imageView.getParent() instanceof ViewGroup
         && ((ViewGroup) imageView.getParent()).getChildAt(2) != null
         && ((ViewGroup) imageView.getParent()).getChildAt(2) instanceof ProgressBar)
       ((ViewGroup) imageView.getParent()).getChildAt(2).setVisibility(View.VISIBLE);
   }
   super.onPreExecute();
 }
Ejemplo n.º 3
0
  @Override
  public void onDrag(float dx, float dy) {
    if (mScaleDragDetector.isScaling()) {
      return; // Do not drag if we are already scaling
    }

    if (DEBUG) {
      LogManager.getLogger().d(LOG_TAG, String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy));
    }

    ImageView imageView = getImageView();
    mSuppMatrix.postTranslate(dx, dy);
    checkAndDisplayMatrix();

    /**
     * Here we decide whether to let the ImageView's parent to start taking over the touch event.
     *
     * <p>First we check whether this function is enabled. We never want the parent to take over if
     * we're scaling. We then check the edge we're on, and the direction of the scroll (i.e. if
     * we're pulling against the edge, aka 'overscrolling', let the parent take over).
     */
    ViewParent parent = imageView.getParent();
    if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) {
      if (mScrollEdge == EDGE_BOTH
          || (mScrollEdge == EDGE_LEFT && dx >= 1f)
          || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
        if (null != parent) parent.requestDisallowInterceptTouchEvent(false);
      }
    } else {
      if (null != parent) {
        parent.requestDisallowInterceptTouchEvent(true);
      }
    }
  }
  protected void performWatchedToggle() {
    View posterLayout = (View) vciv.getParent();
    posterLayout.findViewById(R.id.posterInprogressIndicator).setVisibility(View.INVISIBLE);

    toggleGraphicIndicators(posterLayout);
    info.toggleWatchStatus();
  }
Ejemplo n.º 5
0
 private void moveSearchIconFromBeginToEnd(SearchView searchView) {
   ImageView searchIcon =
       (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
   ViewGroup parent = (ViewGroup) searchIcon.getParent();
   parent.removeView(searchIcon);
   parent.addView(searchIcon);
 }
Ejemplo n.º 6
0
  public final void onDrag(float dx, float dy) {
    if (DEBUG) {
      Log.d(LOG_TAG, String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy));
    }

    ImageView imageView = getImageView();

    if (null != imageView && hasDrawable(imageView)) {
      mSuppMatrix.postTranslate(dx, dy);
      checkAndDisplayMatrix();

      /**
       * Here we decide whether to let the ImageView's parent to start taking over the touch event.
       *
       * <p>First we check whether this function is enabled. We never want the parent to take over
       * if we're scaling. We then check the edge we're on, and the direction of the scroll (i.e. if
       * we're pulling against the edge, aka 'overscrolling', let the parent take over).
       */
      if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling()) {
        if (mScrollEdge == EDGE_BOTH
            || (mScrollEdge == EDGE_LEFT && dx >= 1f)
            || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
          imageView.getParent().requestDisallowInterceptTouchEvent(false);
        }
      }
    }
  }
Ejemplo n.º 7
0
  private void TimerOnFinish() {
    // Sync threads !!
    CurrentGame.AcquireLOCK();

    isAnimating = true;
    SecondsLeft_TimeTrial = 0;
    CurrentGame.SetGameInfoText();

    CurrentGame.Btn_Power.setEnabled(false);
    SetEnableControls(false, CurrentGame.GameBoard);

    ImageView[] availableCards = new ImageView[CurrentGame.RowSize * CurrentGame.ColumnSize];
    int length = GetAvailableCards(availableCards);
    if (length == 1) {
      TransitionDrawable cross_fade =
          CreateTransitionDrawable(
              R.drawable.lock, R.drawable.card_destroyed, CurrentGame.mContext);
      ImageView card = availableCards[0];
      card.getParent().requestChildFocus(card, card);
      card.setOnClickListener(null);
      card.setImageDrawable(cross_fade);
      cross_fade.startTransition(800);
      new CountDownTimer(800, 800) {
        @Override
        public void onTick(long milliSecondsToFinish) {}

        @Override
        public void onFinish() {
          // Sync threads !!
          CurrentGame.AcquireLOCK();

          CurrentGame.GameTimer.cancel();
          CurrentGame.postGameLogic();
          SetEnableControls(true, CurrentGame.GameBoard);
          CurrentGame.Btn_Power.setEnabled(true);

          // Sync threads !!
          CurrentGame.ReleaseLOCK();
          isAnimating = false;
        }
      }.start();

    } else if (length == 2) {
      ShuffleCards(availableCards, length);
    } else if (length > 2) {
      if (CurrentGame.EffectiveClickCount % 2 == 0
          && Math.random() <= .75) // Replace card 75% time for first card
      {
        ImageView[] selected_cards = SelectCardsRandomly(availableCards, length, POW_REPLACE);
        ReplaceCards(selected_cards, selected_cards.length);
      } else {
        ImageView[] selected_cards = SelectCardsRandomly(availableCards, length, POW_SHUFFLE);
        ShuffleCards(selected_cards, selected_cards.length);
      }
    }

    // Sync threads !!
    CurrentGame.ReleaseLOCK();
  }
Ejemplo n.º 8
0
  @Override
  public void destroyItem(View container, int position, Object object) {
    ViewPicWrapper wrapper = (ViewPicWrapper) object;
    ImageView imageView = (wrapper).imageView;
    View parent = (View) imageView.getParent();

    mActiveRequesters.remove(wrapper);
    ContentHandler.getInstance().removeRequester(wrapper);
    ((ViewPager) container).removeView(parent);
  }
Ejemplo n.º 9
0
    @Override
    protected void onPostExecute(Bitmap bitmap) {

      if (!destroyed) {
        if (isCancelled()) {
          bitmap = null;
        }
        if (imageViewReference != null && bitmap != null) {
          final ImageView imageView = imageViewReference.get();
          if (imageView != null) {
            imageView.setImageBitmap(bitmap);
            if (imageView.getParent() != null
                && imageView.getParent() instanceof ViewGroup
                && ((ViewGroup) imageView.getParent()).getChildAt(2) != null
                && ((ViewGroup) imageView.getParent()).getChildAt(2) instanceof ProgressBar) {
              ((ViewGroup) imageView.getParent()).getChildAt(2).setVisibility(View.GONE);
            }
          }
        }
      }
    }
 /** 监听ListView滑动 */
 @Override
 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
   super.onScrollChanged(l, t, oldl, oldt);
   // 获得ImageView的父控件
   View header = (View) mImageView.getParent();
   if (header.getTop() < 0 && mImageView.getHeight() > mImageViewHeight) {
     // 减小ImageView的高度 -- 不能超过图片最原始的高度
     mImageView.getLayoutParams().height =
         Math.max(mImageView.getHeight() + header.getTop(), mImageViewHeight);
     // ImageView所在的容器的高度也要变化:getTop--->0
     header.layout(header.getLeft(), 0, header.getRight(), header.getHeight());
     mImageView.requestLayout();
   }
 }
Ejemplo n.º 11
0
	@Override
	public void doChange(int lastIndex, int currentIndex) {
		if (lastIndex != currentIndex) {
			TranslateAnimation animation = null;
			LinearLayout layout = null;
			switch (currentIndex) {
			case 0:
				if (lastIndex == 1) {
					layout = (LinearLayout) tab1.getParent();
					animation = new TranslateAnimation(0, -layout.getWidth(),
							0, 0);
				} else if (lastIndex == 2) {
					layout = (LinearLayout) tab2.getParent();
					animation = new TranslateAnimation(layout.getLeft(),
							-((LinearLayout) tab1.getParent()).getWidth(), 0, 0);
				}
				break;
			case 1:
				if (lastIndex < 1) {
					layout = (LinearLayout) tab1.getParent();
					animation = new TranslateAnimation(-layout.getWidth(), 0,
							0, 0);
				} else if (lastIndex > 1) {
					layout = (LinearLayout) tab2.getParent();
					animation = new TranslateAnimation(layout.getLeft(), 0, 0,
							0);
				}
				break;
			case 2:
				if (lastIndex == 1) {
					layout = (LinearLayout) tab2.getParent();
					animation = new TranslateAnimation(0, layout.getLeft(), 0,
							0);
				} else if (lastIndex == 0) {
					layout = (LinearLayout) tab2.getParent();
					animation = new TranslateAnimation(
							-((LinearLayout) tab1.getParent()).getWidth(),
							layout.getLeft(), 0, 0);
				}
				break;
			}
			animation.setDuration(300);
			animation.setFillAfter(true);
			imageView.startAnimation(animation);
		}
	}
Ejemplo n.º 12
0
  private void updateTopButton(int scrollY) {

    if (actionButton != null && portrait && isActionButtonVisible()) {
      double scale = mapActivity.getResources().getDisplayMetrics().density;
      int originalPosition = mFlexibleSpaceImageHeight - (int) (80 * scale);
      int minTop = mFlexibleBlurSpaceHeight + (int) (5 * scale);
      FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) actionButton.getLayoutParams();
      if (minTop > originalPosition - scrollY) {
        hideActionButton();
      } else {
        actionButton.setVisibility(View.VISIBLE);
        lp.topMargin = originalPosition - scrollY;
        ((FrameLayout) actionButton.getParent()).updateViewLayout(actionButton, lp);
      }
    }
  }
Ejemplo n.º 13
0
  // sets up database on first open
  // or initialize stone positions based on database data
  private void initializeStones() {
    if (dbHandler.isEmpty()) {
      Log.d("V", "filling up table");
      FrameLayout b0 = (FrameLayout) findViewById(R.id.b0);
      FrameLayout t1 = (FrameLayout) findViewById(R.id.t1);
      FrameLayout t2 = (FrameLayout) findViewById(R.id.t2);
      FrameLayout t3 = (FrameLayout) findViewById(R.id.t3);
      FrameLayout b4 = (FrameLayout) findViewById(R.id.b4);
      FrameLayout b5 = (FrameLayout) findViewById(R.id.b5);
      FrameLayout t6 = (FrameLayout) findViewById(R.id.t6);
      FrameLayout t7 = (FrameLayout) findViewById(R.id.t7);
      FrameLayout t8 = (FrameLayout) findViewById(R.id.t8);
      FrameLayout b9 = (FrameLayout) findViewById(R.id.b9);
      FrameLayout b10 = (FrameLayout) findViewById(R.id.b10);
      FrameLayout t11 = (FrameLayout) findViewById(R.id.t11);
      FrameLayout t12 = (FrameLayout) findViewById(R.id.t12);
      FrameLayout t13 = (FrameLayout) findViewById(R.id.t13);
      FrameLayout b14 = (FrameLayout) findViewById(R.id.b14);
      dbHandler.addStone("" + b0.getId());
      dbHandler.addStone("" + t1.getId());
      dbHandler.addStone("" + t2.getId());
      dbHandler.addStone("" + t3.getId());
      dbHandler.addStone("" + b4.getId());
      dbHandler.addStone("" + b5.getId());
      dbHandler.addStone("" + t6.getId());
      dbHandler.addStone("" + t7.getId());
      dbHandler.addStone("" + t8.getId());
      dbHandler.addStone("" + b9.getId());
      dbHandler.addStone("" + b10.getId());
      dbHandler.addStone("" + t11.getId());
      dbHandler.addStone("" + t12.getId());
      dbHandler.addStone("" + t13.getId());
      dbHandler.addStone("" + b14.getId());
    }

    for (int i = 1; i <= numofstones; i++) {
      String ispot = dbHandler.getSpot(i);
      int spotid = Integer.parseInt(ispot);
      FrameLayout spot = (FrameLayout) findViewById(spotid);
      ImageView currentStone = allStones[i - 1];
      FrameLayout parent = (FrameLayout) currentStone.getParent();
      parent.removeView(currentStone);
      spot.addView(currentStone);
      currentStone.setVisibility(View.VISIBLE);
    }
  }
Ejemplo n.º 14
0
        public boolean onDrag(View v, DragEvent event) {
          int dragEvent = event.getAction();

          switch (dragEvent) {
            case DragEvent.ACTION_DRAG_STARTED:
              View draggedView = (View) event.getLocalState();
              draggedView.setVisibility(View.INVISIBLE);
              break;
            case DragEvent.ACTION_DRAG_ENTERED:
              Log.i("Drag Event", "Entered");
              break;
            case DragEvent.ACTION_DRAG_EXITED:
              Log.i("Drag Event", "Exited");
              break;
            case DragEvent.ACTION_DROP:
              Log.i("Drag Event", "Dropped");
              ImageView view = (ImageView) event.getLocalState();
              ViewGroup owner = (ViewGroup) view.getParent();
              FrameLayout container = (FrameLayout) v;
              if ((container.getChildCount() > 0)) {
                Log.d("V", "Already stone in spot");
                view.setVisibility(view.VISIBLE);
              } else {
                owner.removeView(view);
                Stone thisstone = (Stone) view.getTag();
                int id = thisstone.get_id();
                int spot = container.getId();
                dbHandler.update(id, spot);
                container.addView(view);
                view.setVisibility(View.VISIBLE);
                Log.d("V", "drop success");
              }
              break;
            case DragEvent.ACTION_DRAG_ENDED:
              ImageView oldview = (ImageView) event.getLocalState();
              oldview.setVisibility(oldview.VISIBLE);
              break;
            default:
              break;
          }
          return true;
        }
Ejemplo n.º 15
0
 public final cf.a f(View paramView, boolean paramBoolean) {
   super.aB(paramView);
   dkB = ((TextView) paramView.findViewById(a.i.chatting_time_tv));
   cLx = ((EmojiView) paramView.findViewById(a.i.chatting_content_iv));
   doF = ((CheckBox) paramView.findViewById(a.i.chatting_checkbox));
   fxt = paramView.findViewById(a.i.chatting_maskview);
   if (paramBoolean) {
     eYr = ((TextView) paramView.findViewById(a.i.chatting_user_tv));
     type = 14;
   }
   for (; ; ) {
     if (iRD != null) {
       ((ViewGroup) iRD.getParent()).setBackgroundDrawable(null);
     }
     return this;
     ewK = ((ProgressBar) paramView.findViewById(a.i.uploading_pb));
     eYr = ((TextView) paramView.findViewById(a.i.chatting_user_tv));
     iRN = ((ImageView) paramView.findViewById(a.i.chatting_state_iv));
     type = 15;
     iRF = ((ImageView) paramView.findViewById(a.i.chatting_status_tick));
   }
 }
Ejemplo n.º 16
0
  private void setImageFromUrlOrDisk(
      final String url,
      final ImageView imageView,
      final String type,
      int width,
      int height,
      boolean useDiskCache) {

    if (cancelPotentialWork(url, imageView)) {

      GetImage task = new GetImage(url, imageView, width, height, useDiskCache, type);
      final AsyncDrawable asyncDrawable =
          new AsyncDrawable(getResources(), zapp.cache.get(url + type), task);
      imageView.setImageDrawable(asyncDrawable);
      if (imageView.getParent() != null
          && imageView.getParent() instanceof ViewGroup
          && ((ViewGroup) imageView.getParent()).getChildAt(2) != null
          && ((ViewGroup) imageView.getParent()).getChildAt(2) instanceof ProgressBar) {
        ((ViewGroup) imageView.getParent()).getChildAt(2).setVisibility(View.GONE);
      }
      if (zapp.cache.get(url + type) == null) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, 1L);
      } else if (imageView != null
          && imageView.getDrawable() != null
          && ((BitmapDrawable) imageView.getDrawable()).getBitmap() != null) {
        imageView.setBackgroundResource(0);
        Bitmap blurBitmap = null;
        if (imageView.getParent() != null
            && imageView.getParent() instanceof ViewGroup
            && ((ViewGroup) imageView.getParent()).getChildAt(2) != null
            && ((ViewGroup) imageView.getParent()).getChildAt(2) instanceof ProgressBar) {
          ((ViewGroup) imageView.getParent()).getChildAt(2).setVisibility(View.GONE);
        }
      }
    }
  }
Ejemplo n.º 17
0
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
      // 对ViewPager页号求模取出View列表中要显示的项
      position %= viewlist.size();
      if (position < 0) {
        position = viewlist.size() + position;
      }
      ImageView view = viewlist.get(position);

      mCircleIndicatorView.setCircleCount(mViewPageNum);
      mCircleIndicatorView.setCircleSelectedPosition(position);
      mCircleIndicatorView.drawCircleView();

      // 如果View已经在之前添加到了一个父组件,则必须先remove,否则会抛出IllegalStateException。
      ViewParent vp = view.getParent();
      if (vp != null) {
        ViewGroup parent = (ViewGroup) vp;
        parent.removeView(view);
      }
      container.addView(view);
      // add listeners here if necessary
      return view;
    }
  private void refreshViews(Cursor cursor) {
    if (!cursor.moveToFirst()) return;

    // check whether or not to show the edit button
    String state = cursor.getString(cursor.getColumnIndex("uploadState"));
    mIsLocal = MediaUtils.isLocalFile(state);
    if (mIsLocal && getActivity() != null) {
      getActivity().invalidateOptionsMenu();
    }

    // title
    mTitleView.setText(cursor.getString(cursor.getColumnIndex("title")));

    // caption
    String caption = cursor.getString(cursor.getColumnIndex("caption"));
    if (caption == null || caption.length() == 0) {
      mCaptionView.setVisibility(View.GONE);
    } else {
      mCaptionView.setText(caption);
      mCaptionView.setVisibility(View.VISIBLE);
    }

    // description
    String desc = cursor.getString(cursor.getColumnIndex("description"));
    if (desc == null || desc.length() == 0) {
      mDescriptionView.setVisibility(View.GONE);
    } else {
      mDescriptionView.setText(desc);
      mDescriptionView.setVisibility(View.VISIBLE);
    }

    // added / upload date
    String date = MediaUtils.getDate(cursor.getLong(cursor.getColumnIndex("date_created_gmt")));
    if (mIsLocal) {
      mDateView.setText("Added on: " + date);
    } else {
      mDateView.setText("Uploaded on: " + date);
    }

    // file name
    String fileName = cursor.getString(cursor.getColumnIndex("fileName"));
    mFileNameView.setText("File name: " + fileName);

    // get the file extension from the fileURL
    String fileURL = cursor.getString(cursor.getColumnIndex("fileURL"));
    if (fileURL != null) {
      String fileType = fileURL.replaceAll(".*\\.(\\w+)$", "$1").toUpperCase();
      mFileTypeView.setText("File type: " + fileType);
      mFileTypeView.setVisibility(View.VISIBLE);
    } else {
      mFileTypeView.setVisibility(View.GONE);
    }

    String imageUri = cursor.getString(cursor.getColumnIndex("fileURL"));
    if (imageUri == null) imageUri = cursor.getString(cursor.getColumnIndex("filePath"));

    inflateImageView();

    // image and dimensions
    if (MediaUtils.isValidImage(imageUri)) {
      int width = cursor.getInt(cursor.getColumnIndex("width"));
      int height = cursor.getInt(cursor.getColumnIndex("height"));

      float screenWidth;

      View parentView = (View) mImageView.getParent();

      // differentiating between tablet and phone
      if (this.isInLayout()) {
        screenWidth = parentView.getMeasuredWidth();
      } else {
        screenWidth = getActivity().getResources().getDisplayMetrics().widthPixels;
      }
      float screenHeight = getActivity().getResources().getDisplayMetrics().heightPixels;

      if (width > 0 && height > 0) {
        String dimensions = width + "x" + height;
        mDimensionsView.setText("Dimensions: " + dimensions);
        mDimensionsView.setVisibility(View.VISIBLE);
      } else {
        mDimensionsView.setVisibility(View.GONE);
      }

      if (width > screenWidth) {
        height = (int) (height / (width / screenWidth));
        width = (int) screenWidth;
      } else if (height > screenHeight) {
        width = (int) (width / (height / screenHeight));
        height = (int) screenHeight;
      }

      if (mIsLocal) {
        final String filePath = cursor.getString(cursor.getColumnIndex("filePath"));
        loadLocalImage(mImageView, filePath, width, height);
      } else {
        // Allow non-private wp.com and Jetpack blogs to use photon to get a higher res thumbnail
        if (WordPress.getCurrentBlog() != null && WordPress.getCurrentBlog().isPhotonCapable()) {
          String thumbnailURL = StringUtils.getPhotonUrl(imageUri, (int) screenWidth);
          ((NetworkImageView) mImageView).setImageUrl(thumbnailURL, mImageLoader);
        } else {
          ((NetworkImageView) mImageView).setImageUrl(imageUri + "?w=" + screenWidth, mImageLoader);
        }
      }
      mImageView.setVisibility(View.VISIBLE);

      mImageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));

    } else {
      mImageView.setVisibility(View.GONE);
      mDimensionsView.setVisibility(View.GONE);
    }
  }
Ejemplo n.º 19
0
  private void ShuffleCards(final ImageView[] cardsToShuffle, final int length) {
    {
      int x[] = new int[length];
      int y[] = new int[length];
      AnimationSet swap_anim[] = new AnimationSet[length];

      for (int i = 0; i < length; i++) {
        View v = cardsToShuffle[i];
        int[] position = new int[2];
        v.getLocationOnScreen(position);
        x[i] = position[0];
        y[i] = position[1];
        ConfigureOutOfParentAnimation(v, true);
      }
      for (int i = 0; i < length - 1; i++) {
        int deltaX = x[i + 1] - x[i];
        int deltaY = y[i + 1] - y[i];
        swap_anim[i] = SwapAnimation(deltaX, deltaY);
      }
      swap_anim[length - 1] = SwapAnimation(x[0] - x[length - 1], y[0] - y[length - 1]);

      swap_anim[length - 1].setAnimationListener(
          new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
              // Sync threads !!
              CurrentGame.AcquireLOCK();

              int[] image_resource = new int[length];
              int lengthOfImageResource = length;
              int r, c;
              for (int i = 0; i < length; i++) {
                r = Integer.parseInt(cardsToShuffle[i].getTag().toString().split(DELIMITER)[0]);
                c = Integer.parseInt(cardsToShuffle[i].getTag().toString().split(DELIMITER)[1]);
                image_resource[i] = CurrentGame.Cards_ImageResID[r][c];
              }
              for (int i = 0; i < length; i++) {
                int random_index = ((int) (Math.random() * 1000)) % lengthOfImageResource;
                r = Integer.parseInt(cardsToShuffle[i].getTag().toString().split(DELIMITER)[0]);
                c = Integer.parseInt(cardsToShuffle[i].getTag().toString().split(DELIMITER)[1]);
                CurrentGame.Cards_ImageResID[r][c] = image_resource[random_index];
                lengthOfImageResource--;
                while (random_index < lengthOfImageResource)
                  image_resource[random_index] = image_resource[++random_index];
              }

              // Sync threads !!
              CurrentGame.ReleaseLOCK();
            }

            @Override
            public void onAnimationEnd(Animation animation) {
              // Sync threads !!
              CurrentGame.AcquireLOCK();

              SetEnableControls(true, CurrentGame.GameBoard);
              CurrentGame.Btn_Power.setEnabled(true);

              if (!CurrentGame.powFind_flag) // To sy
              TimeTrialTimer.start();

              // Sync threads !!
              CurrentGame.ReleaseLOCK();
              isAnimating = false;
            }

            @Override
            public void onAnimationRepeat(Animation animation) {}
          });

      for (int i = 0; i < length; i++) {
        ImageView card = cardsToShuffle[i];
        card.getParent().requestChildFocus(card, card);
        card.startAnimation(swap_anim[i]);
      }
    }
  }
Ejemplo n.º 20
0
  private void ReplaceCards(final ImageView[] cardsToReplace, final int length) {
    AnimationSet fade_out = RotateAndFadeOutAnimation();
    final AnimationSet fade_in = RotateAndFadeInAnimation();

    fade_out.setAnimationListener(
        new Animation.AnimationListener() {

          boolean flag;

          @Override
          public void onAnimationStart(Animation animation) {
            // Sync threads !!
            CurrentGame.AcquireLOCK();

            flag = true;
            int r, c;
            int imgResToReplace;
            int indexOfReplacement = 0;
            for (int i = 0; i < length; i++) {
              r = Integer.parseInt(cardsToReplace[i].getTag().toString().split(DELIMITER)[0]);
              c = Integer.parseInt(cardsToReplace[i].getTag().toString().split(DELIMITER)[1]);
              imgResToReplace = CurrentGame.Cards_ImageResID[r][c];

              int new_imageRes = CurrentGame.ReplacementCards[indexOfReplacement];
              CurrentGame.ReplacementCards[indexOfReplacement++] = imgResToReplace;
              ReplaceImageRes(imgResToReplace, new_imageRes);
            }

            // Sync threads !!
            CurrentGame.ReleaseLOCK();
          }

          @Override
          public void onAnimationEnd(Animation animation) {
            // Sync threads !!
            CurrentGame.AcquireLOCK();

            if (flag) {
              for (int i = 0; i < length; i++) cardsToReplace[i].startAnimation(fade_in);
            }
            flag = false;

            // Sync threads !!
            CurrentGame.ReleaseLOCK();
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}
        });

    fade_in.setAnimationListener(
        new Animation.AnimationListener() {
          @Override
          public void onAnimationStart(Animation animation) {}

          @Override
          public void onAnimationEnd(Animation animation) {
            // Sync threads !!
            CurrentGame.AcquireLOCK();

            for (int i = 0; i < length; i++) {
              cardsToReplace[i].setImageResource(R.drawable.lock);
            }
            SetEnableControls(true, CurrentGame.GameBoard);
            CurrentGame.Btn_Power.setEnabled(true);

            if (!CurrentGame.powFind_flag) TimeTrialTimer.start();

            // Sync threads !!
            CurrentGame.ReleaseLOCK();
            isAnimating = false;
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}
        });

    for (int i = 0; i < length; i++) {
      ImageView card = cardsToReplace[i];
      card.getParent().requestChildFocus(card, card);
      card.startAnimation(fade_out);
    }
  }