/** Config UI just one time */
  private void configUI() {
    setOrientation(LinearLayout.VERTICAL);
    setPadding(8, 8, 8, 8);

    TextView titleView = new TextView(ctx);
    titleView.setText(TEXT_TITLE);
    titleView.setTextColor(Color.LTGRAY);
    addView(titleView);

    LinearLayout subLayout = new LinearLayout(ctx);
    subLayout.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams subLayoutParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // configuring the iconView
    iconView.setImageDrawable(icon);
    LayoutParams icParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    icParams.gravity = Gravity.CENTER_VERTICAL;

    // configuring the msgView
    msgView.setText(msg);
    msgView.setPadding(10, 0, 0, 0);
    msgView.setTextSize(20);
    msgView.setTextColor(Color.WHITE);
    msgView.setGravity(Gravity.CENTER_VERTICAL);
    msgView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    msgView.setMaxLines(1);
    LayoutParams tvParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    subLayout.addView(iconView, icParams);
    subLayout.addView(msgView, tvParams);

    addView(subLayout, subLayoutParams);

    actionBtn.setText(TEXT_DELETE);
    actionBtn.setTextColor(Color.WHITE);
    addView(actionBtn, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    undoRedoLayout.setOrientation(LinearLayout.HORIZONTAL);
    undoView = new ImageView(ctx);
    redoView = new ImageView(ctx);
    undoView.setImageDrawable(DrawableFactory.build(ctx, DrawableFactory.ICON_UNDO));
    redoView.setImageDrawable(DrawableFactory.build(ctx, DrawableFactory.ICON_REDO));
    undoView.setClickable(true);
    redoView.setClickable(true);
    LayoutParams undoRedoParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    undoRedoParams.weight = 1;
    undoRedoLayout.addView(undoView, undoRedoParams);
    undoRedoLayout.addView(redoView, undoRedoParams);
    addView(undoRedoLayout);
  }
Ejemplo n.º 2
0
  @Override
  public void update(float timeDelta, BaseObject parent) {
    if (mRenderComponent != null) {
      final TimeSystem time = sSystemRegistry.timeSystem;
      final float currentTime = time.getGameTime();

      // Support repeating "phases" on top of the looping fade itself.
      // Complexity++, but it lets this component handle several
      // different use cases.
      if (mActivateTime == 0.0f) {
        mActivateTime = currentTime;
        mInitialDelayTimer = mInitialDelay;
      } else if (mPhaseDuration > 0.0f && currentTime - mActivateTime > mPhaseDuration) {
        mActivateTime = currentTime;
        mInitialDelayTimer = mInitialDelay;
        mStartTime = 0.0f;
      }

      if (mInitialDelayTimer > 0.0f) {
        mInitialDelayTimer -= timeDelta;
      } else {
        if (mStartTime == 0) {
          mStartTime = currentTime;
        }
        float elapsed = currentTime - mStartTime;
        float opacity = mInitialOpacity;
        if (mLoopType != LOOP_TYPE_NONE && elapsed > mDuration) {
          final float endTime = mStartTime + mDuration;
          elapsed = endTime - currentTime;
          mStartTime = endTime;
          if (mLoopType == LOOP_TYPE_PING_PONG) {
            float temp = mInitialOpacity;
            mInitialOpacity = mTargetOpacity;
            mTargetOpacity = temp;
          }
        }

        if (elapsed > mDuration) {
          opacity = mTargetOpacity;
        } else if (elapsed != 0.0f) {
          if (mFunction == FADE_LINEAR) {
            opacity = Lerp.lerp(mInitialOpacity, mTargetOpacity, mDuration, elapsed);
          } else if (mFunction == FADE_EASE) {
            opacity = Lerp.ease(mInitialOpacity, mTargetOpacity, mDuration, elapsed);
          }
        }

        if (mTexture != null) {
          // If a texture is set then we supply a drawable to the render component.
          // If not, we take whatever drawable the renderer already has.
          final DrawableFactory factory = sSystemRegistry.drawableFactory;
          if (factory != null) {
            GameObject parentObject = ((GameObject) parent);
            DrawableBitmap bitmap = factory.allocateDrawableBitmap();
            bitmap.resize((int) mTexture.width, (int) mTexture.height);
            // TODO: Super tricky scale.  fix this!
            bitmap.setWidth((int) parentObject.width);
            bitmap.setHeight((int) parentObject.height);
            bitmap.setOpacity(opacity);
            bitmap.setTexture(mTexture);
            mRenderComponent.setDrawable(bitmap);
          }
        } else {
          DrawableObject drawable = mRenderComponent.getDrawable();
          // TODO: ack, instanceof!  Fix this!
          if (drawable != null && drawable instanceof DrawableBitmap) {
            ((DrawableBitmap) drawable).setOpacity(opacity);
          }
        }
      }
    }
  }