Skip to content

Commit 245fd70

Browse files
committed
very basic open file
0 parents  commit 245fd70

21 files changed

+342
-0
lines changed

app/build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.3"
6+
defaultConfig {
7+
applicationId "enotes.encryptednotepad"
8+
minSdkVersion 19
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.+'
28+
compile 'com.android.support:design:25.+'
29+
testCompile 'junit:junit:4.12'
30+
}

app/src/main/AndroidManifest.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="enotes.encryptednotepad">
4+
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
7+
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
8+
9+
<application
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity
15+
android:name=".EditNoteActivity"
16+
android:label="@string/app_name"
17+
android:theme="@style/AppTheme.NoActionBar">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
<intent-filter>
23+
<action android:name="android.intent.action.VIEW" />
24+
<category android:name="android.intent.category.DEFAULT" />
25+
<category android:name="android.intent.category.BROWSABLE" />
26+
<data android:scheme="file" android:mimeType="application/*" android:pathPattern=".*\\.etxt" android:host="*" />
27+
<data android:scheme="content" android:mimeType="application/*" android:pathPattern=".*\\.etxt" android:host="*" />
28+
</intent-filter>
29+
</activity>
30+
</application>
31+
32+
</manifest>

app/src/main/ic_launcher-web.png

5.15 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package enotes.encryptednotepad;
2+
3+
import android.app.Activity;
4+
import android.app.AlertDialog;
5+
import android.content.DialogInterface;
6+
import android.content.Intent;
7+
import android.net.Uri;
8+
import android.os.Bundle;
9+
import android.support.design.widget.FloatingActionButton;
10+
import android.support.design.widget.Snackbar;
11+
import android.support.v7.app.AppCompatActivity;
12+
import android.support.v7.widget.Toolbar;
13+
import android.text.InputType;
14+
import android.util.Log;
15+
import android.view.Menu;
16+
import android.view.MenuItem;
17+
import android.view.View;
18+
import android.widget.EditText;
19+
import enotes.doc.Doc;
20+
import enotes.doc.DocException;
21+
import enotes.doc.DocPasswordException;
22+
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
26+
public class EditNoteActivity extends AppCompatActivity {
27+
28+
private static final int ID_OPEN_NOTE = 1872;
29+
30+
private EditText editText;
31+
32+
@Override
33+
protected void onCreate(Bundle savedInstanceState) {
34+
super.onCreate(savedInstanceState);
35+
setContentView(R.layout.activity_edit_note);
36+
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
37+
setSupportActionBar(toolbar);
38+
39+
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
40+
fab.setOnClickListener(new View.OnClickListener() {
41+
@Override
42+
public void onClick(View view) {
43+
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
44+
.setAction("Action", null).show();
45+
}
46+
});
47+
editText = (EditText) findViewById(R.id.editText);
48+
Intent intent = getIntent();
49+
if (intent != null && intent.getAction().equals(Intent.ACTION_VIEW)) {
50+
openNote(intent.getData());
51+
}
52+
}
53+
54+
@Override
55+
public boolean onCreateOptionsMenu(Menu menu) {
56+
getMenuInflater().inflate(R.menu.menu_edit_note, menu);
57+
return super.onCreateOptionsMenu(menu);
58+
}
59+
60+
@Override
61+
public boolean onOptionsItemSelected(MenuItem item) {
62+
int id = item.getItemId();
63+
if (id == R.id.action_open) {
64+
chooseDocument();
65+
return true;
66+
}
67+
return super.onOptionsItemSelected(item);
68+
}
69+
70+
private void chooseDocument() {
71+
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
72+
intent.addCategory(Intent.CATEGORY_OPENABLE);
73+
intent.setType("application/*");
74+
startActivityForResult(intent, ID_OPEN_NOTE);
75+
}
76+
77+
@Override
78+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
79+
if (requestCode == ID_OPEN_NOTE && resultCode == Activity.RESULT_OK) {
80+
if (data != null) {
81+
Uri uri = data.getData();
82+
openNote(uri);
83+
}
84+
}
85+
super.onActivityResult(requestCode, resultCode, data);
86+
}
87+
88+
private void openNote(final Uri uri) {
89+
AlertDialog.Builder pwDialog = new AlertDialog.Builder(this);
90+
final EditText edit = new EditText(this);
91+
edit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
92+
pwDialog.setView(edit);
93+
pwDialog.setTitle("Enter password:");
94+
pwDialog.setCancelable(true);
95+
pwDialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
96+
@Override
97+
public void onClick(DialogInterface dialog, int i) {
98+
String pwd = edit.getText().toString();
99+
if (pwd != null && !pwd.isEmpty()) {
100+
try (InputStream inputStream = getContentResolver().openInputStream(uri)) {
101+
Doc doc = Doc.open(inputStream, pwd);
102+
editText.setText(doc.getText());
103+
dialog.dismiss();
104+
} catch (DocPasswordException ignored) {
105+
// edit.setText(""); - the dialog is being dismissed anyway
106+
} catch (IOException | DocException e) {
107+
Log.e("ENOTES", e.getMessage(), e);
108+
dialog.dismiss();
109+
}
110+
}
111+
}
112+
});
113+
pwDialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
114+
@Override
115+
public void onClick(DialogInterface dialog, int i) {
116+
dialog.cancel();
117+
}
118+
});
119+
pwDialog.show();
120+
}
121+
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:fitsSystemWindows="true"
8+
tools:context="enotes.encryptednotepad.EditNoteActivity">
9+
10+
<android.support.design.widget.AppBarLayout
11+
android:layout_height="wrap_content"
12+
android:layout_width="match_parent"
13+
android:theme="@style/AppTheme.AppBarOverlay">
14+
15+
<android.support.v7.widget.Toolbar
16+
android:id="@+id/toolbar"
17+
android:layout_width="match_parent"
18+
android:layout_height="?attr/actionBarSize"
19+
android:background="?attr/colorPrimary"
20+
app:popupTheme="@style/AppTheme.PopupOverlay" />
21+
22+
</android.support.design.widget.AppBarLayout>
23+
24+
<include layout="@layout/content_edit_note" />
25+
26+
<android.support.design.widget.FloatingActionButton
27+
android:id="@+id/fab"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:layout_gravity="bottom|end"
31+
android:layout_margin="@dimen/fab_margin"
32+
app:srcCompat="@android:drawable/ic_dialog_email" />
33+
34+
</android.support.design.widget.CoordinatorLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:id="@+id/content_edit_note"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
android:paddingLeft="@dimen/activity_horizontal_margin"
9+
android:paddingRight="@dimen/activity_horizontal_margin"
10+
android:paddingTop="@dimen/activity_vertical_margin"
11+
android:paddingBottom="@dimen/activity_vertical_margin"
12+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
13+
tools:showIn="@layout/activity_edit_note"
14+
tools:context="enotes.encryptednotepad.EditNoteActivity"
15+
android:focusableInTouchMode="true" >
16+
17+
<ScrollView
18+
android:id="@+id/SCROLLER_ID"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:layout_alignParentTop="true"
22+
android:layout_alignParentStart="true"
23+
android:scrollbars="vertical"
24+
android:fillViewport="true">
25+
<EditText
26+
android:id="@+id/editText"
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content"
29+
android:inputType="textMultiLine"
30+
android:ems="10"
31+
android:background="@android:color/transparent"
32+
android:fontFamily="serif-monospace"
33+
android:scrollHorizontally="true"
34+
android:gravity="top"
35+
android:scrollbars="vertical|horizontal"
36+
/>
37+
</ScrollView>
38+
</RelativeLayout>
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item android:title="@string/menu_item_open"
5+
android:id="@+id/action_open" />
6+
<item android:title="@string/menu_item_save" />
7+
</menu>
857 Bytes
Loading
537 Bytes
Loading
1.12 KB
Loading
1.65 KB
Loading
1.88 KB
Loading
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<resources>
2+
3+
<style name="AppTheme.NoActionBar">
4+
<item name="windowActionBar">false</item>
5+
<item name="windowNoTitle">true</item>
6+
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
7+
<item name="android:statusBarColor">@android:color/transparent</item>
8+
</style>
9+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
3+
(such as screen margins) for screens with more than 820dp of available width. This
4+
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
5+
<dimen name="activity_horizontal_margin">64dp</dimen>
6+
</resources>

app/src/main/res/values/colors.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#9E9E9E</color>
4+
<color name="colorPrimaryDark">#706363</color>
5+
<color name="colorAccent">#823934</color>
6+
</resources>

app/src/main/res/values/dimens.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<!-- Default screen margins, per the Android Design guidelines. -->
3+
<dimen name="activity_horizontal_margin">16dp</dimen>
4+
<dimen name="activity_vertical_margin">16dp</dimen>
5+
<dimen name="fab_margin">16dp</dimen>
6+
</resources>

app/src/main/res/values/ids.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<item name="action_open" type="id">action_open</item>
4+
</resources>

app/src/main/res/values/strings.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
<string name="app_name">Encrypted Notepad</string>
3+
<string name="menu_item_open">Open</string>
4+
<string name="menu_item_save">Save</string>
5+
</resources>

app/src/main/res/values/styles.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5+
<item name="colorPrimary">@color/colorPrimary</item>
6+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
7+
<item name="colorAccent">@color/colorAccent</item>
8+
</style>
9+
10+
<style name="AppTheme.NoActionBar">
11+
<item name="windowActionBar">false</item>
12+
<item name="windowNoTitle">true</item>
13+
</style>
14+
15+
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
16+
17+
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
18+
19+
</resources>

build.gradle

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:2.2.2'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
jcenter()
18+
}
19+
}
20+
21+
task clean(type: Delete) {
22+
delete rootProject.buildDir
23+
}

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ':app'

0 commit comments

Comments
 (0)