package com.example.ghomi.chapter8_1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import java.io.FileInputStream;

public class RetreiveActivity extends AppCompatActivity {
    TextView getname, getpass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retreive);
        getname = (TextView) findViewById(R.id.getName);
        getpass = (TextView) findViewById(R.id.getPass);
    }
    public void load(View view) {
        try {
            FileInputStream input = openFileInput("code.txt");
            int read = -1;
            StringBuffer buffer = new StringBuffer();
            while ((read = input.read()) != -1) {
                buffer.append((char) read);
            }
            String name = buffer.substring(0, buffer.indexOf(" "));
            String pass = buffer.substring(buffer.indexOf(" ") + 1);
            getname.setText(name);
            getpass.setText(pass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Toast.makeText(this, "Loaded", Toast.LENGTH_SHORT).show();
    }
    public void back (View view){
        Toast.makeText(this, "Back", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }
}
