Some fixes

This commit is contained in:
Vlad Mihalachi
2014-10-07 18:55:18 +02:00
parent 04faa104ed
commit df5a302129
13 changed files with 321 additions and 201 deletions

View File

@@ -178,22 +178,28 @@ public abstract class BaseHomeActivity extends Activity {
onBackPressed();
return true;
}
else if(keyCode == KeyEvent.KEYCODE_MENU){
return false;
}
else {
if (editor == null)
editor = (EditText) findViewById(R.id.editor);
// this will happen on first key pressed on hard-keyboard only. Once myInputField
// gets the focus again, it will automatically receive further key presses.
if (editor == null)
editor = (EditText) findViewById(R.id.editor);
// this will happen on first key pressed on hard-keyboard only. Once myInputField
// gets the focus again, it will automatically receive further key presses.
try {
if (editor != null && !editor.hasFocus()) {
editor.requestFocus();
editor.onKeyDown(keyCode, event);
return true;
}
} catch (NullPointerException ex) {
try {
if (editor != null && !editor.hasFocus()) {
editor.requestFocus();
editor.onKeyDown(keyCode, event);
}
} catch (NullPointerException ex) {
}
return true;
return false;
}
@Override
@@ -226,7 +232,6 @@ public abstract class BaseHomeActivity extends Activity {
return super.onOptionsItemSelected(item);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2014 Vlad Mihalachi
*
* This file is part of Turbo Editor.
*
* Turbo Editor 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.
*
* Turbo Editor 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 <http://www.gnu.org/licenses/>.
*/
package sharedcode.turboeditor.activity;
import android.app.Application;
import android.view.ViewConfiguration;
import java.lang.reflect.Field;
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// force to sow the overflow menu icon
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ex) {
// Ignore
}
}
}

View File

@@ -59,9 +59,9 @@ import sharedcode.turboeditor.util.Constants;
import sharedcode.turboeditor.util.RootUtils;
public class SelectFileActivity extends Activity implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener, EditDialogFragment.EditDialogListener {
private String currentFolder;
private String currentFolder = PreferenceHelper.SD_CARD_ROOT;
private ListView listView;
private boolean wantAFile;
private boolean wantAFile = true;
private MenuItem mSearchViewMenuItem;
private SearchView mSearchView;

View File

@@ -95,10 +95,12 @@ public class AdapterDrawer extends
selectedPath = "";
}
});
if (TextUtils.equals(selectedPath, files.get(position).getAbsolutePath()))
if (TextUtils.equals(selectedPath, files.get(position).getAbsolutePath())) {
hold.nameLabel.setTypeface(hold.nameLabel.getTypeface(), Typeface.BOLD);
else
}
else {
hold.nameLabel.setTypeface(hold.nameLabel.getTypeface(), Typeface.NORMAL);
}
}
return convertView;
}

View File

@@ -151,11 +151,15 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String fileText = getArguments().getString("fileText");
if(fileText == null)
fileText = "";
setHasOptionsMenu(true);
sFilePath = getArguments().getString("filePath");
pageSystem = new PageSystem(getActivity(), this, getArguments().getString("fileText"));
pageSystem = new PageSystem(getActivity(), this, fileText);
currentEncoding = getArguments().getString("encoding");
getArguments().remove("fileText");
}
@@ -290,8 +294,18 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
if (searchingText) {
MenuItem imReplace = menu.findItem(R.id.im_replace);
MenuItem imPrev = menu.findItem(R.id.im_previous_item);
MenuItem imNext = menu.findItem(R.id.im_next_item);
if (imReplace != null)
imReplace.setVisible(searchResult.isReplace);
imReplace.setVisible(searchResult.canReplaceSomething());
if (imPrev != null)
imPrev.setVisible(searchResult.hasPrevious());
if (imNext != null)
imNext.setVisible(searchResult.hasNext());
} else {
MenuItem imSave = menu.findItem(R.id.im_save);
@@ -344,8 +358,9 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
}
else if(i == R.id.im_goto_line){
int min = mEditor.getLineUtils().firstReadLine();
int max = mEditor.getLineUtils().lastReadLine();
SeekbarDialogFragment dialogFrag = SeekbarDialogFragment.newInstance(SeekbarDialogFragment.Actions.GoToLine, 0, 0, max);
SeekbarDialogFragment dialogFrag = SeekbarDialogFragment.newInstance(SeekbarDialogFragment.Actions.GoToLine, min, min, max);
dialogFrag.setTargetFragment(EditorFragment.this, 0);
dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
}
@@ -368,6 +383,9 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
}
else {
}
return super.onOptionsItemSelected(item);
}
@@ -562,6 +580,8 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
mEditor.setSelection(searchResult.foundIndex.get(searchResult.index), searchResult.foundIndex.get(searchResult.index) + searchResult.textLength);
}
getActivity().invalidateOptionsMenu();
}
public void previousResult() {
@@ -584,12 +604,20 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
mEditor.setSelection(searchResult.foundIndex.get(searchResult.index), searchResult.foundIndex.get(searchResult.index) + searchResult.textLength);
}
getActivity().invalidateOptionsMenu();
}
public void replaceText() {
mEditor.setText(mEditor.getText().replace(searchResult.foundIndex.get(searchResult.index), searchResult.foundIndex.get(searchResult.index) + searchResult.textLength, searchResult.textToReplace));
searchResult.doneReplace();
nextResult();
getActivity().invalidateOptionsMenu();
if(searchResult.hasNext())
nextResult();
else if(searchResult.hasPrevious())
previousResult();
}
//endregion
@@ -712,7 +740,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
*/
private final EditTextChangeListener
mChangeListener;
int lineCount, realLine;
private int lineCount, realLine;
private LineUtils lineUtils;
private boolean modified = true;
/**
@@ -787,7 +815,27 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return true;
if (event.isCtrlPressed()) {
switch (keyCode) {
case KeyEvent.KEYCODE_A:
case KeyEvent.KEYCODE_X:
case KeyEvent.KEYCODE_C:
case KeyEvent.KEYCODE_V:
case KeyEvent.KEYCODE_Z:
case KeyEvent.KEYCODE_Y:
case KeyEvent.KEYCODE_S:
return true;
default:
return false;
}
} else {
switch (keyCode) {
case KeyEvent.KEYCODE_TAB:
return true;
default:
return false;
}
}
}
@Override
@@ -1030,67 +1078,70 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
return editable;
}
firstVisibleIndex = 0;
int end = CHARS_TO_COLOR;
int end;
int height = getHeight();
if(height > 0) {
firstVisibleIndex = getLayout().getLineStart(getLineUtils().getFirstVisibleLine(editorInterface.getVerticalScrollView(), height, getLineCount()));
end = getLayout().getLineStart(getLineUtils().getLastVisibleLine(editorInterface.getVerticalScrollView(), height, lineCount, deviceHeight));
//int end = firstColoredIndex + CHARS_TO_COLOR;
end = getLayout().getLineStart(getLineUtils().getLastVisibleLine(editorInterface.getVerticalScrollView(), height, getLineCount(), deviceHeight));
} else {
firstVisibleIndex = 0;
end = CHARS_TO_COLOR;
}
firstColoredIndex = firstVisibleIndex - (CHARS_TO_COLOR / 5);
// normalize
if (firstColoredIndex < 0)
firstColoredIndex = 0;
if (end > editable.length())
end = editable.length();
CharSequence textToHiglight = editable.subSequence(firstColoredIndex, end);
CharSequence textToHighlight = editable.subSequence(firstColoredIndex, end);
if (fileExtension.contains("htm")
|| fileExtension.contains("xml")) {
color(Patterns.HTML_OPEN_TAGS, editable, textToHiglight, firstColoredIndex);
color(Patterns.HTML_CLOSE_TAGS, editable, textToHiglight, firstColoredIndex);
color(Patterns.HTML_ATTRS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_STRINGS, editable, textToHiglight, firstColoredIndex);
color(Patterns.XML_COMMENTS, editable, textToHiglight, firstColoredIndex);
color(Patterns.HTML_OPEN_TAGS, editable, textToHighlight, firstColoredIndex);
color(Patterns.HTML_CLOSE_TAGS, editable, textToHighlight, firstColoredIndex);
color(Patterns.HTML_ATTRS, editable, textToHighlight, firstColoredIndex);
color(Patterns.GENERAL_STRINGS, editable, textToHighlight, firstColoredIndex);
color(Patterns.XML_COMMENTS, editable, textToHighlight, firstColoredIndex);
} else if (fileExtension.equals("css")) {
//color(CSS_STYLE_NAME, editable);
color(Patterns.CSS_ATTRS, editable, textToHiglight, firstColoredIndex);
color(Patterns.CSS_ATTR_VALUE, editable, textToHiglight, firstColoredIndex);
color(Patterns.SYMBOLS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_COMMENTS, editable, textToHiglight, firstColoredIndex);
color(Patterns.CSS_ATTRS, editable, textToHighlight, firstColoredIndex);
color(Patterns.CSS_ATTR_VALUE, editable, textToHighlight, firstColoredIndex);
color(Patterns.SYMBOLS, editable, textToHighlight, firstColoredIndex);
color(Patterns.GENERAL_COMMENTS, editable, textToHighlight, firstColoredIndex);
} else if (Arrays.asList(MimeTypes.MIME_CODE).contains(fileExtension)) {
if(fileExtension.equals("lua"))
color(Patterns.LUA_KEYWORDS, editable, textToHiglight, firstColoredIndex);
color(Patterns.LUA_KEYWORDS, editable, textToHighlight, firstColoredIndex);
else if(fileExtension.equals("py"))
color(Patterns.PY_KEYWORDS, editable, textToHiglight, firstColoredIndex);
color(Patterns.PY_KEYWORDS, editable, textToHighlight, firstColoredIndex);
else
color(Patterns.GENERAL_KEYWORDS, editable, textToHiglight, firstColoredIndex);
color(Patterns.NUMBERS, editable, textToHiglight, firstColoredIndex);
color(Patterns.SYMBOLS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_STRINGS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_COMMENTS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_KEYWORDS, editable, textToHighlight, firstColoredIndex);
color(Patterns.NUMBERS, editable, textToHighlight, firstColoredIndex);
color(Patterns.SYMBOLS, editable, textToHighlight, firstColoredIndex);
color(Patterns.GENERAL_STRINGS, editable, textToHighlight, firstColoredIndex);
color(Patterns.GENERAL_COMMENTS, editable, textToHighlight, firstColoredIndex);
if (fileExtension.equals("php"))
color(Patterns.PHP_VARIABLES, editable, textToHiglight, firstColoredIndex);
color(Patterns.PHP_VARIABLES, editable, textToHighlight, firstColoredIndex);
} else if (Arrays.asList(MimeTypes.MIME_SQL).contains(fileExtension)) {
color(Patterns.SYMBOLS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_STRINGS, editable, textToHiglight, firstColoredIndex);
color(Patterns.SQL_KEYWORDS, editable, textToHiglight, firstColoredIndex);
color(Patterns.SYMBOLS, editable, textToHighlight, firstColoredIndex);
color(Patterns.GENERAL_STRINGS, editable, textToHighlight, firstColoredIndex);
color(Patterns.SQL_KEYWORDS, editable, textToHighlight, firstColoredIndex);
} else {
if(!fileExtension.contains("md"))
color(Patterns.GENERAL_KEYWORDS, editable, textToHiglight, firstColoredIndex);
color(Patterns.NUMBERS, editable, textToHiglight, firstColoredIndex);
color(Patterns.SYMBOLS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_STRINGS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_KEYWORDS, editable, textToHighlight, firstColoredIndex);
color(Patterns.NUMBERS, editable, textToHighlight, firstColoredIndex);
color(Patterns.SYMBOLS, editable, textToHighlight, firstColoredIndex);
color(Patterns.GENERAL_STRINGS, editable, textToHighlight, firstColoredIndex);
if (fileExtension.equals("prop") || fileExtension.contains("conf") || fileExtension.contains("md"))
color(Patterns.GENERAL_COMMENTS_NO_SLASH, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_COMMENTS_NO_SLASH, editable, textToHighlight, firstColoredIndex);
else
color(Patterns.GENERAL_COMMENTS, editable, textToHiglight, firstColoredIndex);
color(Patterns.GENERAL_COMMENTS, editable, textToHighlight, firstColoredIndex);
if(fileExtension.contains("md"))
color(Patterns.LINK, editable, textToHiglight, firstColoredIndex);
color(Patterns.LINK, editable, textToHighlight, firstColoredIndex);
}
return editable;
@@ -1098,7 +1149,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
private void color(Pattern pattern,
Editable allText,
CharSequence textToHiglight,
CharSequence textToHighlight,
int start) {
int color = 0;
if (pattern.equals(Patterns.HTML_OPEN_TAGS)
@@ -1128,7 +1179,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S
color = getResources().getColor(R.color.syntax_variable);
}
m = pattern.matcher(textToHiglight);
m = pattern.matcher(textToHighlight);
while (m.find()) {
allText.setSpan(

View File

@@ -38,10 +38,6 @@ public class LineUtils {
return scrollView.getChildAt(0).getHeight() / lineCount * line;
}
public int getFirstVisibleLine(ScrollView scrollView, int lineCount){
return getFirstVisibleLine(scrollView, scrollView.getChildAt(0).getHeight(), lineCount);
}
public int getFirstVisibleLine(ScrollView scrollView, int childHeight, int lineCount) throws ArithmeticException{
int line = (scrollView.getScrollY() * lineCount) / childHeight;
if (line < 0) line = 0;
@@ -108,6 +104,10 @@ public class LineUtils {
return line;
}
public int firstReadLine() {
return realLines[0];
}
public int lastReadLine() {
return realLines[realLines.length-1];
}

View File

@@ -22,6 +22,7 @@ package sharedcode.turboeditor.util;
import java.util.LinkedList;
public class SearchResult {
// list of index
public LinkedList<Integer> foundIndex;
public int textLength;
public boolean isReplace;
@@ -47,4 +48,16 @@ public class SearchResult {
public int numberOfResults() {
return foundIndex.size();
}
public boolean hasNext() {
return index < foundIndex.size() - 1;
}
public boolean hasPrevious() {
return index > 0;
}
public boolean canReplaceSomething() {
return isReplace && foundIndex.size() > 0;
}
}

View File

@@ -50,7 +50,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="144dp"
android:layout_height="104dp"
android:id="@id/drawer_buttons"
android:layout_alignParentBottom="true"
android:orientation="vertical">
@@ -62,7 +62,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_height="52dp"
android:orientation="horizontal"
>
@@ -97,12 +97,20 @@
android:textColor="@color/navigation_drawer_button_text_color_inverted"/>
</LinearLayout>
<View
android:background="@color/divider_inverted"
android:layout_width="@dimen/line_dimension"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/ic_add_dark"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<ImageView
android:id="@+id/ic_add_dark"
android:layout_width="64dp"
android:layout_height="match_parent"
android:src="@drawable/ic_add_dark"
android:padding="12dp"
android:padding="14dp"
android:layout_alignParentRight="true"
android:clickable="true"
android:onClick="CreateFile"
@@ -117,69 +125,64 @@
android:layout_width="match_parent"
android:layout_height="@dimen/line_dimension"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:clickable="true"
android:gravity="center_vertical"
android:onClick="OpenSettings"
android:background="@drawable/item_background_holo_dark">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_settings_dark"
android:paddingStart="16dp"
android:paddingLeft="16dp"/>
<TextView
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/preferenze"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingEnd="20dp"
android:paddingRight="20dp"
android:gravity="center_vertical"
android:textSize="12sp"
android:textAllCaps="true"
android:textColor="@color/navigation_drawer_button_text_color_inverted"/>
</LinearLayout>
android:layout_height="52dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clickable="true"
android:gravity="center_vertical"
android:onClick="OpenSettings"
android:background="@drawable/item_background_holo_dark"
android:layout_toLeftOf="@+id/ic_info_dark"
>
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_settings_dark"
android:paddingStart="16dp"
android:paddingLeft="16dp"/>
<View
android:background="@color/divider_inverted"
android:layout_width="match_parent"
android:layout_height="@dimen/line_dimension"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/preferenze"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingEnd="20dp"
android:paddingRight="20dp"
android:textSize="12sp"
android:textAllCaps="true"
android:textColor="@color/navigation_drawer_button_text_color_inverted"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:clickable="true"
android:gravity="center_vertical"
android:onClick="OpenInfo"
android:background="@drawable/item_background_holo_dark">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_info_dark"
android:paddingStart="16dp"
android:paddingLeft="16dp"/>
<View
android:background="@color/divider_inverted"
android:layout_width="@dimen/line_dimension"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/ic_info_dark"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/info"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingEnd="20dp"
android:paddingRight="20dp"
android:gravity="center_vertical"
android:textSize="12sp"
android:textAllCaps="true"
android:textColor="@color/navigation_drawer_button_text_color_inverted"/>
</LinearLayout>
<ImageView
android:id="@+id/ic_info_dark"
android:layout_width="64dp"
android:layout_height="match_parent"
android:src="@drawable/ic_info_dark"
android:padding="14dp"
android:layout_alignParentRight="true"
android:clickable="true"
android:onClick="OpenInfo"
android:background="@drawable/item_background_holo_dark"
/>
</RelativeLayout>
</LinearLayout>

View File

@@ -29,7 +29,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:textSize="20sp"
android:textSize="18sp"
android:paddingStart="@dimen/item_drawer_list_padding"
android:paddingEnd="@dimen/item_drawer_list_padding"
android:paddingLeft="@dimen/item_drawer_list_padding"