forked from android/architecture-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Syncing with current codebase and adding databinding
- Loading branch information
1 parent
8ab49f1
commit 391b0bb
Showing
170 changed files
with
7,914 additions
and
374 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.idea | ||
*.iml | ||
local.properties | ||
build | ||
.gradle | ||
# Eclipse project files | ||
.project | ||
.settings/ | ||
.classpath |
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,30 @@ | ||
# How to become a contributor and submit your own code | ||
|
||
## Contributor License Agreements | ||
|
||
We'd love to accept your patches! Before we can take them, we | ||
have to jump a couple of legal hurdles. | ||
|
||
### Before you contribute | ||
Before we can use your code, you must sign the | ||
[Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual) | ||
(CLA), which you can do online. The CLA is necessary mainly because you own the | ||
copyright to your changes, even after your contribution becomes part of our | ||
codebase, so we need your permission to use and distribute your code. We also | ||
need to be sure of various other things—for instance that you'll tell us if you | ||
know that your code infringes on other people's patents. You don't have to sign | ||
the CLA until after you've submitted your code for review and a member has | ||
approved it, but you must do it before we can put your code into our codebase. | ||
Before you start working on a larger contribution, you should get in touch with | ||
us first through the issue tracker with your idea so that we can help out and | ||
possibly guide you. Coordinating up front makes it much easier to avoid | ||
frustration later on. | ||
|
||
### Code reviews | ||
All submissions, including submissions by project members, require review. We | ||
use Github pull requests for this purpose. | ||
|
||
### The small print | ||
Contributions made by corporations are covered by a different agreement than | ||
the one above, the | ||
[Software Grant and Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate). |
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 @@ | ||
/build |
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,91 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'com.neenbedankt.android-apt' | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.compileSdkVersion | ||
buildToolsVersion rootProject.ext.buildToolsVersion | ||
|
||
defaultConfig { | ||
applicationId "com.example.android.architecture.blueprints.tododatabinding" | ||
minSdkVersion rootProject.ext.minSdkVersion | ||
targetSdkVersion rootProject.ext.targetSdkVersion | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' | ||
} | ||
|
||
buildTypes { | ||
debug { | ||
// Run code coverage reports by default on debug builds. | ||
// testCoverageEnabled = true | ||
} | ||
} | ||
|
||
// If you need to add more flavors, consider using flavor dimensions. | ||
productFlavors { | ||
mock { | ||
applicationIdSuffix = ".mock" | ||
} | ||
prod | ||
} | ||
|
||
// Remove mockRelease as it's not needed. | ||
android.variantFilter { variant -> | ||
if(variant.buildType.name.equals('release') | ||
&& variant.getFlavors().get(0).name.equals('mock')) { | ||
variant.setIgnore(true); | ||
} | ||
} | ||
|
||
// Always show the result of every unit test, even if it passes. | ||
testOptions.unitTests.all { | ||
testLogging { | ||
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' | ||
} | ||
} | ||
|
||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
|
||
/* | ||
Dependency versions are defined in the top level build.gradle file. This helps keeping track of | ||
all versions in a single place. This improves readability and helps managing project complexity. | ||
*/ | ||
dependencies { | ||
// App's dependencies, including test | ||
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion" | ||
compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion" | ||
compile "com.android.support:design:$rootProject.supportLibraryVersion" | ||
compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion" | ||
compile "com.android.support:support-v4:$rootProject.supportLibraryVersion" | ||
compile "com.google.guava:guava:$rootProject.guavaVersion" | ||
compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.espressoVersion" | ||
|
||
// Dependencies for local unit tests | ||
testCompile "junit:junit:$rootProject.ext.junitVersion" | ||
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion" | ||
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion" | ||
|
||
// Android Testing Support Library's runner and rules | ||
androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion" | ||
androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion" | ||
|
||
// Dependencies for Android unit tests | ||
androidTestCompile "junit:junit:$rootProject.ext.junitVersion" | ||
androidTestCompile "org.mockito:mockito-core:$rootProject.ext.mockitoVersion" | ||
androidTestCompile 'com.google.dexmaker:dexmaker:1.2' | ||
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' | ||
|
||
// Espresso UI Testing | ||
androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion" | ||
androidTestCompile ("com.android.support.test.espresso:espresso-contrib:$rootProject.espressoVersion") | ||
androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.espressoVersion" | ||
|
||
// Resolve conflicts between main and test APK: | ||
androidTestCompile "com.android.support:support-annotations:$rootProject.supportLibraryVersion" | ||
androidTestCompile "com.android.support:support-v4:$rootProject.supportLibraryVersion" | ||
androidTestCompile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion" | ||
} |
54 changes: 54 additions & 0 deletions
54
...p/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/TestUtils.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,54 @@ | ||
/* | ||
* Copyright 2016, The Android Open Source Project | ||
* | ||
* 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 | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.android.architecture.blueprints.todoapp; | ||
|
||
import android.app.Activity; | ||
import android.content.pm.ActivityInfo; | ||
import android.content.res.Configuration; | ||
import android.support.test.rule.ActivityTestRule; | ||
|
||
/** | ||
* Useful test methods common to all activities | ||
*/ | ||
public class TestUtils { | ||
|
||
private static void rotateToLandscape(ActivityTestRule<? extends Activity> activityTestRule) { | ||
activityTestRule.getActivity() | ||
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | ||
} | ||
|
||
private static void rotateToPortrait(ActivityTestRule<? extends Activity> activityTestRule) { | ||
activityTestRule.getActivity() | ||
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | ||
} | ||
|
||
public static void rotateOrientation(ActivityTestRule<? extends Activity> activityTestRule) { | ||
int currentOrientation = | ||
activityTestRule.getActivity().getResources().getConfiguration().orientation; | ||
|
||
switch (currentOrientation) { | ||
case Configuration.ORIENTATION_LANDSCAPE: | ||
rotateToPortrait(activityTestRule); | ||
break; | ||
case Configuration.ORIENTATION_PORTRAIT: | ||
rotateToLandscape(activityTestRule); | ||
break; | ||
default: | ||
rotateToLandscape(activityTestRule); | ||
} | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
.../example/android/architecture/blueprints/todoapp/custom/action/NavigationViewActions.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,129 @@ | ||
/* | ||
* Copyright 2016, The Android Open Source Project | ||
* | ||
* 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 | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.android.architecture.blueprints.todoapp.custom.action; | ||
|
||
import org.hamcrest.Matcher; | ||
|
||
import android.content.res.Resources.NotFoundException; | ||
import android.support.design.widget.NavigationView; | ||
import android.support.test.espresso.PerformException; | ||
import android.support.test.espresso.UiController; | ||
import android.support.test.espresso.ViewAction; | ||
import android.support.test.espresso.matcher.ViewMatchers; | ||
import android.support.test.espresso.util.HumanReadables; | ||
import android.support.v4.widget.DrawerLayout; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; | ||
import static org.hamcrest.Matchers.allOf; | ||
|
||
/** | ||
* View actions for interacting with {@link NavigationView} | ||
*/ | ||
public final class NavigationViewActions { | ||
|
||
private NavigationViewActions() { | ||
// no Instance | ||
} | ||
|
||
/** | ||
* Returns a {@link ViewAction} that navigates to a menu item in {@link NavigationView} using a | ||
* menu item resource id. | ||
* | ||
* <p> | ||
* View constraints: | ||
* <ul> | ||
* <li>View must be a child of a {@link DrawerLayout} | ||
* <li>View must be of type {@link NavigationView} | ||
* <li>View must be visible on screen | ||
* <li>View must be displayed on screen | ||
* <ul> | ||
* | ||
* @param menuItemId the resource id of the menu item | ||
* @return a {@link ViewAction} that navigates on a menu item | ||
*/ | ||
public static ViewAction navigateTo(final int menuItemId) { | ||
|
||
return new ViewAction() { | ||
|
||
@Override | ||
public void perform(UiController uiController, View view) { | ||
NavigationView navigationView = (NavigationView) view; | ||
Menu menu = navigationView.getMenu(); | ||
if (null == menu.findItem(menuItemId)) { | ||
throw new PerformException.Builder() | ||
.withActionDescription(this.getDescription()) | ||
.withViewDescription(HumanReadables.describe(view)) | ||
.withCause(new RuntimeException(getErrorMessage(menu, view))) | ||
.build(); | ||
} | ||
menu.performIdentifierAction(menuItemId, 0); | ||
uiController.loopMainThreadUntilIdle(); | ||
} | ||
|
||
private String getErrorMessage(Menu menu, View view) { | ||
String NEW_LINE = System.getProperty("line.separator"); | ||
StringBuilder errorMessage = new StringBuilder("Menu item was not found, " | ||
+ "available menu items:") | ||
.append(NEW_LINE); | ||
for (int position = 0; position < menu.size(); position++) { | ||
errorMessage.append("[MenuItem] position=") | ||
.append(position); | ||
MenuItem menuItem = menu.getItem(position); | ||
if (menuItem != null) { | ||
CharSequence itemTitle = menuItem.getTitle(); | ||
if (itemTitle != null) { | ||
errorMessage.append(", title=") | ||
.append(itemTitle); | ||
} | ||
if (view.getResources() != null) { | ||
int itemId = menuItem.getItemId(); | ||
try { | ||
errorMessage.append(", id="); | ||
String menuItemResourceName = view.getResources() | ||
.getResourceName(itemId); | ||
errorMessage.append(menuItemResourceName); | ||
} catch (NotFoundException nfe) { | ||
errorMessage.append("not found"); | ||
} | ||
} | ||
errorMessage.append(NEW_LINE); | ||
} | ||
} | ||
return errorMessage.toString(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "click on menu item with id"; | ||
} | ||
|
||
@Override | ||
public Matcher<View> getConstraints() { | ||
return allOf(isAssignableFrom(NavigationView.class), | ||
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), | ||
isDisplayingAtLeast(90) | ||
); | ||
} | ||
}; | ||
|
||
} | ||
} |
Oops, something went wrong.