Skip to content

Commit

Permalink
Uploading img to server
Browse files Browse the repository at this point in the history
  • Loading branch information
MamdouhRElNakeeb committed May 4, 2019
1 parent 37d9f6d commit 959bd48
Show file tree
Hide file tree
Showing 38 changed files with 81 additions and 83 deletions.
File renamed without changes.
4 changes: 0 additions & 4 deletions SmartShopping/.idea/encodings.xml

This file was deleted.

15 changes: 0 additions & 15 deletions SmartShopping/.idea/gradle.xml

This file was deleted.

9 changes: 0 additions & 9 deletions SmartShopping/.idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions SmartShopping/.idea/runConfigurations.xml

This file was deleted.

This file was deleted.

File renamed without changes.
6 changes: 4 additions & 2 deletions SmartShopping/app/build.gradle → app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ahmedkhaled.smartshopping"
minSdkVersion 24
applicationId "com.smartshopping"
minSdkVersion 20
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -25,4 +25,6 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.amitshekhar.android:android-networking:1.0.2'
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ahmedkhaled.smartshopping">
package="com.smartshopping">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"> </uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"> </uses-permission>
<uses-permission android:name="android.permission.CAMERA"> </uses-permission>
<uses-permission android:name="android.permission.INTERNET"> </uses-permission>
<uses-feature android:name="android.hardware.camera"> </uses-feature>



<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -26,4 +27,5 @@

</application>


</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ahmedkhaled.smartshopping;
package com.smartshopping;

import android.Manifest;
import android.content.Intent;
Expand All @@ -17,13 +17,29 @@
import android.widget.Toast;


import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.common.ANRequest;
import com.androidnetworking.common.Priority;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.JSONArrayRequestListener;
import com.androidnetworking.interfaces.JSONObjectRequestListener;
import com.androidnetworking.interfaces.OkHttpResponseAndJSONObjectRequestListener;
import com.androidnetworking.interfaces.OkHttpResponseAndStringRequestListener;
import com.androidnetworking.interfaces.UploadProgressListener;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import okhttp3.Response;


public class MainActivity extends AppCompatActivity
{
Expand All @@ -49,6 +65,7 @@ protected void onCreate(Bundle savedInstanceState)
setContentView(R.layout.activity_main);

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

b.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
Expand All @@ -58,7 +75,7 @@ public void onClick(View v)
try
{
//set time in mili
Thread.sleep(5000);
Thread.sleep(1000);

}
catch (Exception e)
Expand Down Expand Up @@ -91,14 +108,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data)
if(file.exists())
{
// Test if it created the file correctly
// Toast.makeText(this, "File is found!", Toast.LENGTH_SHORT).show();
// Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
// ImageView myImage = (ImageView) findViewById(R.id.barcodeImage);
// myImage.setImageBitmap(myBitmap);
Toast.makeText(this, "File is found!", Toast.LENGTH_SHORT).show();
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.barcodeImage);
myImage.setImageBitmap(myBitmap);

uploadImage(file);

// TODO
// uploadImage(file);
}

}
Expand All @@ -115,6 +131,7 @@ public void capturePhoto()

public void checkAndRequestPermission()
{

List<String> listPermissionsNeeded = new ArrayList<>();
for (String perm : appPermissions)
{
Expand Down Expand Up @@ -155,8 +172,51 @@ public File createFile(Bitmap bitmap)
}


public void uploadImage()
public void uploadImage(File file)
{
// TODO

Log.d("fileee", file.getAbsolutePath());

ANRequest.MultiPartBuilder multiPartBuilder = AndroidNetworking.upload("http://34.73.23.49:5000/upload");

multiPartBuilder
.addMultipartFile("image", file)
.setTag("image")
.setPriority(Priority.HIGH)
.build()
.setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
Log.d("progress", String.valueOf(bytesUploaded) + " / " + String.valueOf(totalBytes));
}
})
.getAsOkHttpResponseAndJSONObject(new OkHttpResponseAndJSONObjectRequestListener() {
@Override
public void onResponse(Response okHttpResponse, JSONObject response) {
Log.d("JSON", response.toString());
}

@Override
public void onError(ANError anError) {
Log.d("eerrrrr", "errroor ya 3amaaam");
Log.d("err", anError.getErrorBody());
}
});

}
}


//
//.getAsJSONArray(new JSONArrayRequestListener() {
//@Override
//public void onResponse(JSONArray response) {
// Log.v("JSON","GOT RESPONSE");
// }
//
//@Override
//public void onError(ANError anError) {
//
// }
// });
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ahmedkhaled.smartshopping;
package com.smartshopping;

import org.junit.Test;

Expand Down
2 changes: 1 addition & 1 deletion SmartShopping/build.gradle → build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:3.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu May 02 22:31:30 EET 2019
#Sat May 04 18:19:20 EET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
0 SmartShopping/gradlew → gradlew
100644 → 100755
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 959bd48

Please sign in to comment.