Commented some parts of the app
This commit is contained in:
parent
41e9161e2b
commit
44773c2f1c
@ -39,7 +39,7 @@
|
||||
android:theme="@style/AppStyle">
|
||||
|
||||
<activity
|
||||
android:name=".HomeActivity"
|
||||
android:name=".activity.HomeActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:windowSoftInputMode="stateHidden|adjustResize"
|
||||
android:hardwareAccelerated="false"
|
||||
@ -72,17 +72,17 @@
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.vmihalachi.turboeditor.PreferenceAbout"
|
||||
android:name=".activity.PreferenceAbout"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/aboutactivity_info_category"/>
|
||||
|
||||
<activity
|
||||
android:name="com.vmihalachi.turboeditor.LicensesActivity"
|
||||
android:name=".activity.LicensesActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/open_source_license"/>
|
||||
|
||||
<activity
|
||||
android:name="com.vmihalachi.turboeditor.SelectFileActivity"
|
||||
android:name=".activity.SelectFileActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/open_a_file"/>
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* along with Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.activity;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
@ -38,10 +38,14 @@ 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;
|
||||
@ -68,12 +72,9 @@ public class HomeActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
//
|
||||
checkTaskRoot();
|
||||
//
|
||||
setContentView(R.layout.activity_home);
|
||||
//
|
||||
setupDrawerLayout();
|
||||
// setup the navigation drawer
|
||||
setupNavigationDrawer();
|
||||
// Replace fragment
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
@ -86,9 +87,9 @@ public class HomeActivity extends Activity {
|
||||
// Set the default title
|
||||
getActionBar().setTitle(getString(R.string.nome_app_turbo_editor));
|
||||
}
|
||||
//
|
||||
receiveIntent();
|
||||
//
|
||||
// parse the intent
|
||||
parseIntent(getIntent());
|
||||
// show a dialog with the changelog
|
||||
showChangeLog();
|
||||
}
|
||||
|
||||
@ -189,6 +190,12 @@ public class HomeActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
parseIntent(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param event
|
||||
@ -243,7 +250,9 @@ public class HomeActivity extends Activity {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* When a file can't be opened
|
||||
* Invoked by the EditorFragment
|
||||
* @param event The event called
|
||||
*/
|
||||
public void onEvent(ErrorOpeningFileEvent event){
|
||||
//
|
||||
@ -273,16 +282,9 @@ public class HomeActivity extends Activity {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Setup the navigation drawer
|
||||
*/
|
||||
private void checkTaskRoot(){
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void setupDrawerLayout(){
|
||||
final String defaultTitle = getString(R.string.nome_app_turbo_editor);
|
||||
private void setupNavigationDrawer(){
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
/* Action Bar */
|
||||
final ActionBar ab = getActionBar();
|
||||
@ -311,41 +313,8 @@ public class HomeActivity extends Activity {
|
||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(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()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void receiveIntent(){
|
||||
// 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) {
|
||||
// Post the NewFileOpened Event
|
||||
EventBus.getDefault().postSticky(new NewFileOpened(intent.getData().getPath()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Show a dialog with the changelog
|
||||
*/
|
||||
private void showChangeLog(){
|
||||
final String currentVersion = AppInfoHelper.getCurrentVersion(this);
|
||||
@ -353,7 +322,23 @@ public class HomeActivity extends Activity {
|
||||
final String lastVersion = preferences.getString("last_version", currentVersion);
|
||||
preferences.edit().putString("last_version", currentVersion).commit();
|
||||
if (!lastVersion.equals(currentVersion)) {
|
||||
DialogStandardFragment.showChangeLogDialog(getFragmentManager());
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
@ -10,6 +10,8 @@ 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{
|
||||
|
||||
/**
|
@ -17,7 +17,7 @@
|
||||
* along with Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@ -25,6 +25,8 @@ 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 {
|
||||
@ -61,7 +63,7 @@ public class PreferenceAbout extends PreferenceActivity {
|
||||
changelog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(final Preference preference) {
|
||||
DialogStandardFragment.showChangeLogDialog(getFragmentManager());
|
||||
ChangelogDialogFragment.showChangeLogDialog(getFragmentManager());
|
||||
return false;
|
||||
}
|
||||
});
|
@ -17,7 +17,7 @@
|
||||
* along with Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
@ -32,6 +32,7 @@ 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.util.AlphanumComparator;
|
||||
|
@ -20,7 +20,6 @@
|
||||
package com.vmihalachi.turboeditor.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -35,63 +34,42 @@ import com.vmihalachi.turboeditor.util.MimeTypes;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
public class AdapterDetailedList extends
|
||||
ArrayAdapter<AdapterDetailedList.FileDetail> {
|
||||
|
||||
// Layout Inflater
|
||||
final LayoutInflater inflater;
|
||||
private final LayoutInflater inflater;
|
||||
|
||||
// The Context to get drawables from resources
|
||||
private final Context context;
|
||||
|
||||
// The list of names
|
||||
final LinkedList<FileDetail> fileDetails;
|
||||
|
||||
// Change HashMap<Integer, Boolean> to SparseBooleanArray
|
||||
private HashMap<String, Boolean> mSelection =
|
||||
new HashMap<String, Boolean>();
|
||||
|
||||
private final int default_text_color;
|
||||
private final int highlight_text_color;
|
||||
// List of file details
|
||||
private final LinkedList<FileDetail> fileDetails;
|
||||
|
||||
public static class ViewHolder {
|
||||
|
||||
// Text view with the name of the file
|
||||
public TextView label;
|
||||
// Name of the file
|
||||
public TextView nameLabel;
|
||||
|
||||
// Text view with the name of the file
|
||||
// Size of the file
|
||||
public TextView sizeLabel;
|
||||
|
||||
// Date of the file
|
||||
public TextView dateLabel;
|
||||
|
||||
// The icon of the file
|
||||
// Icon of the file
|
||||
public ImageView icon;
|
||||
}
|
||||
|
||||
public AdapterDetailedList(final Context context,
|
||||
final LinkedList<FileDetail> fileDetails,
|
||||
final boolean isRoot) {
|
||||
// super
|
||||
super(context,
|
||||
R.layout.item_file_list,
|
||||
fileDetails);
|
||||
this.context = context;
|
||||
super(context, R.layout.item_file_list, fileDetails);
|
||||
this.fileDetails = fileDetails;
|
||||
// Cache the LayoutInflate to avoid asking for a new one each time.
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
this.default_text_color = context.getResources().getColor(android.R.color.primary_text_dark);
|
||||
this.highlight_text_color = context.getResources().getColor(android.R.color.holo_blue_dark);
|
||||
if (!isRoot) {
|
||||
this.fileDetails.addFirst(new FileDetail("..",
|
||||
context.getString(R.string.folder), ""));
|
||||
this.fileDetails.addFirst(new FileDetail("..", context.getString(R.string.folder), ""));
|
||||
} else {
|
||||
this.fileDetails.addFirst(new FileDetail(context.getString(R.string.home),
|
||||
context.getString(R.string.folder),
|
||||
""));
|
||||
this.fileDetails.addFirst(new FileDetail(context.getString(R.string.home), context.getString(R.string.folder), ""));
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +81,7 @@ public class AdapterDetailedList extends
|
||||
.inflate(R.layout.item_file_list,
|
||||
null);
|
||||
final ViewHolder hold = new ViewHolder();
|
||||
hold.label = (TextView) convertView.findViewById(android.R.id.title);
|
||||
hold.nameLabel = (TextView) convertView.findViewById(android.R.id.title);
|
||||
hold.sizeLabel = (TextView) convertView.findViewById(android.R.id.text1);
|
||||
hold.dateLabel = (TextView) convertView.findViewById(android.R.id.text2);
|
||||
hold.icon = (ImageView) convertView.findViewById(android.R.id.icon);
|
||||
@ -111,117 +89,51 @@ public class AdapterDetailedList extends
|
||||
final FileDetail fileDetail = fileDetails.get(position);
|
||||
final String fileName = fileDetail.getName();
|
||||
setIcon(hold, fileDetail);
|
||||
hold.label
|
||||
.setText(fileName);
|
||||
hold.sizeLabel
|
||||
.setText(fileDetail.getSize());
|
||||
hold.dateLabel
|
||||
.setText(fileDetail.getDateModified());
|
||||
if (isPositionChecked(fileName)) {
|
||||
hold.label
|
||||
.setTextColor(this.highlight_text_color);
|
||||
hold.label
|
||||
.setTypeface(null, Typeface.ITALIC);
|
||||
} else {
|
||||
hold.label
|
||||
.setTextColor(this.default_text_color);
|
||||
hold.label
|
||||
.setTypeface(null, Typeface.NORMAL);
|
||||
}
|
||||
hold.nameLabel.setText(fileName);
|
||||
hold.sizeLabel.setText(fileDetail.getSize());
|
||||
hold.dateLabel.setText(fileDetail.getDateModified());
|
||||
} else {
|
||||
final ViewHolder hold = ((ViewHolder) convertView.getTag());
|
||||
final FileDetail fileDetail = fileDetails.get(position);
|
||||
final String fileName = fileDetail.getName();
|
||||
setIcon(hold, fileDetail);
|
||||
hold.label
|
||||
.setText(fileName);
|
||||
hold.sizeLabel
|
||||
.setText(fileDetail.getSize());
|
||||
hold.dateLabel
|
||||
.setText(fileDetail.getDateModified());
|
||||
if (isPositionChecked(fileName)) {
|
||||
hold.label
|
||||
.setTextColor(this.highlight_text_color);
|
||||
hold.label
|
||||
.setTypeface(null, Typeface.ITALIC);
|
||||
} else {
|
||||
hold.label
|
||||
.setTextColor(this.default_text_color);
|
||||
hold.label
|
||||
.setTypeface(null, Typeface.NORMAL);
|
||||
}
|
||||
hold.nameLabel.setText(fileName);
|
||||
hold.sizeLabel.setText(fileDetail.getSize());
|
||||
hold.dateLabel.setText(fileDetail.getDateModified());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private void setIcon(final ViewHolder viewHolder,
|
||||
final FileDetail fileDetail) {
|
||||
private void setIcon(final ViewHolder viewHolder, final FileDetail fileDetail) {
|
||||
final String fileName = fileDetail.getName();
|
||||
final String ext = FilenameUtils.getExtension(fileName);
|
||||
if (fileDetail.isFolder()) {
|
||||
viewHolder.icon
|
||||
.setImageResource(R.color.file_folder);
|
||||
} else if (Arrays.asList(MimeTypes.MIME_HTML)
|
||||
.contains(ext) || ext.endsWith("html")) {
|
||||
viewHolder.icon
|
||||
.setImageResource(R.color.file_html);
|
||||
} else if (Arrays.asList(MimeTypes.MIME_CODE)
|
||||
.contains(ext)
|
||||
viewHolder.icon.setImageResource(R.color.file_folder);
|
||||
}
|
||||
else if (Arrays.asList(MimeTypes.MIME_HTML).contains(ext) || ext.endsWith("html")) {
|
||||
viewHolder.icon.setImageResource(R.color.file_html);
|
||||
}
|
||||
else if (Arrays.asList(MimeTypes.MIME_CODE).contains(ext)
|
||||
|| fileName.endsWith("css")
|
||||
|| fileName.endsWith("js")) {
|
||||
viewHolder.icon
|
||||
.setImageResource(R.color.file_code);
|
||||
} else if (Arrays.asList(MimeTypes.MIME_ARCHIVE).contains(ext)) {
|
||||
viewHolder.icon
|
||||
.setImageResource(R.color.file_archive);
|
||||
} else if (Arrays.asList(MimeTypes.MIME_MUSIC)
|
||||
viewHolder.icon.setImageResource(R.color.file_code);
|
||||
}
|
||||
else if (Arrays.asList(MimeTypes.MIME_ARCHIVE).contains(ext)) {
|
||||
viewHolder.icon.setImageResource(R.color.file_archive);
|
||||
}
|
||||
else if (Arrays.asList(MimeTypes.MIME_MUSIC)
|
||||
.contains(ext)) {
|
||||
viewHolder.icon
|
||||
.setImageResource(R.color.file_media_music);
|
||||
} else if (Arrays.asList(MimeTypes.MIME_PICTURE).contains(ext)) {
|
||||
viewHolder.icon
|
||||
.setImageResource(R.color.file_media_picture);
|
||||
} else if (Arrays.asList(MimeTypes.MIME_VIDEO)
|
||||
.contains(ext)) {
|
||||
viewHolder.icon
|
||||
.setImageResource(R.color.file_media_video);
|
||||
} else {
|
||||
viewHolder.icon
|
||||
.setImageResource(R.color.file_text);
|
||||
viewHolder.icon.setImageResource(R.color.file_media_music);
|
||||
}
|
||||
else if (Arrays.asList(MimeTypes.MIME_PICTURE).contains(ext)) {
|
||||
viewHolder.icon.setImageResource(R.color.file_media_picture);
|
||||
}
|
||||
|
||||
public void checkPosition(final String name) {
|
||||
if (isPositionChecked(name)) {
|
||||
removeSelection(name);
|
||||
} else {
|
||||
setNewSelection(name, true);
|
||||
else if (Arrays.asList(MimeTypes.MIME_VIDEO).contains(ext)) {
|
||||
viewHolder.icon.setImageResource(R.color.file_media_video);
|
||||
}
|
||||
else {
|
||||
viewHolder.icon.setImageResource(R.color.file_text);
|
||||
}
|
||||
|
||||
void setNewSelection(final String name,
|
||||
final boolean value) {
|
||||
this.mSelection.put(name, value);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
boolean isPositionChecked(final String name) {
|
||||
final Boolean result = this.mSelection.get(name);
|
||||
return (result == null) ? false : result;
|
||||
}
|
||||
|
||||
public Set<String> getCurrentCheckedPosition() {
|
||||
return this.mSelection.keySet();
|
||||
}
|
||||
|
||||
private void removeSelection(final String name) {
|
||||
this.mSelection.remove(name);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void clearSelection() {
|
||||
this.mSelection = new HashMap<String, Boolean>();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static class FileDetail {
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.fragment;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
@ -28,16 +28,13 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.vmihalachi.turboeditor.R;
|
||||
|
||||
import it.gmariotti.changelibs.library.view.ChangeLogListView;
|
||||
|
||||
/**
|
||||
* Example with Dialog
|
||||
*
|
||||
* @author Gabriele Mariotti (gabri.mariotti@gmail.com)
|
||||
*/
|
||||
public class DialogStandardFragment extends DialogFragment {
|
||||
public class ChangelogDialogFragment extends DialogFragment {
|
||||
|
||||
public DialogStandardFragment() {
|
||||
public ChangelogDialogFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,13 +67,13 @@ public class DialogStandardFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
public static final void showChangeLogDialog(FragmentManager fragmentManager){
|
||||
DialogStandardFragment dialogStandardFragment = new DialogStandardFragment();
|
||||
ChangelogDialogFragment changelogDialogFragment = new ChangelogDialogFragment();
|
||||
FragmentTransaction ft = fragmentManager.beginTransaction();
|
||||
Fragment prev = fragmentManager.findFragmentByTag("changelogdemo_dialog");
|
||||
if (prev != null) {
|
||||
ft.remove(prev);
|
||||
}
|
||||
ft.addToBackStack(null);
|
||||
dialogStandardFragment.show(ft, "changelogdemo_dialog");
|
||||
changelogDialogFragment.show(ft, "changelogdemo_dialog");
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* along with Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.fragment;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
@ -47,6 +47,7 @@ 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;
|
||||
@ -67,7 +68,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class EditorFragment extends Fragment implements EditTextDialog.EditDialogListener{
|
||||
public class EditorFragment extends Fragment implements EncodingDialogFragment.EditDialogListener {
|
||||
|
||||
private static final String TAG = "A0A";
|
||||
private Editor mEditor;
|
||||
@ -179,7 +180,7 @@ public class EditorFragment extends Fragment implements EditTextDialog.EditDialo
|
||||
}
|
||||
|
||||
private void showEncodingDialog() {
|
||||
EditTextDialog dialogFrag = EditTextDialog.newInstance(this.mCurrentEncoding);
|
||||
EncodingDialogFragment dialogFrag = EncodingDialogFragment.newInstance(this.mCurrentEncoding);
|
||||
dialogFrag.setTargetFragment(this, 0);
|
||||
dialogFrag.show(getFragmentManager().beginTransaction(), "encodingDialog");
|
||||
}
|
||||
@ -188,7 +189,7 @@ public class EditorFragment extends Fragment implements EditTextDialog.EditDialo
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onFinishEditDialog(final String inputText, final EditTextDialog.Actions action, final String hint) {
|
||||
public void onFinishEditDialog(final String inputText, final String hint) {
|
||||
PreferenceHelper.setEncoding(getActivity(), inputText);
|
||||
updateTextEditor();
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* along with Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.fragment;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
@ -32,14 +32,15 @@ import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.vmihalachi.turboeditor.R;
|
||||
|
||||
// ...
|
||||
public class EditTextDialog extends DialogFragment implements TextView.OnEditorActionListener {
|
||||
public class EncodingDialogFragment extends DialogFragment implements TextView.OnEditorActionListener {
|
||||
|
||||
private EditText mEditText;
|
||||
|
||||
public static EditTextDialog newInstance(final String hint) {
|
||||
final EditTextDialog f = new EditTextDialog();
|
||||
|
||||
public static EncodingDialogFragment newInstance(final String hint) {
|
||||
final EncodingDialogFragment f = new EncodingDialogFragment();
|
||||
// Supply num input as an argument.
|
||||
final Bundle args = new Bundle();
|
||||
args.putString("hint", hint);
|
||||
@ -81,8 +82,7 @@ public class EditTextDialog extends DialogFragment implements TextView.OnEditorA
|
||||
if (target == null) {
|
||||
target = (EditDialogListener) getActivity();
|
||||
}
|
||||
target.onFinishEditDialog(this.mEditText.getText().toString(),
|
||||
(Actions) getArguments().getSerializable("action"), getArguments().getString("hint"));
|
||||
target.onFinishEditDialog(this.mEditText.getText().toString(), getArguments().getString("hint"));
|
||||
this.dismiss();
|
||||
}
|
||||
|
||||
@ -95,12 +95,8 @@ public class EditTextDialog extends DialogFragment implements TextView.OnEditorA
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum Actions {
|
||||
NewRemoteFolder, NewRemoteFile, NewLocalFolder, Rename, Move, EditEncoding
|
||||
}
|
||||
|
||||
public interface EditDialogListener {
|
||||
void onFinishEditDialog(String inputText, Actions action, String hint);
|
||||
void onFinishEditDialog(String inputText, String hint);
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,10 @@
|
||||
* along with Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.fragment;
|
||||
|
||||
import android.app.ListFragment;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.ActionMode;
|
||||
import android.view.LayoutInflater;
|
||||
@ -35,8 +33,10 @@ 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;
|
||||
|
||||
@ -48,15 +48,15 @@ import de.greenrobot.event.EventBus;
|
||||
|
||||
public class NavigationDrawerListFragment extends ListFragment implements AbsListView.MultiChoiceModeListener {
|
||||
|
||||
List<String> fileNames;
|
||||
ArrayAdapter<String> arrayAdapter;
|
||||
private List<String> fileNames;
|
||||
private ArrayAdapter<String> arrayAdapter;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// Out custom layout
|
||||
// Our custom layout
|
||||
View rootView = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
|
||||
return rootView;
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class NavigationDrawerListFragment extends ListFragment implements AbsLis
|
||||
super.onResume();
|
||||
// Register the Event Bus for events
|
||||
EventBus.getDefault().registerSticky(this);
|
||||
//
|
||||
// Refresh the list view
|
||||
refreshList();
|
||||
}
|
||||
|
||||
@ -98,14 +98,8 @@ public class NavigationDrawerListFragment extends ListFragment implements AbsLis
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
// don't open the same file twice
|
||||
//if(this.mCurrentCheckedPosition == position) return;
|
||||
// set current checked position
|
||||
//this.mCurrentCheckedPosition = position;
|
||||
// Shared Preferences
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
// File paths saved in preferences
|
||||
String[] savedPaths = sharedPreferences.getString("savedPaths", "").split(",");
|
||||
String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity());
|
||||
// Path of the file selected
|
||||
String filePath = savedPaths[position];
|
||||
// Send the event that a file was selected
|
||||
@ -144,21 +138,23 @@ public class NavigationDrawerListFragment extends ListFragment implements AbsLis
|
||||
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.im_remove:
|
||||
// Shared Preferences
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
// File paths saved in preferences
|
||||
String[] savedPaths = sharedPreferences.getString("savedPaths", "").split(",");
|
||||
//
|
||||
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:
|
||||
@ -182,66 +178,54 @@ public class NavigationDrawerListFragment extends ListFragment implements AbsLis
|
||||
*/
|
||||
public void onEvent(NewFileOpened event){
|
||||
EventBus.getDefault().removeStickyEvent(event);
|
||||
// Shared Preferences
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
// File paths saved in preferences
|
||||
String[] savedPaths = sharedPreferences.getString("savedPaths", "").split(",");
|
||||
|
||||
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 refresh){
|
||||
// Shared Preferences
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
// Editor
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
private void addPath(String path, boolean refreshTheList){
|
||||
// File paths saved in preferences
|
||||
String[] savedPaths = sharedPreferences.getString("savedPaths", "").split(",");
|
||||
String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity());
|
||||
// StringBuilder
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// for cycle
|
||||
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
|
||||
editor.putString("savedPaths", sb.toString());
|
||||
// Commit
|
||||
editor.commit();
|
||||
// Put the string and commit
|
||||
PreferenceHelper.setSavedPaths(getActivity(), sb);
|
||||
// Update list
|
||||
//arrayAdapter.add(FilenameUtils.getName(path));
|
||||
//arrayAdapter.notifyDataSetChanged();
|
||||
if(refresh){
|
||||
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){
|
||||
// Shared Preferences
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
// Editor
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
// File paths saved in preferences
|
||||
String[] savedPaths = sharedPreferences.getString("savedPaths", "").split(",");
|
||||
String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity());
|
||||
// StringBuilder
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// for cycle
|
||||
@ -249,40 +233,32 @@ public class NavigationDrawerListFragment extends ListFragment implements AbsLis
|
||||
if(path.equals(savedPaths[count])) continue;
|
||||
sb.append(savedPaths[count]).append(",");
|
||||
}
|
||||
// Put the string
|
||||
editor.putString("savedPaths", sb.toString());
|
||||
// Commit
|
||||
editor.commit();
|
||||
// Put the string and commit
|
||||
PreferenceHelper.setSavedPaths(getActivity(), sb);
|
||||
// Update list
|
||||
//arrayAdapter.remove(FilenameUtils.getName(path));
|
||||
//arrayAdapter.notifyDataSetChanged();
|
||||
if(refresh){
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ void refreshList(){
|
||||
// Shared Preferences
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
private void refreshList(){
|
||||
// File paths saved in preferences
|
||||
String[] savedPaths = sharedPreferences.getString("savedPaths", "").split(",");
|
||||
String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity());
|
||||
// File names for the list
|
||||
fileNames = new ArrayList<String>(savedPaths.length);
|
||||
//
|
||||
// StringBuilder that will contain the file paths
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// for cycle to convert paths to names
|
||||
for(String path : savedPaths){
|
||||
|
||||
if(!path.isEmpty()){
|
||||
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
|
||||
sharedPreferences.edit().putString("savedPaths", sb.toString()).commit();
|
||||
PreferenceHelper.setSavedPaths(getActivity(), sb);
|
||||
// Adapter
|
||||
arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.item_drawer_list, fileNames);
|
||||
// Set adapter
|
@ -17,7 +17,7 @@
|
||||
* along with Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.vmihalachi.turboeditor;
|
||||
package com.vmihalachi.turboeditor.fragment;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
@ -25,6 +25,8 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.vmihalachi.turboeditor.R;
|
||||
|
||||
/**
|
||||
* Created by Vlad on 9/23/13.
|
||||
*/
|
@ -28,9 +28,8 @@ public final class PreferenceHelper {
|
||||
private PreferenceHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter Methods
|
||||
*/
|
||||
// Getter Methods
|
||||
|
||||
public static SharedPreferences getPrefs(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
@ -50,9 +49,12 @@ public final class PreferenceHelper {
|
||||
public static String getEncoding(Context context) {
|
||||
return getPrefs(context).getString("editor_encoding", "UTF-8");
|
||||
}
|
||||
/**
|
||||
* Setter Methods
|
||||
*/
|
||||
|
||||
public static String[] getSavedPaths(Context context) {
|
||||
return getPrefs(context).getString("savedPaths", "").split(",");
|
||||
}
|
||||
|
||||
// Setter methods
|
||||
|
||||
public static void setWrapText(Context context, boolean value) {
|
||||
getEditor(context).putBoolean("editor_wrap_text", value).commit();
|
||||
@ -65,4 +67,8 @@ public final class PreferenceHelper {
|
||||
public static void setEncoding(Context context, String value) {
|
||||
getEditor(context).putString("editor_encoding", value).commit();
|
||||
}
|
||||
|
||||
public static void setSavedPaths(Context context, StringBuilder stringBuilder) {
|
||||
getEditor(context).putString("savedPaths", stringBuilder.toString()).commit();
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,3 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Vlad Mihalachi
|
||||
*
|
||||
* This file is part of Turbo Editor.
|
||||
*
|
||||
* Turbo Editor is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Turbo Editor is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Turbo Editor. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.vmihalachi.turboeditor.util;/*
|
||||
* The Alphanum Algorithm is an improved sorting algorithm for strings
|
||||
* containing numbers. Instead of sorting numbers in ASCII order like
|
||||
|
@ -21,126 +21,24 @@ package com.vmihalachi.turboeditor.util;
|
||||
|
||||
public class MimeTypes {
|
||||
public static final String[] MIME_TEXT = {
|
||||
"ajx",
|
||||
"am",
|
||||
"asa",
|
||||
"asc",
|
||||
"asp",
|
||||
"aspx",
|
||||
"awk",
|
||||
"bat",
|
||||
"c",
|
||||
"cdf",
|
||||
"cf",
|
||||
"cfg",
|
||||
"cfm",
|
||||
"cgi",
|
||||
"cnf",
|
||||
"conf",
|
||||
"cpp",
|
||||
"css",
|
||||
"csv",
|
||||
"ctl",
|
||||
"dat",
|
||||
"dhtml",
|
||||
"diz",
|
||||
"file",
|
||||
"forward",
|
||||
"grp",
|
||||
"h",
|
||||
"hpp",
|
||||
"hqx",
|
||||
"hta",
|
||||
"htaccess",
|
||||
"htc",
|
||||
"htm",
|
||||
"html",
|
||||
"htpasswd",
|
||||
"htt",
|
||||
"htx",
|
||||
"in",
|
||||
"inc",
|
||||
"info",
|
||||
"ini",
|
||||
"ink",
|
||||
"java",
|
||||
"js",
|
||||
"jsp",
|
||||
"key",
|
||||
"log",
|
||||
"logfile",
|
||||
"m3u",
|
||||
"m4",
|
||||
"m4a",
|
||||
"mak",
|
||||
"map",
|
||||
"model",
|
||||
"msg",
|
||||
"nfo",
|
||||
"nsi",
|
||||
"info",
|
||||
"old",
|
||||
"pas",
|
||||
"patch",
|
||||
"perl",
|
||||
"php",
|
||||
"php2",
|
||||
"php3",
|
||||
"php4",
|
||||
"php5",
|
||||
"php6",
|
||||
"phtml",
|
||||
"pix",
|
||||
"pl",
|
||||
"pm",
|
||||
"po",
|
||||
"pwd",
|
||||
"py",
|
||||
"qmail",
|
||||
"rb",
|
||||
"rbl",
|
||||
"rbw",
|
||||
"readme",
|
||||
"reg",
|
||||
"rss",
|
||||
"rtf",
|
||||
"ruby",
|
||||
"session",
|
||||
"setup",
|
||||
"sh",
|
||||
"shtm",
|
||||
"shtml",
|
||||
"sql",
|
||||
"ssh",
|
||||
"stm",
|
||||
"style",
|
||||
"svg",
|
||||
"tcl",
|
||||
"text",
|
||||
"threads",
|
||||
"tmpl",
|
||||
"tpl",
|
||||
"txt",
|
||||
"ubb",
|
||||
"vbs",
|
||||
"xhtml",
|
||||
"xml",
|
||||
"xrc",
|
||||
"xsl"};
|
||||
public static final String[] MIME_CODE =
|
||||
{"xml", "php", "asp", "json", "wiki"};
|
||||
public static final String[] MIME_HTML =
|
||||
{"htm"};
|
||||
public static final String[] MIME_PICTURE = {
|
||||
"png", "jpeg", "jpg", "ico", "gif", "bmp",
|
||||
"tiff"
|
||||
"ajx","am","asa","asc","asp","aspx","awk","bat","c","cdf","cf","cfg","cfm","cgi","cnf","conf","cpp","css","csv","ctl","dat","dhtml","diz","file","forward","grp","h","hpp","hqx","hta","htaccess","htc","htm","html","htpasswd","htt","htx","in","inc","info","ini","ink","java","js","jsp","key","log","logfile","m3u","m4","m4a","mak","map","model","msg","nfo","nsi","info","old","pas","patch","perl","php","php2","php3","php4","php5","php6","phtml","pix","pl","pm","po","pwd","py","qmail","rb","rbl","rbw","readme","reg","rss","rtf","ruby","session","setup","sh","shtm","shtml","sql","ssh","stm","style","svg","tcl","text","threads","tmpl","tpl","txt","ubb","vbs","xhtml","xml","xrc","xsl"
|
||||
};
|
||||
public static final String[] MIME_CODE = {
|
||||
"xml", "php", "asp", "json", "wiki"
|
||||
};
|
||||
public static final String[] MIME_HTML = {
|
||||
"htm"
|
||||
};
|
||||
public static final String[] MIME_PICTURE = {
|
||||
"png", "jpeg", "jpg", "ico", "gif", "bmp","tiff"
|
||||
};
|
||||
public static final String[] MIME_MUSIC = {
|
||||
"mp3", "avi", "flac", "mpga"
|
||||
};
|
||||
public static final String[] MIME_VIDEO = {
|
||||
"mp4", "mkv", "wmw"
|
||||
};
|
||||
public static final String[] MIME_MUSIC =
|
||||
{"mp3", "avi", "flac", "mpga"};
|
||||
public static final String[] MIME_VIDEO =
|
||||
{"mp4", "mkv", "wmw"};
|
||||
public static final String[] MIME_ARCHIVE = {
|
||||
"zip", "tar", "gz", "bz2", "rar", "7z"
|
||||
};
|
||||
public static String[] USER_MIME_TEXT;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
<fragment android:layout_width="@dimen/navigation_drawer_width"
|
||||
android:layout_height="match_parent"
|
||||
android:name="com.vmihalachi.turboeditor.NavigationDrawerListFragment"
|
||||
android:name="com.vmihalachi.turboeditor.fragment.NavigationDrawerListFragment"
|
||||
android:id="@id/drawer_list"
|
||||
android:layout_gravity="left"/>
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
android:fillViewport="true">
|
||||
|
||||
<view
|
||||
class="com.vmihalachi.turboeditor.EditorFragment$Editor"
|
||||
class="com.vmihalachi.turboeditor.fragment.EditorFragment$Editor"
|
||||
android:id="@id/editor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user