List<List<MonthCellDescriptor>> getMonthCells(MonthDescriptor month, Calendar startCal) {
    Calendar cal = Calendar.getInstance(locale);
    cal.setTime(startCal.getTime());
    List<List<MonthCellDescriptor>> cells = new ArrayList<List<MonthCellDescriptor>>();
    cal.set(DAY_OF_MONTH, 1);
    int firstDayOfWeek = cal.get(DAY_OF_WEEK);
    int offset = cal.getFirstDayOfWeek() - firstDayOfWeek;
    if (offset > 0) {
      offset -= 7;
    }
    cal.add(Calendar.DATE, offset);

    Calendar minSelectedCal = minDate(selectedCals);
    Calendar maxSelectedCal = maxDate(selectedCals);

    while ((cal.get(MONTH) < month.getMonth() + 1 || cal.get(YEAR) < month.getYear()) //
        && cal.get(YEAR) <= month.getYear()) {
      Logr.d("Building week row starting at %s", cal.getTime());
      List<MonthCellDescriptor> weekCells = new ArrayList<MonthCellDescriptor>();
      cells.add(weekCells);
      for (int c = 0; c < 7; c++) {
        Date date = cal.getTime();
        boolean isCurrentMonth = cal.get(MONTH) == month.getMonth();
        boolean isSelected = isCurrentMonth && containsDate(selectedCals, cal);
        boolean isSelectable =
            isCurrentMonth && betweenDates(cal, minCal, maxCal) && isDateSelectable(date);
        boolean isToday = sameDate(cal, today);
        boolean isHighlighted = containsDate(highlightedCals, cal);
        int value = cal.get(DAY_OF_MONTH);

        MonthCellDescriptor.RangeState rangeState = MonthCellDescriptor.RangeState.NONE;
        if (selectedCals.size() > 1) {
          if (sameDate(minSelectedCal, cal)) {
            rangeState = MonthCellDescriptor.RangeState.FIRST;
          } else if (sameDate(maxDate(selectedCals), cal)) {
            rangeState = MonthCellDescriptor.RangeState.LAST;
          } else if (betweenDates(cal, minSelectedCal, maxSelectedCal)) {
            rangeState = MonthCellDescriptor.RangeState.MIDDLE;
          }
        }

        weekCells.add(
            new MonthCellDescriptor(
                date,
                isCurrentMonth,
                isSelectable,
                isSelected,
                isToday,
                isHighlighted,
                value,
                rangeState));
        cal.add(DATE, 1);
      }
    }
    return cells;
  }
Esempio n. 2
0
  private void updateLocalVersions() {
    if (NavigineApp.Navigation == null) return;

    for (int i = 0; i < mInfoList.size(); ++i) {
      LocationInfo info = mInfoList.get(i);
      String versionStr = LocationLoader.getLocalVersion(NavigineApp.AppContext, info.title);
      if (versionStr != null) {
        // Log.d(TAG, info.title + ": " + versionStr);
        info.localModified = versionStr.endsWith("+");
        if (info.localModified) versionStr = versionStr.substring(0, versionStr.length() - 1);
        try {
          info.localVersion = Integer.parseInt(versionStr);
        } catch (Throwable e) {
        }
      } else {
        info.localVersion = -1;

        String mapFile = NavigineApp.Settings.getString("map_file", "");
        if (mapFile.equals(info.archiveFile)) {
          NavigineApp.Navigation.loadArchive(null);
          SharedPreferences.Editor editor = NavigineApp.Settings.edit();
          editor.putString("map_file", "");
          editor.commit();
        }
      }
    }
    mAdapter.updateList();
  }
Esempio n. 3
0
 public void run() {
   if (myBook != null) {
     for (BookmarkQuery query = new BookmarkQuery(myBook, 20); ; query = query.next()) {
       final List<Bookmark> thisBookBookmarks = myCollection.bookmarks(query);
       if (thisBookBookmarks.isEmpty()) {
         break;
       }
       myThisBookAdapter.addAll(thisBookBookmarks);
       myAllBooksAdapter.addAll(thisBookBookmarks);
     }
   }
   for (BookmarkQuery query = new BookmarkQuery(20); ; query = query.next()) {
     final List<Bookmark> allBookmarks = myCollection.bookmarks(query);
     if (allBookmarks.isEmpty()) {
       break;
     }
     myAllBooksAdapter.addAll(allBookmarks);
   }
   runOnUiThread(
       new Runnable() {
         public void run() {
           setProgressBarIndeterminateVisibility(false);
         }
       });
 }
 private static Calendar maxDate(List<Calendar> selectedCals) {
   if (selectedCals == null || selectedCals.size() == 0) {
     return null;
   }
   Collections.sort(selectedCals);
   return selectedCals.get(selectedCals.size() - 1);
 }
 private void setResultIds(Item item, int index) {
   if (item != null && item instanceof CatalogItem) {
     CatalogItem catalogItem = (CatalogItem) item;
     if (catalogItem.IsChecked) {
       int insertIndex = index <= 0 ? -1 : (index - 1);
       if (mySelectedItems.contains(catalogItem)) {
         mySelectedItems.remove(catalogItem);
       }
       if (insertIndex >= 0) {
         mySelectedItems.add(insertIndex, catalogItem);
       } else {
         mySelectedItems.add(catalogItem);
       }
     } else {
       mySelectedItems.remove(catalogItem);
     }
     final ArrayList<String> ids = new ArrayList<String>();
     for (Item selectedItem : mySelectedItems) {
       if (selectedItem instanceof CatalogItem) {
         final CatalogItem ci = (CatalogItem) selectedItem;
         if (ci.IsChecked) {
           ids.add(ci.Id);
         }
       }
     }
     setResult(
         RESULT_OK,
         new Intent()
             .putStringArrayListExtra(NetworkLibraryActivity.ENABLED_CATALOG_IDS_KEY, ids));
   }
 }
 public List<Date> getSelectedDates() {
   List<Date> selectedDates = new ArrayList<Date>();
   for (MonthCellDescriptor cal : selectedCells) {
     selectedDates.add(cal.getDate());
   }
   Collections.sort(selectedDates);
   return selectedDates;
 }
 private void clearOldSelections() {
   for (MonthCellDescriptor selectedCell : selectedCells) {
     // De-select the currently-selected cell.
     selectedCell.setSelected(false);
   }
   selectedCells.clear();
   selectedCals.clear();
 }
Esempio n. 8
0
 @Override
 public int getSectionForPosition(int position) {
   SectionAndItem<T> sectionAndItem = getSectionAndItem(position);
   if (sectionAndItem != null && sectionAndItem.getType() != SectionAndItem.Type.ACTIVITY_CIRCLE) {
     return Math.max(
         0, Math.min(sectionKeys.indexOf(sectionAndItem.sectionKey), sectionKeys.size() - 1));
   }
   return 0;
 }
Esempio n. 9
0
 @Override
 public int getPositionForSection(int section) {
   if (displaySections) {
     section = Math.max(0, Math.min(section, sectionKeys.size() - 1));
     if (section < sectionKeys.size()) {
       return getPosition(sectionKeys.get(section), null);
     }
   }
   return 0;
 }
Esempio n. 10
0
  public List parsePage(String pageCode) {
    List sections = new ArrayList();
    List folders = new ArrayList();
    List files = new ArrayList();
    int start = pageCode.indexOf("<div id=\"list-view\" class=\"view\"");
    int end = pageCode.indexOf("<div id=\"gallery-view\" class=\"view\"");
    String usefulSection = "";
    if (start != -1 && end != -1) {
      usefulSection = pageCode.substring(start, end);
    } else {
      debug("Could not parse page");
    }
    try {
      DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      InputSource is = new InputSource();
      is.setCharacterStream(new StringReader(usefulSection));
      Document doc = db.parse(is);

      NodeList divs = doc.getElementsByTagName("div");
      for (int i = 0; i < divs.getLength(); i++) {
        Element div = (Element) divs.item(i);
        boolean isFolder = false;
        if (div.getAttribute("class").equals("filename")) {
          NodeList imgs = div.getElementsByTagName("img");
          for (int j = 0; j < imgs.getLength(); j++) {
            Element img = (Element) imgs.item(j);
            if (img.getAttribute("class").indexOf("folder") > 0) {
              isFolder = true;
            } else {
              isFolder = false; // it's a file
            }
          }

          NodeList anchors = div.getElementsByTagName("a");
          Element anchor = (Element) anchors.item(0);
          String attr = anchor.getAttribute("href");
          String fileName = anchor.getAttribute("title");
          String fileURL;
          if (isFolder && !attr.equals("#")) {
            folders.add(attr);
            folders.add(fileName);
          } else if (!isFolder && !attr.equals("#")) {
            // Dropbox uses ajax to get the file for download, so the url isn't enough. We must be
            // sneaky here.
            fileURL = "https://dl.dropbox.com" + attr.substring(23) + "?dl=1";
            files.add(fileURL);
            files.add(fileName);
          }
        }
      }
    } catch (Exception e) {
      debug(e.toString());
    }

    sections.add(files);
    sections.add(folders);

    return sections;
  }
Esempio n. 11
0
 void showSearchResultsTab(LinkedList<Bookmark> results) {
   if (mySearchResultsView == null) {
     mySearchResultsView = createTab("searchResults", R.id.search_results);
     new BookmarksAdapter(mySearchResultsView, mySearchResults, false);
   } else {
     mySearchResults.clear();
   }
   mySearchResults.addAll(results);
   mySearchResultsView.invalidateViews();
   mySearchResultsView.requestLayout();
   getTabHost().setCurrentTabByTag("searchResults");
 }
Esempio n. 12
0
  private void rebuildSections() {
    sectionKeys = new ArrayList<String>();
    graphObjectsBySection = new HashMap<String, ArrayList<T>>();
    graphObjectsById = new HashMap<String, T>();
    displaySections = false;

    if (cursor == null || cursor.getCount() == 0) {
      return;
    }

    int objectsAdded = 0;
    cursor.moveToFirst();
    do {
      T graphObject = cursor.getGraphObject();

      if (!filterIncludesItem(graphObject)) {
        continue;
      }

      objectsAdded++;

      String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject);
      if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) {
        sectionKeys.add(sectionKeyOfItem);
        graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<T>());
      }
      List<T> section = graphObjectsBySection.get(sectionKeyOfItem);
      section.add(graphObject);

      graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject);
    } while (cursor.moveToNext());

    if (sortFields != null) {
      final Collator collator = Collator.getInstance();
      for (List<T> section : graphObjectsBySection.values()) {
        Collections.sort(
            section,
            new Comparator<GraphObject>() {
              @Override
              public int compare(GraphObject a, GraphObject b) {
                return compareGraphObjects(a, b, sortFields, collator);
              }
            });
      }
    }

    Collections.sort(sectionKeys, Collator.getInstance());

    displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD;
  }
Esempio n. 13
0
 @Override
 public final Bookmark getItem(int position) {
   if (myShowAddBookmarkItem) {
     --position;
   }
   return (position >= 0) ? myBookmarks.get(position) : null;
 }
Esempio n. 14
0
  public void prioritizeViewRange(int firstVisibleItem, int lastVisibleItem, int prefetchBuffer) {
    if ((lastVisibleItem < firstVisibleItem) || (sectionKeys.size() == 0)) {
      return;
    }

    // We want to prioritize requests for items which are visible but do not have pictures
    // loaded yet. We also want to pre-fetch pictures for items which are not yet visible
    // but are within a buffer on either side of the visible items, on the assumption that
    // they will be visible soon. For these latter items, we'll store the images in memory
    // in the hopes we can immediately populate their image view when needed.

    // Prioritize the requests in reverse order since each call to prioritizeRequest will just
    // move it to the front of the queue. And we want the earliest ones in the range to be at
    // the front of the queue, so all else being equal, the list will appear to populate from
    // the top down.
    for (int i = lastVisibleItem; i >= 0; i--) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        String id = getIdOfGraphObject(sectionAndItem.graphObject);
        ImageRequest request = pendingRequests.get(id);
        if (request != null) {
          ImageDownloader.prioritizeRequest(request);
        }
      }
    }

    // For items which are not visible, but within the buffer on either side, we want to
    // fetch those items and store them in a small in-memory cache of bitmaps.
    int start = Math.max(0, firstVisibleItem - prefetchBuffer);
    int end = Math.min(lastVisibleItem + prefetchBuffer, getCount() - 1);
    ArrayList<T> graphObjectsToPrefetchPicturesFor = new ArrayList<T>();
    // Add the IDs before and after the visible range.
    for (int i = start; i < firstVisibleItem; ++i) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        graphObjectsToPrefetchPicturesFor.add(sectionAndItem.graphObject);
      }
    }
    for (int i = lastVisibleItem + 1; i <= end; ++i) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        graphObjectsToPrefetchPicturesFor.add(sectionAndItem.graphObject);
      }
    }
    for (T graphObject : graphObjectsToPrefetchPicturesFor) {
      URI uri = getPictureUriOfGraphObject(graphObject);
      final String id = getIdOfGraphObject(graphObject);

      // This URL already have been requested for pre-fetching, but we want to act in an LRU manner,
      // so move
      // it to the end of the list regardless.
      boolean alreadyPrefetching = prefetchedProfilePictureIds.remove(id);
      prefetchedProfilePictureIds.add(id);

      // If we've already requested it for pre-fetching, no need to do so again.
      if (!alreadyPrefetching) {
        downloadProfilePicture(id, uri, null);
      }
    }
  }
Esempio n. 15
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);
    }
  }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   if (months.isEmpty()) {
     throw new IllegalStateException(
         "Must have at least one month to display.  Did you forget to call init()?");
   }
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Esempio n. 17
0
 @Override
 public Object[] getSections() {
   if (displaySections) {
     return sectionKeys.toArray();
   } else {
     return new Object[0];
   }
 }
Esempio n. 18
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    c = this;
    preferences = PreferenceManager.getDefaultSharedPreferences(c);

    super.onCreate(savedInstanceState);

    setContentView(R.layout.gpu_sgx540);

    gpuCurrent = readFile(Constants.GPU_SGX540);
    seekGpu = (SeekBar) findViewById(R.id.seek_gpu);

    gpu = Arrays.asList(153, 307, 384);
    seekBar(gpu.size() - 1, gpu.indexOf(gpuCurrent));

    /*else{
    seekGpu.setEnabled(false);
    seekIva.setEnabled(false);
    TextView ns = (TextView)findViewById(R.id.not_supported);
    ns.setVisibility(View.VISIBLE);
    }*/
    preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    curGpuTxt = (TextView) findViewById(R.id.current_gpu);
    maxGpuTxt = (TextView) findViewById(R.id.max_gpu);
    minGpuTxt = (TextView) findViewById(R.id.min_gpu);

    mhz = getResources().getString(R.string.mhz);
    current = getResources().getString(R.string.current);
    max = getResources().getString(R.string._max);
    min = getResources().getString(R.string._min);
    curGpuTxt.setText(current + ": " + (gpuCurrent) + mhz);
    maxGpuTxt.setText(max + ": " + gpu.get(2) + mhz);
    minGpuTxt.setText(min + ": " + gpu.get(0) + mhz);

    Button cancel = (Button) findViewById(R.id.cancel);
    cancel.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            finish();
          }
        });
  }
 private Date applyMultiSelect(Date date, Calendar selectedCal) {
   for (MonthCellDescriptor selectedCell : selectedCells) {
     if (selectedCell.getDate().equals(date)) {
       // De-select the currently-selected cell.
       selectedCell.setSelected(false);
       selectedCells.remove(selectedCell);
       date = null;
       break;
     }
   }
   for (Calendar cal : selectedCals) {
     if (sameDate(cal, selectedCal)) {
       selectedCals.remove(cal);
       break;
     }
   }
   return date;
 }
Esempio n. 20
0
  private void addBookmark() {
    final FBReader fbreader = (FBReader) FBReader.Instance();
    final ZLTextView textView = fbreader.getTextView();
    final ZLTextWordCursor cursor = textView.getStartCursor();

    if (cursor.isNull()) {
      // TODO: implement
      return;
    }

    // TODO: text edit dialog
    final Bookmark bookmark =
        new Bookmark(
            fbreader.Model.Book, createBookmarkText(cursor), textView.getModel().getId(), cursor);
    myThisBookBookmarks.add(0, bookmark);
    AllBooksBookmarks.add(0, bookmark);
    invalidateAllViews();
  }
  public void highlightDates(Collection<Date> dates) {
    for (Date date : dates) {
      validateDate(date);

      MonthCellWithMonthIndex monthCellWithMonthIndex = getMonthCellWithIndexByDate(date);
      if (monthCellWithMonthIndex != null) {
        Calendar newlyHighlightedCal = Calendar.getInstance();
        newlyHighlightedCal.setTime(date);
        MonthCellDescriptor cell = monthCellWithMonthIndex.cell;

        highlightedCells.add(cell);
        highlightedCals.add(newlyHighlightedCal);
        cell.setHighlighted(true);
      }
    }

    adapter.notifyDataSetChanged();
    setAdapter(adapter);
  }
  @Override
  public void onStart() {
    super.onStart();
    if (D) Log.d(TAG, "++ ON START ++");

    if (!mBluetoothAdapter.isEnabled()) {
      // ask the user to enable BlueTooth
      Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
      startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
    } else {
      // this only works if you already bonded with this device
      if (D) Log.d(TAG, "BT already enabled");

      final BluetoothDevice[] bondedDevices =
          new BluetoothDevice[mBluetoothAdapter.getBondedDevices().size()];
      mBluetoothAdapter.getBondedDevices().toArray(bondedDevices);

      List<CharSequence> devices = new ArrayList<CharSequence>();

      // update the "Select device" spinner
      for (BluetoothDevice btd : bondedDevices) {
        Log.d(TAG, "Found bonded device: " + btd.getName());
        devices.add(btd.getName());
      }

      ArrayAdapter spinnerAdapter =
          new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, devices);
      spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

      Spinner selectDeviceSpinner = (Spinner) findViewById(R.id.spinner);
      selectDeviceSpinner.setAdapter(spinnerAdapter);

      selectDeviceSpinner.setOnItemSelectedListener(
          new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
              if (D) Log.d(TAG, "Selected: " + bondedDevices[pos].getName());
              btDevice = bondedDevices[pos];
            }

            public void onNothingSelected(AdapterView<?> arg0) {}
          });
    }
  }
Esempio n. 23
0
  @Override
  public int getCount() {
    if (sectionKeys.size() == 0) {
      return 0;
    }

    // If we are not displaying sections, we don't display a header; otherwise, we have one header
    // per item in
    // addition to the actual items.
    int count = (displaySections) ? sectionKeys.size() : 0;
    for (List<T> section : graphObjectsBySection.values()) {
      count += section.size();
    }

    // If we should show a cell with an activity circle indicating more data is coming, add it to
    // the count.
    if (shouldShowActivityCircleCell()) {
      ++count;
    }

    return count;
  }
  @Override
  protected void onStart() {
    super.onStart();

    myAllItems.clear();

    final Intent intent = getIntent();

    myAllItems.add(new SectionItem("enabled"));
    final List<String> enabledIds =
        intent.getStringArrayListExtra(NetworkLibraryActivity.ENABLED_CATALOG_IDS_KEY);
    if (enabledIds.size() > 0) {
      final TreeSet<CatalogItem> cItems = new TreeSet<CatalogItem>();
      for (String id : enabledIds) {
        final NetworkTree tree = NetworkLibrary.Instance().getCatalogTreeByUrlAll(id);
        if (tree != null && tree.getLink() != null) {
          cItems.add(new CatalogItem(id, true, tree));
        }
      }
      myAllItems.addAll(cItems);
      mySelectedItems.addAll(cItems);
    }

    myAllItems.add(new SectionItem("disabled"));
    final List<String> disabledIds =
        intent.getStringArrayListExtra(NetworkLibraryActivity.DISABLED_CATALOG_IDS_KEY);
    if (disabledIds.size() > 0) {
      final TreeSet<CatalogItem> cItems = new TreeSet<CatalogItem>();
      for (String id : disabledIds) {
        cItems.add(
            new CatalogItem(id, false, NetworkLibrary.Instance().getCatalogTreeByUrlAll(id)));
      }
      myAllItems.addAll(cItems);
    }

    setListAdapter(new CatalogsListAdapter());
  }
Esempio n. 25
0
  SectionAndItem<T> getSectionAndItem(int position) {
    if (sectionKeys.size() == 0) {
      return null;
    }
    String sectionKey = null;
    T graphObject = null;

    if (!displaySections) {
      sectionKey = sectionKeys.get(0);
      List<T> section = graphObjectsBySection.get(sectionKey);
      if (position >= 0 && position < section.size()) {
        graphObject = graphObjectsBySection.get(sectionKey).get(position);
      } else {
        // We are off the end; we must be adding an activity circle to indicate more data is coming.
        assert dataNeededListener != null && cursor.areMoreObjectsAvailable();
        // We return null for both to indicate this.
        return new SectionAndItem<T>(null, null);
      }
    } else {
      // Count through the sections; the "0" position in each section is the header. We decrement
      // position each time we skip forward a certain number of elements, including the header.
      for (String key : sectionKeys) {
        // Decrement if we skip over the header
        if (position-- == 0) {
          sectionKey = key;
          break;
        }

        List<T> section = graphObjectsBySection.get(key);
        if (position < section.size()) {
          // The position is somewhere in this section. Get the corresponding graph object.
          sectionKey = key;
          graphObject = section.get(position);
          break;
        }
        // Decrement by as many items as we skipped over
        position -= section.size();
      }
    }
    if (sectionKey != null) {
      // Note: graphObject will be null if this represents a section header.
      return new SectionAndItem<T>(sectionKey, graphObject);
    } else {
      throw new IndexOutOfBoundsException("position");
    }
  }
  /** Initializes "select account" spinner with existing accounts. */
  private void initAccountSpinner() {
    Spinner accountsSpiner = (Spinner) findViewById(R.id.selectAccountSpinner);

    Iterator<ProtocolProviderService> providers = AccountUtils.getRegisteredProviders().iterator();

    List<AccountID> accounts = new ArrayList<AccountID>();

    int selectedIdx = -1;
    int idx = 0;

    while (providers.hasNext()) {
      ProtocolProviderService provider = providers.next();

      OperationSet opSet = provider.getOperationSet(OperationSetPresence.class);

      if (opSet == null) continue;

      AccountID account = provider.getAccountID();
      accounts.add(account);
      idx++;

      if (account.isPreferredProvider()) {
        selectedIdx = idx;
      }
    }

    AccountsListAdapter accountsAdapter =
        new AccountsListAdapter(
            this, R.layout.select_account_row, R.layout.select_account_dropdown, accounts, true);
    accountsSpiner.setAdapter(accountsAdapter);

    // if we have only select account option and only one account
    // select the available account
    if (accounts.size() == 1) accountsSpiner.setSelection(0);
    else accountsSpiner.setSelection(selectedIdx);
  }
 private void scrollToSelectedDates() {
   Integer selectedIndex = null;
   Integer todayIndex = null;
   Calendar today = Calendar.getInstance(locale);
   for (int c = 0; c < months.size(); c++) {
     MonthDescriptor month = months.get(c);
     if (selectedIndex == null) {
       for (Calendar selectedCal : selectedCals) {
         if (sameMonth(selectedCal, month)) {
           selectedIndex = c;
           break;
         }
       }
       if (selectedIndex == null && todayIndex == null && sameMonth(today, month)) {
         todayIndex = c;
       }
     }
   }
   if (selectedIndex != null) {
     scrollToSelectedMonth(selectedIndex);
   } else if (todayIndex != null) {
     scrollToSelectedMonth(todayIndex);
   }
 }
Esempio n. 28
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   final int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;
   final ListView view = (ListView) getTabHost().getCurrentView();
   final Bookmark bookmark = ((BookmarksAdapter) view.getAdapter()).getItem(position);
   switch (item.getItemId()) {
     case OPEN_ITEM_ID:
       gotoBookmark(bookmark);
       return true;
     case EDIT_ITEM_ID:
       final Intent intent = new Intent(this, BookmarkEditActivity.class);
       startActivityForResult(intent, 1);
       // TODO: implement
       return true;
     case DELETE_ITEM_ID:
       bookmark.delete();
       myThisBookBookmarks.remove(bookmark);
       AllBooksBookmarks.remove(bookmark);
       mySearchResults.remove(bookmark);
       invalidateAllViews();
       return true;
   }
   return super.onContextItemSelected(item);
 }
Esempio n. 29
0
  private void updateLoader() {
    if (NavigineApp.Navigation == null) return;

    // Log.d(TAG, String.format(Locale.ENGLISH, "Update loader: %d", mLoader));

    long timeNow = DateTimeUtils.currentTimeMillis();
    if (mLoader < 0) return;

    int status = LocationLoader.checkLocationLoader(mLoader);
    if (status < 100) {
      if ((Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT / 3 && status == 0)
          || (Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT)) {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText("Loading timeout!\nPlease, check your internet connection!");
        Log.d(TAG, String.format(Locale.ENGLISH, "Load stopped on timeout!"));
        LocationLoader.stopLocationLoader(mLoader);
        mLoader = -1;
      } else {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText(String.format(Locale.ENGLISH, "Loading content (%d%%)", status));
      }
    } else {
      Log.d(TAG, String.format(Locale.ENGLISH, "Load finished with result: %d", status));
      LocationLoader.stopLocationLoader(mLoader);
      mLoader = -1;

      if (status == 100) {
        parseMapsXml();
        if (mInfoList.isEmpty()) {
          mListView.setVisibility(View.GONE);
          mStatusLabel.setVisibility(View.VISIBLE);
          mStatusLabel.setText("No locations available");
        } else {
          mListView.setVisibility(View.VISIBLE);
          mStatusLabel.setVisibility(View.GONE);
        }
      } else {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText("Error loading!\nPlease, check your ID!");
      }
    }
  }
Esempio n. 30
0
  public void getFilesFromFolder(List filesAndFolders, String savePath) {
    // create a File object for the parent directory
    File downloadsDirectory = new File(savePath);
    // create the folder if needed.
    downloadsDirectory.mkdir();

    for (int i = 0; i < filesAndFolders.size(); i++) {
      Object links = filesAndFolders.get(i);
      List linksArray = (ArrayList) links;
      if (i == 0) {
        for (int j = 0; j < linksArray.size(); j += 2) {
          // We've got an array of file urls so download each one to a directory with the folder
          // name
          String fileURL = linksArray.get(j).toString();
          String fileName = linksArray.get(j + 1).toString();
          downloadFile(fileURL, savePath, fileName);
          progress++;
          Message msg = mHandler.obtainMessage();
          msg.arg1 = progress;
          mHandler.sendMessage(msg);
        }
      } else if (i == 1) {
        // we've got an array of folders so recurse down the levels, extracting subfolders and files
        // until we've downloaded everything.
        for (int j = 0; j < linksArray.size(); j += 2) {
          String folderURL = linksArray.get(j).toString();
          String folderName = linksArray.get(j + 1).toString();

          String page = getData(folderURL);
          List newFilesAndFolders = parsePage(page);
          String dlDirPath = savePath + folderName + "/";

          getFilesFromFolder(newFilesAndFolders, dlDirPath);
        }
      }
    }
  }