Skip to content

Commit

Permalink
Merge pull request #54 from SanojPunchihewa/dev
Browse files Browse the repository at this point in the history
Add option to select folder in Terminal mode
  • Loading branch information
SanojPunchihewa authored Oct 19, 2019
2 parents 2b26a1b + 97cc9c4 commit 8289b94
Showing 1 changed file with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package com.mobilegenomics.f5n.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.mobilegenomics.f5n.GUIConfiguration;
import com.mobilegenomics.f5n.R;
import com.mobilegenomics.f5n.core.Step;
import com.obsez.android.lib.filechooser.ChooserDialog;
import java.util.List;
import java.util.Objects;

public class TerminalActivity extends AppCompatActivity {

Expand All @@ -24,13 +32,74 @@ public class TerminalActivity extends AppCompatActivity {

private List<Step> steps;

private String folderPath;

private EditText editTextFolderPath;

private Button btnCopyPath;

private Button btnOpenFolder;

private Button btnPastePath;

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_vertical);
setContentView(R.layout.layout_step);

linearLayout = findViewById(R.id.vertical_linear_layout);

editTextFolderPath = findViewById(R.id.edit_text_folder_path);
editTextFolderPath.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {

}

@Override
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {

}

@Override
public void afterTextChanged(final Editable s) {
folderPath = s.toString();
}
});

btnCopyPath = findViewById(R.id.btn_copy_path);
btnCopyPath.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("folderpath", folderPath);
clipboard.setPrimaryClip(clip);
}
});
btnOpenFolder = findViewById(R.id.btn_open_folder);
btnOpenFolder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
openFileManager();
}
});
btnPastePath = findViewById(R.id.btn_paste_path);
btnPastePath.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
try {
ClipData.Item item = Objects.requireNonNull(clipboard.getPrimaryClip()).getItemAt(0);
folderPath = item.getText().toString();
if (!TextUtils.isEmpty(folderPath)) {
editTextFolderPath.setText(folderPath);
}
} catch (NullPointerException e) {
Toast.makeText(TerminalActivity.this, "No file path was copied", Toast.LENGTH_SHORT).show();
}
}
});

steps = GUIConfiguration.getSteps();

stepId = 0;
Expand Down Expand Up @@ -74,4 +143,17 @@ public void onClick(final View v) {

}

private void openFileManager() {

new ChooserDialog(TerminalActivity.this)
.withFilter(true, false)
// to handle the result(s)
.withChosenListener((path, pathFile) -> {
folderPath = path;
editTextFolderPath.setText(folderPath);
})
.build()
.show();
}

}

0 comments on commit 8289b94

Please sign in to comment.