public void doClick(boolean selectedInActionMode) {
    if (selectedInActionMode && mDragInfo != null && mDragInfo.parentView instanceof AbsListView) {
      Log.i(TAG, "Do click in action mode.");
      if (mDragReady) {
        if (mDragProgressDelegate != null) {
          mDragProgressDelegate.revertDragPreparation(this);
        }
        mDragReady = false;
      } else {
        // Due to the interactive ability of this widget
        AbsListView parentListView = (AbsListView) mDragInfo.parentView;
        int position = mDragInfo.positionAsChild;
        if (parentListView != null && position >= 0) {
          boolean lastChecked = parentListView.isItemChecked(position);

          parentListView.setItemChecked(position, !lastChecked);
          parentListView.invalidate();
        }
      }
    } else {
      Log.i(TAG, "Do click in non action mode .");
      if (mDragInfo.parentView instanceof AbsListView && mDragInfo.positionAsChild >= 0) {
        AbsListView parentListView = (AbsListView) mDragInfo.parentView;
        int position = mDragInfo.positionAsChild;
        OnItemClickListener clickListener = parentListView.getOnItemClickListener();
        if (clickListener != null) {
          clickListener.onItemClick(parentListView, this, position, this.getId());
        }
      }
    }
  }
Esempio n. 2
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    View view = convertView;
    OCFile file = null;
    LayoutInflater inflator =
        (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (mFiles != null && mFiles.size() > position) {
      file = mFiles.get(position);
    }

    // Find out which layout should be displayed
    ViewType viewType;
    if (!mGridMode) {
      viewType = ViewType.LIST_ITEM;
    } else if (file.isImage()) {
      viewType = ViewType.GRID_IMAGE;
    } else {
      viewType = ViewType.GRID_ITEM;
    }

    // Create View
    switch (viewType) {
      case GRID_IMAGE:
        view = inflator.inflate(R.layout.grid_image, null);
        break;
      case GRID_ITEM:
        view = inflator.inflate(R.layout.grid_item, null);
        break;
      case LIST_ITEM:
        view = inflator.inflate(R.layout.list_item, null);
        break;
    }

    view.invalidate();

    if (file != null) {

      ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);

      fileIcon.setTag(file.getFileId());
      TextView fileName;
      String name = file.getFileName();

      LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.ListItemLayout);
      linearLayout.setContentDescription("LinearLayout-" + name);

      switch (viewType) {
        case LIST_ITEM:
          TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
          TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
          ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);

          lastModV.setVisibility(View.VISIBLE);
          lastModV.setText(showRelativeTimestamp(file));

          checkBoxV.setVisibility(View.GONE);

          fileSizeV.setVisibility(View.VISIBLE);
          fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));

          if (!file.isFolder()) {
            AbsListView parentList = (AbsListView) parent;
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
              if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) {
                checkBoxV.setVisibility(View.GONE);
              } else {
                if (parentList.isItemChecked(position)) {
                  checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
                } else {
                  checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
                }
                checkBoxV.setVisibility(View.VISIBLE);
              }
            }

          } else { // Folder
            fileSizeV.setVisibility(View.INVISIBLE);
          }

        case GRID_ITEM:
          // filename
          fileName = (TextView) view.findViewById(R.id.Filename);
          name = file.getFileName();
          fileName.setText(name);

        case GRID_IMAGE:
          // sharedIcon
          ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
          if (file.isShareByLink()) {
            sharedIconV.setVisibility(View.VISIBLE);
            sharedIconV.bringToFront();
          } else {
            sharedIconV.setVisibility(View.GONE);
          }

          // local state
          ImageView localStateView = (ImageView) view.findViewById(R.id.localFileIndicator);
          localStateView.bringToFront();
          FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
          FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
          boolean downloading =
              (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file));
          OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder();
          downloading |=
              (opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath()));
          if (downloading) {
            localStateView.setImageResource(R.drawable.downloading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
          } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.uploading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
          } else if (file.isDown()) {
            localStateView.setImageResource(R.drawable.local_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
          } else {
            localStateView.setVisibility(View.INVISIBLE);
          }

          // share with me icon
          if (!file.isFolder()) {
            ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon);
            sharedWithMeIconV.bringToFront();
            if (checkIfFileIsSharedWithMe(file)) {
              sharedWithMeIconV.setVisibility(View.VISIBLE);
            } else {
              sharedWithMeIconV.setVisibility(View.GONE);
            }
          }

          break;
      }

      // For all Views

      // this if-else is needed even though favorite icon is visible by default
      // because android reuses views in listview
      if (!file.keepInSync()) {
        view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE);
      } else {
        view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE);
      }

      // No Folder
      if (!file.isFolder()) {
        if (file.isImage() && file.getRemoteId() != null) {
          // Thumbnail in Cache?
          Bitmap thumbnail =
              ThumbnailsCacheManager.getBitmapFromDiskCache(String.valueOf(file.getRemoteId()));
          if (thumbnail != null && !file.needsUpdateThumbnail()) {
            fileIcon.setImageBitmap(thumbnail);
          } else {
            // generate new Thumbnail
            if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) {
              final ThumbnailsCacheManager.ThumbnailGenerationTask task =
                  new ThumbnailsCacheManager.ThumbnailGenerationTask(
                      fileIcon, mStorageManager, mAccount);
              if (thumbnail == null) {
                thumbnail = ThumbnailsCacheManager.mDefaultImg;
              }
              final ThumbnailsCacheManager.AsyncDrawable asyncDrawable =
                  new ThumbnailsCacheManager.AsyncDrawable(
                      mContext.getResources(), thumbnail, task);
              fileIcon.setImageDrawable(asyncDrawable);
              task.execute(file);
            }
          }
        } else {
          fileIcon.setImageResource(
              DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName()));
        }

      } else {
        // Folder
        if (checkIfFileIsSharedWithMe(file)) {
          fileIcon.setImageResource(R.drawable.shared_with_me_folder);
        } else if (file.isShareByLink()) {
          // If folder is sharedByLink, icon folder must be changed to
          // folder-public one
          fileIcon.setImageResource(R.drawable.folder_public);
        } else {
          fileIcon.setImageResource(
              DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName()));
        }
      }
    }

    return view;
  }