Commit fc988d22 authored by chris.crook's avatar chris.crook

> adding load / save

parent 89633afc
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Summative_Chris_Crook"> android:theme="@style/Theme.Summative_Chris_Crook">
<activity android:name=".register_page"></activity>
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
......
...@@ -3,12 +3,63 @@ package com.example.summative_chris_crook; ...@@ -3,12 +3,63 @@ package com.example.summative_chris_crook;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity { import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class MainActivity extends AppCompatActivity {
String filename1 = "magicwords";
String filename2 = "appdatatxt";
File file1;
File file2;
@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);
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
file2 = new File(getApplicationContext().getFilesDir(), filename2 + ".txt");
try{
Scanner reader = new Scanner(file1);
String temp = "";
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_LONG).show();
}
}
public void openandload(View view){
try{
Scanner reader = new Scanner(file1);
String temp = "";
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_LONG).show();
}
}
public void saveandclose(View view){
try{
FileWriter stream = new FileWriter(file1, false);
stream.write(" ");
stream.close();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_LONG).show();
} }
}
//
} }
\ No newline at end of file
package com.example.summative_chris_crook;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class register_page extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_page);
}
}
\ No newline at end of file
package com.example.summative_chris_crook;
import java.io.File;
public class txt_interaction {
String filename1 = "magicwords";
String filename2 = "appdatatxt";
File file1;
File file2;
public void loadfrom(){
}
}
...@@ -6,13 +6,47 @@ ...@@ -6,13 +6,47 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username:" />
<EditText
android:id="@+id/username_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<TextView <TextView
android:layout_width="wrap_content" android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password:" />
<EditText
android:id="@+id/password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Log In" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Hello World!" android:text="register" />
app:layout_constraintBottom_toBottomOf="parent" </LinearLayout>
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".register_page">
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment