Esempio n. 1
0
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   MenuInflater inflater = mCoolReader.getMenuInflater();
   menu.clear();
   inflater.inflate(
       mList.isShortcutMode()
           ? R.menu.cr3_bookmark_shortcut_context_menu
           : R.menu.cr3_bookmark_context_menu,
       menu);
   AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
   if (mi != null) selectedItem = mi.position;
   Bookmark bm = mList.getSelectedBookmark();
   menu.setHeaderTitle(getContext().getString(R.string.context_menu_title_bookmark));
   for (int i = 0; i < menu.size(); i++) {
     MenuItem menuItem = menu.getItem(i);
     if (menuItem.getItemId() == R.id.bookmark_shortcut_goto
         || menuItem.getItemId() == R.id.bookmark_edit
         || menuItem.getItemId() == R.id.bookmark_delete) menuItem.setEnabled(bm != null);
     if (menuItem.getItemId() == R.id.bookmark_edit)
       menuItem.setEnabled(
           bm != null
               && (bm.getType() == Bookmark.TYPE_COMMENT
                   || bm.getType() == Bookmark.TYPE_CORRECTION));
     menuItem.setOnMenuItemClickListener(
         new OnMenuItemClickListener() {
           public boolean onMenuItemClick(MenuItem item) {
             onContextItemSelected(item);
             return true;
           }
         });
   }
 }
Esempio n. 2
0
 private void initCacheDirectory() {
   String cacheDirName = null;
   // SD card
   cacheDirName = createCacheDir(Environment.getExternalStorageDirectory(), CACHE_BASE_DIR_NAME);
   // non-standard SD mount points
   if (cacheDirName == null) {
     for (String dirname : Scanner.SD_MOUNT_POINTS) {
       cacheDirName = createCacheDir(new File(dirname), CACHE_BASE_DIR_NAME);
       if (cacheDirName != null) break;
     }
   }
   // internal flash
   if (cacheDirName == null) {
     File cacheDir = mActivity.getCacheDir();
     if (!cacheDir.isDirectory()) cacheDir.mkdir();
     cacheDirName = createCacheDir(cacheDir, null);
     // File cacheDir = mActivity.getDir("cache", Context.MODE_PRIVATE);
     //			if (cacheDir.isDirectory() && cacheDir.canWrite())
     //				cacheDirName = cacheDir.getAbsolutePath();
   }
   // set cache directory for engine
   if (cacheDirName != null) {
     log.i(cacheDirName + " will be used for cache, maxCacheSize=" + CACHE_DIR_SIZE);
     synchronized (this) {
       setCacheDirectoryInternal(cacheDirName, CACHE_DIR_SIZE);
     }
   }
 }
Esempio n. 3
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   Log.v("cr3", "creating BookmarksDlg");
   setTitle(mCoolReader.getResources().getString(R.string.win_title_bookmarks));
   setCancelable(true);
   mInflater = LayoutInflater.from(getContext());
   super.onCreate(savedInstanceState);
   registerForContextMenu(mList);
   // mList.
 }
Esempio n. 4
0
 private void installLibrary() {
   try {
     if (force_install_library) throw new Exception("forcing install");
     // try loading library w/o manual installation
     log.i("trying to load library " + LIBRARY_NAME + " w/o installation");
     System.loadLibrary(LIBRARY_NAME);
     // try invoke native method
     // log.i("trying execute native method ");
     // setHyphenationMethod(HYPH_NONE, new byte[] {});
     log.i(LIBRARY_NAME + " loaded successfully");
   } catch (Exception ee) {
     log.i(SO_NAME + " not found using standard paths, will install manually");
     File sopath = mActivity.getDir("libs", Context.MODE_PRIVATE);
     File soname = new File(sopath, SO_NAME);
     try {
       sopath.mkdirs();
       File zip = new File(mActivity.getPackageCodePath());
       ZipFile zipfile = new ZipFile(zip);
       ZipEntry zipentry = zipfile.getEntry("lib/armeabi/" + SO_NAME);
       if (!soname.exists() || zipentry.getSize() != soname.length()) {
         InputStream is = zipfile.getInputStream(zipentry);
         OutputStream os = new FileOutputStream(soname);
         Log.i("cr3", "Installing JNI library " + soname.getAbsolutePath());
         final int BUF_SIZE = 0x10000;
         byte[] buf = new byte[BUF_SIZE];
         int n;
         while ((n = is.read(buf)) > 0) os.write(buf, 0, n);
         is.close();
         os.close();
       } else {
         log.i("JNI library " + soname.getAbsolutePath() + " is up to date");
       }
       System.load(soname.getAbsolutePath());
       // setHyphenationMethod(HYPH_NONE, new byte[] {});
     } catch (Exception e) {
       log.e("cannot install " + LIBRARY_NAME + " library", e);
     }
   }
 }
Esempio n. 5
0
 public void fatalError(String msg) {
   AlertDialog dlg =
       new AlertDialog.Builder(mActivity)
           .setMessage(msg)
           .setTitle("CoolReader fatal error")
           .show();
   try {
     Thread.sleep(10);
   } catch (InterruptedException e) {
     // do nothing
   }
   dlg.dismiss();
   mActivity.finish();
 }
Esempio n. 6
0
 public BookmarksDlg(CoolReader activity, ReaderView readerView) {
   super(activity, activity.getResources().getString(R.string.win_title_bookmarks), true, false);
   mThis = this; // for inner classes
   mInflater = LayoutInflater.from(getContext());
   mCoolReader = activity;
   mReaderView = readerView;
   mBookInfo = mReaderView.getBookInfo();
   setPositiveButtonImage(R.drawable.cr3_button_add, R.string.mi_bookmark_add);
   View frame = mInflater.inflate(R.layout.bookmark_list_dialog, null);
   ViewGroup body = (ViewGroup) frame.findViewById(R.id.bookmark_list);
   mList = new BookmarkList(activity, false);
   body.addView(mList);
   setView(frame);
   setFlingHandlers(mList, null, null);
 }
Esempio n. 7
0
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   MenuInflater inflater = mCoolReader.getMenuInflater();
   inflater.inflate(R.menu.cr3_bookmark_shortcut_context_menu, menu);
   AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
   if (mi != null) selectedItem = mi.position;
   menu.setHeaderTitle(getContext().getString(R.string.context_menu_title_bookmark));
   for (int i = 0; i < menu.size(); i++) {
     menu.getItem(i)
         .setOnMenuItemClickListener(
             new OnMenuItemClickListener() {
               public boolean onMenuItemClick(MenuItem item) {
                 onContextItemSelected(item);
                 return true;
               }
             });
   }
 }
Esempio n. 8
0
    public void runInternal() {
      connection = null;

      try {
        setProgressMessage(url.toString(), -1);
        long startTimeStamp = System.currentTimeMillis();
        delayedProgress =
            coolReader.getEngine().showProgressDelayed(0, progressMessage, PROGRESS_DELAY_MILLIS);
        URLConnection conn = url.openConnection();
        if (conn instanceof HttpsURLConnection) {
          onError("HTTPs is not supported yet");
          return;
        }
        if (!(conn instanceof HttpURLConnection)) {
          onError("Only HTTP supported");
          return;
        }
        connection = (HttpURLConnection) conn;
        connection.setRequestProperty("User-Agent", "CoolReader/3(Android)");
        if (referer != null) connection.setRequestProperty("Referer", referer);
        connection.setInstanceFollowRedirects(true);
        connection.setAllowUserInteraction(false);
        connection.setConnectTimeout(20000);
        connection.setReadTimeout(40000);
        connection.setDoInput(true);
        String fileName = null;
        String disp = connection.getHeaderField("Content-Disposition");
        if (disp != null) {
          int p = disp.indexOf("filename=");
          if (p > 0) {
            fileName = disp.substring(p + 9);
          }
        }
        // connection.setDoOutput(true);
        // connection.set

        int response = -1;

        response = connection.getResponseCode();
        L.d("Response: " + response);
        if (response != 200) {
          onError("Error " + response);
          return;
        }
        String contentType = connection.getContentType();
        String contentEncoding = connection.getContentEncoding();
        int contentLen = connection.getContentLength();
        // connection.getC
        L.d("Entity content length: " + contentLen);
        L.d("Entity content type: " + contentType);
        L.d("Entity content encoding: " + contentEncoding);
        setProgressMessage(url.toString(), contentLen);
        InputStream is = connection.getInputStream();
        delayedProgress.cancel();
        is = new ProgressInputStream(is, startTimeStamp, progressMessage, contentLen, 80);
        final int MAX_CONTENT_LEN_TO_BUFFER = 256 * 1024;
        boolean isZip = contentType != null && contentType.equals("application/zip");
        if (expectedType != null) contentType = expectedType;
        else if (contentLen > 0 && contentLen < MAX_CONTENT_LEN_TO_BUFFER) { // autodetect type
          byte[] buf = new byte[contentLen];
          if (is.read(buf) != contentLen) {
            onError("Wrong content length");
            return;
          }
          is.close();
          is = null;
          is = new ByteArrayInputStream(buf);
          if (findSubstring(buf, "<?xml version=") >= 0 && findSubstring(buf, "<feed") >= 0)
            contentType = "application/atom+xml"; // override type
        }
        if (contentType.startsWith("application/atom+xml")) {
          L.d("Parsing feed");
          parseFeed(is);
        } else {
          if (fileName == null) fileName = defaultFileName;
          L.d("Downloading book: " + contentEncoding);
          downloadBook(contentType, url.toString(), is, contentLen, fileName, isZip);
        }
      } catch (Exception e) {
        L.e("Exception while trying to open URI " + url.toString(), e);
        onError("Error occured while reading OPDS catalog");
      } finally {
        if (connection != null)
          try {
            connection.disconnect();
          } catch (Exception e) {
            // ignore
          }
      }
    }
Esempio n. 9
0
 private void setProgressMessage(String url, int totalSize) {
   progressMessage =
       coolReader.getString(org.coolreader.R.string.progress_downloading) + " " + url;
   if (totalSize > 0) progressMessage = progressMessage + " (" + totalSize + ")";
 }
Esempio n. 10
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {

    int shortcut = selectedItem; // mList.getSelectedItemPosition();
    Bookmark bm = mList.getSelectedBookmark();
    if (mList.isShortcutMode()) {
      if (shortcut >= 0 && shortcut < SHORTCUT_COUNT) {
        switch (item.getItemId()) {
          case R.id.bookmark_shortcut_add:
            mReaderView.addBookmark(shortcut + 1);
            listUpdated();
            dismiss();
            return true;
          case R.id.bookmark_delete:
            if (mReaderView.removeBookmark(bm) != null) listUpdated();
            return true;
          case R.id.bookmark_shortcut_goto:
            mReaderView.goToBookmark(shortcut + 1);
            dismiss();
            return true;
        }
      }
      return super.onContextItemSelected(item);
    }
    switch (item.getItemId()) {
      case R.id.bookmark_add:
        mReaderView.addBookmark(0);
        listUpdated();
        dismiss();
        return true;
      case R.id.bookmark_delete:
        if (mReaderView.removeBookmark(bm) != null) listUpdated();
        return true;
      case R.id.bookmark_goto:
        if (bm != null) mReaderView.goToBookmark(bm);
        dismiss();
        return true;
      case R.id.bookmark_edit:
        if (bm != null
            && (bm.getType() == Bookmark.TYPE_COMMENT
                || bm.getType() == Bookmark.TYPE_CORRECTION)) {
          BookmarkEditDialog dlg = new BookmarkEditDialog(mCoolReader, mReaderView, bm, false);
          dlg.show();
        }
        dismiss();
        return true;
      case R.id.bookmark_export:
        if (mBookInfo.getBookmarkCount() > 0) {
          FileInfo fi = mBookInfo.getFileInfo();
          String s = fi.getPathName();
          s = s.replace(FileInfo.ARC_SEPARATOR, "_");
          s = s + ".bmk.txt";
          if (mBookInfo.exportBookmarks(s))
            mCoolReader.showToast(
                getContext().getString(R.string.toast_bookmark_export_ok) + " " + s);
          else
            mCoolReader.showToast(
                getContext().getString(R.string.toast_bookmark_export_failed) + " " + s);
        }
        dismiss();
        return true;
      case R.id.bookmark_send:
        if (mBookInfo.getBookmarkCount() > 0) {
          String s = mBookInfo.getBookmarksExportText();
          mCoolReader.sendBookFragment(mBookInfo, s);
        }
        dismiss();
        return true;
    }
    return super.onContextItemSelected(item);
  }
Esempio n. 11
0
 private boolean addMountRoot(Map<String, String> list, String pathname, int resourceId) {
   return addMountRoot(list, pathname, mActivity.getResources().getString(resourceId));
 }
Esempio n. 12
0
 // public void setProgressDrawable( final BitmapDrawable drawable )
 // {
 // if ( enable_progress ) {
 // mBackgroundThread.executeGUI( new Runnable() {
 // public void run() {
 // // show progress
 // log.v("showProgress() - in GUI thread");
 // if ( mProgress!=null && progressShown ) {
 // hideProgress();
 // progressIcon = drawable;
 // showProgress(mProgressPos, mProgressMessage);
 // //mProgress.setIcon(drawable);
 // }
 // }
 // });
 // }
 // }
 public void showProgress(final int mainProgress, final int resourceId) {
   showProgress(mainProgress, mActivity.getResources().getString(resourceId));
 }