Skip to content

Commit 183c5f6

Browse files
committed
Initial version
0 parents  commit 183c5f6

24 files changed

+869
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apply plugin: 'com.android.application'
2+
3+
4+
android {
5+
compileSdkVersion 23
6+
buildToolsVersion "23.0.3"
7+
8+
defaultConfig {
9+
applicationId "br.com.inovant.genius"
10+
minSdkVersion 21
11+
targetSdkVersion 23
12+
versionCode 1
13+
versionName "1.0"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
compile fileTree(dir: 'libs', include: ['*.jar'])
25+
compile 'com.google.android.support:wearable:1.3.0'
26+
compile 'com.google.android.gms:play-services-wearable:8.4.0'
27+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\Development\Android\sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

app/src/main/AndroidManifest.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="br.com.inovant.genius" >
4+
5+
<uses-feature android:name="android.hardware.type.watch" />
6+
7+
<uses-permission android:name="android.permission.WAKE_LOCK" />
8+
9+
<application
10+
android:allowBackup="true"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:supportsRtl="true"
14+
android:theme="@android:style/Theme.DeviceDefault" >
15+
<uses-library
16+
android:name="com.google.android.wearable"
17+
android:required="false" />
18+
19+
<activity
20+
android:name=".Main"
21+
android:label="@string/app_name"
22+
android:theme="@android:style/Theme.DeviceDefault.Light" >
23+
<intent-filter>
24+
<action android:name="android.intent.action.MAIN" />
25+
26+
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
</activity>
29+
30+
<activity
31+
android:name=".Game"
32+
android:label="@string/app_name"
33+
android:theme="@android:style/Theme.DeviceDefault.Light" />
34+
</application>
35+
36+
</manifest>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package br.com.inovant.genius;
2+
3+
import android.os.Bundle;
4+
import android.support.wearable.activity.WearableActivity;
5+
6+
public class Game extends WearableActivity {
7+
8+
private LightButton mYellow;
9+
private LightButton mBlue;
10+
private LightButton mGreen;
11+
private LightButton mRed;
12+
private RulesHandler rulesHandler;
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.activity_game);
18+
setAmbientEnabled();
19+
20+
mYellow = (LightButton) findViewById(R.id.buttonYellow);
21+
mYellow.setLightColor(R.color.yellow_light).setDarkColor(R.color.yellow_dark);//.setId(YELLOW);
22+
23+
mBlue = (LightButton) findViewById(R.id.buttonBlue);
24+
mBlue.setLightColor(R.color.blue_light).setDarkColor(R.color.blue_dark);//.setId(BLUE);
25+
26+
mGreen = (LightButton) findViewById(R.id.buttonGreen);
27+
mGreen.setLightColor(R.color.green_light).setDarkColor(R.color.green_dark);//.setId(GREEN);
28+
29+
mRed = (LightButton) findViewById(R.id.buttonRed);
30+
mRed.setLightColor(R.color.red_light).setDarkColor(R.color.red_dark);//.setId(RED);
31+
32+
rulesHandler = new RulesHandler(this);
33+
rulesHandler.addButton(mYellow);
34+
rulesHandler.addButton(mBlue);
35+
rulesHandler.addButton(mGreen);
36+
rulesHandler.addButton(mRed);
37+
38+
rulesHandler.generateNextSequence();
39+
40+
}
41+
42+
@Override
43+
protected void onResume() {
44+
super.onResume();
45+
rulesHandler.blink();
46+
}
47+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package br.com.inovant.genius;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
import android.view.MotionEvent;
6+
import android.view.View;
7+
import android.widget.Button;
8+
9+
/**
10+
* Created by Milton on 04/06/2016.
11+
*/
12+
public class LightButton extends Button {
13+
14+
// public static final int YELLOW = 0;
15+
// public static final int BLUE = 0;
16+
// public static final int GREEN = 0;
17+
// public static final int RED = 0;
18+
19+
private Integer lightColor;
20+
private Integer darkColor;
21+
private Integer index;
22+
private OnTouchListener onTouchListener;
23+
private OnClickListener onClickListener;
24+
25+
public LightButton(Context context, AttributeSet attrs) {
26+
super(context, attrs);
27+
onTouchListener = new View.OnTouchListener() {
28+
@Override
29+
public boolean onTouch(View v, MotionEvent event) {
30+
switch(event.getAction()) {
31+
case MotionEvent.ACTION_DOWN:
32+
LightButton.this.setBackgroundColor(getResources().getColor(lightColor));
33+
break;
34+
case MotionEvent.ACTION_UP:
35+
LightButton.this.setBackgroundColor(getResources().getColor(darkColor));
36+
break;
37+
}
38+
return false;
39+
}
40+
};
41+
enableTouch(true);
42+
}
43+
44+
@Override
45+
public void setOnClickListener(OnClickListener onClickListener) {
46+
this.onClickListener = onClickListener;
47+
super.setOnClickListener(onClickListener);
48+
}
49+
50+
public Integer getIndex() {
51+
return index;
52+
}
53+
54+
public void setIndex(Integer id) {
55+
this.index = id;
56+
}
57+
58+
public LightButton setLightColor(int lightColor) {
59+
this.lightColor = lightColor;
60+
return this;
61+
}
62+
63+
public LightButton setDarkColor(int darkColor) {
64+
this.darkColor = darkColor;
65+
return this;
66+
}
67+
68+
public LightButton enableTouch(final boolean enable){
69+
if (enable){
70+
setOnTouchListener(onTouchListener);
71+
} else {
72+
setOnTouchListener(null);
73+
}
74+
return this;
75+
}
76+
77+
public LightButton enableClick(final boolean enable){
78+
if (enable){
79+
setOnClickListener(onClickListener);
80+
} else {
81+
setOnClickListener(null);
82+
}
83+
return this;
84+
}
85+
86+
public LightButton enableLight(final boolean enable){
87+
if (enable){
88+
setBackgroundColor(getResources().getColor(lightColor));
89+
} else {
90+
setBackgroundColor(getResources().getColor(darkColor));
91+
}
92+
return this;
93+
}
94+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package br.com.inovant.genius;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.content.SharedPreferences;
6+
import android.os.Bundle;
7+
import android.os.Handler;
8+
import android.support.wearable.activity.WearableActivity;
9+
import android.view.View;
10+
import android.widget.Button;
11+
import android.widget.TextView;
12+
import android.widget.Toast;
13+
14+
public class Main extends WearableActivity {
15+
16+
public static final String PREFS_NAME = "br.com.inovant.genius";
17+
public static final int SCORE = 1;
18+
private int highScore;
19+
private TextView mScore;
20+
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
setContentView(R.layout.activity_main);
26+
setAmbientEnabled();
27+
28+
// Restore preferences
29+
final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
30+
highScore = settings.getInt("highScore", 0);
31+
32+
mScore = (TextView) findViewById(R.id.score);
33+
mScore.setText(highScore + "");
34+
35+
Button mStart = (Button) findViewById(R.id.start);
36+
mStart.setOnClickListener(new View.OnClickListener() {
37+
@Override
38+
public void onClick(View v) {
39+
Intent intent = new Intent(Main.this, Game.class);
40+
startActivityForResult(intent, SCORE);
41+
}
42+
});
43+
}
44+
45+
@Override
46+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
47+
// If the request went well (OK) and the request was PICK_CONTACT_REQUEST
48+
if (resultCode == Activity.RESULT_OK && requestCode == SCORE) {
49+
int score = data.getIntExtra(RulesHandler.SCORE, 0);
50+
if(score > highScore){
51+
highScore = score;
52+
53+
// We need an Editor object to make preference changes.
54+
// All objects are from android.context.Context
55+
final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
56+
SharedPreferences.Editor editor = settings.edit();
57+
editor.putInt("highScore", highScore);
58+
59+
// Commit the edits!
60+
editor.commit();
61+
62+
mScore.setText(highScore + "");
63+
showToast("New high score!");
64+
}
65+
}
66+
}
67+
68+
private void showToast(final String msg){
69+
final Toast toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
70+
toast.show();
71+
Handler handler = new Handler();
72+
handler.postDelayed(new Runnable() {
73+
@Override
74+
public void run() {
75+
toast.cancel();
76+
}
77+
}, 2000);
78+
}
79+
}

0 commit comments

Comments
 (0)