Skip to content

Commit

Permalink
Merge pull request #1785 from kaluozi/master
Browse files Browse the repository at this point in the history
#5 #541 提交实验五代码
  • Loading branch information
zengsn authored May 7, 2019
2 parents 0b08861 + 7f6ffe2 commit cfb98ff
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:roundIcon="@drawable/ic_launcher_appico"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Soft1714080902401_newActivity"></activity>
<activity android:name=".Soft1714080902401_FileStoreActivity"></activity>
<activity android:name=".Soft1714080902401_01Activity" />
<activity android:name=".Soft1714080902401Activity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft_1714080902401_01);


Button NewD = (Button) findViewById(R.id.newD);
NewD.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Soft1714080902401_01Activity.this, Soft1714080902401_newActivity.class);
Intent intent = new Intent(Soft1714080902401_01Activity.this, Soft1714080902401_FileStoreActivity.class);
startActivity(intent);
}
});

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package edu.hzuapps.androidlabs.soft1714080902401;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.text.TextUtils;

import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;


public class Soft1714080902401_FileStoreActivity extends AppCompatActivity {


public static final String FILENAME = "file_demo.txt";
public static final String TAG = Soft1714080902401_FileStoreActivity.class.getSimpleName();
private EditText savetext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_soft_1714080902401_filestore);
savetext = (EditText) findViewById(R.id.savetext);
String inputText = load();
if(!TextUtils.isEmpty(inputText)){
savetext.setText(inputText);
savetext.setSelection(inputText.length());
Toast.makeText(this,"读取成功!",Toast.LENGTH_LONG).show();
}


// ((Button) findViewById(R.id.button_save_internal)).setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// }
// });
}

@Override
protected void onDestroy(){
super.onDestroy();
String inputText = savetext.getText().toString();
save(inputText);
}
// 将数据保存
public void save(String inputText){
FileOutputStream out = null;
BufferedWriter writer = null;
try{
out = openFileOutput("data", Context.MODE_PRIVATE);
writer = new BufferedWriter(new OutputStreamWriter(out));
writer.write(inputText);
} catch (IOException e){
e.printStackTrace();
}finally{
try{
if (writer != null){
writer.close();
}
}catch (IOException e){
e.printStackTrace();
}
}
}
//读取数据
public String load(){
FileInputStream in = null;
BufferedReader reader = null;
StringBuilder content = new StringBuilder();

try{
in = openFileInput("data");
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null){
content.append(line);
}
}catch(IOException e){
e.printStackTrace();
}finally {
if (reader != null){
try{
reader.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
return content.toString();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.hzuapps.androidlabs.soft1714080902401;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class Soft1714080902401Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft_1714080902401);

Button begin = (Button) findViewById(R.id.Begin);
begin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Soft1714080902401Activity.this,Soft1714080902401_01Activity.class);
startActivity(intent);
}
});
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.hzuapps.androidlabs.soft1714080902401;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class Soft1714080902401_01Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft1714080902401_01);



Button NewD = (Button) findViewById(R.id.newD);
NewD.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Soft1714080902401_01Activity.this, Soft1714080902401_newActivity.class);
startActivity(intent);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Soft1714080902401_newActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft_1714080902401_new);
setContentView(R.layout.activity_soft1714080902401_new);

Button Save = (Button) findViewById(R.id.save);
Save.setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@drawable/fbackgroud"
tools:context=".Soft1714080902401_FileStoreActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="530dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="80dp"
android:background="@color/colorliwhite"
android:orientation="vertical">

<EditText
android:id="@+id/savetext"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_weight="1"
android:hint="今天过得怎么样?"
android:ems="10"
android:paddingLeft="50dp"
android:paddingTop="10dp"
android:paddingRight="50dp"
android:paddingBottom="20dp" />

<Button
android:id="@+id/button_save_internal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="保存" />

</LinearLayout>

</RelativeLayout>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

</resources>

0 comments on commit cfb98ff

Please sign in to comment.