First Update
This commit is contained in:
17
app/src/main/java/com/zadanie1/mw/FormPassword.java
Normal file
17
app/src/main/java/com/zadanie1/mw/FormPassword.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.zadanie1.mw;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
|
||||
public class FormPassword extends Activity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_form_password);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
57
app/src/main/java/com/zadanie1/mw/MainActivity.java
Normal file
57
app/src/main/java/com/zadanie1/mw/MainActivity.java
Normal file
@ -0,0 +1,57 @@
|
||||
package com.zadanie1.mw;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
TextView response;
|
||||
Button button;
|
||||
Button restartpassword;
|
||||
private EditText textPassword;
|
||||
private View viewPassword;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
response = (TextView) findViewById(R.id.textView);
|
||||
button = (Button) findViewById(R.id.button);
|
||||
restartpassword = (Button) findViewById(R.id.restartpassword);
|
||||
textPassword = findViewById(R.id.editText);
|
||||
|
||||
restartpassword.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View arg0) {
|
||||
Intent myIntent = new Intent(MainActivity.this,
|
||||
FormPassword.class);
|
||||
startActivity(myIntent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
button.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
response.setText(textPassword.getText());
|
||||
if (textPassword.getText().toString().equals("123")) {
|
||||
Intent myIntent2 = new Intent(MainActivity.this,
|
||||
Noto.class);
|
||||
startActivity(myIntent2);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
88
app/src/main/java/com/zadanie1/mw/Noto.java
Normal file
88
app/src/main/java/com/zadanie1/mw/Noto.java
Normal file
@ -0,0 +1,88 @@
|
||||
package com.zadanie1.mw;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class Noto extends AppCompatActivity {
|
||||
EditText ChangeNote;
|
||||
Button SaveNote;
|
||||
|
||||
private static final String FILE_NAME = "notes.txt";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_noto);
|
||||
|
||||
ChangeNote = (EditText) findViewById(R.id.changeNote);
|
||||
SaveNote = (Button) findViewById(R.id.SaveNote);
|
||||
FileInputStream fis = null;
|
||||
|
||||
try {
|
||||
fis = openFileInput(FILE_NAME);
|
||||
InputStreamReader isr = new InputStreamReader(fis);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String text;
|
||||
|
||||
while ((text = br.readLine()) != null) {
|
||||
sb.append(text).append("\n");
|
||||
}
|
||||
|
||||
if (sb.toString() != null) {
|
||||
ChangeNote.setText(sb.toString());
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fis != null){
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void save (View v) throws IOException {
|
||||
|
||||
String text = ChangeNote.getText().toString();
|
||||
FileOutputStream fos = null;
|
||||
|
||||
try {
|
||||
fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
|
||||
fos.write(text.getBytes());
|
||||
|
||||
ChangeNote.getText().clear();
|
||||
Toast.makeText(this, "Saved to " + getFilesDir() + "/" + FILE_NAME, Toast.LENGTH_LONG).show();
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null){
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user