Exemplo n.º 1
0
  @Override
  public void onClick(View arg0) {
    // If audio is playing then this is a pause button
    if (player.isPlaying()) {
      player.stop();
      setCompoundDrawablesWithIntrinsicBounds(playIcon, null, null, null);
    } else {
      // Set animated throbber
      setCompoundDrawablesWithIntrinsicBounds(animLoading, null, null, null);
      setEnabled(false);

      // Start animation
      animLoading.setOneShot(false);
      animLoading.start();

      try {
        if (cached) {
          onFetchCompleted(null, true);
        } else {
          int timeout = getContext().getResources().getInteger(R.integer.connection_timeout);
          FetchToFileTask audioFetchTask = new FetchToFileTask(cacheFile, timeout);
          audioFetchTask.setListener(this);
          audioFetchTask.execute(audioURL);
        }

      } catch (Exception e) {
        Dialogs.toast(getContext(), getContext().getString(R.string.err_communicationfailed));
      }
    }
  }
  private void initView(Context context) {
    // 初始情况,设置下拉刷新view高度为0
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0);
    mContainer =
        (LinearLayout) LayoutInflater.from(context).inflate(R.layout.xlistview_header, null);
    addView(mContainer, lp);
    setGravity(Gravity.BOTTOM);

    mArrowImageView = (ImageView) findViewById(R.id.xlistview_header_arrow);
    mHintTextView = (TextView) findViewById(R.id.xlistview_header_hint_textview);
    mProgressBar = (ImageView) findViewById(R.id.xlistview_header_progressbar);

    mRotateUpAnim =
        new RotateAnimation(
            0.0f, -180.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    mRotateUpAnim.setDuration(ROTATE_ANIM_DURATION);
    mRotateUpAnim.setFillAfter(true);
    mRotateDownAnim =
        new RotateAnimation(
            -180.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    mRotateDownAnim.setDuration(ROTATE_ANIM_DURATION);
    mRotateDownAnim.setFillAfter(true);

    mProgressBar.setImageResource(R.anim.loadmore_animation);
    animationDrawable = (AnimationDrawable) mProgressBar.getDrawable();
    animationDrawable.setOneShot(false);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_saomiao_layout);

    imageView = (ImageView) findViewById(R.id.imageView);
    imageView.setImageResource(R.drawable.image_values);
    animationDrawable = (AnimationDrawable) imageView.getDrawable();
    // 是否循环一次
    animationDrawable.setOneShot(false);
    animationDrawable.start();
    MyThread();
  }
  private AnimationDrawable getAnimation(Bitmap bitmap) {
    AnimationDrawable animation = new AnimationDrawable();
    animation.setOneShot(false);

    List<Bitmap> shiftedBitmaps = getShiftedBitmaps(bitmap);
    int duration = 50;

    for (Bitmap image : shiftedBitmaps) {
      BitmapDrawable navigationBackground = new BitmapDrawable(getResources(), image);
      navigationBackground.setTileModeX(TileMode.REPEAT);

      animation.addFrame(navigationBackground, duration);
    }
    return animation;
  }
Exemplo n.º 5
0
  /**
   * Create and return animation drawable
   *
   * @param assetsFramesPath Path to folder with animation frames relative to "assets" folder of
   *     android application
   * @param defaultDuration How long in milliseconds a single frame should appear
   * @param oneShot Play once (true) or repeat (false)
   * @return AnimationDrawable instance
   */
  public AnimationDrawable create(
      final String assetsFramesPath, final int defaultDuration, final boolean oneShot) {
    final List<String> files = assetUtil.getFileList(assetsFramesPath);
    final SortedMap<Integer, String> frames = frameUtil.extractFrames(files);

    final AnimationDrawable animationDrawable = new AnimationDrawable();
    animationDrawable.setOneShot(oneShot);

    for (final Integer key : frames.keySet()) {
      final Bitmap frame = BitmapFactory.decodeStream(assetUtil.open(frames.get(key)));
      animationDrawable.addFrame(new BitmapDrawable(frame), defaultDuration);
    }

    return animationDrawable;
  }
  /**
   * Convert a AnimationDrawable for use as a barberpole animation. Each frame of the animation is
   * wrapped in a ClipDrawable and given a tiling BitmapShader.
   */
  private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
      AnimationDrawable background = (AnimationDrawable) drawable;
      final int N = background.getNumberOfFrames();
      AnimationDrawable newBg = new AnimationDrawable();
      newBg.setOneShot(background.isOneShot());

      for (int i = 0; i < N; i++) {
        Drawable frame = tileify(background.getFrame(i), true);
        frame.setLevel(10000);
        newBg.addFrame(frame, background.getDuration(i));
      }
      newBg.setLevel(10000);
      drawable = newBg;
    }
    return drawable;
  }
Exemplo n.º 7
0
        @Override
        public void handleMessage(Message msg) {
          // TODO Auto-generated method stub
          // 朗读 (语音合成)
          if (msg.what == 0) {

            showFrame(1);
            animListen.setOneShot(false);

            if (msg.obj == null) {
              text = "您好,验光开始,请在三秒后说话。。。。。。";
              playSpeech(text);
            } else {
              text = (String) msg.obj;
              playSpeech(text);
            }
          }
          // 录音(语音识别)
          if (msg.what == 1) {
            setParam();
            boolean isShowDialog = true;
            // showFrame(2);
            if (isShowDialog) {
              // 显示听写对话框
              iatDialog.setListener(recognizerDialogListener);
              iatDialog.show();
            } else {
              // 不显示听写对话框
              ret = mIat.startListening(recognizerListener);
              if (ret != ErrorCode.SUCCESS) {
                Toast.makeText(RecodeActivity.this, "听写失败,错误码:" + ret, Toast.LENGTH_LONG).show();
              } else {
                Toast.makeText(RecodeActivity.this, "begin" + ret, Toast.LENGTH_LONG).show();
              }
            }
          }
        }
Exemplo n.º 8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent newint = getIntent();
    address =
        newint.getStringExtra(
            com.fast0n.majoranaopd.DeviceList
                .EXTRA_ADDRESS); // receive the address of the bluetooth device

    // view of the ledControl
    setContentView(R.layout.activity_main);

    // call the widgtes

    start = (Button) findViewById(R.id.button2);
    stop = (Button) findViewById(R.id.button3);
    color = (Button) findViewById(R.id.button4);

    switch1 = (Switch) findViewById(R.id.switch1);
    switch2 = (Switch) findViewById(R.id.switch2);

    prima = (ImageView) findViewById(R.id.imageView);
    seconda = (ImageView) findViewById(R.id.imageView2);
    terza = (ImageView) findViewById(R.id.imageView3);

    final Vibrator vibe = (Vibrator) MainActivity.this.getSystemService(Context.VIBRATOR_SERVICE);

    new ConnectBT().execute();

    BitmapDrawable frame0 = (BitmapDrawable) getResources().getDrawable(R.drawable.funon0);
    BitmapDrawable frame1 = (BitmapDrawable) getResources().getDrawable(R.drawable.funon1);
    BitmapDrawable frame2 = (BitmapDrawable) getResources().getDrawable(R.drawable.funon2);
    BitmapDrawable frame3 = (BitmapDrawable) getResources().getDrawable(R.drawable.funon3);
    BitmapDrawable frame4 = (BitmapDrawable) getResources().getDrawable(R.drawable.funon4);
    BitmapDrawable frame5 = (BitmapDrawable) getResources().getDrawable(R.drawable.funon5);
    BitmapDrawable frame6 = (BitmapDrawable) getResources().getDrawable(R.drawable.funon6);

    BitmapDrawable frame7 = (BitmapDrawable) getResources().getDrawable(R.drawable.motor0);
    BitmapDrawable frame8 = (BitmapDrawable) getResources().getDrawable(R.drawable.motor1);
    BitmapDrawable frame9 = (BitmapDrawable) getResources().getDrawable(R.drawable.motor2);
    BitmapDrawable frame10 = (BitmapDrawable) getResources().getDrawable(R.drawable.motor3);

    int reasonableDuration2 = 40;
    mframeAnimation2 = new AnimationDrawable();
    mframeAnimation2.setOneShot(false);
    mframeAnimation2.addFrame(frame7, reasonableDuration2);
    mframeAnimation2.addFrame(frame8, reasonableDuration2);
    mframeAnimation2.addFrame(frame9, reasonableDuration2);
    mframeAnimation2.addFrame(frame10, reasonableDuration2);
    terza.setBackgroundDrawable(mframeAnimation2);
    mframeAnimation2.setVisible(true, true);

    int reasonableDuration = 20;
    mframeAnimation = new AnimationDrawable();
    mframeAnimation.setOneShot(false);
    mframeAnimation.addFrame(frame0, reasonableDuration);
    mframeAnimation.addFrame(frame1, reasonableDuration);
    mframeAnimation.addFrame(frame2, reasonableDuration);
    mframeAnimation.addFrame(frame3, reasonableDuration);
    mframeAnimation.addFrame(frame4, reasonableDuration);
    mframeAnimation.addFrame(frame5, reasonableDuration);
    mframeAnimation.addFrame(frame6, reasonableDuration);
    seconda.setBackgroundDrawable(mframeAnimation);
    mframeAnimation.setVisible(true, true);

    switch1.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked) {

              prima.setImageResource(R.drawable.ledon);
              turnOnLed(); // method to turn off
            } else {
              prima.setImageResource(R.drawable.ledoff);
              turnOffLed(); // method to turn on
            }
          }
        });

    switch2.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked) {
              seconda.setImageResource(R.drawable.funon);
              turnOnFan(); // method to turn off
              mframeAnimation.start();

            } else {

              turnOffFan(); // method to turn on
              mframeAnimation.stop();
            }
          }
        });

    start.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mframeAnimation2.start();
            vibe.vibrate(50);
            turnOnMotor(); // close connection
            color.setBackgroundTintList(getResources().getColorStateList(R.color.start));
            terza.setImageResource(R.drawable.funon);
          }
        });

    stop.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            vibe.vibrate(50);
            turnOffMotor(); // close connection
            color.setBackgroundTintList(getResources().getColorStateList(R.color.stop));
            mframeAnimation2.stop();
          }
        });
  }