Version 1.2: font size

font size
This commit is contained in:
Vlad Mihalachi 2013-10-11 15:18:06 +02:00
parent d7a5d513c7
commit ba0fb4ebaa
20 changed files with 287 additions and 74 deletions

1
.gitignore vendored
View File

@ -30,7 +30,6 @@ proguard/
# Android Studio
.gradle
*.gradle
*.jks
/local.properties
/.idea/workspace.xml

30
Turbo Editor/build.gradle Normal file
View File

@ -0,0 +1,30 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 18
}
}
dependencies {
compile 'com.github.gabrielemariotti.changeloglib:library:1.2.0'
compile 'com.android.support:support-v13:18.0.0'
compile "commons-io:commons-io:2.4"
compile fileTree(dir: 'libs', include: '*.jar')
}

Binary file not shown.

View File

@ -20,8 +20,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vmihalachi.turboeditor"
android:versionCode="5"
android:versionName="1.1"
android:versionCode="6"
android:versionName="1.2"
android:installLocation="auto">
<uses-sdk

View File

@ -232,8 +232,8 @@ public class SelectFileActivity extends Activity implements AdapterView.OnItemCl
*/
@Override
protected void onPostExecute(final LinkedList<AdapterDetailedList.FileDetail> names) {
boolean isRoot = currentFolder.equals("/");
if (names != null) {
boolean isRoot = currentFolder.equals("/");
listView.setAdapter(new AdapterDetailedList(getBaseContext(), names, isRoot));
}
super.onPostExecute(names);

View File

@ -45,13 +45,10 @@ public class EditDialogFragment extends DialogFragment implements TextView.OnEdi
public static EditDialogFragment newInstance(final Actions action, final String hint) {
final EditDialogFragment f = new EditDialogFragment();
// Supply num input as an argument.
final Bundle args = new Bundle();
args.putSerializable("action", action);
args.putString("hint", hint);
f.setArguments(args);
return f;
}

View File

@ -69,7 +69,7 @@ import java.util.regex.Pattern;
import de.greenrobot.event.EventBus;
public class EditorFragment extends Fragment implements EditDialogFragment.EditDialogListener {
public class EditorFragment extends Fragment implements EditDialogFragment.EditDialogListener, SeekbarDialogFragment.onSeekbarDialogDismissed {
private static final String TAG = "A0A";
private Editor mEditor;
@ -77,6 +77,7 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
// Editor Variables
static boolean sWrapText;
static boolean sColorSyntax;
static int sFontSize;
//
private boolean mUseMonospace;
private String mCurrentEncoding;
@ -99,6 +100,12 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
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());
this.sFontSize = PreferenceHelper.getFontSize(getActivity());
}
@ -107,10 +114,20 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Out custom layout
View rootView = inflater.inflate(R.layout.fragment_editor, container, false);
//
mEditor = (Editor) rootView.findViewById(R.id.editor);
mEditor.setHorizontallyScrolling(!this.sWrapText);
if (!this.sWrapText) {
int paddingLeft = (int) PixelDipConverter.convertDpToPixel(sFontSize * 1.5f, getActivity());
mEditor.setPadding(paddingLeft, 0, 0, 0);
} else {
int paddingLeft = (int) PixelDipConverter.convertDpToPixel(5, getActivity());
mEditor.setPadding(paddingLeft, 0, 0, 0);
}
if(this.mUseMonospace){
mEditor.setTypeface(Typeface.MONOSPACE);
}
mEditor.setTextSize(sFontSize);
return rootView;
}
@ -121,18 +138,8 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(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"));
//
getActivity().getActionBar().setTitle(fileName);
//
configureEditText();
//
try {
final FileInputStream inputStream =
new FileInputStream(
@ -174,7 +181,16 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Y, new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_Y));
} else if (i == R.id.im_editor_encoding) {
showEncodingDialog();
EditDialogFragment dialogFrag = EditDialogFragment.newInstance(EditDialogFragment.Actions.Encoding, this.mCurrentEncoding);
dialogFrag.setTargetFragment(this, 0);
dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
} else if (i == R.id.im_text_size) {
int fontMax = 36;
float scaledDensity = getResources().getDisplayMetrics().scaledDensity;
int fontCurrent = (int) (mEditor.getTextSize() / scaledDensity);
SeekbarDialogFragment dialogFrag = SeekbarDialogFragment.newInstance(SeekbarDialogFragment.Actions.FileSize, fontCurrent, fontMax);
dialogFrag.setTargetFragment(this, 0);
dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
} else if (i == R.id.im_syntax_highlight) {
item.setChecked(!item.isChecked());
PreferenceHelper.setSyntaxHiglight(getActivity(), item.isChecked());
@ -191,13 +207,6 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
return super.onOptionsItemSelected(item);
}
private void showEncodingDialog() {
EditDialogFragment dialogFrag = EditDialogFragment.newInstance(EditDialogFragment.Actions.Encoding, this.mCurrentEncoding);
dialogFrag.setTargetFragment(this, 0);
dialogFrag.show(getFragmentManager().beginTransaction(), "encodingDialog");
}
/**
* {@inheritDoc}
*/
@ -209,33 +218,50 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
}
}
/**
* {@inheritDoc}
*/
@Override
public void onSeekbarDialogDismissed(SeekbarDialogFragment.Actions action, int value) {
PreferenceHelper.setFontSize(getActivity(), value);
updateTextEditor();
}
private void updateTextEditor() {
final boolean countLines = PreferenceHelper.getWrapText(getActivity());
final boolean wrapText = PreferenceHelper.getWrapText(getActivity());
final boolean syntaxHighlight = PreferenceHelper.getSyntaxHiglight(getActivity());
final boolean useMonospace = PreferenceHelper.getUseMonospace(getActivity());
final String encoding = PreferenceHelper.getEncoding(getActivity());
final int fontSize = PreferenceHelper.getFontSize(getActivity());
if (this.sWrapText != countLines) {
this.sWrapText = countLines;
final String s = this.mEditor.getText().toString();
//inflateOfWrapText();
this.mEditor.setText(s);
configureEditText();
if (this.sWrapText != wrapText) {
this.sWrapText = wrapText;
this.mEditor.setText(this.mEditor.getText().toString());
this.mEditor.setHorizontallyScrolling(!this.sWrapText);
if (!this.sWrapText) {
int paddingLeft = (int) PixelDipConverter.convertDpToPixel(sFontSize * 1.5f, getActivity());
mEditor.setPadding(paddingLeft, 0, 0, 0);
} else {
int paddingLeft = (int) PixelDipConverter.convertDpToPixel(5, getActivity());
mEditor.setPadding(paddingLeft, 0, 0, 0);
}
}
if (this.sColorSyntax != syntaxHighlight) {
this.sColorSyntax = syntaxHighlight;
final String s = this.mEditor.getText().toString();
//inflateOfWrapText();
this.mEditor.setText(s);
this.mEditor.setText(this.mEditor.getText().toString());
}
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.sFontSize != fontSize) {
this.sFontSize = fontSize;
int paddingLeft = (int) PixelDipConverter.convertDpToPixel(fontSize * 1.5f, getActivity());
mEditor.setPadding(paddingLeft, 0, 0, 0);
this.mEditor.setTextSize(fontSize);
}
if (!this.mCurrentEncoding.equals(encoding)) {
@ -248,20 +274,6 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
}
}
private void configureEditText() {
this.mEditor.setHorizontallyScrolling(!this.sWrapText);
if (!this.sWrapText) {
int paddingLeft = (int) PixelDipConverter.convertDpToPixel(25, getActivity());
mEditor.setPadding(paddingLeft, 0, 0, 0);
} else {
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> {
/**
@ -301,7 +313,6 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
ID_REDO = R.id.im_redo;
private static final int SYNTAX_DELAY_MILLIS =
0;
private static final float textSize = 16;
private final Handler updateHandler =
new Handler();
private final TextPaint mPaintNumbers =
@ -346,11 +357,11 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
super(context, attrs);
this.mScale = context.getResources()
.getDisplayMetrics().density;
init(context);
init();
}
// Init the class
private void init(final Context context) {
private void init() {
mEditHistory = new EditHistory();
mChangeListener =
new EditTextChangeListener();
@ -361,7 +372,7 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
getTextColors().getDefaultColor());
this.mPaintNumbers
.setTextSize(
textSize * this.mScale * 0.8f);
sFontSize);
this.mPaintNumbers.setAntiAlias(true);
// Syntax editor
@ -393,6 +404,12 @@ public class EditorFragment extends Fragment implements EditDialogFragment.EditD
}});
}
@Override
public void setTextSize(float size) {
super.setTextSize(size);
this.mPaintNumbers.setTextSize(sFontSize);
}
/**
* {@inheritDoc}
*/

View File

@ -0,0 +1,108 @@
/*
* Copyright (C) 2013 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 Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
*/
package com.vmihalachi.turboeditor.fragment;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import com.vmihalachi.turboeditor.R;
// ...
public class SeekbarDialogFragment extends DialogFragment {
SeekBar mSeekBar;
public static SeekbarDialogFragment newInstance(final Actions action) {
return SeekbarDialogFragment.newInstance(action, 50, 100);
}
public static SeekbarDialogFragment newInstance(final Actions action, final int current, final int max) {
final SeekbarDialogFragment f = new SeekbarDialogFragment();
final Bundle args = new Bundle();
args.putSerializable("action", action);
args.putInt("current", current);
args.putInt("max", max);
f.setArguments(args);
return f;
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
final Dialog dialog = getDialog();
final Actions action = (Actions) getArguments().getSerializable("action");
final String title;
switch (action) {
case FileSize:
title = getString(R.string.text_size);
break;
default:
title = null;
break;
}
dialog.setTitle(title);
final View view = inflater.inflate(R.layout.dialog_fragment_seekbar, container);
this.mSeekBar = (SeekBar) view.findViewById(android.R.id.input);
this.mSeekBar.setProgress(getArguments().getInt("current"));
this.mSeekBar.setMax(getArguments().getInt("max"));
view.findViewById(android.R.id.button1)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
returnData();
}
});
return view;
}
void returnData(){
try {
((onSeekbarDialogDismissed) getTargetFragment()).onSeekbarDialogDismissed(
(Actions) getArguments().getSerializable("action"),
mSeekBar.getProgress()
);
} catch (Exception e){
try {
((onSeekbarDialogDismissed) getActivity()).onSeekbarDialogDismissed(
(Actions) getArguments().getSerializable("action"),
mSeekBar.getProgress()
);
} catch (Exception e2){
}
}
this.dismiss();
}
public enum Actions {
FileSize
}
public interface onSeekbarDialogDismissed {
void onSeekbarDialogDismissed(Actions action, int value);
}
}

View File

@ -57,6 +57,10 @@ public final class PreferenceHelper {
return getPrefs(context).getString("editor_encoding", "UTF-8");
}
public static int getFontSize(Context context) {
return getPrefs(context).getInt("font_size", 18);
}
public static String getLastNavigatedFolder(Context context) {
return getPrefs(context).getString("last_navigated_folder", SD_CARD_ROOT);
}
@ -83,6 +87,10 @@ public final class PreferenceHelper {
getEditor(context).putString("editor_encoding", value).commit();
}
public static void setFontSize(Context context, int value) {
getEditor(context).putInt("font_size", value).commit();
}
public static void setLastNavigatedFolder(Context context, String value) {
getEditor(context).putString("last_navigated_folder", value).commit();
}

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2013 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 Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<SeekBar
android:id="@android:id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dialog_edittext_margin"/>
<View
android:background="?android:attr/listDivider"
android:layout_width="match_parent"
android:layout_height="@dimen/line_dimension"/>
<Button
android:background="@drawable/holo_selector"
android:gravity="center_vertical|center_horizontal"
android:id="@android:id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/dialog_button_padding"
android:maxLines="1"
android:text="@android:string/ok"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>

View File

@ -36,7 +36,6 @@
android:inputType="textMultiLine|textImeMultiLine|textNoSuggestions"
android:maxLength="@integer/editor_max_file_size"
android:singleLine="false"
android:text="@null"
android:textSize="@dimen/text_size_editor" />
android:text="@null" />
</ScrollView>

View File

@ -39,7 +39,8 @@
android:maxLines="1"
android:textSize="@dimen/text_size_title"
android:ellipsize="end"
android:padding="@dimen/minimum_padding" />
android:padding="@dimen/minimum_padding"
android:textColor="@android:color/primary_text_dark_nodisable"/>
<LinearLayout
android:layout_height="wrap_content"

View File

@ -40,10 +40,6 @@
android:title="@string/preferenze"
android:showAsAction="ifRoom|withText">
<menu>
<item
android:id="@id/im_editor_encoding"
android:showAsAction="ifRoom"
android:title="@string/codifica"/>
<item
android:id="@id/im_wrap_text"
android:showAsAction="ifRoom"
@ -59,6 +55,14 @@
android:showAsAction="ifRoom"
android:title="@string/use_monospace"
android:checkable="true"/>
<item
android:id="@id/im_editor_encoding"
android:showAsAction="ifRoom"
android:title="@string/codifica"/>
<item
android:id="@id/im_text_size"
android:showAsAction="ifRoom"
android:title="@string/text_size"/>
</menu>
</item>
</menu>

View File

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog bulletedList="true">
<changelogversion versionName="1.2" changeDate="Oct 10, 2013">
<changelogtext>Now you can change the font size</changelogtext>
</changelogversion>
<changelogversion versionName="1.1" changeDate="Oct 6, 2013">
<changelogtext>Now you can create new files (open -> create new file)</changelogtext>
<changelogtext>Added the monospace font (choose it in the preferences)</changelogtext>

View File

@ -21,9 +21,7 @@
<!-- action bar background color -->
<color name="actionbar_background">#111111</color>
<!-- activity background color -->
<color name="activity_background">#202020</color>
<!-- activity text color -->
<color name="activity_text_color">#fff7f7f9</color>
<color name="activity_background">#ff191919</color>
<!-- navigation drawer background color -->
<color name="navigation_drawer_background">#1d1d1d</color>
<!-- colors used as file icons -->

View File

@ -34,5 +34,4 @@
<dimen name="text_size_mega_title">25sp</dimen>
<dimen name="text_size_title">16sp</dimen>
<dimen name="text_size_subtitle">14sp</dimen>
<dimen name="text_size_editor">16sp</dimen>
</resources>

View File

@ -32,6 +32,7 @@
<item type="id" name="im_syntax_highlight"/>
<item type="id" name="im_use_monospace"/>
<item type="id" name="im_new_file"/>
<item type="id" name="im_text_size"/>
<!-- layout item ids -->
<item type="id" name="drawer_layout"/>
<item type="id" name="fragment_editor"/>

View File

@ -116,7 +116,8 @@
<string name="open_this_time_only">Open this time only</string>
<string name="advise_editor_title">Are you missing Turbo Editor?</string>
<string name="advise_editor_subtitle">The best free and open source file editor!</string>
<string name="change_list_type">Change the list type</string>
<string name="use_monospace">Use monospace</string>
<string name="recent_files">Recent files</string>
<string name="change_list_type">Change The List Type</string>
<string name="use_monospace">Use Monospace</string>
<string name="recent_files">Recent Files</string>
<string name="text_size">Text Size</string>
</resources>

View File

@ -22,7 +22,6 @@
parent="android:Theme.Holo">
<item name="android:windowBackground">@color/activity_background</item>
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
<item name="android:textColor">@color/activity_text_color</item>
</style>
<style name="ActionBarStyle"