diff --git a/.gitignore b/.gitignore index 812c2dd..329423e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,61 @@ -# built application files +# Built application files *.apk *.ap_ -# files for the dex VM +# Files for the Dalvik VM *.dex # Java class files *.class -# generated files +# Generated files bin/ gen/ -# Local configuration file (sdk path, etc) -local.properties - -# Eclipse project files -.classpath -.project - # Proguard folder generated by Eclipse proguard/ -# Intellij project files -*.iml -*.ipr -*.iws -.idea/ +# Log Files +*.log -# Android Studio -.gradle -*.jks -/local.properties -/.idea/workspace.xml +app-pro/ + +# Built application files +/*/build/ + +# Crashlytics configuations +com_crashlytics_export_strings.xml +crashlytics-build.properties +crashlytics.properties + +# Local configuration file (sdk path, etc) +local.properties + +# Gradle generated files +.gradle/ + +# Signing files +.signing/ + +# User-specific configurations +.idea/libraries/ +.idea/workspace.xml +.idea/tasks.xml +.idea/.name +.idea/compiler.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/misc.xml +.idea/modules.xml +.idea/scopes/scope_settings.xml +.idea/vcs.xml +*.iml + +# OS-specific files .DS_Store -/build -/Turbo Editor/build/ \ No newline at end of file +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db diff --git a/.idea/copyright/Copyright_Vlad_Mihalachi.xml b/.idea/copyright/Copyright_Vlad_Mihalachi.xml new file mode 100644 index 0000000..52b8817 --- /dev/null +++ b/.idea/copyright/Copyright_Vlad_Mihalachi.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..286ffea --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,23 @@ + + + + + + + diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..259ff23 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/Turbo Editor/build.gradle b/Turbo Editor/build.gradle deleted file mode 100644 index 74a57bf..0000000 --- a/Turbo Editor/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:0.12.+' - } -} - -apply plugin: 'android' - -repositories { - mavenCentral() -} - -android { - compileSdkVersion 19 - buildToolsVersion "19.1" - - defaultConfig { - minSdkVersion 16 - } - - lintOptions { - abortOnError false - } -} - -dependencies { - compile 'com.github.gabrielemariotti.changeloglib:library:1.2.0' - compile 'commons-io:commons-io:2.4' - compile 'com.android.support:support-v13:18.0.0' - compile ('de.greenrobot:eventbus:2.1.0-beta-1') { - exclude module: 'support-v4' - } -} diff --git a/Turbo Editor/src/main/AndroidManifest.xml b/Turbo Editor/src/main/AndroidManifest.xml deleted file mode 100644 index ac05d60..0000000 --- a/Turbo Editor/src/main/AndroidManifest.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/HomeActivity.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/HomeActivity.java deleted file mode 100644 index d74ab0e..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/HomeActivity.java +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.activity; - -import android.app.ActionBar; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Bundle; -import android.os.IBinder; -import android.preference.PreferenceManager; -import android.support.v4.app.ActionBarDrawerToggle; -import android.support.v4.widget.DrawerLayout; -import android.text.TextUtils; -import android.util.Log; -import android.view.Gravity; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.inputmethod.InputMethodManager; - -import com.vmihalachi.turboeditor.R; -import com.vmihalachi.turboeditor.event.ErrorOpeningFileEvent; -import com.vmihalachi.turboeditor.event.FileSavedEvent; -import com.vmihalachi.turboeditor.event.FileSelectedEvent; -import com.vmihalachi.turboeditor.event.NewFileOpened; -import com.vmihalachi.turboeditor.fragment.ChangelogDialogFragment; -import com.vmihalachi.turboeditor.fragment.EditorFragment; -import com.vmihalachi.turboeditor.fragment.NoFileOpenedFragment; -import com.vmihalachi.turboeditor.helper.AppInfoHelper; - -import de.greenrobot.event.EventBus; - -public class HomeActivity extends Activity { - - private String TAG = "A0A"; - public static final int SELECT_FILE_CODE = 121; - - /* - * This class provides a handy way to tie together the functionality of - * {@link DrawerLayout} and the framework ActionBar to implement the recommended - * design for navigation drawers. - */ - protected ActionBarDrawerToggle mDrawerToggle; - /* - * The Drawer Layout - */ - protected DrawerLayout mDrawerLayout; - - - /** - * {@inheritDoc} - */ - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_home); - // setup the navigation drawer - setupNavigationDrawer(); - // Replace fragment - getFragmentManager() - .beginTransaction() - .replace(R.id.fragment_editor, new NoFileOpenedFragment()) - .commit(); - /* First Time we open this activity */ - if (savedInstanceState == null) { - // Open - mDrawerLayout.openDrawer(Gravity.START); - // Set the default title - getActionBar().setTitle(getString(R.string.nome_app_turbo_editor)); - } - // parse the intent - parseIntent(getIntent()); - // show a dialog with the changelog - showChangeLog(); - } - - /** - * {@inheritDoc} - */ - @Override - protected final void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - mDrawerToggle.syncState(); - } - - - /** - * {@inheritDoc} - */ - @Override - public void onResume() { - super.onResume(); - // Register the Event Bus for events - EventBus.getDefault().register(this); - } - - - /** - * {@inheritDoc} - */ - @Override - public void onPause() { - super.onPause(); - // Unregister the Event Bus - EventBus.getDefault().unregister(this); - } - - - /** - * {@inheritDoc} - */ - @Override - protected void onDestroy() { - try { - closeKeyBoard(); - } catch (NullPointerException e) { - Log.e(TAG, e.getMessage(), e); - } - super.onDestroy(); - } - - - /** - * {@inheritDoc} - */ - @Override - public final void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - mDrawerToggle.onConfigurationChanged(newConfig); - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.activity_home, menu); - return super.onCreateOptionsMenu(menu); - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean onOptionsItemSelected(MenuItem item) { - /* If we clicked on the Navigation Drawer Menu item */ - if (mDrawerToggle.onOptionsItemSelected(item)) { - return true; - } else switch (item.getItemId()) { - case R.id.im_open: - startActivityForResult(new Intent(HomeActivity.this, SelectFileActivity.class) - .putExtra("path", "") - .putExtra("action", SelectFileActivity.Actions.SelectFile), - SELECT_FILE_CODE); - return true; - case R.id.im_info: - startActivity(new Intent(this, PreferenceAbout.class)); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - - /** - * {@inheritDoc} - */ - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == RESULT_OK && requestCode == SELECT_FILE_CODE) { - String path = data.getStringExtra("path"); - if (!TextUtils.isEmpty(path)) { - EventBus.getDefault().postSticky(new NewFileOpened(path)); - } - } - } - - /** - * {@inheritDoc} - */ - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - parseIntent(intent); - } - - /** - * @param event - */ - public void onEvent(FileSelectedEvent event) { - // Close the drawer - mDrawerLayout.closeDrawer(Gravity.LEFT); - // Replace fragment - getFragmentManager() - .beginTransaction() - .replace(R.id.fragment_editor, EditorFragment.newInstance(event.getPath())) - .commit(); - } - - /** - * When a file is saved - * Invoked by the EditorFragment - * - * @param event The event called - */ - public void onEvent(FileSavedEvent event) { - try { - closeKeyBoard(); - } catch (NullPointerException e) { - Log.e(TAG, e.getMessage(), e); - } - // Get intent, action and MIME type - final Intent intent = getIntent(); - final String action = intent.getAction(); - final String type = intent.getType(); - - if (Intent.ACTION_VIEW.equals(action) - || Intent.ACTION_EDIT.equals(action) - || Intent.ACTION_PICK.equals(action) - && type != null) { - //This Activity was called by startActivityForResult - final Intent returnIntent = new Intent(); - setResult(Activity.RESULT_OK, returnIntent); - // finish the activity - finish(); - } else { - //This Activity was called by startActivity - // - mDrawerLayout.openDrawer(Gravity.LEFT); - // - getActionBar().setTitle(getString(R.string.nome_app_turbo_editor)); - // Replace fragment - getFragmentManager() - .beginTransaction() - .replace(R.id.fragment_editor, new NoFileOpenedFragment()) - .commit(); - } - } - - /** - * When a file can't be opened - * Invoked by the EditorFragment - * - * @param event The event called - */ - public void onEvent(ErrorOpeningFileEvent event) { - // - mDrawerLayout.openDrawer(Gravity.LEFT); - // - getActionBar().setTitle(getString(R.string.nome_app_turbo_editor)); - // Replace fragment - getFragmentManager() - .beginTransaction() - .replace(R.id.fragment_editor, new NoFileOpenedFragment()) - .commit(); - } - - private void closeKeyBoard() throws NullPointerException { - // Central system API to the overall input method framework (IMF) architecture - InputMethodManager inputManager = - (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - - // Base interface for a remotable object - IBinder windowToken = getCurrentFocus().getWindowToken(); - - // Hide type - int hideType = InputMethodManager.HIDE_NOT_ALWAYS; - - // Hide the KeyBoard - inputManager.hideSoftInputFromWindow(windowToken, hideType); - } - - /** - * Setup the navigation drawer - */ - private void setupNavigationDrawer() { - mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - /* Action Bar */ - final ActionBar ab = getActionBar(); - ab.setDisplayHomeAsUpEnabled(true); - ab.setHomeButtonEnabled(true); - /* Navigation drawer */ - mDrawerToggle = - new ActionBarDrawerToggle( - this, - mDrawerLayout, - R.drawable.ic_drawer, - R.string.nome_app_turbo_editor, - R.string.nome_app_turbo_editor) { - - /** - * {@inheritDoc} - */ - @Override - public void onDrawerClosed(View view) { - invalidateOptionsMenu(); - } - - /** - * {@inheritDoc} - */ - @Override - public void onDrawerOpened(View drawerView) { - invalidateOptionsMenu(); - } - }; - /* link the mDrawerToggle to the Drawer Layout */ - mDrawerLayout.setDrawerListener(mDrawerToggle); - } - - /** - * Show a dialog with the changelog - */ - private void showChangeLog() { - final String currentVersion = AppInfoHelper.getCurrentVersion(this); - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - final String lastVersion = preferences.getString("last_version", currentVersion); - preferences.edit().putString("last_version", currentVersion).commit(); - if (!lastVersion.equals(currentVersion)) { - ChangelogDialogFragment.showChangeLogDialog(getFragmentManager()); - } - } - - /** - * Parses the intent - */ - private void parseIntent(Intent intent) { - final String action = intent.getAction(); - final String type = intent.getType(); - - if (Intent.ACTION_VIEW.equals(action) - || Intent.ACTION_EDIT.equals(action) - || Intent.ACTION_PICK.equals(action) - && type != null) { - // Post the NewFileOpened Event - EventBus.getDefault().postSticky(new NewFileOpened(intent.getData().getPath())); - } - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/LicensesActivity.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/LicensesActivity.java deleted file mode 100644 index 455b9ed..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/LicensesActivity.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.vmihalachi.turboeditor.activity; - -import android.app.Activity; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.TextView; - -import com.vmihalachi.turboeditor.R; - -public class LicensesActivity extends Activity implements AdapterView.OnItemClickListener { - - - /** - * {@inheritDoc} - */ - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_licenses); - ListView listView = (ListView) findViewById(android.R.id.list); - listView.setOnItemClickListener(this); - ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.open_source_libs)); - listView.setAdapter(adapter); - } - - - /** - * {@inheritDoc} - */ - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - String openSourceLib = ((TextView) view.findViewById(android.R.id.text1)).getText().toString(); - Intent browserIntent = null; - if (openSourceLib.equals("ChangeLog Library")) { - browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/gabrielemariotti/changeloglib?source=c#license")); - } else if (openSourceLib.equals("EventBus")) { - browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/greenrobot/EventBus?source=c#license")); - } else if (openSourceLib.equals("commons-io")) { - browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://commons.apache.org/proper/commons-io/")); - } - if (browserIntent != null) { - startActivity(browserIntent); - } - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/PreferenceAbout.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/PreferenceAbout.java deleted file mode 100644 index 7584570..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/PreferenceAbout.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.activity; - -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceActivity; - -import com.vmihalachi.turboeditor.R; -import com.vmihalachi.turboeditor.fragment.ChangelogDialogFragment; -import com.vmihalachi.turboeditor.helper.AppInfoHelper; - -public class PreferenceAbout extends PreferenceActivity { - /** - * {@inheritDoc} - */ - @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.about); - setupClickablePreferences(); - } - - public void setupClickablePreferences() { - final Preference email = findPreference("aboutactivity_authoremail"), - changelog = findPreference("aboutactivity_changelog"), - open_source_licenses = findPreference("aboutactivity_open_source_licenses"), - market = findPreference("aboutactivity_authormarket"); - if (email != null) { - email.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - /** - * {@inheritDoc} - */ - @Override - public boolean onPreferenceClick(final Preference preference) { - Intent i = new Intent(Intent.ACTION_SEND); - i.setType("message/rfc822"); - i.putExtra(Intent.EXTRA_EMAIL, new String[]{"app.feedback.mail@gmail.com"}); - i.putExtra(Intent.EXTRA_SUBJECT, AppInfoHelper.getApplicationName(getBaseContext()) + " " + AppInfoHelper.getCurrentVersion(getBaseContext())); - i.putExtra(Intent.EXTRA_TEXT, ""); - try { - startActivity(Intent.createChooser(i, getString(R.string.aboutactivity_authoremail_summary))); - } catch (android.content.ActivityNotFoundException ex) { - } - return false; - } - }); - } - if (changelog != null) { - changelog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - /** - * {@inheritDoc} - */ - @Override - public boolean onPreferenceClick(final Preference preference) { - ChangelogDialogFragment.showChangeLogDialog(getFragmentManager()); - return false; - } - }); - } - if (open_source_licenses != null) { - open_source_licenses.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - /** - * {@inheritDoc} - */ - @Override - public boolean onPreferenceClick(final Preference preference) { - startActivity(new Intent(PreferenceAbout.this, LicensesActivity.class)); - return false; - } - }); - } - if (market != null) { - market.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - /** - * {@inheritDoc} - */ - @Override - public boolean onPreferenceClick(final Preference preference) { - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:Vlad+Mihalachi")) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); - } catch (Exception e) { - } - return false; - } - }); - } - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/SelectFileActivity.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/SelectFileActivity.java deleted file mode 100644 index 405212a..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/activity/SelectFileActivity.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.activity; - -import android.app.Activity; -import android.content.Intent; -import android.os.AsyncTask; -import android.os.Bundle; -import android.text.TextUtils; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; -import android.widget.TextView; - -import com.vmihalachi.turboeditor.R; -import com.vmihalachi.turboeditor.adapter.AdapterDetailedList; -import com.vmihalachi.turboeditor.fragment.EditDialogFragment; -import com.vmihalachi.turboeditor.helper.PreferenceHelper; -import com.vmihalachi.turboeditor.util.AlphanumComparator; - -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.AbstractMap; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; - -public class SelectFileActivity extends Activity implements AdapterView.OnItemClickListener, EditDialogFragment.EditDialogListener { - private static final String TAG = "A0A"; - private String currentFolder; - private ListView listView; - private boolean wantAFile, wantAFolder; - - - /** - * {@inheritDoc} - */ - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.activity_select_file); - final Actions action = (Actions) getIntent().getExtras().getSerializable("action"); - wantAFile = action == Actions.SelectFile; - wantAFolder = action == Actions.SelectFolder; - - this.listView = (ListView) findViewById(android.R.id.list); - this.listView.setOnItemClickListener(this); - - String path = getIntent().getExtras().getString("path"); - if (TextUtils.isEmpty(path)) { - new UpdateList().execute(PreferenceHelper.getLastNavigatedFolder(this)); - } else { - new UpdateList().execute(path); - } - } - - void returnData(String path) { - if(!TextUtils.isEmpty(path)){ - PreferenceHelper.setLastNavigatedFolder(this, path); - } - final Intent returnIntent = new Intent(); - returnIntent.putExtra("path", path); - setResult(RESULT_OK, returnIntent); - // finish the activity - finish(); - } - - /** - * {@inheritDoc} - */ - @Override - public void onItemClick(AdapterView parent, - View view, int position, long id) { - final String name = ((TextView) view.findViewById(android.R.id.title)).getText().toString(); - if (name.equals("..")) { - if (currentFolder.equals("/")) { - new UpdateList().execute(PreferenceHelper.getLastNavigatedFolder(this)); - } else { - File tempFile = new File(currentFolder); - if (tempFile.isFile()) { - tempFile = tempFile.getParentFile() - .getParentFile(); - } else { - tempFile = tempFile.getParentFile(); - } - new UpdateList().execute(tempFile.getAbsolutePath()); - } - return; - } else if (name.equals(getString(R.string.home))) { - new UpdateList().execute(PreferenceHelper.getLastNavigatedFolder(this)); - return; - } - - final File selectedFile = new File(currentFolder, name); - - if (selectedFile.isFile() && wantAFile) { - returnData(selectedFile.getAbsolutePath()); - } else if (selectedFile.isDirectory()) { - new UpdateList().execute(selectedFile.getAbsolutePath()); - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.activity_select_file, menu); - menu.findItem(R.id.im_button).setTitle(getString(wantAFolder ? R.string.seleziona - : android.R.string.cancel)); - return super.onCreateOptionsMenu(menu); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int i = item.getItemId(); - if (i == R.id.im_button) { - if (wantAFolder) { - returnData(currentFolder); - } else if (wantAFile) { - returnData(""); - } - } else if (i == R.id.im_new_file) { - final EditDialogFragment dialogFrag = EditDialogFragment.newInstance(EditDialogFragment.Actions.NewLocalFile); - dialogFrag.show(getFragmentManager().beginTransaction(), "dialog"); - } - return super.onOptionsItemSelected(item); - } - - /** - * {@inheritDoc} - */ - @Override - public void onFinishEditDialog(final String inputText, final String hint, final EditDialogFragment.Actions actions) { - if(actions == EditDialogFragment.Actions.NewLocalFile){ - File file = new File(currentFolder, inputText); - try { - file.createNewFile(); - } catch (IOException e) { - Log.e(TAG, e.getMessage(), e); - } - returnData(file.getAbsolutePath()); - } - } - - private class UpdateList extends AsyncTask> { - - /** - * {@inheritDoc} - */ - @Override - protected LinkedList doInBackground(final String... params) { - try { - - final String path = params[0]; - if (TextUtils.isEmpty(path)) { - return null; - } - - File tempFile = new File(path); - if (tempFile.isFile()) { - tempFile = tempFile.getParentFile(); - } - - final File[] files = tempFile.listFiles(); - Arrays.sort(files, - getFileNameComparator()); - - final LinkedList fileDetails = new LinkedList(); - final LinkedList - folderDetails = new LinkedList(); - final AbstractMap tempList = new HashMap(); - currentFolder = tempFile.getAbsolutePath(); - - if (files != null) { - for (final File f : files) { - if (f.isHidden()) { - continue; - } else if (f.isDirectory() - && f.canRead()) { - folderDetails.add(new AdapterDetailedList.FileDetail(f.getName(), - getString(R.string.folder), - "")); - } else if (f.isFile()) { - final long fileSize = f.length(); - SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy hh:mm a"); - String date = format.format(f.lastModified()); - fileDetails.add(new AdapterDetailedList.FileDetail(f.getName(), - FileUtils.byteCountToDisplaySize(fileSize), date)); - } - tempList.put(f.getName(), f); - } - } - - folderDetails.addAll(fileDetails); - return folderDetails; - } catch (Exception e) { - return null; - } - } - - /** - * {@inheritDoc} - */ - @Override - protected void onPostExecute(final LinkedList names) { - if (names != null) { - boolean isRoot = currentFolder.equals("/"); - listView.setAdapter(new AdapterDetailedList(getBaseContext(), names, isRoot)); - } - super.onPostExecute(names); - } - - public final Comparator getFileNameComparator() { - return new AlphanumComparator() { - /** - * {@inheritDoc} - */ - @Override - public String getTheString(Object obj) { - return ((File) obj).getName() - .toLowerCase(); - } - }; - } - } - - public enum Actions { - SelectFile, SelectFolder - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/event/OpenDrawerEvent.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/event/OpenDrawerEvent.java deleted file mode 100644 index d2a7a17..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/event/OpenDrawerEvent.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.event; - -public class OpenDrawerEvent { -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/EditorFragment.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/EditorFragment.java deleted file mode 100644 index c714e61..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/EditorFragment.java +++ /dev/null @@ -1,1039 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.fragment; - -import android.app.Fragment; -import android.content.Context; -import android.content.SharedPreferences; -import android.graphics.Canvas; -import android.graphics.Typeface; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Handler; -import android.text.Editable; -import android.text.InputFilter; -import android.text.Selection; -import android.text.Spannable; -import android.text.Spanned; -import android.text.TextPaint; -import android.text.TextWatcher; -import android.text.style.ForegroundColorSpan; -import android.text.style.UnderlineSpan; -import android.util.AttributeSet; -import android.util.Log; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.EditText; -import android.widget.Toast; - -import com.vmihalachi.turboeditor.R; -import com.vmihalachi.turboeditor.event.ErrorOpeningFileEvent; -import com.vmihalachi.turboeditor.event.FileSavedEvent; -import com.vmihalachi.turboeditor.helper.PixelDipConverter; -import com.vmihalachi.turboeditor.helper.PreferenceHelper; -import com.vmihalachi.turboeditor.util.Patterns; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.LinkedList; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import de.greenrobot.event.EventBus; - -public class EditorFragment extends Fragment implements EditDialogFragment.EditDialogListener, SeekbarDialogFragment.onSeekbarDialogDismissed { - - private static final String TAG = "A0A"; - private Editor mEditor; - - // Editor Variables - static boolean sLineNumbers; - static boolean sColorSyntax; - static int sFontSize; - // - private boolean mUseMonospace; - private String mCurrentEncoding; - private static String sFilePath; - - - public static EditorFragment newInstance(String filePath) { - EditorFragment frag = new EditorFragment(); - Bundle args = new Bundle(); - args.putString("filePath", filePath); - frag.setArguments(args); - return frag; - } - - - /** - * {@inheritDoc} - */ - @Override - 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.sLineNumbers = PreferenceHelper.getLineNumbers(getActivity()); - this.sFontSize = PreferenceHelper.getFontSize(getActivity()); - } - - - /** - * {@inheritDoc} - */ - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_editor, container, false); - mEditor = (Editor) rootView.findViewById(R.id.editor); - if (this.sLineNumbers) { - 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; - } - - - /** - * {@inheritDoc} - */ - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - String fileName = FilenameUtils.getName(getArguments().getString("filePath")); - getActivity().getActionBar().setTitle(fileName); - try { - final FileInputStream inputStream = - new FileInputStream( - new File(this.sFilePath)); - mEditor.setText(IOUtils.toString(inputStream, this.mCurrentEncoding)); - inputStream.close(); - } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); - EventBus.getDefault().post(new ErrorOpeningFileEvent()); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - inflater.inflate(R.menu.fragment_editor, menu); - menu.findItem(R.id.im_line_numbers).setChecked(this.sLineNumbers); - menu.findItem(R.id.im_syntax_highlight).setChecked(this.sColorSyntax); - menu.findItem(R.id.im_use_monospace).setChecked(this.mUseMonospace); - super.onCreateOptionsMenu(menu, inflater); - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int i = item.getItemId(); - if (i == R.id.im_save) { - new SaveFile().execute(); - } else if (i == R.id.im_undo) { - this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Z, new KeyEvent(KeyEvent.ACTION_DOWN, - KeyEvent.KEYCODE_Z)); - } else if (i == R.id.im_redo) { - this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Y, new KeyEvent(KeyEvent.ACTION_DOWN, - KeyEvent.KEYCODE_Y)); - } else if (i == R.id.im_editor_encoding) { - 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()); - updateTextEditor(); - } else if (i == R.id.im_line_numbers) { - item.setChecked(!item.isChecked()); - PreferenceHelper.setLineNumbers(getActivity(), item.isChecked()); - updateTextEditor(); - } else if (i == R.id.im_use_monospace) { - item.setChecked(!item.isChecked()); - PreferenceHelper.setUseMonospace(getActivity(), item.isChecked()); - updateTextEditor(); - } - return super.onOptionsItemSelected(item); - } - - /** - * {@inheritDoc} - */ - @Override - public void onFinishEditDialog(final String inputText, final String hint, final EditDialogFragment.Actions actions) { - if(actions == EditDialogFragment.Actions.Encoding){ - PreferenceHelper.setEncoding(getActivity(), inputText); - updateTextEditor(); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void onSeekbarDialogDismissed(SeekbarDialogFragment.Actions action, int value) { - PreferenceHelper.setFontSize(getActivity(), value); - updateTextEditor(); - } - - private void updateTextEditor() { - final boolean wrapText = PreferenceHelper.getLineNumbers(getActivity()); - final boolean syntaxHighlight = PreferenceHelper.getSyntaxHiglight(getActivity()); - final boolean useMonospace = PreferenceHelper.getUseMonospace(getActivity()); - final String encoding = PreferenceHelper.getEncoding(getActivity()); - final int fontSize = PreferenceHelper.getFontSize(getActivity()); - - if (this.sLineNumbers != wrapText) { - this.sLineNumbers = wrapText; - this.mEditor.setText(this.mEditor.getText().toString()); - if (this.sLineNumbers) { - 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; - this.mEditor.setText(this.mEditor.getText().toString()); - } - - if (this.mUseMonospace != useMonospace) { - this.mUseMonospace = useMonospace; - this.mEditor.setTypeface(Typeface.MONOSPACE); - } - - 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)) { - try { - final byte[] oldText = this.mEditor.getText().toString().getBytes(this.mCurrentEncoding); - this.mEditor.setText(new String(oldText, encoding)); - this.mCurrentEncoding = encoding; - } catch (UnsupportedEncodingException ignored) { - } - } - } - - class SaveFile extends AsyncTask { - - /** - * {@inheritDoc} - */ - @Override - protected Void doInBackground(final Void... voids) { - try { - FileUtils.write(new File(EditorFragment.this.sFilePath), - EditorFragment.this.mEditor.getText(), - EditorFragment.this.mCurrentEncoding); - } catch (IOException e) { - Log.e(TAG, e.getMessage(), e); - } - return null; - } - - /** - * {@inheritDoc} - */ - @Override - protected void onPostExecute(final Void aVoid) { - super.onPostExecute(aVoid); - EventBus.getDefault().post(new FileSavedEvent(EditorFragment.this.sFilePath)); - } - } - - - public static class Editor extends EditText { - - protected static final int - ID_SELECT_ALL = android.R.id.selectAll, - ID_CUT = android.R.id.cut, - ID_COPY = android.R.id.copy, - ID_PASTE = android.R.id.paste, - ID_UNDO = R.id.im_undo, - ID_REDO = R.id.im_redo; - private static final int SYNTAX_DELAY_MILLIS = 800; - private final Handler updateHandler = new Handler(); - private final TextPaint mPaintNumbers = new TextPaint(); - private boolean modified = true; - private boolean firstTimeColoring = true; - - /** - * Is undo/redo being performed? This member - * signals if an undo/redo operation is - * currently being performed. Changes in the - * text during undo/redo are not recorded - * because it would mess up the undo history. - */ - private boolean mIsUndoOrRedo = false; - - /** - * The edit history. - */ - private EditHistory mEditHistory; - - /** - * The change listener. - */ - private EditTextChangeListener - mChangeListener; - - private final Runnable updateRunnable = - new Runnable() { - /** - * {@inheritDoc} - */ - @Override - public void run() { - replaceTextKeepCursor(getText()); - } - }; - - public Editor(Context context, - AttributeSet attrs) { - super(context, attrs); - init(); - } - - // Init the class - private void init() { - mEditHistory = new EditHistory(); - mChangeListener = new EditTextChangeListener(); - addTextChangedListener(mChangeListener); - - this.mPaintNumbers.setColor(getTextColors().getDefaultColor()); - this.mPaintNumbers.setAntiAlias(true); - - // Syntax editor - setFilters(new InputFilter[]{ - new InputFilter() { - /** - * {@inheritDoc} - */ - @Override - public CharSequence filter( - CharSequence source, - int start, - int end, - Spanned dest, - int dstart, - int dend) { - if (modified) { - return autoIndent( - source, - start, - end, - dest, - dstart, - dend); - } - - return source; - } - }}); - } - - @Override - public void setTextSize(float size) { - super.setTextSize(size); - final float scale = getContext().getResources().getDisplayMetrics().density; - this.mPaintNumbers.setTextSize((int) (size * scale * 0.5f)); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean onKeyShortcut( - final int keyCode, final KeyEvent event) { - switch (keyCode) { - case KeyEvent.KEYCODE_A: - return onTextContextMenuItem( - ID_SELECT_ALL); - case KeyEvent.KEYCODE_X: - return onTextContextMenuItem(ID_CUT); - case KeyEvent.KEYCODE_C: - return onTextContextMenuItem(ID_COPY); - case KeyEvent.KEYCODE_V: - return onTextContextMenuItem(ID_PASTE); - case KeyEvent.KEYCODE_Z: - if (getCanUndo()) { - return onTextContextMenuItem(ID_UNDO); - } - break; - case KeyEvent.KEYCODE_Y: - if (getCanRedo()) { - return onTextContextMenuItem(ID_REDO); - } - break; - } - - return super.onKeyShortcut(keyCode, event); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean onTextContextMenuItem( - final int id) { - if (id == ID_UNDO) { - undo(); - return true; - } else if (id == ID_REDO) { - redo(); - return true; - } else { - return super.onTextContextMenuItem(id); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void onDraw(final Canvas canvas) { - if (EditorFragment.sLineNumbers) { - final int max = getLineCount(); - final TextPaint paint = mPaintNumbers; - for (int min = 0; min < max; min++) { - canvas.drawText(String.valueOf(min + 1), - 0, - getLineBounds(min, null), - paint); - } - } - super.onDraw(canvas); - } - - private CharSequence autoIndent( - CharSequence source, - int start, - int end, - Spanned dest, - int dstart, - int dend) { - if (end - start != 1 || - start >= source.length() || - source.charAt(start) != '\n' || - dstart >= dest.length()) { - return source; - } - - int istart = dstart; - int iend; - String indent = ""; - - // skip end of line if cursor is at the end of a line - if (dest.charAt(istart) == '\n') { - --istart; - } - - // indent next line if this one isn't terminated - if (istart > -1) { - // skip white space - for (; istart > -1; --istart) { - char c = dest.charAt(istart); - - if (c != ' ' && - c != '\t') { - break; - } - } - - if (istart > -1) { - char c = dest.charAt(istart); - - if (c != ';' && - c != '\n') { - indent = "\t"; - } - } - } - - // find start of previous line - for (; istart > -1; --istart) { - if (dest.charAt(istart) == '\n') { - break; - } - } - - // cursor is in the first line - if (istart < 0) { - return source; - } - - // span over previous indent - for (iend = ++istart; - iend < dend; - ++iend) { - char c = dest.charAt(iend); - - if (c != ' ' && - c != '\t') { - break; - } - } - - // copy white space of previous lines and append new indent - return "\n" + dest.subSequence( - istart, - iend) + indent; - } - - private void cancelUpdate() { - updateHandler.removeCallbacks( - updateRunnable); - } - - private void replaceTextKeepCursor( - Editable e) { - int p = getSelectionStart(); - disconnect(); - modified = false; - - setText(highlight(e)); - - modified = true; - addTextChangedListener(mChangeListener); - - if (p > -1) { - setSelection(p); - } - } - - private CharSequence highlight(Editable editable) { - final String fileExtension = FilenameUtils.getExtension(EditorFragment.sFilePath); - editable.clearSpans(); - - if (editable.length() == 0) { - return editable; - } - - if (fileExtension.contains("html") - || fileExtension.contains("xml")) { - color(Patterns.HTML_OPEN_TAGS, editable); - color(Patterns.HTML_CLOSE_TAGS, editable); - color(Patterns.HTML_ATTRS, editable); - color(Patterns.GENERAL_STRINGS, editable); - color(Patterns.XML_COMMENTS, editable); - } else if (fileExtension.equals("css")) { - //color(CSS_STYLE_NAME, editable); - color(Patterns.CSS_ATTRS, editable); - color(Patterns.CSS_ATTR_VALUE, editable); - color(Patterns.GENERAL_COMMENTS, editable); - } else if (fileExtension.equals("js")) { - color(Patterns.GENERAL_KEYWORDS, editable); - color(Patterns.NUMBERS, editable); - color(Patterns.GENERAL_COMMENTS, editable); - } else if (fileExtension.equals("php")){ - color(Patterns.HTML_OPEN_TAGS, editable); - color(Patterns.HTML_CLOSE_TAGS, editable); - color(Patterns.HTML_ATTRS, editable); - color(Patterns.GENERAL_KEYWORDS, editable); - color(Patterns.NUMBERS, editable); - color(Patterns.GENERAL_COMMENTS, editable); - } else { - color(Patterns.GENERAL_KEYWORDS, editable); - color(Patterns.NUMBERS, editable); - color(Patterns.GENERAL_COMMENTS, editable); - } - - return editable; - } - - private void color(Pattern pattern, - Editable editable) { - int color = 0; - if (pattern.equals(Patterns.HTML_OPEN_TAGS) - || pattern.equals(Patterns.HTML_CLOSE_TAGS) - || pattern.equals(Patterns.GENERAL_KEYWORDS) - //|| pattern.equals(CSS_STYLE_NAME) - ) { - color = Patterns.COLOR_KEYWORD; - } else if (pattern.equals(Patterns.HTML_ATTRS) - || pattern.equals(Patterns.CSS_ATTRS)) { - color = Patterns.COLOR_ATTR; - } else if (pattern.equals(Patterns.CSS_ATTR_VALUE)) { - color = Patterns.COLOR_ATTR_VALUE; - } else if (pattern.equals(Patterns.XML_COMMENTS) - || pattern.equals(Patterns.GENERAL_COMMENTS)) { - color = Patterns.COLOR_COMMENT; - } else if (pattern.equals( - Patterns.GENERAL_STRINGS)) { - color = Patterns.COLOR_STRING; - } else if (pattern.equals(Patterns.NUMBERS)) { - color = Patterns.COLOR_NUMBER; - } - - for (final Matcher m = - pattern.matcher(editable); - m.find(); ) { - editable.setSpan( - new ForegroundColorSpan(color), - m.start(), - m.end(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - } - - // =================================================================== // - - /** - * Disconnect this undo/redo from the text - * view. - */ - public void disconnect() { - removeTextChangedListener(mChangeListener); - } - - /** - * Set the maximum history size. If size is - * negative, then history size is only limited - * by the device memory. - */ - public void setMaxHistorySize( - int maxHistorySize) { - mEditHistory.setMaxHistorySize( - maxHistorySize); - } - - /** - * Clear history. - */ - public void clearHistory() { - mEditHistory.clear(); - } - - /** - * Can undo be performed? - */ - public boolean getCanUndo() { - return (mEditHistory.mmPosition > 0); - } - - /** - * Perform undo. - */ - public void undo() { - EditItem edit = mEditHistory.getPrevious(); - if (edit == null) { - return; - } - - Editable text = getEditableText(); - int start = edit.mmStart; - int end = start + (edit.mmAfter != null - ? edit.mmAfter.length() : 0); - - mIsUndoOrRedo = true; - text.replace(start, end, edit.mmBefore); - mIsUndoOrRedo = false; - - // This will get rid of underlines inserted when editor tries to come - // up with a suggestion. - for (Object o : text.getSpans(0, - text.length(), UnderlineSpan.class)) { - text.removeSpan(o); - } - - Selection.setSelection(text, - edit.mmBefore == null ? start - : (start + edit.mmBefore.length())); - } - - /** - * Can redo be performed? - */ - public boolean getCanRedo() { - return (mEditHistory.mmPosition - < mEditHistory.mmHistory.size()); - } - - /** - * Perform redo. - */ - public void redo() { - EditItem edit = mEditHistory.getNext(); - if (edit == null) { - return; - } - - Editable text = getEditableText(); - int start = edit.mmStart; - int end = start + (edit.mmBefore != null - ? edit.mmBefore.length() : 0); - - mIsUndoOrRedo = true; - text.replace(start, end, edit.mmAfter); - mIsUndoOrRedo = false; - - // This will get rid of underlines inserted when editor tries to come - // up with a suggestion. - for (Object o : text.getSpans(0, - text.length(), UnderlineSpan.class)) { - text.removeSpan(o); - } - - Selection.setSelection(text, - edit.mmAfter == null ? start - : (start + edit.mmAfter.length())); - } - - /** - * Store preferences. - */ - public void storePersistentState( - SharedPreferences.Editor editor, - String prefix) { - // Store hash code of text in the editor so that we can check if the - // editor contents has changed. - editor.putString(prefix + ".hash", - String.valueOf( - getText().toString().hashCode())); - editor.putInt(prefix + ".maxSize", - mEditHistory.mmMaxHistorySize); - editor.putInt(prefix + ".position", - mEditHistory.mmPosition); - editor.putInt(prefix + ".size", - mEditHistory.mmHistory.size()); - - int i = 0; - for (EditItem ei : mEditHistory.mmHistory) { - String pre = prefix + "." + i; - - editor.putInt(pre + ".start", ei.mmStart); - editor.putString(pre + ".before", - ei.mmBefore.toString()); - editor.putString(pre + ".after", - ei.mmAfter.toString()); - - i++; - } - } - - /** - * Restore preferences. - * - * @param prefix The preference key prefix - * used when state was stored. - * @return did restore succeed? If this is - * false, the undo history will be empty. - */ - public boolean restorePersistentState( - SharedPreferences sp, String prefix) - throws IllegalStateException { - - boolean ok = - doRestorePersistentState(sp, prefix); - if (!ok) { - mEditHistory.clear(); - } - - return ok; - } - - private boolean doRestorePersistentState( - SharedPreferences sp, String prefix) { - - String hash = - sp.getString(prefix + ".hash", null); - if (hash == null) { - // No state to be restored. - return true; - } - - if (Integer.valueOf(hash) - != getText().toString().hashCode()) { - return false; - } - - mEditHistory.clear(); - mEditHistory.mmMaxHistorySize = - sp.getInt(prefix + ".maxSize", -1); - - int count = sp.getInt(prefix + ".size", -1); - if (count == -1) { - return false; - } - - for (int i = 0; i < count; i++) { - String pre = prefix + "." + i; - - int start = sp.getInt(pre + ".start", -1); - String before = - sp.getString(pre + ".before", null); - String after = - sp.getString(pre + ".after", null); - - if (start == -1 - || before == null - || after == null) { - return false; - } - mEditHistory.add( - new EditItem(start, before, after)); - } - - mEditHistory.mmPosition = - sp.getInt(prefix + ".position", -1); - if (mEditHistory.mmPosition == -1) { - return false; - } - - return true; - } - - // =================================================================== // - - /** - * Keeps track of all the edit history of a - * text. - */ - private final class EditHistory { - - /** - * The position from which an EditItem will - * be retrieved when getNext() is called. If - * getPrevious() has not been called, this - * has the same value as mmHistory.size(). - */ - private int mmPosition = 0; - - /** - * Maximum undo history size. - */ - private int mmMaxHistorySize = -1; - - /** - * The list of edits in chronological - * order. - */ - private final LinkedList - mmHistory = new LinkedList(); - - /** - * Clear history. - */ - private void clear() { - mmPosition = 0; - mmHistory.clear(); - } - - /** - * Adds a new edit operation to the history - * at the current position. If executed - * after a call to getPrevious() removes all - * the future history (elements with - * positions >= current history position). - */ - private void add(EditItem item) { - while (mmHistory.size() > mmPosition) { - mmHistory.removeLast(); - } - mmHistory.add(item); - mmPosition++; - - if (mmMaxHistorySize >= 0) { - trimHistory(); - } - } - - /** - * Set the maximum history size. If size is - * negative, then history size is only - * limited by the device memory. - */ - private void setMaxHistorySize( - int maxHistorySize) { - mmMaxHistorySize = maxHistorySize; - if (mmMaxHistorySize >= 0) { - trimHistory(); - } - } - - /** - * Trim history when it exceeds max history - * size. - */ - private void trimHistory() { - while (mmHistory.size() - > mmMaxHistorySize) { - mmHistory.removeFirst(); - mmPosition--; - } - - if (mmPosition < 0) { - mmPosition = 0; - } - } - - /** - * Traverses the history backward by one - * position, returns and item at that - * position. - */ - private EditItem getPrevious() { - if (mmPosition == 0) { - return null; - } - mmPosition--; - return mmHistory.get(mmPosition); - } - - /** - * Traverses the history forward by one - * position, returns and item at that - * position. - */ - private EditItem getNext() { - if (mmPosition >= mmHistory.size()) { - return null; - } - - EditItem item = mmHistory.get(mmPosition); - mmPosition++; - return item; - } - } - - /** - * Represents the changes performed by a - * single edit operation. - */ - private final class EditItem { - private final int mmStart; - private final CharSequence mmBefore; - private final CharSequence mmAfter; - - /** - * Constructs EditItem of a modification - * that was applied at position start and - * replaced CharSequence before with - * CharSequence after. - */ - public EditItem(int start, - CharSequence before, CharSequence after) { - mmStart = start; - mmBefore = before; - mmAfter = after; - } - } - - /** - * Class that listens to changes in the text. - */ - private final class EditTextChangeListener - implements TextWatcher { - - /** - * The text that will be removed by the - * change event. - */ - private CharSequence mBeforeChange; - - /** - * The text that was inserted by the change - * event. - */ - private CharSequence mAfterChange; - - public void beforeTextChanged( - CharSequence s, int start, int count, - int after) { - if (mIsUndoOrRedo) { - return; - } - - mBeforeChange = - s.subSequence(start, start + count); - } - - public void onTextChanged(CharSequence s, - int start, int before, - int count) { - if (mIsUndoOrRedo) { - return; - } - - mAfterChange = - s.subSequence(start, start + count); - mEditHistory.add( - new EditItem(start, mBeforeChange, - mAfterChange)); - } - - public void afterTextChanged(Editable s) { - cancelUpdate(); - - if (!EditorFragment.sColorSyntax || !modified) { - return; - } - if(firstTimeColoring){ - firstTimeColoring = false; - updateHandler.post(updateRunnable); - } else { - updateHandler.removeCallbacks(updateRunnable); - updateHandler.postDelayed(updateRunnable, SYNTAX_DELAY_MILLIS); - } - } - } - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/NavigationDrawerListFragment.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/NavigationDrawerListFragment.java deleted file mode 100644 index d3dd7d9..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/NavigationDrawerListFragment.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.fragment; - -import android.app.ListFragment; -import android.os.Bundle; -import android.util.SparseBooleanArray; -import android.view.ActionMode; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AbsListView; -import android.widget.ArrayAdapter; -import android.widget.ListView; - -import com.vmihalachi.turboeditor.R; -import com.vmihalachi.turboeditor.event.FileSelectedEvent; -import com.vmihalachi.turboeditor.event.NewFileOpened; -import com.vmihalachi.turboeditor.helper.PreferenceHelper; - -import org.apache.commons.io.FilenameUtils; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import de.greenrobot.event.EventBus; - - -public class NavigationDrawerListFragment extends ListFragment implements AbsListView.MultiChoiceModeListener { - - private List fileNames; - private ArrayAdapter arrayAdapter; - - - /** - * {@inheritDoc} - */ - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Our custom layout - View rootView = inflater.inflate(R.layout.fragment_navigation_drawer, container, false); - return rootView; - } - - - /** - * {@inheritDoc} - */ - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - getListView().setMultiChoiceModeListener(this); - } - - - /** - * {@inheritDoc} - */ - @Override - public void onResume() { - super.onResume(); - // Register the Event Bus for events - EventBus.getDefault().registerSticky(this); - // Refresh the list view - refreshList(); - } - - - /** - * {@inheritDoc} - */ - @Override - public void onPause() { - super.onPause(); - // Unregister the Event Bus - EventBus.getDefault().unregister(this); - } - - - /** - * {@inheritDoc} - */ - @Override - public void onListItemClick(ListView l, View v, int position, long id) { - super.onListItemClick(l, v, position, id); - // File paths saved in preferences - String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity()); - // Path of the file selected - String filePath = savedPaths[position]; - // Send the event that a file was selected - EventBus.getDefault().post(new FileSelectedEvent(filePath)); - } - - - /** - * {@inheritDoc} - */ - @Override - public void onItemCheckedStateChanged(ActionMode actionMode, int position, long l, boolean isChecked) { - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { - MenuInflater inflater = actionMode.getMenuInflater(); - inflater.inflate(R.menu.action_mode_navigation_drawer, menu); - return true; - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { - return false; - } - - - /** - * {@inheritDoc} - */ - @Override - public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { - switch (menuItem.getItemId()) { - case R.id.im_remove: - // File paths saved in preferences - String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity()); - // We get the checked positions - SparseBooleanArray checkedItems = getListView().getCheckedItemPositions(); - // If we have some checked positions - if (checkedItems != null) { - for (int i = 0; i < checkedItems.size(); i++) { - // check if the value is checked - if (checkedItems.valueAt(i)) { - // remove the checked path, but don't refresh the list - removePath(savedPaths[checkedItems.keyAt(i)], false); - } - } - // In the end refresh the list - refreshList(); - } - // Close the action mode - actionMode.finish(); - return true; - default: - return false; - } - } - - - /** - * {@inheritDoc} - */ - @Override - public void onDestroyActionMode(ActionMode actionMode) { - - } - - - /** - * When a new file is opened - * Invoked by the main activity which receive the intent - * - * @param event The event called - */ - public void onEvent(NewFileOpened event) { - EventBus.getDefault().removeStickyEvent(event); - // File paths saved in preferences - String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity()); - for (int i = 0; i < savedPaths.length; i++) { - // We don't need to save the file path twice - if (savedPaths[i].equals(event.getFilePath())) { - // Send the event that a file was selected - EventBus.getDefault().post(new FileSelectedEvent(event.getFilePath())); - return; - } - } - // Add the path if it wasn't added before - addPath(event.getFilePath()); - // Send the event that a file was selected - EventBus.getDefault().post(new FileSelectedEvent(event.getFilePath())); - } - - private void addPath(String path) { - // Add a path and refresh the list - addPath(path, true); - } - - private void addPath(String path, boolean refreshTheList) { - // File paths saved in preferences - String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity()); - // StringBuilder - StringBuilder sb = new StringBuilder(); - for (int count = 0; count < savedPaths.length; count++) { - // Append the file path and a comma - sb.append(savedPaths[count]).append(","); - } - // Append new path - sb.append(path); - // Put the string and commit - PreferenceHelper.setSavedPaths(getActivity(), sb); - // Update list - if (refreshTheList) { - refreshList(); - } - } - - private void removePath(String path) { - // Remove the path and refresh the list - removePath(path, true); - } - - private void removePath(String path, boolean refresh) { - // File paths saved in preferences - String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity()); - // StringBuilder - StringBuilder sb = new StringBuilder(); - // for cycle - for (int count = 0; count < savedPaths.length; count++) { - if (path.equals(savedPaths[count])) continue; - sb.append(savedPaths[count]).append(","); - } - // Put the string and commit - PreferenceHelper.setSavedPaths(getActivity(), sb); - // Update list - if (refresh) { - refreshList(); - } - } - - private void refreshList() { - // File paths saved in preferences - String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity()); - // File names for the list - fileNames = new ArrayList(savedPaths.length); - // StringBuilder that will contain the file paths - StringBuilder sb = new StringBuilder(); - // for cycle to convert paths to names - for (String path : savedPaths) { - File file = new File(path); - // Check that the file exist - if (file.exists()) { - fileNames.add(FilenameUtils.getName(path)); - sb.append(path).append(","); - } - } - // save list without empty or non existed files - PreferenceHelper.setSavedPaths(getActivity(), sb); - // Adapter - arrayAdapter = new ArrayAdapter(getActivity(), R.layout.item_drawer_list, fileNames); - // Set adapter - setListAdapter(arrayAdapter); - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/SeekbarDialogFragment.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/SeekbarDialogFragment.java deleted file mode 100644 index 04e70d5..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/fragment/SeekbarDialogFragment.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.fragment; - -import android.app.Dialog; -import android.app.DialogFragment; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.SeekBar; - -import com.vmihalachi.turboeditor.R; - -// ... -public class SeekbarDialogFragment extends DialogFragment { - - SeekBar mSeekBar; - - public static SeekbarDialogFragment newInstance(final Actions action) { - return SeekbarDialogFragment.newInstance(action, 50, 100); - } - - public static SeekbarDialogFragment newInstance(final Actions action, final int current, final int max) { - final SeekbarDialogFragment f = new SeekbarDialogFragment(); - final Bundle args = new Bundle(); - args.putSerializable("action", action); - args.putInt("current", current); - args.putInt("max", max); - f.setArguments(args); - return f; - } - - @Override - public View onCreateView(final LayoutInflater inflater, final ViewGroup container, - final Bundle savedInstanceState) { - - final Dialog dialog = getDialog(); - final Actions action = (Actions) getArguments().getSerializable("action"); - final String title; - switch (action) { - case FileSize: - title = getString(R.string.font_size); - break; - default: - title = null; - break; - } - dialog.setTitle(title); - - final View view = inflater.inflate(R.layout.dialog_fragment_seekbar, container); - this.mSeekBar = (SeekBar) view.findViewById(android.R.id.input); - this.mSeekBar.setProgress(getArguments().getInt("current")); - this.mSeekBar.setMax(getArguments().getInt("max")); - - view.findViewById(android.R.id.button1) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View v) { - returnData(); - } - }); - return view; - } - - void returnData(){ - try { - ((onSeekbarDialogDismissed) getTargetFragment()).onSeekbarDialogDismissed( - (Actions) getArguments().getSerializable("action"), - mSeekBar.getProgress() - ); - } catch (Exception e){ - try { - ((onSeekbarDialogDismissed) getActivity()).onSeekbarDialogDismissed( - (Actions) getArguments().getSerializable("action"), - mSeekBar.getProgress() - ); - } catch (Exception e2){ - } - } - this.dismiss(); - } - - public enum Actions { - FileSize - } - - public interface onSeekbarDialogDismissed { - void onSeekbarDialogDismissed(Actions action, int value); - } -} \ No newline at end of file diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/AppInfoHelper.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/AppInfoHelper.java deleted file mode 100644 index 17d8d0f..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/AppInfoHelper.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.vmihalachi.turboeditor.helper; - -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; - -public class AppInfoHelper { - public static String getApplicationName(final Context context) { - final ApplicationInfo applicationInfo = context.getApplicationInfo(); - return context.getString(applicationInfo.labelRes); - } - - public static String getCurrentVersion(final Context context) { - try { - final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), - 0); - return packageInfo.versionName; - } catch (PackageManager.NameNotFoundException e) { - return ""; - } - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/PreferenceHelper.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/PreferenceHelper.java deleted file mode 100644 index 7a3bca0..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/PreferenceHelper.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.helper; - -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Environment; -import android.preference.PreferenceManager; - -public final class PreferenceHelper { - - private static final String SD_CARD_ROOT = Environment.getExternalStorageDirectory().getAbsolutePath(); - - private PreferenceHelper() { - } - - // Getter Methods - - public static SharedPreferences getPrefs(Context context) { - return PreferenceManager.getDefaultSharedPreferences(context); - } - - public static SharedPreferences.Editor getEditor(Context context) { - return getPrefs(context).edit(); - } - - public static boolean getUseMonospace(Context context) { - return getPrefs(context).getBoolean("use_monospace", false); - } - - public static boolean getLineNumbers(Context context) { - return getPrefs(context).getBoolean("editor_line_numbers", true); - } - - public static boolean getSyntaxHiglight(Context context) { - return getPrefs(context).getBoolean("editor_syntax_highlight", true); - } - - public static String getEncoding(Context context) { - return getPrefs(context).getString("editor_encoding", "UTF-8"); - } - - public static int getFontSize(Context context) { - return getPrefs(context).getInt("font_size", 18); - } - - public static String getLastNavigatedFolder(Context context) { - return getPrefs(context).getString("last_navigated_folder", SD_CARD_ROOT); - } - - public static String[] getSavedPaths(Context context) { - return getPrefs(context).getString("savedPaths", "").split(","); - } - - // Setter methods - - public static void setUseMonospace(Context context, boolean value) { - getEditor(context).putBoolean("use_monospace", value).commit(); - } - - public static void setLineNumbers(Context context, boolean value) { - getEditor(context).putBoolean("editor_line_numbers", value).commit(); - } - - public static void setSyntaxHiglight(Context context, boolean value) { - getEditor(context).putBoolean("editor_syntax_highlight", 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(); - } - - public static void setLastNavigatedFolder(Context context, String value) { - getEditor(context).putString("last_navigated_folder", value).commit(); - } - - public static void setSavedPaths(Context context, StringBuilder stringBuilder) { - getEditor(context).putString("savedPaths", stringBuilder.toString()).commit(); - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/StringHelper.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/StringHelper.java deleted file mode 100644 index a9e387f..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/helper/StringHelper.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.helper; - -public final class StringHelper { - - private StringHelper() { - } - - public static String join(final String... strings) { - final StringBuffer buffer = new StringBuffer(); - for (String string : strings) { - if (!string.endsWith("/")) { - string += "/"; - } - buffer.append(string); - } - String result = buffer.toString(); - if (result.endsWith("/")) { - result = result.substring(0, result.length() - 1); - } - return result; - } -} diff --git a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/util/Patterns.java b/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/util/Patterns.java deleted file mode 100644 index ab85741..0000000 --- a/Turbo Editor/src/main/java/com/vmihalachi/turboeditor/util/Patterns.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2013 Vlad Mihalachi - * - * This file is part of Turbo Editor. - * - * Turbo Editor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Turbo Editor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Turbo Editor. If not, see . - */ - -package com.vmihalachi.turboeditor.util; - -import java.util.regex.Pattern; - -public class Patterns { - public static final int COLOR_NUMBER = 0xffff6600; - public static final int COLOR_KEYWORD = 0xff2f6f9f; - public static final int COLOR_ATTR = 0xff4f9fcf; - public static final int COLOR_ATTR_VALUE = 0xffd44950; - public static final int COLOR_STRING = 0xffd44950; - public static final int COLOR_COMMENT = 0xff999999; - - // Strings - public static final Pattern GENERAL_STRINGS = Pattern.compile("\"(.*?)\"|'(.*?)'"); - - public static final Pattern HTML_OPEN_TAGS = Pattern.compile( - "<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>"); - public static final Pattern HTML_CLOSE_TAGS = Pattern.compile( - "]*>"); - public static final Pattern HTML_ATTRS = Pattern.compile( - "(\\S+)=[\"']?((?:.(?![\"']?\\s+(?:\\S+)=|[>\"']))+.)[\"']?"); - - //static final Pattern CSS_STYLE_NAME= Pattern.compile( - // "[ \\t\\n\\r\\f](.+?)\\{([^\\)]+)\\}"); - public static final Pattern CSS_ATTRS = Pattern.compile( - "(.+?):(.+?);"); - public static final Pattern CSS_ATTR_VALUE = Pattern.compile( - ":[ \t](.+?);"); - - public static final Pattern NUMBERS = Pattern.compile( - "\\b(\\d*[.]?\\d+)\\b"); - public static final Pattern CSS_NUMBERS = Pattern.compile( - "/^auto$|^[+-]?[0-9]+\\.?([0-9]+)?(px|em|ex|%|in|cm|mm|pt|pc)?$/ig"); - public static final Pattern GENERAL_KEYWORDS = Pattern.compile( - "\\b(alignas|alignof|and|and_eq|asm|auto|bitand|bitorbool|break|case|catch|char|" - + "char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|decltype" - + "|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|" - + "false|float|for|friend|function|goto|if|inline|int|mutable|namespace|new|noexcept|" - + "not|not_eq|nullptr|operator|or|or_eq|private|protected|public|register|" - + "reinterpret_cast|return|short|signed|sizeof|static|static_assert|static_cast" - + "|struct|switch|template|this|thread_local|throw|true|try|typedef|typeid|typename" - + "|union|unsigned|using|var|virtual|void|volatile|wchar_t|while|xor|xor_eq)\\b"); - // Comments - public static final Pattern XML_COMMENTS = Pattern.compile("(?s)"); - public static final Pattern GENERAL_COMMENTS = Pattern.compile( - "/\\*(?:.|[\\n\\r])*?\\*/|//.*"); -} diff --git a/Turbo Editor/src/main/res/drawable-hdpi/ic_action_redo.png b/Turbo Editor/src/main/res/drawable-hdpi/ic_action_redo.png deleted file mode 100644 index f52a806..0000000 Binary files a/Turbo Editor/src/main/res/drawable-hdpi/ic_action_redo.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-hdpi/ic_action_tick.png b/Turbo Editor/src/main/res/drawable-hdpi/ic_action_tick.png deleted file mode 100644 index 3511bc6..0000000 Binary files a/Turbo Editor/src/main/res/drawable-hdpi/ic_action_tick.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-hdpi/ic_action_undo.png b/Turbo Editor/src/main/res/drawable-hdpi/ic_action_undo.png deleted file mode 100644 index 5fa7f7c..0000000 Binary files a/Turbo Editor/src/main/res/drawable-hdpi/ic_action_undo.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-hdpi/ic_drawer.png b/Turbo Editor/src/main/res/drawable-hdpi/ic_drawer.png deleted file mode 100644 index ff7b1de..0000000 Binary files a/Turbo Editor/src/main/res/drawable-hdpi/ic_drawer.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-mdpi/ic_action_redo.png b/Turbo Editor/src/main/res/drawable-mdpi/ic_action_redo.png deleted file mode 100644 index 46d55be..0000000 Binary files a/Turbo Editor/src/main/res/drawable-mdpi/ic_action_redo.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-mdpi/ic_action_tick.png b/Turbo Editor/src/main/res/drawable-mdpi/ic_action_tick.png deleted file mode 100644 index 70e7703..0000000 Binary files a/Turbo Editor/src/main/res/drawable-mdpi/ic_action_tick.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-mdpi/ic_action_undo.png b/Turbo Editor/src/main/res/drawable-mdpi/ic_action_undo.png deleted file mode 100644 index ceed2ef..0000000 Binary files a/Turbo Editor/src/main/res/drawable-mdpi/ic_action_undo.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-mdpi/ic_drawer.png b/Turbo Editor/src/main/res/drawable-mdpi/ic_drawer.png deleted file mode 100644 index fb681ba..0000000 Binary files a/Turbo Editor/src/main/res/drawable-mdpi/ic_drawer.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_redo.png b/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_redo.png deleted file mode 100644 index 71ec893..0000000 Binary files a/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_redo.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_tick.png b/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_tick.png deleted file mode 100644 index c86b376..0000000 Binary files a/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_tick.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_undo.png b/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_undo.png deleted file mode 100644 index bbcbcd1..0000000 Binary files a/Turbo Editor/src/main/res/drawable-xhdpi/ic_action_undo.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-xhdpi/ic_drawer.png b/Turbo Editor/src/main/res/drawable-xhdpi/ic_drawer.png deleted file mode 100644 index b9bc3d7..0000000 Binary files a/Turbo Editor/src/main/res/drawable-xhdpi/ic_drawer.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_redo.png b/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_redo.png deleted file mode 100644 index 2ee0a35..0000000 Binary files a/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_redo.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_tick.png b/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_tick.png deleted file mode 100644 index 37f0cc3..0000000 Binary files a/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_tick.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_undo.png b/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_undo.png deleted file mode 100644 index d7f8781..0000000 Binary files a/Turbo Editor/src/main/res/drawable-xxhdpi/ic_action_undo.png and /dev/null differ diff --git a/Turbo Editor/src/main/res/drawable/holo_selector.xml b/Turbo Editor/src/main/res/drawable/holo_selector.xml deleted file mode 100644 index 1abef56..0000000 --- a/Turbo Editor/src/main/res/drawable/holo_selector.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - diff --git a/Turbo Editor/src/main/res/layout/demo_changelog_fragment_dialogstandard.xml b/Turbo Editor/src/main/res/layout/demo_changelog_fragment_dialogstandard.xml deleted file mode 100644 index 962f085..0000000 --- a/Turbo Editor/src/main/res/layout/demo_changelog_fragment_dialogstandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/Turbo Editor/src/main/res/layout/dialog_fragment_edittext.xml b/Turbo Editor/src/main/res/layout/dialog_fragment_edittext.xml deleted file mode 100644 index 6b02437..0000000 --- a/Turbo Editor/src/main/res/layout/dialog_fragment_edittext.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - -