This repository has been archived by the owner on Jan 4, 2018. It is now read-only.
forked from square/flow
-
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.
Merge pull request square#238 from square/ray/is-it-safe-211
Fixes intent handling and adds sample app, test for it.
- Loading branch information
Showing
16 changed files
with
331 additions
and
1 deletion.
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,46 @@ | ||
buildscript { | ||
dependencies { | ||
classpath deps.android_gradle_plugin | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.compileSdkVersion | ||
buildToolsVersion rootProject.ext.buildToolsVersion | ||
|
||
defaultConfig { | ||
applicationId "flow.sample.intents" | ||
|
||
minSdkVersion rootProject.ext.minSdkVersion | ||
versionName VERSION_NAME | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
|
||
packagingOptions { | ||
exclude 'LICENSE.txt' | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(':flow') | ||
compile 'com.android.support:appcompat-v7:23.1.1' | ||
compile 'com.android.support:design:23.1.1' | ||
androidTestCompile 'com.android.support.test:runner:0.4' | ||
androidTestCompile 'com.android.support.test:rules:0.4' | ||
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' | ||
} | ||
|
||
//noinspection GroovyAssignabilityCheck | ||
configurations.all { | ||
resolutionStrategy { | ||
force 'com.android.support:support-annotations:23.1.1' | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
flow-sample-intents/src/androidTest/java/flow/sample/basic/IntentsSampleTest.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,58 @@ | ||
package flow.sample.basic; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.test.rule.ActivityTestRule; | ||
import flow.Flow; | ||
import flow.History; | ||
import flow.sample.intents.IntentsSingleInstanceSampleActivity; | ||
import flow.sample.intents.IntentsStandardSampleActivity; | ||
import flow.sample.intents.StringParceler; | ||
import java.util.List; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static android.support.test.InstrumentationRegistry.getInstrumentation; | ||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.action.ViewActions.pressBack; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static java.util.Arrays.asList; | ||
|
||
/** | ||
* Demonstrates the use of Intents to drive espresso tests to specific screens. | ||
*/ | ||
public class IntentsSampleTest { | ||
|
||
@Rule public ActivityTestRule rule = new ActivityTestRule<>(IntentsSingleInstanceSampleActivity.class); | ||
|
||
@Test public void singleInstanceActivity() { | ||
List<String> expected = asList("Able", "Baker", "Charlie"); | ||
History h = History.emptyBuilder().pushAll(expected).build(); | ||
|
||
Context context = getInstrumentation().getTargetContext().getApplicationContext(); | ||
Intent intent = new Intent(context, IntentsSingleInstanceSampleActivity.class); | ||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
Flow.addHistory(intent, h, new StringParceler()); | ||
context.startActivity(intent); | ||
|
||
onView(withText("Charlie")).perform(pressBack()); | ||
onView(withText("Baker")).perform(pressBack()); | ||
onView(withText("Able")).perform(click()); | ||
} | ||
|
||
@Test public void standardActivity() { | ||
List<String> expected = asList("Higgledy", "Piggledy", "Pop"); | ||
History h = History.emptyBuilder().pushAll(expected).build(); | ||
|
||
Context context = getInstrumentation().getTargetContext().getApplicationContext(); | ||
Intent intent = new Intent(context, IntentsStandardSampleActivity.class); | ||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
Flow.addHistory(intent, h, new StringParceler()); | ||
context.startActivity(intent); | ||
|
||
onView(withText("Pop")).perform(pressBack()); | ||
onView(withText("Piggledy")).perform(pressBack()); | ||
onView(withText("Higgledy")).perform(click()); | ||
} | ||
} |
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,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright 2017 Square 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 | ||
~ 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. | ||
--> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="flow.sample.intents" > | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" > | ||
|
||
<activity | ||
android:name=".IntentsSingleInstanceSampleActivity" | ||
android:launchMode="singleInstance" | ||
> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity | ||
android:name=".IntentsStandardSampleActivity" | ||
> | ||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> |
40 changes: 40 additions & 0 deletions
40
...sample-intents/src/main/java/flow/sample/intents/IntentsSingleInstanceSampleActivity.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,40 @@ | ||
/* | ||
* Copyright 2017 Square 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 | ||
* 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 flow.sample.intents; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import flow.Flow; | ||
|
||
public class IntentsSingleInstanceSampleActivity extends Activity { | ||
|
||
@Override protected void attachBaseContext(Context baseContext) { | ||
baseContext = Flow.configure(baseContext, this).keyParceler(new StringParceler()).install(); | ||
super.attachBaseContext(baseContext); | ||
} | ||
|
||
@Override protected void onNewIntent(Intent intent) { | ||
Flow.onNewIntent(intent, this); | ||
} | ||
|
||
@Override public void onBackPressed() { | ||
if (!Flow.get(this).goBack()) { | ||
super.onBackPressed(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
flow-sample-intents/src/main/java/flow/sample/intents/IntentsStandardSampleActivity.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,35 @@ | ||
/* | ||
* Copyright 2017 Square 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 | ||
* 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 flow.sample.intents; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import flow.Flow; | ||
|
||
public class IntentsStandardSampleActivity extends Activity { | ||
|
||
@Override protected void attachBaseContext(Context baseContext) { | ||
baseContext = Flow.configure(baseContext, this).keyParceler(new StringParceler()).install(); | ||
super.attachBaseContext(baseContext); | ||
} | ||
|
||
@Override public void onBackPressed() { | ||
if (!Flow.get(this).goBack()) { | ||
super.onBackPressed(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
flow-sample-intents/src/main/java/flow/sample/intents/StringParceler.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,35 @@ | ||
/* | ||
* Copyright 2017 Square 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 | ||
* 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 flow.sample.intents; | ||
|
||
import android.os.Bundle; | ||
import android.os.Parcelable; | ||
import android.support.annotation.NonNull; | ||
import flow.KeyParceler; | ||
|
||
public class StringParceler implements KeyParceler { | ||
@NonNull @Override public Parcelable toParcelable(@NonNull Object key) { | ||
Bundle bundle = new Bundle(); | ||
bundle.putString("stringKey", (String) key); | ||
return bundle; | ||
} | ||
|
||
@NonNull @Override public Object toKey(@NonNull Parcelable parcelable) { | ||
Bundle bundle = (Bundle) parcelable; | ||
return bundle.getString("stringKey"); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright 2017 Square 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 | ||
~ 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. | ||
--> | ||
|
||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
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,19 @@ | ||
<!-- | ||
~ Copyright 2017 Square 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 | ||
~ 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. | ||
--> | ||
|
||
<resources> | ||
<string name="app_name">Flow Intents Sample</string> | ||
</resources> |
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,27 @@ | ||
<!-- | ||
~ Copyright 2017 Square 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 | ||
~ 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. | ||
--> | ||
|
||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
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