Skip to content

Commit

Permalink
Version 1.2: font size
Browse files Browse the repository at this point in the history
font size
  • Loading branch information
Vlad Mihalachi committed Oct 11, 2013
1 parent d7a5d51 commit ba0fb4e
Show file tree
Hide file tree
Showing 20 changed files with 288 additions and 75 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ proguard/

# Android Studio
.gradle
*.gradle
*.jks
/local.properties
/.idea/workspace.xml
Expand Down
30 changes: 30 additions & 0 deletions Turbo Editor/build.gradle
Original file line number Diff line number Diff line change
@@ -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 added Turbo Editor/libs/eventbus-2.0.2.jar
Binary file not shown.
Binary file removed Turbo Editor/libs/eventbus-2.1.0-beta-1.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions Turbo Editor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ protected LinkedList<AdapterDetailedList.FileDetail> doInBackground(final String
*/
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ public static EditDialogFragment newInstance(final Actions action) {

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@

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;

// Editor Variables
static boolean sWrapText;
static boolean sColorSyntax;
static int sFontSize;
//
private boolean mUseMonospace;
private String mCurrentEncoding;
Expand All @@ -99,6 +100,12 @@ public static EditorFragment newInstance(String filePath) {
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());
}


Expand All @@ -107,10 +114,20 @@ public void onCreate(Bundle savedInstanceState) {
*/
@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;
}

Expand All @@ -121,18 +138,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@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(
Expand Down Expand Up @@ -174,7 +181,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
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());
Expand All @@ -191,13 +207,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
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}
*/
Expand All @@ -209,33 +218,50 @@ public void onFinishEditDialog(final String inputText, final String hint, final
}
}

/**
* {@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());

if (this.sWrapText != countLines) {
this.sWrapText = countLines;
final String s = this.mEditor.getText().toString();
//inflateOfWrapText();
this.mEditor.setText(s);
configureEditText();
final int fontSize = PreferenceHelper.getFontSize(getActivity());

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)) {
Expand All @@ -248,20 +274,6 @@ private void updateTextEditor() {
}
}

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> {

/**
Expand Down Expand Up @@ -301,7 +313,6 @@ public static class Editor extends EditText {
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 =
Expand Down Expand Up @@ -346,11 +357,11 @@ public Editor(Context context,
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();
Expand All @@ -361,7 +372,7 @@ private void init(final Context context) {
getTextColors().getDefaultColor());
this.mPaintNumbers
.setTextSize(
textSize * this.mScale * 0.8f);
sFontSize);
this.mPaintNumbers.setAntiAlias(true);

// Syntax editor
Expand Down Expand Up @@ -393,6 +404,12 @@ public CharSequence filter(
}});
}

@Override
public void setTextSize(float size) {
super.setTextSize(size);
this.mPaintNumbers.setTextSize(sFontSize);
}

/**
* {@inheritDoc}
*/
Expand Down
Loading

0 comments on commit ba0fb4e

Please sign in to comment.