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