Skip to content

Instantly share code, notes, and snippets.

View cdmunoz's full-sized avatar

Carlos Daniel cdmunoz

View GitHub Profile
fun createImageCaptureActivityResultStub(activity: Activity): Instrumentation.ActivityResult {
val bundle = Bundle()
bundle.putParcelable("IMG_DATA", BitmapFactory.decodeResource(activity.resources, R.mipmap.ic_launcher))
// Create the Intent that will include the bundle.
val resultData = Intent()
resultData.putExtras(bundle)
// Create the ActivityResult with the Intent.
return Instrumentation.ActivityResult(Activity.RESULT_OK, resultData)
}
@Test
fun auctionPhotos_CreationCameraClickUI() {
val imgCaptureResult = CameraAndGallery.createImageCaptureActivityResultStub(mActivityTestRule.activity)
intending(hasAction(MediaStore.ACTION_IMAGE_CAPTURE)).respondWith(imgCaptureResult)
auctionPhotos_CreationInitialUI()
onView(withId(R.id.auctionphotos_button_camera)).perform(click())
onView(withId(R.id.auctionphotos_bigimage_viewer)).check(matches(hasImageSet()))
}
fun savePickedImage(activity: Activity) {
val bm = BitmapFactory.decodeResource(activity.resources, R.mipmap.ic_launcher)
val dir = activity.externalCacheDir
val file = File(dir?.path, "pickImageResult.jpeg")
val outStream: FileOutputStream?
try {
outStream = FileOutputStream(file)
bm.compress(Bitmap.CompressFormat.JPEG, 100, outStream)
with(outStream) {
flush()
fun hasImageSet(): BoundedMatcher<View, ImageView> {
return object : BoundedMatcher<View, ImageView>(ImageView::class.java) {
override fun describeTo(description: Description) {
description.appendText("has image set.")
}
override fun matchesSafely(imageView: ImageView): Boolean {
return imageView.background != null
}
}
fun createImageGallerySetResultStub(activity: Activity): Instrumentation.ActivityResult {
val bundle = Bundle()
val parcels = ArrayList<Parcelable>()
val resultData = Intent()
val dir = activity.externalCacheDir
val file = File(dir?.path, "pickImageResult.jpeg")
val uri = Uri.fromFile(file)
val parcelable1 = uri as Parcelable
parcels.add(parcelable1)
bundle.putParcelableArrayList(Intent.EXTRA_STREAM, parcels)
@cdmunoz
cdmunoz / CountingSort1.kt
Created June 28, 2019 22:47
Output Format Output the number of times every number from through appears in as a list of space-separated integers on one line.
//Hackerrank's counting sort problem:
// https://www.hackerrank.com/challenges/countingsort1/problem
//Challenge
//Given a list of integers, count and output the number of times each value appears as a list of space-separated integers.
//Function Description:
//Complete the countingSort function in the editor below. It should return an array of integers where each value is the number of occurrences of the element's index value in the original array.
//countingSort has the following parameter(s):
// arr: an array of integers
//Output Format
//Output the number of times every number from 0 through 99 appears in arr as a list of space-separated integers on one line.
public class AuctionsFragment extends Fragment {
......
private void initViewModels() {
auctionsViewModel = ViewModelProviders.of(this).get(AuctionsViewModel.class);
}
private void initObservers() {
auctionsViewModel.getUploadAuction().observe(this, new Observer<Auction>() {
@Override
public void onChanged(Auction auction) {
if (null != auction) onAuctionToUpload(auction);
public class AuctionViewModel extends ViewModel {
private SingleLiveEvent<Auction> uploadAuction = new SingleLiveEvent<>();
public SingleLiveEvent<Auction> getUploadAuction() {
return uploadAuction;
}
public void onAuctionToUpload(Auction auction) {
uploadAuction.setValue(auction);
}
}
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software