diff --git a/app-pro/src/main/AndroidManifest.xml b/app-pro/src/main/AndroidManifest.xml index 67bdfc0..1312ba9 100644 --- a/app-pro/src/main/AndroidManifest.xml +++ b/app-pro/src/main/AndroidManifest.xml @@ -86,7 +86,7 @@ android:theme="@style/AppTheme.Dark"> + android:value=".HomeActivity" /> + android:value=".PreferenceAbout" /> + android:value=".HomeActivity" /> + + + + + android:value=".HomeActivity" /> + android:value=".PreferenceAbout" /> + android:value=".HomeActivity" /> + + + + + + + - + + + + sha1="a3cd442213d832a910c1ec51cd2f2c507f7fea64"/> + - +--> - + package="sharedcode.turboeditor" > diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/BaseHomeActivity.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/BaseHomeActivity.java index 7ed2d45..657a174 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/BaseHomeActivity.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/BaseHomeActivity.java @@ -33,8 +33,6 @@ import android.os.IBinder; import android.preference.PreferenceManager; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.ActivityOptionsCompat; -import android.text.TextUtils; -import android.util.Log; import android.view.Gravity; import android.view.KeyEvent; import android.view.MenuItem; @@ -43,19 +41,6 @@ import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.Toast; -import sharedcode.turboeditor.R; -import sharedcode.turboeditor.fragment.ChangelogDialogFragment; -import sharedcode.turboeditor.fragment.EditorFragment; -import sharedcode.turboeditor.fragment.NoFileOpenedFragment; -import sharedcode.turboeditor.preferences.SettingsFragment; -import sharedcode.turboeditor.util.AppInfoHelper; -import sharedcode.turboeditor.util.Constants; -import sharedcode.turboeditor.util.ProCheckUtils; -import sharedcode.turboeditor.views.CustomDrawerLayout; -import sharedcode.turboeditor.util.EventBusEvents; -import sharedcode.turboeditor.preferences.PreferenceHelper; -import sharedcode.turboeditor.util.ThemeHelper; - import org.apache.commons.io.FilenameUtils; import org.sufficientlysecure.rootcommands.Shell; import org.sufficientlysecure.rootcommands.Toolbox; @@ -63,6 +48,16 @@ import org.sufficientlysecure.rootcommands.Toolbox; import java.io.File; import de.greenrobot.event.EventBus; +import sharedcode.turboeditor.R; +import sharedcode.turboeditor.fragment.ChangelogDialogFragment; +import sharedcode.turboeditor.fragment.EditorFragment; +import sharedcode.turboeditor.fragment.NoFileOpenedFragment; +import sharedcode.turboeditor.preferences.PreferenceHelper; +import sharedcode.turboeditor.util.AppInfoHelper; +import sharedcode.turboeditor.util.EventBusEvents; +import sharedcode.turboeditor.util.ProCheckUtils; +import sharedcode.turboeditor.util.ThemeHelper; +import sharedcode.turboeditor.views.CustomDrawerLayout; public abstract class BaseHomeActivity extends Activity { @@ -145,7 +140,18 @@ public abstract class BaseHomeActivity extends Activity { @Override public void onBackPressed() { - if (getFragmentManager().findFragmentById(R.id.fragment_editor) instanceof EditorFragment) { + + // if we should ignore the back button + if(PreferenceHelper.getIgnoreBackButton(this)) + return; + + + boolean fileOpened = getFragmentManager().findFragmentById(R.id.fragment_editor) instanceof EditorFragment; + if (mDrawerLayout.isDrawerOpen(Gravity.START) && fileOpened) { + mDrawerLayout.closeDrawer(Gravity.START); + } else if (mDrawerLayout.isDrawerOpen(Gravity.END) && fileOpened) { + mDrawerLayout.closeDrawer(Gravity.END); + } else if (fileOpened) { // remove editor fragment getFragmentManager() @@ -178,12 +184,12 @@ public abstract class BaseHomeActivity extends Activity { // 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{ + try { if (editor != null && !editor.hasFocus()) { editor.requestFocus(); editor.onKeyDown(keyCode, event); } - } catch (NullPointerException ex){ + } catch (NullPointerException ex) { } @@ -204,7 +210,7 @@ public abstract class BaseHomeActivity extends Activity { File file = new File(path); if (file.isFile() && file.exists()) { EventBus.getDefault().postSticky(new EventBusEvents.NewFileToOpen(new File(path))); - } else if(file.isDirectory()) { + } else if (file.isDirectory()) { } } @@ -234,7 +240,7 @@ public abstract class BaseHomeActivity extends Activity { subActivity.putExtra("action", SelectFileActivity.Actions.SelectFile); Bundle scaleBundle = ActivityOptionsCompat.makeScaleUpAnimation( view, 0, 0, view.getWidth(), view.getHeight()).toBundle(); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) startActivityForResult(subActivity, SELECT_FILE_CODE, scaleBundle); else startActivityForResult(subActivity, SELECT_FILE_CODE); @@ -249,7 +255,7 @@ public abstract class BaseHomeActivity extends Activity { Intent subActivity = new Intent(BaseHomeActivity.this, PreferenceAbout.class); Bundle scaleBundle = ActivityOptionsCompat.makeScaleUpAnimation( view, 0, 0, view.getWidth(), view.getHeight()).toBundle(); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) startActivity(subActivity, scaleBundle); else startActivity(subActivity); @@ -269,6 +275,7 @@ public abstract class BaseHomeActivity extends Activity { File file; String message; String fileText; + String encoding; ProgressDialog progressDialog; @Override @@ -312,20 +319,17 @@ public abstract class BaseHomeActivity extends Activity { } boolean autoencoding = PreferenceHelper.getAutoEncoding(BaseHomeActivity.this); - if (autoencoding) { - String encoding = sharedcode.turboeditor.util.FileUtils.getDetectedEncoding(file); - if (!TextUtils.isEmpty(encoding)) { - encoding = SettingsFragment.sCurrentEncoding; - } else { - SettingsFragment.sCurrentEncoding = encoding; + encoding = sharedcode.turboeditor.util.FileUtils.getDetectedEncoding(file); + if (encoding.isEmpty()) { + encoding = PreferenceHelper.getEncoding(BaseHomeActivity.this); } - - fileText = org.apache.commons.io.FileUtils.readFileToString(file, encoding); } else { - fileText = org.apache.commons.io.FileUtils.readFileToString(file, SettingsFragment.sCurrentEncoding); + encoding = PreferenceHelper.getEncoding(BaseHomeActivity.this); } + + fileText = org.apache.commons.io.FileUtils.readFileToString(file, encoding); } catch (Exception e) { message = e.getMessage(); fileText = ""; @@ -351,7 +355,7 @@ public abstract class BaseHomeActivity extends Activity { } else { getFragmentManager() .beginTransaction() - .replace(R.id.fragment_editor, EditorFragment.newInstance(event.getFile().getAbsolutePath(), fileText)) + .replace(R.id.fragment_editor, EditorFragment.newInstance(event.getFile().getAbsolutePath(), fileText, encoding)) .commit(); } @@ -386,9 +390,9 @@ public abstract class BaseHomeActivity extends Activity { displayInterstitial(); } - public void onEvent(EventBusEvents.AFileIsSelected event){ + public void onEvent(EventBusEvents.AFileIsSelected event) { String name = FilenameUtils.getName(event.getPath()); - if(name.isEmpty()) + if (name.isEmpty()) getActionBar().setTitle(R.string.nome_app_turbo_editor); else getActionBar().setTitle(name); @@ -414,7 +418,7 @@ public abstract class BaseHomeActivity extends Activity { public void onEvent(EventBusEvents.APreferenceValueWasChanged event) { - if (event.getType() == EventBusEvents.APreferenceValueWasChanged.Type.THEME_CHANGE) { + if (event.hasType(EventBusEvents.APreferenceValueWasChanged.Type.THEME_CHANGE)) { ThemeHelper.setWindowsBackground(this); } } @@ -506,8 +510,7 @@ public abstract class BaseHomeActivity extends Activity { && type != null) { // Post event EventBus.getDefault().postSticky(new EventBusEvents.NewFileToOpen(new File(intent.getData().getPath()))); - } - else if (Intent.ACTION_SEND.equals(action) && type != null) { + } else if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { onEvent(new EventBusEvents.NewFileToOpen(intent.getStringExtra(Intent.EXTRA_TEXT))); onEvent(new EventBusEvents.AFileIsSelected("")); // simulate click on the list diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/LicensesActivity.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/LicensesActivity.java index aed2b6a..62285c1 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/LicensesActivity.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/LicensesActivity.java @@ -37,13 +37,14 @@ public class LicensesActivity extends Activity implements AdapterView.OnItemClic @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); boolean light = PreferenceHelper.getLightTheme(this); if (light) { setTheme(R.style.AppTheme_Light); } else { setTheme(R.style.AppTheme_Dark); } + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_licenses); ListView listView = (ListView) findViewById(android.R.id.list); listView.setOnItemClickListener(this); diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/PreferenceAbout.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/PreferenceAbout.java index 8502537..e63e9bf 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/PreferenceAbout.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/PreferenceAbout.java @@ -20,14 +20,10 @@ package sharedcode.turboeditor.activity; import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.widget.TextView; @@ -79,8 +75,8 @@ public class PreferenceAbout extends Activity { public void GoToProVersion(View view) { try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.maskyn.fileeditorpro")) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.maskyn.fileeditorpro")) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { } } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/SelectFileActivity.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/SelectFileActivity.java index 84de8ee..316082b 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/SelectFileActivity.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/activity/SelectFileActivity.java @@ -35,13 +35,6 @@ import android.widget.TextView; import android.widget.Toast; import com.faizmalkani.floatingactionbutton.FloatingActionButton; -import sharedcode.turboeditor.R; -import sharedcode.turboeditor.adapter.AdapterDetailedList; -import sharedcode.turboeditor.fragment.EditDialogFragment; -import sharedcode.turboeditor.util.AlphanumComparator; -import sharedcode.turboeditor.util.Constants; -import sharedcode.turboeditor.preferences.PreferenceHelper; -import sharedcode.turboeditor.util.RootUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; @@ -57,6 +50,14 @@ import java.util.Comparator; import java.util.LinkedList; import java.util.concurrent.TimeoutException; +import sharedcode.turboeditor.R; +import sharedcode.turboeditor.adapter.AdapterDetailedList; +import sharedcode.turboeditor.fragment.EditDialogFragment; +import sharedcode.turboeditor.preferences.PreferenceHelper; +import sharedcode.turboeditor.util.AlphanumComparator; +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 ListView listView; @@ -87,7 +88,7 @@ public class SelectFileActivity extends Activity implements SearchView.OnQueryTe listView.setOnItemClickListener(this); listView.setTextFilterEnabled(true); - FloatingActionButton mFab = (FloatingActionButton)findViewById(R.id.fabbutton); + FloatingActionButton mFab = (FloatingActionButton) findViewById(R.id.fabbutton); mFab.setColor(getResources().getColor(R.color.fab_light)); mFab.setDrawable(getResources().getDrawable(R.drawable.ic_fab_add)); @@ -218,15 +219,15 @@ public class SelectFileActivity extends Activity implements SearchView.OnQueryTe MenuItem imSetAsWorkingFolder = menu.findItem(R.id.im_set_as_working_folder); MenuItem imIsWorkingFolder = menu.findItem(R.id.im_is_working_folder); MenuItem imSelectFolder = menu.findItem(R.id.im_select_folder); - if(imSetAsWorkingFolder != null){ + if (imSetAsWorkingFolder != null) { // set the imSetAsWorkingFolder visible only if the two folder dont concide imSetAsWorkingFolder.setVisible(!currentFolder.equals(PreferenceHelper.getWorkingFolder(SelectFileActivity.this))); } - if(imIsWorkingFolder != null) { + if (imIsWorkingFolder != null) { // set visible is the other is invisible imIsWorkingFolder.setVisible(!imSetAsWorkingFolder.isVisible()); } - if(imSelectFolder != null) { + if (imSelectFolder != null) { imSelectFolder.setVisible(!wantAFile); } return super.onPrepareOptionsMenu(menu); @@ -329,8 +330,8 @@ public class SelectFileActivity extends Activity implements SearchView.OnQueryTe getString(R.string.folder), "")); } else if (f.isFile() - && !FilenameUtils.isExtension(f.getName().toLowerCase(), unopenableExtensions) - && FileUtils.sizeOf(f) <= Constants.MAX_FILE_SIZE * FileUtils.ONE_KB) { + && !FilenameUtils.isExtension(f.getName().toLowerCase(), unopenableExtensions) + && FileUtils.sizeOf(f) <= Constants.MAX_FILE_SIZE * FileUtils.ONE_KB) { final long fileSize = f.length(); SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy hh:mm a"); String date = format.format(f.lastModified()); diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/adapter/AdapterDetailedList.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/adapter/AdapterDetailedList.java index 7a6e94b..0b44d7f 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/adapter/AdapterDetailedList.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/adapter/AdapterDetailedList.java @@ -29,14 +29,14 @@ import android.widget.Filter; import android.widget.ImageView; import android.widget.TextView; -import sharedcode.turboeditor.R; -import sharedcode.turboeditor.util.MimeTypes; - import org.apache.commons.io.FilenameUtils; import java.util.Arrays; import java.util.LinkedList; +import sharedcode.turboeditor.R; +import sharedcode.turboeditor.util.MimeTypes; + public class AdapterDetailedList extends ArrayAdapter { diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/adapter/AdapterDrawer.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/adapter/AdapterDrawer.java index 321f38d..ca7fd91 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/adapter/AdapterDrawer.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/adapter/AdapterDrawer.java @@ -29,11 +29,11 @@ import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; -import sharedcode.turboeditor.R; - import java.io.File; import java.util.ArrayList; +import sharedcode.turboeditor.R; + public class AdapterDrawer extends ArrayAdapter { @@ -111,6 +111,7 @@ public class AdapterDrawer extends public interface Callbacks { void CancelItem(int position, boolean andCloseOpenedFile); + void ItemSelected(String path); } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/ChangelogDialogFragment.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/ChangelogDialogFragment.java index 86037c2..9af4197 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/ChangelogDialogFragment.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/ChangelogDialogFragment.java @@ -31,9 +31,8 @@ import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; -import sharedcode.turboeditor.R; - import it.gmariotti.changelibs.library.view.ChangeLogListView; +import sharedcode.turboeditor.R; import sharedcode.turboeditor.util.Constants; public class ChangelogDialogFragment extends DialogFragment { diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/EditorFragment.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/EditorFragment.java index c92d3cd..0393772 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/EditorFragment.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/EditorFragment.java @@ -63,8 +63,8 @@ import sharedcode.turboeditor.preferences.SettingsFragment; import sharedcode.turboeditor.util.EditorInterface; import sharedcode.turboeditor.util.EdittextPadding; import sharedcode.turboeditor.util.EventBusEvents; -import sharedcode.turboeditor.views.GoodScrollView; import sharedcode.turboeditor.util.LineUtils; +import sharedcode.turboeditor.views.GoodScrollView; import sharedcode.turboeditor.util.MimeTypes; import sharedcode.turboeditor.util.PageSystem; import sharedcode.turboeditor.util.PageSystemButtons; @@ -105,6 +105,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S private SearchResult searchResult; private PageSystem pageSystem; private PageSystemButtons pageSystemButtons; + private String currentEncoding; private static final int SYNTAX_DELAY_MILLIS_SHORT = 250; private static final int SYNTAX_DELAY_MILLIS_LONG = 1500; @@ -115,7 +116,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S static final int ID_PASTE = android.R.id.paste; private static final int ID_UNDO = R.id.im_undo; private static final int ID_REDO = R.id.im_redo; - private static final int CHARS_TO_COLOR = 2000; + private static final int CHARS_TO_COLOR = 2500; private final Handler updateHandler = new Handler(); private final Runnable colorRunnable_duringEditing = @@ -134,11 +135,12 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S }; //endregion - public static EditorFragment newInstance(String filePath, String fileText) { + public static EditorFragment newInstance(String filePath, String fileText, String encoding) { EditorFragment frag = new EditorFragment(); Bundle args = new Bundle(); args.putString("filePath", filePath); args.putString("fileText", fileText); + args.putString("encoding", encoding); frag.setArguments(args); return frag; } @@ -151,6 +153,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S setHasOptionsMenu(true); sFilePath = getArguments().getString("filePath"); pageSystem = new PageSystem(this, getArguments().getString("fileText")); + currentEncoding = getArguments().getString("encoding"); getArguments().remove("fileText"); } @@ -164,49 +167,49 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S mEditor.setEditorInterface(this); - if (SettingsFragment.sWrapContent) { + if (PreferenceHelper.getWrapContent(getActivity())) { horizontalScroll.removeView(mEditor); verticalScroll.removeView(horizontalScroll); verticalScroll.addView(mEditor); } else { // else show what is in the xml file fragment_editor.xml- } - if (SettingsFragment.sLightTheme) { + if (PreferenceHelper.getLightTheme(getActivity())) { mEditor.setTextColor(getResources().getColor(R.color.textColorInverted)); } else { mEditor.setTextColor(getResources().getColor(R.color.textColor)); } - if (SettingsFragment.sLineNumbers) { - mEditor.setPadding(EdittextPadding.getPaddingWithLineNumbers(getActivity(), SettingsFragment.sFontSize), EdittextPadding.getPaddingTop(getActivity()), 0, 0); + if (PreferenceHelper.getLineNumbers(getActivity())) { + mEditor.setPadding(EdittextPadding.getPaddingWithLineNumbers(getActivity(), PreferenceHelper.getFontSize(getActivity())), EdittextPadding.getPaddingTop(getActivity()), 0, 0); } else { mEditor.setPadding(EdittextPadding.getPaddingWithoutLineNumbers(getActivity()), EdittextPadding.getPaddingTop(getActivity()), 0, 0); } - if(SettingsFragment.sReadOnly) { + if(PreferenceHelper.getReadOnly(getActivity())) { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mEditor.setReadOnly(true); } else { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); mEditor.setReadOnly(false); - if (SettingsFragment.sSuggestionsActive) { + if (PreferenceHelper.getSuggestionActive(getActivity())) { mEditor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE); } else { mEditor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE); } } - if (SettingsFragment.sUseMonospace) { + if (PreferenceHelper.getUseMonospace(getActivity())) { mEditor.setTypeface(Typeface.MONOSPACE); } else { mEditor.setTypeface(Typeface.DEFAULT); } - mEditor.setTextSize(SettingsFragment.sFontSize); + mEditor.setTextSize(PreferenceHelper.getFontSize(getActivity())); mEditor.setFocusable(true); mEditor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if(!SettingsFragment.sReadOnly) { + if(!PreferenceHelper.getReadOnly(getActivity())) { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(mEditor, InputMethodManager.SHOW_IMPLICIT); } @@ -216,7 +219,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S mEditor.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { - if(hasFocus && !SettingsFragment.sReadOnly) { + if(hasFocus && !PreferenceHelper.getReadOnly(getActivity())) { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(mEditor, InputMethodManager.SHOW_IMPLICIT); } @@ -249,7 +252,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S // Unregister the Event Bus EventBus.getDefault().unregister(this); - if(SettingsFragment.sAutoSave && mEditor.canSaveFile()) { + if(PreferenceHelper.getAutoSave(getActivity()) && mEditor.canSaveFile()) { onEvent(new EventBusEvents.SaveAFile()); mEditor.fileSaved(); // so it doesn't ask to save in onDetach } @@ -260,7 +263,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S super.onDetach(); if (!getActivity().isFinishing() && mEditor.canSaveFile()) - SaveFileDialogFragment.newInstance(sFilePath, pageSystem.getAllText(mEditor.getText().toString())).show(getFragmentManager(), "dialog"); + SaveFileDialogFragment.newInstance(sFilePath, pageSystem.getAllText(mEditor.getText().toString()), currentEncoding).show(getFragmentManager(), "dialog"); } //endregion @@ -286,8 +289,8 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S if (searchingText) { MenuItem imReplace = menu.findItem(R.id.im_replace); - if (imReplace != null) - imReplace.setVisible(searchResult.isReplace); + if (imReplace != null) + imReplace.setVisible(searchResult.isReplace); } else { MenuItem imSave = menu.findItem(R.id.im_save); @@ -387,7 +390,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S @Override public void updateTextSyntax() { - if (!SettingsFragment.sColorSyntax || mEditor.hasSelection() || updateHandler == null || colorRunnable_duringEditing == null) + if (!PreferenceHelper.getSyntaxHiglight(getActivity()) || mEditor.hasSelection() || updateHandler == null || colorRunnable_duringEditing == null) return; updateHandler.removeCallbacks(colorRunnable_duringEditing); @@ -492,7 +495,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S public void onScrollChanged(int l, int t, int oldl, int oldt) { pageSystemButtons.updateVisibility(Math.abs(t) > 10); - if (!SettingsFragment.sColorSyntax || (mEditor.hasSelection() && !searchingText) || updateHandler == null || colorRunnable_duringScroll == null) + if (!PreferenceHelper.getSyntaxHiglight(getActivity()) || (mEditor.hasSelection() && !searchingText) || updateHandler == null || colorRunnable_duringScroll == null) return; updateHandler.removeCallbacks(colorRunnable_duringEditing); @@ -592,8 +595,8 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S //region Eventbus public void onEvent(EventBusEvents.APreferenceValueWasChanged event) { - if (event.getType() == WRAP_CONTENT) { - if (SettingsFragment.sWrapContent) { + if (event.hasType(WRAP_CONTENT)) { + if (PreferenceHelper.getWrapContent(getActivity())) { horizontalScroll.removeView(mEditor); verticalScroll.removeView(horizontalScroll); verticalScroll.addView(mEditor); @@ -602,65 +605,65 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S verticalScroll.addView(horizontalScroll); horizontalScroll.addView(mEditor); } - } else if (event.getType() == LINE_NUMERS) { + } else if (event.hasType(LINE_NUMERS)) { mEditor.disableTextChangedListener(); mEditor.replaceTextKeepCursor(null, true); mEditor.enableTextChangedListener(); - if (SettingsFragment.sLineNumbers) { - mEditor.setPadding(EdittextPadding.getPaddingWithLineNumbers(getActivity(), SettingsFragment.sFontSize), EdittextPadding.getPaddingTop(getActivity()), 0, 0); + if (PreferenceHelper.getLineNumbers(getActivity())) { + mEditor.setPadding(EdittextPadding.getPaddingWithLineNumbers(getActivity(), PreferenceHelper.getFontSize(getActivity())), EdittextPadding.getPaddingTop(getActivity()), 0, 0); } else { mEditor.setPadding(EdittextPadding.getPaddingWithoutLineNumbers(getActivity()), EdittextPadding.getPaddingTop(getActivity()), 0, 0); } - } else if (event.getType() == SYNTAX) { + } else if (event.hasType(SYNTAX)) { mEditor.disableTextChangedListener(); mEditor.replaceTextKeepCursor(null, true); mEditor.enableTextChangedListener(); - } else if (event.getType() == MONOSPACE) { - if (SettingsFragment.sUseMonospace) + } else if (event.hasType(MONOSPACE)) { + if (PreferenceHelper.getUseMonospace(getActivity())) this.mEditor.setTypeface(Typeface.MONOSPACE); else this.mEditor.setTypeface(Typeface.DEFAULT); - } else if (event.getType() == THEME_CHANGE) { - if (SettingsFragment.sLightTheme) { + } else if (event.hasType(THEME_CHANGE)) { + if (PreferenceHelper.getLightTheme(getActivity())) { mEditor.setTextColor(getResources().getColor(R.color.textColorInverted)); } else { mEditor.setTextColor(getResources().getColor(R.color.textColor)); } - } else if (event.getType() == TEXT_SUGGESTIONS || event.getType() == READ_ONLY) { - if(SettingsFragment.sReadOnly) { + } else if (event.hasType(TEXT_SUGGESTIONS) || event.hasType(READ_ONLY)) { + if(PreferenceHelper.getReadOnly(getActivity())) { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mEditor.setReadOnly(true); } else { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); mEditor.setReadOnly(false); - if (SettingsFragment.sSuggestionsActive) { + if (PreferenceHelper.getSuggestionActive(getActivity())) { mEditor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE); } else { mEditor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE); } } // sometimes it becomes monospace after setting the input type - if (SettingsFragment.sUseMonospace) + if (PreferenceHelper.getUseMonospace(getActivity())) this.mEditor.setTypeface(Typeface.MONOSPACE); else this.mEditor.setTypeface(Typeface.DEFAULT); - } else if (event.getType() == FONT_SIZE) { - if (SettingsFragment.sLineNumbers) { - mEditor.setPadding(EdittextPadding.getPaddingWithLineNumbers(getActivity(), SettingsFragment.sFontSize), EdittextPadding.getPaddingTop(getActivity()), 0, 0); + } else if (event.hasType(FONT_SIZE)) { + if (PreferenceHelper.getLineNumbers(getActivity())) { + mEditor.setPadding(EdittextPadding.getPaddingWithLineNumbers(getActivity(), PreferenceHelper.getFontSize(getActivity())), EdittextPadding.getPaddingTop(getActivity()), 0, 0); } else { mEditor.setPadding(EdittextPadding.getPaddingWithoutLineNumbers(getActivity()), EdittextPadding.getPaddingTop(getActivity()), 0, 0); } - this.mEditor.setTextSize(SettingsFragment.sFontSize); - } else if (event.getType() == ENCODING) { + this.mEditor.setTextSize(PreferenceHelper.getFontSize(getActivity())); + } else if (event.hasType(ENCODING)) { String oldEncoding, newEncoding; - oldEncoding = SettingsFragment.sCurrentEncoding; + oldEncoding = currentEncoding; newEncoding = PreferenceHelper.getEncoding(getActivity()); try { final byte[] oldText = this.mEditor.getText().toString().getBytes(oldEncoding); mEditor.disableTextChangedListener(); mEditor.replaceTextKeepCursor(new String(oldText, newEncoding), true); mEditor.enableTextChangedListener(); - SettingsFragment.sCurrentEncoding = newEncoding; + currentEncoding = newEncoding; } catch (UnsupportedEncodingException ignored) { try { final byte[] oldText = this.mEditor.getText().toString().getBytes(oldEncoding); @@ -676,9 +679,9 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S public void onEvent(EventBusEvents.SaveAFile event) { File file = new File(sFilePath); if(!file.getName().isEmpty()) - new SaveFileTask(getActivity(), sFilePath, pageSystem.getAllText(mEditor.getText().toString()), SettingsFragment.sCurrentEncoding).execute(); + new SaveFileTask(getActivity(), sFilePath, pageSystem.getAllText(mEditor.getText().toString()), currentEncoding).execute(); else { - NewFileDetailsDialogFragment dialogFrag = NewFileDetailsDialogFragment.newInstance(pageSystem.getAllText(mEditor.getText().toString()), SettingsFragment.sCurrentEncoding); + NewFileDetailsDialogFragment dialogFrag = NewFileDetailsDialogFragment.newInstance(pageSystem.getAllText(mEditor.getText().toString()), currentEncoding); dialogFrag.show(getFragmentManager().beginTransaction(), "dialog"); } } @@ -724,6 +727,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S private boolean canSaveFile = false; private KeyListener keyListener; private int firstVisibleIndex = 0, firstColoredIndex = 0; + private int deviceHeight; //endregion //region CONSTRUCTOR @@ -732,6 +736,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S mEditHistory = new EditHistory(); mChangeListener = new EditTextChangeListener(); lineUtils = new LineUtils(); + deviceHeight = getResources().getDisplayMetrics().heightPixels; this.mPaintNumbers.setAntiAlias(true); this.mPaintNumbers.setDither(false); @@ -846,21 +851,23 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S @Override public void onDraw(final Canvas canvas) { - if (SettingsFragment.sLineNumbers) { + if (PreferenceHelper.getLineNumbers(getContext())) { if (lineCount != getLineCount()) { lineCount = getLineCount(); lineUtils.updateHasNewLineArray(editorInterface.getPageSystem().getStartingLine(), lineCount, getLayout(), getText().toString()); } - int i = lineUtils.getFirstVisibleLine(editorInterface.getVerticalScrollView(), lineCount); - int lastLine = lineUtils.getLastVisibleLine(i, lineCount); + int editorHeight = getHeight(); + int i = lineUtils.getFirstVisibleLine(editorInterface.getVerticalScrollView(), editorHeight, lineCount); + int lastLine = lineUtils.getLastVisibleLine(editorInterface.getVerticalScrollView(), editorHeight, lineCount, deviceHeight); boolean[] hasNewLineArray = lineUtils.getToCountLinesArray(); int[] realLines = lineUtils.getRealLines(); + boolean wrapContent = PreferenceHelper.getWrapContent(getContext()); while (i < lastLine) { // if last line we count it anyway - if (!SettingsFragment.sWrapContent + if (!wrapContent || hasNewLineArray[i] || i == lastLine - 1) { if (i == lastLine - 1) @@ -994,7 +1001,7 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S - if(SettingsFragment.sColorSyntax) + if(PreferenceHelper.getSyntaxHiglight(getContext())) setText(highlight(textToUpdate == null ? getEditableText() : Editable.Factory.getInstance().newEditable(textToUpdate))); else setText(textToUpdate == null ? getText().toString() : textToUpdate); @@ -1022,12 +1029,18 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S } firstVisibleIndex = 0; - if(getHeight() > 0) - firstVisibleIndex = getLayout().getLineStart(getLineUtils().getFirstVisibleLine(editorInterface.getVerticalScrollView(), getHeight(), getLineCount())); + int end = CHARS_TO_COLOR; + 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; + } + firstColoredIndex = firstVisibleIndex - (CHARS_TO_COLOR / 5); if (firstColoredIndex < 0) firstColoredIndex = 0; - int end = firstColoredIndex + CHARS_TO_COLOR; if (end > editable.length()) end = editable.length(); @@ -1550,4 +1563,4 @@ public class EditorFragment extends Fragment implements FindTextDialogFragment.S } -} +} \ No newline at end of file diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/EncodingDialogFragment.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/EncodingDialogFragment.java index 662ffa8..b93981d 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/EncodingDialogFragment.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/EncodingDialogFragment.java @@ -22,23 +22,18 @@ package sharedcode.turboeditor.fragment; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; -import android.content.DialogInterface; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CompoundButton; import android.widget.ListView; import android.widget.Switch; +import org.mozilla.universalchardet.Constants; + import sharedcode.turboeditor.R; import sharedcode.turboeditor.preferences.PreferenceHelper; -import sharedcode.turboeditor.preferences.SettingsFragment; -import sharedcode.turboeditor.util.SaveFileTask; - -import org.mozilla.universalchardet.Constants; public class EncodingDialogFragment extends DialogFragment implements AdapterView.OnItemClickListener { diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/FindTextDialogFragment.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/FindTextDialogFragment.java index 4162906..7dd660b 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/FindTextDialogFragment.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/FindTextDialogFragment.java @@ -32,14 +32,13 @@ import android.widget.CompoundButton; import android.widget.EditText; import android.widget.Toast; -import sharedcode.turboeditor.R; - -import sharedcode.turboeditor.util.SearchResult; - import java.util.LinkedList; import java.util.regex.Matcher; import java.util.regex.Pattern; +import sharedcode.turboeditor.R; +import sharedcode.turboeditor.util.SearchResult; + // ... public class FindTextDialogFragment extends DialogFragment { @@ -91,30 +90,24 @@ public class FindTextDialogFragment extends DialogFragment { } @Override - public void onStart() - { + public void onStart() { super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point - AlertDialog d = (AlertDialog)getDialog(); - if(d != null) - { + AlertDialog d = (AlertDialog) getDialog(); + if (d != null) { Button positiveButton = (Button) d.getButton(Dialog.BUTTON_POSITIVE); positiveButton.setText(getString(R.string.find)); - positiveButton.setOnClickListener(new View.OnClickListener() - { + positiveButton.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) - { + public void onClick(View v) { returnData(); } }); Button negativeButton = (Button) d.getButton(Dialog.BUTTON_NEGATIVE); negativeButton.setText(getString(android.R.string.cancel)); - negativeButton.setOnClickListener(new View.OnClickListener() - { + negativeButton.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) - { + public void onClick(View v) { dismiss(); } }); @@ -122,7 +115,7 @@ public class FindTextDialogFragment extends DialogFragment { } void returnData() { - if(textToFind.getText().toString().isEmpty()) { + if (textToFind.getText().toString().isEmpty()) { this.dismiss(); } else { // we disable the okButton while we search @@ -130,7 +123,11 @@ public class FindTextDialogFragment extends DialogFragment { } } - private class SearchTask extends AsyncTask{ + public interface SearchDialogInterface { + void onSearchDone(SearchResult searchResult); + } + + private class SearchTask extends AsyncTask { LinkedList foundIndex; boolean foundSomething; @@ -145,9 +142,9 @@ public class FindTextDialogFragment extends DialogFragment { Matcher matcher = null; foundSomething = false; - if(isRegex) { + if (isRegex) { try { - if(caseSensitive) + if (caseSensitive) matcher = Pattern.compile(whatToSearch, Pattern.MULTILINE).matcher(allText); else matcher = Pattern.compile(whatToSearch, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(allText); @@ -156,14 +153,14 @@ public class FindTextDialogFragment extends DialogFragment { } } - if(isRegex) { + if (isRegex) { while (matcher.find()) { foundSomething = true; foundIndex.add(matcher.start()); } } else { - if(caseSensitive == false) { // by default is case sensitive + if (caseSensitive == false) { // by default is case sensitive whatToSearch = whatToSearch.toLowerCase(); allText = allText.toLowerCase(); } @@ -183,15 +180,15 @@ public class FindTextDialogFragment extends DialogFragment { @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); - if(foundSomething) { + if (foundSomething) { // the class that called this Dialog should implement the SearchDialogIterface SearchDialogInterface searchDialogInterface; - searchDialogInterface = ((SearchDialogInterface) getTargetFragment()); - if(searchDialogInterface == null) + searchDialogInterface = ((SearchDialogInterface) getTargetFragment()); + if (searchDialogInterface == null) searchDialogInterface = ((SearchDialogInterface) getActivity()); // if who called this has not implemented the interface we return nothing - if(searchDialogInterface == null) + if (searchDialogInterface == null) return; // else we return positions and other things else { @@ -206,8 +203,4 @@ public class FindTextDialogFragment extends DialogFragment { FindTextDialogFragment.this.dismiss(); } } - - public interface SearchDialogInterface { - void onSearchDone(SearchResult searchResult); - } } \ No newline at end of file diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/NavigationDrawerListFragment.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/NavigationDrawerListFragment.java index 392d308..d45eab7 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/NavigationDrawerListFragment.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/NavigationDrawerListFragment.java @@ -27,15 +27,14 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; -import sharedcode.turboeditor.R; -import sharedcode.turboeditor.adapter.AdapterDrawer; -import sharedcode.turboeditor.util.EventBusEvents; -import sharedcode.turboeditor.preferences.PreferenceHelper; - import java.io.File; import java.util.ArrayList; import de.greenrobot.event.EventBus; +import sharedcode.turboeditor.R; +import sharedcode.turboeditor.adapter.AdapterDrawer; +import sharedcode.turboeditor.preferences.PreferenceHelper; +import sharedcode.turboeditor.util.EventBusEvents; public class NavigationDrawerListFragment extends Fragment implements AdapterView.OnItemClickListener, AdapterDrawer.Callbacks { diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/NewFileDetailsDialogFragment.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/NewFileDetailsDialogFragment.java index 6241aad..5cebbb5 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/NewFileDetailsDialogFragment.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/NewFileDetailsDialogFragment.java @@ -24,17 +24,13 @@ import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; import android.os.Bundle; -import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; -import android.view.inputmethod.EditorInfo; import android.widget.EditText; -import android.widget.TextView; import java.io.File; import sharedcode.turboeditor.R; -import sharedcode.turboeditor.activity.PreferenceAbout; import sharedcode.turboeditor.preferences.PreferenceHelper; import sharedcode.turboeditor.util.SaveFileTask; @@ -72,7 +68,7 @@ public class NewFileDetailsDialogFragment extends DialogFragment { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - if(!mName.getText().toString().isEmpty() && !mFolder.getText().toString().isEmpty()) { + if (!mName.getText().toString().isEmpty() && !mFolder.getText().toString().isEmpty()) { File file = new File(mFolder.getText().toString(), mName.getText().toString()); new SaveFileTask(getActivity(), file.getPath(), getArguments().getString("fileText"), getArguments().getString("fileEncoding")).execute(); } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/SaveFileDialogFragment.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/SaveFileDialogFragment.java index c5f749c..97f102c 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/SaveFileDialogFragment.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/fragment/SaveFileDialogFragment.java @@ -25,21 +25,21 @@ import android.app.DialogFragment; import android.content.DialogInterface; import android.os.Bundle; -import sharedcode.turboeditor.R; -import sharedcode.turboeditor.preferences.SettingsFragment; -import sharedcode.turboeditor.util.SaveFileTask; - import org.apache.commons.io.FilenameUtils; import java.io.File; +import sharedcode.turboeditor.R; +import sharedcode.turboeditor.util.SaveFileTask; + public class SaveFileDialogFragment extends DialogFragment { - public static SaveFileDialogFragment newInstance(String filePath, String text) { + public static SaveFileDialogFragment newInstance(String filePath, String text, String encoding) { SaveFileDialogFragment frag = new SaveFileDialogFragment(); Bundle args = new Bundle(); args.putString("filePath", filePath); args.putString("text", text); + args.putString("encoding", encoding); frag.setArguments(args); return frag; } @@ -48,6 +48,7 @@ public class SaveFileDialogFragment extends DialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { final String filePath = getArguments().getString("filePath"); final String text = getArguments().getString("text"); + final String encoding = getArguments().getString("encoding"); final String fileName = FilenameUtils.getName(filePath); final File file = new File(filePath); @@ -57,10 +58,10 @@ public class SaveFileDialogFragment extends DialogFragment { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - if(!fileName.isEmpty()) - new SaveFileTask(getActivity(), filePath, text, SettingsFragment.sCurrentEncoding).execute(); + if (!fileName.isEmpty()) + new SaveFileTask(getActivity(), filePath, text, encoding).execute(); else { - NewFileDetailsDialogFragment dialogFrag = NewFileDetailsDialogFragment.newInstance(text, SettingsFragment.sCurrentEncoding); + NewFileDetailsDialogFragment dialogFrag = NewFileDetailsDialogFragment.newInstance(text, encoding); dialogFrag.show(getFragmentManager().beginTransaction(), "dialog"); } } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/ExtraSettingsActivity.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/ExtraSettingsActivity.java new file mode 100644 index 0000000..e61b918 --- /dev/null +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/ExtraSettingsActivity.java @@ -0,0 +1,215 @@ +/* + * 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 . + */ + +package sharedcode.turboeditor.preferences; + +import android.content.Context; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; + +import java.util.ArrayList; +import java.util.List; + +import de.greenrobot.event.EventBus; +import sharedcode.turboeditor.R; +import sharedcode.turboeditor.util.EventBusEvents; + +/** + * A {@link PreferenceActivity} that presents a set of application settings. On + * handset devices, settings are presented as a single list. On tablets, + * settings are split by category, with category headers shown to the left of + * the list of settings. + *

+ * See + * Android Design: Settings for design guidelines and the Settings + * API Guide for more information on developing a Settings UI. + */ +public class ExtraSettingsActivity extends PreferenceActivity { + /** + * Determines whether to always show the simplified settings UI, where + * settings are presented in a single list. When false, settings are shown + * as a master/detail two-pane view on tablets. When true, a single pane is + * shown on tablets. + */ + private static final boolean ALWAYS_SIMPLE_PREFS = true; + boolean encodingChanged = false, + themeChanged = false, + keyboardSuggestionsChanged = false; + /** + * A preference value change listener that updates the preference's summary + * to reflect its new value. + */ + private Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object value) { + String stringValue = value.toString(); + + if (preference instanceof ListPreference) { + // For list preferences, look up the correct display value in + // the preference's 'entries' list. + ListPreference listPreference = (ListPreference) preference; + int index = listPreference.findIndexOfValue(stringValue); + + // Set the summary to reflect the new value. + preference.setSummary( + index >= 0 + ? listPreference.getEntries()[index] + : null); + + } + switch (preference.getKey()) { + case "light_theme": + themeChanged = !themeChanged; + break; + case "suggestion_active": + keyboardSuggestionsChanged = !keyboardSuggestionsChanged; + break; + case "editor_encoding": + encodingChanged = true; + break; + + } + return true; + } + }; + + /** + * Helper method to determine if the device has an extra-large screen. For + * example, 10" tablets are extra-large. + */ + private static boolean isXLargeTablet(Context context) { + return (context.getResources().getConfiguration().screenLayout + & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + boolean light = PreferenceHelper.getLightTheme(this); + if (light) { + setTheme(R.style.AppTheme_Light); + } else { + setTheme(R.style.AppTheme_Dark); + } + super.onCreate(savedInstanceState); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + + setupSimplePreferencesScreen(); + } + + /** + * Shows the simplified settings UI if the device configuration if the + * device configuration dictates that a simplified, single-pane UI should be + * shown. + */ + private void setupSimplePreferencesScreen() { + if (!isSimplePreferences(this)) { + return; + } + + // In the simplified UI, fragments are not used at all and we instead + // use the older PreferenceActivity APIs. + + // Add 'general' preferences. + addPreferencesFromResource(R.xml.extra_options); + + // Bind the summaries of EditText/List/Dialog/Ringtone preferences to + // their values. When their values change, their summaries are updated + // to reflect the new value, per the Android Design guidelines. + bindPreferenceSummaryToValue(findPreference("editor_encoding")); + + String[] checkBoxPreferences = {"light_theme", "suggestion_active"}; + for (String key : checkBoxPreferences) { + // Set the listener to watch for value changes. + findPreference(key).setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean onIsMultiPane() { + return isXLargeTablet(this) && !isSimplePreferences(this); + } + + /** + * Determines whether the simplified settings UI should be shown. This is + * true if this is forced via {@link #ALWAYS_SIMPLE_PREFS}, or the device + * doesn't have newer APIs like {@link PreferenceFragment}, or the device + * doesn't have an extra-large screen. In these cases, a single-pane + * "simplified" settings UI should be shown. + */ + private boolean isSimplePreferences(Context context) { + return ALWAYS_SIMPLE_PREFS + || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB + || !isXLargeTablet(context); + } + + @Override + protected void onDestroy() { + List listOfChanges = new ArrayList<>(); + if (themeChanged) { + listOfChanges.add(EventBusEvents.APreferenceValueWasChanged.Type.THEME_CHANGE); + } + if (keyboardSuggestionsChanged) { + listOfChanges.add(EventBusEvents.APreferenceValueWasChanged.Type.TEXT_SUGGESTIONS); + } + if (encodingChanged) { + listOfChanges.add(EventBusEvents.APreferenceValueWasChanged.Type.ENCODING); + } + + + if (listOfChanges.size() > 0) { + EventBus.getDefault().postSticky(new EventBusEvents.APreferenceValueWasChanged(listOfChanges)); + } + super.onDestroy(); + } + + /** + * Binds a preference's summary to its value. More specifically, when the + * preference's value is changed, its summary (line of text below the + * preference title) is updated to reflect the value. The summary is also + * immediately updated upon calling this method. The exact display format is + * dependent on the type of preference. + * + * @see #sBindPreferenceSummaryToValueListener + */ + private void bindPreferenceSummaryToValue(Preference preference) { + // Set the listener to watch for value changes. + preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); + + // Trigger the listener immediately with the preference's + // current value. + sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, + PreferenceManager + .getDefaultSharedPreferences(preference.getContext()) + .getString(preference.getKey(), "")); + } +} diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/PreferenceHelper.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/PreferenceHelper.java index d6ca741..f91a52c 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/PreferenceHelper.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/PreferenceHelper.java @@ -105,6 +105,10 @@ public final class PreferenceHelper { return getPrefs(context).getBoolean("read_only", false); } + public static boolean getIgnoreBackButton(Context context) { + return getPrefs(context).getBoolean("ignore_back_button", false); + } + // Setter methods public static void setUseMonospace(Context context, boolean value) { @@ -123,30 +127,14 @@ public final class PreferenceHelper { getEditor(context).putBoolean("editor_wrap_content", value).commit(); } - public static void setLightTheme(Context context, boolean value) { - getEditor(context).putBoolean("light_theme", value).commit(); - } - - public static void setSuggestionActive(Context context, boolean value) { - getEditor(context).putBoolean("suggestion_active", value).commit(); - } - public static void setAutoencoding(Context context, boolean value) { getEditor(context).putBoolean("autoencoding", value).commit(); } - public static void setSendErrorReports(Context context, boolean value) { - getEditor(context).putBoolean("send_error_reports", value).commit(); - } - public static void setLastDayAdShowed(Context context, int value) { getEditor(context).putInt("last_day_ad_showed", value).commit(); } - public static void setEncoding(Context context, String value) { - getEditor(context).putString("editor_encoding", value).commit(); - } - public static void setFontSize(Context context, int value) { getEditor(context).putInt("font_size", value).commit(); } @@ -163,10 +151,6 @@ public final class PreferenceHelper { getEditor(context).putBoolean("page_system_button_popup_shown", value).commit(); } - public static void setAutoSave(Context context, boolean value) { - getEditor(context).putBoolean("auto_save", value).commit(); - } - public static void setReadOnly(Context context, boolean value) { getEditor(context).putBoolean("read_only", value).commit(); } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/SettingsFragment.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/SettingsFragment.java index a916b4a..d539b4f 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/SettingsFragment.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/preferences/SettingsFragment.java @@ -27,59 +27,39 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; -import android.widget.CheckedTextView; import android.widget.CompoundButton; -import android.widget.Switch; import android.widget.TextView; -import sharedcode.turboeditor.R; -import sharedcode.turboeditor.fragment.EncodingDialogFragment; -import sharedcode.turboeditor.fragment.SeekbarDialogFragment; - import de.greenrobot.event.EventBus; +import sharedcode.turboeditor.R; +import sharedcode.turboeditor.fragment.SeekbarDialogFragment; import sharedcode.turboeditor.util.ProCheckUtils; import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged; -import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.AUTO_SAVE; -import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.ENCODING; import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.FONT_SIZE; import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.LINE_NUMERS; import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.MONOSPACE; import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.READ_ONLY; import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.SYNTAX; -import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.TEXT_SUGGESTIONS; -import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.THEME_CHANGE; import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.WRAP_CONTENT; -public class SettingsFragment extends Fragment implements EncodingDialogFragment.DialogListener, SeekbarDialogFragment.onSeekbarDialogDismissed { +public class SettingsFragment extends Fragment implements SeekbarDialogFragment.onSeekbarDialogDismissed { - public static String sCurrentEncoding; // Editor Variables - public static boolean sLineNumbers; - public static boolean sColorSyntax; - public static boolean sWrapContent; - public static int sFontSize; - public static boolean sUseMonospace; - public static boolean sLightTheme; - public static boolean sSuggestionsActive; - public static boolean sAutoSave; - public static boolean sReadOnly; - public static boolean sSendErrorReports; + private boolean sLineNumbers; + private boolean sColorSyntax; + private boolean sWrapContent; + private boolean sUseMonospace; + private boolean sReadOnly; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - SettingsFragment.sCurrentEncoding = PreferenceHelper.getEncoding(getActivity()); - SettingsFragment.sUseMonospace = PreferenceHelper.getUseMonospace(getActivity()); - SettingsFragment.sColorSyntax = PreferenceHelper.getSyntaxHiglight(getActivity()); - SettingsFragment.sWrapContent = PreferenceHelper.getWrapContent(getActivity()); - SettingsFragment.sLineNumbers = PreferenceHelper.getLineNumbers(getActivity()); - SettingsFragment.sFontSize = PreferenceHelper.getFontSize(getActivity()); - SettingsFragment.sSuggestionsActive = PreferenceHelper.getSuggestionActive(getActivity()); - SettingsFragment.sLightTheme = PreferenceHelper.getLightTheme(getActivity()); - SettingsFragment.sAutoSave = PreferenceHelper.getAutoSave(getActivity()); - SettingsFragment.sReadOnly = PreferenceHelper.getReadOnly(getActivity()); - SettingsFragment.sSendErrorReports = PreferenceHelper.getSendErrorReports(getActivity()); + sUseMonospace = PreferenceHelper.getUseMonospace(getActivity()); + sColorSyntax = PreferenceHelper.getSyntaxHiglight(getActivity()); + sWrapContent = PreferenceHelper.getWrapContent(getActivity()); + sLineNumbers = PreferenceHelper.getLineNumbers(getActivity()); + sReadOnly = PreferenceHelper.getReadOnly(getActivity()); } @Override @@ -92,25 +72,17 @@ public class SettingsFragment extends Fragment implements EncodingDialogFragment switchSyntax = (CheckBox) rootView.findViewById(R.id.switch_syntax); switchWrapContent = (CheckBox) rootView.findViewById(R.id.switch_wrap_content); switchMonospace = (CheckBox) rootView.findViewById(R.id.switch_monospace); - switchLightTheme = (CheckBox) rootView.findViewById(R.id.switch_light_theme); - switchSuggestionsActive = (CheckBox) rootView.findViewById(R.id.switch_suggestions_active); - switchAutoSave = (CheckBox) rootView.findViewById(R.id.switch_auto_save); switchReadOnly = (CheckBox) rootView.findViewById(R.id.switch_read_only); - switchSendErrorReports = (CheckBox) rootView.findViewById(R.id.switch_send_error_reports); switchLineNumbers.setChecked(sLineNumbers); switchSyntax.setChecked(sColorSyntax); switchWrapContent.setChecked(sWrapContent); switchMonospace.setChecked(sUseMonospace); - switchLightTheme.setChecked(sLightTheme); - switchSuggestionsActive.setChecked(sSuggestionsActive); - switchAutoSave.setChecked(sAutoSave); switchReadOnly.setChecked(sReadOnly); - switchSendErrorReports.setChecked(sSendErrorReports); - TextView encodingView, fontSizeView, goProView; - encodingView = (TextView) rootView.findViewById(R.id.drawer_button_encoding); + TextView fontSizeView, goProView, extraOptionsView; fontSizeView = (TextView) rootView.findViewById(R.id.drawer_button_font_size); + extraOptionsView = (TextView) rootView.findViewById(R.id.drawer_button_extra_options); goProView = (TextView) rootView.findViewById(R.id.drawer_button_go_pro); switchLineNumbers.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @@ -151,33 +123,6 @@ public class SettingsFragment extends Fragment implements EncodingDialogFragment } }); - switchLightTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - sLightTheme = isChecked; - PreferenceHelper.setLightTheme(getActivity(), isChecked); - EventBus.getDefault().post(new APreferenceValueWasChanged(THEME_CHANGE)); - } - }); - - switchSuggestionsActive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - sSuggestionsActive = isChecked; - PreferenceHelper.setSuggestionActive(getActivity(), isChecked); - EventBus.getDefault().post(new APreferenceValueWasChanged(TEXT_SUGGESTIONS)); - } - }); - - switchAutoSave.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - sAutoSave = isChecked; - PreferenceHelper.setAutoSave(getActivity(), isChecked); - EventBus.getDefault().post(new APreferenceValueWasChanged(AUTO_SAVE)); - } - }); - switchReadOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -187,23 +132,6 @@ public class SettingsFragment extends Fragment implements EncodingDialogFragment } }); - switchSendErrorReports.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - sSendErrorReports = isChecked; - PreferenceHelper.setSendErrorReports(getActivity(), isChecked); - } - }); - - encodingView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - EncodingDialogFragment dialogFrag = EncodingDialogFragment.newInstance(); - dialogFrag.setTargetFragment(SettingsFragment.this, 0); - dialogFrag.show(getFragmentManager().beginTransaction(), "dialog"); - } - }); - fontSizeView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -217,6 +145,13 @@ public class SettingsFragment extends Fragment implements EncodingDialogFragment } }); + extraOptionsView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(getActivity(), ExtraSettingsActivity.class)); + } + }); + goProView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -232,33 +167,10 @@ public class SettingsFragment extends Fragment implements EncodingDialogFragment return rootView; } - - @Override - public void onEncodingSelected(String value) { - PreferenceHelper.setEncoding(getActivity(), value); - EventBus.getDefault().post(new APreferenceValueWasChanged(ENCODING)); - } - @Override public void onSeekbarDialogDismissed(SeekbarDialogFragment.Actions action, int value) { - sFontSize = value; PreferenceHelper.setFontSize(getActivity(), value); EventBus.getDefault().post(new APreferenceValueWasChanged(FONT_SIZE)); } - - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - *

- * See the Android Training lesson Communicating with Other Fragments for more information. - */ - public interface OnFragmentInteractionListener { - // TODO: Update argument type and name - public void onFragmentInteraction(Uri uri); - } } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/EditorInterface.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/EditorInterface.java index bf6236e..491f042 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/EditorInterface.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/EditorInterface.java @@ -19,13 +19,14 @@ package sharedcode.turboeditor.util; -import android.widget.ScrollView; - import sharedcode.turboeditor.views.GoodScrollView; public interface EditorInterface { - public GoodScrollView getVerticalScrollView(); - public String getFilePath(); - public PageSystem getPageSystem(); - public void updateTextSyntax(); - } \ No newline at end of file + public GoodScrollView getVerticalScrollView(); + + public String getFilePath(); + + public PageSystem getPageSystem(); + + public void updateTextSyntax(); +} \ No newline at end of file diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/EventBusEvents.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/EventBusEvents.java index 49b4362..9fe0669 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/EventBusEvents.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/EventBusEvents.java @@ -20,6 +20,7 @@ package sharedcode.turboeditor.util; import java.io.File; +import java.util.List; public class EventBusEvents { public static class CannotOpenAFile { @@ -65,21 +66,28 @@ public class EventBusEvents { public static class APreferenceValueWasChanged { private Type type; + private List types; public APreferenceValueWasChanged(Type type) { this.type = type; } - public Type getType() { - return type; + public APreferenceValueWasChanged(List types) { + this.types = types; } - public void setType(Type type) { - this.type = type; + public boolean hasType(Type value) { + + if (type != null) { + return value == type; + } else { + return types.contains(value); + } + } public enum Type { - FONT_SIZE, ENCODING, SYNTAX, WRAP_CONTENT, MONOSPACE, LINE_NUMERS, THEME_CHANGE, TEXT_SUGGESTIONS, AUTO_SAVE, READ_ONLY + FONT_SIZE, ENCODING, SYNTAX, WRAP_CONTENT, MONOSPACE, LINE_NUMERS, THEME_CHANGE, TEXT_SUGGESTIONS, READ_ONLY } } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/LineUtils.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/LineUtils.java index e26f435..20a6e13 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/LineUtils.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/LineUtils.java @@ -48,9 +48,8 @@ public class LineUtils { return line; } - public int getLastVisibleLine(int firstVisibleLine, int lineCount) { - int line; - line = firstVisibleLine + 150; + public int getLastVisibleLine(ScrollView scrollView, int childHeight, int lineCount, int deviceHeight) { + int line = ((scrollView.getScrollY() + deviceHeight) * lineCount) / childHeight; if (line > lineCount) line = lineCount; return line; } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/PageSystem.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/PageSystem.java index 10cf4a5..6f0c96a 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/PageSystem.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/PageSystem.java @@ -24,16 +24,9 @@ import java.util.List; public class PageSystem { - public interface PageSystemInterface { - void onPageChanged(int page); - } - private List pages; - private int[] startingLines; - private int currentPage = 0; - private PageSystemInterface pageSystemInterface; public PageSystem(PageSystemInterface pageSystemInterface, String text) { @@ -46,7 +39,7 @@ public class PageSystem { int to; int indexOfReturn; int textLenght = text.length(); - if(textLenght > maxLenghtInOnePage) { + if (textLenght > maxLenghtInOnePage) { while (i < textLenght) { to = i + charForPage; indexOfReturn = text.indexOf("\n", to); @@ -78,8 +71,8 @@ public class PageSystem { public String getTextOfNextPages(boolean includeCurrent, int nOfPages) { StringBuilder stringBuilder = new StringBuilder(); int i; - for(i = includeCurrent ? 0 : 1; i < nOfPages; i++){ - if(pages.size() > (currentPage + i)) { + for (i = includeCurrent ? 0 : 1; i < nOfPages; i++) { + if (pages.size() > (currentPage + i)) { stringBuilder.append(pages.get(currentPage + 1)); } } @@ -92,25 +85,25 @@ public class PageSystem { } public void nextPage() { - if(!canReadNextPage()) return; + if (!canReadNextPage()) return; goToPage(currentPage + 1); } public void prevPage() { - if(!canReadPrevPage()) return; + if (!canReadPrevPage()) return; goToPage(currentPage - 1); } public void goToPage(int page) { - if(page >= pages.size()) page = pages.size() - 1; - if(page < 0) page = 0; + if (page >= pages.size()) page = pages.size() - 1; + if (page < 0) page = 0; boolean shouldUpdateLines = page > currentPage && canReadNextPage(); - if(shouldUpdateLines) { + if (shouldUpdateLines) { String text = getCurrentPageText(); int nOfNewLineNow = (text.length() - text.replace("\n", "").length()) + 1; // normally the last line is not counted so we have to add 1 - int nOfNewLineBefore = startingLines[currentPage+1] - startingLines[currentPage]; - int difference = nOfNewLineNow - nOfNewLineBefore; - updateStartingLines(currentPage+1, difference); + int nOfNewLineBefore = startingLines[currentPage + 1] - startingLines[currentPage]; + int difference = nOfNewLineNow - nOfNewLineBefore; + updateStartingLines(currentPage + 1, difference); } currentPage = page; pageSystemInterface.onPageChanged(page); @@ -122,8 +115,8 @@ public class PageSystem { int nOfNewLines; String text; startingLines[0] = 0; - for(i = 1; i < pages.size(); i++) { - text = pages.get(i-1); + for (i = 1; i < pages.size(); i++) { + text = pages.get(i - 1); nOfNewLines = text.length() - text.replace("\n", "").length() + 1; startingLine = startingLines[i - 1] + nOfNewLines; startingLines[i] = startingLine; @@ -131,11 +124,11 @@ public class PageSystem { } public void updateStartingLines(int fromPage, int difference) { - if(difference == 0) + if (difference == 0) return; int i; - if(fromPage < 1) fromPage = 1; - for(i = fromPage; i < pages.size(); i++) { + if (fromPage < 1) fromPage = 1; + for (i = fromPage; i < pages.size(); i++) { startingLines[i] += difference; } } @@ -144,13 +137,15 @@ public class PageSystem { return pages.size() - 1; } - public int getCurrentPage() { return currentPage; } + public int getCurrentPage() { + return currentPage; + } public String getAllText(String currentPageText) { pages.set(currentPage, currentPageText); int i; StringBuilder allText = new StringBuilder(); - for(i = 0; i < pages.size(); i++) { + for (i = 0; i < pages.size(); i++) { allText.append(pages.get(i)).append("\n"); } return allText.toString(); @@ -163,4 +158,8 @@ public class PageSystem { public boolean canReadPrevPage() { return currentPage >= 1; } + + public interface PageSystemInterface { + void onPageChanged(int page); + } } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/PageSystemButtons.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/PageSystemButtons.java index acf5154..c7a104d 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/PageSystemButtons.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/PageSystemButtons.java @@ -24,21 +24,20 @@ import android.os.Handler; import android.view.View; import com.faizmalkani.floatingactionbutton.FloatingActionButton; + import sharedcode.turboeditor.R; public class PageSystemButtons { private static final int TIME_TO_SHOW_FABS = 2000; - - public interface PageButtonsInterface { - public void nextPageClicked(); - public void prevPageClicked(); - public void pageSystemButtonLongClicked(); - - public boolean canReadNextPage(); - public boolean canReadPrevPage(); - } - + final Handler handler = new Handler(); + final Runnable runnable = new Runnable() { + @Override + public void run() { + PageSystemButtons.this.next.setVisibility(View.GONE); + PageSystemButtons.this.prev.setVisibility(View.GONE); + } + }; FloatingActionButton prev, next; PageButtonsInterface pageButtonsInterface; @@ -53,10 +52,10 @@ public class PageSystemButtons { this.prev.setColor(context.getResources().getColor(R.color.fab_light)); this.prev.setDrawable(context.getResources().getDrawable(R.drawable.ic_keyboard_arrow_left)); - if(pageButtonsInterface.canReadNextPage()) + if (pageButtonsInterface.canReadNextPage()) next.setVisibility(View.VISIBLE); - if(pageButtonsInterface.canReadPrevPage()) + if (pageButtonsInterface.canReadPrevPage()) prev.setVisibility(View.VISIBLE); this.next.setOnClickListener(new View.OnClickListener() { @@ -90,23 +89,14 @@ public class PageSystemButtons { }); } - final Handler handler = new Handler(); - final Runnable runnable = new Runnable() { - @Override - public void run() { - PageSystemButtons.this.next.setVisibility(View.GONE); - PageSystemButtons.this.prev.setVisibility(View.GONE); - } - }; - public void updateVisibility(boolean autoHide) { - if(pageButtonsInterface.canReadNextPage()) + if (pageButtonsInterface.canReadNextPage()) PageSystemButtons.this.next.setVisibility(View.VISIBLE); else PageSystemButtons.this.next.setVisibility(View.GONE); - if(pageButtonsInterface.canReadPrevPage()) + if (pageButtonsInterface.canReadPrevPage()) PageSystemButtons.this.prev.setVisibility(View.VISIBLE); else PageSystemButtons.this.prev.setVisibility(View.GONE); @@ -121,7 +111,7 @@ public class PageSystemButtons { else prev.hideFab();*/ - if(autoHide) { + if (autoHide) { handler.removeCallbacks(runnable); handler.postDelayed(runnable, TIME_TO_SHOW_FABS); } else { @@ -129,4 +119,16 @@ public class PageSystemButtons { } } + public interface PageButtonsInterface { + public void nextPageClicked(); + + public void prevPageClicked(); + + public void pageSystemButtonLongClicked(); + + public boolean canReadNextPage(); + + public boolean canReadPrevPage(); + } + } diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/Patterns.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/Patterns.java index bcc06f5..06af62f 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/Patterns.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/Patterns.java @@ -69,9 +69,9 @@ public class Patterns { "\\b(int|float|long|complex|str|unicode|list|tuple|bytearray|buffer|xrange|set|frozenset|dict|bool)|(True|False|None|self|NotImplemented|Ellipsis|__debug__|__file__)|(and|del|from|not|while|as|elif|global|or|with|assert|else|if|pass|yield|break|except|import|print|class|exec|in|raise|continue|finally|is|return|def|for|lambda|try)|(ArithmeticError|AssertionError|AttributeError|BaseException|DeprecationWarning|EnvironmentError|EOFError|Exception|FloatingPointError|FutureWarning|GeneratorExit|IOError|ImportError|ImportWarning|IndexError|KeyError|KeyboardInterrupt|LookupError|MemoryError|NameError|NotImplementedError|OSError|OverflowError|PendingDeprecationWarning|ReferenceError|RuntimeError|RuntimeWarning|StandardError|StopIteration|SyntaxError|SyntaxWarning|SystemError|SystemExit|TypeError|UnboundLocalError|UserWarning|UnicodeError|UnicodeWarning|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|Warning|WindowsError|ZeroDivisionError)\\b", Pattern.CASE_INSENSITIVE); public static final Pattern LUA_KEYWORDS = Pattern.compile( -"@[A-Za-z0-9_\\.]*|\\b(local|global|boolean|number|userdata)\\b|\\b(true|false|nil)\\b|\\b(return|then|while|and|break|do|else|elseif|end|for|function|if|in|not|or|repeat|until|thread|table)\\b" + - "|(?i)\\b(editsetText|editText|inkey|touch|system.exit|system.expCall|system.getAppPath|system.getCardMnt|system.getSec|system.impCallActionSend|system.impCallActionView|system.setrun|system.setScreen|system.version|El_Psy_Congroo|canvas.drawCircle|canvas.drawCls|canvas.drawLine|canvas.drawRect|canvas.getBmpSize|canvas.getColor|canvas.getg|canvas.getviewSize|canvas.loadBmp|canvas.putCircle|canvas.putCls|canvas.putflush|canvas.putg|canvas.putLine|canvas.putRect|canvas.putrotg|canvas.putWork|canvas.saveBmp|canvas.setMainBmp|canvas.setWorkBmp|canvas.workCls|canvas.workflush|color|canvas.drawText|canvas.drawTextBox|canvas.drawTextCenter|canvas.drawTextRotate|canvas.putText|canvas.putTextBox|canvas.putTextRotate|http.addHeader|http.addParam|http.clrHeader|http.clrParam|http.get|http.post|http.setContentType|http.setPostFile|http.status|dialog|item.add|item.check|item.clear|item.list|item.radio|toast|sensor.getAccel|sensor.setdevAccel|sensor.setdevMagnet|sensor.setdevOrient|sensor.getGdirection|sensor.getMagnet|sensor.getOrient|sound.beep|sound.isPlay|sound.pause|sound.restart|sound.setSoundFile|sound.start|sound.stop|zip.addFile|zip.exec|zip.status|sock.close|sock.connectOpen|sock.getAddress|sock.listenOpen|sock.recv|sock.send|sprite.clear|sprite.define|sprite.init|sprite.move|sprite.put)\\b" + - "|(?i)\\b(assert|collectgarbage|coroutine.create|coroutine.resume|coroutine.running|coroutine.status|coroutine.wrap|coroutine.yield|debug.debug|debug.getfenv|debug.gethook|debug.getinfo|debug.getlocal|debug.getmetatable|debug.getregistry|debug.getupvalue|debug.setfenv|debug.sethook|debug.setlocal|debug.setmetatable|debug.setupvalue|debug.traceback|dofile|error|file:close|file:flush|file:lines|file:read|file:seek|file:setvbuf|file:write|getfenv|getmetatable|io.close|io.flush|io.input|io.lines|io.open|io.output|io.popen|io.read|io.tmpfile|io.type|io.write|ipairs|load|loadfile|loadstring|math.abs|math.acos|math.asin|math.atan2|math.atan|math.ceil|math.cosh|math.cos|math.deg|math.exp|math.floor|math.fmod|math.frexp|math.ldexp|math.log10|math.log|math.max|math.min|math.modf|math.pow|math.rad|math.random|math.randomseed|math.sinh|math.sin|math.sqrt|math.tanh|math.tan|module|next|os.clock|os.date|os.difftime|os.execute|os.exit|os.getenv|os.remove|os.rename|os.setlocale|os.time|os.tmpname|package.cpath|package.loaded|package.loadlib|package.path|package.preload|package.seeal|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|string.byte|string.char|string.dump|string.find|string.format|string.gmatch|string.gsub|string.len|string.lower|string.match|string.rep|string.reverse|string.sub|string.upper|table.concat|table.insert|table.maxn|table.remove|table.sort|tonumber|tostring|type|unpack|xpcall)\\b" + "@[A-Za-z0-9_\\.]*|\\b(local|global|boolean|number|userdata)\\b|\\b(true|false|nil)\\b|\\b(return|then|while|and|break|do|else|elseif|end|for|function|if|in|not|or|repeat|until|thread|table)\\b" + + "|(?i)\\b(editsetText|editText|inkey|touch|system.exit|system.expCall|system.getAppPath|system.getCardMnt|system.getSec|system.impCallActionSend|system.impCallActionView|system.setrun|system.setScreen|system.version|El_Psy_Congroo|canvas.drawCircle|canvas.drawCls|canvas.drawLine|canvas.drawRect|canvas.getBmpSize|canvas.getColor|canvas.getg|canvas.getviewSize|canvas.loadBmp|canvas.putCircle|canvas.putCls|canvas.putflush|canvas.putg|canvas.putLine|canvas.putRect|canvas.putrotg|canvas.putWork|canvas.saveBmp|canvas.setMainBmp|canvas.setWorkBmp|canvas.workCls|canvas.workflush|color|canvas.drawText|canvas.drawTextBox|canvas.drawTextCenter|canvas.drawTextRotate|canvas.putText|canvas.putTextBox|canvas.putTextRotate|http.addHeader|http.addParam|http.clrHeader|http.clrParam|http.get|http.post|http.setContentType|http.setPostFile|http.status|dialog|item.add|item.check|item.clear|item.list|item.radio|toast|sensor.getAccel|sensor.setdevAccel|sensor.setdevMagnet|sensor.setdevOrient|sensor.getGdirection|sensor.getMagnet|sensor.getOrient|sound.beep|sound.isPlay|sound.pause|sound.restart|sound.setSoundFile|sound.start|sound.stop|zip.addFile|zip.exec|zip.status|sock.close|sock.connectOpen|sock.getAddress|sock.listenOpen|sock.recv|sock.send|sprite.clear|sprite.define|sprite.init|sprite.move|sprite.put)\\b" + + "|(?i)\\b(assert|collectgarbage|coroutine.create|coroutine.resume|coroutine.running|coroutine.status|coroutine.wrap|coroutine.yield|debug.debug|debug.getfenv|debug.gethook|debug.getinfo|debug.getlocal|debug.getmetatable|debug.getregistry|debug.getupvalue|debug.setfenv|debug.sethook|debug.setlocal|debug.setmetatable|debug.setupvalue|debug.traceback|dofile|error|file:close|file:flush|file:lines|file:read|file:seek|file:setvbuf|file:write|getfenv|getmetatable|io.close|io.flush|io.input|io.lines|io.open|io.output|io.popen|io.read|io.tmpfile|io.type|io.write|ipairs|load|loadfile|loadstring|math.abs|math.acos|math.asin|math.atan2|math.atan|math.ceil|math.cosh|math.cos|math.deg|math.exp|math.floor|math.fmod|math.frexp|math.ldexp|math.log10|math.log|math.max|math.min|math.modf|math.pow|math.rad|math.random|math.randomseed|math.sinh|math.sin|math.sqrt|math.tanh|math.tan|module|next|os.clock|os.date|os.difftime|os.execute|os.exit|os.getenv|os.remove|os.rename|os.setlocale|os.time|os.tmpname|package.cpath|package.loaded|package.loadlib|package.path|package.preload|package.seeal|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|string.byte|string.char|string.dump|string.find|string.format|string.gmatch|string.gsub|string.len|string.lower|string.match|string.rep|string.reverse|string.sub|string.upper|table.concat|table.insert|table.maxn|table.remove|table.sort|tonumber|tostring|type|unpack|xpcall)\\b" ); public static final Pattern PHP_VARIABLES = Pattern.compile("\\$\\s*(\\w+)"); diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/ProCheckUtils.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/ProCheckUtils.java index d7ed05a..40b9040 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/ProCheckUtils.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/ProCheckUtils.java @@ -26,9 +26,9 @@ public class ProCheckUtils { String packageName = context.getPackageName(); - if(Constants.FOR_AMAZON) + if (Constants.FOR_AMAZON) return true; - else if(packageName.equals("com.maskyn.fileeditorpro")) + else if (packageName.equals("com.maskyn.fileeditorpro")) return true; else return false; diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/SaveFileTask.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/SaveFileTask.java index 019c198..2c94b8e 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/SaveFileTask.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/SaveFileTask.java @@ -23,8 +23,6 @@ import android.content.Context; import android.os.AsyncTask; import android.widget.Toast; -import sharedcode.turboeditor.R; - import org.sufficientlysecure.rootcommands.Shell; import org.sufficientlysecure.rootcommands.Toolbox; @@ -33,6 +31,7 @@ import java.io.IOException; import java.util.concurrent.TimeoutException; import de.greenrobot.event.EventBus; +import sharedcode.turboeditor.R; public class SaveFileTask extends AsyncTask { @@ -100,7 +99,7 @@ public class SaveFileTask extends AsyncTask { protected void onPostExecute(final Void aVoid) { super.onPostExecute(aVoid); Toast.makeText(context, message, Toast.LENGTH_LONG).show(); - if(message.equals(positiveMessage)) + if (message.equals(positiveMessage)) EventBus.getDefault().post(new EventBusEvents.SavedAFile(filePath)); } } \ No newline at end of file diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/SearchResult.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/SearchResult.java index df814ab..eb9ab22 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/SearchResult.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/SearchResult.java @@ -38,7 +38,7 @@ public class SearchResult { public void doneReplace() { foundIndex.remove(index); int i; - for(i = index; i < foundIndex.size(); i++) { + for (i = index; i < foundIndex.size(); i++) { foundIndex.set(i, foundIndex.get(i) + textToReplace.length() - textLength); } index--; // an element was removed so we decrease the index diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/views/GoodScrollView.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/views/GoodScrollView.java index 60efd0b..e03e380 100644 --- a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/views/GoodScrollView.java +++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/views/GoodScrollView.java @@ -21,11 +21,13 @@ package sharedcode.turboeditor.views; import android.content.Context; import android.util.AttributeSet; +import android.view.View; import android.widget.ScrollView; public class GoodScrollView extends ScrollView { public ScrollInterface scrollInterface; + int lastY; public GoodScrollView(Context context) { super(context); @@ -39,24 +41,33 @@ public class GoodScrollView extends ScrollView { super(context, attrs, defStyle); } - public interface ScrollInterface { - public void onScrollChanged(int l, int t, int oldl, int oldt); - } - public void setScrollInterface(ScrollInterface scrollInterface) { this.scrollInterface = scrollInterface; } - int lastY; - @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); - if(scrollInterface == null) return; - if(Math.abs(lastY - t) > 50){ - lastY = t; - scrollInterface.onScrollChanged(l, t, oldl, oldt); - } + if (scrollInterface == null) return; + + + + if (Math.abs(lastY - t) > 100) { + lastY = t; + scrollInterface.onScrollChanged(l, t, oldl, oldt); + } } + + public boolean hasReachedBottom(){ + View firstChild = getChildAt(getChildCount()-1); + + int diff = (firstChild.getBottom()-(getHeight()+getScrollY()+firstChild.getTop()));// Calculate the scrolldiff + return diff <= 0; + } + + + public interface ScrollInterface { + public void onScrollChanged(int l, int t, int oldl, int oldt); + } } diff --git a/libraries/sharedCode/src/main/res/layout/fragment_settings.xml b/libraries/sharedCode/src/main/res/layout/fragment_settings.xml index 9d6fd02..5af7835 100644 --- a/libraries/sharedCode/src/main/res/layout/fragment_settings.xml +++ b/libraries/sharedCode/src/main/res/layout/fragment_settings.xml @@ -143,71 +143,6 @@ android:layout_width="match_parent" android:layout_height="@dimen/line_dimension"/> - - - - - - - - - - - - - - - - - + + + + \ No newline at end of file diff --git a/libraries/sharedCode/src/main/res/values/arrays.xml b/libraries/sharedCode/src/main/res/values/arrays.xml index f093d60..0b71647 100644 --- a/libraries/sharedCode/src/main/res/values/arrays.xml +++ b/libraries/sharedCode/src/main/res/values/arrays.xml @@ -26,4 +26,36 @@ RootCommands Floating Action Button + + + ISO-2022-JP + ISO-2022-CN + ISO-2022-KR + ISO-8859-5 + ISO-8859-7 + ISO-8859-8 + BIG5 + GB18030 + EUC-JP + EUC-KR + EUC-TW + SHIFT_JIS + IBM855 + IBM866 + KOI8-R + MACCYRILLIC + WINDOWS-1251 + WINDOWS-1252 + WINDOWS-1253 + WINDOWS-1255 + UTF-8 + UTF-16BE + UTF-16LE + UTF-32BE + UTF-32LE + GB2312 + HZ-GB-2312 + X-ISO-10646-UCS-4-3412 + X-ISO-10646-UCS-4-2143 + \ No newline at end of file diff --git a/libraries/sharedCode/src/main/res/values/ids.xml b/libraries/sharedCode/src/main/res/values/ids.xml index 7618435..14c2aae 100644 --- a/libraries/sharedCode/src/main/res/values/ids.xml +++ b/libraries/sharedCode/src/main/res/values/ids.xml @@ -73,7 +73,7 @@ - + diff --git a/libraries/sharedCode/src/main/res/values/strings.xml b/libraries/sharedCode/src/main/res/values/strings.xml index 91ef12d..ce44053 100644 --- a/libraries/sharedCode/src/main/res/values/strings.xml +++ b/libraries/sharedCode/src/main/res/values/strings.xml @@ -167,5 +167,7 @@ Auto save Read only Send error reports - + Extra options + Split the text if too long + Ignore back button diff --git a/libraries/sharedCode/src/main/res/xml/extra_options.xml b/libraries/sharedCode/src/main/res/xml/extra_options.xml new file mode 100644 index 0000000..39eda45 --- /dev/null +++ b/libraries/sharedCode/src/main/res/xml/extra_options.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + +