Guest User

Untitled

a guest
Mar 19th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. package com.example.easytune;
  2.  
  3. import android.content.Context;
  4. import android.graphics.Canvas;
  5. import android.graphics.Paint;
  6. import android.util.AttributeSet;
  7. import android.view.View;
  8. import android.widget.ImageView;
  9.  
  10. public class PitchView extends View{
  11.  
  12. public float centerPitch, currentPitch;
  13. private int width, height;
  14. private final Paint paint = new Paint();
  15.  
  16. private ImageView middlesquare_off = (ImageView) findViewById(R.drawable.middlesquare_off);
  17. private ImageView right_arrow_off = (ImageView) findViewById(R.drawable.right_arrow_off);
  18. private ImageView left_arrow_off = (ImageView) findViewById(R.drawable.left_arrow_off);
  19.  
  20. public PitchView(Context context) {
  21. super(context);
  22. }
  23.  
  24. public PitchView(Context context, AttributeSet attrs) {
  25. super(context, attrs);
  26. }
  27.  
  28. public PitchView(Context context, AttributeSet attrs, int defStyle) {
  29. super(context, attrs, defStyle);
  30. }
  31.  
  32. public void setCenterPitch(float centerPitch) {
  33. this.centerPitch = centerPitch;
  34. invalidate();
  35. }
  36.  
  37. public void setCurrentPitch(float currentPitch) {
  38. this.currentPitch = currentPitch;
  39. invalidate();
  40. }
  41.  
  42. @Override
  43. protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  44. super.onSizeChanged(w, h, oldw, oldh);
  45. width = w;
  46. height = h;
  47. }
  48.  
  49. @Override
  50. protected void onDraw(Canvas canvas) {
  51. //float halfWidth = width / 2;
  52. //paint.setStrokeWidth(6.0f);
  53. //paint.setColor(0xFFFF0000);
  54. //canvas.drawLine(halfWidth, 0, halfWidth, height, paint);
  55.  
  56. float dx = (currentPitch - centerPitch) / 2;
  57. if (-1 < dx && dx < 1) {
  58. // paint.setStrokeWidth(2.0f);
  59. // paint.setColor(Color.BLUE);
  60. changeMiddleTuner();
  61. } else {
  62. // paint.setStrokeWidth(8.0f);
  63. // paint.setColor(Color.RED);
  64. dx = (dx < 0) ? -1 : 1;
  65. }
  66. //double phi = dx * Math.PI / 4;
  67. // canvas.drawLine(halfWidth, height,
  68. // halfWidth + (float)Math.sin(phi) * height * 0.9f,
  69. // height - (float)Math.cos(phi) * height * 0.9f, paint);
  70. }
  71.  
  72. public void changeLeftTuner(){
  73. left_arrow_off.setImageResource(R.drawable.left_arrow_on);
  74. }
  75.  
  76. public void changeMiddleTuner(){
  77. middlesquare_off.setImageResource(R.drawable.middlesquare_on);
  78. }
  79.  
  80. public void changeRightTuner(){
  81. right_arrow_off.setImageResource(R.drawable.right_arrow_on);
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment