/* Scan the files in the new directory, and store them in the filelist.
   * Update the UI by refreshing the list adapter.
   */
  private void loadDirectory(String newdirectory) {
    if (newdirectory.equals("../")) {
      try {
        directory = new File(directory).getParent();
      } catch (Exception e) {
      }
    } else {
      directory = newdirectory;
    }
    SharedPreferences.Editor editor = getPreferences(0).edit();
    editor.putString("lastBrowsedDirectory", directory);
    editor.commit();
    directoryView.setText(directory);

    filelist = new ArrayList<FileUri>();
    ArrayList<FileUri> sortedDirs = new ArrayList<FileUri>();
    ArrayList<FileUri> sortedFiles = new ArrayList<FileUri>();
    if (!newdirectory.equals(rootdir)) {
      String parentDirectory = new File(directory).getParent() + "/";
      Uri uri = Uri.parse("file://" + parentDirectory);
      sortedDirs.add(new FileUri(uri, parentDirectory));
    }
    try {
      File dir = new File(directory);
      File[] files = dir.listFiles();
      if (files != null) {
        for (File file : files) {
          if (file == null) {
            continue;
          }
          String filename = file.getName();
          if (file.isDirectory()) {
            Uri uri = Uri.parse("file://" + file.getAbsolutePath() + "/");
            FileUri fileuri = new FileUri(uri, uri.getPath());
            sortedDirs.add(fileuri);
          } else if (filename.endsWith(".mid")
              || filename.endsWith(".MID")
              || filename.endsWith(".midi")
              || filename.endsWith(".MIDI")) {

            Uri uri = Uri.parse("file://" + file.getAbsolutePath());
            FileUri fileuri = new FileUri(uri, uri.getLastPathSegment());
            sortedFiles.add(fileuri);
          }
        }
      }
    } catch (Exception e) {
    }

    if (sortedDirs.size() > 0) {
      Collections.sort(sortedDirs, sortedDirs.get(0));
    }
    if (sortedFiles.size() > 0) {
      Collections.sort(sortedFiles, sortedFiles.get(0));
    }
    filelist.addAll(sortedDirs);
    filelist.addAll(sortedFiles);
    adapter = new IconArrayAdapter<FileUri>(this, android.R.layout.simple_list_item_1, filelist);
    this.setListAdapter(adapter);
  }
Esempio n. 2
0
  /** @return */
  public static String getIPv4Address() {
    String ipv4address = null;

    try {
      final List<NetworkInterface> networkinterfaces =
          Collections.list(NetworkInterface.getNetworkInterfaces());
      for (final NetworkInterface networkinterface : networkinterfaces) {
        final List<InetAddress> addresses = Collections.list(networkinterface.getInetAddresses());
        for (final InetAddress address : addresses) {
          if ((address == null) || address.isLoopbackAddress()) {
            continue;
          }
          if (address instanceof Inet4Address) {
            ipv4address = address.getHostAddress().toString();
            break;
          }
        }
      }
    } catch (Exception x) {
      DBG.m(x);
    }

    return ipv4address;
  }
Esempio n. 3
0
  @Override
  public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    Thread.setDefaultUncaughtExceptionHandler(
        new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));

    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);

    final TabHost host = getTabHost();
    LayoutInflater.from(this).inflate(R.layout.bookmarks, host.getTabContentView(), true);

    AllBooksBookmarks = Bookmark.bookmarks();
    Collections.sort(AllBooksBookmarks, new Bookmark.ByTimeComparator());
    final FBReader fbreader = (FBReader) FBReader.Instance();

    if (fbreader.Model != null) {
      final long bookId = fbreader.Model.Book.getId();
      for (Bookmark bookmark : AllBooksBookmarks) {
        if (bookmark.getBookId() == bookId) {
          myThisBookBookmarks.add(bookmark);
        }
      }

      myThisBookView = createTab("thisBook", R.id.this_book);
      new BookmarksAdapter(myThisBookView, myThisBookBookmarks, true);
    } else {
      findViewById(R.id.this_book).setVisibility(View.GONE);
    }

    myAllBooksView = createTab("allBooks", R.id.all_books);
    new BookmarksAdapter(myAllBooksView, AllBooksBookmarks, false);

    findViewById(R.id.search_results).setVisibility(View.GONE);
  }
Esempio n. 4
0
 public List<Bookmark> bookmarks() {
   return Collections.unmodifiableList(myBookmarks);
 }
Esempio n. 5
0
  private final class BookmarksAdapter extends BaseAdapter
      implements AdapterView.OnItemClickListener, View.OnCreateContextMenuListener {
    private final List<Bookmark> myBookmarks =
        Collections.synchronizedList(new LinkedList<Bookmark>());
    private final boolean myShowAddBookmarkItem;

    BookmarksAdapter(ListView listView, boolean showAddBookmarkItem) {
      myShowAddBookmarkItem = showAddBookmarkItem;
      listView.setAdapter(this);
      listView.setOnItemClickListener(this);
      listView.setOnCreateContextMenuListener(this);
    }

    public List<Bookmark> bookmarks() {
      return Collections.unmodifiableList(myBookmarks);
    }

    public void addAll(final List<Bookmark> bookmarks) {
      runOnUiThread(
          new Runnable() {
            public void run() {
              synchronized (myBookmarks) {
                for (Bookmark b : bookmarks) {
                  final int position = Collections.binarySearch(myBookmarks, b, myComparator);
                  if (position < 0) {
                    myBookmarks.add(-position - 1, b);
                  }
                }
              }
              notifyDataSetChanged();
            }
          });
    }

    public void add(final Bookmark b) {
      runOnUiThread(
          new Runnable() {
            public void run() {
              synchronized (myBookmarks) {
                final int position = Collections.binarySearch(myBookmarks, b, myComparator);
                if (position < 0) {
                  myBookmarks.add(-position - 1, b);
                }
              }
              notifyDataSetChanged();
            }
          });
    }

    public void remove(final Bookmark b) {
      runOnUiThread(
          new Runnable() {
            public void run() {
              myBookmarks.remove(b);
              notifyDataSetChanged();
            }
          });
    }

    public void clear() {
      runOnUiThread(
          new Runnable() {
            public void run() {
              myBookmarks.clear();
              notifyDataSetChanged();
            }
          });
    }

    public void onCreateContextMenu(
        ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
      final int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
      if (getItem(position) != null) {
        menu.setHeaderTitle(getItem(position).getText());
        menu.add(0, OPEN_ITEM_ID, 0, myResource.getResource("open").getValue());
        // menu.add(0, EDIT_ITEM_ID, 0, myResource.getResource("edit").getValue());
        menu.add(0, DELETE_ITEM_ID, 0, myResource.getResource("delete").getValue());
      }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      final View view =
          (convertView != null)
              ? convertView
              : LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.bookmark_item, parent, false);
      final ImageView imageView = ViewUtil.findImageView(view, R.id.bookmark_item_icon);
      final TextView textView = ViewUtil.findTextView(view, R.id.bookmark_item_text);
      final TextView bookTitleView = ViewUtil.findTextView(view, R.id.bookmark_item_booktitle);

      final Bookmark bookmark = getItem(position);
      if (bookmark == null) {
        imageView.setVisibility(View.VISIBLE);
        imageView.setImageResource(R.drawable.ic_list_plus);
        textView.setText(myResource.getResource("new").getValue());
        bookTitleView.setVisibility(View.GONE);
      } else {
        imageView.setVisibility(View.GONE);
        textView.setText(bookmark.getText());
        if (myShowAddBookmarkItem) {
          bookTitleView.setVisibility(View.GONE);
        } else {
          bookTitleView.setVisibility(View.VISIBLE);
          bookTitleView.setText(bookmark.getBookTitle());
        }
      }
      return view;
    }

    @Override
    public final boolean areAllItemsEnabled() {
      return true;
    }

    @Override
    public final boolean isEnabled(int position) {
      return true;
    }

    @Override
    public final long getItemId(int position) {
      return position;
    }

    @Override
    public final Bookmark getItem(int position) {
      if (myShowAddBookmarkItem) {
        --position;
      }
      return (position >= 0) ? myBookmarks.get(position) : null;
    }

    @Override
    public final int getCount() {
      return myShowAddBookmarkItem ? myBookmarks.size() + 1 : myBookmarks.size();
    }

    public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      final Bookmark bookmark = getItem(position);
      if (bookmark != null) {
        gotoBookmark(bookmark);
      } else {
        addBookmark();
      }
    }
  }
 /**
  * Returns the list of detected codecs.
  *
  * @return the list of detected codecs.
  */
 public static List<CodecInfo> getSupportedCodecs() {
   return Collections.unmodifiableList(codecs);
 }