Skip to content

Commit

Permalink
Version 1.1 monospace, create new file
Browse files Browse the repository at this point in the history
monospace, create new file
  • Loading branch information
Vlad Mihalachi committed Oct 7, 2013
1 parent 49f890a commit e540b8f
Show file tree
Hide file tree
Showing 30 changed files with 806 additions and 186 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ proguard/

# Android Studio
.gradle
*.gradle
*.jks
/local.properties
/.idea/workspace.xml
.DS_Store
.DS_Store
/Turbo Editor/build/
1 change: 0 additions & 1 deletion Turbo Editor/.gitignore

This file was deleted.

6 changes: 2 additions & 4 deletions Turbo Editor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vmihalachi.turboeditor"
android:versionCode="2"
android:versionName="0.3"
android:versionCode="5"
android:versionName="1.1"
android:installLocation="auto">

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -34,28 +34,27 @@

import com.vmihalachi.turboeditor.R;
import com.vmihalachi.turboeditor.adapter.AdapterDetailedList;
import com.vmihalachi.turboeditor.fragment.EditDialogFragment;
import com.vmihalachi.turboeditor.helper.PreferenceHelper;
import com.vmihalachi.turboeditor.util.AlphanumComparator;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;

public class SelectFileActivity extends Activity implements AdapterView.OnItemClickListener {
public class SelectFileActivity extends Activity implements AdapterView.OnItemClickListener, EditDialogFragment.EditDialogListener {
private static final String TAG = "A0A";
private String currentFolder;
private ListView listView;
private boolean wantAFile, wantAFolder;

// The android SD card root path
public static final String SD_CARD_ROOT =
Environment.getExternalStorageDirectory()
.getAbsolutePath();


/**
* {@inheritDoc}
Expand All @@ -74,13 +73,16 @@ protected void onCreate(Bundle savedInstanceState) {

String path = getIntent().getExtras().getString("path");
if (TextUtils.isEmpty(path)) {
new UpdateList().execute(SD_CARD_ROOT);
new UpdateList().execute(PreferenceHelper.getLastNavigatedFolder(this));
} else {
new UpdateList().execute(path);
}
}

void returnData(String path) {
if(!TextUtils.isEmpty(path)){
PreferenceHelper.setLastNavigatedFolder(this, path);
}
final Intent returnIntent = new Intent();
returnIntent.putExtra("path", path);
setResult(RESULT_OK, returnIntent);
Expand All @@ -96,10 +98,21 @@ public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
final String name = ((TextView) view.findViewById(android.R.id.title)).getText().toString();
if (name.equals("..")) {
vaiIndietro();
if (currentFolder.equals("/")) {
new UpdateList().execute(PreferenceHelper.getLastNavigatedFolder(this));
} else {
File tempFile = new File(currentFolder);
if (tempFile.isFile()) {
tempFile = tempFile.getParentFile()
.getParentFile();
} else {
tempFile = tempFile.getParentFile();
}
new UpdateList().execute(tempFile.getAbsolutePath());
}
return;
} else if (name.equals(getString(R.string.home))) {
new UpdateList().execute(SD_CARD_ROOT);
new UpdateList().execute(PreferenceHelper.getLastNavigatedFolder(this));
return;
}

Expand Down Expand Up @@ -135,27 +148,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
} else if (wantAFile) {
returnData("");
}
} else if (i == R.id.im_new_file) {
final EditDialogFragment dialogFrag = EditDialogFragment.newInstance(EditDialogFragment.Actions.NewLocalFile);
dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
}
return super.onOptionsItemSelected(item);
}

void vaiIndietro() {
if (currentFolder.equals("/")) {
new UpdateList().execute(SD_CARD_ROOT);
} else {
File tempFile = new File(currentFolder);
if (tempFile.isFile()) {
tempFile = tempFile.getParentFile()
.getParentFile();
} else {
tempFile = tempFile.getParentFile();
/**
* {@inheritDoc}
*/
@Override
public void onFinishEditDialog(final String inputText, final String hint, final EditDialogFragment.Actions actions) {
if(actions == EditDialogFragment.Actions.NewLocalFile){
File file = new File(currentFolder, inputText);
try {
file.createNewFile();
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
}
new UpdateList().execute(tempFile.getAbsolutePath());
returnData(file.getAbsolutePath());
}
}

private class UpdateList extends
AsyncTask<String, Void, LinkedList<AdapterDetailedList.FileDetail>> {
private class UpdateList extends AsyncTask<String, Void, LinkedList<AdapterDetailedList.FileDetail>> {

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,44 @@
import com.vmihalachi.turboeditor.R;

// ...
public class EncodingDialogFragment extends DialogFragment implements TextView.OnEditorActionListener {
public class EditDialogFragment extends DialogFragment implements TextView.OnEditorActionListener {

private EditText mEditText;
EditText mEditText;

public static EditDialogFragment newInstance(final Actions action) {
return EditDialogFragment.newInstance(action, "");
}

public static EditDialogFragment newInstance(final Actions action, final String hint) {
final EditDialogFragment f = new EditDialogFragment();

public static EncodingDialogFragment newInstance(final String hint) {
final EncodingDialogFragment f = new EncodingDialogFragment();
// Supply num input as an argument.
final Bundle args = new Bundle();
args.putSerializable("action", action);
args.putString("hint", hint);
f.setArguments(args);

return f;
}

/**
* {@inheritDoc}
*/
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {

final Dialog dialog = getDialog();
final String title = getString(R.string.codifica);
final Actions action = (Actions) getArguments().getSerializable("action");
final String title;
switch (action) {
case Encoding:
title = getString(R.string.codifica);
break;
case NewLocalFile:
title = getString(R.string.new_local_file);
break;
default:
title = null;
break;
}
dialog.setTitle(title);

final View view = inflater.inflate(R.layout.dialog_fragment_edittext, container);
Expand All @@ -65,15 +81,11 @@ public View onCreateView(final LayoutInflater inflater, final ViewGroup containe
// Show soft keyboard automatically
this.mEditText.setText(getArguments().getString("hint"));
this.mEditText.requestFocus();
dialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
this.mEditText.setOnEditorActionListener(this);

final Button button = (Button) view.findViewById(android.R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
/**
* {@inheritDoc}
*/
@Override
public void onClick(final View v) {
returnData();
Expand All @@ -88,13 +100,11 @@ void returnData() {
if (target == null) {
target = (EditDialogListener) getActivity();
}
target.onFinishEditDialog(this.mEditText.getText().toString(), getArguments().getString("hint"));
target.onFinishEditDialog(this.mEditText.getText().toString(), getArguments().getString("hint"),
(Actions) getArguments().getSerializable("action"));
this.dismiss();
}

/**
* {@inheritDoc}
*/
@Override
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
if (EditorInfo.IME_ACTION_DONE == actionId) {
Expand All @@ -104,9 +114,11 @@ public boolean onEditorAction(final TextView v, final int actionId, final KeyEve
return false;
}

public interface EditDialogListener {
void onFinishEditDialog(String inputText, String hint);
public enum Actions {
Encoding, NewLocalFile
}
}


public interface EditDialogListener {
void onFinishEditDialog(String inputText, String hint, Actions action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -68,7 +69,7 @@

import de.greenrobot.event.EventBus;

public class EditorFragment extends Fragment implements EncodingDialogFragment.EditDialogListener {
public class EditorFragment extends Fragment implements EditDialogFragment.EditDialogListener {

private static final String TAG = "A0A";
private Editor mEditor;
Expand All @@ -77,6 +78,7 @@ public class EditorFragment extends Fragment implements EncodingDialogFragment.E
static boolean sWrapText;
static boolean sColorSyntax;
//
private boolean mUseMonospace;
private String mCurrentEncoding;
private static String sFilePath;

Expand Down Expand Up @@ -122,6 +124,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
//
this.sFilePath = getArguments().getString("filePath");
this.mCurrentEncoding = PreferenceHelper.getEncoding(getActivity());
this.mUseMonospace = PreferenceHelper.getUseMonospace(getActivity());
this.sColorSyntax = PreferenceHelper.getSyntaxHiglight(getActivity());
this.sWrapText = PreferenceHelper.getWrapText(getActivity());
String fileName = FilenameUtils.getName(getArguments().getString("filePath"));
Expand Down Expand Up @@ -151,6 +154,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_editor, menu);
menu.findItem(R.id.im_wrap_text).setChecked(this.sWrapText);
menu.findItem(R.id.im_syntax_highlight).setChecked(this.sColorSyntax);
menu.findItem(R.id.im_use_monospace).setChecked(this.mUseMonospace);
super.onCreateOptionsMenu(menu, inflater);
}

Expand Down Expand Up @@ -179,12 +183,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
item.setChecked(!item.isChecked());
PreferenceHelper.setWrapText(getActivity(), item.isChecked());
updateTextEditor();
} else if (i == R.id.im_use_monospace) {
item.setChecked(!item.isChecked());
PreferenceHelper.setUseMonospace(getActivity(), item.isChecked());
updateTextEditor();
}
return super.onOptionsItemSelected(item);
}

private void showEncodingDialog() {
EncodingDialogFragment dialogFrag = EncodingDialogFragment.newInstance(this.mCurrentEncoding);
EditDialogFragment dialogFrag = EditDialogFragment.newInstance(EditDialogFragment.Actions.Encoding, this.mCurrentEncoding);
dialogFrag.setTargetFragment(this, 0);
dialogFrag.show(getFragmentManager().beginTransaction(), "encodingDialog");
}
Expand All @@ -194,14 +202,17 @@ private void showEncodingDialog() {
* {@inheritDoc}
*/
@Override
public void onFinishEditDialog(final String inputText, final String hint) {
PreferenceHelper.setEncoding(getActivity(), inputText);
updateTextEditor();
public void onFinishEditDialog(final String inputText, final String hint, final EditDialogFragment.Actions actions) {
if(actions == EditDialogFragment.Actions.Encoding){
PreferenceHelper.setEncoding(getActivity(), inputText);
updateTextEditor();
}
}

private void updateTextEditor() {
final boolean countLines = PreferenceHelper.getWrapText(getActivity());
final boolean syntaxHighlight = PreferenceHelper.getSyntaxHiglight(getActivity());
final boolean useMonospace = PreferenceHelper.getUseMonospace(getActivity());
final String encoding = PreferenceHelper.getEncoding(getActivity());

if (this.sWrapText != countLines) {
Expand All @@ -219,6 +230,14 @@ private void updateTextEditor() {
this.mEditor.setText(s);
}

if (this.mUseMonospace != useMonospace) {
this.mUseMonospace = useMonospace;
this.mEditor.setTypeface(Typeface.MONOSPACE);
//final String s = this.mEditor.getText().toString();
//inflateOfWrapText();
//this.mEditor.setText(s);
}

if (!this.mCurrentEncoding.equals(encoding)) {
try {
final byte[] oldText = this.mEditor.getText().toString().getBytes(this.mCurrentEncoding);
Expand All @@ -238,6 +257,9 @@ private void configureEditText() {
int paddingLeft = (int) PixelDipConverter.convertDpToPixel(5, getActivity());
mEditor.setPadding(paddingLeft, 0, 0, 0);
}
if(this.mUseMonospace){
this.mEditor.setTypeface(Typeface.MONOSPACE);
}
}

class SaveFile extends AsyncTask<Void, Void, Void> {
Expand Down
Loading

0 comments on commit e540b8f

Please sign in to comment.