You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2016/06/13 12:58:14 UTC
[05/18] incubator-taverna-mobile git commit: refactor code using
CheckStyle
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/RunFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/RunFragment.java b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/RunFragment.java
index 8d1fb52..c3eb276 100644
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/RunFragment.java
+++ b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/RunFragment.java
@@ -1,6 +1,12 @@
package org.apache.taverna.mobile.fragments.workflowdetails;
+import org.apache.taverna.mobile.R;
+import org.apache.taverna.mobile.tavernamobile.TavernaPlayerAPI;
+import org.apache.taverna.mobile.utils.WorkflowDownloadManager;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
@@ -18,12 +24,6 @@ import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
-import org.apache.taverna.mobile.R;
-import org.apache.taverna.mobile.tavernamobile.TavernaPlayerAPI;
-import org.apache.taverna.mobile.utils.WorkflowDownloadManager;
-import org.json.JSONException;
-import org.json.JSONObject;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -41,17 +41,21 @@ import static org.apache.taverna.mobile.activities.DashboardMainActivity.APP_DIR
* Use the {@link RunFragment#newInstance} factory method to
* create an instance of this fragment.
*/
-public class RunFragment extends Fragment implements View.OnClickListener{
+public class RunFragment extends Fragment implements View.OnClickListener {
private View rootView;
- private TextView runIdTextView,runNameTextView;
+ private TextView runIdTextView, runNameTextView;
private ImageButton status;
- private TextView runStateTextView, runStartTime,runEndTime, runInputsText;
- private Button downloadOutput,downloadLogs;
+ private TextView runStateTextView, runStartTime, runEndTime, runInputsText;
+ private Button downloadOutput, downloadLogs;
private int run_id;
private String run_output_url = "";
private String run_logs_url = "";
+ public RunFragment() {
+ // Required empty public constructor
+ }
+
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
@@ -65,10 +69,6 @@ public class RunFragment extends Fragment implements View.OnClickListener{
return fragment;
}
- public RunFragment() {
- // Required empty public constructor
- }
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -76,23 +76,24 @@ public class RunFragment extends Fragment implements View.OnClickListener{
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
+ savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_run_result, container, false);
- runIdTextView = (TextView) rootView.findViewById(R.id.textview_runid);
- runNameTextView = (TextView) rootView.findViewById(R.id.textView_runName);
- status = (ImageButton) rootView.findViewById(R.id.statusButton);
- runStateTextView = (TextView) rootView.findViewById(R.id.statusTextView);
- runStartTime = (TextView) rootView.findViewById(R.id.start_time);
- runEndTime = (TextView) rootView.findViewById(R.id.runfinish);
- runInputsText = (TextView) rootView.findViewById(R.id.runinputsTextView);
- downloadOutput = (Button) rootView.findViewById(R.id.buttonWorkflowDownloadOutput);
- downloadLogs = (Button) rootView.findViewById(R.id.downloadRunLogs);
+ runIdTextView = (TextView) rootView.findViewById(R.id.textview_runid);
+ runNameTextView = (TextView) rootView.findViewById(R.id.textView_runName);
+ status = (ImageButton) rootView.findViewById(R.id.statusButton);
+ runStateTextView = (TextView) rootView.findViewById(R.id.statusTextView);
+ runStartTime = (TextView) rootView.findViewById(R.id.start_time);
+ runEndTime = (TextView) rootView.findViewById(R.id.runfinish);
+ runInputsText = (TextView) rootView.findViewById(R.id.runinputsTextView);
+ downloadOutput = (Button) rootView.findViewById(R.id.buttonWorkflowDownloadOutput);
+ downloadLogs = (Button) rootView.findViewById(R.id.downloadRunLogs);
return rootView;
}
@Override
- public void onCreateOptionsMenu(Menu menu,MenuInflater menuInflater) {
+ public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.run_result, menu);
return;
@@ -102,38 +103,38 @@ public class RunFragment extends Fragment implements View.OnClickListener{
public void onResume() {
super.onResume();
String runresult = getActivity().getIntent().getStringExtra("runresult");
- try{
+ try {
JSONObject resultObject = new JSONObject(runresult);
String runName = resultObject.getString("name");
run_id = (int) resultObject.get("id");
- String runId = ""+run_id;
+ String runId = "" + run_id;
String runState = resultObject.getString("state");
String runStarted = resultObject.getString("start_time");
String runEnded = resultObject.getString("finish_time");
String runInputs = resultObject.getString("inputs");
- runIdTextView.setText(runId);
- runNameTextView.setText(runName);
+ runIdTextView.setText(runId);
+ runNameTextView.setText(runName);
- if(runState.contains("Pending"))
- status.setImageResource(android.R.drawable.presence_busy);
+ if (runState.contains("Pending"))
+ status.setImageResource(android.R.drawable.presence_busy);
else if (runState.contains("Running"))
- status.setImageResource(android.R.drawable.presence_away);
+ status.setImageResource(android.R.drawable.presence_away);
else if (runState.contains("Finished"))
- status.setImageResource(android.R.drawable.presence_online);
+ status.setImageResource(android.R.drawable.presence_online);
else if (runState.contains("Failed"))
- status.setImageResource(android.R.drawable.presence_offline);
+ status.setImageResource(android.R.drawable.presence_offline);
else
status.setImageResource(android.R.drawable.presence_invisible);
- runStateTextView.setText(runState);
- runStartTime.setHint(runStarted);
- runEndTime.setHint(runEnded);
- runInputsText.setText(runInputs);
- runInputsText.setMovementMethod(new ScrollingMovementMethod());
+ runStateTextView.setText(runState);
+ runStartTime.setHint(runStarted);
+ runEndTime.setHint(runEnded);
+ runInputsText.setText(runInputs);
+ runInputsText.setMovementMethod(new ScrollingMovementMethod());
- downloadOutput.setOnClickListener(this);
- downloadLogs.setOnClickListener(this);
+ downloadOutput.setOnClickListener(this);
+ downloadLogs.setOnClickListener(this);
reloadRunResult();
} catch (JSONException e) {
e.printStackTrace();
@@ -150,85 +151,96 @@ public class RunFragment extends Fragment implements View.OnClickListener{
reloadRunResult();
return true;
}
- if(id == android.R.id.home){
- //getActivity().finish();
+ if (id == android.R.id.home) {
+ //getActivity().finish();
return true;
}
return super.onOptionsItemSelected(item);
}
- private void reloadRunResult(){
+ private void reloadRunResult() {
Timer t = new Timer();
- // t.scheduleAtFixedRate(new RunTimerTask(getActivity(), run_id), 0, 5000);
- t.schedule(new RunTimerTask(getActivity(),run_id),1);
+ // t.scheduleAtFixedRate(new RunTimerTask(getActivity(), run_id), 0, 5000);
+ t.schedule(new RunTimerTask(getActivity(), run_id), 1);
}
@Override
public void onClick(View view) {
- switch(view.getId()){
+ switch (view.getId()) {
case R.id.buttonWorkflowDownloadOutput:
try {
- System.out.println("output url: "+run_output_url);
- if(run_output_url.isEmpty()){
- Toast.makeText(getActivity(), "No run logs available", Toast.LENGTH_LONG).show();
- }else {
+ System.out.println("output url: " + run_output_url);
+ if (run_output_url.isEmpty()) {
+ Toast.makeText(getActivity(), "No run logs available", Toast.LENGTH_LONG)
+ .show();
+ } else {
new WorkflowDownloadManager(getActivity()).downloadWorkflow(
- new File(PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(
- APP_DIRECTORY_NAME + "/Runoutput/outputs", "/TavernaMobile/Runouput/outputs/")),
- new TavernaPlayerAPI(getActivity()).PLAYER_RUN_URL + run_output_url.substring(0, 5));
+ new File(PreferenceManager.getDefaultSharedPreferences
+ (getActivity()).getString(
+ APP_DIRECTORY_NAME + "/Runoutput/outputs",
+ "/TavernaMobile/Runouput/outputs/")),
+ new TavernaPlayerAPI(getActivity()).PLAYER_RUN_URL +
+ run_output_url.substring(0, 5));
}
} catch (Exception e) {
e.printStackTrace();
- Toast.makeText(getActivity(), "Error downloading run output",Toast.LENGTH_LONG).show();
+ Toast.makeText(getActivity(), "Error downloading run output", Toast
+ .LENGTH_LONG).show();
}
break;
case R.id.downloadRunLogs:
try {
- System.out.println("run logs: "+run_logs_url);
- if(run_logs_url.isEmpty()){
- Toast.makeText(getActivity(), "No run logs available", Toast.LENGTH_LONG).show();
- }else {
+ System.out.println("run logs: " + run_logs_url);
+ if (run_logs_url.isEmpty()) {
+ Toast.makeText(getActivity(), "No run logs available", Toast.LENGTH_LONG)
+ .show();
+ } else {
new WorkflowDownloadManager(getActivity()).downloadWorkflow(
- new File(PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(
- APP_DIRECTORY_NAME + "/Runoutput/logs/", "/TavernaMobile/Runoutput/logs")),
- new TavernaPlayerAPI(getActivity()).PLAYER_RUN_URL + run_logs_url.substring(0, 5));
+ new File(PreferenceManager.getDefaultSharedPreferences
+ (getActivity()).getString(
+ APP_DIRECTORY_NAME + "/Runoutput/logs/",
+ "/TavernaMobile/Runoutput/logs")),
+ new TavernaPlayerAPI(getActivity()).PLAYER_RUN_URL + run_logs_url
+ .substring(0, 5));
}
} catch (Exception e) {
e.printStackTrace();
- Toast.makeText(getActivity(), "Error downloading run logs",Toast.LENGTH_LONG).show();
+ Toast.makeText(getActivity(), "Error downloading run logs", Toast
+ .LENGTH_LONG).show();
}
break;
}
}
- public void updateRun(Context context, final JSONObject runInfo){
- if(null != runInfo)
- ((Activity)context).runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- runStartTime.setHint(runInfo.getString("start_time"));
- runEndTime.setHint(runInfo.getString("finish_time"));
- runStateTextView.setText(runInfo.getString("status_message"));
-
- if(runInfo.getString("status_message").contains("Pending"))
- status.setImageResource(android.R.drawable.presence_busy);
- else if (runInfo.getString("status_message").contains("Running"))
- status.setImageResource(android.R.drawable.presence_away);
- else if (runInfo.getString("status_message").contains("Finished"))
- status.setImageResource(android.R.drawable.presence_online);
- else if (runInfo.getString("status_message").contains("Failed"))
- status.setImageResource(android.R.drawable.presence_offline);
- else
- status.setImageResource(android.R.drawable.presence_invisible);
-
- run_output_url = runInfo.has("outputs_zip")? runInfo.getString("outputs_zip"):"";
- run_logs_url = runInfo.has("log")?runInfo.getString("log"):"";
- } catch (JSONException e) {
- e.printStackTrace();
+ public void updateRun(Context context, final JSONObject runInfo) {
+ if (null != runInfo)
+ ((Activity) context).runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ runStartTime.setHint(runInfo.getString("start_time"));
+ runEndTime.setHint(runInfo.getString("finish_time"));
+ runStateTextView.setText(runInfo.getString("status_message"));
+
+ if (runInfo.getString("status_message").contains("Pending"))
+ status.setImageResource(android.R.drawable.presence_busy);
+ else if (runInfo.getString("status_message").contains("Running"))
+ status.setImageResource(android.R.drawable.presence_away);
+ else if (runInfo.getString("status_message").contains("Finished"))
+ status.setImageResource(android.R.drawable.presence_online);
+ else if (runInfo.getString("status_message").contains("Failed"))
+ status.setImageResource(android.R.drawable.presence_offline);
+ else
+ status.setImageResource(android.R.drawable.presence_invisible);
+
+ run_output_url = runInfo.has("outputs_zip") ? runInfo.getString
+ ("outputs_zip") : "";
+ run_logs_url = runInfo.has("log") ? runInfo.getString("log") : "";
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
}
- }
- });
+ });
}
private class RunTimerTask extends TimerTask {
@@ -243,11 +255,13 @@ public class RunFragment extends Fragment implements View.OnClickListener{
@Override
public void run() {
- //QUERY player for the continuous status of the workflow run and update the ui with the results
+ //QUERY player for the continuous status of the workflow run and update the ui with
+ // the results
StringBuffer sb = new StringBuffer();
try {
- URL workflowurl = new URL(new TavernaPlayerAPI(this.context).PLAYER_RUN_URL+this.runid);
+ URL workflowurl = new URL(new TavernaPlayerAPI(this.context).PLAYER_RUN_URL +
+ this.runid);
HttpURLConnection connection = (HttpURLConnection) workflowurl.openConnection();
connection.setRequestProperty("Accept", "application/json");
@@ -259,7 +273,7 @@ public class RunFragment extends Fragment implements View.OnClickListener{
String jsonData = "";
while ((jsonData = br.readLine()) != null) {
- //json results of the full workflow details
+ //json results of the full workflow details
sb.append(jsonData);
}
dis.close();
@@ -269,7 +283,7 @@ public class RunFragment extends Fragment implements View.OnClickListener{
JSONObject runInfo = new JSONObject(sb.toString());
updateRun(this.context, runInfo);
- }catch (IOException ex){
+ } catch (IOException ex) {
ex.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowAboutFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowAboutFragment.java b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowAboutFragment.java
index c8f1e64..1a8192d 100644
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowAboutFragment.java
+++ b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowAboutFragment.java
@@ -2,10 +2,10 @@ package org.apache.taverna.mobile.fragments.workflowdetails;
/**
* Apache Taverna Mobile
* Copyright 2015 The Apache Software Foundation
-
+ *
* This product includes software developed at
* The Apache Software Foundation (http://www.apache.org/).
-
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -24,14 +24,14 @@ package org.apache.taverna.mobile.fragments.workflowdetails;
* under the License.
*/
+import org.apache.taverna.mobile.R;
+
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import org.apache.taverna.mobile.R;
-
/**
* A simple {@link Fragment} subclass.
* Use the {@link WorkflowAboutFragment#newInstance} factory method to
@@ -47,6 +47,9 @@ public class WorkflowAboutFragment extends Fragment {
private String mParam1;
private String mParam2;
+ public WorkflowAboutFragment() {
+ }
+
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
@@ -65,9 +68,6 @@ public class WorkflowAboutFragment extends Fragment {
return fragment;
}
- public WorkflowAboutFragment() {
- }
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowLicenceFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowLicenceFragment.java b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowLicenceFragment.java
index 8226dc3..a4865b7 100644
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowLicenceFragment.java
+++ b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowLicenceFragment.java
@@ -2,10 +2,10 @@ package org.apache.taverna.mobile.fragments.workflowdetails;
/**
* Apache Taverna Mobile
* Copyright 2015 The Apache Software Foundation
-
+ *
* This product includes software developed at
* The Apache Software Foundation (http://www.apache.org/).
-
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -24,14 +24,14 @@ package org.apache.taverna.mobile.fragments.workflowdetails;
* under the License.
*/
+import org.apache.taverna.mobile.R;
+
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import org.apache.taverna.mobile.R;
-
/**
* A simple {@link Fragment} subclass.
* Use the {@link WorkflowLicenceFragment#newInstance} factory method to
@@ -47,6 +47,10 @@ public class WorkflowLicenceFragment extends Fragment {
private String mParam1;
private String mParam2;
+ public WorkflowLicenceFragment() {
+ // Required empty public constructor
+ }
+
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
@@ -65,10 +69,6 @@ public class WorkflowLicenceFragment extends Fragment {
return fragment;
}
- public WorkflowLicenceFragment() {
- // Required empty public constructor
- }
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowRunHistoryFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowRunHistoryFragment.java b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowRunHistoryFragment.java
index 7d9ffda..edc67f9 100644
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowRunHistoryFragment.java
+++ b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowRunHistoryFragment.java
@@ -2,10 +2,10 @@ package org.apache.taverna.mobile.fragments.workflowdetails;
/**
* Apache Taverna Mobile
* Copyright 2015 The Apache Software Foundation
-
+ *
* This product includes software developed at
* The Apache Software Foundation (http://www.apache.org/).
-
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -24,6 +24,12 @@ package org.apache.taverna.mobile.fragments.workflowdetails;
* under the License.
*/
+import org.apache.taverna.mobile.R;
+import org.apache.taverna.mobile.adapters.RunAdapter;
+import org.apache.taverna.mobile.tavernamobile.Runs;
+import org.apache.taverna.mobile.tavernamobile.Workflow;
+import org.apache.taverna.mobile.utils.DetailsLoader;
+
import android.app.LoaderManager;
import android.app.ProgressDialog;
import android.content.Loader;
@@ -36,12 +42,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
-import org.apache.taverna.mobile.R;
-import org.apache.taverna.mobile.adapters.RunAdapter;
-import org.apache.taverna.mobile.tavernamobile.Runs;
-import org.apache.taverna.mobile.tavernamobile.Workflow;
-import org.apache.taverna.mobile.utils.DetailsLoader;
-
import java.util.ArrayList;
import java.util.List;
@@ -50,17 +50,21 @@ import java.util.List;
* Use the {@link WorkflowRunHistoryFragment#newInstance} factory method to
* create an instance of this fragment.
*/
-public class WorkflowRunHistoryFragment extends Fragment implements LoaderManager.LoaderCallbacks<Workflow>{
+public class WorkflowRunHistoryFragment extends Fragment implements LoaderManager
+ .LoaderCallbacks<Workflow> {
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM2 = "param2";
+ private static String workflowID; //represents a run name that matches the given workflow
+ List<Runs> runsList;
private ProgressDialog progressDialog;
private RecyclerView mRecyclerView;
private TextView emptyRunHistoryTextView;
private RunAdapter runAdapter;
- List<Runs> runsList;
- private static String workflowID; //represents a run name that matches the given workflow
+ public WorkflowRunHistoryFragment() {
+ // Required empty public constructor
+ }
/**
* Use this factory method to create a new instance of
@@ -78,14 +82,10 @@ public class WorkflowRunHistoryFragment extends Fragment implements LoaderManage
return fragment;
}
- public WorkflowRunHistoryFragment() {
- // Required empty public constructor
- }
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- runsList = new ArrayList<Runs>();
+ runsList = new ArrayList<Runs>();
/* runsList.add(new Runs("Test Run1 ",
SimpleDateFormat.getDateTimeInstance().format(new Date()).toString()
,SimpleDateFormat.getDateTimeInstance().format(new Date()).toString(),"failed"));
@@ -97,21 +97,21 @@ public class WorkflowRunHistoryFragment extends Fragment implements LoaderManage
progressDialog.setMessage(getActivity().getResources().getString(R.string.loading));
progressDialog.setCancelable(true);
- runAdapter = new RunAdapter(getActivity(),runsList );
- // System.out.println("WorkflowTitle->Run->"+workflowID);
+ runAdapter = new RunAdapter(getActivity(), runsList);
+ // System.out.println("WorkflowTitle->Run->"+workflowID);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
- View rootView =inflater.inflate(R.layout.fragment_workflow_run_history, container, false);
+ View rootView = inflater.inflate(R.layout.fragment_workflow_run_history, container, false);
emptyRunHistoryTextView = (TextView) rootView.findViewById(android.R.id.empty);
mRecyclerView = (RecyclerView) rootView.findViewById(android.R.id.list);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
- mRecyclerView.setAdapter(runAdapter);
- getActivity().getLoaderManager().initLoader(0,savedInstanceState,this).forceLoad();
+ mRecyclerView.setAdapter(runAdapter);
+ getActivity().getLoaderManager().initLoader(0, savedInstanceState, this).forceLoad();
return rootView;
}
@@ -125,7 +125,7 @@ public class WorkflowRunHistoryFragment extends Fragment implements LoaderManage
public void onResume() {
super.onResume();
- // mRecyclerView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
+ // mRecyclerView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
//getActivity().getLoaderManager().initLoader(1,null,this);
}
@@ -138,30 +138,30 @@ public class WorkflowRunHistoryFragment extends Fragment implements LoaderManage
public Loader<Workflow> onCreateLoader(int i, Bundle bundle) {
//progressDialog.show();
return new DetailsLoader(getActivity(),
- DetailsLoader.LOAD_TYPE.TYPE_RUN_HISTORY,
+ DetailsLoader.LoadType.TYPE_RUN_HISTORY,
workflowID);
}
@Override
public void onLoadFinished(Loader<Workflow> workflowLoader, Workflow workflow) {
- try {
- if (workflow.getWorkflow_runs() !=null | workflow.getWorkflow_runs().size() !=0) {
+ try {
+ if (workflow.getWorkflow_runs() != null | workflow.getWorkflow_runs().size() != 0) {
- runAdapter.setRunList(workflow.getWorkflow_runs());
- mRecyclerView.setAdapter(runAdapter);
- mRecyclerView.setVisibility(View.VISIBLE);
- emptyRunHistoryTextView.setVisibility(View.GONE);
+ runAdapter.setRunList(workflow.getWorkflow_runs());
+ mRecyclerView.setAdapter(runAdapter);
+ mRecyclerView.setVisibility(View.VISIBLE);
+ emptyRunHistoryTextView.setVisibility(View.GONE);
- } else {
- mRecyclerView.setVisibility(View.GONE);
- emptyRunHistoryTextView.setVisibility(View.VISIBLE);
+ } else {
+ mRecyclerView.setVisibility(View.GONE);
+ emptyRunHistoryTextView.setVisibility(View.VISIBLE);
+ }
+ } catch (NullPointerException np) {
+ np.printStackTrace();
}
- }catch(NullPointerException np){
- np.printStackTrace();
- }
- // progressDialog.dismiss();
+ // progressDialog.dismiss();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
index 0449dd7..9f45d7f 100644
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
+++ b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
@@ -2,10 +2,10 @@ package org.apache.taverna.mobile.fragments.workflowdetails;
/**
* Apache Taverna Mobile
* Copyright 2015 The Apache Software Foundation
-
+ *
* This product includes software developed at
* The Apache Software Foundation (http://www.apache.org/).
-
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -24,6 +24,26 @@ package org.apache.taverna.mobile.fragments.workflowdetails;
* under the License.
*/
+import com.dropbox.client2.DropboxAPI;
+import com.dropbox.client2.ProgressListener;
+import com.dropbox.client2.android.AndroidAuthSession;
+import com.dropbox.client2.exception.DropboxException;
+import com.dropbox.client2.session.AppKeyPair;
+
+import org.apache.taverna.mobile.R;
+import org.apache.taverna.mobile.activities.DashboardMainActivity;
+import org.apache.taverna.mobile.adapters.WorkflowAdapter;
+import org.apache.taverna.mobile.tavernamobile.TavernaPlayerAPI;
+import org.apache.taverna.mobile.tavernamobile.User;
+import org.apache.taverna.mobile.tavernamobile.Workflow;
+import org.apache.taverna.mobile.utils.DetailsLoader;
+import org.apache.taverna.mobile.utils.RunTask;
+import org.apache.taverna.mobile.utils.WorkflowDownloadManager;
+import org.apache.taverna.mobile.utils.WorkflowDB;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DownloadManager;
@@ -31,7 +51,6 @@ import android.app.LoaderManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.content.res.Resources;
@@ -56,33 +75,10 @@ import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
-import android.widget.ZoomControls;
-
-import com.dropbox.client2.DropboxAPI;
-import com.dropbox.client2.ProgressListener;
-import com.dropbox.client2.android.AndroidAuthSession;
-import com.dropbox.client2.exception.DropboxException;
-import com.dropbox.client2.session.AppKeyPair;
-
-import org.apache.taverna.mobile.R;
-import org.apache.taverna.mobile.activities.DashboardMainActivity;
-import org.apache.taverna.mobile.activities.RunResult;
-import org.apache.taverna.mobile.adapters.WorkflowAdapter;
-import org.apache.taverna.mobile.tavernamobile.TavernaPlayerAPI;
-import org.apache.taverna.mobile.tavernamobile.User;
-import org.apache.taverna.mobile.tavernamobile.Workflow;
-import org.apache.taverna.mobile.utils.DetailsLoader;
-import org.apache.taverna.mobile.utils.RunTask;
-import org.apache.taverna.mobile.utils.WorkflowDownloadManager;
-import org.apache.taverna.mobile.utils.Workflow_DB;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -90,7 +86,6 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
-import java.nio.charset.CharsetEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -98,34 +93,38 @@ import java.util.Date;
/**
* Created by Larry Akah on 6/9/15.
*/
-public class WorkflowdetailFragment extends Fragment implements View.OnClickListener,LoaderManager.LoaderCallbacks<Workflow>{
+public class WorkflowdetailFragment extends Fragment implements View.OnClickListener,
+ LoaderManager.LoaderCallbacks<Workflow> {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
- private DownloadManager downloadManager;
+ private static final String BOX_APP_KEY = "doicbvkfyzligh2";
+ private static final String BOX_APP_SECRET = "3uuuw36mm7jkflc";
+ public static String WORKFLO_ID = "";
+ public static Context cont;
+ public static String workflow_uri;
static View rootView;
+ static Animation zoomin;
+ static Animation zoomout;
+ static Workflow currentWorkflow = null;
private static ProgressDialog progressDialog;
- public AlertDialog runDialog;
- public AlertDialog.Builder alertDialogBuilder;
private static String download_url;
- public static String WORKFLO_ID = "";
- public static Context cont;
- SharedPreferences sharedPreferences;
private static boolean LOAD_STATE = false;
private static boolean DROPUPLOAD = false;
- static Animation zoomin;
- static Animation zoomout;
+ public AlertDialog runDialog;
+ public AlertDialog.Builder alertDialogBuilder;
public boolean isZoomIn;
- public static String workflow_uri ;
- final static private String BOX_APP_KEY = "doicbvkfyzligh2";
- final static private String BOX_APP_SECRET = "3uuuw36mm7jkflc";
- static Workflow currentWorkflow = null;
+ SharedPreferences sharedPreferences;
+ private DownloadManager downloadManager;
private long wid;
private DropboxAPI<AndroidAuthSession> mDBApi;
+ public WorkflowdetailFragment() {
+ }
+
/**
* Returns a new instance of this fragment for the given section
* number.
@@ -138,30 +137,114 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
return fragment;
}
- public static WorkflowdetailFragment getInstance(){
+ public static WorkflowdetailFragment getInstance() {
return WorkflowdetailFragment.getInstance();
}
- public WorkflowdetailFragment() {
+ public static void setWorkflowDetails(final Workflow wk) {
+ currentWorkflow = wk;
+ final TextView author = (TextView) rootView.findViewById(R.id.wkf_author_text);
+ //final TextView updated = (TextView) rootView.findViewById(R.id.wupdatedat);
+ final TextView type = (TextView) rootView.findViewById(R.id.wtype);
+ final TextView title = (TextView) rootView.findViewById(R.id.wtitle);
+ final TextView desc = (TextView) rootView.findViewById(R.id.wdescription);
+ final TextView createdat = (TextView) rootView.findViewById(R.id.wcreatedat);
+ final ImageView preview = (ImageView) rootView.findViewById(R.id.wkf_image);
+ WORKFLO_ID = wk.getWorkflow_title();
+ ((Activity) cont).runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ //load necessary widgets
+
+ //set widget data
+ //Use android resources to insert text into placeholder
+ Resources resources = cont.getResources();
+ User uploader = wk.getUploader();
+ //String uploaderText = String.format(resources.getString(R.string
+ // .workflow_author), uploader != null ? uploader.getName():"Unknown");
+ author.setText((uploader != null) ? uploader.getName() : "Unknown");
+ title.setText(wk.getWorkflow_title());
+ if (wk.getWorkflow_description() != null) {
+ desc.setText(wk.getWorkflow_description());
+ } else {
+ //desc.setVisibility(View.INVISIBLE); //Not sure I trust this! Needs
+ // investigating.
+ }
+ String createdAtText = String.format(resources.getString(R.string.created), wk
+ .getWorkflow_datecreated());
+ createdat.setText(createdAtText);
+ //updated.setText("Workflow Description");
+ String typeText = String.format(resources.getString(R.string.workflow_type_text),
+ wk.getWorkflow_Type());
+ type.setText(typeText);
+
+ //preview.setImageURI(Uri.parse(wk.getWorkflow_preview()));
+ new LoadImageThread(preview, wk.getWorkflow_preview()).execute();
+ download_url = wk.getWorkflow_remote_url();
+ zoomin.setAnimationListener(new Animation.AnimationListener() {
+
+ @Override
+ public void onAnimationStart(Animation arg0) {
+ // TODO Auto-generated method stub
+ preview.startAnimation(zoomout);
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onAnimationEnd(Animation arg0) {
+ preview.startAnimation(zoomout);
+
+ }
+ });
+ zoomout.setAnimationListener(new Animation.AnimationListener() {
+
+ @Override
+ public void onAnimationStart(Animation arg0) {
+ // TODO Auto-generated method stub
+ preview.startAnimation(zoomin);
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onAnimationEnd(Animation arg0) {
+ preview.startAnimation(zoomin);
+
+ }
+ });
+ progressDialog.dismiss();
+ }
+ });
+ // preview.setOnClickListener(WorkflowdetailFragment.getInstance());
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
+ savedInstanceState) {
AppKeyPair appKeys = new AppKeyPair(BOX_APP_KEY, BOX_APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
- // long workflowid = getActivity().getIntent().getLongExtra("workflowid", 0);
+ // long workflowid = getActivity().getIntent().getLongExtra("workflowid", 0);
rootView = inflater.inflate(R.layout.fragment_workflow_detail, container, false);
progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage(getActivity().getResources().getString(R.string.loading));
progressDialog.setCancelable(false);
- // WORKFLO_ID = workflowid;
+ // WORKFLO_ID = workflowid;
zoomin = AnimationUtils.loadAnimation(getActivity(), R.anim.zoomin);
zoomout = AnimationUtils.loadAnimation(getActivity(), R.anim.zoomout);
isZoomIn = false;
- sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
+ sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
wid = getActivity().getIntent().getLongExtra("wid", 0);
Button createRun = (Button) rootView.findViewById(R.id.run_wk);
createRun.setOnClickListener(this);
@@ -171,31 +254,32 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
mark_workflow.setOnClickListener(this);
final String favs = sharedPreferences.getString(WorkflowAdapter.FAVORITE_LIST_DB, "");
String[] ids = favs.split(",");
- if(ids.length > 0) {
+ if (ids.length > 0) {
for (String id : ids)
- if (id.equalsIgnoreCase("" +wid )){
- mark_workflow.setBackgroundResource(R.drawable.abc_list_selector_disabled_holo_light);
+ if (id.equalsIgnoreCase("" + wid)) {
+ mark_workflow.setBackgroundResource(R.drawable
+ .abc_list_selector_disabled_holo_light);
break;
}
}
rootView.findViewById(R.id.saveToDropboxButton).setOnClickListener(this);
rootView.findViewById(R.id.saveToGoogleDriveButton).setOnClickListener(this);
- (rootView.findViewById(R.id.wkf_image)).setOnLongClickListener(new View.OnLongClickListener() {
+ (rootView.findViewById(R.id.wkf_image)).setOnLongClickListener(new View
+ .OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
view.setAnimation(zoomin);
return true;
}
});
- downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
+ downloadManager = (DownloadManager) getActivity().getSystemService(Context
+ .DOWNLOAD_SERVICE);
return rootView;
}
/**
* Called when a fragment is first attached to its activity.
* {@link #onCreate(android.os.Bundle)} will be called after this.
- *
- * @param activity
*/
//@Override
//public void onAttach(Activity activity) {
@@ -210,19 +294,23 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
@Override
public void onClick(View view) {
- switch(view.getId()){
+ switch (view.getId()) {
case R.id.run_wk:
- if (((TextView)rootView.findViewById(R.id.wtype)).getText().toString().contains("Taverna 2"))
+ if (((TextView) rootView.findViewById(R.id.wtype)).getText().toString().contains
+ ("Taverna 2"))
new WorkflowProcessTask(getActivity()).execute(download_url);
else
- Toast.makeText(getActivity(), "Sorry! Only Taverna 2 workflows can be run.", Toast.LENGTH_LONG).show();
+ Toast.makeText(getActivity(), "Sorry! Only Taverna 2 workflows can be run.",
+ Toast.LENGTH_LONG).show();
break;
case R.id.download_wk:
// start the android Download manager to start downloading a remote workflow file
- WorkflowDownloadManager dmgr = new WorkflowDownloadManager(getActivity(), downloadManager);
+ WorkflowDownloadManager dmgr = new WorkflowDownloadManager(getActivity(),
+ downloadManager);
try {
- dmgr.downloadWorkflow(new File(PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(
- DashboardMainActivity.APP_DIRECTORY_NAME, "/")),
+ dmgr.downloadWorkflow(new File(PreferenceManager.getDefaultSharedPreferences
+ (getActivity()).getString(
+ DashboardMainActivity.APP_DIRECTORY_NAME, "/")),
download_url);
} catch (Exception e) {
e.printStackTrace();
@@ -241,19 +329,25 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
mfav.add(SimpleDateFormat.getDateTimeInstance().format(new Date()).toString());
mfav.add(currentWorkflow.getWorkflow_details_url());
mfav.add(((TextView) rootView.findViewById(R.id.wkf_author)).getText());
- int result = new Workflow_DB(getActivity(), WorkflowAdapter.WORKFLOW_FAVORITE_KEY).insert(mfav);
- if(result >0) {
- sharedPreferences.edit().putString(WorkflowAdapter.FAVORITE_LIST_DB, favs+wid+",").apply();
- Toast.makeText(getActivity(), "Workflow marked as favorite", Toast.LENGTH_SHORT).show();
- view.setBackgroundResource(R.drawable.abc_list_selector_disabled_holo_light);
-
- }else if(result == -1){
- Toast.makeText(getActivity(),"Sorry! This workflow has already been marked as a favourite",Toast.LENGTH_SHORT).show();
- }else
- Toast.makeText(getActivity(),"Error!, please try again",Toast.LENGTH_SHORT).show();
+ int result = new WorkflowDB(getActivity(), WorkflowAdapter
+ .WORKFLOW_FAVORITE_KEY).insert(mfav);
+ if (result > 0) {
+ sharedPreferences.edit().putString(WorkflowAdapter.FAVORITE_LIST_DB, favs +
+ wid + ",").apply();
+ Toast.makeText(getActivity(), "Workflow marked as favorite", Toast
+ .LENGTH_SHORT).show();
+ view.setBackgroundResource(R.drawable.abc_list_selector_disabled_holo_light);
+
+ } else if (result == -1) {
+ Toast.makeText(getActivity(), "Sorry! This workflow has already been marked " +
+ "as a favourite", Toast.LENGTH_SHORT).show();
+ } else
+ Toast.makeText(getActivity(), "Error!, please try again", Toast.LENGTH_SHORT)
+ .show();
break;
case R.id.saveToDropboxButton:
- String authToken = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("dropboxauth", "");
+ String authToken = PreferenceManager.getDefaultSharedPreferences(getActivity())
+ .getString("dropboxauth", "");
if (authToken.isEmpty())
mDBApi.getSession().startOAuth2Authentication(getActivity());
else {
@@ -275,8 +369,8 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
@Override
public void onResume() {
super.onResume();
- if(!LOAD_STATE)
- workflow_uri = getActivity().getIntent().getStringExtra("uri");
+ if (!LOAD_STATE)
+ workflow_uri = getActivity().getIntent().getStringExtra("uri");
getActivity().getLoaderManager().initLoader(1, null, this).forceLoad();
@@ -285,7 +379,8 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
// Required to complete auth, sets the access token on the session
mDBApi.getSession().finishAuthentication();
String accessToken = mDBApi.getSession().getOAuth2AccessToken();
- PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString("dropboxauth", accessToken).commit();
+ PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString
+ ("dropboxauth", accessToken).commit();
new WorkflowDriveUpload().execute(download_url);
} catch (IllegalStateException e) {
Log.i("DbAuthLog", "Error authenticating", e);
@@ -303,7 +398,7 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
public Loader<Workflow> onCreateLoader(int i, Bundle bundle) {
progressDialog.show();
return new DetailsLoader(getActivity(),
- DetailsLoader.LOAD_TYPE.TYPE_WORKFLOW_DETAIL,
+ DetailsLoader.LoadType.TYPE_WORKFLOW_DETAIL,
workflow_uri);
}
@@ -317,91 +412,29 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
workflowLoader.reset();
}
- public static void setWorkflowDetails(final Workflow wk){
- currentWorkflow = wk;
- final TextView author = (TextView) rootView.findViewById(R.id.wkf_author_text);
- //final TextView updated = (TextView) rootView.findViewById(R.id.wupdatedat);
- final TextView type = (TextView) rootView.findViewById(R.id.wtype);
- final TextView title = (TextView) rootView.findViewById(R.id.wtitle);
- final TextView desc = (TextView) rootView.findViewById(R.id.wdescription);
- final TextView createdat = (TextView) rootView.findViewById(R.id.wcreatedat);
- final ImageView preview = (ImageView) rootView.findViewById(R.id.wkf_image);
- WORKFLO_ID = wk.getWorkflow_title();
- ((Activity)cont).runOnUiThread(new Runnable() {
- @Override
- public void run() {
- //load necessary widgets
-
- //set widget data
- //Use android resources to insert text into placeholder
- Resources resources = cont.getResources();
- User uploader = wk.getUploader();
- //String uploaderText = String.format(resources.getString(R.string.workflow_author), uploader != null ? uploader.getName():"Unknown");
- author.setText((uploader != null) ? uploader.getName() : "Unknown");
- title.setText(wk.getWorkflow_title());
- if (wk.getWorkflow_description() != null) {
- desc.setText(wk.getWorkflow_description());
- } else {
- //desc.setVisibility(View.INVISIBLE); //Not sure I trust this! Needs investigating.
- }
- String createdAtText = String.format(resources.getString(R.string.created), wk.getWorkflow_datecreated());
- createdat.setText(createdAtText);
- //updated.setText("Workflow Description");
- String typeText = String.format(resources.getString(R.string.workflow_type_text), wk.getWorkflow_Type());
- type.setText(typeText);
-
- //preview.setImageURI(Uri.parse(wk.getWorkflow_preview()));
- new LoadImageThread(preview, wk.getWorkflow_preview()).execute();
- download_url =wk.getWorkflow_remote_url();
- zoomin.setAnimationListener(new Animation.AnimationListener() {
-
- @Override
- public void onAnimationStart(Animation arg0) {
- // TODO Auto-generated method stub
- preview.startAnimation(zoomout);
- }
-
- @Override
- public void onAnimationRepeat(Animation arg0) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onAnimationEnd(Animation arg0) {
- preview.startAnimation(zoomout);
-
- }
- });
- zoomout.setAnimationListener(new Animation.AnimationListener() {
-
- @Override
- public void onAnimationStart(Animation arg0) {
- // TODO Auto-generated method stub
- preview.startAnimation(zoomin);
- }
-
- @Override
- public void onAnimationRepeat(Animation arg0) {
- // TODO Auto-generated method stub
-
- }
+ //create and return a new TextView
+ public TextView createTextView(Context mcontext, String placeholder) {
+ TextView tv = new TextView(mcontext);
+ tv.setText(placeholder);
+ tv.setMinLines(2);
- @Override
- public void onAnimationEnd(Animation arg0) {
- preview.startAnimation(zoomin);
+ return tv;
+ }
- }
- });
- progressDialog.dismiss();
- }
- });
- // preview.setOnClickListener(WorkflowdetailFragment.getInstance());
+ //create and return a new EdiText view
+ public EditText createEditText(Context ctx, int i) {
+ EditText edt;
+ edt = new EditText(ctx);
+ edt.setHint("Enter Value");
+ edt.setMinLines(1);
+ edt.setId(i);
+ return edt;
}
- private static class LoadImageThread extends AsyncTask<String, Void, Bitmap>{
- ImageView imageView;
- String src ;
+ private static class LoadImageThread extends AsyncTask<String, Void, Bitmap> {
+ ImageView imageView;
+ String src;
+
public LoadImageThread(ImageView image, String source) {
imageView = image;
src = source;
@@ -417,7 +450,7 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
- myBitmap = BitmapFactory.decodeStream(input);
+ myBitmap = BitmapFactory.decodeStream(input);
// imageView.setImageBitmap(myBitmap);
} catch (IOException e) {
e.printStackTrace();
@@ -431,29 +464,11 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
}
}
- //create and return a new TextView
- public TextView createTextView(Context mcontext, String placeholder){
- TextView tv = new TextView(mcontext);
- tv.setText(placeholder);
- tv.setMinLines(2);
-
- return tv;
- }
-
- //create and return a new EdiText view
- public EditText createEditText(Context ctx, int i){
- EditText edt;
- edt = new EditText(ctx);
- edt.setHint("Enter Value");
- edt.setMinLines(1);
- edt.setId(i);
- return edt;
- }
//fetch and compute the framework on which the run inputs are to be built and entered
- private class WorkflowRunTask extends AsyncTask<String, Void, String>{
+ private class WorkflowRunTask extends AsyncTask<String, Void, String> {
- private Context context;
TavernaPlayerAPI tavernaPlayerAPI = new TavernaPlayerAPI();
+ private Context context;
private WorkflowRunTask(Context context) {
this.context = context;
@@ -471,10 +486,13 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
StringBuffer sb = new StringBuffer();
try {
- URL workflowurl = new URL(new TavernaPlayerAPI(this.context).PLAYER_RUN_FRAMEWORK_URL+params[0]);
+ URL workflowurl = new URL(new TavernaPlayerAPI(this.context)
+ .PLAYER_RUN_FRAMEWORK_URL + params[0]);
HttpURLConnection connection = (HttpURLConnection) workflowurl.openConnection();
- String userpass = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" + tavernaPlayerAPI.getPlayerUserPassword(this.context);
- String basicAuth = "Basic " + Base64.encodeToString(userpass.getBytes(), Base64.DEFAULT);
+ String userpass = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" +
+ tavernaPlayerAPI.getPlayerUserPassword(this.context);
+ String basicAuth = "Basic " + Base64.encodeToString(userpass.getBytes(), Base64
+ .DEFAULT);
connection.setRequestProperty("Authorization", basicAuth);
connection.setRequestProperty("Accept", "application/json");
@@ -497,7 +515,7 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
br.close();
return sb.toString();
- }catch (IOException ex){
+ } catch (IOException ex) {
ex.printStackTrace();
}
return sb.toString();
@@ -515,10 +533,11 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
try {
final JSONObject json = new JSONObject(result); //main server response json
JSONObject mjson = json.getJSONObject("run"); //main framework response json
- String name = mjson.getString("name"); //a name that can be configured or edited for the new run to be created
+ String name = mjson.getString("name"); //a name that can be configured or edited
+ // for the new run to be created
ll.addView(createTextView(ctx, name));
final JSONArray attr_array = mjson.getJSONArray("inputs_attributes");
- for(int i=0; i<attr_array.length(); i++){
+ for (int i = 0; i < attr_array.length(); i++) {
JSONObject obj = attr_array.getJSONObject(i);
ll.addView(createTextView(ctx, obj.getString("name")));
ll.addView(createEditText(ctx, i));
@@ -526,20 +545,25 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
alertDialogBuilder = new AlertDialog.Builder(ctx);
alertDialogBuilder.setView(sv);
- // alertDialogBuilder.setMessage(result);
+ // alertDialogBuilder.setMessage(result);
alertDialogBuilder.setIcon(ctx.getResources().getDrawable(R.mipmap.ic_launcher));
alertDialogBuilder.setTitle("New Workflow Run");
- alertDialogBuilder.setPositiveButton("Execute", new DialogInterface.OnClickListener() {
+ alertDialogBuilder.setPositiveButton("Execute", new DialogInterface
+ .OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int n = attr_array.length();
- for(int j=0; j<n; j++){
+ for (int j = 0; j < n; j++) {
try {
EditText inputText = (EditText) ll.findViewById(j);
- String value = inputText.getText().toString();//get input entry entered by the user
- JSONObject jojb = attr_array.getJSONObject(j); //get the input attributes provided by the skeleton
- jojb.put("value", value); //replace value field in object with the entry provided by the user
- attr_array.put(j, jojb); //replace the input entry with the new name/input json object
+ String value = inputText.getText().toString(); //get input entry
+ // entered by the user
+ JSONObject jojb = attr_array.getJSONObject(j); //get the input
+ // attributes provided by the skeleton
+ jojb.put("value", value); //replace value field in object with
+ // the entry provided by the user
+ attr_array.put(j, jojb); //replace the input entry with the new
+ // name/input json object
} catch (JSONException e) {
e.printStackTrace();
@@ -553,13 +577,14 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
new RunTask(ctx).execute(json.toString());
} catch (JSONException e) {
e.printStackTrace();
- }catch (Exception ex){
+ } catch (Exception ex) {
ex.printStackTrace();
}
}
});
- alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface
+ .OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
@@ -579,16 +604,20 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
}
/**
- * Send request for the execution of a run on a Taverna server through the Taverna player using the Player API
- * This process passes through several steps,\n
- * 1- Downloading and caching a local version of the workflow whose run we need \n
- * 2- uploading the workflow through the portal to register it so a run can be generated from it. The request requires some authentication
- * 3- Retrieving the results and extracting data required to create a run (the workflow_id) as provided by the results
- * 4- Posting a run request to the player so that a new run can be created and started
- * 5- retrieving a run framework so that users can know what types of input is expected for a successful run
- * 6- retrieving and displaying run results
+ * Send request for the execution of a run on a Taverna server through the Taverna player using
+ * the Player API
+ * This process passes through several steps,\n
+ * 1- Downloading and caching a local version of the workflow whose run we need \n
+ * 2- uploading the workflow through the portal to register it so a run can be generated from
+ * it. The request requires some authentication
+ * 3- Retrieving the results and extracting data required to create a run (the workflow_id) as
+ * provided by the results
+ * 4- Posting a run request to the player so that a new run can be created and started
+ * 5- retrieving a run framework so that users can know what types of input is expected for a
+ * successful run
+ * 6- retrieving and displaying run results
*/
- private class WorkflowProcessTask extends AsyncTask<String, Void, String>{
+ private class WorkflowProcessTask extends AsyncTask<String, Void, String> {
private Context context;
@@ -607,56 +636,65 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
StringBuffer sb = new StringBuffer();
try {
//prepare connection requests
- URL workflowurl = new URL(params[0]); //the resource xml file representing the workflow to be uploaded to the player
- String playerurl = new TavernaPlayerAPI(this.context).PLAYER_BASE_URL+"workflows.json";
+ URL workflowurl = new URL(params[0]); //the resource xml file representing the
+ // workflow to be uploaded to the player
+ String playerurl = new TavernaPlayerAPI(this.context).PLAYER_BASE_URL +
+ "workflows.json";
TavernaPlayerAPI tavernaPlayerAPI = new TavernaPlayerAPI();
URL posturl = new URL(playerurl);
HttpURLConnection connection = (HttpURLConnection) posturl.openConnection();
HttpURLConnection wconn = (HttpURLConnection) workflowurl.openConnection();
- wconn.setRequestMethod("GET");
- wconn.setDoOutput(true);
- wconn.setRequestProperty("Accept", "application/xml");
- wconn.connect();
-
- String user = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" + tavernaPlayerAPI.getPlayerUserPassword(this.context);
- String basicAuth = "Basic " + Base64.encodeToString(user.getBytes(), Base64.DEFAULT);
+ wconn.setRequestMethod("GET");
+ wconn.setDoOutput(true);
+ wconn.setRequestProperty("Accept", "application/xml");
+ wconn.connect();
+
+ String user = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" +
+ tavernaPlayerAPI.getPlayerUserPassword(this.context);
+ String basicAuth = "Basic " + Base64.encodeToString(user.getBytes(), Base64
+ .DEFAULT);
//read the file from remote resource and encode the stream with a base64 algorithm
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(wconn.getInputStream()));
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(wconn
+ .getInputStream()));
String str = "";
while ((str = bufferedReader.readLine()) != null)
- sb.append(str); //in this string builder we have read the workflow( as .t2flow or .xml) workflow from remote resource. Now we need to post that to the player.
+ sb.append(str); //in this string builder we have read the workflow( as
+ // .t2flow or .xml) workflow from remote resource. Now we need to post that to
+ // the player.
bufferedReader.close();
wconn.disconnect();
String data = "{\"document\":\"data:application/octet-stream;base64," +
- Base64.encodeToString(sb.toString().getBytes("UTF-8"), Base64.URL_SAFE|Base64.NO_WRAP).replace('-','+')+"\"}";
- String post = "{\"workflow\":"+data+"}";
+ Base64.encodeToString(sb.toString().getBytes("UTF-8"), Base64.URL_SAFE |
+ Base64.NO_WRAP).replace('-', '+') + "\"}";
+ String post = "{\"workflow\":" + data + "}";
//clear sb so that we can use it again to fetch results from this post request
- sb.delete(0,sb.length()-1);
- System.out.println("BODY=>"+post);
+ sb.delete(0, sb.length() - 1);
+ System.out.println("BODY=>" + post);
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization", basicAuth);
connection.setRequestProperty("Accept", "*/*");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Content-Encoding", "UTF-8");
- connection.setUseCaches (false);
+ connection.setUseCaches(false);
connection.setDoOutput(true);
connection.connect(); //send request
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
- dos.writeBytes(post);//write post data which is a formatted json data representing body of workflow
+ dos.writeBytes(post); //write post data which is a formatted json data
+ // representing body of workflow
dos.flush();
dos.close();
InputStream dis = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
- while ((str = br.readLine())!= null)
+ while ((str = br.readLine()) != null)
sb.append(str);
connection.disconnect();
- }catch (IOException e){
+ } catch (IOException e) {
e.printStackTrace();
sb.append("Error reading remote workflow. Please try again later");
}
@@ -665,8 +703,11 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
}
/**
- * Receives a result from the player as a json describing the workflow that has just been uploaded along with key components that
- * can be used to generate a run from thw workflow. A run is started that would fetch and build a sample UI for a workflow run to be executed
+ * Receives a result from the player as a json describing the workflow that has just been
+ * uploaded along with key components that
+ * can be used to generate a run from thw workflow. A run is started that would fetch and
+ * build a sample UI for a workflow run to be executed
+ *
* @param s the json result that describes the uploaded workflow
*/
@Override
@@ -687,7 +728,7 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
/**
* Upload workflow from myexperiment to DropBox
*/
- private class WorkflowDriveUpload extends AsyncTask<String, Void, String>{
+ private class WorkflowDriveUpload extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
Toast.makeText(getActivity(), "Saving workflow to dropBox", Toast.LENGTH_LONG).show();
@@ -695,9 +736,9 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
@Override
protected String doInBackground(String... files) {
- // File file = new File(files[0]);
- HttpURLConnection mconn ;
- // FileInputStream inputStream = null;
+ // File file = new File(files[0]);
+ HttpURLConnection mconn;
+ // FileInputStream inputStream = null;
DropboxAPI.Entry response = null;
DropboxAPI.Entry metaDataEntry = null;
try {
@@ -705,20 +746,23 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
mconn.setRequestMethod("GET");
mconn.connect();
- // inputStream = new FileInputStream(file);
+ // inputStream = new FileInputStream(file);
- response = mDBApi.putFile("/"+ Uri.parse(files[0]).getLastPathSegment(), mconn.getInputStream(),
+ response = mDBApi.putFile("/" + Uri.parse(files[0]).getLastPathSegment(), mconn
+ .getInputStream(),
mconn.getContentLength(), null, new ProgressListener() {
- @Override
- public void onProgress(long l, long l2) {
- if (l==l2){
- Toast.makeText(getActivity(), "Upload complete", Toast.LENGTH_LONG).show();
- }
- }
- });
+ @Override
+ public void onProgress(long l, long l2) {
+ if (l == l2) {
+ Toast.makeText(getActivity(), "Upload complete", Toast
+ .LENGTH_LONG).show();
+ }
+ }
+ });
Log.i("DbExampleLog", "The uploaded file's rev is: " + response.rev);
- // metaDataEntry = mDBApi.metadata("/"+Uri.parse(files[0]).getLastPathSegment(), 1, null, false, null);
+ // metaDataEntry = mDBApi.metadata("/"+Uri.parse(files[0]).getLastPathSegment(),
+ // 1, null, false, null);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DropboxException e) {
@@ -734,12 +778,13 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
@Override
protected void onPostExecute(String s) {
- if(null != s) {
- Toast.makeText(getActivity(), "File Saved to dropbox. Reference: " + s, Toast.LENGTH_LONG).show();
+ if (null != s) {
+ Toast.makeText(getActivity(), "File Saved to dropbox. Reference: " + s, Toast
+ .LENGTH_LONG).show();
DROPUPLOAD = true;
- }
- else{
- Toast.makeText(getActivity(), "Failed to save to dropbox "+s, Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(getActivity(), "Failed to save to dropbox " + s, Toast
+ .LENGTH_LONG).show();
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java
index 8eeba06..f2755a3 100644
--- a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java
+++ b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java
@@ -12,16 +12,16 @@ public class Runs {
private String run_ended_date;
private String state;
private String run_author;
- public static enum RUN_STATE { FAILED,FINISHED,RUNNING};
-
public Runs(String run_name, String run_started_date, String run_ended_date, String state) {
this.run_name = run_name;
this.run_started_date = run_started_date;
this.run_ended_date = run_ended_date;
- this.state=state;
+ this.state = state;
}
+ ;
+
public long getRun_id() {
return run_id;
}
@@ -38,13 +38,13 @@ public class Runs {
this.run_workflow_id = run_workflow_id;
}
- public RUN_STATE getState() {
- if(state.equalsIgnoreCase("finished"))
- return RUN_STATE.FINISHED;
+ public RunState getState() {
+ if (state.equalsIgnoreCase("finished"))
+ return RunState.FINISHED;
else if (state.equalsIgnoreCase("failed"))
- return RUN_STATE.FAILED;
+ return RunState.FAILED;
else
- return RUN_STATE.RUNNING;
+ return RunState.RUNNING;
}
public void setState(String state) {
@@ -82,4 +82,6 @@ public class Runs {
public void setRun_ended_date(String run_ended_date) {
this.run_ended_date = run_ended_date;
}
+
+ public static enum RunState { FAILED, FINISHED, RUNNING }
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java
index 638094b..41f392a 100644
--- a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java
+++ b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java
@@ -2,10 +2,10 @@ package org.apache.taverna.mobile.tavernamobile;
/**
* Apache Taverna Mobile
* Copyright 2015 The Apache Software Foundation
-
+ *
* This product includes software developed at
* The Apache Software Foundation (http://www.apache.org/).
-
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -23,6 +23,7 @@ package org.apache.taverna.mobile.tavernamobile;
* specific language governing permissions and limitations
* under the License.
*/
+
import android.content.Context;
import android.preference.PreferenceManager;
@@ -35,23 +36,28 @@ public class TavernaPlayerAPI {
public static String PLAYER_BASE_URL = "http://heater.cs.man.ac.uk:3000/";
public static String SERVER_BASE_URL = "http://heater.cs.man.ac.uk:8090/taverna-2.5.4/";
- public static String PLAYER_WORKFLOW_URL = PLAYER_BASE_URL+"workflows/";
- public static String PLAYER_RUN_URL = PLAYER_BASE_URL+"runs/";
- public static String PLAYER_RUN_FRAMEWORK_URL = PLAYER_RUN_URL+"new?workflow_id="; //returns a json 'framework' used for creating runs for the given workflow
+ public static String PLAYER_WORKFLOW_URL = PLAYER_BASE_URL + "workflows/";
+ public static String PLAYER_RUN_URL = PLAYER_BASE_URL + "runs/";
+ public static String PLAYER_RUN_FRAMEWORK_URL = PLAYER_RUN_URL + "new?workflow_id=";
+ //returns a json 'framework' used for creating runs for the given workflow
public TavernaPlayerAPI(Context context) {
- String server = PreferenceManager.getDefaultSharedPreferences(context).getString("pref_server_url","/");
- String player = PreferenceManager.getDefaultSharedPreferences(context).getString("pref_player_url","/");
- String user = PreferenceManager.getDefaultSharedPreferences(context).getString("pref_player_url","/");
- String password = PreferenceManager.getDefaultSharedPreferences(context).getString("pref_player_url","/");
+ String server = PreferenceManager.getDefaultSharedPreferences(context).getString
+ ("pref_server_url", "/");
+ String player = PreferenceManager.getDefaultSharedPreferences(context).getString
+ ("pref_player_url", "/");
+ String user = PreferenceManager.getDefaultSharedPreferences(context).getString
+ ("pref_player_url", "/");
+ String password = PreferenceManager.getDefaultSharedPreferences(context).getString
+ ("pref_player_url", "/");
PLAYER_BASE_URL = player;
SERVER_BASE_URL = server;
- PLAYER_WORKFLOW_URL = PLAYER_BASE_URL+"workflows/";
- PLAYER_RUN_URL = PLAYER_BASE_URL+"runs/";
- PLAYER_RUN_FRAMEWORK_URL = PLAYER_RUN_URL+"new?workflow_id=";
+ PLAYER_WORKFLOW_URL = PLAYER_BASE_URL + "workflows/";
+ PLAYER_RUN_URL = PLAYER_BASE_URL + "runs/";
+ PLAYER_RUN_FRAMEWORK_URL = PLAYER_RUN_URL + "new?workflow_id=";
}
- public TavernaPlayerAPI(){
+ public TavernaPlayerAPI() {
}
@@ -75,15 +81,16 @@ public class TavernaPlayerAPI {
return PLAYER_RUN_FRAMEWORK_URL;
}
- public String getPlayerUserName(Context c){
- return PreferenceManager.getDefaultSharedPreferences(c).getString("pref_user","default");
+ public String getPlayerUserName(Context c) {
+ return PreferenceManager.getDefaultSharedPreferences(c).getString("pref_user", "default");
}
- public String getPlayerUserPassword(Context c){
- return PreferenceManager.getDefaultSharedPreferences(c).getString("pref_password","default");
+ public String getPlayerUserPassword(Context c) {
+ return PreferenceManager.getDefaultSharedPreferences(c).getString("pref_password",
+ "default");
}
- public static class Authenticator extends java.net.Authenticator{
+ public static class Authenticator extends java.net.Authenticator {
private String username, password;
public Authenticator(String username, String password) {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java
index 09ca6e5..9d85682 100644
--- a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java
+++ b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java
@@ -2,10 +2,10 @@ package org.apache.taverna.mobile.tavernamobile;
/**
* Apache Taverna Mobile
* Copyright 2015 The Apache Software Foundation
-
+ *
* This product includes software developed at
* The Apache Software Foundation (http://www.apache.org/).
-
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -24,11 +24,11 @@ package org.apache.taverna.mobile.tavernamobile;
* under the License.
*/
-import android.graphics.Bitmap;
-
import org.apache.taverna.mobile.adapters.WorkflowAdapter;
import org.simpleframework.xml.Element;
+import android.graphics.Bitmap;
+
import java.util.List;
/**
@@ -56,11 +56,13 @@ public class User {
@Element(required = false)
protected String website;
protected String details_uri;
+ protected List<Workflow> user_workflows; //a list of workflows owned by this user
private String avatar_url;
- private String row_id; //identifies the row to which this user is being loaded in, in the workflow listview
+ private String row_id; //identifies the row to which this user is being loaded in, in the
+ // workflow listview
private WorkflowAdapter.ViewHolder userViewHolder;
- public User(String rid, WorkflowAdapter.ViewHolder vh){
+ public User(String rid, WorkflowAdapter.ViewHolder vh) {
super();
row_id = rid;
this.userViewHolder = vh;
@@ -78,8 +80,6 @@ public class User {
return this.row_id;
}
- protected List<Workflow> user_workflows; //a list of workflows owned by this user
-
public void setId(String id) {
this.id = id;
}
@@ -165,7 +165,7 @@ public class User {
}
@Override
- public String toString(){
+ public String toString() {
return "This is the user object";
}
}