Skip to content

Commit 4d57969

Browse files
JAVATECHIGJAVATECHIG
JAVATECHIG
authored and
JAVATECHIG
committed
added ListAllFiles example
1 parent 6efefbe commit 4d57969

File tree

17 files changed

+213
-0
lines changed

17 files changed

+213
-0
lines changed

ListAllFiles/AndroidManifest.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.listallfiles"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="8"
9+
android:targetSdkVersion="18" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:icon="@drawable/ic_launcher"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme" >
16+
<activity
17+
android:name="com.example.listallfiles.MainActivity"
18+
android:label="@string/app_name" >
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
543 KB
Binary file not shown.

ListAllFiles/project.properties

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-18
7.48 KB
Loading
3.69 KB
Loading
12.2 KB
Loading
24.2 KB
Loading
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/scrollView"
4+
android:layout_width="fill_parent"
5+
android:layout_height="fill_parent" >
6+
7+
<LinearLayout
8+
android:id="@+id/view"
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent"
11+
android:orientation="vertical"
12+
android:padding="8dp" >
13+
</LinearLayout>
14+
15+
</ScrollView>

ListAllFiles/res/menu/main.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
2+
3+
<item
4+
android:id="@+id/action_settings"
5+
android:orderInCategory="100"
6+
android:showAsAction="never"
7+
android:title="@string/action_settings"/>
8+
9+
</menu>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw600dp devices (e.g. 7" tablets) here.
6+
-->
7+
8+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
6+
-->
7+
<dimen name="activity_horizontal_margin">128dp</dimen>
8+
9+
</resources>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>

ListAllFiles/res/values/dimens.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<!-- Default screen margins, per the Android Design guidelines. -->
4+
<dimen name="activity_horizontal_margin">16dp</dimen>
5+
<dimen name="activity_vertical_margin">16dp</dimen>
6+
7+
</resources>

ListAllFiles/res/values/strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">ListAllFiles</string>
5+
<string name="action_settings">Settings</string>
6+
<string name="hello_world">Hello world!</string>
7+
8+
</resources>

ListAllFiles/res/values/styles.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.javatechig.listallfiles;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
6+
import com.example.listallfiles.R;
7+
8+
import android.app.Activity;
9+
import android.graphics.Color;
10+
import android.os.Bundle;
11+
import android.os.Environment;
12+
import android.widget.LinearLayout;
13+
import android.widget.TextView;
14+
15+
public class MainActivity extends Activity {
16+
17+
private File root;
18+
private ArrayList<File> fileList = new ArrayList<File>();
19+
private LinearLayout view;
20+
21+
@Override
22+
protected void onCreate(Bundle savedInstanceState) {
23+
super.onCreate(savedInstanceState);
24+
setContentView(R.layout.activity_main);
25+
26+
view = (LinearLayout) findViewById(R.id.view);
27+
28+
//getting SDcard root path
29+
root = new File(Environment.getExternalStorageDirectory()
30+
.getAbsolutePath());
31+
getfile(root);
32+
33+
for (int i = 0; i < fileList.size(); i++) {
34+
TextView textView = new TextView(this);
35+
textView.setText(fileList.get(i).getName());
36+
textView.setPadding(5, 5, 5, 5);
37+
38+
System.out.println(fileList.get(i).getName());
39+
40+
if (fileList.get(i).isDirectory()) {
41+
textView.setTextColor(Color.parseColor("#FF0000"));
42+
}
43+
view.addView(textView);
44+
}
45+
46+
}
47+
48+
public ArrayList<File> getfile(File dir) {
49+
File listFile[] = dir.listFiles();
50+
if (listFile != null && listFile.length > 0) {
51+
for (int i = 0; i < listFile.length; i++) {
52+
53+
if (listFile[i].isDirectory()) {
54+
fileList.add(listFile[i]);
55+
getfile(listFile[i]);
56+
57+
} else {
58+
if (listFile[i].getName().endsWith(".png")
59+
|| listFile[i].getName().endsWith(".jpg")
60+
|| listFile[i].getName().endsWith(".jpeg")
61+
|| listFile[i].getName().endsWith(".gif"))
62+
63+
{
64+
fileList.add(listFile[i]);
65+
}
66+
}
67+
68+
}
69+
}
70+
return fileList;
71+
}
72+
73+
}

0 commit comments

Comments
 (0)