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 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(); }
public static List<String> GetListeners() { List<String> listeners = new ArrayList<String>(); listeners.add("gps"); listeners.add("network"); listeners.add("passive"); return listeners; }
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; }
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"); }
@Override public final Bookmark getItem(int position) { if (myShowAddBookmarkItem) { --position; } return (position >= 0) ? myBookmarks.get(position) : null; }
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 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 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(); }
private void getAccountInfo() { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); String id = sharedPref.getString("id", ""); if (!TextUtils.isEmpty(id)) { accountBean = DatabaseManager.getInstance().getAccount(id); if (accountBean != null) { token = accountBean.getAccess_token(); getActionBar().setSubtitle(accountBean.getUsernick()); } else { List<AccountBean> accountList = DatabaseManager.getInstance().getAccountList(); if (accountList != null && accountList.size() > 0) { AccountBean account = accountList.get(0); accountBean = account; token = account.getAccess_token(); getActionBar().setSubtitle(account.getUsernick()); } } } }
@Override public void onReceive(Context context, Intent intent) { final ArrayList<PluginApi.ActionInfo> actions = getResultExtras(true) .<PluginApi.ActionInfo>getParcelableArrayList(PluginApi.PluginInfo.KEY); if (actions != null) { synchronized (myPluginActions) { final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance(); int index = 0; while (index < myPluginActions.size()) { fbReader.removeAction(PLUGIN_ACTION_PREFIX + index++); } myPluginActions.addAll(actions); index = 0; for (PluginApi.ActionInfo info : myPluginActions) { fbReader.addAction( PLUGIN_ACTION_PREFIX + index++, new RunPluginAction(FBReader.this, fbReader, info.getId())); } } } }
@Override public void onStart() { super.onStart(); final ZLAndroidApplication application = (ZLAndroidApplication) getApplication(); final int fullScreenFlag = application.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN; if (fullScreenFlag != myFullScreenFlag) { finish(); startActivity(new Intent(this, getClass())); } final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance(); final RelativeLayout root = (RelativeLayout) findViewById(R.id.root_view); ((PopupPanel) fbReader.getPopupById(TextSearchPopup.ID)) .createControlPanel(this, root, PopupWindow.Location.Bottom); ((PopupPanel) fbReader.getPopupById(NavigationPopup.ID)) .createControlPanel(this, root, PopupWindow.Location.Bottom); ((PopupPanel) fbReader.getPopupById(SelectionPopup.ID)) .createControlPanel(this, root, PopupWindow.Location.Floating); synchronized (myPluginActions) { int index = 0; while (index < myPluginActions.size()) { fbReader.removeAction(PLUGIN_ACTION_PREFIX + index++); } myPluginActions.clear(); } sendOrderedBroadcast( new Intent(PluginApi.ACTION_REGISTER), null, myPluginInfoReceiver, null, RESULT_OK, null, null); }
@Override protected Void doInBackground(Void... params) { Map<String, String> emotions = GlobalContext.getInstance().getEmotions(); List<String> index = new ArrayList<String>(); index.addAll(emotions.keySet()); for (String str : index) { if (!isCancelled()) { String url = emotions.get(str); String path = FileManager.getFileAbsolutePathFromUrl(url, FileLocationMethod.emotion); String name = new File(path).getName(); AssetManager assetManager = GlobalContext.getInstance().getAssets(); InputStream inputStream; try { inputStream = assetManager.open(name); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); emotionsPic.put(str, bitmap); } catch (IOException ignored) { } } } return null; }
@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); }
@Override protected String doInBackground(Void... params) { Geocoder geocoder = new Geocoder(WriteWeiboActivity.this, Locale.getDefault()); List<Address> addresses = null; try { addresses = geocoder.getFromLocation(geoBean.getLat(), geoBean.getLon(), 1); } catch (IOException e) { cancel(true); } if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); StringBuilder builder = new StringBuilder(); int size = address.getMaxAddressLineIndex(); for (int i = 0; i < size; i++) { builder.append(address.getAddressLine(i)); } return builder.toString(); } return ""; }
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!"); } } }
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); } } } }
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(); }
@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); }
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 onCreate() { int flags, screenLightVal = 1; Sensor mSensor; List<Sensor> sensors; if (scanData == null) return; // no ScanData, not possible to run correctly... PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); try { screenLightVal = Integer.parseInt(SP.getString("screenLight", "2")); } catch (NumberFormatException nfe) { } if (screenLightVal == 1) flags = PowerManager.PARTIAL_WAKE_LOCK; else if (screenLightVal == 3) flags = PowerManager.FULL_WAKE_LOCK; else flags = PowerManager.SCREEN_DIM_WAKE_LOCK; wl = pm.newWakeLock(flags, "OpenWLANMap"); wl.acquire(); while (myWLocate == null) { try { myWLocate = new MyWLocate(this); break; } catch (IllegalArgumentException iae) { myWLocate = null; } try { Thread.sleep(100); } catch (InterruptedException ie) { } } try { scanData.setUploadThres(Integer.parseInt(SP.getString("autoUpload", "0"))); } catch (NumberFormatException nfe) { } try { scanData.setNoGPSExitInterval( Integer.parseInt(SP.getString("noGPSExitInterval", "0")) * 60 * 1000); } catch (NumberFormatException nfe) { } Intent intent = new Intent(this, OWMapAtAndroid.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0); notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon) .setContentTitle(getResources().getText(R.string.app_name)) .setContentText("") .setContentIntent(pendIntent) .build(); notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(1703, notification); getScanData().setService(this); getScanData().setmView(new HUDView(this)); getScanData().getmView().setValue(getScanData().incStoredValues()); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.LEFT | Gravity.BOTTOM; params.setTitle("Load Average"); WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(getScanData().getmView(), params); sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); sensorManager.registerListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); sensorManager.registerListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME); sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); mSensor = sensors.get(0); getScanData().getTelemetryData().setAccelMax(mSensor.getMaximumRange()); telemetryDir = Environment.getExternalStorageDirectory().getPath() + "/telemetry/"; File dir = new File(telemetryDir); dir.mkdir(); connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); }
/** 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); } }
@Override public final int getCount() { return myShowAddBookmarkItem ? myBookmarks.size() + 1 : myBookmarks.size(); }
/** * 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); } }
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)); }
public final int getCount() { return myCurrentBook ? myBookmarks.size() + 1 : myBookmarks.size(); }
public final Bookmark getItem(int position) { if (myCurrentBook) { --position; } return (position >= 0) ? myBookmarks.get(position) : null; }