コード例 #1
0
  private QuickAction prepareDirAction(final SeafDirent dirent) {
    final QuickAction mQuickAction = new QuickAction(mActivity);
    Resources resources = mActivity.getResources();
    ActionItem shareAction;
    shareAction =
        new ActionItem(
            ACTION_ID_SHARE,
            resources.getString(R.string.file_action_share),
            resources.getDrawable(R.drawable.action_share));
    mQuickAction.addActionItem(shareAction);

    // setup the action item click listener
    mQuickAction.setOnActionItemClickListener(
        new QuickAction.OnActionItemClickListener() {
          @Override
          public void onItemClick(QuickAction quickAction, int pos, int actionId) {
            NavContext nav = mActivity.getNavContext();
            String repoName = nav.getRepoName();
            String repoID = nav.getRepoID();
            String dir = nav.getDirPath();
            String path = Utils.pathJoin(dir, dirent.name);
            switch (actionId) {
              case ACTION_ID_SHARE:
                mActivity.shareDir(repoID, path);
                break;
            }
          }
        });

    mQuickAction.mAnimateTrack(false);
    return mQuickAction;
  }
コード例 #2
0
  @SuppressLint("NewApi")
  public void refreshView(boolean forceRefresh) {
    if (mActivity == null) return;

    mErrorText.setVisibility(View.GONE);
    mListContainer.setVisibility(View.VISIBLE);

    navToActivitiesView(forceRefresh);

    mActivity.supportInvalidateOptionsMenu();
  }
コード例 #3
0
  private void setFileView(SeafDirent dirent, Viewholder viewHolder, int position) {
    NavContext nav = mActivity.getNavContext();
    DataManager dataManager = mActivity.getDataManager();
    String repoName = nav.getRepoName();
    String repoID = nav.getRepoID();
    String filePath = Utils.pathJoin(nav.getDirPath(), dirent.name);
    File file = dataManager.getLocalRepoFile(repoName, repoID, filePath);
    boolean cacheExists = false;

    if (file.exists()) {
      SeafCachedFile cf = dataManager.getCachedFile(repoName, repoID, filePath);
      String subtitle = null;
      long size = file.length();
      if (size == dirent.size) {
        subtitle = dirent.getSubtitle();
      } else {
        subtitle = Utils.readableFileSize(size) + ", modified";
      }
      if (cf != null) {
        cacheExists = true;
        if (dirent.id.equals(cf.fileID) && dirent.size == size) {
          subtitle += ", cached";
        }
      }
      viewHolder.subtitle.setText(subtitle);

      if (Utils.isViewableImage(file.getName())) {
        setImageThumbNail(file, dirent, dataManager, viewHolder);
      } else viewHolder.icon.setImageResource(dirent.getIcon());

    } else {
      viewHolder.subtitle.setText(dirent.getSubtitle());
      viewHolder.icon.setImageResource(dirent.getIcon());
    }

    setFileAction(dirent, viewHolder, position, cacheExists);
  }
コード例 #4
0
 private void showError(int strID) {
   showError(mActivity.getResources().getString(strID));
 }
コード例 #5
0
ファイル: sendThread.java プロジェクト: lidanxia/syncseafile
  public synchronized void sendPacket(Packet pt, String sub_fileID, int i, String filename) {
    long start = System.currentTimeMillis();
    byte[] messages = null;
    String file_name = null;
    if (filename != null && filename != "")
      file_name = filename.substring(filename.lastIndexOf("/") + 1);
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(pt);
      messages = baos.toByteArray(); // Packet类中除去data,其它字段的大小是261左右个字节,实验得出的。
      baos.close();
      oos.close();

      packet = new DatagramPacket(messages, messages.length, addr, port);
      socket.send(packet);
      if (pt.islast == true)
        System.out.println("@@@@@@@@ 发送本节点最后一个文件的最后一个包 ---pt.islast:  " + pt.islast);

      System.out.println("发送ING-- " + file_name + "-- " + sub_fileID + "---packet:" + i);
      if (pt.islast == true) // 判断每一个包,如果它的islast标志是true,说明是我们要找的最后一个文件的最后一个包
      {
        System.out.println("@@@@@@@@@ 发完最后一个文件的最后一个包,开始发送 nextIP+end");
        // 知道发送方自己的IP,从savedMap中找到这个IP对应的下一个IP,下一个IP就是下一个要发送的节点
        synchronized (FileSharing.savedMap) {
          String ip = BrowserActivity.getIp();
          Iterator it = FileSharing.savedMap.keySet().iterator();
          String nextip;
          while (it.hasNext()) {
            String key;

            key = (String) it.next();
            if (ip.equals(key)) {
              if (it.hasNext()) // 如果有下一个,发送end+nextip,让下一个IP接着发送
              {
                nextip = (String) it.next();
                System.out.println("@@@@ 发送完最后一个文件后,发送nextIP:  " + nextip);
                String infos = nextip;
                requestSyncFunction rsf = new requestSyncFunction(3, null, infos);
                rsf.start();
                break;
              } else // 如果找不到下一个说明这是savedMap中最后一个发送文件的,发完同步就结束了
              {
                // 将同步标志改回来,删除sync表
                System.out.println("本次同步结束了");
              }
            }
          }
          // 一个节点发完自己该发的最后一个文件后,且找到了下一个,对于这个结点来说,savedmap的使命就完成了,这时应该清空
          // 要不就和下一次同步的内容混了,
          FileSharing.savedMap.clear();
        }
      }

    } catch (SocketException e) {
      return;
    } catch (Exception e) {
      e.printStackTrace();
    }
    FileSharing.total_sending_length += messages.length;
    long end = System.currentTimeMillis();
    FileSharing.total_sending_timer += (end - start);

    String[] bb = sub_fileID.split("-");
    // FileSharing.writeLog("send-one-packet:"+bb[1]+"--"+bb[bb.length-1]+"---"+i+",
    //	"+(end-start)+"ms,	"+"\r\n");
  }
コード例 #6
0
  private QuickAction prepareFileAction(final SeafDirent dirent, boolean cacheExists) {
    final QuickAction mQuickAction = new QuickAction(mActivity);
    Resources resources = mActivity.getResources();
    ActionItem shareAction, downloadAction, updateAction, exportAction, renameAction, deleteAction;

    shareAction =
        new ActionItem(
            ACTION_ID_SHARE,
            resources.getString(R.string.file_action_share),
            resources.getDrawable(R.drawable.action_share));
    mQuickAction.addActionItem(shareAction);

    // deleteAction = new ActionItem(ACTION_ID_DELETE,
    //                               resources.getString(R.string.file_action_delete),
    //                               resources.getDrawable(R.drawable.action_delete));
    // mQuickAction.addActionItem(deleteAction);

    renameAction =
        new ActionItem(
            ACTION_ID_RENAME,
            resources.getString(R.string.file_action_rename),
            resources.getDrawable(R.drawable.action_rename));
    mQuickAction.addActionItem(renameAction);

    exportAction =
        new ActionItem(
            ACTION_ID_EXPORT,
            resources.getString(R.string.file_action_export),
            resources.getDrawable(R.drawable.action_export));
    mQuickAction.addActionItem(exportAction);

    if (cacheExists) {
      if (mActivity.hasRepoWritePermission()) {
        updateAction =
            new ActionItem(
                ACTION_ID_UPDATE,
                resources.getString(R.string.file_action_update),
                resources.getDrawable(R.drawable.action_update));
        mQuickAction.addActionItem(updateAction);
      }

    } else {
      downloadAction =
          new ActionItem(
              ACTION_ID_DOWNLOAD,
              resources.getString(R.string.file_action_download),
              resources.getDrawable(R.drawable.action_download));
      mQuickAction.addActionItem(downloadAction);
    }

    // setup the action item click listener
    mQuickAction.setOnActionItemClickListener(
        new QuickAction.OnActionItemClickListener() {
          @Override
          public void onItemClick(QuickAction quickAction, int pos, int actionId) {
            NavContext nav = mActivity.getNavContext();
            String repoName = nav.getRepoName();
            String repoID = nav.getRepoID();
            String dir = nav.getDirPath();
            String path = Utils.pathJoin(dir, dirent.name);
            DataManager dataManager = mActivity.getDataManager();
            String localPath = dataManager.getLocalRepoFile(repoName, repoID, path).getPath();
            switch (actionId) {
              case ACTION_ID_SHARE:
                mActivity.shareFile(repoID, path);
                break;
              case ACTION_ID_EXPORT:
                mActivity.exportFile(dirent.name);
                break;
              case ACTION_ID_DOWNLOAD:
                mActivity.onFileSelected(dirent);
                break;
              case ACTION_ID_UPDATE:
                mActivity.addUpdateTask(repoID, repoName, dir, localPath);
                break;
              case ACTION_ID_RENAME:
                mActivity.renameFile(repoID, repoName, path);
                break;
            }
          }
        });

    mQuickAction.mAnimateTrack(false);
    return mQuickAction;
  }