-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1785 from kaluozi/master
- Loading branch information
Showing
9 changed files
with
206 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...n/java/edu/hzuapps/androidlabs/soft1714080902401/Soft1714080902401_FileStoreActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...c/main/java/java/edu/hzuapps/androidlabs/soft1714080902401/Soft1714080902401Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
...ain/java/java/edu/hzuapps/androidlabs/soft1714080902401/Soft1714080902401_01Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
students/soft1714080902401/app/src/main/res/layout/activity_soft_1714080902401_filestore.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
53 changes: 0 additions & 53 deletions
53
students/soft1714080902401/app/src/main/res/layout/activity_soft_1714080902401_new.xml
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
students/soft1714080902401/app/src/main/res/values/mystyle.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
</resources> |