Skip to content

Commit

Permalink
Merge pull request #997 from pilimachao/master
Browse files Browse the repository at this point in the history
#90 #210 实验4
  • Loading branch information
zengsn authored Jun 21, 2016
2 parents 037040b + f8375b3 commit 07f93c2
Show file tree
Hide file tree
Showing 15 changed files with 466 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.example.playinggame;
package com.example.meimei;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class Com1314080901238ctivity extends Activity {
public class Com1314080901238Activity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_com1314080901238ctivity);
setContentView(R.layout.activity_com1314080901238);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.example.yaoyiyao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
* Created by Administrator on 2016/6/15.
*/
public class DBHelper extends SQLiteOpenHelper{

public DBHelper(Context context) {

super(context, "cj", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table user(userID INTEGER primary key autoincrement,date text not null)";
db.execSQL(sql);
String sql1 = "insert into user (date) values ('詹姆斯')";
String sql2 = "insert into user (date) values ('犀牛')";
String sql3 = "insert into user (date) values ('大象')";
String sql4 = "insert into user (date) values ('钓鱼')";
String sql5 = "insert into user (date) values ('鹤立鸡群')";
String sql6 = "insert into user (date) values ('天人合一')";
String sql7 = "insert into user (date) values ('考试')";
String sql8 = "insert into user (date) values ('驾驶')";
String sql9 = "insert into user (date) values ('飞机')";
String sql10 = "insert into user (date) values ('刘翔')";
String sql11 = "insert into user (date) values ('马马虎虎')";
String sql12 = "insert into user (date) values ('厕所')";
String sql13 = "insert into user (date) values ('爱情')";
String sql14 = "insert into user (date) values ('维纳斯')";
String sql15 = "insert into user (date) values ('佛祖')";
String sql16 = "insert into user (date) values ('孙悟空')";
String sql17 = "insert into user (date) values ('猪八戒')";
String sql18 = "insert into user (date) values ('大哥')";
String sql19 = "insert into user (date) values ('马超荣')";

db.execSQL(sql1);
db.execSQL(sql2);
db.execSQL(sql3);
db.execSQL(sql4);
db.execSQL(sql5);
db.execSQL(sql6);
db.execSQL(sql7);
db.execSQL(sql8);
db.execSQL(sql9);
db.execSQL(sql10);
db.execSQL(sql11);
db.execSQL(sql12);
db.execSQL(sql13);
db.execSQL(sql14);
db.execSQL(sql15);
db.execSQL(sql16);
db.execSQL(sql17);
db.execSQL(sql18);
db.execSQL(sql19);



}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.yaoyiyao;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1=(Button)findViewById(R.id.button);
Button button2=(Button)findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent();
i.setClass(MainActivity.this,Shark.class);
startActivity(i);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.this.finish();
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
package com.example.yaoyiyao;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Service;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.Random;

/**
* Created by Administrator on 2016/6/15.
*/
public class Shark extends Activity implements SensorEventListener {

private SensorManager sensorManager = null;
private Vibrator vibrator = null;
private LinearLayout topLayout, bottomLayout;
private ImageView topLineIv, bottomLineIv;
private boolean isShake = false;
String date;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shark_layout);
topLayout = (LinearLayout)findViewById(R.id.shake_top_layout);
topLineIv = (ImageView)findViewById(R.id.shake_top_line);
bottomLayout = (LinearLayout)findViewById(R.id.shake_bottom_layout);
bottomLineIv = (ImageView)findViewById(R.id.shake_bottom_line);

topLineIv.setVisibility(View.GONE);
bottomLineIv.setVisibility(View.GONE);
sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
vibrator = (Vibrator)getSystemService(Service.VIBRATOR_SERVICE);
}

@Override
public void onBackPressed() {
super.onBackPressed();
Shark.this.finish();
}

@Override
public void onPause() {
// TODO Auto-generated method stub
super.onPause();
sensorManager.unregisterListener(this);
}

@Override
public void onResume() {
super.onResume();
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
}

@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
int sensorType = event.sensor.getType();
// values[0]:X轴,values[1]:Y轴,values[2]:Z轴
float[] values = event.values;
if (sensorType == Sensor.TYPE_ACCELEROMETER) {
if ((Math.abs(values[0]) > 17 || Math.abs(values[1]) > 17 || Math
.abs(values[2]) > 17) && !isShake) {
isShake = true;
new Thread() {
public void run() {
try {
runOnUiThread(new Runnable() {
public void run() {
// 摇动手机后,再伴随震动提示~~
vibrator.vibrate(300);
topLineIv.setVisibility(View.VISIBLE);
bottomLineIv.setVisibility(View.VISIBLE);
startAnimation(false);
}
});
Thread.sleep(500);
runOnUiThread(new Runnable() {
public void run() {
// 摇动手机后,再伴随震动提示~~
vibrator.vibrate(300);
}
});
Thread.sleep(500);
runOnUiThread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
isShake = false;
startAnimation(true);
}
});
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
}
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub

}

private void startAnimation(boolean isBack) {
int type = TranslateAnimation.RELATIVE_TO_SELF;
float topFromYValue;
float topToYValue;
float bottomFromYValue;
float bottomToYValue;
if (isBack) {
topFromYValue = -0.5f;
topToYValue = 0;
bottomFromYValue = 0.5f;
bottomToYValue = 0;
} else {
topFromYValue = 0;
topToYValue = -0.5f;
bottomFromYValue = 0;
bottomToYValue = 0.5f;
}
TranslateAnimation topAnimation = new TranslateAnimation(type, 0, type,
0, type, topFromYValue, type, topToYValue);
topAnimation.setDuration(200);
topAnimation.setFillAfter(true);
TranslateAnimation bottomAnimation = new TranslateAnimation(type, 0,
type, 0, type, bottomFromYValue, type, bottomToYValue);
bottomAnimation.setDuration(200);
bottomAnimation.setFillAfter(true);
if (isBack) {
bottomAnimation
.setAnimationListener(new TranslateAnimation.AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
topLineIv.setVisibility(View.GONE);
bottomLineIv.setVisibility(View.GONE);
// Toast.makeText(getActivity(),"摇一摇ok!!!",Toast.LENGTH_LONG).show();

Random random = new Random();
int n;
DBHelper dbHelper=new DBHelper(Shark.this);
SQLiteDatabase readdb = dbHelper.getReadableDatabase();
Cursor c = readdb.query("user", null,null,null,null,null,null);
int m=c.getCount();
do {
n = random.nextInt(m);
} while (n == 0);
getdbdate(n);

// DBHelper dbHelper=new DBHelper(Shark.this);
// SQLiteDatabase readdb = dbHelper.getReadableDatabase();
// Cursor c = readdb.query("user", null,"userID=?",new String[]{String.valueOf(2)} , null, null, null);
//// Cursor c = readdb.query("user", null,null,null , null, null, null);
// while (c.moveToNext()){
// date=c.getString(c.getColumnIndex("date"));
// System.out.println("摇一摇:"+String.format("date=%s",date));
// }
// readdb.close();

new AlertDialog.Builder(Shark.this).setItems(
new String[]{date}, null).show();
}
});
}
bottomLayout.startAnimation(bottomAnimation);
topLayout.startAnimation(topAnimation);
}

public String getdbdate(int n){
String mname=null;
DBHelper dbHelper=new DBHelper(Shark.this);
SQLiteDatabase readdb = dbHelper.getReadableDatabase();
Cursor c = readdb.query("user", null,"userID=?",new String[]{String.valueOf(n)} , null, null, null);
while (c.moveToNext()){
date=c.getString(c.getColumnIndex("date"));
System.out.println("摇一摇:"+String.format("date=%s",date));
}
readdb.close();
return mname;

}



}

Binary file added app/src/main/res/drawable-hdpi/base_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/me.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/shake_bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/shake_bottom_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/shake_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/shake_top_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions app/src/main/res/layout/activity_com1314080901238.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Com1314080901238Activity"
android:background="@drawable/base_bg"
>


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始游戏"
android:id="@+id/button"
android:textSize="30dp"
android:textColor="#FFFFFF"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="149dp"
android:background="#00000000"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="结束游戏"
android:id="@+id/button2"
android:textSize="30dp"
android:textColor="#FFFFFF"
android:layout_below="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="101dp"
android:background="#00000000"/>



</RelativeLayout>
Loading

0 comments on commit 07f93c2

Please sign in to comment.