├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── raw │ │ │ │ ├── game.flac │ │ │ │ ├── item.flac │ │ │ │ ├── meal.flac │ │ │ │ ├── ending.flac │ │ │ │ ├── happy.flac │ │ │ │ ├── meeting.flac │ │ │ │ ├── neutral.flac │ │ │ │ ├── numeric.flac │ │ │ │ ├── offer.flac │ │ │ │ ├── problem.flac │ │ │ │ ├── puzzle.flac │ │ │ │ ├── unhappy.flac │ │ │ │ ├── unknown.flac │ │ │ │ ├── yes_no.flac │ │ │ │ ├── challenge.flac │ │ │ │ ├── conflict.flac │ │ │ │ ├── direction.flac │ │ │ │ ├── achievement.flac │ │ │ │ ├── preparation.flac │ │ │ │ ├── requirement.flac │ │ │ │ └── transaction.flac │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values-w720dp │ │ │ │ └── dimens.xml │ │ │ ├── anim │ │ │ │ ├── slide_in_left.xml │ │ │ │ ├── slide_in_right.xml │ │ │ │ ├── slide_out_left.xml │ │ │ │ ├── slide_out_right.xml │ │ │ │ ├── scale_up_fade_in.xml │ │ │ │ └── scale_down_fade_out.xml │ │ │ ├── drawable │ │ │ │ ├── ic_done_black_24dp.xml │ │ │ │ ├── ic_info_outline_black_24dp.xml │ │ │ │ ├── ic_shortcuts_black_24dp.xml │ │ │ │ └── ic_settings_black_24dp.xml │ │ │ ├── values │ │ │ │ ├── styles.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings_settings.xml │ │ │ │ ├── strings.xml │ │ │ │ └── colors.xml │ │ │ ├── menu │ │ │ │ ├── menu_main.xml │ │ │ │ └── menu_navigation.xml │ │ │ ├── layout │ │ │ │ ├── activity_achievements_dialog.xml │ │ │ │ ├── fragment_stories.xml │ │ │ │ ├── activity_scenario_dialog.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── activity_about.xml │ │ │ │ ├── item_achievement.xml │ │ │ │ └── item_story.xml │ │ │ └── xml │ │ │ │ └── settings.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── nickrout │ │ │ │ └── shortstories │ │ │ │ ├── model │ │ │ │ ├── Finish.java │ │ │ │ ├── Achieve.java │ │ │ │ ├── Achievement.java │ │ │ │ ├── Story.java │ │ │ │ ├── Scenario.java │ │ │ │ ├── Choice.java │ │ │ │ └── type │ │ │ │ │ └── ScenarioType.java │ │ │ │ ├── ui │ │ │ │ ├── StoryListener.java │ │ │ │ ├── databinding │ │ │ │ │ ├── GlideBindingAdapters.java │ │ │ │ │ ├── SingleLayoutDataBindingAdapter.java │ │ │ │ │ ├── DataBindingViewHolder.java │ │ │ │ │ └── DataBindingAdapter.java │ │ │ │ ├── NoDisplayActivity.java │ │ │ │ ├── recyclerview │ │ │ │ │ ├── AchievementAdapter.java │ │ │ │ │ ├── VerticalSpaceItemDecoration.java │ │ │ │ │ └── StoryAdapter.java │ │ │ │ ├── QuitStoryActivity.java │ │ │ │ ├── ScenarioDialogActivity.java │ │ │ │ ├── AboutActivity.java │ │ │ │ ├── AchievementsDialogActivity.java │ │ │ │ ├── SettingsFragment.java │ │ │ │ ├── AddShowScenarioShortcutActivity.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── StoriesFragment.java │ │ │ │ └── ChoiceActivity.java │ │ │ │ ├── util │ │ │ │ ├── IdUtil.java │ │ │ │ ├── UiUtil.java │ │ │ │ ├── TypefaceUtil.java │ │ │ │ ├── BitmapUtil.java │ │ │ │ └── IntentUtil.java │ │ │ │ └── prefs │ │ │ │ ├── Settings.java │ │ │ │ ├── Progress.java │ │ │ │ └── Achievements.java │ │ ├── AndroidManifest.xml │ │ └── assets │ │ │ └── stories │ │ │ └── an_androids_tale.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── nickrout │ │ │ └── shortstories │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── nickrout │ │ └── shortstories │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── art ├── screenshots.png ├── shortstories.sketch └── google-play-badge.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── .gitignore ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /art/screenshots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/art/screenshots.png -------------------------------------------------------------------------------- /art/shortstories.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/art/shortstories.sketch -------------------------------------------------------------------------------- /art/google-play-badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/art/google-play-badge.png -------------------------------------------------------------------------------- /app/src/main/res/raw/game.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/game.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/item.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/item.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/meal.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/meal.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/ending.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/ending.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/happy.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/happy.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/meeting.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/meeting.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/neutral.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/neutral.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/numeric.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/numeric.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/offer.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/offer.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/problem.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/problem.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/puzzle.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/puzzle.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/unhappy.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/unhappy.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/unknown.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/unknown.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/yes_no.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/yes_no.flac -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/raw/challenge.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/challenge.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/conflict.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/conflict.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/direction.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/direction.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/achievement.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/achievement.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/preparation.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/preparation.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/requirement.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/requirement.flac -------------------------------------------------------------------------------- /app/src/main/res/raw/transaction.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/raw/transaction.flac -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ricknout/shortstories/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-w720dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/model/Finish.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.model; 2 | 3 | import org.simpleframework.xml.Root; 4 | 5 | @Root(name = "Finish") 6 | public class Finish { 7 | } 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Mar 05 11:02:18 SAST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/StoryListener.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import com.nickrout.shortstories.model.Story; 6 | 7 | public interface StoryListener { 8 | 9 | void startStory(@NonNull Story story); 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/model/Achieve.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.model; 2 | 3 | import org.simpleframework.xml.Attribute; 4 | import org.simpleframework.xml.Root; 5 | 6 | @Root(name = "Achieve") 7 | public class Achieve { 8 | 9 | @Attribute(name = "achievement_name") 10 | public String achievementName; 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/model/Achievement.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.model; 2 | 3 | public class Achievement { 4 | 5 | public Achievement(String name, boolean achieved) { 6 | this.name = name; 7 | this.achieved = achieved; 8 | } 9 | 10 | public String name; 11 | 12 | public boolean achieved; 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_done_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/util/IdUtil.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.util; 2 | 3 | import java.util.UUID; 4 | 5 | public class IdUtil { 6 | 7 | public static final int ID_NOTIFICATION = 1; 8 | public static final String TAG_NOTIFICATION = "com.nickrout.shortstories.notification"; 9 | 10 | public static String getRandomUniqueShortcutId() { 11 | return UUID.randomUUID().toString(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/databinding/GlideBindingAdapters.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui.databinding; 2 | 3 | import android.databinding.BindingAdapter; 4 | import android.widget.ImageView; 5 | 6 | import com.bumptech.glide.Glide; 7 | 8 | public class GlideBindingAdapters { 9 | 10 | @BindingAdapter("app:imageUrl") 11 | public static void imageUrl(ImageView imageView, String url){ 12 | Glide.with(imageView.getContext()).load(url).into(imageView); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/databinding/SingleLayoutDataBindingAdapter.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui.databinding; 2 | 3 | public abstract class SingleLayoutDataBindingAdapter extends DataBindingAdapter { 4 | 5 | private final int mLayoutId; 6 | 7 | public SingleLayoutDataBindingAdapter(int layoutId) { 8 | mLayoutId = layoutId; 9 | } 10 | 11 | @Override 12 | protected int getLayoutIdForPosition(int position) { 13 | return mLayoutId; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/nickrout/shortstories/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_info_outline_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 24dp 7 | 12dp 8 | 2dp 9 | 8dp 10 | 0dp 11 | 44dp 12 | 40dp 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/anim/scale_up_fade_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/anim/scale_down_fade_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/NoDisplayActivity.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | public abstract class NoDisplayActivity extends AppCompatActivity { 8 | 9 | @Override 10 | protected void onCreate(@Nullable Bundle savedInstanceState) { 11 | performPreFinishOperations(); 12 | finish(); 13 | overridePendingTransition(0, 0); 14 | super.onCreate(savedInstanceState); 15 | } 16 | 17 | protected abstract void performPreFinishOperations(); 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_achievements_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_stories.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 17 | 18 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/databinding/DataBindingViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui.databinding; 2 | 3 | import android.databinding.ViewDataBinding; 4 | import android.support.v7.widget.RecyclerView; 5 | 6 | import com.nickrout.shortstories.BR; 7 | 8 | public class DataBindingViewHolder extends RecyclerView.ViewHolder { 9 | 10 | private final ViewDataBinding mBinding; 11 | 12 | public DataBindingViewHolder(ViewDataBinding binding) { 13 | super(binding.getRoot()); 14 | mBinding = binding; 15 | } 16 | 17 | public void bind(Object item) { 18 | mBinding.setVariable(BR.item, item); 19 | mBinding.executePendingBindings(); 20 | } 21 | 22 | public ViewDataBinding getBinding() { 23 | return mBinding; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_scenario_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle 18 | .gradle/ 19 | build/ 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # Proguard folder generated by Eclipse 25 | proguard/ 26 | 27 | # Log Files 28 | *.log 29 | 30 | # Android Studio Navigation editor temp files 31 | .navigation/ 32 | 33 | # Android Studio captures folder 34 | captures/ 35 | 36 | # Android Studio 37 | /*/local.properties 38 | /*/out 39 | /*/*/build 40 | /*/*/production 41 | *.iml 42 | *.iws 43 | *.ipr 44 | *~ 45 | *.swp 46 | proguard/ 47 | *.log 48 | 49 | # Intellij 50 | *.iml 51 | .idea/ 52 | .idea/workspace.xml 53 | 54 | # Keystore files 55 | *.jks 56 | 57 | # Android SDK 58 | /android-sdk.zip 59 | /android-studio 60 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/nickrout/shortstories/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.nickrout.shortcuts", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/recyclerview/AchievementAdapter.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui.recyclerview; 2 | 3 | import com.nickrout.shortstories.R; 4 | import com.nickrout.shortstories.model.Achievement; 5 | import com.nickrout.shortstories.ui.databinding.SingleLayoutDataBindingAdapter; 6 | 7 | import java.util.List; 8 | 9 | public class AchievementAdapter extends SingleLayoutDataBindingAdapter { 10 | 11 | private List mAchievements; 12 | 13 | public AchievementAdapter(List achievements) { 14 | super(R.layout.item_achievement); 15 | mAchievements = achievements; 16 | } 17 | 18 | @Override 19 | public int getItemCount() { 20 | return mAchievements == null ? 0 : mAchievements.size(); 21 | } 22 | 23 | @Override 24 | protected Object getItemForPosition(int position) { 25 | return mAchievements == null || mAchievements.isEmpty() ? null : mAchievements.get(position); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/model/Story.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.model; 2 | 3 | import org.simpleframework.xml.Attribute; 4 | import org.simpleframework.xml.Element; 5 | import org.simpleframework.xml.ElementMap; 6 | import org.simpleframework.xml.Root; 7 | 8 | import java.util.Map; 9 | 10 | @Root(name="Story") 11 | public class Story { 12 | 13 | @Attribute(name = "title") 14 | public String title; 15 | 16 | @Attribute(name = "author") 17 | public String author; 18 | 19 | @Attribute(name = "description") 20 | public String description; 21 | 22 | @Attribute(name = "image") 23 | public String image; 24 | 25 | @ElementMap(entry = "Achievement", key = "name", attribute = true, inline = true, valueType = Boolean.class, value = "false") 26 | public Map achievements; 27 | 28 | @Element(name = "Choice") 29 | public Choice choice; 30 | 31 | public String file; 32 | 33 | public boolean inProgress; 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/recyclerview/VerticalSpaceItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui.recyclerview; 2 | 3 | import android.graphics.Rect; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | 7 | public class VerticalSpaceItemDecoration extends RecyclerView.ItemDecoration { 8 | 9 | private final int mVerticalSpaceHeight; 10 | private boolean mIncludeTop; 11 | 12 | public VerticalSpaceItemDecoration(int verticalSpaceHeight, boolean includeTop) { 13 | mVerticalSpaceHeight = verticalSpaceHeight; 14 | mIncludeTop = includeTop; 15 | } 16 | 17 | @Override 18 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 19 | RecyclerView.State state) { 20 | if (parent.getChildAdapterPosition(view) != 0 && mIncludeTop) { 21 | outRect.top = mVerticalSpaceHeight; 22 | } 23 | outRect.bottom = mVerticalSpaceHeight; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/nickrout/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_shortcuts_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 11 | 16 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/model/Scenario.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.model; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | 6 | import com.nickrout.shortstories.model.type.ScenarioType; 7 | import com.nickrout.shortstories.util.BitmapUtil; 8 | 9 | import org.simpleframework.xml.Attribute; 10 | import org.simpleframework.xml.Root; 11 | import org.simpleframework.xml.Text; 12 | 13 | @Root(name = "Scenario") 14 | public class Scenario { 15 | 16 | @Text 17 | public String scenario; 18 | 19 | @Attribute(name = "scenario_type") 20 | private int mScenarioType; 21 | 22 | @Attribute(name = "emoji") 23 | private String mEmoji; 24 | 25 | public ScenarioType getScenarioType() { 26 | ScenarioType[] scenarioTypes = ScenarioType.values(); 27 | if (mScenarioType > scenarioTypes.length - 1) { 28 | return ScenarioType.UNKNOWN; 29 | } 30 | return scenarioTypes[mScenarioType]; 31 | } 32 | 33 | public Bitmap getEmoji(Context context) { 34 | return BitmapUtil.getNotificationEmoji(context, mEmoji); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/QuitStoryActivity.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.content.pm.ShortcutManager; 4 | import android.support.v4.app.NotificationManagerCompat; 5 | 6 | import com.nickrout.shortstories.prefs.Progress; 7 | import com.nickrout.shortstories.util.IdUtil; 8 | 9 | public class QuitStoryActivity extends NoDisplayActivity { 10 | 11 | private static final String TAG = "QuitStoryActivity"; 12 | 13 | @Override 14 | protected void performPreFinishOperations() { 15 | removeAllShortcuts(); 16 | clearStatsAndProgress(); 17 | cancelScenarioNotification(); 18 | } 19 | 20 | private void removeAllShortcuts() { 21 | ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); 22 | shortcutManager.removeAllDynamicShortcuts(); 23 | } 24 | 25 | private void clearStatsAndProgress() { 26 | new Progress(this).setNotInProgress(); 27 | } 28 | 29 | private void cancelScenarioNotification() { 30 | NotificationManagerCompat.from(this).cancel(IdUtil.TAG_NOTIFICATION, IdUtil.ID_NOTIFICATION); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/util/UiUtil.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.util; 2 | 3 | import android.app.Activity; 4 | 5 | import java.lang.reflect.InvocationTargetException; 6 | import java.lang.reflect.Method; 7 | 8 | public class UiUtil { 9 | 10 | @SuppressWarnings({"ResourceType", "SpellCheckingInspection"}) 11 | public static void expandNotificationsPanel(Activity activity) { 12 | Object statusbar = activity.getSystemService("statusbar"); 13 | Class statusBarManager; 14 | try { 15 | statusBarManager = Class.forName("android.app.StatusBarManager"); 16 | } catch (ClassNotFoundException ignored) { 17 | return; 18 | } 19 | Method expandNotificationsPanel; 20 | try { 21 | expandNotificationsPanel = statusBarManager.getMethod("expandNotificationsPanel"); 22 | } catch (NoSuchMethodException ignored) { 23 | return; 24 | } 25 | try { 26 | expandNotificationsPanel.invoke(statusbar); 27 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) { 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_settings_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/databinding/DataBindingAdapter.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui.databinding; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.databinding.ViewDataBinding; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.ViewGroup; 8 | 9 | public abstract class DataBindingAdapter extends RecyclerView.Adapter { 10 | 11 | public DataBindingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 12 | LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); 13 | ViewDataBinding binding = DataBindingUtil.inflate(layoutInflater, viewType, parent, false); 14 | return new DataBindingViewHolder(binding); 15 | } 16 | 17 | public void onBindViewHolder(DataBindingViewHolder holder, int position) { 18 | Object item = getItemForPosition(position); 19 | holder.bind(item); 20 | } 21 | 22 | @Override 23 | public int getItemViewType(int position) { 24 | return getLayoutIdForPosition(position); 25 | } 26 | 27 | protected abstract Object getItemForPosition(int position); 28 | 29 | protected abstract int getLayoutIdForPosition(int position); 30 | } 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ShortStories 2 | 3 | ## Interactive stories told through App Shortcuts and Notifications 4 | 5 | ![Alt text](art/screenshots.png?raw=true "Screenshots") 6 | 7 | ShortStories provides a platform to play text-based games using the various elements of the Android System UI: 8 | 9 | • Notifications indicate scenarios in a story, posing a situation in which a choice is required 10 | 11 | • App Shortcuts provide a means of making a choice, and making a choice poses a new scenario 12 | 13 | • Dialogs provide a means of viewing a list of achievements, gained by exploring various paths in a story 14 | 15 | Unique colors, icons, vibration patterns and sounds exist for different types of scenarios, and are used to theme the Notifications. Emoji provide a contextual icon for scenarios and choices. 16 | 17 | Stories are defined in XML. A basic structure of Story, Choice, Scenario, Achievement and Finish tags allows ShortStories to parse and play almost any kind of text-based, multiple choice game. 18 | 19 | [![App](art/google-play-badge.png?raw=true)](https://play.google.com/store/apps/details?id=com.nickrout.shortstories) 20 | 21 | Available on Android 7.1 (Nougat MR1) and above. Ensure that your launcher supports App Shortcuts (tested and works with Pixel Launcher, Google Now Launcher, Nova Launcher and Action Launcher). 22 | 23 | Notification sound audio produced by Calvin Davey. 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/ScenarioDialogActivity.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | 8 | import com.nickrout.shortstories.R; 9 | import com.nickrout.shortstories.databinding.ActivityScenarioDialogBinding; 10 | import com.nickrout.shortstories.util.IntentUtil; 11 | 12 | public class ScenarioDialogActivity extends AppCompatActivity { 13 | 14 | @Override 15 | protected void onCreate(@Nullable Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | overridePendingTransition(R.anim.scale_up_fade_in, R.anim.scale_down_fade_out); 18 | Bundle extras = getIntent().getExtras(); 19 | String scenario = extras.getString(IntentUtil.EXTRA_SCENARIO); 20 | ActivityScenarioDialogBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_scenario_dialog); 21 | binding.scenario.setText(scenario); 22 | boolean hasAchievements = extras.getBoolean(IntentUtil.EXTRA_HAS_ACHIEVEMENTS); 23 | boolean isFinish = extras.getBoolean(IntentUtil.EXTRA_IS_FINISH); 24 | if (hasAchievements) { 25 | setTitle(R.string.title_achievement); 26 | } else if (isFinish) { 27 | setTitle(R.string.title_end); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/res/xml/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 14 | 15 | 16 | 17 | 19 | 20 | 25 | 26 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | defaultConfig { 7 | applicationId "com.nickrout.shortstories" 8 | minSdkVersion 25 9 | targetSdkVersion 25 10 | versionCode 5 11 | versionName "1.0.4" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | dataBinding { 21 | enabled = true 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | compile 'com.android.support:design:25.3.1' 29 | compile 'com.android.support:recyclerview-v7:25.3.1' 30 | compile 'com.android.support:cardview-v7:25.3.1' 31 | compile 'com.android.support:preference-v14:25.3.1' 32 | compile('org.simpleframework:simple-xml:2.7.1'){ 33 | exclude module: 'stax' 34 | exclude module: 'stax-api' 35 | exclude module: 'xpp3' 36 | } 37 | compile 'com.github.bumptech.glide:glide:3.7.0' 38 | testCompile 'junit:junit:4.12' 39 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 40 | exclude group: 'com.android.support', module: 'support-annotations' 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 17 | 18 | 25 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_achievement.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 10 | 11 | 12 | 17 | 18 | 26 | 27 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/prefs/Settings.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.prefs; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.preference.PreferenceManager; 6 | 7 | import com.nickrout.shortstories.R; 8 | 9 | public class Settings { 10 | 11 | private static final String TAG = "Settings"; 12 | 13 | private Context mContext; 14 | private SharedPreferences mSharedPreferences; 15 | 16 | public Settings(Context context) { 17 | mContext = context; 18 | } 19 | 20 | private SharedPreferences sharedPreferences() { 21 | if (mSharedPreferences == null) { 22 | mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); 23 | } 24 | return mSharedPreferences; 25 | } 26 | 27 | public int notificationPriority() { 28 | return mContext == null ? 0 : Integer.parseInt( 29 | sharedPreferences().getString(mContext.getString(R.string.setting_key_notification_priority), "0")); 30 | } 31 | 32 | public boolean goHomeNewScenario() { 33 | return mContext == null || 34 | sharedPreferences().getBoolean(mContext.getString(R.string.setting_key_go_home_new_scenario), true); 35 | } 36 | 37 | public boolean expandNotificationsNewScenario() { 38 | return mContext == null || 39 | sharedPreferences().getBoolean(mContext.getString(R.string.setting_key_expand_notifications_new_scenario), true); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/recyclerview/StoryAdapter.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui.recyclerview; 2 | 3 | import android.databinding.ViewDataBinding; 4 | 5 | import com.nickrout.shortstories.BR; 6 | import com.nickrout.shortstories.R; 7 | import com.nickrout.shortstories.model.Story; 8 | import com.nickrout.shortstories.ui.StoryListener; 9 | import com.nickrout.shortstories.ui.databinding.DataBindingViewHolder; 10 | import com.nickrout.shortstories.ui.databinding.SingleLayoutDataBindingAdapter; 11 | 12 | import java.util.List; 13 | 14 | public class StoryAdapter extends SingleLayoutDataBindingAdapter { 15 | 16 | private List mStories; 17 | private StoryListener mStoryListener; 18 | 19 | public StoryAdapter(List stories, StoryListener storyListener) { 20 | super(R.layout.item_story); 21 | mStories = stories; 22 | mStoryListener = storyListener; 23 | } 24 | 25 | @Override 26 | public int getItemCount() { 27 | return mStories == null ? 0 : mStories.size(); 28 | } 29 | 30 | @Override 31 | protected Object getItemForPosition(int position) { 32 | return mStories == null || mStories.isEmpty() ? null : mStories.get(position); 33 | } 34 | 35 | @Override 36 | public void onBindViewHolder(DataBindingViewHolder holder, int position) { 37 | super.onBindViewHolder(holder, position); 38 | ViewDataBinding binding = holder.getBinding(); 39 | binding.setVariable(BR.listener, mStoryListener); 40 | binding.executePendingBindings(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/util/TypefaceUtil.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.util; 2 | 3 | import android.content.Context; 4 | import android.content.res.AssetManager; 5 | import android.graphics.Typeface; 6 | import android.util.LruCache; 7 | 8 | public class TypefaceUtil { 9 | 10 | public final static int NOTO_COLOR_EMOJI = 0; 11 | 12 | private static TypefaceUtil sInstance = new TypefaceUtil(); 13 | 14 | private static LruCache sTypefaceCache = new LruCache<>(12); 15 | 16 | public static TypefaceUtil getInstance() { 17 | return sInstance; 18 | } 19 | 20 | private TypefaceUtil() { 21 | } 22 | 23 | public static Typeface getTypeface(Context context, int typefaceId) { 24 | Typeface typeface = sTypefaceCache.get(typefaceId); 25 | if (typeface != null) { 26 | return typeface; 27 | } 28 | typeface = getInstance().createTypeface(context, getTypefaceName(typefaceId)); 29 | if (typeface != null) { 30 | sTypefaceCache.put(typefaceId, typeface); 31 | } 32 | return typeface; 33 | } 34 | 35 | private static String getTypefaceName(int typefaceId) { 36 | switch (typefaceId) { 37 | case NOTO_COLOR_EMOJI: 38 | return "NotoColorEmoji.ttf"; 39 | } 40 | return null; 41 | } 42 | 43 | private Typeface createTypeface(Context context, String typefaceName) { 44 | AssetManager assetManager = context.getAssets(); 45 | return Typeface.createFromAsset(assetManager, "fonts/" + typefaceName); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/AboutActivity.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.text.Html; 8 | import android.text.method.LinkMovementMethod; 9 | import android.view.MenuItem; 10 | 11 | import com.nickrout.shortstories.R; 12 | import com.nickrout.shortstories.databinding.ActivityAboutBinding; 13 | 14 | public class AboutActivity extends AppCompatActivity { 15 | 16 | @Override 17 | protected void onCreate(@Nullable Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | ActivityAboutBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_about); 20 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 21 | binding.text.setText(Html.fromHtml(getString(R.string.text_about), 0)); 22 | binding.text.setMovementMethod(LinkMovementMethod.getInstance()); 23 | } 24 | 25 | @Override 26 | public void onBackPressed() { 27 | finish(); 28 | } 29 | 30 | @Override 31 | public boolean onOptionsItemSelected(MenuItem item) { 32 | switch (item.getItemId()) { 33 | case android.R.id.home: 34 | finish(); 35 | return true; 36 | } 37 | return super.onOptionsItemSelected(item); 38 | } 39 | 40 | @Override 41 | public void finish() { 42 | super.finish(); 43 | overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Notifications 5 | Notification priority 6 | notification_priority 7 | System UI 8 | Go home on new scenario 9 | Return to the launcher home screen for each new scenario. This dismisses the current list of app shortcuts (choices), if showing. 10 | go_home_new_scenario 11 | Expand notification panel 12 | Attempt to drop down the notification panel for each new scenario notification. 13 | expand_notifications_new_scenario 14 | 15 | 16 | Default 17 | Minimum 18 | Low 19 | High 20 | Maximum 21 | 22 | 23 | 24 | 0 25 | -2 26 | -1 27 | 1 28 | 2 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/prefs/Progress.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.prefs; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.text.TextUtils; 6 | 7 | public class Progress { 8 | 9 | private static final String TAG = "Progress"; 10 | private static final String SHARED_PREFERENCES_NAME = "progress_shared_preferences"; 11 | private static final String KEY_IN_PROGRESS = "in_progress"; 12 | private static final String KEY_STORY_FILE = "story_file"; 13 | 14 | private Context mContext; 15 | private SharedPreferences mSharedPreferences; 16 | 17 | public Progress(Context context) { 18 | mContext = context; 19 | } 20 | 21 | private SharedPreferences sharedPreferences() { 22 | if (mSharedPreferences == null) { 23 | mSharedPreferences = mContext.getSharedPreferences( 24 | SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); 25 | } 26 | return mSharedPreferences; 27 | } 28 | 29 | public void setInProgress(String storyFile) { 30 | sharedPreferences().edit().putString(KEY_STORY_FILE, storyFile).apply(); 31 | sharedPreferences().edit().putBoolean(KEY_IN_PROGRESS, true).apply(); 32 | } 33 | 34 | public void setNotInProgress() { 35 | sharedPreferences().edit().putBoolean(KEY_IN_PROGRESS, false).apply(); 36 | } 37 | 38 | public boolean isInProgress(String storyFile) { 39 | return TextUtils.equals(storyFile, sharedPreferences().getString(KEY_STORY_FILE, null)) 40 | && sharedPreferences().getBoolean(KEY_IN_PROGRESS, false); 41 | } 42 | 43 | public String getStoryFile() { 44 | return sharedPreferences().getString(KEY_STORY_FILE, null); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/AchievementsDialogActivity.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.DividerItemDecoration; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | 10 | import com.nickrout.shortstories.R; 11 | import com.nickrout.shortstories.databinding.ActivityAchievementsDialogBinding; 12 | import com.nickrout.shortstories.prefs.Achievements; 13 | import com.nickrout.shortstories.prefs.Progress; 14 | import com.nickrout.shortstories.ui.recyclerview.AchievementAdapter; 15 | import com.nickrout.shortstories.ui.recyclerview.VerticalSpaceItemDecoration; 16 | 17 | public class AchievementsDialogActivity extends AppCompatActivity { 18 | 19 | @Override 20 | protected void onCreate(@Nullable Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | overridePendingTransition(R.anim.scale_up_fade_in, R.anim.scale_down_fade_out); 23 | ActivityAchievementsDialogBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_achievements_dialog); 24 | binding.recycler.setLayoutManager(new LinearLayoutManager(this)); 25 | String storyFile = new Progress(this).getStoryFile(); 26 | binding.recycler.setAdapter(new AchievementAdapter(new Achievements(this, storyFile).getAchievements())); 27 | binding.recycler.addItemDecoration(new VerticalSpaceItemDecoration( 28 | getResources().getDimensionPixelSize(R.dimen.padding_vertical), true)); 29 | binding.recycler.addItemDecoration(new DividerItemDecoration( 30 | getApplicationContext(), DividerItemDecoration.VERTICAL)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/model/Choice.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.model; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.text.TextUtils; 6 | 7 | import com.nickrout.shortstories.model.type.ScenarioType; 8 | import com.nickrout.shortstories.util.BitmapUtil; 9 | 10 | import org.simpleframework.xml.Attribute; 11 | import org.simpleframework.xml.Element; 12 | import org.simpleframework.xml.ElementList; 13 | import org.simpleframework.xml.Root; 14 | 15 | import java.util.List; 16 | 17 | @Root(name = "Choice") 18 | public class Choice { 19 | 20 | @Attribute(name = "action", required = false) 21 | public String action; 22 | 23 | @Attribute(name = "emoji", required = false) 24 | private String mEmoji; 25 | 26 | @Element(name = "Scenario") 27 | private Scenario mScenario; 28 | 29 | @ElementList(inline = true, required = false) 30 | public List achievements; 31 | 32 | @ElementList(inline = true, required = false) 33 | public List choices; 34 | 35 | @Element(name = "Finish", required = false) 36 | private Finish finish; 37 | 38 | public boolean isFinish() { 39 | return finish != null; 40 | } 41 | 42 | public boolean hasAchievements() { 43 | return achievements != null && !achievements.isEmpty(); 44 | } 45 | 46 | public String getScenario() { 47 | return mScenario == null || TextUtils.isEmpty(mScenario.scenario) ? 48 | null : mScenario.scenario.trim(); 49 | } 50 | 51 | public ScenarioType getScenarioType() { 52 | return mScenario == null ? 53 | ScenarioType.UNKNOWN : mScenario.getScenarioType(); 54 | } 55 | 56 | public Bitmap getScenarioEmoji(Context context) { 57 | return mScenario.getEmoji(context); 58 | } 59 | 60 | public Bitmap getActionEmoji(Context context) { 61 | return BitmapUtil.getShortcutEmoji(context, mEmoji); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/SettingsFragment.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.preference.Preference; 5 | import android.support.v7.preference.PreferenceFragmentCompat; 6 | 7 | import com.nickrout.shortstories.R; 8 | import com.nickrout.shortstories.prefs.Settings; 9 | 10 | import java.util.Arrays; 11 | 12 | public class SettingsFragment extends PreferenceFragmentCompat { 13 | 14 | public SettingsFragment() { 15 | } 16 | 17 | public static SettingsFragment newInstance() { 18 | return new SettingsFragment(); 19 | } 20 | 21 | @Override 22 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 23 | addPreferencesFromResource(R.xml.settings); 24 | Settings settings = new Settings(getActivity()); 25 | final Preference notificationPriorityPreference = findPreference( 26 | getString(R.string.setting_key_notification_priority)); 27 | notificationPriorityPreference.setSummary( 28 | summaryForNotificationPriority(String.valueOf(settings.notificationPriority()))); 29 | notificationPriorityPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { 30 | @Override 31 | public boolean onPreferenceChange(Preference preference, Object newValue) { 32 | notificationPriorityPreference.setSummary( 33 | summaryForNotificationPriority(String.valueOf(newValue))); 34 | return true; 35 | } 36 | }); 37 | } 38 | 39 | private String summaryForNotificationPriority(String notificationPriority) { 40 | String[] entriesArray = getResources().getStringArray( 41 | R.array.setting_entries_notification_priority); 42 | String[] entryValuesArray = getResources().getStringArray( 43 | R.array.setting_entry_values_notification_priority); 44 | int position = Arrays.asList(entryValuesArray).indexOf(notificationPriority); 45 | if (position < 0 || position > entriesArray.length - 1) { 46 | return null; 47 | } 48 | return entriesArray[position]; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | 34 | 35 | 40 | 41 | 46 | 47 | 51 | 52 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/AddShowScenarioShortcutActivity.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.content.pm.ShortcutInfo; 4 | import android.content.pm.ShortcutManager; 5 | import android.graphics.drawable.Icon; 6 | import android.support.v4.content.ContextCompat; 7 | import android.util.Log; 8 | 9 | import com.nickrout.shortstories.R; 10 | import com.nickrout.shortstories.model.Choice; 11 | import com.nickrout.shortstories.util.BitmapUtil; 12 | import com.nickrout.shortstories.util.IdUtil; 13 | import com.nickrout.shortstories.util.IntentUtil; 14 | 15 | import org.simpleframework.xml.Serializer; 16 | import org.simpleframework.xml.core.Persister; 17 | 18 | import java.util.Collections; 19 | 20 | public class AddShowScenarioShortcutActivity extends NoDisplayActivity { 21 | 22 | private static final String TAG = "AddShowScenarioShortcut"; 23 | 24 | private Choice mChoice; 25 | 26 | @Override 27 | protected void performPreFinishOperations() { 28 | Serializer serializer = new Persister(); 29 | String choiceXml = getIntent().getExtras().getString(IntentUtil.EXTRA_CHOICE_XML); 30 | try { 31 | mChoice = serializer.read(Choice.class, choiceXml); 32 | } catch (Exception e) { 33 | Log.d(TAG, e.toString()); 34 | return; 35 | } 36 | addShowScenarioShortcut(); 37 | } 38 | 39 | private void addShowScenarioShortcut() { 40 | ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); 41 | ShortcutInfo showScenarioShortcut = new ShortcutInfo.Builder(this, IdUtil.getRandomUniqueShortcutId()) 42 | .setShortLabel(getString(R.string.shortcut_title_show_scenario)) 43 | .setLongLabel(getString(R.string.shortcut_title_show_scenario)) 44 | .setDisabledMessage(getString(R.string.shortcut_disabled_message)) 45 | .setIcon(Icon.createWithBitmap(BitmapUtil.getShortcutIcon( 46 | this, ContextCompat.getColor(this, R.color.color_shortcut_background), 47 | R.drawable.ic_info_outline_black_24dp, ContextCompat.getColor(this, R.color.color_primary)))) 48 | .setIntent(IntentUtil.choice(this, mChoice)) 49 | .setRank(0) 50 | .build(); 51 | shortcutManager.addDynamicShortcuts(Collections.singletonList(showScenarioShortcut)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ShortStories 5 | Stories 6 | Settings 7 | Scenario 8 | Achievement! 9 | The end 10 | Achievements 11 | About 12 | Share 13 | Send to 14 | Author 15 | Description 16 | Start 17 | Restart 18 | Achievements 19 | Quit 20 | Show scenario 21 | This choice is no longer available! 22 | Failed to load story 23 | Interactive stories told through App Shortcuts and Notifications 24 |
• Notifications indicate scenarios in a story, posing a situation in which a choice is required

• App Shortcuts provide a means of making a choice, and making a choice poses a new scenario

• Dialogs provide a means of viewing a list of achievements, gained by exploring various paths in a story


Unique colors, vibration patterns and sounds exist for different types of scenarios, and are used to theme the Notifications. Emoji provide a contextual icon for scenarios and choices.

Stories are defined in XML. A basic structure of Story, Choice, Scenario, Achievement and Finish tags allows ShortStories to parse and play almost any kind of text-based, multiple choice game.

ShortStories is written by Nick Rout
Twitter | Google+

View the source code and contribute your own stories on Github.

Notification sound audio produced by Calvin Davey.]]>
25 | Get the ShortStories app 26 | Interactive stories told through App Shortcuts and Notifications.\n\nGet the ShortStories app:\nhttps://play.google.com/store/apps/details?id=com.nickrout.shortstories 27 | 28 |
29 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/model/type/ScenarioType.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.model.type; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | import android.support.annotation.ColorInt; 6 | import android.support.annotation.ColorRes; 7 | import android.support.annotation.RawRes; 8 | import android.support.v4.content.ContextCompat; 9 | 10 | import com.nickrout.shortstories.R; 11 | 12 | public enum ScenarioType { 13 | 14 | UNKNOWN(R.color.color_primary, R.raw.unknown, new long[] {0, 100}), 15 | ACHIEVEMENT(R.color.red_600, R.raw.achievement, new long[] {0, 100, 100, 100, 100, 200}), 16 | CHALLENGE(R.color.pink_600, R.raw.challenge, new long[] {0, 100, 100, 100, 100, 100, 100, 100}), 17 | CONFLICT(R.color.purple_600, R.raw.conflict, new long[] {0, 200, 100, 200, 100, 200}), 18 | DIRECTION(R.color.deep_purple_600, R.raw.direction, new long[] {0, 200, 300, 200}), 19 | ENDING(R.color.black, R.raw.ending, new long[] {0, 100, 100, 300}), 20 | GAME(R.color.indigo_600, R.raw.game, new long[] {0, 200, 100, 100, 100, 200, 100, 100}), 21 | HAPPY(R.color.blue_600, R.raw.happy, new long[] {0, 100, 100, 200, 100, 300}), 22 | ITEM(R.color.light_blue_600, R.raw.item, new long[] {0, 200, 100, 100, 100, 100}), 23 | MEAL(R.color.cyan_600, R.raw.meal, new long[] {0, 100, 100, 200}), 24 | MEETING(R.color.teal_600, R.raw.meeting, new long[] {0, 100, 100, 100}), 25 | NEUTRAL(R.color.green_600, R.raw.neutral, new long[] {0, 100, 100, 100, 100, 100}), 26 | NUMERIC(R.color.light_green_600, R.raw.numeric, new long[] {0, 200, 100, 100}), 27 | OFFER(R.color.lime_600, R.raw.offer, new long[] {0, 100, 200, 300}), 28 | PREPARATION(R.color.yellow_600, R.raw.preparation, new long[] {0, 200, 100, 200}), 29 | PROBLEM(R.color.amber_600, R.raw.problem, new long[] {0, 200, 200, 100, 200, 200}), 30 | PUZZLE(R.color.orange_600, R.raw.puzzle, new long[] {0, 300, 200, 100, 100, 100}), 31 | REQUIREMENT(R.color.deep_orange_600, R.raw.requirement, new long[] {0, 200, 100, 100, 100, 100, 100, 100}), 32 | TRANSACTION(R.color.brown_600, R.raw.transaction, new long[] {0, 200, 100, 300, 100, 100}), 33 | UNHAPPY(R.color.grey_600, R.raw.unhappy, new long[] {0, 300, 100, 200, 100, 100}), 34 | YES_NO(R.color.blue_grey_600, R.raw.yes_no, new long[] {0, 200, 100, 100, 100, 200}); 35 | 36 | private @ColorRes int mColorResId; 37 | private @RawRes int mSoundResId; 38 | public long[] vibratePattern; 39 | 40 | ScenarioType(@ColorRes int colorResId, @RawRes int soundResId, long[] vibratePattern) { 41 | mColorResId = colorResId; 42 | mSoundResId = soundResId; 43 | this.vibratePattern = vibratePattern; 44 | } 45 | 46 | public @ColorInt int getColor(Context context) { 47 | return ContextCompat.getColor(context, mColorResId); 48 | } 49 | 50 | public Uri getSound(Context context) { 51 | return Uri.parse("android.resource://" + context.getPackageName() + "/" + mSoundResId); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/prefs/Achievements.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.prefs; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.util.Log; 6 | 7 | import com.nickrout.shortstories.model.Achievement; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.Comparator; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | public class Achievements { 16 | 17 | private static final String TAG = "Achievements"; 18 | 19 | private Context mContext; 20 | private String mSharedPreferencesName; 21 | private SharedPreferences mSharedPreferences; 22 | private Comparator mAchievementComparator = new Comparator() { 23 | @Override 24 | public int compare(Achievement a1, Achievement a2) { 25 | return a1.name.compareTo(a2.name); 26 | } 27 | }; 28 | 29 | public Achievements(Context context, String sharedPreferencesName) { 30 | mContext = context; 31 | mSharedPreferencesName = sharedPreferencesName; 32 | } 33 | 34 | private SharedPreferences sharedPreferences() { 35 | if (mSharedPreferences == null) { 36 | mSharedPreferences = mContext.getSharedPreferences( 37 | mSharedPreferencesName, Context.MODE_PRIVATE); 38 | } 39 | return mSharedPreferences; 40 | } 41 | 42 | public void setAll(Map achievements) { 43 | if (achievements == null || achievements.isEmpty()) { 44 | Log.e(TAG, "Attempted to set all achievements with empty map"); 45 | return; 46 | } 47 | for (Map.Entry achievementEntry : achievements.entrySet()) { 48 | if (contains(achievementEntry.getKey())) { 49 | continue; 50 | } 51 | set(achievementEntry.getKey(), achievementEntry.getValue() == null ? false : achievementEntry.getValue()); 52 | } 53 | } 54 | 55 | private boolean contains(String achievementName) { 56 | return sharedPreferences().contains(achievementName); 57 | } 58 | 59 | public void achieve(String achievementName) { 60 | set(achievementName, true); 61 | } 62 | 63 | private void set(String achievementName, boolean value) { 64 | sharedPreferences().edit().putBoolean(achievementName, value).apply(); 65 | } 66 | 67 | public List getAchievements() { 68 | List achievements = new ArrayList<>(); 69 | Map achievementsMap = getAll(); 70 | if (achievementsMap == null || achievementsMap.isEmpty()) { 71 | return achievements; 72 | } 73 | for (Map.Entry achievementEntry : achievementsMap.entrySet()) { 74 | Achievement achievement = new Achievement(achievementEntry.getKey(), achievementEntry.getValue()); 75 | achievements.add(achievement); 76 | } 77 | Collections.sort(achievements, mAchievementComparator); 78 | return achievements; 79 | } 80 | 81 | @SuppressWarnings("unchecked") 82 | private Map getAll() { 83 | try { 84 | return (Map) sharedPreferences().getAll(); 85 | } catch (ClassCastException e) { 86 | Log.e(TAG, e.toString()); 87 | return null; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.support.annotation.NonNull; 5 | import android.support.design.widget.BottomNavigationView; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.view.Menu; 9 | import android.view.MenuInflater; 10 | import android.view.MenuItem; 11 | 12 | import com.nickrout.shortstories.R; 13 | import com.nickrout.shortstories.databinding.ActivityMainBinding; 14 | import com.nickrout.shortstories.model.Story; 15 | import com.nickrout.shortstories.prefs.Achievements; 16 | import com.nickrout.shortstories.prefs.Progress; 17 | import com.nickrout.shortstories.util.IntentUtil; 18 | 19 | public class MainActivity extends AppCompatActivity implements StoryListener { 20 | 21 | private static final String TAG = "MainActivity"; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | final ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); 27 | if (savedInstanceState == null) { 28 | getSupportFragmentManager().beginTransaction().replace(R.id.container, StoriesFragment.newInstance()).commit(); 29 | } 30 | binding.navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { 31 | @Override 32 | public boolean onNavigationItemSelected(@NonNull MenuItem item) { 33 | switch (item.getItemId()) { 34 | case R.id.navigation_stories: 35 | if (binding.navigation.getSelectedItemId() == R.id.navigation_stories) { 36 | return true; 37 | } 38 | getSupportFragmentManager() 39 | .beginTransaction() 40 | .setCustomAnimations(R.anim.scale_up_fade_in, R.anim.scale_down_fade_out) 41 | .replace(R.id.container, StoriesFragment.newInstance()).commit(); 42 | return true; 43 | case R.id.navigation_settings: 44 | if (binding.navigation.getSelectedItemId() == R.id.navigation_settings) { 45 | return true; 46 | } 47 | getSupportFragmentManager() 48 | .beginTransaction() 49 | .setCustomAnimations(R.anim.scale_up_fade_in, R.anim.scale_down_fade_out) 50 | .replace(R.id.container, SettingsFragment.newInstance()).commit(); 51 | return true; 52 | } 53 | return false; 54 | } 55 | }); 56 | } 57 | 58 | @Override 59 | public boolean onCreateOptionsMenu(Menu menu) { 60 | MenuInflater inflater = getMenuInflater(); 61 | inflater.inflate(R.menu.menu_main, menu); 62 | return true; 63 | } 64 | 65 | @Override 66 | public boolean onOptionsItemSelected(MenuItem item) { 67 | switch (item.getItemId()) { 68 | case R.id.about: 69 | startActivity(IntentUtil.about(this)); 70 | overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right); 71 | return true; 72 | case R.id.share: 73 | startActivity(IntentUtil.share(this)); 74 | return true; 75 | } 76 | return super.onOptionsItemSelected(item); 77 | } 78 | 79 | @Override 80 | public void startStory(@NonNull Story story) { 81 | new Achievements(this, story.file).setAll(story.achievements); 82 | new Progress(this).setInProgress(story.file); 83 | finishAndRemoveTask(); 84 | startActivity(IntentUtil.choice(MainActivity.this, story.choice)); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/ui/StoriesFragment.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.ui; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.AsyncTask; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.annotation.Nullable; 8 | import android.support.v4.app.Fragment; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.util.Log; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | 15 | import com.nickrout.shortstories.R; 16 | import com.nickrout.shortstories.databinding.FragmentStoriesBinding; 17 | import com.nickrout.shortstories.model.Story; 18 | import com.nickrout.shortstories.prefs.Progress; 19 | import com.nickrout.shortstories.ui.recyclerview.StoryAdapter; 20 | import com.nickrout.shortstories.ui.recyclerview.VerticalSpaceItemDecoration; 21 | 22 | import org.simpleframework.xml.Serializer; 23 | import org.simpleframework.xml.core.Persister; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Arrays; 27 | import java.util.List; 28 | 29 | public class StoriesFragment extends Fragment implements StoryListener { 30 | 31 | private static final String TAG = "StoriesFragment"; 32 | 33 | private FragmentStoriesBinding mBinding; 34 | private static final List STORY_FILES = new ArrayList<>(Arrays.asList("an_androids_tale.xml")); 35 | 36 | public StoriesFragment() { 37 | } 38 | 39 | public static StoriesFragment newInstance() { 40 | return new StoriesFragment(); 41 | } 42 | 43 | @Nullable 44 | @Override 45 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 46 | mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_stories, container, false); 47 | mBinding.recycler.setLayoutManager(new LinearLayoutManager(getActivity())); 48 | mBinding.recycler.addItemDecoration(new VerticalSpaceItemDecoration( 49 | getResources().getDimensionPixelSize(R.dimen.padding_vertical), false)); 50 | return mBinding.getRoot(); 51 | } 52 | 53 | @Override 54 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 55 | super.onViewCreated(view, savedInstanceState); 56 | loadStories(STORY_FILES); 57 | } 58 | 59 | private void loadStories(@NonNull final List storyFiles) { 60 | new AsyncTask>() { 61 | @Override 62 | protected List doInBackground(Void... params) { 63 | Serializer serializer = new Persister(); 64 | Progress progress = new Progress(getActivity()); 65 | boolean foundInProgressStory = false; 66 | List stories = new ArrayList<>(); 67 | for (String storyFile : storyFiles) { 68 | try { 69 | Story story = serializer.read(Story.class, getActivity().getAssets().open("stories/" + storyFile)); 70 | story.file = storyFile; 71 | if (!foundInProgressStory) { 72 | boolean inProgress = progress.isInProgress(storyFile); 73 | story.inProgress = inProgress; 74 | foundInProgressStory = inProgress; 75 | } else { 76 | story.inProgress = false; 77 | } 78 | stories.add(story); 79 | } catch (Exception e) { 80 | Log.d(TAG, e.toString()); 81 | } 82 | } 83 | return stories; 84 | } 85 | @Override 86 | protected void onPostExecute(List stories) { 87 | assignStoriesToView(stories); 88 | } 89 | }.execute(); 90 | } 91 | 92 | private void assignStoriesToView(@NonNull List stories) { 93 | mBinding.recycler.setAdapter(new StoryAdapter(stories, this)); 94 | } 95 | 96 | @Override 97 | public void startStory(@NonNull Story story) { 98 | if (!(getActivity() instanceof StoryListener)) { 99 | return; 100 | } 101 | ((StoryListener) getActivity()).startStory(story); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/nickrout/shortstories/util/BitmapUtil.java: -------------------------------------------------------------------------------- 1 | package com.nickrout.shortstories.util; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.drawable.BitmapDrawable; 8 | import android.graphics.drawable.Drawable; 9 | import android.graphics.drawable.LayerDrawable; 10 | import android.graphics.drawable.ShapeDrawable; 11 | import android.graphics.drawable.shapes.OvalShape; 12 | import android.support.annotation.ColorInt; 13 | import android.support.annotation.DimenRes; 14 | import android.support.annotation.DrawableRes; 15 | import android.support.v4.content.ContextCompat; 16 | import android.support.v4.graphics.drawable.DrawableCompat; 17 | import android.text.TextUtils; 18 | 19 | import com.nickrout.shortstories.R; 20 | 21 | public class BitmapUtil { 22 | 23 | public static Bitmap getShortcutIcon( 24 | Context context, @ColorInt int backgroundColor, 25 | @DrawableRes int iconResId, @ColorInt int iconColor) { 26 | return getCircleIcon(context, 27 | backgroundColor, 28 | context.getResources().getDimensionPixelSize(R.dimen.inset_shortcut_icon_background), 29 | iconResId, 30 | iconColor, 31 | context.getResources().getDimensionPixelSize(R.dimen.inset_shortcut_icon)); 32 | } 33 | 34 | private static Bitmap getCircleIcon( 35 | Context context, @ColorInt int backgroundColor, int backgroundInset, 36 | @DrawableRes int iconResId, @ColorInt int iconColor, int iconInset) { 37 | Drawable[] layers = new Drawable[2]; 38 | ShapeDrawable background = new ShapeDrawable(new OvalShape()); 39 | background.getPaint().setColor(backgroundColor); 40 | Drawable icon = ContextCompat.getDrawable(context, iconResId); 41 | Drawable tintedIcon = DrawableCompat.wrap(icon.mutate()); 42 | DrawableCompat.setTint(tintedIcon, iconColor); 43 | layers[0] = background; 44 | layers[1] = tintedIcon; 45 | LayerDrawable layerDrawable = new LayerDrawable(layers); 46 | layerDrawable.setLayerInset(1, iconInset, iconInset, iconInset, iconInset); 47 | layerDrawable.setLayerInset(0, backgroundInset, backgroundInset, backgroundInset, backgroundInset); 48 | return drawableToBitmap(layerDrawable); 49 | } 50 | 51 | private static Bitmap drawableToBitmap(Drawable drawable) { 52 | if (drawable instanceof BitmapDrawable) { 53 | return ((BitmapDrawable) drawable).getBitmap(); 54 | } 55 | int width = drawable.getIntrinsicWidth(); 56 | width = width > 0 ? width : 1; 57 | int height = drawable.getIntrinsicHeight(); 58 | height = height > 0 ? height : 1; 59 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 60 | Canvas canvas = new Canvas(bitmap); 61 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 62 | drawable.draw(canvas); 63 | return bitmap; 64 | } 65 | 66 | public static Bitmap getShortcutEmoji(Context context, String emoji) { 67 | return getEmoji(context, emoji, R.dimen.size_emoji_shortcut, R.dimen.inset_emoji_shortcut); 68 | } 69 | 70 | public static Bitmap getNotificationEmoji(Context context, String emoji) { 71 | return getEmoji(context, emoji, R.dimen.size_emoji_notification, R.dimen.inset_emoji_notification); 72 | } 73 | 74 | private static Bitmap getEmoji( 75 | Context context, String emoji, @DimenRes int sizeResId, @DimenRes int insetResId) { 76 | if (context == null || TextUtils.isEmpty(emoji)) { 77 | return null; 78 | } 79 | int size = context.getResources().getDimensionPixelSize(sizeResId); 80 | int inset = context.getResources().getDimensionPixelSize(insetResId); 81 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 82 | paint.setStyle(Paint.Style.FILL); 83 | paint.setTextAlign(Paint.Align.LEFT); 84 | paint.setTextSize(size); 85 | float baseline = -paint.ascent(); 86 | int width = (int) (paint.measureText(emoji) + 0.5f); 87 | int height = (int) (baseline + paint.descent() + 0.5f); 88 | Bitmap bitmap = Bitmap.createBitmap(width + inset * 2, height + inset * 2, Bitmap.Config.ARGB_8888); 89 | Canvas canvas = new Canvas(bitmap); 90 | canvas.drawText(emoji, inset, baseline + inset, paint); 91 | return bitmap; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_story.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 11 | 14 | 15 | 16 | 19 | 20 | 24 | 25 | 31 | 32 | 41 | 42 | 51 | 52 | 57 | 58 | 67 | 68 | 73 | 74 | 82 | 83 | 84 | 85 | 89 | 90 |