初次提交

This commit is contained in:
2022-09-19 18:05:01 +08:00
commit 57051fc44b
5401 changed files with 325410 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Sample2_6</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Fri Jul 01 08:09:10 CST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="com.bn.pp6">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Sample2_6_Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-7

View File

@@ -0,0 +1,28 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.bn.pp6;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int back=0x7f050000;
public static final int currDirTV=0x7f050001;
public static final int lv=0x7f050002;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:background="#ffffff"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/back"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="返回上一层目录"
android:textSize="18dip"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/currDirTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
>
<ListView
android:id="@+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18dip"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Sample3_2_Activity!</string>
<string name="app_name">Sample2_6</string>
</resources>

View File

@@ -0,0 +1,118 @@
package com.bn.pp6;
import java.io.File; //导入相关包
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Sample2_6_Activity extends Activity {// 创建Activity
String currPath; // 当前路径字符串
String rootPath = "/"; // 根目录路径
TextView currDirTV;//显示当前路径的TextView
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // 设置layout
final ListView lv = (ListView) this.findViewById(R.id.lv); // 获取ListView
Button back = (Button) this.findViewById(R.id.back); // 获取返回按钮
final File[] files = getFiles(rootPath); // 调用getFiles方法获取根目录下文件列表
currDirTV = (TextView) this.findViewById(R.id.currDirTV); // 获取ListView
currPath = rootPath;
currDirTV.setText("当前路径:" + currPath);//设置当前路径
initListView(files, lv); // 初始化显示列表
back.setOnClickListener // 返回按钮监听器
(new OnClickListener() {
@Override
public void onClick(View v) {
if (!currPath.equals(rootPath)) {// 若当前路径不是根目录,返回到上一层目录
File f = new File(currPath); // 获取当前路径下的文件列表
f = f.getParentFile(); // 获取当前路径的上层路径
currPath = f.getPath(); // 更改当前路径
currDirTV.setText("当前路径:" + currPath);//设置当前路径
initListView(getFiles(currPath), lv); // 初始化显示列表
}
}
});
}
// 获取当前目录下的文件列表的方法
public File[] getFiles(String filePath) {
File[] files = new File(filePath).listFiles();// 获取当前目录下的文件列表
return files; // 返回文件列表
}
// 初始化ListView进行显示
public void initListView(final File[] files, final ListView lv) {
// 当文件列表不为空时
if (files != null) {
if (files.length == 0) {// 当前目录为空
File f = new File(currPath); // 获取当前路径对应文件列表
f = f.getParentFile(); // 获取上层路径
currPath = f.getPath(); // 记录当前路径
currDirTV.setText("当前路径:" + currPath);//设置当前路径
Toast.makeText(this, "该文件夹为空!!", Toast.LENGTH_SHORT).show();
} else {
BaseAdapter ba = new BaseAdapter()// 创建适配器
{
@Override
public int getCount() {
return files.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
LinearLayout ll = new LinearLayout(
Sample2_6_Activity.this); // 创建LinearLayout
ll.setOrientation(LinearLayout.VERTICAL); // 竖直排列
ll.setPadding(5, 5, 5, 5); // 设置留白
TextView tv = new TextView(Sample2_6_Activity.this); // 创建TextView
tv.setTextColor(Color.BLACK); // 设置字体颜色
tv.setText(files[arg0].getName()); // 添加文字为文件名称
tv.setGravity(Gravity.LEFT); // 左对齐
tv.setTextSize(16); // 字体大小
ll.addView(tv); // 添加TextView
return ll; // 返回LinearLayout
}
};
lv.setAdapter(ba); // 为ListView设置适配器
lv.setOnItemClickListener // 为ListView添加监听器
(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
currPath = files[arg2].getPath(); // 获取点击的文件名称的当前路径
currDirTV.setText("当前路径:" + currPath);//设置当前路径
File[] fs = getFiles(currPath); // 获取当前路径的文件列表
initListView(fs, lv); // 初始化ListView
}
});
}
} else {
File f = new File(currPath); // 获取当前文件列表的路径对应的文件
f = f.getParentFile(); // 获取父目录文件
currPath = f.getPath(); // 记录当前文件列表路径
currDirTV.setText("当前路径:" + currPath);//设置当前路径
Toast.makeText(this, "该目录不是文件夹或无权限访问!", Toast.LENGTH_SHORT).show();
}
}
}