[tor-commits] [orbot/master] added background view; fixed long click;
n8fr8 at torproject.org
n8fr8 at torproject.org
Thu Jun 28 05:18:40 UTC 2012
commit 97a0709eb3f18cfca5afc81bc27d600aacebdf23
Author: n8fr8 <nathan at freitas.net>
Date: Wed Jun 27 21:40:19 2012 -0400
added background view; fixed long click;
---
src/org/torproject/android/AnimatedBlockView.java | 160 +++++++++++++++++++++
src/org/torproject/android/Orbot.java | 10 +-
2 files changed, 167 insertions(+), 3 deletions(-)
diff --git a/src/org/torproject/android/AnimatedBlockView.java b/src/org/torproject/android/AnimatedBlockView.java
new file mode 100644
index 0000000..1599ccd
--- /dev/null
+++ b/src/org/torproject/android/AnimatedBlockView.java
@@ -0,0 +1,160 @@
+package org.torproject.android;
+
+import java.util.Random;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.os.Handler;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.MeasureSpec;
+
+public class AnimatedBlockView extends View implements Runnable {
+
+ private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+
+ private float initX, initY, radius;
+ private boolean drawing = false;
+
+ Random rand = new Random();
+
+ private Handler mHandler = new Handler()
+ {
+ public void handleMessage(Message msg) {
+
+ invalidate();
+ }
+ };
+
+
+ public AnimatedBlockView(Context context) {
+ super(context);
+ // TODO Auto-generated constructor stub
+ init();
+
+ }
+
+ public AnimatedBlockView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ }
+
+ public AnimatedBlockView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ init();
+ }
+
+ private void init(){
+ paint.setStyle(Paint.Style.FILL);
+ paint.setColor(Color.WHITE);
+ paint.setAntiAlias(true);
+
+ new Thread (this).start();
+
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ // TODO Auto-generated method stub
+ setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
+ MeasureSpec.getSize(heightMeasureSpec));
+ }
+
+ int a1 = 30;
+ int a2 = 255;
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+
+
+ for (int i = 0; i < 20; i++)
+ {
+ float r = rand.nextFloat()*255f;
+ float g = rand.nextFloat()*255f;
+ float b = rand.nextFloat()*255f;
+
+ paint.setARGB(a1,(int)r,(int)g,(int)b);
+
+ float x = rand.nextFloat() * getWidth();
+ float y = rand.nextFloat() * getHeight();
+
+ float w = rand.nextFloat() * getWidth();
+ float h = rand.nextFloat() * getHeight();
+
+ canvas.drawCircle(x, y, w/2, paint);
+
+
+ }
+
+ }
+
+ int a1mod = 1;
+
+ public void updateAlpha ()
+ {
+ a1 += a1mod;
+
+ if (a1 > 255 || a1 < 0)
+ a1mod *= -1;
+
+
+ }
+
+ public void run ()
+ {
+
+
+ /*while (true)
+ {
+
+
+ try
+ {
+ Thread.sleep(10);
+ }
+ catch (Exception e)
+ {}
+
+ mHandler.sendEmptyMessage(0);
+
+ }*/
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+
+
+ int action = event.getAction();
+ if (action==MotionEvent.ACTION_MOVE){
+ float x = event.getX();
+ float y = event.getY();
+
+ // radius = (float) Math.sqrt(Math.pow(x-initX, 2) + Math.pow(y-initY, 2));
+ //updateAlpha();
+
+ a1 = (int)(255*(y/((float)getHeight())));
+
+ }
+ else if (action==MotionEvent.ACTION_DOWN){
+ initX = event.getX();
+ initY = event.getY();
+ radius = 1;
+ drawing = true;
+
+
+ }
+ else if (action==MotionEvent.ACTION_UP){
+ drawing = false;
+
+
+ }
+
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index 7a21607..654aea6 100644
--- a/src/org/torproject/android/Orbot.java
+++ b/src/org/torproject/android/Orbot.java
@@ -39,11 +39,12 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;
import android.widget.TextView;
-public class Orbot extends Activity implements OnLongClickListener, TorConstants
+public class Orbot extends Activity implements TorConstants, OnLongClickListener
{
@@ -90,7 +91,7 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
//obvious? -yep got everything so far
lblStatus = (TextView)findViewById(R.id.lblStatus);
- lblStatus.setOnLongClickListener(this);
+
imgStatus = (ImageView)findViewById(R.id.imgStatus);
imgStatus.setOnLongClickListener(this);
@@ -665,14 +666,17 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
stopTor();
}
+
+ return true;
}
catch (Exception e)
{
Log.d(TAG,"error onclick",e);
}
+
+ return false;
- return true;
}
More information about the tor-commits
mailing list