// TurningArrowActivity.java Copyright (c) Kari Laitinen // http://www.naturalprogramming.com/ // 2016-03-04 File created. // 2016-03-04 Last modification. /* This is the main activity of an Android application that shows how to - use a SeekBar to adjust a value - specify a Path - translate and rotate the coordinate system of a Canvas To run this program, set up an Android Studio project, so that TurningArrowActivity is the name of the main activity class. You should use the package name used below. You should copy the following files to your project: java/turning/arrow/TurningArrowActivity.java java/turning/arrow/TurningArrowView.java res/layout/activity_turning_arrow.xml */ package turning.arrow ; import android.app.Activity ; import android.os.Bundle ; import android.graphics.* ; // Classes Canvas, Color, Paint, RectF, etc. import android.view.View ; import android.content.Context ; import android.widget.SeekBar ; import android.widget.SeekBar.OnSeekBarChangeListener ; public class TurningArrowActivity extends Activity { TurningArrowView turning_arrow_view; public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ) ; setContentView( R.layout.activity_turning_arrow ) ; turning_arrow_view = (TurningArrowView) findViewById( R.id.turning_arrow_view_id ) ; SeekBar seekbar = (SeekBar) findViewById( R.id.seekbar_for_arrow_angle ) ; seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { public void onProgressChanged( SeekBar seekbar, int progresValue, boolean fromUser) { // System.out.print( "\n Changed: " + seekbar.getProgress() ) ; // arrow_angle must be -90 ... + 90 // seekbar gives values between in the range 0 .... 180 turning_arrow_view.set_arrow_angle( seekbar.getProgress() - 90 ) ; } public void onStartTrackingTouch( SeekBar seekbar ) { // Use a wider outline for the arrow while the SeekBar is used. turning_arrow_view.set_outline_stroke_width( 8 ) ; } public void onStopTrackingTouch( SeekBar seekbar ) { turning_arrow_view.set_outline_stroke_width( 2 ) ; } }); } }