Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nvmd committed Apr 23, 2012
2 parents f6b21d6 + 4f22dd7 commit 79f03df
Show file tree
Hide file tree
Showing 22 changed files with 502 additions and 163 deletions.
5 changes: 1 addition & 4 deletions client/android/Android.iml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
<option name="RUN_PROCESS_RESOURCES_MAVEN_TASK" value="true" />
<option name="GENERATE_UNSIGNED_APK" value="false" />
<option name="CUSTOM_DEBUG_KEYSTORE_PATH" value="" />
<option name="PACK_TEST_CODE" value="false" />
<option name="RUN_PROGUARD" value="false" />
<option name="PROGUARD_CFG_PATH" value="/proguard.cfg" />
<resOverlayFolders />
</configuration>
</facet>
</component>
Expand All @@ -35,6 +31,7 @@
</content>
<orderEntry type="jdk" jdkName="Android 2.3.3 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="classes" level="project" />
</component>
</module>

3 changes: 3 additions & 0 deletions client/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<activity android:name="SpendingsSumActivity"
android:label="@string/app_name">
</activity>
<activity android:name="SpendingsPeriodActivity"
android:label="@string/app_name">
</activity>
</application>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET"/>
Expand Down
3 changes: 2 additions & 1 deletion client/android/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<!--android:text="Hello World, Main"-->
<!--/>-->
<Button android:id="@+id/takePhoto" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Take photo"/>
<Button android:id="@+id/spendingsSum" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="View sum of all spendings"/>
<Button android:id="@+id/spendingsSum" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="All spendings"/>
<Button android:id="@+id/spendingsPeriod" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Spendings on period"/>
</LinearLayout>

38 changes: 38 additions & 0 deletions client/android/res/layout/spendingsperiod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/date1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Date 1"/>
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/date2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Date 2"/>
</LinearLayout>

</LinearLayout>

<TextView android:id="@+id/sum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Error has occurred!"/>
<Button android:id="@+id/goBack"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back"/>
</LinearLayout>
4 changes: 3 additions & 1 deletion client/android/res/layout/spendingssum.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/sum" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Current sum of your spendings is: 100500$"/>
<TextView android:id="@+id/sum" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Error has occurred!"/>
<Button android:id="@+id/goBack" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Back"/>
</LinearLayout>
6 changes: 6 additions & 0 deletions client/android/src/ru/spbau/cheque/Cheque.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.spbau.cheque;

import ru.spbau.cheque.recognition.BlueObject;

import java.io.Serializable;
import java.util.List;

Expand All @@ -23,4 +25,8 @@ public String toString() {
public List<BlueObject> getBlues(){
return table;
}

public String getCompany(){
return company;
}
}
88 changes: 81 additions & 7 deletions client/android/src/ru/spbau/cheque/DBOpenHelper.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package ru.spbau.cheque;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import ru.spbau.cheque.recognition.*;
import ru.spbau.cheque.recognition.BlueObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
* Classname:
Expand All @@ -14,23 +21,90 @@ public class DBOpenHelper extends SQLiteOpenHelper{
private static final int DB_VERSION = 1;
public static final String DB_NAME = "test";

public static final String TABLE_NAME = "blue_objects";
public static final String NAME = "name";
public static final String COUNT = "count";
public static final String PRICE = "price";
private static final String CREATE_TABLE = "create table " + TABLE_NAME + " ( _id integer primary key autoincrement, "
+ NAME + " TEXT, " + COUNT + " REAL, " + PRICE + " REAL)";
public static final String CHEQUE_TABLE_NAME = "cheques";
public static final String CHEQUE_DATE = "date";
public static final String CHEQUE_COMPANY = "company";
private static final String CHEQUE_CREATE_TABLE = "create table " + CHEQUE_TABLE_NAME + " ( _cheque_id integer primary key autoincrement, "
+ CHEQUE_DATE + " INTEGER, " + CHEQUE_COMPANY + " TEXT);";


public static final String BLUE_TABLE_NAME = "blue_objects";
public static final String BLUE_NAME = "name";
public static final String BLUE_COUNT = "count";
public static final String BLUE_PRICE = "price";
public static final String BLUE_CHEQUE_REF = "cheque_ref";
private static final String BLUE_CREATE_TABLE = "create table " + BLUE_TABLE_NAME + " ( _id integer primary key autoincrement, "
+ BLUE_NAME + " TEXT, " + BLUE_COUNT + " REAL, " + BLUE_CHEQUE_REF + " INTEGER, " + BLUE_PRICE + " REAL, FOREIGN KEY(" + BLUE_CHEQUE_REF + ") REFERENCES " + CHEQUE_TABLE_NAME + "(_id) ON DELETE CASCADE);";

public DBOpenHelper(Context context) {
super(context, DB_NAME, null,DB_VERSION);
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL(CREATE_TABLE);
sqLiteDatabase.execSQL(CHEQUE_CREATE_TABLE);
sqLiteDatabase.execSQL(BLUE_CREATE_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}

long nextLong(Random rng, long n) {
// error checking and 2^x checking removed for simplicity.
long bits, val;
do {
bits = (rng.nextLong() << 1) >>> 1;
val = bits % n;
} while (bits-val+(n-1) < 0L);
return val;
}

public void putChequeToDB(Cheque inpCheque){
SQLiteDatabase db = getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(DBOpenHelper.CHEQUE_COMPANY, inpCheque.getCompany());
final long millis = 1000;
final long seconds = 60;
final long minutes = 60;
final long hours = 24;
final long days = 356;
final long millisInYear = millis*seconds*minutes*hours*days;
cv.put(DBOpenHelper.CHEQUE_DATE, System.currentTimeMillis() - nextLong(myRand, millisInYear));
long chequeID = db.insert(DBOpenHelper.CHEQUE_TABLE_NAME, null, cv);
for (ru.spbau.cheque.recognition.BlueObject bl : inpCheque.getBlues()){
ContentValues bcv = new ContentValues();
bcv.put(DBOpenHelper.BLUE_NAME, bl.getName());
bcv.put(DBOpenHelper.BLUE_COUNT, bl.getCount());
bcv.put(DBOpenHelper.BLUE_PRICE, bl.getPrice());
bcv.put(DBOpenHelper.BLUE_CHEQUE_REF, chequeID);
db.insert(DBOpenHelper.BLUE_TABLE_NAME, null, bcv);
}
db.close();
}

public void fillDBWithRandomData(int chequesNum){
for (int i = 0; i < chequesNum; ++i){
putChequeToDB(getRandomCheque());
}
}

private static Integer blueCounter = 0;
private static final Random myRand = new Random(12345);

private Cheque getRandomCheque(){
int blueNum = myRand.nextInt(10);
List<ru.spbau.cheque.recognition.BlueObject> table = new ArrayList<ru.spbau.cheque.recognition.BlueObject>();
for (int i = 0; i < blueNum; ++i){
table.add(getRandomBlue());
}
return new Cheque("ROGA & KOPITA", table);
}

private ru.spbau.cheque.recognition.BlueObject getRandomBlue(){
String name = "Name" + blueCounter.toString();
float count = myRand.nextFloat() * 3;
float price = myRand.nextFloat() * 100;
return new BlueObject(name, count, price);
}
}
120 changes: 88 additions & 32 deletions client/android/src/ru/spbau/cheque/Main.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
package ru.spbau.cheque;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import ru.spbau.cheque.recognition.OcrFailedException;

import java.io.File;
import java.io.IOException;

public class Main extends Activity
{
static final int GET_PHOTO_FROM_CAMERA_REQUEST = 1;
static final int CROP = 2;
private Uri outputFileUri;
private Uri outputFileUri = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

outputFileUri = getIntent() != null && getIntent().getExtras() != null ? (Uri) getIntent().getExtras().get("outUri") : null;

setContentView(R.layout.main);
Button takePhotoBtn = (Button) findViewById(R.id.takePhoto);
Button spendingsSumBtn = (Button) findViewById(R.id.spendingsSum);
Button spendingsPeriodBtn = (Button) findViewById(R.id.spendingsPeriod);
takePhotoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent pictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "tmp.jpg");
outputFileUri = Uri.fromFile(file);
try{
startActivityForResult(pictureIntent, GET_PHOTO_FROM_CAMERA_REQUEST);
}
catch (Exception e)
{
System.out.println(e.getStackTrace());
}

ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "My demo image");
values.put(MediaStore.Images.Media.DESCRIPTION, "Image Captured by Camera via an Intent");

// File outputDir = getCacheDir(); // context being the Activity pointer
// File outputFile = null;
// try {
// outputFile = File.createTempFile("", ".jpg", outputDir);
// } catch (IOException e) {
// e.printStackTrace();
// }
// outputFileUri = Uri.fromFile(outputFile);

// outputFileUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
outputFileUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
getIntent().putExtra("outUri", outputFileUri);

pictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, outputFileUri);
// pictureIntent.putExtra("furi", outputFileUri);
//pictureIntent.setData(outputFileUri);

try{
startActivityForResult(pictureIntent, GET_PHOTO_FROM_CAMERA_REQUEST);
}
catch (Exception e)
{
System.out.println(e.getStackTrace());
}
}
});
spendingsSumBtn.setOnClickListener(new View.OnClickListener() {
Expand All @@ -46,35 +73,64 @@ public void onClick(View view) {
startActivity(intent);
}
});


spendingsPeriodBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Main.this, SpendingsPeriodActivity.class);
startActivity(intent);
}
});
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == Activity.RESULT_OK && requestCode == GET_PHOTO_FROM_CAMERA_REQUEST) {
Intent intent = new Intent("com.android.camera.action.CROP");
//Bitmap bmp = (Bitmap) intent.getExtras().get("intent");

Bitmap bmp = null;
try {
bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), outputFileUri);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

//try {
// new Recognizer().doRecognition(bmp, 0, 0, bmp.getWidth(), bmp.getHeight());
//} catch (Exception e) {
// e.printStackTrace();
//} catch (OcrFailedException e) {
// e.printStackTrace();
//}
return;
//Intent intent = new Intent("com.android.camera.action.CROP");
// intent.setClassName("com.android.camera", "com.android.camera.CropImage");
// intent.setClassName("com.android.gallery", "com.android.camera.CropImage");
intent.setType("image/*");
// Bitmap bmp = (Bitmap)data.getExtras().get("data");

//intent.setType("image/*");
// Bitmap bmp = (Bitmap)intent.getExtras().get("intent");

// Uri uri = data.getData();
intent.setData(outputFileUri);

intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
// intent.putExtra("return-data", true);
try {
startActivityForResult(intent, CROP);
}
catch(Exception e){
System.out.println(e.getStackTrace());
}
// Uri uri = intent.getData();
// intent.setData(outputFileUri);
//
// intent.putExtra("outputX", 200);
// intent.putExtra("outputY", 200);
// intent.putExtra("aspectX", 1);
// intent.putExtra("aspectY", 1);
// intent.putExtra("scale", true);
//// intent.putExtra("return-intent", true);
// try {
// startActivityForResult(intent, CROP);
// }
// catch(Exception e){
// System.out.println(e.getStackTrace());
// }
// Socket sock = null;
// try {
// Bitmap pic = (Bitmap) data.getExtras().get("data");
// Bitmap pic = (Bitmap) intent.getExtras().get("intent");
// sock = new Socket("192.168.222.169", 3843);
// OutputStream os = sock.getOutputStream();
// pic.compress(Bitmap.CompressFormat.JPEG, 100, os);
Expand Down
Loading

0 comments on commit 79f03df

Please sign in to comment.