List of usage examples for android.util SparseArray get
public E get(int key)
null
if no such mapping has been made. From source file:org.akvo.caddisfly.helper.TestConfigHelper.java
/** * Creates the json result containing the results for test. * @param testInfo information about the test * @param results the results for the test * @param color the color extracted//from w w w . ja va2 s .com * @param resultImageUrl the url of the image * @param groupingType type of grouping * @return the result in json format */ public static JSONObject getJsonResult(TestInfo testInfo, SparseArray<String> results, int color, String resultImageUrl, StripTest.GroupType groupingType) { JSONObject resultJson = new JSONObject(); try { resultJson.put(SensorConstants.TYPE, SensorConstants.TYPE_NAME); resultJson.put(SensorConstants.NAME, testInfo.getName()); resultJson.put(SensorConstants.UUID, testInfo.getId()); JSONArray resultsJsonArray = new JSONArray(); for (TestInfo.SubTest subTest : testInfo.getSubTests()) { JSONObject subTestJson = new JSONObject(); subTestJson.put(SensorConstants.NAME, subTest.getDesc()); subTestJson.put(SensorConstants.UNIT, subTest.getUnit()); subTestJson.put(SensorConstants.ID, subTest.getId()); // If a result exists for the sub test id then add it if (results.size() >= subTest.getId()) { subTestJson.put(SensorConstants.VALUE, results.get(subTest.getId())); } if (color > -1) { subTestJson.put("resultColor", Integer.toHexString(color & BIT_MASK)); // Add calibration details to result subTestJson.put("calibratedDate", testInfo.getCalibrationDateString()); subTestJson.put("reagentExpiry", testInfo.getExpiryDateString()); subTestJson.put("reagentBatch", testInfo.getBatchNumber()); JSONArray calibrationSwatches = new JSONArray(); for (Swatch swatch : testInfo.getSwatches()) { calibrationSwatches.put(Integer.toHexString(swatch.getColor() & BIT_MASK)); } subTestJson.put("calibration", calibrationSwatches); } resultsJsonArray.put(subTestJson); if (groupingType == StripTest.GroupType.GROUP) { break; } } resultJson.put(SensorConstants.RESULT, resultsJsonArray); if (!resultImageUrl.isEmpty()) { resultJson.put(SensorConstants.IMAGE, resultImageUrl); } // Add current date to result resultJson.put("testDate", new SimpleDateFormat(SensorConstants.DATE_TIME_FORMAT, Locale.US) .format(Calendar.getInstance().getTime())); // Add user preference details to the result resultJson.put(SensorConstants.USER, TestConfigHelper.getUserPreferences()); // Add app details to the result resultJson.put(SensorConstants.APP, TestConfigHelper.getAppDetails()); // Add standard diagnostic details to the result resultJson.put(SensorConstants.DEVICE, TestConfigHelper.getDeviceDetails()); } catch (JSONException e) { Timber.e(e); } return resultJson; }
From source file:it.unicaradio.android.activities.MainActivity.java
private void initTabs() { Tabs tabsContainer = (Tabs) findViewById(R.id.tabs); SparseArray<Tab> tabs = Tabs.getTabs(tabsContainer); tabs.get(TabSelectedListener.getCurrentTab()).setSelected(true); setupListeners(tabs);/*from w ww . j a v a2 s. co m*/ }
From source file:de.skubware.opentraining.activity.settings.sync.WgerImageDownloader.java
/** * Download the missing images from wger. If an image already exists Open * Training assumes that the exercise is duplicate and will remove it from * the download list.//from ww w . java 2s. co m */ public ArrayList<ExerciseType> downloadImages(List<ExerciseType.Builder> exerciseBuilderList) throws IOException, JSONException { ArrayList<ExerciseType> newExerciseList = new ArrayList<ExerciseType>(); // add label to be able to break/continue from inner loop outerloop: for (ExerciseType.Builder exBuilder : exerciseBuilderList) { List<File> newImagePathList = new ArrayList<File>(); Map<File, License> newImageLicenseMap = new HashMap<File, License>(); ExerciseType ex = exBuilder.build(); for (File img : ex.getImagePaths()) { String imageAsJSON = mClient.get(img.getPath() + "/"); // get image name JSONObject imageJSONObject = new JSONObject(imageAsJSON); String imageDownloadPath = imageJSONObject.getString("image"); // parse JSON and get license SparseArray<LicenseType> licenseSparseArray = WgerJSONParser.parseLicenses(mLicenseJSONString); int licenseNumber = WgerJSONParser.getLastNumberOfJson(imageJSONObject.getString("license")); LicenseType licenseType = licenseSparseArray.get(licenseNumber); String author = imageJSONObject.getString("license_author"); Log.v(TAG, "license=" + licenseType.toString() + " license_author=" + author); License license = new License(licenseType, author); //String licensePath = imageJSONObject.getString("license"); // skip exercise (and image download) if there's already one with the same name DataHelper dataHelper = new DataHelper(mContext); String imageName = (new File(imageDownloadPath)).getName(); if (dataHelper.drawableExist(imageName)) { Log.d(TAG, "There's already an image with the same name as: " + imageDownloadPath + ". The exercise: " + ex.getLocalizedName() + " is propably duplicate, it will not be added."); continue outerloop; } else { // only download image if its name is unique imageName = downloadImageToSyncedImagesFolder(imageDownloadPath); // imageName may change! } // add image name + license to list/map File imageFile = new File(imageName); newImagePathList.add(imageFile); newImageLicenseMap.put(imageFile, license); } // set collected values for builder, add new object to exercise list exBuilder.imagePath(newImagePathList); exBuilder.imageLicenseMap(newImageLicenseMap); newExerciseList.add(exBuilder.build()); } return newExerciseList; }
From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java
public String[] update(Class<?> clazz, int oldVersion, int newVersion) { SparseArray<List<String>> versionUpdates = new SparseArray<>(); versionUpdates.put(-1, new ArrayList<String>()); for (int i = oldVersion + 1; i <= newVersion; i++) { versionUpdates.put(i, new ArrayList<String>()); }//from w w w .j a v a 2 s.c o m if (!doesTableExists(clazz)) { versionUpdates.get(-1).add(create(clazz)); } else { versionUpdates.get(-1).addAll(createTableUpdates(clazz)); } collectTableUpdatesAnnotations(versionUpdates, clazz); collectFieldUpdatesAnnotations(versionUpdates, clazz); return StringArrayUtils.toArray(versionUpdates); }
From source file:com.tmall.wireless.tangram.dataparser.concrete.PojoGroupBasicAdapter.java
@Override protected void diffGroup(SparseArray<Card> added, SparseArray<Card> removed) { for (int i = 0, size = removed.size(); i < size; i++) { int key = removed.keyAt(i); Card card = removed.get(key); if (card != null) { card.removed();//from w w w. ja va2s .c o m } } for (int i = 0, size = added.size(); i < size; i++) { int key = added.keyAt(i); Card card = added.get(key); if (card != null) { card.added(); } } }
From source file:com.teocci.utubinbg.BackgroundAudioService.java
/** * Extracts link from youtube video ID, so mediaPlayer can play it *///w ww . j a v a2 s. c o m private void extractUrlAndPlay() { final String youtubeLink = "http://youtube.com/watch?v=" + videoItem.getId(); YouTubeUriExtractor ytEx = new YouTubeUriExtractor(this) { @Override public void onUrisAvailable(String videoId, String videoTitle, SparseArray<YtFile> ytFiles) { if (ytFiles != null) { YtFile ytFile = ytFiles.get(YOUTUBE_ITAG_140); if (ytFile == null) { ytFile = ytFiles.get(YOUTUBE_ITAG_18); } try { Log.d(TAG, "Start playback"); if (mMediaPlayer != null) { mMediaPlayer.reset(); mMediaPlayer.setDataSource(ytFile.getUrl()); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.prepare(); mMediaPlayer.start(); } } catch (IOException io) { io.printStackTrace(); } } } }; ytEx.execute(youtubeLink); }
From source file:com.abid_mujtaba.fetchheaders.MainActivity.java
private void speak_emails() { for (int ii = 0; ii < Account.numberOfAccounts(); ii++) { Account account = Account.get(ii); SparseArray<Email> emails = account.emails(); int num_emails = emails.size(); if (account.num_unseen_emails() > 0) { speak(account); // Speak Account name for (int jj = 0; jj < num_emails; jj++) { Email email = emails.get(jj); if (!email.seen()) { speak(email);//from w w w . ja va 2s . c o m } } } } }
From source file:com.cryart.sabbathschool.ui.activity.SSMainActivity.java
@Override public void onScrollChanged(int deltaX, int deltaY, int scrollY) { _SSHero.setTranslationY(scrollY * 0.5f); int headerHeight = _SSHero.getHeight() - _SSToolbar.getHeight() - _SSStatusBar.getHeight(); float ratio = (float) Math.min(Math.max(scrollY * -1, 0), headerHeight) / headerHeight; setToolbarStatusBarAlpha((int) (ratio * 255)); int scrollOtherFragments = scrollY * -1; if (_SSTabs.getTop() + scrollY < _SSToolbar.getHeight() + _SSStatusBar.getHeight()) { _SSTabs.setY(_SSToolbar.getHeight() + _SSStatusBar.getHeight()); scrollOtherFragments = _SSTabs.getBottom() - (_SSToolbar.getHeight() + _SSStatusBar.getHeight() + _SSTabs.getHeight()); } else {/*from ww w .j a v a 2 s. c o m*/ _SSTabs.setTranslationY(scrollY); } SparseArray<Fragment> registeredFragments = ((SSTabsAdapter) _SSPager.getAdapter()).registeredFragments; for (int i = 0; i < registeredFragments.size(); i++) { if (i == _SSPager.getCurrentItem()) continue; ((SSWebViewFragment) (registeredFragments.get(i)))._SSWebView._SSOnScrollChangedCallbackEnabled = false; ((SSWebViewFragment) (registeredFragments.get(i)))._SSWebView.scrollTo(0, scrollOtherFragments); ((SSWebViewFragment) (registeredFragments.get(i)))._SSWebView._SSOnScrollChangedCallbackEnabled = true; } }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
private ColorStateList getTintListFromCache(@NonNull Context context, @DrawableRes int resId) { if (mTintLists != null) { final SparseArray<ColorStateList> tints = mTintLists.get(context); return tints != null ? tints.get(resId) : null; }/* w w w . j a v a 2s . c om*/ return null; }
From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java
private LineData getData() { ArrayList<ILineDataSet> dataSets = new ArrayList<>(); final SparseArray<Pair<Date, Double>> sparseArray = JobCheckpointsContract.getHourlyReport(mDataType); if (mDataType == DataType.WEEK) { final SparseArray<SparseArray<Double>> weeksDays = groupValues(sparseArray, 0, Calendar.DAY_OF_WEEK); if (weeksDays.size() > 0) { final Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); final int startValue = calendar.get(Calendar.DAY_OF_WEEK); dataSets.add(getData(0, "", weeksDays.get(weeksDays.keyAt(0)), startValue)); }//from w ww. jav a2 s.c o m } else if (mDataType == DataType.MONTH) { final SparseArray<SparseArray<Double>> weeksInMonth = groupValues(sparseArray, Calendar.WEEK_OF_YEAR, Calendar.DAY_OF_WEEK); for (int i = 0; i < weeksInMonth.size(); i++) { final String label = getString(R.string.chart_week_label, i + 1); dataSets.add(getData(i, label, weeksInMonth.get(weeksInMonth.keyAt(i)), 0)); } } else if (mDataType == DataType.ALL_TIME) { final SparseArray<SparseArray<Double>> years = groupValues(sparseArray, Calendar.YEAR, Calendar.YEAR); if (years.size() > 0) { dataSets.add(getData(0, "", years.get(years.keyAt(0)), 0)); } } return new LineData(dataSets); }