Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use falcon for screenshots in order to capture dialogs. #502

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext.versions = [
'minSdk': 9,
'minSdk': 10,
'compileSdk': 25,
'buildTools': '26.0.2',

Expand Down Expand Up @@ -45,7 +45,7 @@ buildscript {
]

dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta7'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
Expand Down
1 change: 1 addition & 0 deletions spoon-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ android {
dependencies {
compile project(':spoon-common')
compile deps.junit
compile 'com.jraska:falcon:1.0.4'

testCompile deps.truth
}
Expand Down
54 changes: 0 additions & 54 deletions spoon-client/src/main/java/com/squareup/spoon/Screenshot.java

This file was deleted.

4 changes: 3 additions & 1 deletion spoon-client/src/main/java/com/squareup/spoon/SpoonRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.graphics.Bitmap;
import android.util.Log;

import com.jraska.falcon.Falcon;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
Expand Down Expand Up @@ -66,7 +68,7 @@ public File screenshot(Activity activity, String tag) {
obtainDirectory(activity.getApplicationContext(), className, methodName, SPOON_SCREENSHOTS);
String screenshotName = System.currentTimeMillis() + NAME_SEPARATOR + tag + EXTENSION;
File screenshotFile = new File(screenshotDirectory, screenshotName);
Bitmap bitmap = Screenshot.capture(tag, activity);
Bitmap bitmap = Falcon.takeScreenshotBitmap(activity);
writeBitmapToFile(bitmap, screenshotFile);
Log.d(TAG, "Captured screenshot '" + tag + "'.");
return screenshotFile;
Expand Down
4 changes: 2 additions & 2 deletions test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
}

defaultConfig {
minSdkVersion versions.minSdk
targetSdkVersion versions.compileSdk
minSdkVersion 11
targetSdkVersion 11

applicationId 'com.example.boxup.bucks'
versionCode 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public final class BucksSendingTest {

onView(withText("Send")).perform(click());
spoon.screenshot(amountActivityRule.getActivity(), "send_clicked");

onView(withText("OK")).perform(click());
spoon.screenshot(amountActivityRule.getActivity(), "ok_clicked");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.example.boxup.bucks;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.transition.TransitionManager;
import android.view.View;
Expand Down Expand Up @@ -71,8 +75,13 @@ void numberClicked(TextView number) {
}

@OnClick(R.id.action_send) void actionSend() {
DialogFragment newFragment = new ConfirmDialog();
newFragment.show(getSupportFragmentManager(), "dialog");
}

private void sendAfterConfirm() {
int amountCents = (int) (parsedAmount() * 100);
startActivity(RecipientActivity.createIntent(this, amountCents));
startActivity(RecipientActivity.createIntent(AmountActivity.this, amountCents));

amount = "";
renderAmount();
Expand All @@ -95,4 +104,31 @@ private void renderAmount() {
private double parsedAmount() {
return amount.isEmpty() ? 0d : Double.parseDouble(amount);
}

public static class ConfirmDialog extends DialogFragment {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

return new AlertDialog.Builder(getActivity())
.setTitle(R.string.confirm_title)
.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
((AmountActivity) getActivity()).sendAfterConfirm();
dismiss();
}
}
)
.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismiss();
}
}
)
.create();
}
}
}
2 changes: 2 additions & 0 deletions test-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
<string name="send_success">Sent %1$s to\n%2$s</string>
<string name="to">To</string>
<string name="note">Note</string>
<string name="cancel">Cancel</string>
<string name="confirm_title">Are you sure?</string>
</resources>