Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4 #1031第四次实验报告 #2571

Merged
merged 9 commits into from
Jun 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion soft1614080902410/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Soft1614080902410_2"></activity>
<activity android:name=".Soft1614080902410_2" />
<activity android:name=".Soft1614080902410Activity_3" />
<activity android:name=".Soft1614080902410Activity_4" />
<activity
android:name=".Soft1614080902410Activity_5"
android:label="@string/title_activity_soft1614080902410_5"
android:theme="@style/AppTheme.NoActionBar" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.liyang.soft1614080902410;

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

public class Soft1614080902410Activity_3 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft16140809024103);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

package com.example.liyang.soft1614080902410;

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

public class Soft1614080902410Activity_4 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft1614080902410_4);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,117 @@
package com.example.liyang.soft1614080902410;

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

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Soft1614080902410_2 extends AppCompatActivity {
private TextView textView;
public static final String DIRECTORY = "demo";
public static final String FILENAME = "file_demo.txt";

public static final String TAG = Soft1614080902410_2.class.getSimpleName();

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

final Activity thisActivity = this;
Button btnHome1 = (Button) findViewById(R.id.buttom2);
Button btnHome2 = (Button) findViewById(R.id.buttom3);
btnHome1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View vv) {
Intent intent1 = new Intent(thisActivity,Soft1614080902410Activity_4.class);
thisActivity.startActivity(intent1);
}
});
btnHome2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v1) {
Intent intent2 = new Intent(thisActivity, Soft1614080902410Activity_3.class);
thisActivity.startActivity(intent2);
}
});

String text = "content";
saveTextIntoExternalStorage(text);
}

private void saveTextIntoExternalStorage(String text) {
if (!isExternalStorageWritable()) {
Log.e(TAG, "外部存储不可写!");
return;
}

File dir = getPublicExtStorageDir(DIRECTORY, Environment.DIRECTORY_DOWNLOADS);
File file = new File(dir, FILENAME);

try {
FileOutputStream fos = new FileOutputStream(file);
fos.write(text.getBytes());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

// 显示结果
showResult(file.getAbsolutePath());
}

/* Checks if external storage is available for read and write */
private boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}

/* Checks if external storage is available to at least read */
private boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}

// 创建公开的外部存储目录(App卸载时不会删除)
private File getPublicExtStorageDir(String dirName, String type) {
if (type == null) { // 指定文件类型
type = Environment.DIRECTORY_PICTURES;
}
File dir = new File(Environment //
.getExternalStoragePublicDirectory(type), dirName);
if (!dir.mkdirs()) {
Log.e(TAG, "目录无法创建!");
}

long freeSpace = dir.getFreeSpace();
Log.i(TAG, "剩余空间大小: " + (freeSpace / 1024 / 1024) + "MB");
long totalSpace = dir.getTotalSpace();
Log.i(TAG, "总空间大小: " + (totalSpace / 1024 / 1024) + "MB");

return dir;
}

private void showResult(String result) {
((TextView) findViewById(R.id.text_path))//
.setText(result.toCharArray(), 0, result.length());
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:background="#006400"
tools:context=".Soft1614080902410Activity_3">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="@drawable/ozil"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Mesut oezil
场上位置:中场
国籍:德国"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="@drawable/ramsey"/>

<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="ARON RAMSEY
场上位置;中场
国籍:威尔士"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="@drawable/aubu"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Aubameyang
场上位置;前锋
国籍;加蓬"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="@drawable/lacazette"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="LACAZETTE
场上位置;前锋
国籍;法国"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="@drawable/cazorla"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="SANTI CAZORLA
场上位置;中场
国籍;西班牙"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout 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=".Soft1614080902410_2">
tools:context=".Soft1614080902410_2"
android:orientation="vertical"
android:background="@drawable/ic_launcher3">

</android.support.constraint.ConstraintLayout>
<Button
android:id="@+id/buttom2"
android:layout_width="136dp"
android:layout_height="66dp"
android:gravity="center"
android:text="球队赛程"
android:layout_gravity="center_horizontal"
android:layout_marginTop="80dp"
tools:layout_editor_absoluteX="124dp"
tools:layout_editor_absoluteY="371dp" />

<Button
android:id="@+id/buttom3"
android:layout_width="136dp"
android:layout_height="66dp"
android:gravity="center"
android:text="球队球员"
android:layout_gravity="center_horizontal"
android:layout_marginTop="200dp"
tools:layout_editor_absoluteX="124dp"
tools:layout_editor_absoluteY="63dp" />
</LinearLayout>
Loading