Skip to content

Instantly share code, notes, and snippets.

Akbolat Sadvakassov iRYO400

Block or report user

Report or block iRYO400

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View [Espresso-3.11] Examples
// Spinner. Click->Select->Check
YourObject expectedText = YourObject.PIECE; // for example, if it's ENUM
onData(allOf(is(instanceOf(YourObject.class)), is(expectedText))).perform(click());
onView(withId(R.id.spinner)).check(matches(withSpinnerText(containsString(expectedText.name()))));
// Spinner. Click on Spinner by id-> then Select exact what you need by specifying expectedText
onView(withId(R.id.spinner))
.perform(click());
@iRYO400
iRYO400 / [Robolectric-4.0] Assert views
Last active Feb 4, 2019
#robolectric #robolectric4
View [Robolectric-4.0] Assert views
// Backgrounds of views
Drawable currentDrawable = textView.getBackground();
Drawable expectedDrawable = getApplicationContext().getDrawable(R.drawable.background_item_chip_yellow);
assertThat(shadowOf(currentDrawable).getCreatedFromResId()).isEqualTo(shadowOf(expectedDrawable).getCreatedFromResId());
// Colors of TextView
int expectedColor = ContextCompat.getColor(getApplicationContext(), R.color.text_blue);
assertThat(textView.getCurrentTextColor()).isEqualTo(expectedColor);
// Colors of Drawable backgrounds
@iRYO400
iRYO400 / Which one should I do?
Created Jan 24, 2019
Микромомент в юнит тестировании
View Which one should I do?
public void checkCalculation() {
Product product = new Product(10, 10);
String totalSum = model.calculateSum(product);
String expected = "100 руб."; // #1 способ
assertThat(totalSum).isEqualTo(expected); // #1 способ
int expectedValue = getString(R.string.total_sum, 100); // #2 способ
assertThat(totalSum).isEqualTo(expectedValue); // #2 способ
@iRYO400
iRYO400 / a_snippet3
Created Jul 24, 2018
A-snippet #3 Drawable to BitmapDescriptor
View a_snippet3
private fun bitmapDescriptorFromVector(vectorResId: Int, context: Context): BitmapDescriptor {
val vectorDrawable = ContextCompat.getDrawable(context, vectorResId)
vectorDrawable!!.setBounds(0, 0, vectorDrawable.intrinsicWidth, vectorDrawable.intrinsicHeight)
val bitmap = Bitmap.createBitmap(vectorDrawable.intrinsicWidth, vectorDrawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
vectorDrawable.draw(canvas)
return BitmapDescriptorFactory.fromBitmap(bitmap)
}
@iRYO400
iRYO400 / a_snippet2
Created Jul 17, 2018
A-snippet #2 - Relative time converting
View a_snippet2
const val TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" // eg. 2018-04-01T04:20:25.434Z
/**
* Time converting from any timestamp pattern to "5 minutes ago", "1 day ago", etc.
*/
fun convertTime(timestamp: String): String {
val mDataFormat: DateFormat = SimpleDateFormat(TIMESTAMP_PATTERN, Locale.ENGLISH)
return try {
val date = mDataFormat.parse(timestamp)
val relativeDateStr = DateUtils.getRelativeTimeSpanString(date.time, Calendar.getInstance().timeInMillis, DateUtils.MINUTE_IN_MILLIS)
@iRYO400
iRYO400 / a_snippet1_1.txt
Last active Jul 17, 2018
A-snippet #1 - Smoothing Marker rotating in Google Maps
View a_snippet1_1.txt
/**
* Smooth rotating my location marker arrow
* @param marker - marker itself
* @param newBearing - new direction to rotate
*/
private fun changeBearingSmoothly(marker: Marker?, newBearing: Float) {
if (marker == null) {
return
}
val animation = ValueAnimator.ofFloat(0f, 100f)
@iRYO400
iRYO400 / a_snippet1.txt
Last active Jul 17, 2018
A-snippet #1 - Smoothing Marker moving in Google Maps
View a_snippet1.txt
/**
* Smooth moving my location marker arrow
* @param marker - marker itself
* @param newLatLng - new location to move
*/
private fun changePositionSmoothly(marker: Marker?, newLatLng: LatLng) {
if (marker == null) {
return
}
val animation = ValueAnimator.ofFloat(0f, 100f)
You can’t perform that action at this time.