You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by sa...@apache.org on 2016/10/31 09:30:12 UTC
[4/7] incubator-taverna-mobile git commit: clear codebase
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/fragments/WorkflowItemFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/fragments/WorkflowItemFragment.java b/app/src/main/java/org/apache/taverna/mobile/fragments/WorkflowItemFragment.java
deleted file mode 100644
index 6b4e89d..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/WorkflowItemFragment.java
+++ /dev/null
@@ -1,492 +0,0 @@
-package org.apache.taverna.mobile.fragments;
-/**
- * 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
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.taverna.mobile.R;
-import org.apache.taverna.mobile.adapters.WorkflowAdapter;
-import org.apache.taverna.mobile.tavernamobile.User;
-import org.apache.taverna.mobile.tavernamobile.Workflow;
-import org.apache.taverna.mobile.utils.AvatarLoader;
-import org.apache.taverna.mobile.utils.WorkflowLoader;
-
-import android.app.Activity;
-import android.app.ProgressDialog;
-import android.app.SearchManager;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.support.v4.util.LruCache;
-import android.support.v4.widget.SwipeRefreshLayout;
-import android.support.v7.widget.DefaultItemAnimator;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.support.v7.widget.SearchView;
-import android.text.TextUtils;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.widget.ImageView;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.List;
-
-/**
- * A fragment representing a list of Items.
- * <p/>
- * Large screen devices (such as tablets) are supported by replacing the ListView
- * with a GridView.
- * <p/>
- */
-public class WorkflowItemFragment extends Fragment implements SwipeRefreshLayout
- .OnRefreshListener, SearchView.OnQueryTextListener {
-
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
- private static final String TAG = "WorkflowItemFragment";
- private static final String ARG_PARAM1 = "param1";
- private static final String ARG_PARAM2 = "param2";
- public static Context cx;
- //variables controlling the different kinds of data loading
- public static boolean isLoadMoreData = false;
- public static boolean isRefreshData = false;
- /**
- * The fragment's ListView/GridView.
- */
- private static RecyclerView mListView;
- private static View rootView;
- private static TextView noDataText;
- private static LruCache<String, Bitmap> avatarCache;
- private static WorkflowAdapter workflowAdapter;
- //variables for controlling the infinite scroll mechanism
- private static int previousTotal = 0;
- private boolean stateOn = false;
- private Animation in;
- private ProgressDialog mProgressDialog; //progressbar used to indicate the state of the
- // workflow loaders
- private String mParam1;
- private String mParam2;
- private SwipeRefreshLayout swipeRefreshLayout;
- private LinearLayoutManager mLinearLayoutManager;
- private int visibleThreshold = 3;
- private int firstVisibleItem, visibleItemCount, totalItemCount;
- private int currentPage = 1;
- private boolean loading = true;
- private InfiniteScrollListener scrollListener;
- private RecyclerView.AdapterDataObserver workflowObserver;
-
- /**
- * Mandatory empty constructor for the fragment manager to instantiate the
- * fragment (e.g. upon screen orientation changes).
- */
- public WorkflowItemFragment() {
- }
-
- public static void setCx(Context cx) {
- WorkflowItemFragment.cx = cx;
- }
-
- public static void setRootView(View rootView) {
- WorkflowItemFragment.rootView = rootView;
- }
-
- public static void setIsLoadMoreData(boolean isLoadMoreData) {
- WorkflowItemFragment.isLoadMoreData = isLoadMoreData;
- }
-
- public static void setIsRefreshData(boolean isRefreshData) {
- WorkflowItemFragment.isRefreshData = isRefreshData;
- }
-
- public static WorkflowItemFragment newInstance(String param1, String param2) {
- WorkflowItemFragment fragment = new WorkflowItemFragment();
- Bundle args = new Bundle();
- args.putString(ARG_PARAM1, param1);
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
-
- public static void updateWorkflowUI(final List<Workflow> data) {
-
- ((Activity) cx).runOnUiThread(new Runnable() {
- @Override
- public void run() {
- WorkflowItemFragment.workflowAdapter = new WorkflowAdapter(cx, data);
- if (isLoadMoreData) {
- setIsLoadMoreData(false);
- setIsRefreshData(false);
- ((WorkflowAdapter) mListView.getAdapter()).addItems(data, previousTotal);
- } else {
- mListView.swapAdapter(workflowAdapter, false);
- }
- if (WorkflowItemFragment.workflowAdapter.getItemCount() == 0) {
- mListView.setVisibility(View.GONE);
- noDataText.setVisibility(View.VISIBLE);
- // Toast.makeText(cx, cx.getResources().getString(R.string
- // .err_workflow_conn), Toast.LENGTH_LONG).show();
- } else {
- mListView.setVisibility(View.VISIBLE);
- noDataText.setVisibility(View.GONE);
- }
- }
- });
- }
-
- public static void startLoadingAvatar(final User author) {
-
- ((Activity) cx).runOnUiThread(new Runnable() {
- @Override
- public void run() {
- synchronized (this) {
- author.getUserViewHolder().author_name.setText(author.getName());
- //((TextView) rootView.findViewById(R.id.workflow_author)).setText(author
- // .getName());
- //check whether avatar is already in the cache before trying to download it
- // from remote resource
- if (avatarCache.get(author.getDetailsUri()) == null) {
- new AvatarLoader(author.getUserViewHolder()).execute(author
- .getDetailsUri(), author.getRowId());
- } else {
- author.getUserViewHolder().author_profile.setImageBitmap(avatarCache.get
- (author.getDetailsUri()));
-// ((ImageView) rootView.findViewById(R.id.author_profile_image))
-// .setImageBitmap(avatarCache.get(author.getDetailsUri()));
- }
- Log.d(TAG, "Author cached ID " + author.getDetailsUri() + "\n Name: " +
- "" + author.getName());
- }
- }
- });
- }
-
- /**
- * Called when avatar xml has finished parsing. fetches the avatar remotely and updates the
- * item
- * in the list view
- *
- * @param author the author avatar to load
- */
- public static void updateAvatar(final User author) {
-
- ((Activity) cx).runOnUiThread(new Runnable() {
- @Override
- public void run() {
- // new LoadAuthorAvatar((ImageView) rootView.findViewById(R.id
- // .author_profile_image),author.getDetailsUri()).execute(author.getAvatarUrl());
- new LoadAuthorAvatar(author.getUserViewHolder().author_profile, author
- .getDetailsUri()).execute(author.getAvatarUrl());
- }
- });
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- setCx(getActivity());
- mLinearLayoutManager = new LinearLayoutManager(cx);
- scrollListener = new InfiniteScrollListener();
- workflowObserver = new RecyclerView.AdapterDataObserver() {
-
- @Override
- public void onItemRangeInserted(int positionStart, int itemCount) {
- super.onItemRangeInserted(positionStart, itemCount);
- mListView.swapAdapter(workflowAdapter, false);
- Toast.makeText(getActivity(), "adding more workflows to listview", Toast
- .LENGTH_SHORT).show();
- }
- };
- workflowAdapter = new WorkflowAdapter(getActivity());
- workflowAdapter.registerAdapterDataObserver(workflowObserver);
-
- if (getArguments() != null) {
- mParam1 = getArguments().getString(ARG_PARAM1);
- mParam2 = getArguments().getString(ARG_PARAM2);
- }
- in = AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_in_left);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
- savedInstanceState) {
- setRootView(inflater.inflate(R.layout.fragment_item, container, false));
- noDataText = (TextView) rootView.findViewById(android.R.id.empty);
- swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh);
- swipeRefreshLayout.setOnRefreshListener(this);
-
- // Set the adapter
- mListView = (RecyclerView) rootView.findViewById(android.R.id.list);
- mListView.setHasFixedSize(true);
- mListView.setLayoutManager(mLinearLayoutManager);
- mListView.setAnimation(in);
- mListView.setAdapter(workflowAdapter);
- mListView.setOnScrollListener(scrollListener);
- mListView.setItemAnimator(new DefaultItemAnimator());
-
- final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
- // Use 1/8th of the available memory for this memory cache. up to 4MB for high screen
- // densities and 1.2Mb for low sds
- final int cacheSize = maxMemory / 8;
- avatarCache = new LruCache<String, Bitmap>(cacheSize) {
- @Override
- protected int sizeOf(String key, Bitmap bitmap) {
- // The cache size will be measured in kilobytes
- return bitmap.getByteCount() / 1024;
- }
- };
-
- return rootView;
- }
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- try {
-
- // ((DashboardMainActivity) activity).onSectionAttached(1);
- } catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()
- + " must implement OnFragmentInteractionListener");
- }
- }
-
- /**
- * Called when the view previously created by {@link #onCreateView} has
- * been detached from the fragment. The next time the fragment needs
- * to be displayed, a new view will be created. This is called
- * after {@link #onStop()} and before {@link #onDestroy()}. It is called
- * <em>regardless</em> of whether {@link #onCreateView} returned a
- * non-null view. Internally it is called after the view's state has
- * been saved but before it has been removed from its parent.
- */
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- setRootView(null);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- if (!stateOn) {
- new WorkflowLoader(getActivity(), swipeRefreshLayout).execute("" + currentPage);
-
- if (mListView.getAdapter().getItemCount() == 0) {
- mListView.setVisibility(View.GONE);
- noDataText.setVisibility(View.VISIBLE);
-
- } else {
- mListView.setVisibility(View.VISIBLE);
- noDataText.setVisibility(View.GONE);
- }
- }
-// ((RecyclerView)(getActivity()).findViewById(R.id.favoriteList)).getAdapter()
-// .notifyDataSetChanged();
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- stateOn = true;
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- super.onCreateOptionsMenu(menu, inflater);
- //menu.clear();
- if (menu.size() == 1) {
- //get the searchview and set the searchable configuration
- SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context
- .SEARCH_SERVICE);
- SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
- //assuming this activity is the searchable activity
- searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity()
- .getComponentName()));
- searchView.setSubmitButtonEnabled(true);
- searchView.setOnQueryTextListener(this);
-// searchView.setOnSearchClickListener(this);
-// searchView.setIconifiedByDefault(false);
- MenuItem mit = menu.add("Refresh");
- mit.setIcon(android.R.drawable.stat_notify_sync);
- mit.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
- }
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getTitle().equals("Refresh")) {
- new WorkflowLoader(getActivity(), swipeRefreshLayout).execute("1");
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public void onDestroy() {
- super.onDetach();
- // workflowAdapter.unregisterAdapterDataObserver(workflowObserver);
- }
-
- //handle a request to query for given workflows
- private void performSearch(String search) {
- WorkflowAdapter ladapter = new WorkflowAdapter(getActivity());
- WorkflowAdapter wk = workflowAdapter;
-
- if (!TextUtils.isEmpty(search)) {
- if (null != wk)
- for (int i = 0; i < wk.getItemCount(); i++) {
- Workflow workflow = wk.getItem(i);
- if (workflow.getWorkflowTitle().toLowerCase().contains(search.toLowerCase())) {
- ladapter.addWorkflow(workflow);
- }
- }
-
- mListView.swapAdapter(ladapter, true);
- if (ladapter.getItemCount() == 0)
- Toast.makeText(getActivity(), "No workflows found matching criteria", Toast
- .LENGTH_SHORT).show();
- }
- }
-
- @Override
- public void onRefresh() {
- setIsRefreshData(true);
- setIsLoadMoreData(false);
-
- new WorkflowLoader(getActivity(), swipeRefreshLayout).execute("" + 1);
- }
-
- /**
- * Search action triggered, handle the search request. Filter the workflows by name/title and
- * swap current adapter with the new adapter
- *
- * @param query Search string criteria
- * @return whether or not user handled request 'manually'
- */
- @Override
- public boolean onQueryTextSubmit(String query) {
- performSearch(query);
- return true;
- }
-
- @Override
- public boolean onQueryTextChange(String s) {
- performSearch(s);
- return true;
- }
-
- /**
- * Load the Author Avatar from a background Task
- */
- private static class LoadAuthorAvatar extends AsyncTask<String, Void, Bitmap> {
- ImageView img;
- String row_id_as_key;
-
- public LoadAuthorAvatar(ImageView imageView, String rowid) {
- img = imageView;
- row_id_as_key = rowid;
- }
-
- @Override
- protected Bitmap doInBackground(String... strings) {
- Bitmap myBitmap = null;
- try {
- URL url = new URL(strings[0]);
- HttpURLConnection connection = null;
- connection = (HttpURLConnection) url.openConnection();
- connection.setDoInput(true);
- connection.connect();
- InputStream input = connection.getInputStream();
- myBitmap = BitmapFactory.decodeStream(input);
- input.close();
-
- } catch (IOException e) {
- Log.e(TAG, "doInBackground: ", e);
- }
- return myBitmap;
- }
-
- @Override
- protected void onPostExecute(Bitmap bitmap) {
- img.setImageBitmap(bitmap);
- //cache this image for faster loading next time
- try {
- avatarCache.put(row_id_as_key, bitmap);
-
- } catch (NullPointerException np) {
-
- }
- }
- }
-
- private class InfiniteScrollListener extends RecyclerView.OnScrollListener {
- /**
- * Callback method to be invoked when the RecyclerView has been scrolled. This will be
- * called after the scroll has completed.
- * <p/>
- * This callback will also be called if visible item range changes after a layout
- * calculation. In that case, dx and dy will be 0.
- *
- * @param recyclerView The RecyclerView which scrolled.
- * @param dx The amount of horizontal scroll.
- * @param dy The amount of vertical scroll.
- */
- @Override
- public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
- super.onScrolled(recyclerView, dx, dy);
- visibleItemCount = mListView.getChildCount();
- totalItemCount = mLinearLayoutManager.getItemCount();
- firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();
- if (loading && totalItemCount > previousTotal) {
- loading = false;
- previousTotal = totalItemCount;
- }
- if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem +
- visibleThreshold)) {
- //list has reached end, load more.
- Toast.makeText(getActivity(), "Loading more", Toast.LENGTH_SHORT).show();
- setIsLoadMoreData(true);
- currentPage++;
- new WorkflowLoader(getActivity(), swipeRefreshLayout).execute("" + currentPage);
- Log.d(TAG, currentPage + "");
- loading = true;
- }
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/fragments/WorkflowViewpager.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/fragments/WorkflowViewpager.java b/app/src/main/java/org/apache/taverna/mobile/fragments/WorkflowViewpager.java
deleted file mode 100644
index df4b0bc..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/WorkflowViewpager.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
-* Apache Taverna Mobile
-* Copyright 2016 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
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-
-package org.apache.taverna.mobile.fragments;
-
-import org.apache.taverna.mobile.R;
-import org.apache.taverna.mobile.ui.workflow.WorkflowFragment;
-
-import android.os.Bundle;
-import android.support.design.widget.TabLayout;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentPagerAdapter;
-import android.support.v4.view.ViewPager;
-import android.support.v7.app.ActionBar;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by rajan on 8/3/16.
- */
-public class WorkflowViewpager extends Fragment {
-
- private final String LOG_TAG = getClass().getSimpleName();
-
- ViewPager viewPager;
- TabLayout tabLayout;
-
-
- public static WorkflowViewpager getInstance(int position) {
- WorkflowViewpager myFragment = new WorkflowViewpager();
- Bundle args = new Bundle();
- args.putInt("position", position);
- myFragment.setArguments(args);
- return myFragment;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
- savedInstanceState) {
- View workflow_pager = inflater.inflate(R.layout.viewpager_workflow, container, false);
-
- /**
- * Setting the tool bar in MainActivity for all fragment
- */
- Toolbar toolbar = (Toolbar) workflow_pager.findViewById(R.id.toolbar);
- ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
-
- final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
- ab.setHomeAsUpIndicator(R.drawable.ic_menu);
- ab.setDisplayHomeAsUpEnabled(true);
-
-
- viewPager = (ViewPager) workflow_pager.findViewById(R.id.mviewpager);
- final Adapter adapter = new Adapter(getChildFragmentManager());
-
- /**
- * Dynamically Adding tabs
- * To add the new Tab "Go to res/values/category_id and add new title and category id"
- */
- adapter.addFragment(new WorkflowFragment(), getResources().getString(R.string
- .title_explore));
- adapter.addFragment(new FavoriteFragment(), getResources().getString(R.string
- .title_favorite));
-
- viewPager.setAdapter(adapter);
- viewPager.setOffscreenPageLimit(2);
- tabLayout = (TabLayout) workflow_pager.findViewById(R.id.mtablayout);
- tabLayout.setupWithViewPager(viewPager);
-
- return workflow_pager;
- }
-
-
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- Log.i(LOG_TAG, "Workflow_viewpager.onCreate");
-
- }
-
- static class Adapter extends FragmentPagerAdapter {
- private final List<Fragment> mFragments = new ArrayList<>();
- private final List<String> mFragmentTitles = new ArrayList<>();
-
- public Adapter(FragmentManager fm) {
- super(fm);
- }
-
- public void addFragment(Fragment fragment, String title) {
- mFragments.add(fragment);
- mFragmentTitles.add(title);
- }
-
- @Override
- public Fragment getItem(int position) {
- return mFragments.get(position);
- }
-
- @Override
- public int getCount() {
- return mFragments.size();
- }
-
-
- @Override
- public CharSequence getPageTitle(int position) {
- return mFragmentTitles.get(position);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/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
deleted file mode 100644
index 3f9d57e..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/RunFragment.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
-* Apache Taverna Mobile
-* Copyright 2016 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
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-
-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;
-import android.preference.PreferenceManager;
-import android.support.v4.app.Fragment;
-import android.text.method.ScrollingMovementMethod;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.ImageButton;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import static org.apache.taverna.mobile.activities.DashboardMainActivity.APP_DIRECTORY_NAME;
-
-/**
- * A simple {@link Fragment} subclass.
- * Use the {@link RunFragment#newInstance} factory method to
- * create an instance of this fragment.
- */
-public class RunFragment extends Fragment implements View.OnClickListener {
-
- private static final String TAG = "RunFragment";
- private View rootView;
- private TextView runIdTextView, runNameTextView;
- private ImageButton status;
- 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.
- *
- * @return A new instance of fragment RunFragment.
- */
- public static RunFragment newInstance() {
- RunFragment fragment = new RunFragment();
- Bundle args = new Bundle();
- fragment.setArguments(args);
- return fragment;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- }
-
- @Override
- 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);
-
- return rootView;
- }
-
- @Override
- 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;
- }
-
- @Override
- public void onResume() {
- super.onResume();
- String runresult = getActivity().getIntent().getStringExtra("runresult");
- try {
- JSONObject resultObject = new JSONObject(runresult);
- String runName = resultObject.getString("name");
- run_id = (int) resultObject.get("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);
-
- if (runState.contains("Pending")) {
- status.setImageResource(android.R.drawable.presence_busy);
- } else if (runState.contains("Running")) {
- status.setImageResource(android.R.drawable.presence_away);
- } else if (runState.contains("Finished")) {
- status.setImageResource(android.R.drawable.presence_online);
- } else if (runState.contains("Failed")) {
- 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());
-
- downloadOutput.setOnClickListener(this);
- downloadLogs.setOnClickListener(this);
- reloadRunResult();
- } catch (JSONException e) {
- Log.e(TAG, "onResume: ", e);
- }
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_refresh) {
- reloadRunResult();
- return true;
- }
- if (id == android.R.id.home) {
- //getActivity().finish();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- private void reloadRunResult() {
- Timer t = new Timer();
- // 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()) {
- case R.id.buttonWorkflowDownloadOutput:
- try {
- Log.d(TAG, "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()).mPlayerRunUrl +
- run_output_url.substring(0, 5));
- }
- } catch (Exception e) {
- Log.e(TAG, "onClick: ", e);
- Toast.makeText(getActivity(), "Error downloading run output", Toast
- .LENGTH_LONG).show();
- }
- break;
- case R.id.downloadRunLogs:
- try {
- Log.d(TAG, "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()).mPlayerRunUrl + run_logs_url
- .substring(0, 5));
- }
- } catch (Exception e) {
- Log.e(TAG, "onClick: ", e);
- 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) {
- Log.e(TAG, "run: ", e);
- }
- }
- });
- }
-
- private class RunTimerTask extends TimerTask {
-
- private Context context;
- private int runid;
-
- public RunTimerTask(Context context, int runID) {
- this.context = context;
- this.runid = runID;
- }
-
- @Override
- public void run() {
- //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).mPlayerRunUrl +
- this.runid);
- HttpURLConnection connection = (HttpURLConnection) workflowurl.openConnection();
-
- connection.setRequestProperty("Accept", "application/json");
- connection.setRequestMethod("GET");
- connection.connect(); //send request
-
- InputStream dis = connection.getInputStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(dis, "UTF-8"));
-
- String jsonData = "";
- while ((jsonData = br.readLine()) != null) {
- //json results of the full workflow details
- sb.append(jsonData);
- }
- dis.close();
- br.close();
- connection.disconnect();
-
- JSONObject runInfo = new JSONObject(sb.toString());
- updateRun(this.context, runInfo);
-
- } catch (IOException ex) {
- Log.e(TAG, "run: ", ex);
- } catch (JSONException e) {
- Log.e(TAG, "run: ", e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/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
deleted file mode 100644
index 1a8192d..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowAboutFragment.java
+++ /dev/null
@@ -1,87 +0,0 @@
-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
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * 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;
-
-/**
- * A simple {@link Fragment} subclass.
- * Use the {@link WorkflowAboutFragment#newInstance} factory method to
- * create an instance of this fragment.
- */
-public class WorkflowAboutFragment extends Fragment {
- // TODO: Rename parameter arguments, choose names that match
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
- private static final String ARG_PARAM1 = "param1";
- private static final String ARG_PARAM2 = "param2";
-
- // TODO: Rename and change types of parameters
- private String mParam1;
- private String mParam2;
-
- public WorkflowAboutFragment() {
- }
-
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- *
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment WorkflowAboutFragment.
- */
- // TODO: Rename and change types and number of parameters
- public static WorkflowAboutFragment newInstance(String param1, String param2) {
- WorkflowAboutFragment fragment = new WorkflowAboutFragment();
- Bundle args = new Bundle();
- args.putString(ARG_PARAM1, param1);
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getArguments() != null) {
- mParam1 = getArguments().getString(ARG_PARAM1);
- mParam2 = getArguments().getString(ARG_PARAM2);
- }
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- return inflater.inflate(R.layout.fragment_workflow_about, container, false);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/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
deleted file mode 100644
index a4865b7..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowLicenceFragment.java
+++ /dev/null
@@ -1,93 +0,0 @@
-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
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * 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;
-
-/**
- * A simple {@link Fragment} subclass.
- * Use the {@link WorkflowLicenceFragment#newInstance} factory method to
- * create an instance of this fragment.
- */
-public class WorkflowLicenceFragment extends Fragment {
- // TODO: Rename parameter arguments, choose names that match
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
- private static final String ARG_PARAM1 = "param1";
- private static final String ARG_PARAM2 = "param2";
-
- // TODO: Rename and change types of parameters
- 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.
- *
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment WorkflowLicenceFragment.
- */
- // TODO: Rename and change types and number of parameters
- public static WorkflowLicenceFragment newInstance(String param1, String param2) {
- WorkflowLicenceFragment fragment = new WorkflowLicenceFragment();
- Bundle args = new Bundle();
- args.putString(ARG_PARAM1, param1);
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getArguments() != null) {
- mParam1 = getArguments().getString(ARG_PARAM1);
- mParam2 = getArguments().getString(ARG_PARAM2);
- }
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- return inflater.inflate(R.layout.fragment_workflow_licence, container, false);
- }
-
- @Override
- public void onDetach() {
- super.onDetach();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/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
deleted file mode 100644
index 774a197..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowRunHistoryFragment.java
+++ /dev/null
@@ -1,172 +0,0 @@
-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
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * 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;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A simple {@link Fragment} subclass.
- * Use the {@link WorkflowRunHistoryFragment#newInstance} factory method to
- * create an instance of this fragment.
- */
-public class WorkflowRunHistoryFragment extends Fragment implements LoaderManager
- .LoaderCallbacks<Workflow> {
- private static final String TAG = "WorkflowRunHistoryFragment";
- // 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;
-
- public WorkflowRunHistoryFragment() {
- // Required empty public constructor
- }
-
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- *
- * @param param2 Parameter 2.
- * @return A new instance of fragment WorkflowRunHistoryFragment.
- */
- public static WorkflowRunHistoryFragment newInstance(String param2) {
- WorkflowRunHistoryFragment fragment = new WorkflowRunHistoryFragment();
- Bundle args = new Bundle();
- workflowID = param2;
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- runsList = new ArrayList<Runs>();
-/* runsList.add(new Runs("Test Run1 ",
- SimpleDateFormat.getDateTimeInstance().format(new Date()).toString()
- ,SimpleDateFormat.getDateTimeInstance().format(new Date()).toString(),"failed"));
- runsList.add(new Runs("Test Run2 ",
- SimpleDateFormat.getDateTimeInstance().format(new Date()).toString()
- ,SimpleDateFormat.getDateTimeInstance().format(new Date()).toString(),"finished"));
- */
- progressDialog = new ProgressDialog(getActivity());
- progressDialog.setMessage(getActivity().getResources().getString(R.string.loading));
- progressDialog.setCancelable(true);
-
- 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);
- 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();
- return rootView;
- }
-
- /**
- * Called when the fragment is visible to the user and actively running.
- * This is generally
- * tied to {@link android.app.Activity#onResume() Activity.onResume} of the containing
- * Activity's lifecycle.
- */
- @Override
- public void onResume() {
- super.onResume();
-
- // mRecyclerView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
- //getActivity().getLoaderManager().initLoader(1,null,this);
- }
-
- @Override
- public void onDetach() {
- super.onDetach();
- }
-
- @Override
- public Loader<Workflow> onCreateLoader(int i, Bundle bundle) {
- //progressDialog.show();
- return new DetailsLoader(getActivity(),
- DetailsLoader.LoadType.TYPE_RUN_HISTORY,
- workflowID);
- }
-
- @Override
- public void onLoadFinished(Loader<Workflow> workflowLoader, Workflow workflow) {
-
- try {
- if (workflow.getWorkflowRuns() != null && workflow.getWorkflowRuns().size() != 0) {
-
- runAdapter.setRunList(workflow.getWorkflowRuns());
- mRecyclerView.setAdapter(runAdapter);
- mRecyclerView.setVisibility(View.VISIBLE);
- emptyRunHistoryTextView.setVisibility(View.GONE);
-
- } else {
- mRecyclerView.setVisibility(View.GONE);
- emptyRunHistoryTextView.setVisibility(View.VISIBLE);
- }
- } catch (NullPointerException np) {
- Log.e(TAG, "onLoadFinished:", np);
- }
-
- // progressDialog.dismiss();
- }
-
- @Override
- public void onLoaderReset(Loader<Workflow> workflowLoader) {
- workflowLoader.reset();
- }
-}