Android Open Source - My-Wallet-Android Circular Progress View






From Project

Back to project page My-Wallet-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project My-Wallet-Android 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

/**
 * Copyright 2011 Google Inc.//from ww w.j a  v  a 2  s  .c o  m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package piuk.blockchain.android.util;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author Andreas Schildbach
 */
public class CircularProgressView extends View
{
  private int width;
  private int height;
  private int progress = 0;
  private int maxProgress = 7;
  private final Path path = new Path();
  private final Paint fillPaint = new Paint();
  private final Paint strokePaint = new Paint();

  public CircularProgressView(final Context context, final AttributeSet attrs)
  {
    super(context, attrs);

    final float density = getResources().getDisplayMetrics().density;

    fillPaint.setStyle(Style.FILL);
    fillPaint.setColor(Color.parseColor("#44ff44"));
    fillPaint.setAntiAlias(true);

    strokePaint.setStyle(Style.STROKE);
    strokePaint.setColor(Color.DKGRAY);
    strokePaint.setStrokeWidth(1 * density);
    strokePaint.setAntiAlias(true);
  }

  @Override
  protected void onDraw(final Canvas canvas)
  {
    super.onDraw(canvas);

    canvas.drawPath(path, fillPaint);
    canvas.drawPath(path, strokePaint);
  }

  public void setColor(final int color)
  {
    fillPaint.setColor(color);
    postInvalidate();
  }

  public void setProgress(final int progress)
  {
    this.progress = progress;

    updatePath(getWidth(), getHeight());
    postInvalidate();
  }

  public void setMaxProgress(final int maxProgress)
  {
    this.maxProgress = maxProgress;

    updatePath(getWidth(), getHeight());
    postInvalidate();
  }

  @Override
  protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh)
  {
    updatePath(w, h);

    super.onSizeChanged(w, h, oldw, oldh);
  }

  private void updatePath(final int w, final int h)
  {
    path.reset();

    if (progress == 0)
    {
      path.close();
    }
    else if (progress < maxProgress)
    {
      final float angle = progress * 360 / maxProgress;

      path.moveTo(w / 2f, h / 2f);
      path.arcTo(new RectF(1, 1, w - 1, h - 1), 270, angle);
      path.close();
    }
    else
    {
      path.addCircle(w / 2f, h / 2f, (w / 2f) - 1, Direction.CW);
    }
  }

  @Override
  protected void onMeasure(final int wMeasureSpec, final int hMeasureSpec)
  {
    final int wMode = MeasureSpec.getMode(wMeasureSpec);
    final int wSize = MeasureSpec.getSize(wMeasureSpec);

    if (wMode == MeasureSpec.EXACTLY)
      width = wSize;
    else if (wMode == MeasureSpec.AT_MOST)
      width = Math.min(width, wSize);

    final int hMode = MeasureSpec.getMode(hMeasureSpec);
    final int hSize = MeasureSpec.getSize(hMeasureSpec);

    if (hMode == MeasureSpec.EXACTLY)
      height = hSize;
    else if (hMode == MeasureSpec.AT_MOST)
      height = Math.min(height, hSize);

    setMeasuredDimension(this.width, this.height);
  }

  @Override
  public int getBaseline()
  {
    return getMeasuredHeight() - 1;
  }
}




Java Source Code List

piuk.BitcoinAddress.java
piuk.BitcoinScript.java
piuk.Hash.java
piuk.MyBlockChain.java
piuk.MyRemoteWallet.java
piuk.MyTransactionConfidence.java
piuk.MyTransactionInput.java
piuk.MyTransactionOutPoint.java
piuk.MyTransactionOutput.java
piuk.MyTransaction.java
piuk.MyWallet.java
piuk.blockchain.android.AddressBookProvider.java
piuk.blockchain.android.BlockchainService.java
piuk.blockchain.android.Constants.java
piuk.blockchain.android.DetermineFirstSeenThread.java
piuk.blockchain.android.ExchangeRatesProvider.java
piuk.blockchain.android.WalletApplication.java
piuk.blockchain.android.WalletBalanceWidgetProvider.java
piuk.blockchain.android.ui.AbstractWalletActivity.java
piuk.blockchain.android.ui.AmountCalculatorFragment.java
piuk.blockchain.android.ui.CurrencyAmountView.java
piuk.blockchain.android.ui.CurrencyCodeDrawable.java
piuk.blockchain.android.ui.EditAddressBookEntryFragment.java
piuk.blockchain.android.ui.ExchangeRatesFragment.java
piuk.blockchain.android.ui.NewAccountFragment.java
piuk.blockchain.android.ui.PairWalletActivity.java
piuk.blockchain.android.ui.PreferencesActivity.java
piuk.blockchain.android.ui.RequestCoinsActivity.java
piuk.blockchain.android.ui.RequestCoinsFragment.java
piuk.blockchain.android.ui.SecondPasswordFragment.java
piuk.blockchain.android.ui.SendCoinsActivity.java
piuk.blockchain.android.ui.SendCoinsFragment.java
piuk.blockchain.android.ui.SendingAddressesFragment.java
piuk.blockchain.android.ui.TransactionActivity.java
piuk.blockchain.android.ui.TransactionFragment.java
piuk.blockchain.android.ui.WalletActivity.java
piuk.blockchain.android.ui.WalletAddressesFragment.java
piuk.blockchain.android.ui.WalletBalanceFragment.java
piuk.blockchain.android.ui.WalletTransactionsFragment.java
piuk.blockchain.android.ui.WelcomeFragment.java
piuk.blockchain.android.util.ActionBarFragment.java
piuk.blockchain.android.util.Base43.java
piuk.blockchain.android.util.CircularProgressView.java
piuk.blockchain.android.util.ErrorReporter.java
piuk.blockchain.android.util.IOUtils.java
piuk.blockchain.android.util.Iso8601Format.java
piuk.blockchain.android.util.NfcTools.java
piuk.blockchain.android.util.QrDialog.java
piuk.blockchain.android.util.ViewPagerTabs.java
piuk.blockchain.android.util.WalletUtils.java