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 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(); }
@Override public final Bookmark getItem(int position) { if (myShowAddBookmarkItem) { --position; } return (position >= 0) ? myBookmarks.get(position) : null; }
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"); } }
@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; }
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); } } } }
@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 void startUpload(int index) { if (NavigineApp.Navigation == null) return; String userHash = NavigineApp.Settings.getString("user_hash", ""); if (userHash.length() == 0) return; LocationInfo info = mInfoList.get(index); String location = new String(info.title); Log.d(TAG, String.format(Locale.ENGLISH, "Start upload: %s", location)); synchronized (mLoaderMap) { if (!mLoaderMap.containsKey(location)) { LoaderState loader = new LoaderState(); loader.location = location; loader.type = UPLOAD; loader.id = LocationLoader.startLocationUploader(location, info.archiveFile, true); mLoaderMap.put(location, loader); } } mAdapter.updateList(); }
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); } }
private void selectItem(int index) { _info = mInfoList.get(index); if (!(new File(_info.archiveFile)).exists()) { String text = String.format( Locale.ENGLISH, "Location '%s' cannot be selected!\n" + "Please, download location first!", _info.title); Toast.makeText(mContext, text, Toast.LENGTH_LONG).show(); return; } AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext); alertBuilder.setTitle(String.format(Locale.ENGLISH, "Location '%s'", _info.title)); alertBuilder.setNegativeButton( "Delete location", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int id) { deleteLocation(_info); } }); alertBuilder.setPositiveButton( "Select location", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int id) { selectLocation(_info); } }); AlertDialog dialog = alertBuilder.create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); }
public void nextLevel() { boolean loaded = false; final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard); this.level++; AssetManager am = getResources().getAssets(); try { List<String> allTutoLevels = new LinkedList<String>(Arrays.asList(am.list("levels/tutorial"))); // if(addMsg){ // allTutoLevels.addAll(Arrays.asList(am.list("msg"))); // } Log.d(TAG, allTutoLevels.toString()); for (String name : allTutoLevels) { if (name.startsWith(this.level + ".")) { BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/tutorial/" + name))); String line; String levelJSON = ""; while ((line = br.readLine()) != null) { levelJSON += line + "\n"; } br.close(); game.initGame( levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); loaded = true; } } } catch (IOException e) { e.printStackTrace(); } if (!loaded) { Random r = new Random(); List<String> allLevels = new ArrayList<>(); try { allLevels = Arrays.asList(am.list("levels")); } catch (IOException e) { } if (r.nextBoolean() && !allLevels.isEmpty() && allLevels.size() != allDoneLevels.size()) { try { int nLevel; do { nLevel = r.nextInt(allLevels.size()); } while (allDoneLevels.contains(allLevels.get(nLevel))); String name = allLevels.get(nLevel); BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/" + name))); String line; String levelJSON = ""; while ((line = br.readLine()) != null) { levelJSON += line + "\n"; } br.close(); allDoneLevels.add(name); game.initGame( levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } catch (IOException e) { this.game.initGame( level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } } else { this.game.initGame( level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } } // am.close(); boardView.setGame(this.game); boardView.invalidate(); boardView.getHowdyShadeView().invalidate(); Toast.makeText(this, this.level + "", Toast.LENGTH_SHORT).show(); Log.i( TAG, "Max tiles : " + (boardView.getMeasuredWidth() / 60) * (boardView.getMeasuredHeight() / 60)); }
private boolean doSelectDate(Date date, MonthCellDescriptor cell) { Calendar newlySelectedCal = Calendar.getInstance(locale); newlySelectedCal.setTime(date); // Sanitize input: clear out the hours/minutes/seconds/millis. setMidnight(newlySelectedCal); // Clear any remaining range state. for (MonthCellDescriptor selectedCell : selectedCells) { selectedCell.setRangeState(RangeState.NONE); } switch (selectionMode) { case RANGE: if (selectedCals.size() > 1) { // We've already got a range selected: clear the old one. clearOldSelections(); } else if (selectedCals.size() == 1 && newlySelectedCal.before(selectedCals.get(0))) { // We're moving the start of the range back in time: clear the // old start date. clearOldSelections(); } break; case MULTIPLE: date = applyMultiSelect(date, newlySelectedCal); break; case SINGLE: clearOldSelections(); break; default: throw new IllegalStateException("Unknown selectionMode " + selectionMode); } if (date != null) { // Select a new cell. if (selectedCells.size() == 0 || !selectedCells.get(0).equals(cell)) { selectedCells.add(cell); cell.setSelected(true); } selectedCals.add(newlySelectedCal); if (selectionMode == SelectionMode.RANGE && selectedCells.size() > 1) { // Select all days in between start and end. Date start = selectedCells.get(0).getDate(); Date end = selectedCells.get(1).getDate(); selectedCells.get(0).setRangeState(MonthCellDescriptor.RangeState.FIRST); selectedCells.get(1).setRangeState(MonthCellDescriptor.RangeState.LAST); for (List<List<MonthCellDescriptor>> month : cells) { for (List<MonthCellDescriptor> week : month) { for (MonthCellDescriptor singleCell : week) { if (singleCell.getDate().after(start) && singleCell.getDate().before(end) && singleCell.isSelectable()) { singleCell.setSelected(true); singleCell.setRangeState(MonthCellDescriptor.RangeState.MIDDLE); selectedCells.add(singleCell); } } } } } } // Update the adapter. validateAndUpdate(); return date != null; }
public Date getSelectedDate() { return (selectedCals.size() > 0 ? selectedCals.get(0).getTime() : null); }
public final Bookmark getItem(int position) { if (myCurrentBook) { --position; } return (position >= 0) ? myBookmarks.get(position) : null; }