Skip to content

Commit

Permalink
Merge pull request #57 from SanojPunchihewa/minIt-android-implementation
Browse files Browse the repository at this point in the history
MinIt android implementation
  • Loading branch information
SanojPunchihewa authored Oct 29, 2019
2 parents e165543 + b2c5c7e commit e7f0391
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 135 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/com/mobilegenomics/f5n/GUIConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mobilegenomics.f5n.core.AppMode;
import com.mobilegenomics.f5n.core.Argument;
import com.mobilegenomics.f5n.core.PipelineComponent;
import com.mobilegenomics.f5n.core.PipelineStep;
Expand All @@ -21,6 +22,8 @@ public class GUIConfiguration {

private static final String TAG = GUIConfiguration.class.getSimpleName();

private static AppMode appMode;

private static ArrayList<PipelineStep> selectedPipelineSteps = new ArrayList<>();

private static ArrayList<Step> steps = new ArrayList<>();
Expand All @@ -39,6 +42,14 @@ public static void eraseSelectedPipeline() {
selectedPipelineSteps.clear();
}

public static AppMode getAppMode() {
return appMode;
}

public static void setAppMode(final AppMode appMode) {
GUIConfiguration.appMode = appMode;
}

public static void printList() {
for (PipelineStep step : selectedPipelineSteps) {
Log.d(TAG, step.toString());
Expand All @@ -55,6 +66,10 @@ public static void configureSteps(Context context, String folderPath) {
}
}

public static void configureSteps(ArrayList<Step> stepList) {
steps = stepList;
}

public static Step getNextStep() {
// TODO Fix boundary conditions
return steps.get(current++);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mobilegenomics.f5n.activity;

import android.content.Intent;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.graphics.Color;
Expand All @@ -22,6 +23,7 @@
import androidx.core.widget.NestedScrollView;
import com.mobilegenomics.f5n.GUIConfiguration;
import com.mobilegenomics.f5n.R;
import com.mobilegenomics.f5n.core.AppMode;
import com.mobilegenomics.f5n.core.PipelineComponent;
import com.mobilegenomics.f5n.support.TimeFormat;
import java.io.BufferedReader;
Expand All @@ -42,6 +44,8 @@ public class ConfirmationActivity extends AppCompatActivity {

private static final String TAG_SAMTOOLS = "samtools-native";

private String resultsSummary;

private int isPipelineRunning = 0;

private boolean logWrittenToFile = false;
Expand All @@ -56,6 +60,8 @@ public class ConfirmationActivity extends AppCompatActivity {

Button btnProceed;

Button btnSendResults;

ProgressBar mProgressBar;

@Override
Expand Down Expand Up @@ -130,6 +136,21 @@ public void onClick(final View v) {
btnWriteLog.setVisibility(View.GONE);
linearLayout.addView(btnWriteLog);

if (GUIConfiguration.getAppMode() == AppMode.SLAVE) {

btnSendResults = new Button(this);
btnSendResults.setText("Send Results");
btnSendResults.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Intent intent = new Intent(ConfirmationActivity.this, MinITActivity.class);
intent.putExtra("PIPELINE_STATUS", resultsSummary);
startActivity(intent);
}
});
btnSendResults.setVisibility(View.GONE);
linearLayout.addView(btnSendResults);
}
}

public class RunPipeline extends AsyncTask<String, Integer, String> {
Expand Down Expand Up @@ -169,6 +190,9 @@ protected void onPostExecute(final String s) {
btnWriteLog.setVisibility(View.VISIBLE);
btnProceed.setEnabled(true);
mProgressBar.setVisibility(View.GONE);
if (GUIConfiguration.getAppMode() == AppMode.SLAVE) {
btnSendResults.setVisibility(View.VISIBLE);
}
}
}

Expand Down Expand Up @@ -249,6 +273,12 @@ private void writeLogToFile() {
}

String logcat = txtLogs.getText().toString();
stringBuilder.append(logcat);

String footer = "\n-------------------- End of Log --------------------\n\n";
stringBuilder.append(footer);

resultsSummary = stringBuilder.toString();

try {
String dirPath = Environment.getExternalStorageDirectory() + "/mobile-genomics";
Expand All @@ -264,8 +294,6 @@ private void writeLogToFile() {
FileOutputStream fOut = new FileOutputStream(logFile, true);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(stringBuilder.toString());
myOutWriter.append(logcat);
myOutWriter.append("-------------------- End of Log --------------------\n\n");
myOutWriter.flush();
myOutWriter.close();
fOut.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.mobilegenomics.f5n.GUIConfiguration;
import com.mobilegenomics.f5n.R;
import com.mobilegenomics.f5n.core.AppMode;
import com.mobilegenomics.f5n.support.ZipManager;
import com.obsez.android.lib.filechooser.ChooserDialog;
import java.io.File;
Expand Down Expand Up @@ -51,6 +53,8 @@ public class DownloadActivity extends AppCompatActivity {

Button btnExtract;

Button btnRunPipeline;

@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
Expand All @@ -65,6 +69,13 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
urlInputPath.setHint("Url of the data set");
linearLayout.addView(urlInputPath);

if (getIntent().getExtras() != null) {
String path = getIntent().getExtras().getString("DATA_SET_URL");
if (path != null && !TextUtils.isEmpty(path)) {
urlInputPath.setText(path);
}
}

folderPathInput = new EditText(this);
folderPathInput.setHint("Path to download data");
linearLayout.addView(folderPathInput);
Expand Down Expand Up @@ -131,6 +142,9 @@ public void onClick(final View v) {
@Override
public void onClick(final View v) {
if (!TextUtils.isEmpty(folderPath)) {
if (GUIConfiguration.getAppMode() == AppMode.SLAVE) {
btnRunPipeline.setVisibility(View.VISIBLE);
}
extractZip(folderPath);
} else {
Toast.makeText(DownloadActivity.this, "Please Select a Zip file", Toast.LENGTH_SHORT).show();
Expand All @@ -139,6 +153,21 @@ public void onClick(final View v) {
}
});

if (GUIConfiguration.getAppMode() == AppMode.SLAVE) {
btnRunPipeline = new Button(this);
btnRunPipeline.setText("Run Pipeline");
btnRunPipeline.setVisibility(View.GONE);
linearLayout.addView(btnRunPipeline);
btnRunPipeline.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Intent intent = new Intent(DownloadActivity.this, TerminalActivity.class);
intent.putExtra("FOLDER_PATH", folderPath.substring(0, folderPath.lastIndexOf(".")));
startActivity(intent);
}
});
}

}

private void openFileManager(boolean dirOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import com.mobilegenomics.f5n.GUIConfiguration;
import com.mobilegenomics.f5n.R;
import com.mobilegenomics.f5n.core.AppMode;
import com.mobilegenomics.f5n.support.PermissionResultCallback;
import com.mobilegenomics.f5n.support.PermissionUtils;
import java.util.ArrayList;
Expand Down Expand Up @@ -46,18 +48,22 @@ protected void onCreate(Bundle savedInstanceState) {
}

public void downloadDataSet(View view) {
GUIConfiguration.setAppMode(AppMode.DOWNLOAD_DATA);
startActivity(new Intent(MainActivity.this, DownloadActivity.class));
}

public void startStandaloneMode(View view) {
GUIConfiguration.setAppMode(AppMode.STANDALONE);
startActivity(new Intent(MainActivity.this, PipelineActivity.class));
}

public void startMinITMode(View view) {
GUIConfiguration.setAppMode(AppMode.SLAVE);
startActivity(new Intent(MainActivity.this, MinITActivity.class));
}

public void startDemoMode(View view) {
GUIConfiguration.setAppMode(AppMode.DEMO);
startActivity(new Intent(MainActivity.this, DemoActivity.class));
}

Expand Down
120 changes: 102 additions & 18 deletions app/src/main/java/com/mobilegenomics/f5n/activity/MinITActivity.java
Original file line number Diff line number Diff line change
@@ -1,57 +1,141 @@
package com.mobilegenomics.f5n.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.mobilegenomics.f5n.GUIConfiguration;
import com.mobilegenomics.f5n.R;
import com.mobilegenomics.f5n.dto.State;
import com.mobilegenomics.f5n.dto.WrapperObject;
import com.mobilegenomics.f5n.support.ServerCallback;
import com.mobilegenomics.f5n.support.ServerConnectionUtils;

public class MinITActivity extends AppCompatActivity {

private static TextView connectionLogText;

private String serverIP;

private String zipFileName;

private Button btnSendResult;

private boolean ranPipeline = false;

private String resultsSummary;

public static void logHandler(Handler handler) {
handler.post(new Runnable() {
@Override
public void run() {
StringBuilder newLogMessage = ServerConnectionUtils.getLogMessage();
if (newLogMessage != null && newLogMessage.toString().trim().length() != 0) {
connectionLogText.setText(newLogMessage);
}
}
});
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_minit);

final EditText serverAddressInput = findViewById(R.id.input_server_address);
connectionLogText = findViewById(R.id.text_conn_log);
final Button btnConnectServer = findViewById(R.id.btn_connect_server);
final Button btnProcessJob = findViewById(R.id.btn_process);
final Button btnRquestJob = findViewById(R.id.btn_request_job);
btnSendResult = findViewById(R.id.btn_send_result);

if (getIntent().getExtras() != null) {
resultsSummary = getIntent().getExtras().getString("PIPELINE_STATUS");
if (resultsSummary != null && !TextUtils.isEmpty(resultsSummary)) {
ranPipeline = true;
btnRquestJob.setText("Send Results");
}
}

btnConnectServer.setOnClickListener(new View.OnClickListener() {
btnRquestJob.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ServerConnectionUtils.setServerAddress(serverAddressInput.getText().toString());
ServerConnectionUtils.connectToServer();
btnProcessJob.setVisibility(View.VISIBLE);

if (serverAddressInput.getText() != null && !TextUtils
.isEmpty(serverAddressInput.getText().toString().trim())) {
serverIP = serverAddressInput.getText().toString().trim();

ServerConnectionUtils.setServerAddress(serverIP);
if (ranPipeline) {
sendJobResults();
} else {
requestJob();
}

} else {
Toast.makeText(MinITActivity.this, "Please input a server IP", Toast.LENGTH_SHORT).show();
}
}
});

btnProcessJob.setOnClickListener(new View.OnClickListener() {
btnSendResult.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ProgressDialog progressDialog = new ProgressDialog(MinITActivity.this);
ServerConnectionUtils.sendResult();
Intent intent = new Intent(MinITActivity.this, DownloadActivity.class);
// TODO Fix the following
// Protocol, file server IP and Port
intent.putExtra("DATA_SET_URL", "http://" + serverIP + ":8000/" + zipFileName);
startActivity(intent);
}
});
}

public static void logHandler(Handler handler) {
handler.post(new Runnable() {
private void requestJob() {
ServerConnectionUtils.connectToServer(State.REQUEST, new ServerCallback() {
@Override
public void run() {
StringBuilder newLogMessage = ServerConnectionUtils.getLogMessage();
if (newLogMessage != null && newLogMessage.toString().trim().length() != 0)
connectionLogText.setText(newLogMessage);
public void onSuccess(final WrapperObject job) {
runOnUiThread(new Runnable() {
@Override
public void run() {
GUIConfiguration.configureSteps(job.getSteps());
zipFileName = job.getPrefix();
btnSendResult.setVisibility(View.VISIBLE);
Log.d("TAG", "Prefix = " + job.getPrefix());
Log.d("TAG", "Dir Path = " + job.getPathToDataDir());
}
});
}

@Override
public void onError(final WrapperObject job) {

}
});
}

private void sendJobResults() {
ServerConnectionUtils.setResultToWrapperObject(resultsSummary);
ServerConnectionUtils.connectToServer(State.COMPLETED, new ServerCallback() {
@Override
public void onSuccess(final WrapperObject job) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MinITActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
});
}

@Override
public void onError(final WrapperObject job) {

}
});
}
Expand Down
Loading

0 comments on commit e7f0391

Please sign in to comment.