Exemplo n.º 1
0
 public void execute(View lastFocus, View nextFocus, boolean animation) {
   if (lastFocus == null || nextFocus == null) return;
   synchronized (control) {
     control.transformAnimation(mBackImageView, lastFocus, nextFocus, mContext, animation, true);
   }
   nextFocus.requestFocus();
 }
Exemplo n.º 2
0
public class AnimationTextButton extends RelativeLayout {
  private FocusFinder mFocusF = FocusFinder.getInstance();
  private AnimationControl control = AnimationControl.getInstance();

  private TextView mTextView;
  private Context mContext;
  private AnimationDrawable mAnimation;
  private ImageView mBackImageView; // move picture need config
  private boolean flag = true;

  public AnimationTextButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context);
  }

  public AnimationTextButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context);
  }

  public AnimationTextButton(Context context) {
    super(context);
    init(context);
  }

  private void init(Context context) {
    this.mContext = context;
    this.mTextView = new TextView(mContext);
    // some config
    setClickable(true);
    setFocusable(true);
    setGravity(Gravity.CENTER);
    mTextView.setTextSize(22);
    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    mTextView.setSelected(true);
    mTextView.setSingleLine(true);
    mTextView.setEllipsize(TruncateAt.MARQUEE);
    mTextView.setTransformationMethod(SingleLineTransformationMethod.getInstance());
    mTextView.setLayoutParams(params);
    mTextView.setTextColor(getResources().getColor(R.color.white));
    mTextView.getPaint().setFakeBoldText(true);
    addView(mTextView);
  }

  public void setBackImageViewff() {}

  public void setBackImageView(ImageView imageview) {
    this.mBackImageView = imageview;
  }

  public ImageView getBackImageView() {
    return this.mBackImageView;
  }

  public void setImageResource(int resId) {
    mTextView.setBackgroundResource(resId);
  }

  public void setText(String str) {
    mTextView.setText(str);
  }

  public boolean isFlag() {
    return flag;
  }

  public void setFlag(boolean flag) {
    this.flag = flag;
  }

  public boolean dispatchKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    int keyAction = event.getAction();
    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && keyAction == KeyEvent.ACTION_DOWN) return true;
    if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && keyAction == KeyEvent.ACTION_DOWN) {

      View lastFocusView = this;
      View nextFocus =
          mFocusF.findNextFocus((ViewGroup) this.getRootView(), lastFocusView, View.FOCUS_RIGHT);

      if (lastFocusView == null) return true;

      execute(lastFocusView, nextFocus, true);
      return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && keyAction == KeyEvent.ACTION_DOWN) {

      View lastFocusView = this;
      View nextFocus =
          mFocusF.findNextFocus((ViewGroup) this.getRootView(), lastFocusView, View.FOCUS_DOWN);

      if (lastFocusView == null) return true;

      execute(lastFocusView, nextFocus, true);
      return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP && keyAction == KeyEvent.ACTION_DOWN) {

      View lastFocusView = this;
      View nextFocus =
          mFocusF.findNextFocus((ViewGroup) this.getRootView(), lastFocusView, View.FOCUS_UP);

      if (lastFocusView == null) return true;

      execute(lastFocusView, nextFocus, true);
      return true;
    }

    return super.dispatchKeyEvent(event);
  }

  public void execute(View lastFocus, View nextFocus, boolean animation) {
    if (lastFocus == null || nextFocus == null) return;
    synchronized (control) {
      control.transformAnimation(mBackImageView, lastFocus, nextFocus, mContext, animation, true);
    }
    nextFocus.requestFocus();
  }

  //	@Override
  //	protected void onFocusChanged(boolean gainFocus, int direction,
  //			Rect previouslyFocusedRect) {
  //		super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
  //		if(gainFocus){
  //			if(mBackImageView!=null){
  //				synchronized (mBackImageView) {
  //					AnimationControl control = AnimationControl.getInstance();
  //					synchronized(control){
  //						if(flag){
  //							control.transformAnimationForImage(mBackImageView, this, mContext,true,false);
  //						}else{
  //							control.transformAnimation(mBackImageView, this, mContext,true,false);
  //						}
  //					}
  //
  //				}
  //			}
  //		}else{
  //		}
  //
  //	}

}
Exemplo n.º 3
0
  /** set range used for linear map from Scalar to DisplayScalar values */
  private synchronized void setRange(
      DataShadow shadow, double low, double hi, boolean unit_flag, int remoteId)
      throws VisADException, RemoteException {
    int i = ScalarIndex;
    if (shadow != null) {
      // WLH - 23 Sept 99
      if (DisplayScalar.equals(Display.Latitude) || DisplayScalar.equals(Display.Longitude)) {
        Unit data_unit = (Scalar instanceof RealType) ? ((RealType) Scalar).getDefaultUnit() : null;
        Unit display_unit = DisplayScalar.getDefaultUnit();
        if (data_unit != null && display_unit != null && Unit.canConvert(data_unit, display_unit)) {
          dataRange[0] = data_unit.toThis(displayRange[0], display_unit);
          dataRange[1] = data_unit.toThis(displayRange[1], display_unit);
        } else {
          if (i < 0 || i >= shadow.ranges[0].length) return;
          dataRange[0] = shadow.ranges[0][i];
          dataRange[1] = shadow.ranges[1][i];
        }
      } else {
        if (i < 0 || i >= shadow.ranges[0].length) return;
        dataRange[0] = shadow.ranges[0][i];
        dataRange[1] = shadow.ranges[1][i];
      }
    } else if (unit_flag) {
      Unit data_unit = (Scalar instanceof RealType) ? ((RealType) Scalar).getDefaultUnit() : null;
      Unit display_unit = DisplayScalar.getDefaultUnit();
      if (data_unit == null || display_unit == null) {
        throw new UnitException("ScalarMap.setRangeByUnits: null Unit");
      }
      dataRange[0] = data_unit.toThis(displayRange[0], display_unit);
      dataRange[1] = data_unit.toThis(displayRange[1], display_unit);
      /*
      System.out.println("data_unit = " + data_unit + " display_unit = " + display_unit);
      System.out.println("dataRange = " + dataRange[0] + " " + dataRange[1] +
      " displayRange = " + displayRange[0] + " " + displayRange[1]);
      */
    } else {
      dataRange[0] = low;
      dataRange[1] = hi;
      // WLH 31 Aug 2000
      // manual range is in overrideUnit. so convert to Scalar default Unit
      if (overrideUnit != null) {
        dataRange[0] = (dataRange[0] - override_offset) / override_scale;
        dataRange[1] = (dataRange[1] - override_offset) / override_scale;
      }
    }
    /*
    if (shadow != null || remoteId != VisADEvent.LOCAL_SOURCE) {
      System.out.println(Scalar + " -> " + DisplayScalar + " range: " + dataRange[0] +
                         " to " + dataRange[1] + " " + display.getName());
    }
    */
    // at this point dataRange is range for Scalar default Unit
    //   even if (overrideUnit != null)
    // DRM 17 Feb 2006 - so set the defaultUnitRange to be these values.
    defaultUnitRange[0] = dataRange[0];
    defaultUnitRange[1] = dataRange[1];
    if (defaultUnitRange[0] == defaultUnitRange[1]) {
      double half = defaultUnitRange[0] / 2000.0;
      if (half < 0.5) half = 0.5;
      defaultUnitRange[0] -= half;
      defaultUnitRange[1] += half;
    }

    if (isScaled) {
      computeScaleAndOffset();
    } else { // if (!isScaled)
      if (dataRange[0] == Double.MAX_VALUE || dataRange[1] == -Double.MAX_VALUE) {
        dataRange[0] = Double.NaN;
        dataRange[1] = Double.NaN;
      }

      // WLH 31 Aug 2000
      if (overrideUnit != null) {
        // now convert dataRange to overrideUnit
        dataRange[0] = defaultUnitRange[0] * override_scale + override_offset;
        dataRange[1] = defaultUnitRange[1] * override_scale + override_offset;
      }
    }
    /*
    System.out.println(Scalar + " -> " + DisplayScalar + " range: " + dataRange[0] +
                       " to " + dataRange[1] + " scale: " + scale + " " + offset);
    */
    if (DisplayScalar.equals(Display.Animation) && shadow != null) {
      if (control != null && ((AnimationControl) control).getComputeSet()) {
        Set set = shadow.animationSampling;
        /* DRM: 04 Jan 2003
        if (set == null) {
          return;
        }
        */
        ((AnimationControl) control).setSet(set, true);
      }
    } else if (DisplayScalar.equals(Display.IsoContour)) {
      if (control != null) {

        // WLH 10 July 2002
        // don't set if application has called control.setLevels()
        float[] lowhibase = new float[3];
        boolean[] dashes = new boolean[1];

        boolean public_set = ((ContourControl) control).getPublicSet();
        if (!public_set) {
          boolean[] bvalues = new boolean[2];
          float[] values = new float[5];
          ((ContourControl) control).getMainContours(bvalues, values);
          if (shadow == null) {
            // don't set surface value for auto-scale
            values[0] = (float) dataRange[0]; // surfaceValue
          }
          // CTR: 29 Jul 1999: interval should never be zero
          float f = (float) (dataRange[1] - dataRange[0]) / 10.0f;
          if (f != 0.0f) values[1] = f; // contourInterval
          values[2] = (float) dataRange[0]; // lowLimit
          values[3] = (float) dataRange[1]; // hiLimit
          values[4] = (float) dataRange[0]; // base
          ((ContourControl) control).setMainContours(bvalues, values, true, true);
        }
      }
    } else if (DisplayScalar.equals(Display.XAxis)
        || DisplayScalar.equals(Display.YAxis)
        || DisplayScalar.equals(Display.ZAxis)) {
      if (dataRange[0] != Double.MAX_VALUE
          && dataRange[1] != -Double.MAX_VALUE
          && dataRange[0] == dataRange[0]
          && dataRange[1] == dataRange[1]
          && dataRange[0] != dataRange[1]
          && scale == scale
          && offset == offset) {
        if (display != null) {
          makeScale();
        } else {
          scale_flag = true;
        }
        back_scale_flag = true;
      }
    }

    if (dataRange[0] == dataRange[0] && dataRange[1] == dataRange[1] && ListenerVector != null) {
      ScalarMapEvent evt;
      evt =
          new ScalarMapEvent(
              this, (shadow == null ? ScalarMapEvent.MANUAL : ScalarMapEvent.AUTO_SCALE), remoteId);
      Vector listeners_clone = null;
      synchronized (ListenerVector) {
        listeners_clone = (Vector) ListenerVector.clone();
      }
      Enumeration listeners = listeners_clone.elements();
      while (listeners.hasMoreElements()) {
        ScalarMapListener listener = (ScalarMapListener) listeners.nextElement();
        listener.mapChanged(evt);
      }
    }
  }