Skip to content

Commit

Permalink
hzuapps#89 hzuapps#125 实验3 Android资源使用编程
Browse files Browse the repository at this point in the history
提交res/drawable及图片使用的代码
  • Loading branch information
WCTNOC committed Apr 22, 2016
1 parent dfa7169 commit c73fa9c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
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.

0 comments on commit c73fa9c

Please sign in to comment.