uploading from android

parent 552c23ab
...@@ -44,15 +44,19 @@ android { ...@@ -44,15 +44,19 @@ android {
DefaultFlavor { DefaultFlavor {
resValue "string", "server", "https://pre.yottacode.com:1337" resValue "string", "server", "https://pre.yottacode.com:1337"
} }
ArturoFlavorNoSSL {
resValue "string", "server", "http://192.168.1.37:1337"
}
} }
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
//compile fileTree(dir: 'E:\\Users\\Fernando\\Google Drive\\experimentos\\Pictogrammar\\android\\app\\libs', include: ['*.jar']) //compile fileTree(dir: 'E:\\Users\\Fernando\\Google Drive\\experimentos\\Pictogrammar\\android\\app\\libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.5.87' compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.github.nkzawa:socket.io-client:0.5.0' compile 'com.github.nkzawa:socket.io-client:0.5.0'
compile 'com.koushikdutta.async:androidasync:2.+' compile 'com.koushikdutta.async:androidasync:2.+'
compile 'com.android.support:support-v4:21.0.+' compile 'com.android.support:support-v4:21.0.+'
compile 'com.koushikdutta.ion:ion:2.1.6'
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yottacode.pictogram" > package="com.yottacode.pictogram">
<uses-sdk android:minSdkVersion="21" /> <uses-sdk android:minSdkVersion="21" />
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
android:allowBackup="true" android:allowBackup="true"
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme" > android:theme="@style/AppTheme">
<activity <activity
android:name=".gui.SplashScreenActivity" android:name=".gui.SplashScreenActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape" > android:screenOrientation="landscape">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<activity <activity
android:name=".gui.MainActivity" android:name=".gui.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape" > android:screenOrientation="landscape">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
</intent-filter> </intent-filter>
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
<activity <activity
android:name=".gui.SerialActivity" android:name=".gui.SerialActivity"
android:label="@string/title_activity_serial" android:label="@string/title_activity_serial"
android:screenOrientation="landscape" > android:screenOrientation="landscape">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
</intent-filter> </intent-filter>
...@@ -53,26 +53,37 @@ ...@@ -53,26 +53,37 @@
android:name=".gui.LoginActivity" android:name=".gui.LoginActivity"
android:exported="true" android:exported="true"
android:label="@string/title_activity_login_activity_fragments" android:label="@string/title_activity_login_activity_fragments"
android:screenOrientation="landscape" > android:screenOrientation="landscape"/>
<activity
android:name="com.yottacode.pictogrammar.UploadActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name=".gui.PictogramActivity" android:name=".gui.PictogramActivity"
android:exported="true" android:exported="true"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape" > android:launchMode="singleTop"
</activity> android:screenOrientation="landscape"/>
<activity <activity
android:name="com.yottacode.pictogrammar.Translate" android:name="com.yottacode.pictogrammar.Translate"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" > android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Intent Filter to run the app when the boot is completed --> <!-- Intent Filter to run the app when the boot is completed -->
<receiver android:name=".kiosk.BootReceiver" > <receiver android:name=".kiosk.BootReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
...@@ -83,8 +94,7 @@ ...@@ -83,8 +94,7 @@
android:exported="false" /> android:exported="false" />
<service <service
android:name=".net.NetService" android:name=".net.NetService"
android:exported="false" > android:exported="false"/>
</service>
</application> </application>
</manifest> </manifest>
package com.yottacode.net;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
/**
* Created by amontejo on 27/01/16.
*/
public class FakeSSLTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(final X509Certificate[] arg0,
final String arg1) throws CertificateException {
// TODO Auto-generated method stub
}
@Override
public void checkServerTrusted(final X509Certificate[] arg0,
final String arg1) throws CertificateException {
// TODO Auto-generated method stub
}
@Override
public final X509Certificate[] getAcceptedIssuers() {
// TODO Auto-generated method stub
return null;
}
}
\ No newline at end of file
...@@ -17,28 +17,6 @@ package com.yottacode.net; ...@@ -17,28 +17,6 @@ package com.yottacode.net;
import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
class FakeSSLTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(final X509Certificate[] arg0,
final String arg1) throws CertificateException {
// TODO Auto-generated method stub
}
@Override
public void checkServerTrusted(final X509Certificate[] arg0,
final String arg1) throws CertificateException {
// TODO Auto-generated method stub
}
@Override
public final X509Certificate[] getAcceptedIssuers() {
// TODO Auto-generated method stub
return null;
}
}
class RelaxedHostNameVerifier implements HostnameVerifier { class RelaxedHostNameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) { public boolean verify(String hostname, SSLSession session) {
return true; return true;
......
package com.yottacode.pictogrammar;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.ProgressBar;
import com.github.nkzawa.socketio.client.IO;
import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
import com.yottacode.net.FakeSSLTrustManager;
import com.yottacode.net.SSLDummyContext;
import com.yottacode.pictogram.R;
import java.io.File;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import static com.yottacode.pictogram.R.layout.activity_upload;
public class UploadActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_upload);
ProgressBar uploadProgressBar;
uploadProgressBar = (ProgressBar) findViewById(R.id.progressBar2);
final Context context = UploadActivity.this;
SSLContext mySSLContext = SSLDummyContext.get();
Ion ion = Ion.getDefault(context);
/* try {
ion.configure().createSSLContext("TLS");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
*/
//ion.getHttpClient().getSSLSocketMiddleware().setSSLContext(mySSLContext);
//ion.getHttpClient().getSSLSocketMiddleware().setTrustManagers(new TrustManager[]{new FakeSSLTrustManager()});
ion.with(context)
.load(context.getResources().getString(R.string.server) + "/picto/upload")
.uploadProgressBar(uploadProgressBar)
.setMultipartParameter("filename", "foo-bar")
.setMultipartParameter("extension", "jpg")
.setMultipartParameter("owner", "10")
.setMultipartParameter("folder", "custompictos")
.setMultipartParameter("source", "1")
.setMultipartParameter("token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvZmZpY2UiOnsiaWQiOjM4MywibmFtZSI6IkNvbXVuaWNhY2nDs24gQXVtZW50YXRpdmEgSkHDqW4gKENBSkEpIiwiYWRkcmVzcyI6IlBhcmFqZSBMYXMgTGFndW5pbGxhcywgRWQgQTMsIHByaW1lcmEgcGxhdGEsIDIzMDcxLiBKYcOpbiIsImVtYWlsIjoiZG9mZXJAdWphZW4uZXMiLCJwaG9uZTEiOiIrMzQgOTUzIDIxIDI4IDg4IiwicGhvbmUyIjpudWxsLCJsYW5nIjoiZXMtZXMiLCJjb3VudHJ5IjoiRVMiLCJhZG1pbiI6MjMsImNvbnRhY3RQZXJzb24iOiJGZXJuYW5kbyBNYXJ0w61uZXogU2FudGlhZ28iLCJtYXhTdHVkZW50cyI6MiwiY3VycmVudFN0dWRlbnRzIjowfSwiaWQiOjIzLCJuYW1lIjoiRmVybmFuZG8iLCJzdXJuYW1lIjoiTWFydMOtbmV6IFNhbnRpYWdvIiwiZ2VuZGVyIjoiTSIsInBpYyI6Imh0dHA6Ly93d3dkaS51amFlbi5lcy9zaXRlcy9kZWZhdWx0L2ZpbGVzL3lvLmpwZz8xNDQ4MDE5MzU2IiwiYWRkcmVzcyI6bnVsbCwiY291bnRyeSI6bnVsbCwiZW1haWwiOiJkb2ZlckB1amFlbi5lcyIsInBob25lIjoiKzM0OTUzMjEyODg4IiwibGFuZyI6ImVzLWVzIiwiYWN0aXZlIjp0cnVlLCJ0dHNFbmdpbmUiOm51bGwsImlzU3VwQWRtaW4iOnRydWUsImlhdCI6MTQ1Mzg2MTkyNSwiZXhwIjoxNDUzODY5MTI1fQ.41Zpp1WHayS9x4VsYUKz0KchUAs0fcQB7wU7FotELKc")
.setMultipartFile("file", "image/jpeg", new File("/storage/emulated/0/DCIM/Camera/shot1.jpg"))
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
if (e == null)
System.out.println("Uploaded to " + context.getResources().getString(R.string.server) + " " + result);
else
System.out.println("Error " + e.getMessage());
e.printStackTrace();
}
});
}
}
<?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="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.yottacode.pictogrammar.UploadActivity">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="148dp" />
</RelativeLayout>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="title_activity_picto_board">PictoBoard</string> <string name="title_activity_picto_board">PictoBoard</string>
<!-- TODO: Remove or change this placeholder text --> <!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
<string name="toggle_turn_on">Desactivar modo supervisor</string> <string name="toggle_turn_on">Desactivar modo supervisor</string>
<string name="toggle_turn_off">Activar modo supervisor</string> <string name="toggle_turn_off">Activar modo supervisor</string>
......
...@@ -11,7 +11,7 @@ dashboardControllers.controller('AddPictoCtrl', function ($scope, $modalInstance ...@@ -11,7 +11,7 @@ dashboardControllers.controller('AddPictoCtrl', function ($scope, $modalInstance
// Initially the source is symbolstx collection // Initially the source is symbolstx collection
$scope.source = 'symbolstx'; $scope.source = 'symbolstx';
// List of studentPictos // List of studentPictos
console.log(JSON.stringify(studentPictos)); //console.log(JSON.stringify(studentPictos));
$scope.studentPictos = studentPictos; $scope.studentPictos = studentPictos;
// List of picto categories // List of picto categories
// console.log(JSON.stringify(categories)); // console.log(JSON.stringify(categories));
...@@ -23,7 +23,7 @@ dashboardControllers.controller('AddPictoCtrl', function ($scope, $modalInstance ...@@ -23,7 +23,7 @@ dashboardControllers.controller('AddPictoCtrl', function ($scope, $modalInstance
$scope.pictos_in_category['cat'+cat_id]=[]; $scope.pictos_in_category['cat'+cat_id]=[];
} }
// List os actual pictos (showed by navigation) // List of actual pictos (showed by navigation)
$scope.pictos = []; $scope.pictos = [];
// List of categories (symbolstx) to show in navigation // List of categories (symbolstx) to show in navigation
$scope.symbolstxCats = []; $scope.symbolstxCats = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment