This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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())) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun auctionPhotos_CreationGalleryClickUI() { | |
CameraAndGallery.savePickedImage(mActivityTestRule.activity) | |
val imgGalleryResult = CameraAndGallery.createImageGallerySetResultStub(mActivityTestRule.activity) | |
intending(hasAction(Intent.ACTION_CHOOSER)).respondWith(imgGalleryResult) | |
auctionPhotos_CreationInitialUI() | |
onView(withId(R.id.auctionphotos_button_gallery)).perform(click()) | |
onView(withId(R.id.auctionphotos_bigimage_viewer)).check(matches(hasImageSet())) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |