From 0c195a60d83e82ed5e70f33ee1925964858dac73 Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Sun, 9 Apr 2017 00:54:07 -0400 Subject: [PATCH 01/13] JobService --- JobService.Java | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 JobService.Java diff --git a/JobService.Java b/JobService.Java new file mode 100644 index 000000000000..52516f1fa53f --- /dev/null +++ b/JobService.Java @@ -0,0 +1,43 @@ + +//1- Add service class +public class MyJobService extends JobService { + @Override + public boolean onStartJob(JobParameters jobParameters) { + // CALL URL, + Log.i("Job"," job is started succefuly"); + jobFinished(jobParameters,false); + return false; + } + + @Override + public boolean onStopJob(JobParameters jobParameters) { + Log.i("Job"," job is stopped succefuly"); + return false; + } +} +//2- Add service to Mainfest.xml +/* + + + */ +//33- Call service + + int JOBID=0; + public void bustart(View view) { + + JobInfo.Builder builder= new + JobInfo.Builder(JOBID++, + new ComponentName( this,MyJobService.class)); + builder.setMinimumLatency(1000); + builder.setOverrideDeadline(2000); + // builder.setPeriodic(2000); + //builder.setRequiresCharging(true); + //builder.setRequiresDeviceIdle(true); + //builder.setPersisted(true); + // builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); + JobScheduler jobScheduler= + (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); + jobScheduler.schedule(builder.build()); + } \ No newline at end of file From 6a9bc1b920de08854dc8b0ac5eaa2fb826454e4d Mon Sep 17 00:00:00 2001 From: hussienalrubaye Date: Sun, 30 Apr 2017 10:53:00 -0400 Subject: [PATCH 02/13] add tic tac toy game --- TicTacToyGame/.gitignore | 9 + TicTacToyGame/.idea/encodings.xml | 6 + TicTacToyGame/.idea/gradle.xml | 18 ++ TicTacToyGame/.idea/misc.xml | 36 +++ TicTacToyGame/.idea/modules.xml | 9 + TicTacToyGame/.idea/runConfigurations.xml | 12 + TicTacToyGame/app/.gitignore | 1 + TicTacToyGame/app/build.gradle | 30 +++ TicTacToyGame/app/proguard-rules.pro | 25 ++ .../ExampleInstrumentedTest.java | 26 +++ .../app/src/main/AndroidManifest.xml | 17 ++ .../hussein/tictactoygame/MainActivity.java | 221 ++++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 99 ++++++++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4208 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2555 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6114 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10056 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 14696 bytes .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 11 + .../tictactoygame/ExampleUnitTest.java | 17 ++ TicTacToyGame/build.gradle | 23 ++ TicTacToyGame/gradle.properties | 17 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + TicTacToyGame/gradlew | 160 +++++++++++++ TicTacToyGame/gradlew.bat | 90 +++++++ TicTacToyGame/settings.gradle | 1 + 34 files changed, 843 insertions(+) create mode 100644 TicTacToyGame/.gitignore create mode 100644 TicTacToyGame/.idea/encodings.xml create mode 100644 TicTacToyGame/.idea/gradle.xml create mode 100644 TicTacToyGame/.idea/misc.xml create mode 100644 TicTacToyGame/.idea/modules.xml create mode 100644 TicTacToyGame/.idea/runConfigurations.xml create mode 100644 TicTacToyGame/app/.gitignore create mode 100644 TicTacToyGame/app/build.gradle create mode 100644 TicTacToyGame/app/proguard-rules.pro create mode 100644 TicTacToyGame/app/src/androidTest/java/com/hussein/tictactoygame/ExampleInstrumentedTest.java create mode 100644 TicTacToyGame/app/src/main/AndroidManifest.xml create mode 100644 TicTacToyGame/app/src/main/java/com/hussein/tictactoygame/MainActivity.java create mode 100644 TicTacToyGame/app/src/main/res/layout/activity_main.xml create mode 100644 TicTacToyGame/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 TicTacToyGame/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 TicTacToyGame/app/src/main/res/values/colors.xml create mode 100644 TicTacToyGame/app/src/main/res/values/strings.xml create mode 100644 TicTacToyGame/app/src/main/res/values/styles.xml create mode 100644 TicTacToyGame/app/src/test/java/com/hussein/tictactoygame/ExampleUnitTest.java create mode 100644 TicTacToyGame/build.gradle create mode 100644 TicTacToyGame/gradle.properties create mode 100644 TicTacToyGame/gradle/wrapper/gradle-wrapper.jar create mode 100644 TicTacToyGame/gradle/wrapper/gradle-wrapper.properties create mode 100755 TicTacToyGame/gradlew create mode 100644 TicTacToyGame/gradlew.bat create mode 100644 TicTacToyGame/settings.gradle diff --git a/TicTacToyGame/.gitignore b/TicTacToyGame/.gitignore new file mode 100644 index 000000000000..39fb081a42a8 --- /dev/null +++ b/TicTacToyGame/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/TicTacToyGame/.idea/encodings.xml b/TicTacToyGame/.idea/encodings.xml new file mode 100644 index 000000000000..97626ba45445 --- /dev/null +++ b/TicTacToyGame/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TicTacToyGame/.idea/gradle.xml b/TicTacToyGame/.idea/gradle.xml new file mode 100644 index 000000000000..7ac24c777f8a --- /dev/null +++ b/TicTacToyGame/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/TicTacToyGame/.idea/misc.xml b/TicTacToyGame/.idea/misc.xml new file mode 100644 index 000000000000..4da8b0b52a27 --- /dev/null +++ b/TicTacToyGame/.idea/misc.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TicTacToyGame/.idea/modules.xml b/TicTacToyGame/.idea/modules.xml new file mode 100644 index 000000000000..1ff53374c021 --- /dev/null +++ b/TicTacToyGame/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/TicTacToyGame/.idea/runConfigurations.xml b/TicTacToyGame/.idea/runConfigurations.xml new file mode 100644 index 000000000000..7f68460d8b38 --- /dev/null +++ b/TicTacToyGame/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/TicTacToyGame/app/.gitignore b/TicTacToyGame/app/.gitignore new file mode 100644 index 000000000000..796b96d1c402 --- /dev/null +++ b/TicTacToyGame/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/TicTacToyGame/app/build.gradle b/TicTacToyGame/app/build.gradle new file mode 100644 index 000000000000..8fb44739c686 --- /dev/null +++ b/TicTacToyGame/app/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + defaultConfig { + applicationId "com.hussein.tictactoygame" + minSdkVersion 12 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:25.3.1' + testCompile 'junit:junit:4.12' + compile 'com.android.support.constraint:constraint-layout:1.0.2' +} diff --git a/TicTacToyGame/app/proguard-rules.pro b/TicTacToyGame/app/proguard-rules.pro new file mode 100644 index 000000000000..823ed0c41709 --- /dev/null +++ b/TicTacToyGame/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/hussienalrubaye/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/TicTacToyGame/app/src/androidTest/java/com/hussein/tictactoygame/ExampleInstrumentedTest.java b/TicTacToyGame/app/src/androidTest/java/com/hussein/tictactoygame/ExampleInstrumentedTest.java new file mode 100644 index 000000000000..c13fbb0fb819 --- /dev/null +++ b/TicTacToyGame/app/src/androidTest/java/com/hussein/tictactoygame/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.hussein.tictactoygame; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.hussein.tictactoygame", appContext.getPackageName()); + } +} diff --git a/TicTacToyGame/app/src/main/AndroidManifest.xml b/TicTacToyGame/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..63dc7105dc0c --- /dev/null +++ b/TicTacToyGame/app/src/main/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TicTacToyGame/app/src/main/java/com/hussein/tictactoygame/MainActivity.java b/TicTacToyGame/app/src/main/java/com/hussein/tictactoygame/MainActivity.java new file mode 100644 index 000000000000..11f106d41331 --- /dev/null +++ b/TicTacToyGame/app/src/main/java/com/hussein/tictactoygame/MainActivity.java @@ -0,0 +1,221 @@ +package com.hussein.tictactoygame; + +import android.graphics.Color; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.Random; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + public void BuClick(View view) { + Button buSelected= (Button) view; + int CellID=0; + switch ((buSelected.getId())){ + + case R.id.bu1: + CellID=1; + break; + + case R.id.bu2: + CellID=2; + break; + + case R.id.bu3: + CellID=3; + break; + + case R.id.bu4: + CellID=4; + break; + + case R.id.bu5: + CellID=5; + break; + + case R.id.bu6: + CellID=6; + break; + + case R.id.bu7: + CellID=7; + break; + + case R.id.bu8: + CellID=8; + break; + + case R.id.bu9: + CellID=9; + break; + } + PlayGame(CellID, buSelected); + } + + int ActivePlayer=1; // 1- for first , 2 for second + ArrayList Player1= new ArrayList();// hold player 1 data + ArrayList Player2= new ArrayList();// hold player 2 data + void PlayGame(int CellID,Button buSelected){ + + Log.d("Player:",String.valueOf(CellID)); + + if (ActivePlayer==1){ + buSelected.setText("X"); + buSelected.setBackgroundColor(Color.GREEN); + Player1.add(CellID); + ActivePlayer=2; + + AutoPlay(); + } + else if (ActivePlayer==2){ + buSelected.setText("O"); + buSelected.setBackgroundColor(Color.BLUE); + Player2.add(CellID); + ActivePlayer=1; + + } + + buSelected.setEnabled(false); + CheckWiner(); + } + + void CheckWiner(){ + int Winer=-1; + //row 1 + if (Player1.contains(1) && Player1.contains(2) && Player1.contains(3)) { + Winer=1 ; + } + if (Player2.contains(1) && Player2.contains(2) && Player2.contains(3)) { + Winer=2 ; + } + + //row 2 + if (Player1.contains(4) && Player1.contains(5) && Player1.contains(6)) { + Winer=1 ; + } + if (Player2.contains(4) && Player2.contains(5) && Player2.contains(6)) { + Winer=2 ; + } + + //row 3 + if (Player1.contains(7) && Player1.contains(8) && Player1.contains(9)) { + Winer=1 ; + } + if (Player2.contains(7) && Player2.contains(8) && Player2.contains(9)) { + Winer=2 ; + } + + + //col 1 + if (Player1.contains(1) && Player1.contains(4) && Player1.contains(7)) { + Winer=1 ; + } + if (Player2.contains(1) && Player2.contains(4) && Player2.contains(7)) { + Winer=2 ; + } + + //col 2 + if (Player1.contains(2) && Player1.contains(5) && Player1.contains(8)) { + Winer=1 ; + } + if (Player2.contains(2) && Player2.contains(5) && Player2.contains(8)) { + Winer=2 ; + } + + + //col 3 + if (Player1.contains(3) && Player1.contains(6) && Player1.contains(9)) { + Winer=1 ; + } + if (Player2.contains(3) && Player2.contains(6) && Player2.contains(9)) { + Winer=2 ; + } + + + if ( Winer !=-1){ + // We have winer + + if (Winer==1){ + Toast.makeText(this,"Player 1 is winner",Toast.LENGTH_LONG).show(); + } + + if (Winer==2){ + Toast.makeText(this,"Player 2 is winner",Toast.LENGTH_LONG).show(); + } + + } + + } + + void AutoPlay(){ + + ArrayList EmptyCells= new ArrayList(); // all un selected cells + //Find empty cells + + for (int cellID=1; cellID<10;cellID++){ + if (!( Player1.contains(cellID) || Player2.contains(cellID))){ + EmptyCells.add(cellID); + } + } + + Random r= new Random(); + int RandIndex=r.nextInt(EmptyCells.size()- 0)+ 0; // if size =3 , select (0,1,2) + int CellID=EmptyCells.get(RandIndex); + + Button buSelected; + switch (CellID){ + + case 1 : + buSelected=(Button) findViewById(R.id.bu1); + break; + + case 2: + buSelected=(Button) findViewById(R.id.bu2); + break; + + case 3: + buSelected=(Button) findViewById(R.id.bu3); + break; + + case 4: + buSelected=(Button) findViewById(R.id.bu4); + break; + + case 5: + buSelected=(Button) findViewById(R.id.bu5); + break; + + case 6: + buSelected=(Button) findViewById(R.id.bu6); + break; + + case 7: + buSelected=(Button) findViewById(R.id.bu7); + break; + + case 8: + buSelected=(Button) findViewById(R.id.bu8); + break; + + case 9: + buSelected=(Button) findViewById(R.id.bu9); + break; + default: + buSelected=(Button) findViewById(R.id.bu1); + break; + + } + PlayGame(CellID, buSelected); + } +} diff --git a/TicTacToyGame/app/src/main/res/layout/activity_main.xml b/TicTacToyGame/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000000..ee3353f796f0 --- /dev/null +++ b/TicTacToyGame/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,99 @@ + + + + + +