forked from hzuapps/android-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hzuapps#89 hzuapps#125 实验3 Android资源使用编程
提交res/drawable及图片使用的代码
- Loading branch information
Showing
7 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...zuapps/androidworks/homeworks/net1314080903112/FileExplorerActivity_net1314080903112.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,83 @@ | ||
package edu.hzuapps.androidworks.homeworks.net1314080903112; | ||
|
||
import android.content.Intent; | ||
import android.os.Environment; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import android.widget.ListView; | ||
import android.widget.SimpleAdapter; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class FileExplorerActivity_net1314080903112 extends AppCompatActivity implements AdapterView.OnItemClickListener { | ||
|
||
ListView listView; | ||
SimpleAdapter adapter; | ||
String rootPath = Environment.getExternalStorageDirectory().getPath(); | ||
String currentPath = rootPath; | ||
List<Map<String, Object>> list = new ArrayList<>(); | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_file_explorer_net1314080903112); | ||
listView = (ListView) findViewById(R.id.list_view); | ||
adapter = new SimpleAdapter(this, list, R.layout.list_item_net1314080903112, | ||
new String[]{"name", "img"}, new int[]{R.id.name, R.id.img}); | ||
listView.setAdapter(adapter); | ||
listView.setOnItemClickListener(this); | ||
refreshListItems(currentPath); | ||
} | ||
|
||
private void refreshListItems(String path) { | ||
setTitle(path); | ||
File[] files = new File(path).listFiles(); | ||
list.clear(); | ||
if (files != null) { | ||
for (File file : files) { | ||
Map<String, Object> map = new HashMap<>(); | ||
if (file.isDirectory()) { | ||
map.put("img", R.drawable.directory_net1314080903112); | ||
} else { | ||
map.put("img", R.drawable.file_doc_net1314080903112); | ||
} | ||
map.put("name", file.getName()); | ||
map.put("currentPath", file.getPath()); | ||
list.add(map); | ||
} | ||
} | ||
adapter.notifyDataSetChanged(); | ||
} | ||
|
||
@Override | ||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) { | ||
currentPath = (String) list.get(position).get("currentPath"); | ||
File file = new File(currentPath); | ||
if (file.isDirectory()) | ||
refreshListItems(currentPath); | ||
else { | ||
Intent intent = new Intent(); | ||
intent.putExtra("apk_path", file.getPath()); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
if (rootPath.equals(currentPath)) { | ||
super.onBackPressed(); | ||
} else { | ||
File file = new File(currentPath); | ||
currentPath = file.getParentFile().getPath(); | ||
refreshListItems(currentPath); | ||
} | ||
} | ||
} |
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.