diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 87e1565..9976b68 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,24 +2,28 @@
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/zadanie1/mw/FirstPassword.java b/app/src/main/java/com/zadanie1/mw/FirstPassword.java
new file mode 100644
index 0000000..f3b1627
--- /dev/null
+++ b/app/src/main/java/com/zadanie1/mw/FirstPassword.java
@@ -0,0 +1,73 @@
+package com.zadanie1.mw;
+
+ import android.content.Intent;
+ import android.os.Bundle;
+ import android.app.Activity;
+ import android.view.View;
+ import android.widget.Button;
+ import android.widget.EditText;
+ import android.widget.TextView;
+ import android.widget.Toast;
+
+ import java.io.FileNotFoundException;
+ import java.io.FileOutputStream;
+ import java.io.IOException;
+ import java.io.PrintWriter;
+
+public class FirstPassword extends Activity {
+ private static final String FILE_NAME = "passwd.txt";
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_first_password);
+
+ final EditText newpassword;
+ final EditText renewpassword;
+ Button confirm;
+
+ newpassword = (EditText) findViewById(R.id.newpassword);
+ renewpassword = (EditText) findViewById(R.id.renewpassword);
+ confirm = (Button) findViewById(R.id.button);
+
+ confirm.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View arg0) {
+ if (newpassword.getText().toString().equals(renewpassword.getText().toString())) {
+
+ String text = newpassword.getText().toString();
+ FileOutputStream fos = null;
+
+ Toast toast = Toast.makeText(getApplicationContext(),
+ "Password has been changed",
+ Toast.LENGTH_SHORT);
+ toast.show();
+
+ try {
+ fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
+ fos.write(text.getBytes());
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ onBackPressed();
+ }
+ else
+ {
+ Toast toast = Toast.makeText(getApplicationContext(),
+ "Password has NOT been changed",
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/zadanie1/mw/FormPassword.java b/app/src/main/java/com/zadanie1/mw/FormPassword.java
index cf7aff9..29d0596 100644
--- a/app/src/main/java/com/zadanie1/mw/FormPassword.java
+++ b/app/src/main/java/com/zadanie1/mw/FormPassword.java
@@ -9,64 +9,106 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
public class FormPassword extends Activity {
private static final String FILE_NAME = "passwd.txt";
+
+
+ public String readFile(String filename) throws IOException {
+ String content = null;
+ File file = new File(filename); // For example, foo.txt
+ FileReader reader = null;
+ try {
+ reader = new FileReader(file);
+ char[] chars = new char[(int) file.length()];
+ reader.read(chars);
+ content = new String(chars);
+ reader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ return content;
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
+
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form_password);
+ final EditText currentpassword;
final EditText newpassword;
final EditText renewpassword;
Button confirm;
+ currentpassword = (EditText) findViewById(R.id.currentpassword);
newpassword = (EditText) findViewById(R.id.newpassword);
renewpassword = (EditText) findViewById(R.id.renewpassword);
confirm = (Button) findViewById(R.id.button);
confirm.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
- if (newpassword.getText().toString().equals(renewpassword.getText().toString())) {
+ final String filename = getFilesDir() + "/passwd.txt";
+ File file = new File(filename);
- String text = newpassword.getText().toString();
- FileOutputStream fos = null;
+ try {
+ if (currentpassword.getText().toString().equals(readFile(filename).toString())) {
+ if (newpassword.getText().toString().equals(renewpassword.getText().toString())) {
- Toast toast = Toast.makeText(getApplicationContext(),
- "Password has been changed",
- Toast.LENGTH_SHORT);
- toast.show();
+ String text = newpassword.getText().toString();
+ FileOutputStream fos = null;
- try {
- fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
- fos.write(text.getBytes());
+ Toast toast = Toast.makeText(getApplicationContext(),
+ "Password has been changed",
+ Toast.LENGTH_SHORT);
+ toast.show();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (fos != null) {
try {
- fos.close();
+ fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
+ fos.write(text.getBytes());
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
+ onBackPressed();
+ } else {
+ Toast toast = Toast.makeText(getApplicationContext(),
+ "Password has NOT been changed!",
+ Toast.LENGTH_SHORT);
+ toast.show();
}
- }
- onBackPressed();
- }
- else
- {
+ } else {
Toast toast = Toast.makeText(getApplicationContext(),
- "Password has NOT been changed",
+ "Current password is WRONG!",
Toast.LENGTH_SHORT);
toast.show();
}
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ currentpassword.getText().clear();
+ newpassword.getText().clear();
+ renewpassword.getText().clear();
}
});
}
diff --git a/app/src/main/java/com/zadanie1/mw/MainActivity.java b/app/src/main/java/com/zadanie1/mw/MainActivity.java
index 8651d12..2434410 100644
--- a/app/src/main/java/com/zadanie1/mw/MainActivity.java
+++ b/app/src/main/java/com/zadanie1/mw/MainActivity.java
@@ -45,12 +45,25 @@ public class MainActivity extends AppCompatActivity {
return content;
}
+ private boolean isFileExists(File file) {
+ return file.exists() && !file.isDirectory();
+
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+ final String filename = getFilesDir() + "/passwd.txt";
+ File file = new File(filename);
+
+ if (!isFileExists(file)){
+ Intent myIntent3 = new Intent(MainActivity.this,
+ FirstPassword.class);
+ startActivity(myIntent3);
+ }
+
response = (TextView) findViewById(R.id.textView);
button = (Button) findViewById(R.id.button);
restartpassword = (Button) findViewById(R.id.restartpassword);
@@ -68,11 +81,6 @@ public class MainActivity extends AppCompatActivity {
button.setOnClickListener(new OnClickListener() {
private final String filename = getFilesDir() + "/passwd.txt";
- private boolean isFileExists(File file) {
- return file.exists() && !file.isDirectory();
-
- }
-
@Override
public void onClick(View view) {
/*response.setText(textPassword.getText());*/
@@ -90,22 +98,24 @@ public class MainActivity extends AppCompatActivity {
Noto.class);
startActivity(myIntent2);
- }
- } else if (textPassword.getText().toString().equals("FirstPassword!")) {
- Intent myIntent2 = new Intent(MainActivity.this,
- Noto.class);
- startActivity(myIntent2);
- } else {
- Toast toast = Toast.makeText(getApplicationContext(),
- "Password is NOT correct",
- Toast.LENGTH_SHORT);
- toast.show();
+ } else {
+ Toast toast = Toast.makeText(getApplicationContext(),
+ "Password is NOT correct",
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ } else {
+ Intent myIntent3 = new Intent(MainActivity.this,
+ FirstPassword.class);
+ startActivity(myIntent3);
}
} catch(IOException e){
e.printStackTrace();
}
+ textPassword.getText().clear();
}
});
+
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/zadanie1/mw/SplashActivity.java b/app/src/main/java/com/zadanie1/mw/SplashActivity.java
new file mode 100644
index 0000000..ec3cad9
--- /dev/null
+++ b/app/src/main/java/com/zadanie1/mw/SplashActivity.java
@@ -0,0 +1,27 @@
+package com.zadanie1.mw;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+
+public class SplashActivity extends Activity {
+
+ Handler handler;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.splashfile);
+
+ handler=new Handler();
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Intent intent=new Intent(SplashActivity.this,MainActivity.class);
+ startActivity(intent);
+ finish();
+ }
+ },3000);
+
+ }
+}
diff --git a/app/src/main/res/layout/activity_first_password.xml b/app/src/main/res/layout/activity_first_password.xml
new file mode 100644
index 0000000..8ea7653
--- /dev/null
+++ b/app/src/main/res/layout/activity_first_password.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_form_password.xml b/app/src/main/res/layout/activity_form_password.xml
index 0f885bb..3549ee1 100644
--- a/app/src/main/res/layout/activity_form_password.xml
+++ b/app/src/main/res/layout/activity_form_password.xml
@@ -1,38 +1,50 @@
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".MainActivity"
+ android:orientation="vertical"
+ android:padding="20px">
-
+
-
+
-
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/splashfile.xml b/app/src/main/res/layout/splashfile.xml
new file mode 100644
index 0000000..d1c6060
--- /dev/null
+++ b/app/src/main/res/layout/splashfile.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index efd3073..23ad585 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,3 +1,3 @@
- My Application
+ Encrypted Noto