package mangavalk.tetris; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdSize; import com.google.android.gms.ads.AdView; import android.app.Activity; import android.graphics.PointF; import android.os.Bundle; import android.util.SparseArray; import android.view.MotionEvent; import android.widget.FrameLayout; public class MainActivity extends Activity { CanvasView canvasClass; private AdView adView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FrameLayout ll; ll = new FrameLayout(this); // Create the adView. adView = new AdView(this); adView.setAdUnitId("ca-app-pub-2360519718191877/5428392148"); adView.setAdSize(AdSize.BANNER); // Initiate a generic request. AdRequest adRequest = new AdRequest.Builder() .addTestDevice("D23CD70B20EE4AF169D112010B8DC97E") // Htc One X .addTestDevice("029011F06A23EB6FFF862E44CC792EF2") // Nexus 7 tablet .build(); canvasClass = new CanvasView(this); canvasClass.PayedVersion = true; // Set payment status canvasClass.startLevel = 0; if (!canvasClass.PayedVersion) { // Load the adView with the ad request. adView.loadAd(adRequest); } ll.addView(canvasClass); // Add the adView to it. FrameLayout.LayoutParams adsParams =new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, android.view.Gravity.TOP|android.view.Gravity.CENTER_HORIZONTAL); ll.addView(adView, adsParams); setContentView(ll); mActivePointers = new SparseArray(); canvasClass.SetActivity(this); } @Override public void onPause() { super.onPause(); canvasClass.onPause(); } @Override public void onResume() { super.onResume(); canvasClass.onResume(); } @Override public void onBackPressed() { super.onBackPressed(); canvasClass.onPause(); } private SparseArray mActivePointers; @Override public boolean onTouchEvent(MotionEvent e) { // MotionEvent reports input details from the touch screen // and other input controls. In this case, you are only // interested in events where the touch position changed. // get pointer index from the event object int pointerIndex = e.getActionIndex(); // get pointer ID int pointerId = e.getPointerId(pointerIndex); // get masked (not specific to a pointer) action int maskedAction = e.getActionMasked(); switch (maskedAction) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: { // We have a new pointer. Lets add it to the list of pointers PointF f = new PointF(); f.x = e.getX(pointerIndex); f.y = e.getY(pointerIndex); canvasClass.sendMove(f.x, f.y, false); mActivePointers.put(pointerId, f); break; } case MotionEvent.ACTION_MOVE: { // a pointer was moved break; } case MotionEvent.ACTION_UP: for (int size = e.getPointerCount(), i = 0; i < size; i++) { PointF point = mActivePointers.get(e.getPointerId(i)); if (point != null) { point.x = e.getX(i); point.y = e.getY(i); canvasClass.sendMove(point.x, point.y, true); } } break; case MotionEvent.ACTION_POINTER_UP: break; case MotionEvent.ACTION_CANCEL: { // TODO use data break; } } return true; } }