Skip to content

Commit

Permalink
initial project code
Browse files Browse the repository at this point in the history
  • Loading branch information
thevery committed Sep 11, 2014
1 parent f442d1b commit 613e3d5
Show file tree
Hide file tree
Showing 19 changed files with 519 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
20 changes: 20 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "20.0.0"

defaultConfig {
applicationId "ru.ifmo.md.lesson1"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/opt/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 *;
#}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.ifmo.md.lesson1">

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.NoActionBar">
<activity
android:name=".MyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
29 changes: 29 additions & 0 deletions app/src/main/java/ru/ifmo/md/lesson1/MyActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.ifmo.md.lesson1;

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


public class MyActivity extends Activity {

private WhirlView whirlView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
whirlView = new WhirlView(this);
setContentView(whirlView);
}

@Override
public void onResume() {
super.onResume();
whirlView.resume();
}

@Override
public void onPause() {
super.onPause();
whirlView.pause();
}
}
113 changes: 113 additions & 0 deletions app/src/main/java/ru/ifmo/md/lesson1/WhirlView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package ru.ifmo.md.lesson1;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import java.util.Random;

/**
* Created by thevery on 11/09/14.
*/
class WhirlView extends SurfaceView implements Runnable {
int [][] field = null;
int width = 0;
int height = 0;
int scale = 4;
final int MAX_COLOR = 10;
int[] palette = {0xFFFF0000, 0xFF800000, 0xFF808000, 0xFF008000, 0xFF00FF00, 0xFF008080, 0xFF0000FF, 0xFF000080, 0xFF800080, 0xFFFFFFFF};
SurfaceHolder holder;
Thread thread = null;
volatile boolean running = false;

public WhirlView(Context context) {
super(context);
holder = getHolder();
}

public void resume() {
running = true;
thread = new Thread(this);
thread.start();
}

public void pause() {
running = false;
try {
thread.join();
} catch (InterruptedException ignore) {}
}

public void run() {
while (running) {
if (holder.getSurface().isValid()) {
long startTime = System.nanoTime();
Canvas canvas = holder.lockCanvas();
updateField();
onDraw(canvas);
holder.unlockCanvasAndPost(canvas);
long finishTime = System.nanoTime();
Log.i("TIME", "Circle: " + (finishTime - startTime) / 1000000);
try {
Thread.sleep(16);
} catch (InterruptedException ignore) {}
}
}
}

@Override
public void onSizeChanged(int w, int h, int oldW, int oldH) {
width = w/scale;
height = h/scale;
initField();
}

void initField() {
field = new int[width][height];
Random rand = new Random();
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
field[x][y] = rand.nextInt(MAX_COLOR);
}
}
}

void updateField() {
int[][] field2 = new int[width][height];
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {

field2[x][y] = field[x][y];

for (int dx=-1; dx<=1; dx++) {
for (int dy=-1; dy<=1; dy++) {
int x2 = x + dx;
int y2 = y + dy;
if (x2<0) x2 += width;
if (y2<0) y2 += height;
if (x2>=width) x2 -= width;
if (y2>=height) y2 -= height;
if ( (field[x][y]+1) % MAX_COLOR == field[x2][y2]) {
field2[x][y] = field[x2][y2];
}
}
}
}
}
field = field2;
}

@Override
public void onDraw(Canvas canvas) {
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
Paint paint = new Paint();
paint.setColor(palette[field[x][y]]);
canvas.drawRect(x*scale, y*scale, (x+1)*scale, (y+1)*scale, paint);
}
}
}
}
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-mdpi/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.
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-xxhdpi/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.
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_my.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<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=".MyActivity">

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

</RelativeLayout>
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Whirl</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>

</resources>
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
}
}
18 changes: 18 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
Loading

0 comments on commit 613e3d5

Please sign in to comment.