diff --git a/PrinterApp/app/build.gradle b/PrinterApp/app/build.gradle index ea258cc..105d372 100644 --- a/PrinterApp/app/build.gradle +++ b/PrinterApp/app/build.gradle @@ -1,16 +1,17 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 21 - buildToolsVersion "20.0.0" + compileSdkVersion 23 + buildToolsVersion "23.0.2" defaultConfig { applicationId "android.app.printerapp" minSdkVersion 14 - targetSdkVersion 20 + targetSdkVersion 23 versionName 1.0 + ";" + computeVersionName() versionCode System.getenv("BUILD_NUMBER") as Integer ?: 0 +// useLibrary 'org.apache.http.legacy' } buildTypes { @@ -52,27 +53,31 @@ def computeVersionName() { repositories { mavenCentral() jcenter() + maven { url "https://jitpack.io" } } dependencies { - compile 'com.android.support:support-v4:21.+' + compile 'com.android.support:support-v4:23.1.1' compile files('libs/autobahn-0.5.0.jar') compile files('libs/devsmartlib.jar') compile files('libs/jmdns.jar') // compile files('libs/nineoldandroids-2.4.0.jar') compile files('libs/core-1.51.0.0.jar') + compile "cz.msebera.android:httpclient:4.4.1.1" //UI libraries compile project(':horizontallistlibrary') compile 'uk.co.androidalliance:edgeeffectoverride:1.0.2' //Scroll mode effect //Material design libraries - compile "com.android.support:appcompat-v7:21.0.+" - compile 'com.android.support:cardview-v7:21.+' - compile 'com.github.navasmdc:MaterialDesign:1.+@aar' - compile 'com.github.fengdai:alertdialogpro-theme-material:0.2.1' + compile "com.android.support:appcompat-v7:23.1.1" + compile 'com.android.support:cardview-v7:23.1.1' + compile 'com.github.navasmdc:MaterialDesign:1.5@aar' + compile 'com.github.fengdai:alertdialogpro-theme-material:0.2.6' compile project(':materialdesignlibrary') - compile 'com.afollestad:material-dialogs:0.6.1.6' //Material design dialogs + compile('com.github.afollestad.material-dialogs:core:0.8.5.6@aar') { + transitive = true + } compile 'com.pnikosis:materialish-progress:1.4' compile 'com.rengwuxian.materialedittext:library:1.8.2' compile 'org.apache.httpcomponents:httpclient-android:4.3.5' - compile files('libs/android-async-http-1.4.6.jar') + compile files('libs/android-async-http-1.4.9.jar') } diff --git a/PrinterApp/app/libs/android-async-http-1.4.6.jar b/PrinterApp/app/libs/android-async-http-1.4.6.jar deleted file mode 100644 index 70391cb..0000000 Binary files a/PrinterApp/app/libs/android-async-http-1.4.6.jar and /dev/null differ diff --git a/PrinterApp/app/libs/android-async-http-1.4.9.jar b/PrinterApp/app/libs/android-async-http-1.4.9.jar new file mode 100644 index 0000000..c2d8b86 Binary files /dev/null and b/PrinterApp/app/libs/android-async-http-1.4.9.jar differ diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/devices/FinishDialog.java b/PrinterApp/app/src/main/java/android/app/printerapp/devices/FinishDialog.java index 40ce012..8fa7117 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/devices/FinishDialog.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/devices/FinishDialog.java @@ -16,7 +16,7 @@ import android.widget.CheckBox; import android.widget.EditText; -import com.afollestad.materialdialogs.MaterialDialogCompat; +import com.afollestad.materialdialogs.AlertDialogWrapper; import java.io.File; @@ -41,7 +41,7 @@ public FinishDialog(Context context, ModelPrinter p){ public void createDialog(){ //Constructor - MaterialDialogCompat.Builder adb = new MaterialDialogCompat.Builder(mContext); + AlertDialogWrapper.Builder adb = new AlertDialogWrapper.Builder(mContext); adb.setTitle(mContext.getString(R.string.finish_dialog_title) + " " + mPrinter.getJob().getFilename()); //Inflate the view @@ -107,7 +107,7 @@ public void onClick(DialogInterface dialogInterface, int i) { public void createFinishDialogSave(final ModelPrinter m, final File file) { //Constructor - MaterialDialogCompat.Builder adb = new MaterialDialogCompat.Builder(mContext); + AlertDialogWrapper.Builder adb = new AlertDialogWrapper.Builder(mContext); adb.setTitle(m.getDisplayName() + " (100%) - " +file.getName()); //Inflate the view diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/devices/camera/CameraHandler.java b/PrinterApp/app/src/main/java/android/app/printerapp/devices/camera/CameraHandler.java index de37fa0..3e9b106 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/devices/camera/CameraHandler.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/devices/camera/CameraHandler.java @@ -8,14 +8,12 @@ import android.view.View.OnClickListener; import android.widget.FrameLayout; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.HttpHostConnectException; -import org.apache.http.impl.client.DefaultHttpClient; - -import java.io.IOException; import java.net.URI; +import cz.msebera.android.httpclient.HttpResponse; +import cz.msebera.android.httpclient.client.methods.HttpGet; +import cz.msebera.android.httpclient.impl.client.DefaultHttpClient; + /** * This class will handle the Camera connection. * The device camera will stream on MJPEG. @@ -103,7 +101,7 @@ protected MjpegInputStream doInBackground(String... url) { HttpResponse res = null; - DefaultHttpClient httpclient = new DefaultHttpClient(); + DefaultHttpClient httpclient = new DefaultHttpClient(); try { res = httpclient.execute(new HttpGet(URI.create(url[0]))); diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/library/LibraryFragment.java b/PrinterApp/app/src/main/java/android/app/printerapp/library/LibraryFragment.java index 5f38040..1de0c1f 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/library/LibraryFragment.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/library/LibraryFragment.java @@ -29,8 +29,8 @@ import android.widget.RadioGroup; import android.widget.TextView; +import com.afollestad.materialdialogs.AlertDialogWrapper; import com.afollestad.materialdialogs.MaterialDialog; -import com.afollestad.materialdialogs.MaterialDialogCompat; import com.rengwuxian.materialedittext.MaterialEditText; import java.io.File; @@ -359,7 +359,7 @@ public void optionSearchLibrary() { final EditText et = new EditText(getActivity()); - MaterialDialogCompat.Builder adb = new MaterialDialogCompat.Builder(getActivity()); + AlertDialogWrapper.Builder adb = new AlertDialogWrapper.Builder(getActivity()); adb.setTitle(R.string.library_search_dialog_title); adb.setView(et); diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/library/LibraryModelCreation.java b/PrinterApp/app/src/main/java/android/app/printerapp/library/LibraryModelCreation.java index ae42bc8..98520b8 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/library/LibraryModelCreation.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/library/LibraryModelCreation.java @@ -1,6 +1,5 @@ package android.app.printerapp.library; -import android.app.AlertDialog; import android.app.printerapp.Log; import android.app.printerapp.R; import android.app.printerapp.viewer.DataStorage; @@ -14,6 +13,7 @@ import android.graphics.Bitmap; import android.os.Handler; import android.support.v4.content.LocalBroadcastManager; +import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.widget.FrameLayout; @@ -40,7 +40,7 @@ */ public class LibraryModelCreation { - static AlertDialog mAlert; + static MaterialDialog mAlert; static String mName; public static ViewerSurfaceView mSnapshotSurface; public static FrameLayout mSnapshotLayout; diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/HttpClientHandler.java b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/HttpClientHandler.java index 0e2cf94..be87243 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/HttpClientHandler.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/HttpClientHandler.java @@ -9,21 +9,21 @@ import com.loopj.android.http.ResponseHandlerInterface; import com.loopj.android.http.SyncHttpClient; -import org.apache.http.HttpEntity; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPatch; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContexts; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; - import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import javax.net.ssl.SSLContext; +import cz.msebera.android.httpclient.HttpEntity; +import cz.msebera.android.httpclient.client.ClientProtocolException; +import cz.msebera.android.httpclient.client.methods.CloseableHttpResponse; +import cz.msebera.android.httpclient.client.methods.HttpPatch; +import cz.msebera.android.httpclient.conn.ssl.SSLConnectionSocketFactory; +import cz.msebera.android.httpclient.impl.client.CloseableHttpClient; +import cz.msebera.android.httpclient.impl.client.HttpClientBuilder; +import cz.msebera.android.httpclient.ssl.SSLContexts; + /** * Static class to handle Http requests with the old API or the new one (with API_KEY) * @author alberto-baeza @@ -87,7 +87,7 @@ public static void patch(Context context, String url, HttpEntity entity, String SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - CloseableHttpClient httpClient= HttpClientBuilder.create() + CloseableHttpClient httpClient= HttpClientBuilder.create() .setSSLSocketFactory(sslsf) .build(); diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintAuthentication.java b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintAuthentication.java index 2807dd1..00705bc 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintAuthentication.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintAuthentication.java @@ -10,8 +10,6 @@ import com.loopj.android.http.JsonHttpResponseHandler; -import org.apache.http.Header; -import org.apache.http.entity.StringEntity; import org.json.JSONException; import org.json.JSONObject; @@ -26,6 +24,9 @@ import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.entity.StringEntity; + /** * Created by alberto-baeza on 11/21/14. */ @@ -46,7 +47,9 @@ public static void getAuth(final Context context, final ModelPrinter p, final bo HttpClientHandler.get(p.getAddress() + HttpUtils.URL_AUTHENTICATION, null, new JsonHttpResponseHandler(){ @Override - public void onProgress(int bytesWritten, int totalSize) { + public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, String responseString, Throwable throwable) { + super.onFailure(statusCode, headers, responseString, throwable); + Log.i("Connection", "Failure! " + responseString); } @Override @@ -61,13 +64,6 @@ public void onSuccess(int statusCode, Header[] headers, JSONObject response) { e.printStackTrace(); } } - - @Override - public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { - super.onFailure(statusCode, headers, responseString, throwable); - - Log.i("Connection", "Failure! " + responseString); - } }); } @@ -118,11 +114,6 @@ public static void postAuth(final Context context, String key, final ModelPrinte HttpClientHandler.post(context, p.getAddress() + HttpUtils.URL_AUTHENTICATION, entity, "application/json", new JsonHttpResponseHandler() { - //Override onProgress because it's faulty - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintConnection.java b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintConnection.java index 305bc16..4f5e984 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintConnection.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintConnection.java @@ -28,17 +28,16 @@ import com.afollestad.materialdialogs.MaterialDialog; import com.loopj.android.http.JsonHttpResponseHandler; -import org.apache.http.Header; -import org.apache.http.entity.StringEntity; import org.json.JSONException; import org.json.JSONObject; -import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.entity.StringEntity; import de.tavendo.autobahn.WebSocketConnection; import de.tavendo.autobahn.WebSocketException; import de.tavendo.autobahn.WebSocketHandler; @@ -76,20 +75,12 @@ public static void startConnection(String url, final Context context, String por entity = new StringEntity(object.toString(), "UTF-8"); } catch (JSONException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); } Log.i("Profile", "Start connection on " + profile); HttpClientHandler.post(context,url + HttpUtils.URL_CONNECTION, entity, "application/json", new JsonHttpResponseHandler(){ - - //Override onProgress because it's faulty - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { @@ -100,9 +91,7 @@ public void onFailure(int statusCode, Header[] headers, super.onFailure(statusCode, headers, responseString, throwable); } - }); - - + }); } public static void disconnect(Context context, String url){ @@ -114,29 +103,15 @@ public static void disconnect(Context context, String url){ entity = new StringEntity(object.toString(), "UTF-8"); } catch (JSONException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); } HttpClientHandler.post(context,url + HttpUtils.URL_CONNECTION, - entity, "application/json", new JsonHttpResponseHandler(){ - - //Override onProgress because it's faulty - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - }); + entity, "application/json", new JsonHttpResponseHandler()); } public static void getLinkedConnection(final Context context, final ModelPrinter p){ HttpClientHandler.get(p.getAddress() + HttpUtils.URL_CONNECTION, null, new JsonHttpResponseHandler(){ - - @Override - public void onProgress(int bytesWritten, int totalSize) { - - } - @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); @@ -375,17 +350,10 @@ public static void getUpdatedSettings(final ModelPrinter p, String profile){ HttpClientHandler.get(p.getAddress() + HttpUtils.URL_PROFILES + "/" + profile, null, new JsonHttpResponseHandler(){ - - @Override - public void onProgress(int bytesWritten, int totalSize) { - - } - @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); - Log.i("Connection", response.toString()); try { @@ -470,14 +438,6 @@ public void onSuccess(int statusCode, Header[] headers, JSONObject response) { } catch (JSONException e) { e.printStackTrace(); } - - - - } - - @Override - public void onProgress(int bytesWritten, int totalSize) { - } @Override @@ -507,18 +467,11 @@ public static void setSettings(final ModelPrinter p, String newName, final Strin entity = new StringEntity(object.toString(), "UTF-8"); } catch (JSONException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); } HttpClientHandler.post(context, p.getAddress() + HttpUtils.URL_SETTINGS, entity, "application/json", new JsonHttpResponseHandler() { - //Override onProgress because it's faulty - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintControl.java b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintControl.java index 3c024b5..7c547de 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintControl.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintControl.java @@ -12,45 +12,46 @@ import com.afollestad.materialdialogs.MaterialDialog; import com.loopj.android.http.JsonHttpResponseHandler; -import org.apache.http.Header; -import org.apache.http.entity.StringEntity; -import org.apache.http.message.BasicHeader; -import org.apache.http.protocol.HTTP; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.entity.StringEntity; +import cz.msebera.android.httpclient.message.BasicHeader; +import cz.msebera.android.httpclient.protocol.HTTP; + /** * This class will issue commands to the server. Mainly control commands like Start, Pause and Cancel. * Also will control print head jog and extruder. - * @author alberto-baeza * + * @author alberto-baeza */ public class OctoprintControl { - - - /** - * Send a command to the server to start/pause/stop a job - * @param context - * @param url - * @param command - */ - public static void sendCommand(Context context, String url, String command){ - - JSONObject object = new JSONObject(); - StringEntity entity = null; - - try { - object.put("command", command); - entity = new StringEntity(object.toString(), "UTF-8"); + + + /** + * Send a command to the server to start/pause/stop a job + * + * @param context + * @param url + * @param command + */ + public static void sendCommand(Context context, String url, String command) { + + JSONObject object = new JSONObject(); + StringEntity entity = null; + + try { + object.put("command", command); + entity = new StringEntity(object.toString(), "UTF-8"); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); - - } catch (JSONException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { e.printStackTrace(); - } + + } catch (JSONException e) { + e.printStackTrace(); + } //Get progress dialog UI View waitingForServiceDialogView = LayoutInflater.from(context).inflate(R.layout.dialog_progress_content_horizontal, null); @@ -64,103 +65,93 @@ public static void sendCommand(Context context, String url, String command){ final Dialog connectionDialog = connectionDialogBuilder.build(); connectionDialog.show(); - - HttpClientHandler.post(context,url + HttpUtils.URL_CONTROL, - entity, "application/json", new JsonHttpResponseHandler(){ - - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - - @Override - public void onSuccess(int statusCode, Header[] headers, - JSONObject response) { - super.onSuccess(statusCode, headers, response); - - //Dismiss progress dialog - connectionDialog.dismiss(); - } - - @Override - public void onFailure(int statusCode, Header[] headers, - String responseString, Throwable throwable) { - - super.onFailure(statusCode, headers, responseString, throwable); - - //Dismiss progress dialog - connectionDialog.dismiss(); - MainActivity.showDialog(responseString); - } - }); - - - } - - /** - * Send a printer head command to jog or move home - * @param context - * @param url - * @param command - * @param axis - * @param amount - */ - public static void sendHeadCommand(Context context, String url, String command, String axis, double amount){ - - JSONObject object = new JSONObject(); - StringEntity entity = null; - - try { - - object.put("command", command); - if (command.equals("home")){ - - //Must be array list to be able to convert a JSONArray in API < 19 - ArrayList s = new ArrayList(); - if (axis.equals("xy")){ + HttpClientHandler.post(context, url + HttpUtils.URL_CONTROL, + entity, "application/json", new JsonHttpResponseHandler() { + + @Override + public void onSuccess(int statusCode, Header[] headers, + JSONObject response) { + super.onSuccess(statusCode, headers, response); + + //Dismiss progress dialog + connectionDialog.dismiss(); + } + + @Override + public void onFailure(int statusCode, Header[] headers, + String responseString, Throwable throwable) { + + super.onFailure(statusCode, headers, responseString, throwable); + + //Dismiss progress dialog + connectionDialog.dismiss(); + MainActivity.showDialog(responseString); + } + }); + + + } + + /** + * Send a printer head command to jog or move home + * + * @param context + * @param url + * @param command + * @param axis + * @param amount + */ + public static void sendHeadCommand(Context context, String url, String command, String axis, double amount) { + + JSONObject object = new JSONObject(); + StringEntity entity = null; + + try { + + object.put("command", command); + if (command.equals("home")) { + + //Must be array list to be able to convert a JSONArray in API < 19 + ArrayList s = new ArrayList(); + if (axis.equals("xy")) { s.add("x"); s.add("y"); } - if (axis.equals("z"))s.add("z"); - - - object.put("axes", new JSONArray(s)); - - } else object.put(axis,amount); - - entity = new StringEntity(object.toString(), "UTF-8"); - - } catch (JSONException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { e.printStackTrace(); - } - - - HttpClientHandler.post(context,url + HttpUtils.URL_PRINTHEAD, - entity, "application/json", new JsonHttpResponseHandler(){ - - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - - @Override - public void onSuccess(int statusCode, Header[] headers, - JSONObject response) { - super.onSuccess(statusCode, headers, response); - - } - - @Override - public void onFailure(int statusCode, Header[] headers, - String responseString, Throwable throwable) { - - super.onFailure(statusCode, headers, responseString, throwable); - MainActivity.showDialog(responseString); - } - }); - - } - - public static void sendToolCommand(Context context, String url, String command, String tool, double amount){ + if (axis.equals("z")) s.add("z"); + + + object.put("axes", new JSONArray(s)); + + } else object.put(axis, amount); + + entity = new StringEntity(object.toString(), "UTF-8"); + + } catch (JSONException e) { + e.printStackTrace(); + } + + HttpClientHandler.post(context, url + HttpUtils.URL_PRINTHEAD, + entity, "application/json", new JsonHttpResponseHandler() { + @Override + public void onSuccess(int statusCode, Header[] headers, + JSONObject response) { + super.onSuccess(statusCode, headers, response); + + } + + @Override + public void onFailure(int statusCode, Header[] headers, + String responseString, Throwable throwable) { + + super.onFailure(statusCode, headers, responseString, throwable); + MainActivity.showDialog(responseString); + } + }); + + } + + public static void sendToolCommand(Context context, String url, String command, String tool, double amount) { JSONObject object = new JSONObject(); StringEntity entity = null; @@ -173,38 +164,33 @@ public static void sendToolCommand(Context context, String url, String command, JSONObject json = new JSONObject(); - if (tool!=null){ + if (tool != null) { - if (tool.equals("bed")){ + if (tool.equals("bed")) { destinationUrl = HttpUtils.URL_BED; - object.put("target",amount); + object.put("target", amount); } else { - json.put(tool,amount); + json.put(tool, amount); object.put("targets", json); } } else { - object.put("amount",amount); + object.put("amount", amount); } entity = new StringEntity(object.toString(), "UTF-8"); - } catch (JSONException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); } - Log.i("TOOL", "Sending: " + object.toString()); - HttpClientHandler.post(context,url + destinationUrl, - entity, "application/json", new JsonHttpResponseHandler(){ - - @Override - public void onProgress(int bytesWritten, int totalSize) { - } + HttpClientHandler.post(context, url + destinationUrl, + entity, "application/json", new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintFiles.java b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintFiles.java index 3df4235..9972b4a 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintFiles.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintFiles.java @@ -14,24 +14,24 @@ import com.loopj.android.http.JsonHttpResponseHandler; import com.loopj.android.http.RequestParams; -import org.apache.http.Header; -import org.apache.http.entity.StringEntity; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.FileNotFoundException; -import java.io.UnsupportedEncodingException; + +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.entity.StringEntity; public class OctoprintFiles { - - /** - * Get the whole filelist from the server. - */ - public static void getFiles(final Context context , final ModelPrinter p, final File fileUpload){ - if (fileUpload!=null){ //TODO emulating fileUpload + /** + * Get the whole filelist from the server. + */ + public static void getFiles(final Context context, final ModelPrinter p, final File fileUpload) { + + if (fileUpload != null) { //TODO emulating fileUpload p.setLoaded(false); @@ -41,183 +41,167 @@ public static void getFiles(final Context context , final ModelPrinter p, final } - - HttpClientHandler.get(p.getAddress() + HttpUtils.URL_FILES, null, new JsonHttpResponseHandler(){ - - //Override onProgress because it's faulty - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - - @Override - public void onSuccess(int statusCode, Header[] headers, - JSONObject response) { - super.onSuccess(statusCode, headers, response); - p.getFiles().clear(); - - try { - - JSONArray json = response.getJSONArray("files"); - - if (json != null) { + HttpClientHandler.get(p.getAddress() + HttpUtils.URL_FILES, null, new JsonHttpResponseHandler() { + @Override + public void onSuccess(int statusCode, Header[] headers, + JSONObject response) { + super.onSuccess(statusCode, headers, response); + + p.getFiles().clear(); - if (fileUpload == null){ + try { - for (int i=0;i + * Right now it uses two requests, the first to upload the file and another one to load it in the printer. + * + * @param file + */ + public static void uploadFile(final Context context, final File file, final ModelPrinter p) { + + RequestParams params = new RequestParams(); - - HttpClientHandler.post(p.getAddress() + HttpUtils.URL_FILES + "/local", - params, new JsonHttpResponseHandler(){ + //if it's a local file + p.setJobPath(file.getAbsolutePath()); - //Override onProgress because it's faulty - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - - //If success, the file was uploaded correctly - @Override - public void onSuccess(int statusCode, Header[] headers, - JSONObject response) { - super.onSuccess(statusCode, headers, response); - + try { + //TODO fix + //params.put("select", true); + params.put("file", file); - Log.i("SUCCESS", response.toString()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + + Toast.makeText(context, p.getDisplayName() + ": " + context.getString(R.string.devices_text_loading) + " " + file.getName() + , Toast.LENGTH_LONG).show(); + p.setLoaded(false); + DatabaseController.handlePreference(DatabaseController.TAG_REFERENCES, p.getName(), p.getJobPath(), true); - try{ - //p.setLoaded(true); - fileCommand(context, p.getAddress(), file.getName(), "/local/", false, true); - Toast.makeText(context, p.getDisplayName() + ": " + context.getString(R.string.devices_toast_upload_1) + file.getName(), Toast.LENGTH_LONG).show(); + HttpClientHandler.post(p.getAddress() + HttpUtils.URL_FILES + "/local", + params, new JsonHttpResponseHandler() { + + //If success, the file was uploaded correctly + @Override + public void onSuccess(int statusCode, Header[] headers, + JSONObject response) { + super.onSuccess(statusCode, headers, response); + + + Log.i("SUCCESS", response.toString()); + + + try { + //p.setLoaded(true); + fileCommand(context, p.getAddress(), file.getName(), "/local/", false, true); + + Toast.makeText(context, p.getDisplayName() + ": " + context.getString(R.string.devices_toast_upload_1) + file.getName(), Toast.LENGTH_LONG).show(); + + } catch (IllegalArgumentException e) { + + e.printStackTrace(); + p.setLoaded(true); + } - } catch (IllegalArgumentException e){ - e.printStackTrace(); - p.setLoaded(true); } - - - - } - - @Override - public void onFailure(int statusCode, Header[] headers, - String responseString, Throwable throwable) { - super.onFailure(statusCode, headers, responseString, throwable); - p.setLoaded(true); - Log.i("RESPONSEFAIL", responseString); - - Toast.makeText(context, p.getDisplayName() + ": " + context.getString(R.string.devices_toast_upload_2) + file.getName(), Toast.LENGTH_LONG).show(); - - } - - }); - - - } - - /** - * Method to delete a file on the server remotely after it was printed. - * @param context - * @param url - * @param filename - * @param target - */ - public static void deleteFile(Context context, String url, String filename, String target){ - - HttpClientHandler.delete(context, url + HttpUtils.URL_FILES + "/local/" + filename, - new JsonHttpResponseHandler(){ - - //Override onProgress because it's faulty - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - - //If success, the file was uploaded correctly - @Override - public void onSuccess(int statusCode, Header[] headers, - JSONObject response) { - super.onSuccess(statusCode, headers, response); - - - } - - @Override - public void onFailure(int statusCode, Header[] headers, - String responseString, Throwable throwable) { - // TODO Auto-generated method stub - super.onFailure(statusCode, headers, responseString, throwable); - - } - - }); - - - } - - /** - * TODO CHANGE TO BACKGROUND DOWNLOAD - * This method will create a Download Manager to retrieve gcode files from the server. - * Files will be saved in the gcode folder for the current project. - * - * @param context - * @param url download reference - * @param path local folder to store the file - * @param filename - */ - public static void downloadFile(Context context, String url, String path, String filename){ + @Override + public void onFailure(int statusCode, Header[] headers, + String responseString, Throwable throwable) { + super.onFailure(statusCode, headers, responseString, throwable); + p.setLoaded(true); + Log.i("RESPONSEFAIL", responseString); + + Toast.makeText(context, p.getDisplayName() + ": " + context.getString(R.string.devices_toast_upload_2) + file.getName(), Toast.LENGTH_LONG).show(); + + } + + }); + + + } + + /** + * Method to delete a file on the server remotely after it was printed. + * + * @param context + * @param url + * @param filename + * @param target + */ + public static void deleteFile(Context context, String url, String filename, String target) { + + HttpClientHandler.delete(context, url + HttpUtils.URL_FILES + "/local/" + filename, + new JsonHttpResponseHandler() { + + //If success, the file was uploaded correctly + @Override + public void onSuccess(int statusCode, Header[] headers, + JSONObject response) { + super.onSuccess(statusCode, headers, response); + + + } + + @Override + public void onFailure(int statusCode, Header[] headers, + String responseString, Throwable throwable) { + // TODO Auto-generated method stub + super.onFailure(statusCode, headers, responseString, throwable); + + } + + }); + + + } + + /** + * TODO CHANGE TO BACKGROUND DOWNLOAD + * This method will create a Download Manager to retrieve gcode files from the server. + * Files will be saved in the gcode folder for the current project. + * + * @param context + * @param url download reference + * @param path local folder to store the file + * @param filename + */ + public static void downloadFile(Context context, String url, String path, String filename) { Log.i("Slicer", "Downloading " + filename); - - DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http:/" + url + filename)); + + DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http:/" + url + filename)); //hide notifications request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); - - // in order for this if to run, you must use the android 3.2 to compile your app - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - request.allowScanningByMediaScanner(); - //request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); - } + + // in order for this if to run, you must use the android 3.2 to compile your app + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + request.allowScanningByMediaScanner(); + //request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); + } //Delete duplicated files - File extra = new File( path + filename); - if (extra.exists()){ + File extra = new File(path + filename); + if (extra.exists()) { extra.delete(); } - - request.setDestinationUri(Uri.parse("file://" + path + filename)); - - - // get download service and enqueue file - DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); - manager.enqueue(request); + request.setDestinationUri(Uri.parse("file://" + path + filename)); - } + // get download service and enqueue file + DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); + manager.enqueue(request); + } - } diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintNetwork.java b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintNetwork.java index c2c57bb..6dc10c1 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintNetwork.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintNetwork.java @@ -10,8 +10,6 @@ import com.loopj.android.http.JsonHttpResponseHandler; -import org.apache.http.Header; -import org.apache.http.entity.StringEntity; import org.json.JSONException; import org.json.JSONObject; @@ -26,6 +24,9 @@ import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.entity.StringEntity; + public class OctoprintNetwork { /** @@ -38,11 +39,6 @@ public static void getNetworkList(final PrintNetworkManager controller, final Mo HttpClientHandler.sync_get(p.getAddress() + HttpUtils.URL_AUTHENTICATION, null, new JsonHttpResponseHandler() { - - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); @@ -95,11 +91,6 @@ public void onSuccess(int statusCode, Header[] headers, JSONObject response) { HttpClientHandler.get(p.getAddress() + HttpUtils.URL_NETWORK, null, new JsonHttpResponseHandler(){ - @Override - public void onProgress(int bytesWritten, int totalSize) { - - } - @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { @@ -110,8 +101,6 @@ public void onSuccess(int statusCode, Header[] headers, } - - @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { @@ -163,7 +152,6 @@ public static void configureNetwork(final PrintNetworkReceiver pr, final Context entity = new StringEntity(object.toString(), "UTF-8"); } catch (JSONException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { e.printStackTrace(); } HttpClientHandler.post(context,url + HttpUtils.URL_NETWORK, diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintProfiles.java b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintProfiles.java index 9129f59..83306df 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintProfiles.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintProfiles.java @@ -5,12 +5,11 @@ import com.loopj.android.http.JsonHttpResponseHandler; -import org.apache.http.Header; -import org.apache.http.entity.StringEntity; import org.json.JSONException; import org.json.JSONObject; -import java.io.UnsupportedEncodingException; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.entity.StringEntity; /** * Created by alberto-baeza on 12/9/14. @@ -41,7 +40,6 @@ public static void uploadProfile(final Context context, final String url, final id = profile.getString("id"); - } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } @@ -51,11 +49,6 @@ public static void uploadProfile(final Context context, final String url, final HttpClientHandler.post(context,url + HttpUtils.URL_PROFILES, entity, "application/json", new JsonHttpResponseHandler(){ - @Override - public void onProgress(int bytesWritten, - int totalSize) { - } - @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { @@ -124,7 +117,6 @@ public static void updateProfile(final Context context, final String url, final entity = new StringEntity(finalProfile.toString(), "UTF-8"); Log.i("OUT", "Profile to add:" + finalProfile.toString()); - } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } diff --git a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintSlicing.java b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintSlicing.java index b82c348..69544ee 100644 --- a/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintSlicing.java +++ b/PrinterApp/app/src/main/java/android/app/printerapp/octoprint/OctoprintSlicing.java @@ -12,25 +12,26 @@ import com.loopj.android.http.JsonHttpResponseHandler; import com.loopj.android.http.RequestParams; -import org.apache.http.Header; -import org.apache.http.entity.StringEntity; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.FileNotFoundException; -import java.io.UnsupportedEncodingException; import java.util.Iterator; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.entity.StringEntity; + public class OctoprintSlicing { /** * Upload a profile to the server with custom parameters + * * @param context * @param p * @param profile */ - public static void sendProfile(final Context context, final ModelPrinter p, JSONObject profile){ + public static void sendProfile(final Context context, final ModelPrinter p, JSONObject profile) { StringEntity entity = null; String key = null; @@ -38,83 +39,68 @@ public static void sendProfile(final Context context, final ModelPrinter p, JSON try { entity = new StringEntity(profile.toString(), "UTF-8"); key = profile.getString("key"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } - //Progress dialog to notify command events - final ProgressDialog pd = new ProgressDialog(context); - pd.setMessage(context.getString(R.string.devices_command_waiting)); - pd.show(); - - - HttpClientHandler.put(context,p.getAddress() + HttpUtils.URL_SLICING + "/" + key, - entity, "application/json", new JsonHttpResponseHandler(){ - - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - - @Override - public void onSuccess(int statusCode, Header[] headers, - JSONObject response) { - super.onSuccess(statusCode, headers, response); - - Log.i("OUT", response.toString()); - //Dismiss progress dialog - pd.dismiss(); + final ProgressDialog pd = new ProgressDialog(context); + pd.setMessage(context.getString(R.string.devices_command_waiting)); + pd.show(); + + + HttpClientHandler.put(context, p.getAddress() + HttpUtils.URL_SLICING + "/" + key, + entity, "application/json", new JsonHttpResponseHandler() { + + @Override + public void onSuccess(int statusCode, Header[] headers, + JSONObject response) { + super.onSuccess(statusCode, headers, response); + + Log.i("OUT", response.toString()); + //Dismiss progress dialog + pd.dismiss(); //Reload profiles - retrieveProfiles(context,p); + retrieveProfiles(context, p); + } - } - - @Override - public void onFailure(int statusCode, Header[] headers, - String responseString, Throwable throwable) { - - super.onFailure(statusCode, headers, responseString, throwable); - Log.i("OUT", responseString.toString()); - //Dismiss progress dialog - pd.dismiss(); - MainActivity.showDialog(responseString); - } - }); - - - } + @Override + public void onFailure(int statusCode, Header[] headers, + String responseString, Throwable throwable) { + + super.onFailure(statusCode, headers, responseString, throwable); + Log.i("OUT", responseString.toString()); + //Dismiss progress dialog + pd.dismiss(); + MainActivity.showDialog(responseString); + } + }); + + + } /** * Delete the profile selected by the profile parameter + * * @param context * @param profile */ - public static void deleteProfile(final Context context, final ModelPrinter p, String profile){ - - HttpClientHandler.delete(context,p.getAddress() + HttpUtils.URL_SLICING + "/" + profile, new JsonHttpResponseHandler(){ - - @Override - public void onProgress(int bytesWritten, int totalSize) { - } + public static void deleteProfile(final Context context, final ModelPrinter p, String profile) { + HttpClientHandler.delete(context, p.getAddress() + HttpUtils.URL_SLICING + "/" + profile, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); //Reload profiles - retrieveProfiles(context,p); - + retrieveProfiles(context, p); } - - }); } @@ -122,32 +108,27 @@ public void onSuccess(int statusCode, Header[] headers, /** * Method to retrieve slice profiles before sending the file to the actual printer - * */ - public static void retrieveProfiles(final Context context, final ModelPrinter p){ - - HttpClientHandler.get(p.getAddress() + HttpUtils.URL_SLICING, null, new JsonHttpResponseHandler(){ - - @Override - public void onProgress(int bytesWritten, int totalSize) { - } - - @Override - public void onSuccess(int statusCode, Header[] headers, - JSONObject response) { + public static void retrieveProfiles(final Context context, final ModelPrinter p) { + + HttpClientHandler.get(p.getAddress() + HttpUtils.URL_SLICING, null, new JsonHttpResponseHandler() { + + @Override + public void onSuccess(int statusCode, Header[] headers, + JSONObject response) { super.onSuccess(statusCode, headers, response); p.getProfiles().clear(); Iterator keys = response.keys(); - while(keys.hasNext()) { + while (keys.hasNext()) { String current = keys.next(); try { - if (response.getJSONObject(current).getBoolean("default")){ + if (response.getJSONObject(current).getBoolean("default")) { Log.i("OUT", "Selected item is " + response.getJSONObject(current).getString("key")); } @@ -155,7 +136,7 @@ public void onSuccess(int statusCode, Header[] headers, e.printStackTrace(); } - HttpClientHandler.get(p.getAddress() + HttpUtils.URL_SLICING + "/" + current , null, new JsonHttpResponseHandler() { + HttpClientHandler.get(p.getAddress() + HttpUtils.URL_SLICING + "/" + current, null, new JsonHttpResponseHandler() { @Override @@ -167,10 +148,11 @@ public void onSuccess(int statusCode, Header[] headers, /** * Check if the profile is already added because auto-refresh */ - for (JSONObject o : p.getProfiles()){ + for (JSONObject o : p.getProfiles()) { try { - if (o.getString("key").equals(response.getString("key"))) return; + if (o.getString("key").equals(response.getString("key"))) + return; } catch (JSONException e) { e.printStackTrace(); } @@ -178,7 +160,7 @@ public void onSuccess(int statusCode, Header[] headers, } - if (!p.getProfiles().contains(response)){ + if (!p.getProfiles().contains(response)) { p.getProfiles().add(response); @@ -195,22 +177,22 @@ public void onSuccess(int statusCode, Header[] headers, } - - @Override - public void onFailure(int statusCode, Header[] headers, - String responseString, Throwable throwable) { - super.onFailure(statusCode, headers, responseString, throwable); - Log.i("OUT", responseString.toString()); - } - }); - - } + @Override + public void onFailure(int statusCode, Header[] headers, + String responseString, Throwable throwable) { + + super.onFailure(statusCode, headers, responseString, throwable); + Log.i("OUT", responseString.toString()); + } + }); + + } - public static void getMetadata(String url, String filename){ + public static void getMetadata(String url, String filename) { - HttpClientHandler.get(url + HttpUtils.URL_FILES + "/local/" + filename, null, new JsonHttpResponseHandler(){ + HttpClientHandler.get(url + HttpUtils.URL_FILES + "/local/" + filename, null, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { @@ -224,13 +206,11 @@ public void onSuccess(int statusCode, Header[] headers, JSONObject response) { ViewerMainFragment.showProgressBar(StateUtils.SLICER_DOWNLOAD, Integer.parseInt(estimated)); - } catch (JSONException e) { e.printStackTrace(); } - } }); @@ -241,11 +221,12 @@ public void onSuccess(int statusCode, Header[] headers, JSONObject response) { /** * Send a slice command by uploading the file first and then send the command, the result * will be handled in the socket payload response + * * @param context * @param url * @param file */ - public static void sliceCommand(final Context context, final String url, final File file, final JSONObject extras){ + public static void sliceCommand(final Context context, final String url, final File file, final JSONObject extras) { RequestParams params = new RequestParams(); try { @@ -256,116 +237,93 @@ public static void sliceCommand(final Context context, final String url, final F } //Log.i("Slicer","Upaload " + file.getName()); - if (file!=null) - HttpClientHandler.post(url + HttpUtils.URL_FILES + "/local", - params, new JsonHttpResponseHandler(){ - - //Override onProgress because it's faulty - @Override - public void onProgress(int bytesWritten, int totalSize) { - super.onProgress(bytesWritten, totalSize); - - int progress = ( bytesWritten * 100 ) / totalSize; - - if (DatabaseController.getPreference(DatabaseController.TAG_SLICING, "Last")!=null) - if ((DatabaseController.getPreference("Slicing","Last")).equals(file.getName())){ - ViewerMainFragment.showProgressBar(StateUtils.SLICER_UPLOAD, progress); - } //else sendFailureMessage(0, null, null, null); - - - } - - - - //If success, the file was uploaded correctly - @Override - public void onSuccess(int statusCode, Header[] headers, - JSONObject response) { - super.onSuccess(statusCode, headers, response); - - - Log.i("Slicer", "Upload successful"); //TODO - - JSONObject object = extras ; - StringEntity entity = null; + if (file != null) + HttpClientHandler.post(url + HttpUtils.URL_FILES + "/local", + params, new JsonHttpResponseHandler() { - try { - object.put("command", "slice"); - object.put("slicer", "cura"); - - //TODO select profile - - //object.put("profile", profile); - object.put("gcode", "temp.gco"); - entity = new StringEntity(object.toString(), "UTF-8"); - - Log.i("OUT", "Uploading " + object.toString()); - - } catch (JSONException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { e.printStackTrace(); + @Override + public void onProgress(long bytesWritten, long totalSize) { + super.onProgress(bytesWritten, totalSize); + long progress = (bytesWritten * 100) / totalSize; + + if (DatabaseController.getPreference(DatabaseController.TAG_SLICING, "Last") != null) + if ((DatabaseController.getPreference("Slicing", "Last")).equals(file.getName())) { + ViewerMainFragment.showProgressBar(StateUtils.SLICER_UPLOAD, (int) progress); + } //else sendFailureMessage(0, null, null, null); } + //If success, the file was uploaded correctly + @Override + public void onSuccess(int statusCode, Header[] headers, + JSONObject response) { + super.onSuccess(statusCode, headers, response); - Log.i("Slicer", "Send slice command for " + file.getName()); + Log.i("Slicer", "Upload successful"); //TODO - if (DatabaseController.getPreference(DatabaseController.TAG_SLICING, "Last")!=null) - if ((DatabaseController.getPreference("Slicing","Last")).equals(file.getName())) - HttpClientHandler.post(context,url + HttpUtils.URL_FILES + "/local/" + file.getName(), - entity, "application/json", new JsonHttpResponseHandler(){ + JSONObject object = extras; + StringEntity entity = null; - @Override - public void onProgress(int bytesWritten, - int totalSize) { - } + try { + object.put("command", "slice"); + object.put("slicer", "cura"); - @Override - public void onSuccess(int statusCode, - Header[] headers, JSONObject response) { - super.onSuccess(statusCode, headers, response); + //TODO select profile + //object.put("profile", profile); + object.put("gcode", "temp.gco"); + entity = new StringEntity(object.toString(), "UTF-8"); - ViewerMainFragment.showProgressBar(StateUtils.SLICER_SLICE, 0); - Log.i("Slicer", "Slicing started"); + Log.i("OUT", "Uploading " + object.toString()); + } catch (JSONException e) { + e.printStackTrace(); + } - } + Log.i("Slicer", "Send slice command for " + file.getName()); + if (DatabaseController.getPreference(DatabaseController.TAG_SLICING, "Last") != null) + if ((DatabaseController.getPreference("Slicing", "Last")).equals(file.getName())) + HttpClientHandler.post(context, url + HttpUtils.URL_FILES + "/local/" + file.getName(), + entity, "application/json", new JsonHttpResponseHandler() { + @Override + public void onSuccess(int statusCode, + Header[] headers, JSONObject response) { + super.onSuccess(statusCode, headers, response); - @Override - public void onFailure(int statusCode, Header[] headers, - String responseString, Throwable throwable) { - super.onFailure(statusCode, headers, responseString, throwable); - Log.i("OUT", responseString.toString()); + ViewerMainFragment.showProgressBar(StateUtils.SLICER_SLICE, 0); + Log.i("Slicer", "Slicing started"); - ViewerMainFragment.showProgressBar(StateUtils.SLICER_HIDE, -1); - } - }); - } + } - @Override - public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { - super.onFailure(statusCode, headers, responseString, throwable); - Log.i("Slicer", "FAILURESLICING"); - ViewerMainFragment.showProgressBar(StateUtils.SLICER_HIDE, -1); - } - }); + @Override + public void onFailure(int statusCode, Header[] headers, + String responseString, Throwable throwable) { + super.onFailure(statusCode, headers, responseString, throwable); + Log.i("OUT", responseString.toString()); + ViewerMainFragment.showProgressBar(StateUtils.SLICER_HIDE, -1); + } + }); + } + @Override + public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { + super.onFailure(statusCode, headers, responseString, throwable); + Log.i("Slicer", "FAILURESLICING"); + ViewerMainFragment.showProgressBar(StateUtils.SLICER_HIDE, -1); + } + }); + } - - - - } - } diff --git a/PrinterApp/build.gradle b/PrinterApp/build.gradle index ddf487e..531973a 100644 --- a/PrinterApp/build.gradle +++ b/PrinterApp/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.android.tools.build:gradle:2.1.0-alpha1' } } diff --git a/PrinterApp/gradle/wrapper/gradle-wrapper.properties b/PrinterApp/gradle/wrapper/gradle-wrapper.properties index 15c3106..bdacaa4 100644 --- a/PrinterApp/gradle/wrapper/gradle-wrapper.properties +++ b/PrinterApp/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Dec 11 10:26:19 CET 2014 +#Thu Mar 10 19:52:45 NZDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/PrinterApp/materialdesignlibrary/build.gradle b/PrinterApp/materialdesignlibrary/build.gradle index f8c9964..a088fe0 100644 --- a/PrinterApp/materialdesignlibrary/build.gradle +++ b/PrinterApp/materialdesignlibrary/build.gradle @@ -3,7 +3,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.android.tools.build:gradle:2.1.0-alpha1' } }