Skip to content

Commit

Permalink
run jar dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
tranleduy2000 committed Jun 15, 2018
1 parent c7c8d97 commit c6186e1
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/com/duy/ide/javaide/JavaIdeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.duy.ide.javaide.run.action.BuildJarAction;
import com.duy.ide.javaide.run.activities.ExecuteActivity;
import com.duy.ide.javaide.run.dialog.DialogRunConfig;
import com.duy.ide.javaide.run.dialog.RunJarDialog;
import com.duy.ide.javaide.sample.activities.JavaSampleActivity;
import com.duy.ide.javaide.setting.CompilerSettingActivity;
import com.duy.ide.javaide.theme.PremiumDialog;
Expand Down Expand Up @@ -240,11 +241,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
saveAll(RC_BUILD_JAR);
break;
case R.id.action_run_jar:
runJar();
break;
}
return super.onOptionsItemSelected(item);
}

private void runJar() {
RunJarDialog runJarDialog = RunJarDialog.newInstance();
runJarDialog.show(getSupportFragmentManager(), RunJarDialog.class.getName());
}

@Override
protected void onSaveComplete(int requestCode) {
super.onSaveComplete(requestCode);
Expand Down
142 changes: 142 additions & 0 deletions app/src/main/java/com/duy/ide/javaide/run/dialog/RunJarDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (C) 2018 Tran Le Duy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.duy.ide.javaide.run.dialog;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

import com.duy.file.explorer.FileExplorerActivity;
import com.duy.ide.R;

import java.io.File;

public class RunJarDialog extends AppCompatDialogFragment implements View.OnClickListener {

private static final int RC_SELECT_JAR = 847;
private static final int RC_ADD_CLASSPATH = 82;
private EditText mEditJarPath;
private EditText mEditClassPath;

public static RunJarDialog newInstance() {

Bundle args = new Bundle();

RunJarDialog fragment = new RunJarDialog();
fragment.setArguments(args);
return fragment;
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.dialog_run_jar, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mEditJarPath = view.findViewById(R.id.edit_jar_path);
mEditClassPath = view.findViewById(R.id.edit_classpath);

view.findViewById(R.id.btn_select_jar).setOnClickListener(this);
view.findViewById(R.id.btn_add_classpath).setOnClickListener(this);
view.findViewById(R.id.btn_ok).setOnClickListener(this);
view.findViewById(R.id.btn_cancel).setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_cancel:
dismiss();
break;
case R.id.btn_select_jar:
selectFile(RC_SELECT_JAR);
break;
case R.id.btn_add_classpath:
selectFile(RC_ADD_CLASSPATH);
break;
case R.id.btn_ok:
break;
}
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK) {
return;
}
switch (requestCode) {
case RC_ADD_CLASSPATH: {
final String filePath = FileExplorerActivity.getFile(data);
if (filePath == null) {
return;
}
File jar = new File(filePath);
if (!jar.isFile() || !jar.getName().endsWith(".jar")) {
Toast.makeText(getContext(), "The file is not jar file", Toast.LENGTH_SHORT).show();
return;
}
mEditClassPath.post(new Runnable() {
@Override
public void run() {
if (!(mEditClassPath.length() == 0)) {
mEditClassPath.append(File.separator);
}
mEditClassPath.append(filePath);
}
});
break;
}
case RC_SELECT_JAR: {
final String filePath = FileExplorerActivity.getFile(data);
if (filePath == null) {
return;
}
File jar = new File(filePath);
if (!jar.isFile() || !jar.getName().endsWith(".jar")) {
Toast.makeText(getContext(), "The file is not jar file", Toast.LENGTH_SHORT).show();
return;
}
mEditJarPath.post(new Runnable() {
@Override
public void run() {
mEditJarPath.setText(filePath);
}
});
break;
}
}
}

private void selectFile(int requestCode) {
Intent it = new Intent(getContext(), FileExplorerActivity.class);
it.putExtra(FileExplorerActivity.EXTRA_MODE, FileExplorerActivity.MODE_PICK_FILE);
startActivityForResult(it, requestCode);
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/dialog_run_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
android:layout_height="wrap_content"
android:gravity="end">

<Button
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/cancel" />

<Button
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_save"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
Expand Down
106 changes: 106 additions & 0 deletions app/src/main/res/layout/dialog_run_jar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2018 Tran Le Duy
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:text="Run jar"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">

<android.support.design.widget.TextInputEditText
android:id="@+id/edit_jar_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Jar file"
android:minEms="10" />
</android.support.design.widget.TextInputLayout>

<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_select_jar"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">

<android.support.design.widget.TextInputEditText
android:id="@+id/edit_classpath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Class path"
android:inputType="textNoSuggestions|textMultiLine"
android:minEms="10" />
</android.support.design.widget.TextInputLayout>

<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_add_classpath"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal">

<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_cancel"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/cancel" />

<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_ok"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/ok" />
</LinearLayout>
</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/menu/menu_nav_javaide.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
<menu>
<item
android:id="@+id/action_build_jar"
android:icon="@drawable/ic_jar_file_format"
android:title="Build jar archive">
</item>
<item
android:id="@+id/action_run_jar"
android:icon="@drawable/ic_jar_file_format"
android:title="Run jar archive" />
</menu>
</item>
Expand Down

0 comments on commit c6186e1

Please sign in to comment.