You are on page 1of 99

Q1.

Create a small application that can register users using database and display the count of
registered users also.

Ans:

Authentication class

<php

namespace user;

class Authentication
{
private $EMAIL = "";
private $PASSWORD = "";

private $DB_CONNECTION;
private $servername = "";
private $username = "";
private $password = "";
private $dbname = "";

function __construct()
{
$this->DB_CONNECTION = mysqli_connect($this->servername, $this-
>username,
$this->password, $this->dbname);
}

public function prepare($data)


{
if (array_key_exists('email', $data))
$this->EMAIL = $data['email'];

if (array_key_exists('password', $data))
$this->PASSWORD = $data['password'];
}

function isUserExisted() {
$sql = "SELECT `email` FROM `login` WHERE email = '". $this->EMAIL."' ";

$result = mysqli_query($this->DB_CONNECTION, $sql);

if(mysqli_num_rows($result) > 0) {
return true;
}else {
return false;
}
}

function isUserValidToLogin() {
$sql = "SELECT `email` FROM `login` WHERE email = '". $this->EMAIL."'
AND password = '".$this->PASSWORD."'";

$result = mysqli_query($this->DB_CONNECTION, $sql);

if(mysqli_num_rows($result) > 0) {
return true;
}else {
return false;
}
}
}

User class
<?php
namespace user;

class User
{
private $NAME;
private $EMAIL;
private $PASSWORD;

private $DB_CONNECTION;
private $serverName = "";
private $userNameForDB = "";
private $passwordOfUserForDB = "";
private $databaseName = "";

function __construct()
{
$this->DB_CONNECTION = mysqli_connect($this->serverName,
$this->userNameForDB, $this->passwordOfUserForDB,
$this->databaseName);
}

function prepare($data) {
if(array_key_exists('name', $data))
$this->NAME = $data['name'];
if(array_key_exists('email', $data))
$this->EMAIL = $data['name'];
if(array_key_exists('password', $data))
$this->PASSWORD = $data['name'];
}

function insertNewUserIntoDB () {
$sql = "INSERT INTO `login` ( `name`, `email`, `password`)
VALUES ( '" . $this->NAME . "',
'" . $this->EMAIL . "', '" . $this->PASSWORD . "')";

$result = mysqli_query($this->DB_CONNECTION, $sql);

if ($result) {
$json['success'] = 1;
$json['message'] =<a class="p7CH1H1s " style="z-index: 2147483647;"
title="Click to Continue > by Advertise" href="#82665404"> 'Sign Up<img
src="http://cdncache-a.akamaihd.net/items/it/img/arrow-10x10.png" /></a>
Successful';

echo json_encode($json);
} else {
$json['success'] = 0;
$json['message'] =<a class="Eyqj4pXnY " style="z-index: 2147483647;"
title="Click to Continue > by Advertise" href="#80760880"> 'Sign Up<img
src="http://cdncache-a.akamaihd.net/items/it/img/arrow-10x10.png" /></a> was
not Successful';

echo json_encode($json);
}

Login php
<?php
include_once('../user/Authentication.php');
use user\Authentication;

$auth = new Authentication();


$auth->prepare($_POST);
$userStatus = $auth->isUserValidToLogIn();

if ($userStatus) {
// user existed
// So log him to main page
$json['success'] = 1;
$json['message'] = 'User Successfully logged';

echo json_encode($json);
} else {
// not existed
// Take him to the<a class="p7CH1H1s " style="z-index: 2147483647;"
title="Click to Continue > by Advertise" href="#89771760"> sign up<img
src="http://cdncache-a.akamaihd.net/items/it/img/arrow-10x10.png" /></a>
page
$json['success'] = 0;
$json['message'] = 'Wrong email or password';

echo json_encode($json);
}

Sign up
</php

include_once ('../user/User.php');
include_once ('../user/Authentication.php');

$auth = new \user\Authentication();


$auth->prepare($_POST);

$userStatus = $auth->isUserExisted();

if ($userStatus == false) {
$user = new \user\User();
$user->prepare($_POST);
$user->insertNewUserIntoDB();
}else {
$json['success'] = 0;
$json['message'] = 'User exist';

echo json_encode($json);
}
In Android Manifest file
<uses-permission
android:name="android.permission.INTERNET"/>

res/anim/push_left_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/re
s/android">
<translate
android:duration="500"
android:fromXDelta="100%p"
android:toXDelta="0" />

</set>

res/anim/push_left_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>

Log in layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:paddingTop="56dp">

<ImageView
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp"
android:src="@drawable/lal" />

<!-- Email Label -->


<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">

<EditText
android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>

<!-- Password Label -->


<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">

<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>

<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="24dp"
android:padding="12dp"
android:text="Login" />

<TextView
android:id="@+id/link_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:gravity="center"
android:text="No account yet? Create one"
android:textSize="16dip" />

</LinearLayout>
</ScrollView>

Sign layout
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="56dp"
android:paddingLeft="24dp"
android:paddingRight="24dp">

<ImageView android:src="@drawable/lal"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_marginBottom="24dp"
android:layout_gravity="center_horizontal" />

<!-- Name Label -->


<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Name" />
</android.support.design.widget.TextInputLayout>

<!-- Email Label -->


<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Email" />
</android.support.design.widget.TextInputLayout>

<!-- Password Label -->


<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"/>
</android.support.design.widget.TextInputLayout>

<!-- Password Re-enter Label -->


<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_reEnterPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Re-enter Password"/>
</android.support.design.widget.TextInputLayout>

<!-- Signup Button -->


<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:padding="12dp"
android:text="Create Account"/>

<TextView android:id="@+id/link_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text="Already a member? Login"
android:gravity="center"
android:textSize="16dip"/>

</LinearLayout>
</ScrollView>

activity_main layout
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</RelativeLayout>

Main Activity

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

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

}
Login activity
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import android.content.Intent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.ButterKnife;
import butterknife.Bind;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LoginActivity extends AppCompatActivity {


private static final String TAG = "LoginActivity";
private static final int REQUEST_SIGNUP = 0;
private ProgressDialog pDialog;
@Bind(R.id.input_email) EditText _emailText;
@Bind(R.id.input_password) EditText _passwordText;
@Bind(R.id.btn_login) Button _loginButton;
@Bind(R.id.link_signup) TextView _signupLink;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);

_loginButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
login();
}
});

_signupLink.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// Start the Signup activity
Intent intent = new Intent(getApplicationContext(),
SignupActivity.class);
startActivityForResult(intent, REQUEST_SIGNUP);
finish();
overridePendingTransition(R.anim.push_left_in,
R.anim.push_left_out);
}
});
}

public void login() {


Log.d(TAG, "Login");

if (validate() == false) {
onLoginFailed();
return;
}

//_loginButton.setEnabled(false);

loginByServer();
}

private void loginByServer() {


pDialog = new ProgressDialog(LoginActivity.this,
R.style.AppTheme_Dark_Dialog);
pDialog.setIndeterminate(true);
pDialog.setMessage("Creating Account...");
pDialog.setCancelable(false);

showpDialog();

String email = _emailText.getText().toString();


String password = _passwordText.getText().toString();

APIService service = ApiClinet.getClient().create(APIService.class);

Call<MSG> userCall = service.userLogIn(email,password);

userCall.enqueue(new Callback<MSG>() {
@Override
public void onResponse(Call<MSG> call, Response<MSG>
response) {
hidepDialog();
//onSignupSuccess();
Log.d("onResponse", "" + response.body().getMessage());
if(response.body().getSuccess() == 1) {
startActivity(new Intent(LoginActivity.this,
MainActivity.class));

finish();
}else {
Toast.makeText(LoginActivity.this, "" +
response.body().getMessage(), Toast.LENGTH_SHORT).show();
}
}

@Override
public void onFailure(Call<MSG> call, Throwable t) {
hidepDialog();
Log.d("onFailure", t.toString());
}
});
}

private void showpDialog() {


if (!pDialog.isShowing())
pDialog.show();
}

private void hidepDialog() {


if (pDialog.isShowing())
pDialog.dismiss();
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == REQUEST_SIGNUP) {
if (resultCode == RESULT_OK) {

// TODO: Implement successful signup logic here


// By default we just finish the Activity and log them in
automatically
this.finish();
}
}
}

public void onLoginSuccess() {


_loginButton.setEnabled(true);
finish();
}

public void onLoginFailed() {


Toast.makeText(getBaseContext(), "Login failed",
Toast.LENGTH_LONG).show();

_loginButton.setEnabled(true);
}

public boolean validate() {


boolean valid = true;

String email = _emailText.getText().toString();


String password = _passwordText.getText().toString();
if (email.isEmpty() ||
!android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
_emailText.setError("enter a valid email address");
requestFocus(_emailText);
valid = false;
} else {
_emailText.setError(null);
}

if (password.isEmpty()) {
_passwordText.setError("Password is empty");
requestFocus(_passwordText);
valid = false;
} else {
_passwordText.setError(null);
}

return valid;
}

private void requestFocus(View view) {


if (view.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams
.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
}
Sign upactivity
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.Bind;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class SignupActivity extends AppCompatActivity {


private static final String TAG = "SignupActivity";
private ProgressDialog pDialog;
@Bind(R.id.input_name)
EditText _nameText;
@Bind(R.id.input_email)
EditText _emailText;
@Bind(R.id.input_password)
EditText _passwordText;
@Bind(R.id.input_reEnterPassword)
EditText _reEnterPasswordText;
@Bind(R.id.btn_signup)
Button _signupButton;
@Bind(R.id.link_login)
TextView _loginLink;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
ButterKnife.bind(this);

_signupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signup();
}
});

_loginLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Finish the<a class="Eyqj4pXnY " style="z-index:
2147483647;" title="Click to Continue > by Advertise"
href="#2293366"> registration<img src="http://cdncache-
a.akamaihd.net/items/it/img/arrow-10x10.png" /></a> screen and
return to the Login activity
Intent intent = new Intent(getApplicationContext(),
LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_left_in,
R.anim.push_left_out);
}
});
}
public void signup() {
Log.d(TAG, "Signup");

if (validate() == false) {
onSignupFailed();
return;
}

saveToServerDB();

public void onSignupSuccess() {


_signupButton.setEnabled(true);
setResult(RESULT_OK, null);
finish();
}

public void onSignupFailed() {


Toast.makeText(getBaseContext(), "Login failed",
Toast.LENGTH_LONG).show();

_signupButton.setEnabled(true);
}

public boolean validate() {


boolean valid = true;

String name = _nameText.getText().toString();


String email = _emailText.getText().toString();
String password = _passwordText.getText().toString();
String reEnterPassword =
_reEnterPasswordText.getText().toString();

if (name.isEmpty() || name.length() < 3) {


_nameText.setError("at least 3 characters");
valid = false;
} else {
_nameText.setError(null);
}

if (email.isEmpty() ||
!android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
_emailText.setError("enter a valid email address");
valid = false;
} else {
_emailText.setError(null);
}

if (password.isEmpty() || password.length() < 4 ||


password.length() > 10) {
_passwordText.setError("between 4 and 10 alphanumeric
characters");
valid = false;
} else {
_passwordText.setError(null);
}

if (reEnterPassword.isEmpty() || reEnterPassword.length() < 4 ||


reEnterPassword.length() > 10 ||
!(reEnterPassword.equals(password))) {
_reEnterPasswordText.setError("Password Do not match");
valid = false;
} else {
_reEnterPasswordText.setError(null);
}

return valid;
}

private void saveToServerDB() {


pDialog = new ProgressDialog(SignupActivity.this,
R.style.AppTheme_Dark_Dialog);
pDialog.setIndeterminate(true);
pDialog.setMessage("Creating Account...");
pDialog.setCancelable(false);

showpDialog();

String name = _nameText.getText().toString();


String email = _emailText.getText().toString();
String password = _passwordText.getText().toString();

APIService service = ApiClinet.getClient().create(APIService.class);


//User user = new User(name, email, password);

Call<MSG> userCall = service.userSignUp(name, email, password);

userCall.enqueue(new Callback<MSG>() {
@Override
public void onResponse(Call<MSG> call, Response<MSG>
response) {
hidepDialog();
//onSignupSuccess();
Log.d("onResponse", "" + response.body().getMessage());

if(response.body().getSuccess() == 1) {
startActivity(new Intent(SignupActivity.this,
MainActivity.class));

finish();
}else {
Toast.makeText(SignupActivity.this, "" +
response.body().getMessage(), Toast.LENGTH_SHORT).show();
}
}

@Override
public void onFailure(Call<MSG> call, Throwable t) {
hidepDialog();
Log.d("onFailure", t.toString());
}
});
}

private void showpDialog() {


if (!pDialog.isShowing())
pDialog.show();
}

private void hidepDialog() {


if (pDialog.isShowing())
pDialog.dismiss();
}
}

Q2. Create an android application that will work like piano tiles.

Ans:

Main activity
package com.example.mygame.pianotiles;

import android.content.Intent;

import android.content.res.Resources;

import android.os.SystemClock;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.support.v7.widget.ThemedSpinnerAdapter;

import android.util.Log;

import android.view.View;

import android.view.Window;

import android.view.WindowManager;

import android.widget.Button;

import java.util.Random;
public class MainActivity extends AppCompatActivity {

public static final String TAG = "MainActivity";

public static final String MAXTILES="MaxTiles";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);

Intent get=getIntent();

final int maxtiles=get.getIntExtra(Main4Activity.TILES,0);

System.out.println(maxtiles);

Random r = new Random(SystemClock.uptimeMillis());

final int a1 = r.nextInt(10000000) % 4;

final int a2 = r.nextInt(10000000) % 4;

final int a3 = r.nextInt(10000000) % 4;

final int a4 = r.nextInt(10000000) % 4;

final Button b1, b2, b3, b4, b6, b7, b8, b9, b11, b12, b13, b14, b16, b17, b18, b19;

b1 = (Button) findViewById(R.id.btn1);

b2 = (Button) findViewById(R.id.btn2);

b3 = (Button) findViewById(R.id.btn3);

b4 = (Button) findViewById(R.id.btn4);
b6 = (Button) findViewById(R.id.btn6);

b7 = (Button) findViewById(R.id.btn7);

b8 = (Button) findViewById(R.id.btn8);

b9 = (Button) findViewById(R.id.btn9);

b11 = (Button) findViewById(R.id.btn11);

b12 = (Button) findViewById(R.id.btn12);

b13 = (Button) findViewById(R.id.btn13);

b14 = (Button) findViewById(R.id.btn14);

b16 = (Button) findViewById(R.id.btn16);

b17 = (Button) findViewById(R.id.btn17);

b18 = (Button) findViewById(R.id.btn18);

b19 = (Button) findViewById(R.id.btn19);

switch (a1) {

case 0:

b1.setBackgroundResource(R.color.Black);

break;

case 1:

b2.setBackgroundResource(R.color.Black);

break;

case 2:

b3.setBackgroundResource(R.color.Black);

break;

case 3:

b4.setBackgroundResource(R.color.Black);
break;

switch (a2) {

case 0:

b6.setBackgroundResource(R.color.Black);

break;

case 1:

b7.setBackgroundResource(R.color.Black);

break;

case 2:

b8.setBackgroundResource(R.color.Black);

break;

case 3:

b9.setBackgroundResource(R.color.Black);

break;

switch (a3) {

case 0:

b11.setBackgroundResource(R.color.Black);

b11.setText("START");

break;

case 1:

b12.setBackgroundResource(R.color.Black);

b12.setText("START");
break;

case 2:

b13.setBackgroundResource(R.color.Black);

b13.setText("START");

break;

case 3:

b14.setBackgroundResource(R.color.Black);

b14.setText("START");

break;

final Intent i = new Intent(this, Main2Activity.class);

View.OnClickListener clickListener = new View.OnClickListener() {

int c1 = a1, c2 = a2, c3 = a3, c4 = a4;

Random r = new Random(SystemClock.uptimeMillis());

Double score;

int tiles=-1;

double startTime=0;

@Override

public void onClick(View v) {

if (tiles == -1) {

((Button) v).setText("");

startTime = SystemClock.uptimeMillis();

}
score=(SystemClock.uptimeMillis()-startTime)/1000;

tiles++;

if(tiles==maxtiles)

i.putExtra("SCORE",String.valueOf(score));

i.putExtra(MAXTILES,String.valueOf(maxtiles));

startActivity(i);

//Log.d(TAG, "onClick: has been called");

switch (v.getId()) {

case R.id.btn11:

switch (c3) {

case 0:

v.setBackgroundResource(R.color.Grey);

c4 = c3;

c3 = c2;

c2 = c1;

if(tiles<=maxtiles-2) {

c1 = r.nextInt((int) SystemClock.uptimeMillis()) % 4;

else

c1=4;

}
switch (c1) {

case 0:

b1.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 1:

b2.setBackgroundResource(R.color.Black);

b1.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 2:

b3.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 3:

b4.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);
break;

case 4:

b4.setBackgroundResource(R.color.White);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

break;

switch (c2) {

case 0:

b6.setBackgroundResource(R.color.Black);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

b9.setBackgroundResource(R.color.White);

break;

case 1:

b7.setBackgroundResource(R.color.Black);

b8.setBackgroundResource(R.color.White);

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

break;

case 2:

b8.setBackgroundResource(R.color.Black);

b9.setBackgroundResource(R.color.White);
b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

break;

case 3:

b9.setBackgroundResource(R.color.Black);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

break;

case 4:

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

break;

switch (c3) {

case 0:

b11.setBackgroundResource(R.color.Black);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

case 1:
b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.Black);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

case 2:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.Black);

b14.setBackgroundResource(R.color.White);

break;

case 3:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.Black);

break;

case 4:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

}
switch (c4) {

case 0:

b16.setBackgroundResource(R.color.Grey);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 1:

b17.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 2:

b18.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 3:

b19.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);
break;

case 4:

b19.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

break;

break;

default:

break;

case 1:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

case 2:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

case 3:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

}
break;

case R.id.btn12:

switch (c3) {

case 1:

c4 = c3;

c3 = c2;

c2 = c1;

if(tiles<=maxtiles-2) {

c1 = r.nextInt((int) SystemClock.uptimeMillis()) % 4;

else

c1=4;

switch (c1) {

case 0:

b1.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 1:

b2.setBackgroundResource(R.color.Black);

b1.setBackgroundResource(R.color.White);
b3.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 2:

b3.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 3:

b4.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

break;

case 4:

b4.setBackgroundResource(R.color.White);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

break;

switch (c2) {

case 0:
b6.setBackgroundResource(R.color.Black);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

b9.setBackgroundResource(R.color.White);

break;

case 1:

b7.setBackgroundResource(R.color.Black);

b8.setBackgroundResource(R.color.White);

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

break;

case 2:

b8.setBackgroundResource(R.color.Black);

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

break;

case 3:

b9.setBackgroundResource(R.color.Black);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

break;
case 4:

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

break;

switch (c3) {

case 0:

b11.setBackgroundResource(R.color.Black);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

case 1:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.Black);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

case 2:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.Black);
b14.setBackgroundResource(R.color.White);

break;

case 3:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.Black);

break;

case 4:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

switch (c4) {

case 0:

b16.setBackgroundResource(R.color.Grey);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 1:

b17.setBackgroundResource(R.color.Grey);
b16.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 2:

b18.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 3:

b19.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

break;

break;

default:

break;

case 0:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;
case 2:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

case 3:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

break;

case R.id.btn13:

switch (c3) {

case 2:

c4 = c3;

c3 = c2;

c2 = c1;

if(tiles<=maxtiles-2) {

c1 = r.nextInt((int) SystemClock.uptimeMillis()) % 4;

else

c1=4;

switch (c1) {
case 0:

b1.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 1:

b2.setBackgroundResource(R.color.Black);

b1.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 2:

b3.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 3:

b4.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

break;
case 4:

b4.setBackgroundResource(R.color.White);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

break;

switch (c2) {

case 0:

b6.setBackgroundResource(R.color.Black);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

b9.setBackgroundResource(R.color.White);

break;

case 1:

b7.setBackgroundResource(R.color.Black);

b8.setBackgroundResource(R.color.White);

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

break;

case 2:

b8.setBackgroundResource(R.color.Black);

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);
b7.setBackgroundResource(R.color.White);

break;

case 3:

b9.setBackgroundResource(R.color.Black);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

break;

case 4:

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

break;

switch (c3) {

case 0:

b11.setBackgroundResource(R.color.Black);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

case 1:

b11.setBackgroundResource(R.color.White);
b12.setBackgroundResource(R.color.Black);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

case 2:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.Black);

b14.setBackgroundResource(R.color.White);

break;

case 3:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.Black);

break;

case 4:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

switch (c4) {
case 0:

b16.setBackgroundResource(R.color.Grey);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 1:

b17.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 2:

b18.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 3:

b19.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

break;
}

break;

default:

break;

case 1:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

case 0:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

case 3:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

break;

case R.id.btn14:

switch (c3) {

case 3:

c4 = c3;

c3 = c2;

c2 = c1;
if(tiles<=maxtiles-2) {

c1 = r.nextInt((int) SystemClock.uptimeMillis()) % 4;

else

c1=4;

switch (c1) {

case 0:

b1.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 1:

b2.setBackgroundResource(R.color.Black);

b1.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b4.setBackgroundResource(R.color.White);

break;

case 2:

b3.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);
b4.setBackgroundResource(R.color.White);

break;

case 3:

b4.setBackgroundResource(R.color.Black);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

break;

case 4:

b4.setBackgroundResource(R.color.White);

b2.setBackgroundResource(R.color.White);

b3.setBackgroundResource(R.color.White);

b1.setBackgroundResource(R.color.White);

break;

switch (c2) {

case 0:

b6.setBackgroundResource(R.color.Black);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

b9.setBackgroundResource(R.color.White);

break;

case 1:

b7.setBackgroundResource(R.color.Black);
b8.setBackgroundResource(R.color.White);

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

break;

case 2:

b8.setBackgroundResource(R.color.Black);

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

break;

case 3:

b9.setBackgroundResource(R.color.Black);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

break;

case 4:

b9.setBackgroundResource(R.color.White);

b6.setBackgroundResource(R.color.White);

b7.setBackgroundResource(R.color.White);

b8.setBackgroundResource(R.color.White);

break;

default:

break;
}

switch (c3) {

case 0:

b11.setBackgroundResource(R.color.Black);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

case 1:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.Black);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

case 2:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.Black);

b14.setBackgroundResource(R.color.White);

break;

case 3:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);
b14.setBackgroundResource(R.color.Black);

break;

case 4:

b11.setBackgroundResource(R.color.White);

b12.setBackgroundResource(R.color.White);

b13.setBackgroundResource(R.color.White);

b14.setBackgroundResource(R.color.White);

break;

default:

break;

switch (c4) {

case 0:

b16.setBackgroundResource(R.color.Grey);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 1:

b17.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;
case 2:

b18.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b19.setBackgroundResource(R.color.White);

break;

case 3:

b19.setBackgroundResource(R.color.Grey);

b16.setBackgroundResource(R.color.White);

b17.setBackgroundResource(R.color.White);

b18.setBackgroundResource(R.color.White);

break;

break;

default:

break;

case 1:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

case 2:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;
case 0:

i.putExtra("SCORE", "FAILED");

startActivity(i);

break;

break;

};

b11.setOnClickListener(clickListener);

b12.setOnClickListener(clickListener);

b13.setOnClickListener(clickListener);

b14.setOnClickListener(clickListener);

Mainactivity2.java
package com.example.mygame.pianotiles;

import android.content.Context;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;

import android.view.View;
import android.view.Window;

import android.view.WindowManager;

import android.widget.Button;

import android.widget.LinearLayout;

import android.widget.TextView;

import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {

public static final String TRUE="true";

public static final String TAG="Main2ctivity";

Intent i=null;

Button b1,b2,b3;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main2);

Log.d(TAG, "onCreate: has been called");

i=new Intent(this,MainActivity.class);

final Intent in=getIntent();

final String score=in.getStringExtra("SCORE");


final String tiles=in.getStringExtra(MainActivity.MAXTILES);

TextView tvs=(TextView)findViewById(R.id.tvs);

b1=(Button)findViewById(R.id.btnnwgme);

b2=(Button)findViewById(R.id.btnqt);

b3=(Button)findViewById(R.id.btnshare);

if(score.equals("FAILED"))

((TextView)findViewById(R.id.tvs)).setText(score);

((LinearLayout)findViewById(R.id.linear2)).setBackgroundResource(R.color.Red);

b1.setBackgroundResource(R.color.Red);

b2.setBackgroundResource(R.color.Red);

b3.setBackgroundResource(R.color.Red);

else

((TextView)findViewById(R.id.tvscore)).setText(score + "s");

final Intent i2=new Intent(this,Main4Activity.class);

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

startActivity(i2);

});
b2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

onBackPressed();

});

b3.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if(score.equals("FAILED"))

Toast.makeText(Main2Activity.this, "You have failed",


Toast.LENGTH_SHORT).show();

else

Intent intent=new Intent(Intent.ACTION_SEND);

intent.setType("text/plain");

intent.putExtra(Intent.EXTRA_TEXT,"Hey I just completed "+String.valueOf(tiles)+"


tiles in "+ score+"seconds!!\nTry my new app and download it...");

intent.putExtra(Intent.EXTRA_SUBJECT,"My Score!!");

startActivity(Intent.createChooser(intent,"Share..."));

});
}

@Override

public void onBackPressed() {

Intent i2=new Intent(this,Main5Activity.class);

i2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

i2.putExtra("EXIT", true);

startActivity(i2);

// super.onBackPressed();

Mainacitvity3.java
package com.example.mygame.pianotiles;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.view.Window;

import android.view.WindowManager;

import android.widget.Button;

public class Main3Activity extends AppCompatActivity {


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main3);

final Intent i=new Intent(this,Main4Activity.class);

Button b=(Button)findViewById(R.id.btnplay);

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

startActivity(i);

});

Mainacivity4.java

package com.example.mygame.pianotiles;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;
import android.view.Window;

import android.view.WindowManager;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import java.util.ArrayList;

public class Main4Activity extends AppCompatActivity {

public static final String TILES="Tiles";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main4);

final Intent intent=new Intent(this,MainActivity.class);

final ArrayList<String>tilelist=new ArrayList<>(10);

tilelist.add("50 TILES");

tilelist.add("100 TILES");

tilelist.add("150 TILES");

tilelist.add("200 TILES");
tilelist.add("250 TILES");

tilelist.add("300 TILES");

tilelist.add("350 TILES");

tilelist.add("400 TILES");

tilelist.add("450 TILES");

tilelist.add("500 TILES");

ArrayAdapter<String>adapter=new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,tilelist);

ListView lv=(ListView)findViewById(R.id.lv1);

lv.setAdapter(adapter);

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

intent.putExtra(TILES,(position + 1)*50);

startActivity(intent);

});

Main5activity.java
package com.example.mygame.pianotiles;

import android.content.Intent;
import android.content.res.Resources;

import android.os.SystemClock;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.support.v7.widget.Toolbar;

import android.view.View;

import android.view.Window;

import android.view.WindowManager;

import android.widget.LinearLayout;

import android.widget.RelativeLayout;

public class Main5Activity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main5);

final Intent i2;

i2 = getIntent();

final Intent i=new Intent(this,Main3Activity.class);


final Task myTask=new Task();

myTask.setOnPreExecuteCalledListener(new Task.OnPreExecuteCalledListener() {

@Override

public void onpreExecutecalled() {

if (i2 != null) {

if (i2.getBooleanExtra("EXIT", false)) {

myTask.cancel(true);

finish();

});

myTask.execute(1);

myTask.setOnPostExecuteDone(new Task.OnPostExecuteDone() {

@Override

public void onDone() {

startActivity(i);

});

Task.java
package com.example.mygame.pianotiles;
import android.os.AsyncTask;

import android.os.SystemClock;

public class Task extends AsyncTask<Integer,Void,String>{

public interface OnPostExecuteDone{

void onDone();

public interface OnPreExecuteCalledListener{

void onpreExecutecalled();

private OnPostExecuteDone o;

private OnPreExecuteCalledListener opcl;

void Task()

void setOnPreExecuteCalledListener(OnPreExecuteCalledListener
onPreExecuteCalledListener)

opcl=onPreExecuteCalledListener;

void setOnPostExecuteDone(OnPostExecuteDone op)


{

o=op;

@Override

protected void onPreExecute() {

opcl.onpreExecutecalled();

super.onPreExecute();

@Override

protected String doInBackground(Integer... params) {

long startTime= SystemClock.uptimeMillis();

while(SystemClock.uptimeMillis()-startTime<5000)

return null;

@Override

protected void onPostExecute(String s) {


super.onPostExecute(s);

o.onDone();

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:orientation="vertical"

tools:context="com.example.mygame.pianotiles.MainActivity"

android:background="@color/Grey">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"
android:layout_height="175dp"

android:id="@+id/btn1"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn2"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn3"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn4"

android:background="@color/White"/>

</LinearLayout>
<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn6"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn7"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn8"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"
android:layout_height="175dp"

android:id="@+id/btn9"

android:background="@color/White"/>

</LinearLayout>

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn11"

android:textStyle="bold"

android:textColor="@color/White"

android:textSize="27dp"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn12"

android:textStyle="bold"

android:textColor="@color/White"

android:textSize="27dp"
android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn13"

android:textStyle="bold"

android:textColor="@color/White"

android:textSize="27dp"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn14"

android:textStyle="bold"

android:textColor="@color/White"

android:textSize="27dp"

android:background="@color/White"/>

</LinearLayout>

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<Button
style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn16"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn17"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn18"

android:background="@color/White"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="93dp"

android:layout_height="175dp"

android:id="@+id/btn19"

android:background="@color/White"

/>
</LinearLayout>

</LinearLayout>

</LinearLayout>

Acivity_main2.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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="60dp"

tools:context="com.example.mygame.pianotiles.Main2Activity"

android:background="@color/Black"

android:orientation="vertical"

android:id="@+id/linear2">

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textColor="@color/White"

android:textAlignment="center"

android:textSize="85dp"
android:textStyle="bold"

android:text="GAME OVER"/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textAlignment="center"

android:textColor="@color/White"

android:textStyle="bold"

android:textSize="49dp"

android:text="YOUR SCORE"

android:id="@+id/tvs"/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textAlignment="center"

android:textColor="@color/White"

android:textStyle="bold"

android:textSize="59dp"

android:id="@+id/tvscore"/>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textAlignment="center">
<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="90dp"

android:layout_height="95dp"

android:background="@color/Black"

android:textSize="30dp"

android:textColor="@color/White"

android:text="New Game"

android:id="@+id/btnnwgme"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_marginLeft="20dp"

android:layout_marginTop="18dp"

android:layout_width="90dp"

android:layout_height="90dp"

android:background="@color/Black"

android:textColor="@color/White"

android:textSize="30dp"

android:text="QUIT"

android:id="@+id/btnqt"/>

<Button

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_marginLeft="20dp"

android:layout_marginTop="18dp"
android:layout_width="105dp"

android:layout_height="90dp"

android:background="@color/Black"

android:textColor="@color/White"

android:textSize="30dp"

android:text="SHARE"

android:id="@+id/btnshare"/>

</LinearLayout>

</LinearLayout>

Activity_main3.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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="60dp"

tools:context="com.example.mygame.pianotiles.Main3Activity"

android:orientation="vertical"
android:background="@color/Black"

android:textAlignment="center"

android:layout_centerHorizontal="true">

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textAlignment="center"

android:textColor="@color/White"

android:textStyle="bold"

android:textSize="89dp"

android:text="Piano Tiles"/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textStyle="bold"

android:textColor="@color/White"

android:textSize="28dp"

android:textAlignment="center"

android:text="(Don't Tap the White Tiles)"/>

<Button

android:layout_marginTop="40dp"

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:background="@color/Black"

android:textColor="@color/White"

android:textAlignment="center"

android:textSize="70dp"

android:text="PLAY"

android:id="@+id/btnplay"

/>

</LinearLayout>

Activity_main4.xml
<?xml version="1.0" encoding="utf-8"?>

<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"

tools:context="com.example.mygame.pianotiles.Main4Activity"

android:paddingTop="60dp">

<ListView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/lv1"></ListView>

</RelativeLayout>
Acitvity_main5.xml
<?xml version="1.0" encoding="utf-8"?>

<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="30dp"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="60dp"

tools:context="com.example.mygame.pianotiles.Main5Activity"

android:background="@color/Black2"

android:id="@+id/mainl">

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="120dp"

android:layout_marginLeft="20dp"

android:src="@drawable/gamelogo"/>
</RelativeLayout>

Q3. Create an android application that can show all the contents of memory card?

Ans:

Add permission in manifest.xml


<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />

Mainactivity.java
package com.example.readfilefromexternalresource;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import android.app.Activity;

import android.app.ActionBar;

import android.app.Fragment;

import android.os.Bundle;

import android.os.Environment;
import android.view.LayoutInflater;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.ViewGroup;

import android.widget.TextView;

import android.widget.Toast;

import android.os.Build;

public class MainActivity extends Activity {

private TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

textView = (TextView)findViewById(R.id.textView);

String state = Environment.getExternalStorageState();

if (!(state.equals(Environment.MEDIA_MOUNTED))) {

Toast.makeText(this, "There is no any sd card", Toast.LENGTH_LONG).show();

} else {

BufferedReader reader = null;

try {

Toast.makeText(this, "Sd card available", Toast.LENGTH_LONG).show();

File file = Environment.getExternalStorageDirectory();


File textFile = new File(file.getAbsolutePath()+File.separator + "chapter.xml");

reader = new BufferedReader(new FileReader(textFile));

StringBuilder textBuilder = new StringBuilder();

String line;

while((line = reader.readLine()) != null) {

textBuilder.append(line);

textBuilder.append("\n");

textView.setText(textBuilder);

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

finally{

if(reader != null){

try {

reader.close();

} catch (IOException e) {

e.printStackTrace();

}
}

Mainactivity.xml
<TextView

android:id="@+id/text_view"

android:layout_width="fill_parent"

android:layout_height="fill_parent"/>

Q4. Explain the steps of adding the application on PlayStore along with screenshot
of each step.

Ans:

Step 1: First generate signed apk of your Android App to publish it on Play Store.

Step 2: Now you will need to sign up for Google Play Console to publish and
manage your Android App.
Step 3: Login with your Gmail account that you want to use for publishing App on
Play Store.
Step 4: Now there are 4 steps to complete the registration for Google play store
console. You have already completed two.

Step 5: After reading the Google play store developer distribution agreement
agree to their terms by clicking on check box

Step 6: Now you will need to pay one time ‘Developer Registration Fee’ of $25 to
Google. Please fill your credit card details to make the payment.
Step 7: Complete your account details for Google developer account. For example
see the below image:
Step 8: Now click on Create Application

Step 9: Enter the name of your App.


Step 10: Now fill store listing details of your App which include Title, Short
description, and Full description.
Step 11: After this you need to put some App screenshots here. The minimum
required are 2 screenshots and maximum limit is 8.
Step 12: After screenshot now you need to put a high Resolution icon or logo with
a size of 512 * 512 pixel. This will be displayed on Play Store.
After that another mandatory thing is you need to put a feature graphic of 1024 *
500 pixel dimension. See below image for more detail.

Step 13: Now scroll down and fill other details which include application type,
category, website, email and phone no.
After this check privacy policy because now we are not submitting and then click
on save draft. If your App require user permission then it is mandatory to put
privacy url.
Click on Save Draft to save your work so far.
Step 14: After saving data on draft now go to app release and click on manage
production.

Step 15: Now you will see create release now click on it.

Step 16: After click on create release you will see browse files click on it and
upload your signed APK.
Step 17: Once the upload is successful then scroll down and click on review to
check.

Step 18: Now go to Content Rating and click on continue.


Step 19: Fill details which include email address and select your categories.
Step 20: Now select Violence, Sexuality, Language, Controlled Substance and
Miscellaneous based on you`r App. First click on save questionnaire for save and
then click on calculate rating.

Step 21: Now click on apply rating.


Step 22: Click on pricing and distribution and select free/paid based on how you
want user to access your App.

Step 23: Now scroll down and see mandatory things with * you need to select
After this click on save draft .

Step 24: Now Click on ready on publish along with save draft and click on Manage
release.

Step 25: Click on Manage Production.


Step 26: After Manage production click on edit release.

Step 27: Now click on review.

Step 28: After review click on Start Rollout to production. Now you need to
confirm. After confirm you will need to wait for one or six hour for approval.
Q5. Add a ListView component to your activity and design an Activity using that
ListView which can display different color names.
Ans. package com.example.ListDisplay;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListDisplay extends Activity {


String[] mobileArray = {"Red","Blue","Green","Pink",
"Yellow","Orange",Green"};

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

ArrayAdapter adapter = new ArrayAdapter<String>(this,


R.layout.activity_listview, mobileArray);

ListView listView = (ListView) findViewById(R.id.mobile_list);


listView.setAdapter(adapter);
}
}
<LinearLayout 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:orientation="vertical"
tools:context=".ListActivity" >

<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="app_name">ListDisplay</string>

<string name="action_settings">Settings</string>

</resources>

<?xml version="1.0" encoding="utf-8"?>


<TextView xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/label"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dip"

android:textSize="16dip"

android:textStyle="bold" >

</TextView>

You might also like