Android Open Source - nxt-remote-controller Progress Bar Determinate






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 w ww  .j a  v a  2  s  . c  o m
import com.gc.materialdesign.R;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

public class ProgressBarDeterminate extends CustomView {

  private int max = 100;
  private int min = 0;
  private int progress = 0;

  protected View progressView;

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

  @Override
  protected void onInitDefaultValues() {
    minWidth = 40;
    minHeight = 3;
    backgroundColor = Color.parseColor("#1E88E5");
  }

  // Set atributtes of XML to View
  @Override
  protected void setAttributes(AttributeSet attrs) {
    progressView = new View(getContext());
    RelativeLayout.LayoutParams params = new LayoutParams(1, 1);
    progressView.setLayoutParams(params);
    if (!isInEditMode()) {
      progressView.setBackgroundResource(R.drawable.background_progress);
    }
    addView(progressView);
    //super????view??????????setAttr?????????????view???????????null
    super.setAttributes(attrs);
    min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0);
    max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 100);
    progress = attrs.getAttributeIntValue(MATERIALDESIGNXML, "progress", min);

    post(new Runnable() {
      @Override
      public void run() {
        RelativeLayout.LayoutParams params = (LayoutParams) progressView.getLayoutParams();
        params.height = getHeight();
        progressView.setLayoutParams(params);
        //setProgress(progress);
      }
    });
  }

  // SETTERS

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (pendindProgress != -1)
      setProgress(pendindProgress);
  }

  public void setMax(int max) {
    this.max = max;
  }

  public int getMax() {
    return max;
  }
  
  public void setMin(int min) {
    this.min = min;
  }
  
  public int getMin() {
    return min;
  }
  
  private int pendindProgress = -1;

  public void setProgress(int progress) {
    this.progress = progress;
    if (getWidth() == 0) {
      pendindProgress = progress;
    } else {
      //this.progress = progress;
      if (progress > max)
        progress = max;
      if (progress < min)
        progress = min;
      int totalWidth = max - min;
      double progressPercent = (double) progress / (double) totalWidth;
      int progressWidth = (int) (getWidth() * progressPercent);
      RelativeLayout.LayoutParams params = (LayoutParams) progressView.getLayoutParams();
      params.width = progressWidth;
      params.height = getHeight();
      progressView.setLayoutParams(params);
      pendindProgress = -1;
    }
  }

  public int getProgress() {
    return progress;
  }

  // Set color of background
  public void setBackgroundColor(int color) {
    backgroundColor = color;
    if (!isInEditMode()) {
      if (isEnabled()) {
        beforeBackground = backgroundColor;
      }
      LayerDrawable layer = (LayerDrawable) progressView.getBackground();
      GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
      shape.setColor(color);
    }
    super.setBackgroundColor(makePressColor(128));
  }
  
  /**
   * Make a dark color to ripple effect
   * @return
   */
  @Override
  protected int makePressColor(int alpha){
    int r = (this.backgroundColor >> 16) & 0xFF;
    int g = (this.backgroundColor >> 8) & 0xFF;
    int b = (this.backgroundColor >> 0) & 0xFF;
    return Color.argb(alpha,r, g, b);    
  }

}




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