Android Open Source - nxt-remote-controller Button Float






From Project

Back to project page nxt-remote-controller.

License

The source code is released under:

MIT License

If you think the Android project nxt-remote-controller listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gc.materialdesign.views;
//from  www  .j a  v a2s .c o m
import com.gc.materialdesign.R;
import com.gc.materialdesign.utils.Utils;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.view.ViewHelper;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * @author:Jack Tony
 * @tips :????????????sizeIcon = 24;sizeRadius = 28;
 * @date :2014-11-1
 */
public class ButtonFloat extends Button {

  protected int iconSize;// ???????
  protected int sizeRadius;// ??????

  ImageView icon; // ????ImageView 
  Drawable iconDrawable;// imageView??drawable

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

  @Override
  protected void onInitDefaultValues() {
    super.onInitDefaultValues();
    icon = new ImageView(getContext());
    iconSize = 24;
    sizeRadius = 28;
    rippleSpeed = 3;
    rippleSize = 5;
    minWidth = sizeRadius * 2;// 56dp
    minHeight = sizeRadius * 2;// 56dp
    backgroundResId = R.drawable.background_button_float;
  }

  @Override
  protected void onInitAttributes(AttributeSet attrs) {
    super.onInitAttributes(attrs);
    // ????????
    int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconDrawable",-1);
    if (iconResource != -1) {
      iconDrawable = getResources().getDrawable(iconResource);
    }

    // animation
    boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "animate", false);
    if (animate) {
      playAnimation();
    }
    
    if (iconDrawable != null) {
      icon.setBackgroundDrawable(iconDrawable);
    }
    // ???????????
    String size = attrs.getAttributeValue(MATERIALDESIGNXML, "iconSize");
    if (size != null) {
      iconSize = (int) Utils.dipOrDpToFloat(size);
    }
    setIconParams();
    addView(icon);
  }

  private void setIconParams() {
    // TODO ??????????
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        Utils.dpToPx(iconSize, getResources()), Utils.dpToPx(iconSize, getResources()));
    params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    icon.setLayoutParams(params);
  }
  
  /**
   * float??? 
   */
  private void playAnimation() {
    post(new Runnable() {
      @Override
      public void run() {
        float originalY = ViewHelper.getY(ButtonFloat.this) - Utils.dpToPx(24, getResources());
        ViewHelper.setY(ButtonFloat.this, 
            ViewHelper.getY(ButtonFloat.this) + getHeight() * 3);
        ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", originalY);
        animator.setInterpolator(new BounceInterpolator());
        animator.setDuration(1500);// ???????
        animator.start();
      }
    });
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (x != -1) {
      Rect src = new Rect(0, 0, getWidth(), getHeight());
      Rect dst = new Rect(Utils.dpToPx(1, getResources()), 
          Utils.dpToPx(2, getResources()), 
          getWidth() - Utils.dpToPx(1, getResources()), 
          getHeight() - Utils.dpToPx(2, getResources()));
      canvas.drawBitmap(cropCircle(makeCircle()), src, dst, null);
    }
    invalidate();
  }

  // ??????????????????
  public Bitmap cropCircle(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
        bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
  }

  // GET AND SET
  
  public void isAnimate(boolean isAnimate) {
    if (isAnimate) {
      playAnimation();
    }
  }
  
  public ImageView getIcon() {
    return icon;
  }
  
  public Drawable getIconDrawable() {
    return iconDrawable;
  }

  public void setIconDrawable(Drawable drawableIcon) {
    this.iconDrawable = drawableIcon;
    icon.setImageDrawable(drawableIcon);
  }

  /**
   * ??button????????????????? 
   * ??????????????????????????????????????????????
   * @param size
   */
  public void setIconSize(int size) {
    iconSize = size;
    setIconParams();
  }

  /**
   * @return ??????????
   */
  public int getIconSize() {
    return iconSize;
  }

  @Override
  @Deprecated
  public TextView getTextView() {
    // ????
    return null;
  }

}




Java Source Code List

.OldPadControllerFragment.java
com.andexert.library.ApplicationTest.java
com.andexert.library.RippleView.java
com.andexert.rippleeffect.ApplicationTest.java
com.andexert.rippleeffect.CustomAdapter.java
com.andexert.rippleeffect.MainActivity.java
com.andexert.rippleeffect.OnTapListener.java
com.gc.materialdesign.utils.Utils.java
com.gc.materialdesign.views.ButtonFlat.java
com.gc.materialdesign.views.ButtonFloatSmall.java
com.gc.materialdesign.views.ButtonFloat.java
com.gc.materialdesign.views.ButtonIcon.java
com.gc.materialdesign.views.ButtonRectangle.java
com.gc.materialdesign.views.Button.java
com.gc.materialdesign.views.Card.java
com.gc.materialdesign.views.CheckBox.java
com.gc.materialdesign.views.CustomView.java
com.gc.materialdesign.views.LayoutRipple.java
com.gc.materialdesign.views.ProgressBarCircularIndeterminate.java
com.gc.materialdesign.views.ProgressBarDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminate.java
com.gc.materialdesign.views.RippleView.java
com.gc.materialdesign.views.ScrollView.java
com.gc.materialdesign.views.Slider.java
com.gc.materialdesign.views.Switch.java
com.gc.materialdesign.widgets.ColorSelector.java
com.gc.materialdesign.widgets.Dialog.java
com.gc.materialdesign.widgets.SnackBar.java
git.egatuts.nxtremotecontroller.ApplicationTest.java
git.egatuts.nxtremotecontroller.GlobalUtils.java
git.egatuts.nxtremotecontroller.activity.ActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.BaseActivity.java
git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
git.egatuts.nxtremotecontroller.activity.DefaultActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.MainActivity.java
git.egatuts.nxtremotecontroller.activity.SettingsActivity.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothConstants.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothUtils.java
git.egatuts.nxtremotecontroller.bluetooth.NXTConnector.java
git.egatuts.nxtremotecontroller.device.PairedDeviceAdapter.java
git.egatuts.nxtremotecontroller.device.PairedDeviceItemClickListener.java
git.egatuts.nxtremotecontroller.device.PairedDeviceViewHolder.java
git.egatuts.nxtremotecontroller.device.PairedDevice.java
git.egatuts.nxtremotecontroller.exception.SocketCreationException.java
git.egatuts.nxtremotecontroller.fragment.ActivityBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BluetoothFragment.java
git.egatuts.nxtremotecontroller.fragment.ControllerBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.DefaultFragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.FragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.HomeFragment.java
git.egatuts.nxtremotecontroller.fragment.LocalControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.OnlineControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.ScanFragment.java
git.egatuts.nxtremotecontroller.fragment.SettingsFragment.java
git.egatuts.nxtremotecontroller.listener.AnimationEndListener.java
git.egatuts.nxtremotecontroller.listener.AppKillerListener.java
git.egatuts.nxtremotecontroller.listener.BaseListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothDiscoveryListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothEnableListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothPairingListener.java
git.egatuts.nxtremotecontroller.navigation.DrawerItemViewHolder.java
git.egatuts.nxtremotecontroller.navigation.DrawerItem.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerAdapter.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerCallback.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerFragment.java
git.egatuts.nxtremotecontroller.preference.PreferencesUtils.java
git.egatuts.nxtremotecontroller.receiver.AppKillerReceiver.java
git.egatuts.nxtremotecontroller.receiver.BaseReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothDiscoveryReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothEnableReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothPairingReceiver.java
git.egatuts.nxtremotecontroller.thread.BaseThread.java
git.egatuts.nxtremotecontroller.thread.ConnectThread.java
git.egatuts.nxtremotecontroller.thread.ConnectedThread.java
git.egatuts.nxtremotecontroller.views.BaseIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.BaseProgressDialog.java
git.egatuts.nxtremotecontroller.views.JoystickView.java
git.egatuts.nxtremotecontroller.views.LongIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.ShortIndeterminateProgressDialog.java