コード例 #1
0
  @Override
  public void onClick(View view, int position, long id) {
    // TODO Auto-generated method stub
    MyFile myFile = mData.get(position);
    File file = new File(myFile.getPath());
    if (file.isDirectory()) {
      // 如果是文件夹节点,则进入下一层,并初始化数据
      initFileData(myFile.getPath());
    } else {
      // Toast.makeText(MainActivity.this, "阅读器待开发", Toast.LENGTH_SHORT).show();
      LayoutInflater layoutInflater = LayoutInflater.from(this);
      View v = layoutInflater.inflate(R.layout.popup_item, null);

      PopupWindow pw = new PopupWindow(v, LayoutParams.MATCH_PARENT, 400, true);
      pw.setBackgroundDrawable(getResources().getDrawable(R.drawable.local_popup_bg));

      TextView tv_fileName = (TextView) v.findViewById(R.id.tv_fileName);
      tv_fileName.setText(myFile.getName());

      TextView tv_filePath = (TextView) v.findViewById(R.id.tv_filePath);
      tv_filePath.setText(myFile.getPath());

      TextView tv_modifyTime = (TextView) v.findViewById(R.id.tv_modifyTime);
      tv_modifyTime.setText(myFile.getModifyTime());

      // 获得Item在屏蔽上的坐标位置
      int[] location = new int[2];
      view.getLocationInWindow(location);

      int windowWidth = FunctionHelper.getWindowWidth(this);
      pw.showAtLocation(
          view, Gravity.TOP | Gravity.LEFT, location[0] + windowWidth / 8, location[1] - 100);
    }
  }
コード例 #2
0
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub
    System.out.println(">>>>>>onItemClick->position:" + position + " id:" + id);
    MyFile myFile = mData.get(position);
    File file = new File(myFile.getPath());
    if (file.isDirectory()) {
      // 如果是文件夹节点,则进入下一层,并初始化数据
      initFileData(myFile.getPath());
    } else if (file.getParentFile() == null) {
      Toast.makeText(MainActivity.this, "无上级目录", Toast.LENGTH_SHORT).show();
      return;
    } else {
      // Toast.makeText(MainActivity.this, "阅读器待开发", Toast.LENGTH_SHORT).show();
      //			Intent intent = new
      // Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      //          startActivityForResult(intent, 1);

      // 如果是图片则读取图片
      if (myFile.isImg()) {
        Intent intent = new Intent();
        intent.setAction("ACTION_PICK");
        intent.putExtra("path", myFile.getPath());
        intent.putExtra("type", FILE_TYPE_IMG);
        startActivity(intent);
      } else {
        // 如果是txt/html/xml 类型的文件则打开
        String path = myFile.getPath().toLowerCase();
        if (path.endsWith(".txt")
            || path.endsWith(".html")
            || path.endsWith(".xml")
            || path.endsWith(".cfg")) {
          Intent intent = new Intent();
          intent.setAction("ACTION_PICK");
          intent.putExtra("path", myFile.getPath());
          intent.putExtra("type", FILE_TYPE_TXT);
          startActivity(intent);
        } else {
          Toast.makeText(MainActivity.this, "未知文件", Toast.LENGTH_SHORT).show();
        }
      }
    }
  }
コード例 #3
0
  @Override
  public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub
    System.out.println(">>>>>>onItemLongClick->position:" + position + " id:" + id);
    final int location = position;
    MyFile myFile = mData.get(location);

    // 如果是路径 暂时先不处理
    File file = new File(myFile.getPath());
    if (file.isDirectory() || "返回".equals(myFile.getName())) {
      Toast.makeText(this, "当前是文件夹或返回", Toast.LENGTH_SHORT).show();
      return false;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("提示");
    builder.setMessage("确定要删除" + myFile.getName() + (file.isDirectory() ? "文件夹" : "文件"));
    builder.setPositiveButton(
        "确定",
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            mData.remove(location);
            fileListAdapter.notifyDataSetChanged();
          }
        });

    builder.setNegativeButton(
        "取消",
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();
          }
        });
    builder.show();

    return false;
  }