/* 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);
  }
 private static Calendar maxDate(List<Calendar> selectedCals) {
   if (selectedCals == null || selectedCals.size() == 0) {
     return null;
   }
   Collections.sort(selectedCals);
   return selectedCals.get(selectedCals.size() - 1);
 }
 public List<Date> getSelectedDates() {
   List<Date> selectedDates = new ArrayList<Date>();
   for (MonthCellDescriptor cal : selectedCells) {
     selectedDates.add(cal.getDate());
   }
   Collections.sort(selectedDates);
   return selectedDates;
 }
Example #4
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;
  }
Example #5
0
  private void UploadToDropBox() {
    Utilities.LogDebug("GpsMainActivity.UploadToDropBox");

    final DropBoxHelper dropBoxHelper = new DropBoxHelper(getApplicationContext(), this);

    if (!dropBoxHelper.IsLinked()) {
      startActivity(new Intent("com.mendhak.gpslogger.DROPBOX_SETUP"));
      return;
    }

    final File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger");

    if (gpxFolder.exists()) {

      String[] enumeratedFiles = gpxFolder.list();
      List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
      Collections.reverse(fileList);
      final String[] files = fileList.toArray(new String[fileList.size()]);

      final Dialog dialog = new Dialog(this);
      dialog.setTitle(R.string.dropbox_upload);
      dialog.setContentView(R.layout.filelist);
      ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

      thelist.setAdapter(
          new ArrayAdapter<String>(
              getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

      thelist.setOnItemClickListener(
          new OnItemClickListener() {

            public void onItemClick(AdapterView<?> av, View v, int index, long arg) {

              dialog.dismiss();
              String chosenFileName = files[index];
              Utilities.ShowProgress(
                  GpsMainActivity.this,
                  getString(R.string.dropbox_uploading),
                  getString(R.string.please_wait));
              dropBoxHelper.UploadFile(chosenFileName);
            }
          });
      dialog.show();
    } else {
      Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
    }
  }
  private void runLanguageFilterDialog() {
    final NetworkLibrary library = NetworkLibrary.Instance();

    final List<String> allLanguageCodes = library.languageCodes();
    Collections.sort(allLanguageCodes, new ZLLanguageUtil.CodeComparator());
    final Collection<String> activeLanguageCodes = library.activeLanguageCodes();
    final CharSequence[] languageNames = new CharSequence[allLanguageCodes.size()];
    final boolean[] checked = new boolean[allLanguageCodes.size()];

    for (int i = 0; i < allLanguageCodes.size(); ++i) {
      final String code = allLanguageCodes.get(i);
      languageNames[i] = ZLLanguageUtil.languageName(code);
      checked[i] = activeLanguageCodes.contains(code);
    }

    final DialogInterface.OnMultiChoiceClickListener listener =
        new DialogInterface.OnMultiChoiceClickListener() {
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            checked[which] = isChecked;
          }
        };
    final ZLResource dialogResource = ZLResource.resource("dialog");
    final AlertDialog dialog =
        new AlertDialog.Builder(this)
            .setMultiChoiceItems(languageNames, checked, listener)
            .setTitle(
                dialogResource.getResource("languageFilterDialog").getResource("title").getValue())
            .setPositiveButton(
                dialogResource.getResource("button").getResource("ok").getValue(),
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    final TreeSet<String> newActiveCodes =
                        new TreeSet<String>(new ZLLanguageUtil.CodeComparator());
                    for (int i = 0; i < checked.length; ++i) {
                      if (checked[i]) {
                        newActiveCodes.add(allLanguageCodes.get(i));
                      }
                    }
                    library.setActiveLanguageCodes(newActiveCodes);
                    library.synchronize();
                    NetworkView.Instance().fireModelChanged();
                  }
                })
            .create();
    dialog.show();
  }
Example #7
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);
  }
Example #8
0
  /** Uploads a GPS Trace to OpenStreetMap.org. */
  private void UploadToOpenStreetMap() {
    Utilities.LogDebug("GpsMainactivity.UploadToOpenStreetMap");

    if (!OSMHelper.IsOsmAuthorized(getApplicationContext())) {
      startActivity(OSMHelper.GetOsmSettingsIntent(getApplicationContext()));
      return;
    }

    final String goToOsmSettings = getString(R.string.menu_settings);

    final File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger");

    if (gpxFolder.exists()) {
      FilenameFilter select =
          new FilenameFilter() {

            public boolean accept(File dir, String filename) {
              return filename.toLowerCase().contains(".gpx");
            }
          };

      String[] enumeratedFiles = gpxFolder.list(select);
      List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
      Collections.reverse(fileList);
      fileList.add(0, goToOsmSettings);
      final String[] files = fileList.toArray(new String[fileList.size()]);

      final Dialog dialog = new Dialog(this);
      dialog.setTitle(R.string.osm_pick_file);
      dialog.setContentView(R.layout.filelist);
      ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

      thelist.setAdapter(
          new ArrayAdapter<String>(
              getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

      thelist.setOnItemClickListener(
          new OnItemClickListener() {

            public void onItemClick(AdapterView<?> av, View v, int index, long arg) {

              dialog.dismiss();
              String chosenFileName = files[index];

              if (chosenFileName.equalsIgnoreCase(goToOsmSettings)) {
                startActivity(OSMHelper.GetOsmSettingsIntent(getApplicationContext()));
              } else {
                OSMHelper osm = new OSMHelper(GpsMainActivity.this, GpsMainActivity.this);
                Utilities.ShowProgress(
                    GpsMainActivity.this,
                    getString(R.string.osm_uploading),
                    getString(R.string.please_wait));
                osm.UploadGpsTrace(chosenFileName);
              }
            }
          });
      dialog.show();
    } else {
      Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
    }
  }
Example #9
0
  /**
   * Allows user to send a GPX/KML file along with location, or location only using a provider.
   * 'Provider' means any application that can accept such an intent (Facebook, SMS, Twitter, Email,
   * K-9, Bluetooth)
   */
  private void Share() {
    Utilities.LogDebug("GpsMainActivity.Share");
    try {

      final String locationOnly = getString(R.string.sharing_location_only);
      final File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger");
      if (gpxFolder.exists()) {
        String[] enumeratedFiles = gpxFolder.list();
        List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
        Collections.reverse(fileList);
        fileList.add(0, locationOnly);
        final String[] files = fileList.toArray(new String[fileList.size()]);

        final Dialog dialog = new Dialog(this);
        dialog.setTitle(R.string.sharing_pick_file);
        dialog.setContentView(R.layout.filelist);
        ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

        thelist.setAdapter(
            new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

        thelist.setOnItemClickListener(
            new OnItemClickListener() {

              public void onItemClick(AdapterView<?> av, View v, int index, long arg) {
                dialog.dismiss();
                String chosenFileName = files[index];

                final Intent intent = new Intent(Intent.ACTION_SEND);

                // intent.setType("text/plain");
                intent.setType("*/*");

                if (chosenFileName.equalsIgnoreCase(locationOnly)) {
                  intent.setType("text/plain");
                }

                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation));
                if (Session.hasValidLocation()) {
                  String bodyText =
                      getString(
                          R.string.sharing_latlong_text,
                          String.valueOf(Session.getCurrentLatitude()),
                          String.valueOf(Session.getCurrentLongitude()));
                  intent.putExtra(Intent.EXTRA_TEXT, bodyText);
                  intent.putExtra("sms_body", bodyText);
                }

                if (chosenFileName.length() > 0 && !chosenFileName.equalsIgnoreCase(locationOnly)) {
                  intent.putExtra(
                      Intent.EXTRA_STREAM, Uri.fromFile(new File(gpxFolder, chosenFileName)));
                }

                startActivity(Intent.createChooser(intent, getString(R.string.sharing_via)));
              }
            });
        dialog.show();
      } else {
        Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
      }
    } catch (Exception ex) {
      Utilities.LogError("Share", ex);
    }
  }
Example #10
0
 public List<Bookmark> bookmarks() {
   return Collections.unmodifiableList(myBookmarks);
 }
Example #11
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();
      }
    }
  }