If app is new runs FirstPassword. Also added SplashActivity.
This commit is contained in:
parent
830ca9db3e
commit
9932754c8e
@ -5,21 +5,25 @@
|
|||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:requestLegacyExternalStorage="true"
|
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:requestLegacyExternalStorage="true"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity android:name=".Noto"></activity>
|
|
||||||
<activity android:name=".FormPassword" />
|
<activity android:name=".SplashActivity">
|
||||||
<activity android:name=".MainActivity">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity android:name=".FirstPassword" />
|
||||||
|
<activity android:name=".Noto" />
|
||||||
|
<activity android:name=".FormPassword" />
|
||||||
|
<activity android:name=".MainActivity"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
73
app/src/main/java/com/zadanie1/mw/FirstPassword.java
Normal file
73
app/src/main/java/com/zadanie1/mw/FirstPassword.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -9,28 +9,60 @@ import android.widget.EditText;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
public class FormPassword extends Activity {
|
public class FormPassword extends Activity {
|
||||||
private static final String FILE_NAME = "passwd.txt";
|
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
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_form_password);
|
setContentView(R.layout.activity_form_password);
|
||||||
|
|
||||||
|
final EditText currentpassword;
|
||||||
final EditText newpassword;
|
final EditText newpassword;
|
||||||
final EditText renewpassword;
|
final EditText renewpassword;
|
||||||
Button confirm;
|
Button confirm;
|
||||||
|
|
||||||
|
currentpassword = (EditText) findViewById(R.id.currentpassword);
|
||||||
newpassword = (EditText) findViewById(R.id.newpassword);
|
newpassword = (EditText) findViewById(R.id.newpassword);
|
||||||
renewpassword = (EditText) findViewById(R.id.renewpassword);
|
renewpassword = (EditText) findViewById(R.id.renewpassword);
|
||||||
confirm = (Button) findViewById(R.id.button);
|
confirm = (Button) findViewById(R.id.button);
|
||||||
|
|
||||||
confirm.setOnClickListener(new View.OnClickListener() {
|
confirm.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View arg0) {
|
public void onClick(View arg0) {
|
||||||
|
final String filename = getFilesDir() + "/passwd.txt";
|
||||||
|
File file = new File(filename);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (currentpassword.getText().toString().equals(readFile(filename).toString())) {
|
||||||
if (newpassword.getText().toString().equals(renewpassword.getText().toString())) {
|
if (newpassword.getText().toString().equals(renewpassword.getText().toString())) {
|
||||||
|
|
||||||
String text = newpassword.getText().toString();
|
String text = newpassword.getText().toString();
|
||||||
@ -59,14 +91,24 @@ public class FormPassword extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Toast toast = Toast.makeText(getApplicationContext(),
|
Toast toast = Toast.makeText(getApplicationContext(),
|
||||||
"Password has NOT been changed",
|
"Password has NOT been changed!",
|
||||||
Toast.LENGTH_SHORT);
|
Toast.LENGTH_SHORT);
|
||||||
toast.show();
|
toast.show();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Toast toast = Toast.makeText(getApplicationContext(),
|
||||||
|
"Current password is WRONG!",
|
||||||
|
Toast.LENGTH_SHORT);
|
||||||
|
toast.show();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
currentpassword.getText().clear();
|
||||||
|
newpassword.getText().clear();
|
||||||
|
renewpassword.getText().clear();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,25 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isFileExists(File file) {
|
||||||
|
return file.exists() && !file.isDirectory();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
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);
|
response = (TextView) findViewById(R.id.textView);
|
||||||
button = (Button) findViewById(R.id.button);
|
button = (Button) findViewById(R.id.button);
|
||||||
restartpassword = (Button) findViewById(R.id.restartpassword);
|
restartpassword = (Button) findViewById(R.id.restartpassword);
|
||||||
@ -68,11 +81,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
button.setOnClickListener(new OnClickListener() {
|
button.setOnClickListener(new OnClickListener() {
|
||||||
private final String filename = getFilesDir() + "/passwd.txt";
|
private final String filename = getFilesDir() + "/passwd.txt";
|
||||||
|
|
||||||
private boolean isFileExists(File file) {
|
|
||||||
return file.exists() && !file.isDirectory();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
/*response.setText(textPassword.getText());*/
|
/*response.setText(textPassword.getText());*/
|
||||||
@ -90,22 +98,24 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
Noto.class);
|
Noto.class);
|
||||||
startActivity(myIntent2);
|
startActivity(myIntent2);
|
||||||
|
|
||||||
}
|
|
||||||
} else if (textPassword.getText().toString().equals("FirstPassword!")) {
|
|
||||||
Intent myIntent2 = new Intent(MainActivity.this,
|
|
||||||
Noto.class);
|
|
||||||
startActivity(myIntent2);
|
|
||||||
} else {
|
} else {
|
||||||
Toast toast = Toast.makeText(getApplicationContext(),
|
Toast toast = Toast.makeText(getApplicationContext(),
|
||||||
"Password is NOT correct",
|
"Password is NOT correct",
|
||||||
Toast.LENGTH_SHORT);
|
Toast.LENGTH_SHORT);
|
||||||
toast.show();
|
toast.show();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Intent myIntent3 = new Intent(MainActivity.this,
|
||||||
|
FirstPassword.class);
|
||||||
|
startActivity(myIntent3);
|
||||||
|
}
|
||||||
|
|
||||||
} catch(IOException e){
|
} catch(IOException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
textPassword.getText().clear();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
27
app/src/main/java/com/zadanie1/mw/SplashActivity.java
Normal file
27
app/src/main/java/com/zadanie1/mw/SplashActivity.java
Normal file
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
40
app/src/main/res/layout/activity_first_password.xml
Normal file
40
app/src/main/res/layout/activity_first_password.xml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
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=".FirstPassword"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="20px">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/newpassword"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="textPassword"
|
||||||
|
android:hint="New Password"
|
||||||
|
tools:layout_editor_absoluteX="97dp"
|
||||||
|
tools:layout_editor_absoluteY="409dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/renewpassword"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="textPassword"
|
||||||
|
android:hint="New Password again"
|
||||||
|
tools:layout_editor_absoluteX="97dp"
|
||||||
|
tools:layout_editor_absoluteY="409dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="CONFIRM NEW PASSWORD"
|
||||||
|
tools:layout_editor_absoluteX="260dp"
|
||||||
|
tools:layout_editor_absoluteY="492dp" />
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
@ -9,12 +9,23 @@ tools:context=".MainActivity"
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="20px">
|
android:padding="20px">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/currentpassword"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="textPassword"
|
||||||
|
android:hint="Current Password"
|
||||||
|
tools:layout_editor_absoluteX="97dp"
|
||||||
|
tools:layout_editor_absoluteY="409dp" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/newpassword"
|
android:id="@+id/newpassword"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
|
android:hint="New Password"
|
||||||
tools:layout_editor_absoluteX="97dp"
|
tools:layout_editor_absoluteX="97dp"
|
||||||
tools:layout_editor_absoluteY="409dp" />
|
tools:layout_editor_absoluteY="409dp" />
|
||||||
|
|
||||||
@ -24,6 +35,7 @@ android:padding="20px">
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
|
android:hint="New Password again"
|
||||||
tools:layout_editor_absoluteX="97dp"
|
tools:layout_editor_absoluteX="97dp"
|
||||||
tools:layout_editor_absoluteY="409dp" />
|
tools:layout_editor_absoluteY="409dp" />
|
||||||
|
|
||||||
|
35
app/src/main/res/layout/splashfile.xml
Normal file
35
app/src/main/res/layout/splashfile.xml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
|
||||||
|
android:id="@+id/logo_id"
|
||||||
|
android:layout_width="250dp"
|
||||||
|
android:layout_height="250dp"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:src="@drawable/img"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/logo_id"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Encrypted Noto"
|
||||||
|
android:textSize="30dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/textView"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="18dp"
|
||||||
|
android:text="by Marcin Wozniak"
|
||||||
|
android:textSize="15dp" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -1,3 +1,3 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">My Application</string>
|
<string name="app_name">Encrypted Noto</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user