Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "info.aario.snotepad"
minSdkVersion 15
targetSdkVersion 25
targetSdkVersion 27
versionCode 2
versionName "1.2.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -23,9 +23,9 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:design:27.1.1'
testCompile 'junit:junit:4.12'
compile 'com.nononsenseapps:filepicker:4.0.0'
}
13 changes: 12 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,27 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>

<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:label="@string/app_name"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".SettingsActivity"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".AboutActivity"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package info.aario.snotepad;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.TextView;

import com.nononsenseapps.filepicker.FilePickerActivity;
Expand All @@ -21,44 +25,41 @@
* Created by aario on 3/16/17.
*/

public class AboutFragment extends Fragment {
private MainActivity activity;
public class AboutActivity extends Activity {
// private MainActivity activity;
private TextView tvAbout;
private static final int FILE_CODE = 1;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
activity = (MainActivity) getActivity();
View view = inflater.inflate(R.layout.about_fragment, container, false);
tvAbout = (TextView) view.findViewById(R.id.tvAbout);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
tvAbout = (TextView) findViewById(R.id.tvAbout);
String aboutHtml = getResources().getString(R.string.tvAbout_text);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
tvAbout.setText(Html.fromHtml(aboutHtml, Html.FROM_HTML_MODE_COMPACT));
} else {
tvAbout.setText(Html.fromHtml(aboutHtml));
}

TextView tvVersion = (TextView) view.findViewById(R.id.tvVersion);
TextView tvVersion = (TextView) findViewById(R.id.tvVersion);
try {
tvVersion.setText(tvVersion.getText() + activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName);
tvVersion.setText(tvVersion.getText() + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
} catch (PackageManager.NameNotFoundException e) {
tvVersion.setVisibility(View.INVISIBLE);
}

FloatingActionButton fab = (FloatingActionButton) activity.findViewById(R.id.fab);
fab.setImageDrawable(ContextCompat.getDrawable(activity, android.R.drawable.ic_dialog_info));
fab.setOnClickListener(new View.OnClickListener() {
Button bt_donate = (Button) findViewById(R.id.bt_donate);
bt_donate.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(getResources().getString(R.string.donate_url)));
startActivity(i);
}
});

return view;
}

}
95 changes: 74 additions & 21 deletions app/src/main/java/info/aario/snotepad/EditorFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
Expand All @@ -22,6 +28,7 @@
public class EditorFragment extends Fragment {
private MainActivity activity;
private String name;
private View view;
private EditText etEditor;
private EditText etTitle;
private String path;
Expand All @@ -32,20 +39,30 @@ public class EditorFragment extends Fragment {
private Button btRedo;
private Button btSave;
private Button btShare;
private long tLastEdit;
private String previousText;
private int undoHistoryCursor = 0;
TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (System.currentTimeMillis() - tLastEdit > 1000 ||
Math.abs(etEditor.getText().length() - textUndoHistory.get(undoHistoryCursor).toString().length()) > 8 ) {
saveUndoRedo();
}
previousText = new String(charSequence.toString());
}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
saveUndoRedo();
tLastEdit = System.currentTimeMillis();
// activity.toast(lastChar(previousText,charSequence.toString()) + "");
if (lastChar(previousText, charSequence.toString()) == ' ') saveUndoRedo();
}

@Override
public void afterTextChanged(Editable editable) {
activity.editor_modified = true;
save();
}
};

Expand Down Expand Up @@ -80,14 +97,57 @@ private void updateUndoRedoButtons() {
btRedo.setEnabled(textUndoHistory.size() > 0 && undoHistoryCursor < textUndoHistory.size() - 1);
}

public char lastChar(String oldStr, String newStr){
String shorter, longer;
// Log.d("string",oldStr+"");
// Log.d("string",newStr+"");

//find which string is shorter so that we don't end up out of bounds
if (oldStr.length()<newStr.length() ) {
shorter = oldStr;
longer = newStr;
} else {
shorter = newStr;
longer = oldStr;
}

//find the first character that is different and return it
for (int i = 0; i < shorter.length(); i++) {
if (longer.charAt(i) != shorter.charAt(i)) return longer.charAt(i);
}

//if no characters are different then return the last char of the longer string
//this means that the undo will be saved if the last char the user erased is a space
Log.d("longer",longer);
return(longer.charAt(longer.length()-1));
}

public void onPrepareOptionsMenu(Menu menu) {
if (menu != null) {
menu.findItem(R.id.action_refresh).setVisible(false);
menu.findItem(R.id.action_sort_by_name).setVisible(false);
menu.findItem(R.id.action_sort_by_date).setVisible(false);
activity.invalidateOptionsMenu();
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
activity = (MainActivity) getActivity();
View view = inflater.inflate(R.layout.editor_fragment, container, false);
FloatingActionButton fab = (FloatingActionButton) activity.findViewById(R.id.fab);
fab.setVisibility(View.INVISIBLE);
view = inflater.inflate(R.layout.editor_fragment, container, false);

Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);

//Set global action bar to this fragment's actions
AppCompatActivity rootActivity = (AppCompatActivity) getActivity();
rootActivity.setSupportActionBar(toolbar);
rootActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
rootActivity.getSupportActionBar().setDisplayShowTitleEnabled(false);

setHasOptionsMenu(true);

etTitle = (EditText) view.findViewById(R.id.etTitle);
path = activity.getOpenedFilePath();
name = activity.filer.getFileNameWithoutExtension(path);
Expand All @@ -96,13 +156,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
if (activity.filer.exists(path))
etEditor.setText(activity.filer.getStringFromFile(path));
etEditor.addTextChangedListener(textWatcher);

textUndoHistory.clear();
selectionStartUndoHistory.clear();
selectionEndUndoHistory.clear();
btUndo = (Button) view.findViewById(R.id.btUndo);
View rootView = view.getRootView();
btUndo = (Button) rootView.findViewById(R.id.btUndo);
btUndo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//due to grouping the last few keystrokes might not have been saved
//save them now except if we are in the middle of an undo streak
//(we don't want to reset the undo stack on every undo)
if (undoHistoryCursor == textUndoHistory.size() - 1) saveUndoRedo();
undoHistoryCursor--;
retrieveUndoRedo();
}
Expand All @@ -115,21 +181,9 @@ public void onClick(View view) {
retrieveUndoRedo();
}
});
tLastEdit = System.currentTimeMillis();
saveUndoRedo();
btSave = (Button) view.findViewById(R.id.btSave);
btSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
save();
}
});
btShare = (Button) view.findViewById(R.id.btShare);
btShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
share();
}
});
previousText = (String)etEditor.getText().toString();
return view;
}

Expand All @@ -147,7 +201,6 @@ public void save() {
}

if (activity.filer.writeToFile(path, getEditorText())) {
activity.makeSnackBar("Changes saved to " + path);
if (rename)
activity.filer.delete(oldPath);
activity.editor_modified = false;
Expand Down
Loading