-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Improved QRCode design #3743
Merged
Merged
Improved QRCode design #3743
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
5444269
moved some functions to qrcode tabs
dba05b0
added scan button in toolbar
80ea5f9
Added embedded scan (WIP)
a7c571c
scan ulitity
3c9c995
added permission request
5116c3b
scanner works
hypercubestart 4684371
beep sound and flashlight for embedded qr camera
hypercubestart 8904e1d
add files from merge commit
hypercubestart 3bcdf63
moved import qrcode item to overflow for QRCodeTabs
hypercubestart b04c7ca
qr_code redesign
hypercubestart 0b22c75
minor fixes
hypercubestart bcd27b9
hook menu item with new QRCodeTabs and fix qrcode generation
hypercubestart 092365a
removed unused
hypercubestart 647138a
change test name
hypercubestart f43aa17
fix NPE bug
hypercubestart 5b8ecba
add analytics and minor issues
hypercubestart 2eec648
update to viewpager2
hypercubestart 01f9cb2
styling
hypercubestart d7d548a
review
hypercubestart f16c57e
address review comments
hypercubestart 817ee55
update flash button to be materialbutton
hypercubestart 9718beb
refactor into preferences.qr
hypercubestart cb0adfa
QrCodeFragmentAction test
pedrop30 29356d7
fixed test
hypercubestart 9f3a5d5
ShowQRFragmentAction test
pedrop30 f341ca3
QRCodeTabsActivityPage
hypercubestart 9658e21
fix bug share qr code doesnt work if qr code not generated yet
hypercubestart 8c5a962
fix tests
hypercubestart a544327
remove copyright
hypercubestart 6a4b27e
fix tests
hypercubestart d2c4bf0
style
hypercubestart 4959cba
update qrcodeutilstest
hypercubestart 4005fe2
comments
hypercubestart 644f357
rule fixing
hypercubestart ee35d8a
merge
hypercubestart 9fb6b6d
fix RuleChain
hypercubestart ee53a50
fix
hypercubestart b267f65
remove @rule
hypercubestart 65e9dff
dark color qr code tabs
hypercubestart 1810f6c
continuous qr code + handle import qrcode
hypercubestart 5318fc1
fix typo
hypercubestart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
192 changes: 192 additions & 0 deletions
192
.../src/androidTest/java/org/odk/collect/android/preferences/qr/ConfigureWithQRCodeTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
package org.odk.collect.android.preferences.qr; | ||
|
||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.app.Instrumentation; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.net.Uri; | ||
|
||
import com.google.zxing.WriterException; | ||
|
||
import androidx.core.content.FileProvider; | ||
import androidx.test.core.app.ApplicationProvider; | ||
import androidx.test.espresso.intent.Intents; | ||
import androidx.test.espresso.intent.rule.IntentsTestRule; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.rule.GrantPermissionRule; | ||
import dagger.Provides; | ||
import io.reactivex.Observable; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.RuleChain; | ||
import org.junit.runner.RunWith; | ||
import org.odk.collect.android.BuildConfig; | ||
import org.odk.collect.android.R; | ||
import org.odk.collect.android.activities.MainMenuActivity; | ||
import org.odk.collect.android.injection.config.AppDependencyModule; | ||
import org.odk.collect.android.storage.StoragePathProvider; | ||
import org.odk.collect.android.storage.StorageSubdirectory; | ||
import org.odk.collect.android.support.ResetStateRule; | ||
import org.odk.collect.android.support.pages.MainMenuPage; | ||
import org.odk.collect.android.utilities.FileUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
import static androidx.test.espresso.intent.Intents.intended; | ||
import static androidx.test.espresso.intent.Intents.intending; | ||
import static androidx.test.espresso.intent.matcher.BundleMatchers.hasEntry; | ||
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; | ||
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtraWithKey; | ||
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtras; | ||
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasType; | ||
import static androidx.test.espresso.intent.matcher.IntentMatchers.isInternal; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ConfigureWithQRCodeTest { | ||
// drawable resource that will act as "qr code" in this test | ||
private static final int CHECKER_BACKGROUND_DRAWABLE_ID = R.drawable.checker_background; | ||
|
||
public IntentsTestRule<MainMenuActivity> rule = new IntentsTestRule<>(MainMenuActivity.class); | ||
|
||
@Rule | ||
public RuleChain copyFormChain = RuleChain | ||
.outerRule(GrantPermissionRule.grant( | ||
Manifest.permission.READ_EXTERNAL_STORAGE, | ||
Manifest.permission.WRITE_EXTERNAL_STORAGE, | ||
Manifest.permission.READ_PHONE_STATE | ||
)) | ||
.around(new ResetStateRule(new AppDependencyModule() { | ||
@Override | ||
@Provides | ||
public QRCodeGenerator providesQRCodeGenerator() { | ||
return new StubQRCodeGenerator(); | ||
} | ||
})) | ||
.around(rule); | ||
|
||
@Before | ||
public void stubAllExternalIntents() { | ||
// By default Espresso Intents does not stub any Intents. Stubbing needs to be setup before | ||
// every test run. In this case all external Intents will be blocked. | ||
intending(not(isInternal())).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, null)); | ||
} | ||
|
||
@Test | ||
public void onMainMenu_clickConfigureQRCode_andClickingOnScan_opensScanner() { | ||
new MainMenuPage(rule) | ||
.assertOnPage() | ||
.clickOnMenu() | ||
.clickConfigureQR() | ||
.clickScanFragment() | ||
.checkIsIdDisplayed(R.id.zxing_barcode_surface); | ||
} | ||
|
||
@Test | ||
public void onMainMenu_clickConfigureQRCode_andClickingOnView_showsQRCode() { | ||
new MainMenuPage(rule) | ||
.assertOnPage() | ||
.clickOnMenu() | ||
.clickConfigureQR() | ||
.clickViewQRFragment() | ||
.assertImageViewShowsImage(R.id.ivQRcode, BitmapFactory.decodeResource( | ||
ApplicationProvider.getApplicationContext().getResources(), | ||
CHECKER_BACKGROUND_DRAWABLE_ID | ||
)); | ||
} | ||
|
||
@Test | ||
public void onMainMenu_clickConfigureQRCode_andClickingOnImportQRCode_startsExternalImagePickerIntent() { | ||
new MainMenuPage(rule) | ||
.assertOnPage() | ||
.clickOnMenu() | ||
.clickConfigureQR() | ||
.clickOnMenu() | ||
.clickOnString(R.string.import_qrcode_sd); | ||
|
||
intended(hasAction(Intent.ACTION_PICK)); | ||
intended(hasType("image/*")); | ||
} | ||
|
||
@Test | ||
public void onMainMenu_clickConfigureQRCode_andClickingOnShareQRCode_startsExternalShareIntent() { | ||
String path = new StubQRCodeGenerator().getQrCodeFilepath(); | ||
Uri expected = FileProvider.getUriForFile(ApplicationProvider.getApplicationContext(), | ||
BuildConfig.APPLICATION_ID + ".provider", | ||
new File(path)); | ||
|
||
new MainMenuPage(rule) | ||
.assertOnPage() | ||
.clickOnMenu() | ||
.clickConfigureQR() | ||
.clickOnId(R.id.menu_item_share); | ||
|
||
// should be two Intents, 1. to QRCodeTabsActivity 2. Share QR Code Intent | ||
assertThat(Intents.getIntents().size(), equalTo(2)); | ||
Intent receivedIntent = Intents.getIntents().get(1); | ||
assertThat(receivedIntent, hasAction(Intent.ACTION_CHOOSER)); | ||
|
||
// test title | ||
assertThat(receivedIntent, hasExtras(hasEntry(Intent.EXTRA_TITLE, | ||
ApplicationProvider.getApplicationContext().getString(R.string.share_qrcode)))); | ||
|
||
// test SEND intent | ||
assertThat(receivedIntent, hasExtraWithKey(Intent.EXTRA_INTENT)); | ||
Intent sendIntent = receivedIntent.getParcelableExtra(Intent.EXTRA_INTENT); | ||
|
||
assertThat(sendIntent, hasAction(Intent.ACTION_SEND)); | ||
assertThat(sendIntent, hasType("image/*")); | ||
assertThat(sendIntent, hasExtras(hasEntry(Intent.EXTRA_STREAM, expected))); | ||
|
||
// test that file stream is valid by checking that file exists | ||
File qrcodeFile = new File(path); | ||
assertTrue(qrcodeFile.exists()); | ||
} | ||
|
||
// StubQRCodeGenerator is a class that is injected during this test | ||
// to verify that the QRCode is generated and shown to user correctly | ||
private static class StubQRCodeGenerator implements QRCodeGenerator { | ||
@Override | ||
public Bitmap generateQRBitMap(String data, int sideLength) throws IOException, WriterException { | ||
// don't use this in this test, so okay to return null | ||
return null; | ||
} | ||
|
||
@Override | ||
public Observable<Bitmap> generateQRCode(Collection<String> selectedPasswordKeys) { | ||
return Observable.create(emitter -> { | ||
Bitmap bitmap = | ||
BitmapFactory.decodeResource( | ||
ApplicationProvider.getApplicationContext().getResources(), | ||
CHECKER_BACKGROUND_DRAWABLE_ID); | ||
emitter.onNext(bitmap); | ||
|
||
// save bitmap to test that shareQRCode generates bitmap if file not there | ||
FileUtils.saveBitmapToFile(bitmap, getQrCodeFilepath()); | ||
emitter.onComplete(); | ||
}); | ||
} | ||
|
||
@Override | ||
public String getQrCodeFilepath() { | ||
return new StoragePathProvider().getDirPath(StorageSubdirectory.SETTINGS) + File.separator + "test-collect-settings.png"; | ||
} | ||
|
||
@Override | ||
public String getMd5CachePath() { | ||
// don't use this in this test, so okay to return null | ||
return null; | ||
} | ||
} | ||
} |
This file contains 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
83 changes: 83 additions & 0 deletions
83
...pp/src/androidTest/java/org/odk/collect/android/support/pages/QRCodeTabsActivityPage.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.odk.collect.android.support.pages; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.drawable.BitmapDrawable; | ||
import android.graphics.drawable.Drawable; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.odk.collect.android.R; | ||
import org.odk.collect.android.support.ActivityHelpers; | ||
|
||
import androidx.test.espresso.Espresso; | ||
import androidx.test.espresso.matcher.BoundedMatcher; | ||
import androidx.test.rule.ActivityTestRule; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.assertion.ViewAssertions.matches; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
|
||
public class QRCodeTabsActivityPage extends Page<QRCodeTabsActivityPage> { | ||
public QRCodeTabsActivityPage(ActivityTestRule rule) { | ||
super(rule); | ||
} | ||
|
||
@Override | ||
public QRCodeTabsActivityPage assertOnPage() { | ||
checkIsStringDisplayed(R.string.configure_via_qr_code); | ||
return this; | ||
} | ||
|
||
public QRCodeTabsActivityPage clickScanFragment() { | ||
onView(withText(R.string.scan_qr_code_fragment_title)).perform(click()); | ||
return this; | ||
} | ||
|
||
public QRCodeTabsActivityPage clickViewQRFragment() { | ||
onView(withText(R.string.view_qr_code_fragment_title)).perform(click()); | ||
return this; | ||
} | ||
|
||
public QRCodeTabsActivityPage assertImageViewShowsImage(int resourceid, Bitmap image) { | ||
onView(withId(resourceid)).check(matches(DrawableMatcher.withBitmap(image))); | ||
return this; | ||
} | ||
|
||
public QRCodeTabsActivityPage clickOnMenu() { | ||
Espresso.openActionBarOverflowOrOptionsMenu(ActivityHelpers.getActivity()); | ||
return this; | ||
} | ||
|
||
// Matcher class to match the contents of a ImageView and compare with a bitmap | ||
private static class DrawableMatcher { | ||
private static Matcher<View> withBitmap(Bitmap match) { | ||
return new BoundedMatcher<View, ImageView>(ImageView.class) { | ||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("bitmaps did not match"); | ||
} | ||
|
||
@Override | ||
protected boolean matchesSafely(ImageView imageView) { | ||
Drawable drawable = imageView.getDrawable(); | ||
if (drawable == null && match == null) { | ||
return true; | ||
} else if (drawable != null && match == null) { | ||
return false; | ||
} else if (drawable == null && match != null) { | ||
return false; | ||
} | ||
|
||
Bitmap actual = ((BitmapDrawable) drawable).getBitmap(); | ||
|
||
return actual.sameAs(match); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've found recently that we could run into ordering problems with rules so it'd be best if this rule was also part of the
RuleChain
below. Just remove the@Rule
and addaround(rule)
to the end of the chain.