Skip to content

Commit

Permalink
Reformat code with K&R code style
Browse files Browse the repository at this point in the history
  • Loading branch information
petrnohejl committed Jul 5, 2018
1 parent a445aa1 commit 817d9d0
Show file tree
Hide file tree
Showing 182 changed files with 2,286 additions and 5,685 deletions.
6 changes: 1 addition & 5 deletions Base/mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
// gradlew test Run local unit test
// gradlew connectedAndroidTest Run instrumented unit test


final VERSION_MAJOR = 1 // max two digits
final VERSION_MINOR = 0 // max two digits
final VERSION_PATCH = 0 // max two digits
final VERSION_BUILD = 0 // max three digits


apply plugin: "com.android.application"
apply from: "../utils.gradle"


android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
Expand Down Expand Up @@ -70,13 +67,12 @@ android {

applicationVariants.all {
variant ->
if(variant.buildType.name.equals("release")) {
if (variant.buildType.name.equals("release")) {
renameArtifact("example", variant)
}
}
}


dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:support-compat:27.0.2"
Expand Down
9 changes: 2 additions & 7 deletions Base/utils.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import groovy.swing.SwingBuilder


ext.getVersionCode = {
majorVersion, minorVersion, patchVersion, buildVersion ->
return majorVersion * 10000000 + minorVersion * 100000 + patchVersion * 1000 + buildVersion
}


ext.getVersionName = {
majorVersion, minorVersion, patchVersion ->
return "${majorVersion}.${minorVersion}.${patchVersion}"
}


ext.renameArtifact = {
name, variant ->
variant.outputs.all {
Expand All @@ -22,7 +19,6 @@ ext.renameArtifact = {
}
}


task askForPasswords {
doLast {
def storePass
Expand All @@ -31,7 +27,7 @@ task askForPasswords {

def keystorePropertiesFile = new File((String) project.property("keystore.properties"))

if(project.hasProperty("keystore.properties") && keystorePropertiesFile.exists()) {
if (project.hasProperty("keystore.properties") && keystorePropertiesFile.exists()) {
println "Loading keystore passwords from property file..."
Properties properties = new Properties()
properties.load(new FileInputStream(keystorePropertiesFile))
Expand Down Expand Up @@ -67,10 +63,9 @@ task askForPasswords {
}
}


tasks.whenTaskAdded {
task ->
if(task.name.equals("packageRelease")) {
if (task.name.equals("packageRelease")) {
task.dependsOn "askForPasswords"
}
}
153 changes: 47 additions & 106 deletions Deprecated/Src-APICall/java/client/APICall.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import java.net.UnknownHostException;
import java.util.zip.GZIPInputStream;


public class APICall
{
public class APICall {
private Request mRequest = null;
private APICallTask mAPICallTask = null;
private Exception mException = null;
Expand All @@ -33,50 +31,35 @@ public class APICall
private OutputStream mRequestStream = null;
private InputStream mResponseStream = null;


public APICall(Request request)
{
public APICall(Request request) {
mRequest = request;
}


public APICall(Request request, APICallTask task)
{
public APICall(Request request, APICallTask task) {
mRequest = request;
mAPICallTask = task;
}


public Request getRequest()
{
public Request getRequest() {
return mRequest;
}


public Exception getException()
{
public Exception getException() {
return mException;
}


public ResponseStatus getResponseStatus()
{
public ResponseStatus getResponseStatus() {
return mResponseStatus;
}


public void kill()
{
public void kill() {
disconnect();
}


public Response<?> execute()
{
try
{
public Response<?> execute() {
try {
// disables Keep-Alive for all connections
if(mAPICallTask != null && mAPICallTask.isCancelled()) return null;
if (mAPICallTask != null && mAPICallTask.isCancelled()) return null;
System.setProperty("http.keepAlive", "false");

// new connection
Expand All @@ -94,11 +77,11 @@ public Response<?> execute()
mConnection.connect();

// send request
if(mAPICallTask != null && mAPICallTask.isCancelled()) return null;
if (mAPICallTask != null && mAPICallTask.isCancelled()) return null;
sendRequest(requestData);

// receive response
if(mAPICallTask != null && mAPICallTask.isCancelled()) return null;
if (mAPICallTask != null && mAPICallTask.isCancelled()) return null;
mResponseStream = receiveResponse();

// response info
Expand All @@ -109,101 +92,72 @@ public Response<?> execute()
//Logcat.d("connection.getResponseMessage() = " + mConnection.getResponseMessage());

// parse response
if(mAPICallTask != null && mAPICallTask.isCancelled()) return null;
if (mAPICallTask != null && mAPICallTask.isCancelled()) return null;
Response<?> response = parseResponse();

if(mAPICallTask != null && mAPICallTask.isCancelled()) return null;
if (mAPICallTask != null && mAPICallTask.isCancelled()) return null;
return response;
}
catch(UnknownHostException e)
{
} catch (UnknownHostException e) {
mException = e;
e.printStackTrace();
return null;
}
catch(FileNotFoundException e)
{
} catch (FileNotFoundException e) {
mException = e;
e.printStackTrace();
return null;
}
catch(SocketException e)
{
} catch (SocketException e) {
mException = e;
e.printStackTrace();
return null;
}
catch(SocketTimeoutException e)
{
} catch (SocketTimeoutException e) {
mException = e;
e.printStackTrace();
return null;
}
catch(JsonParseException e)
{
} catch (JsonParseException e) {
mException = e;
e.printStackTrace();
return null;
}
catch(IOException e)
{
} catch (IOException e) {
mException = e;
e.printStackTrace();
return null;
}
catch(Exception e)
{
} catch (Exception e) {
mException = e;
e.printStackTrace();
return null;
}
finally
{
} finally {
disconnect();
}
}

private void disconnect() {
try {
if (mRequestStream != null) mRequestStream.close();
} catch (IOException e) {}

private void disconnect()
{
try
{
if(mRequestStream != null) mRequestStream.close();
}
catch(IOException e) {}
try {
if (mResponseStream != null) mResponseStream.close();
} catch (IOException e) {}

try
{
if(mResponseStream != null) mResponseStream.close();
}
catch(IOException e) {}

try
{
try {
// set status
if(mConnection != null)
{
if (mConnection != null) {
mResponseStatus.setStatusCode(mConnection.getResponseCode());
mResponseStatus.setStatusMessage(mConnection.getResponseMessage());
mConnection.disconnect();
}
}
catch(Throwable e) {}
} catch (Throwable e) {}

mRequestStream = null;
mResponseStream = null;
mConnection = null;
}


private void setupConnection(byte[] requestData) throws ProtocolException
{
if(mRequest.getRequestMethod() != null)
{
private void setupConnection(byte[] requestData) throws ProtocolException {
if (mRequest.getRequestMethod() != null) {
mConnection.setRequestMethod(mRequest.getRequestMethod()); // GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE
}
if(mRequest.getBasicAuthUsername() != null && mRequest.getBasicAuthPassword() != null)
{
if (mRequest.getBasicAuthUsername() != null && mRequest.getBasicAuthPassword() != null) {
mConnection.setRequestProperty("Authorization", getBasicAuthToken(mRequest.getBasicAuthUsername(), mRequest.getBasicAuthPassword()));
}
mConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
Expand All @@ -213,11 +167,10 @@ private void setupConnection(byte[] requestData) throws ProtocolException
mConnection.setRequestProperty("Accept-Charset", "UTF-8");
//mConnection.setRequestProperty("Content-Length", requestData == null ? "0" : String.valueOf(requestData.length));
//if(requestData!=null) mConnection.setChunkedStreamingMode(0);
if(requestData != null) mConnection.setFixedLengthStreamingMode(requestData.length);
if (requestData != null) mConnection.setFixedLengthStreamingMode(requestData.length);
mConnection.setConnectTimeout(30000);
mConnection.setReadTimeout(30000);
if(requestData != null)
{
if (requestData != null) {
// this call automatically sets request method to POST on Android 4
// if you don't want your app to POST, you must not call setDoOutput
// http://webdiary.com/2011/12/14/ics-get-post/
Expand All @@ -227,50 +180,38 @@ private void setupConnection(byte[] requestData) throws ProtocolException
mConnection.setUseCaches(false);
}


private void sendRequest(byte[] requestData) throws IOException
{
if(requestData != null)
{
private void sendRequest(byte[] requestData) throws IOException {
if (requestData != null) {
mRequestStream = new BufferedOutputStream(mConnection.getOutputStream());
mRequestStream.write(requestData);
mRequestStream.flush();
}
}


private InputStream receiveResponse() throws IOException
{
private InputStream receiveResponse() throws IOException {
InputStream responseStream;
String encoding = mConnection.getHeaderField("Content-Encoding");
boolean gzipped = encoding != null && encoding.toLowerCase().contains("gzip");
try
{
try {
InputStream inputStream = mConnection.getInputStream();
if(gzipped) responseStream = new BufferedInputStream(new GZIPInputStream(inputStream));
if (gzipped) responseStream = new BufferedInputStream(new GZIPInputStream(inputStream));
else responseStream = new BufferedInputStream(inputStream);
}
catch(FileNotFoundException e)
{
} catch (FileNotFoundException e) {
// error stream
InputStream errorStream = mConnection.getErrorStream();
if(gzipped) responseStream = new BufferedInputStream(new GZIPInputStream(errorStream));
if (gzipped) responseStream = new BufferedInputStream(new GZIPInputStream(errorStream));
else responseStream = new BufferedInputStream(errorStream);
}
return responseStream;
}


private Response<?> parseResponse() throws IOException
{
private Response<?> parseResponse() throws IOException {
Response<?> response = mRequest.parseResponse(mResponseStream);
if(response == null) throw new RuntimeException("Parser returned null response");
if (response == null) throw new RuntimeException("Parser returned null response");
return response;
}


private String getBasicAuthToken(String username, String password)
{
private String getBasicAuthToken(String username, String password) {
// Base64.NO_WRAP because of Android <4 problem
String base64 = Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP);
return "Basic " + base64;
Expand Down
4 changes: 1 addition & 3 deletions Deprecated/Src-APICall/java/client/APICallListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.example.client.response.Response;


public interface APICallListener
{
public interface APICallListener {
void onAPICallRespond(APICallTask task, ResponseStatus status, Response<?> response);
void onAPICallFail(APICallTask task, ResponseStatus status, Exception exception);
}
Loading

0 comments on commit 817d9d0

Please sign in to comment.