Android Open Source - nxt-remote-controller Progress Bar Circular Indeterminate






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;
/*w  w  w  .j a  v  a  2 s  .c o  m*/
import com.gc.materialdesign.utils.Utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.util.AttributeSet;

public class ProgressBarCircularIndeterminate extends CustomView {

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

  @Override
  protected void onInitDefaultValues() {
    // TODO ??????????
    minWidth = 32;
    minHeight = 32;
    backgroundColor = Color.parseColor("#1E88E5");
  }
  
  @Override
  protected void setAttributes(AttributeSet attrs) {
    // TODO ??????????
    super.setAttributes(attrs);
    float size = 4;// default ring width
    String width = attrs.getAttributeValue(MATERIALDESIGNXML, "ringWidth");
    doFirstAnimation = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "doFirstAnimation", true);
    if (width != null) {
      size = Utils.dipOrDpToFloat(width);
    }
    ringWidth = size;
  }

  /**
   * Make a dark color to ripple effect
   * 
   * @return
   */
  protected int makePressColor() {
    int r = (this.backgroundColor >> 16) & 0xFF;
    int g = (this.backgroundColor >> 8) & 0xFF;
    int b = (this.backgroundColor >> 0) & 0xFF;
    // r = (r+90 > 245) ? 245 : r+90;
    // g = (g+90 > 245) ? 245 : g+90;
    // b = (b+90 > 245) ? 245 : b+90;
    return Color.argb(128, r, g, b);
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (firstAnimationOver == false && doFirstAnimation == true)
      drawFirstAnimation(canvas);// ???????????
    if (cont > 0 || doFirstAnimation == false)
      drawSecondAnimation(canvas);// ???????
    invalidate();
  }

  private float radius1 = 0;
  private float radius2 = 0;
  private int cont = 0;
  private boolean firstAnimationOver = false;
  private boolean doFirstAnimation = true;
  private float ringWidth = 4;

  /**
   * Draw first animation of view
   * 
   * @param canvas
   */
  private void drawFirstAnimation(Canvas canvas) {
    if (radius1 < getWidth() / 2) {
      Paint paint = new Paint();
      paint.setAntiAlias(true);
      paint.setColor(makePressColor());
      radius1 = (radius1 >= getWidth() / 2) ? (float) getWidth() / 2 : radius1 + 1;
      canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius1, paint);
    } else {
      Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
      Canvas temp = new Canvas(bitmap);
      Paint paint = new Paint();
      paint.setAntiAlias(true);
      paint.setColor(makePressColor());
      temp.drawCircle(getWidth() / 2, getHeight() / 2, getHeight() / 2, paint);
      Paint transparentPaint = new Paint();
      transparentPaint.setAntiAlias(true);
      transparentPaint.setColor(getResources().getColor(android.R.color.transparent));
      transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
      if (cont >= 50) {
        radius2 = (radius2 >= getWidth() / 2) ? (float) getWidth() / 2 : radius2 + 1;
      } else {
        radius2 = (radius2 >= getWidth() / 2 - Utils.dpToPx(ringWidth, getResources())) ? 
            (float) getWidth() / 2 - Utils.dpToPx(ringWidth, getResources()) : radius2 + 1;
      }
      temp.drawCircle(getWidth() / 2, getHeight() / 2, radius2, transparentPaint);
      canvas.drawBitmap(bitmap, 0, 0, new Paint());
      if (radius2 >= getWidth() / 2 - Utils.dpToPx(ringWidth, getResources()))
        cont++;
      if (radius2 >= getWidth() / 2)
        firstAnimationOver = true;
    }
  }

  private int arcD = 1;
  private int arcO = 0;
  private float rotateAngle = 0;
  private int limite = 0;

  /**
   * Draw second animation of view
   * 
   * @param canvas
   */
  private void drawSecondAnimation(Canvas canvas) {
    if (arcO == limite)
      arcD += 6;
    if (arcD >= 290 || arcO > limite) {
      arcO += 6;
      arcD -= 6;
    }
    if (arcO > limite + 290) {
      limite = arcO;
      arcO = limite;
      arcD = 1;
    }
    rotateAngle += 4;
    canvas.rotate(rotateAngle, getWidth() / 2, getHeight() / 2);

    Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas temp = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(backgroundColor);
    // temp.drawARGB(0, 0, 0, 255);
    temp.drawArc(new RectF(0, 0, getWidth(), getHeight()), arcO, arcD, true, paint);
    Paint transparentPaint = new Paint();
    transparentPaint.setAntiAlias(true);
    transparentPaint.setColor(getResources().getColor(android.R.color.transparent));
    transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    temp.drawCircle(getWidth() / 2, getHeight() / 2, (getWidth() / 2) - Utils.dpToPx(ringWidth, getResources()), transparentPaint);

    canvas.drawBitmap(bitmap, 0, 0, new Paint());
  }

  // Set color of background
  public void setBackgroundColor(int color) {
    super.setBackgroundColor(getResources().getColor(android.R.color.transparent));
    if (isEnabled()) {
      beforeBackground = backgroundColor;
    }
    this.backgroundColor = color;
  }

    // Added by Egatuts
    public void setDoFirstAnimation (boolean value) {
        doFirstAnimation = value;
    }

    // Added by Egatuts
    public boolean getDoFirstAnimation () {
        return doFirstAnimation;
    }
  
  public void setRingWidth(float width) {
    ringWidth = width;
  }

}




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