Android Open Source - ivotingverification Triangle View






From Project

Back to project page ivotingverification.

License

The source code is released under:

GNU General Public License

If you think the Android project ivotingverification 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 (C) 2013 Eesti Vabariigi Valimiskomisjon 
 * (Estonian National Electoral Committee), www.vvk.ee
 *//  www.  j ava 2 s.c o m
 * Written in 2013 by AS Finestmedia, www.finestmedia.ee
 * 
 * Vote-verification application for Estonian Internet voting system
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/
 
package ee.vvk.ivotingverification.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.Point;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.LinearLayout;

/**
 * Triangle view.
 * 
 * @version 16.05.2013
 */
public class TriangleView extends LinearLayout {

  private Paint trianglePaint;
  private Path trianglePath;
  private int color;
  private String number;
  private Context context;

  public TriangleView(Context context, int color, String number) {
    super(context);
    this.color = color;
    this.number = number;
    this.context = context;
    commonConstructor(context);
  }

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

  private void commonConstructor(Context context) {
    setBackgroundColor(Color.TRANSPARENT);

    trianglePaint = new Paint();
    trianglePaint.setStyle(Style.FILL);
    trianglePaint.setColor(color);
  }

  @Override
  protected void onDraw(Canvas canvas) {
    trianglePath = getTriangle(super.getWidth());
    canvas.drawPath(trianglePath, trianglePaint);

    Paint mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTypeface(Typeface.create(Typeface.DEFAULT_BOLD,
        Typeface.BOLD));
    mTextPaint.setTextSize((int) Util.convertPixelsToDp(18, context));
    mTextPaint.setColor(Util.generateHexColorValue(C.lblForeground));
    canvas.save();
    canvas.rotate(-45);
    canvas.drawText(number, (int) Util.convertPixelsToDp(-15, context),
        (int) Util.convertPixelsToDp(30, context), mTextPaint);
    canvas.restore();
  }

  private Path getTriangle(int l) {
    Point p1 = null, p2 = null, p3 = null;

    p1 = new Point(0, l);
    p2 = new Point(l, l);
    p3 = new Point(l, 0);

    Path path = new Path();
    path.moveTo(p1.x, p1.y);
    path.lineTo(p2.x, p2.y);
    path.lineTo(p3.x, p3.y);

    return path;
  }
}




Java Source Code List

ee.vvk.ivotingverification.BruteForceActivity.java
ee.vvk.ivotingverification.ErrorActivity.java
ee.vvk.ivotingverification.HelpActivity.java
ee.vvk.ivotingverification.MainActivity.java
ee.vvk.ivotingverification.QRScannerActivity.java
ee.vvk.ivotingverification.VoteActivity.java
ee.vvk.ivotingverification.VoteDownloadActivity.java
ee.vvk.ivotingverification.adapter.CandidatesListAdapter.java
ee.vvk.ivotingverification.dialog.LoadingSpinner.java
ee.vvk.ivotingverification.model.Vote.java
ee.vvk.ivotingverification.qr.AutoFocusCallback.java
ee.vvk.ivotingverification.qr.CameraConfigurationManager.java
ee.vvk.ivotingverification.qr.CameraManager.java
ee.vvk.ivotingverification.qr.CaptureActivityHandler.java
ee.vvk.ivotingverification.qr.DecodeFormatManager.java
ee.vvk.ivotingverification.qr.DecodeHandler.java
ee.vvk.ivotingverification.qr.DecodeThread.java
ee.vvk.ivotingverification.qr.FinishListener.java
ee.vvk.ivotingverification.qr.InactivityTimer.java
ee.vvk.ivotingverification.qr.Intents.java
ee.vvk.ivotingverification.qr.PlanarYUVLuminanceSource.java
ee.vvk.ivotingverification.qr.PreferencesActivity.java
ee.vvk.ivotingverification.qr.PreviewCallback.java
ee.vvk.ivotingverification.qr.ViewfinderResultPointCallback.java
ee.vvk.ivotingverification.qr.ViewfinderView.java
ee.vvk.ivotingverification.util.C.java
ee.vvk.ivotingverification.util.Crypto.java
ee.vvk.ivotingverification.util.CustomHttpsClient.java
ee.vvk.ivotingverification.util.HttpRequest.java
ee.vvk.ivotingverification.util.JSONParser.java
ee.vvk.ivotingverification.util.RegexMatcher.java
ee.vvk.ivotingverification.util.SecureRandomWrapper.java
ee.vvk.ivotingverification.util.TriangleView.java
ee.vvk.ivotingverification.util.Util.java