Initial commit for the re-code
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
local.properties
|
||||
/.gradle
|
||||
/MinimalBible/build
|
||||
/MinimalBible/.gradle
|
||||
/appcompat_v7/build
|
||||
/.idea
|
||||
/build
|
||||
*.iml
|
9
.gitmodules
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
[submodule "jsword"]
|
||||
path = jsword
|
||||
url = https://github.com/crosswire/jsword.git
|
||||
[submodule "jsword-minimalbible"]
|
||||
path = jsword-minimalbible
|
||||
url = https://github.com/MinimalBible/jsword-minimalbible.git
|
||||
[submodule "ProgressWheel"]
|
||||
path = ProgressWheel
|
||||
url = git@github.com:Todd-Davies/ProgressWheel
|
15
.travis.yml
Normal file
@ -0,0 +1,15 @@
|
||||
language: android
|
||||
env:
|
||||
matrix:
|
||||
- ANDROID_SDKS=android-19,sysimg-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
|
||||
|
||||
android:
|
||||
components:
|
||||
- build-tools-20.0.0
|
||||
|
||||
before_install:
|
||||
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
|
||||
- emulator -avd test -no-skin -no-audio -no-window &
|
||||
before_script:
|
||||
- ./wait_for_emulator
|
||||
- adb shell input keyevent 82 &
|
73
Minimal Bible.svg
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="48"
|
||||
height="48"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.4 r9939"
|
||||
sodipodi:docname="New document 1">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="7.9195959"
|
||||
inkscape:cx="1.3613333"
|
||||
inkscape:cy="24.040952"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:snap-bbox="false"
|
||||
inkscape:window-width="1918"
|
||||
inkscape:window-height="1055"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Background"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-1004.3622)">
|
||||
<rect
|
||||
style="fill:#000000;stroke:#000000;stroke-width:6.05299997;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;opacity:1;stroke-dashoffset:0"
|
||||
id="rect2985"
|
||||
width="41.946575"
|
||||
height="41.946575"
|
||||
x="3.0267119"
|
||||
y="1007.3889" />
|
||||
<path
|
||||
style="fill:#ffffff;stroke:none"
|
||||
d="M 21 4 L 21 13 L 9 13 L 9 19 L 21 19 L 21 44 L 27 44 L 27 19 L 39 19 L 39 13 L 27 13 L 27 4 L 21 4 z "
|
||||
transform="translate(0,1004.3622)"
|
||||
id="rect3937" />
|
||||
</g>
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer2"
|
||||
inkscape:label="Cross" />
|
||||
</svg>
|
After Width: | Height: | Size: 2.2 KiB |
9
MinimalBible/.classpath
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
3
MinimalBible/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/gen
|
||||
/bin
|
||||
/libs-src
|
33
MinimalBible/.project
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MinimalBible</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
4
MinimalBible/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
|
184
MinimalBible/README.md
Normal file
@ -0,0 +1,184 @@
|
||||
MinimalBible
|
||||
============
|
||||
|
||||
A Bible app for android designed to be more focused in both UI and feature set.
|
||||
|
||||
Project Outline
|
||||
===============
|
||||
|
||||
This outline is intended to show the tasks needing to be accomplished, and give an idea of when releases will happen.
|
||||
|
||||
Core:
|
||||
-----
|
||||
These are the tasks that will need to be accomplished before the 1.0 major release.
|
||||
|
||||
* Project setup
|
||||
* Add the appcompat project to the Git repository
|
||||
|
||||
**Done as of [d6c7f498e6e1f5bbd7895f979dc25c5537e7cae5](https://github.com/DjBushido/MinimalBible/commit/d6c7f498e6e1f5bbd7895f979dc25c5537e7cae5)**
|
||||
|
||||
* Integration with JSword
|
||||
* Build JSword
|
||||
* Distribute an Android binary that contains JSword and 3rd party libraries
|
||||
|
||||
**Done as of [fd6c0630799d360cef83871cc6b3af05e4dc3a0d](https://github.com/DjBushido/MinimalBible/commit/fd6c0630799d360cef83871cc6b3af05e4dc3a0d)**
|
||||
|
||||
* Download Manager
|
||||
* Bible browser
|
||||
* Can download Bibles
|
||||
* Can remove Bibles
|
||||
* Generate search indexes for Bibles
|
||||
|
||||
* Bible Viewer
|
||||
* UI design finalized
|
||||
* Use Immersive mode for 4.4+?
|
||||
* Panels for footnotes, commentary?
|
||||
* Navigation drawer for books?
|
||||
* What gestures should be used? (Swipe left/right for chapter search?)
|
||||
* How to get to Download Manager / some form of home page?
|
||||
* Navigation of books working
|
||||
* Can display Bible text
|
||||
* Time from launch to viewing text under 5s. Ideally, under 3s. as well.
|
||||
* Can use navigation drawer to open a book
|
||||
* Infinite scroll between chapters
|
||||
* Research how to accomplish infinite scroll
|
||||
* Implement infinite scroll
|
||||
* Red letter enabled
|
||||
|
||||
* Cleanup
|
||||
* Include only necessary libraries for jSword, rather than all dependencies. APK ~20MB is way too big.
|
||||
|
||||
**Release v.1 to Play store**
|
||||
|
||||
* * *
|
||||
|
||||
* Search
|
||||
* UI design finalized (integration in Bible Viewer, separate activity?)
|
||||
* Search functionality implemented
|
||||
* Get Lucene search working (included in JSword)
|
||||
* Tweak search (fuzzy? Lord -> LORD? Are we actually getting results we want?)
|
||||
* Search history recorded
|
||||
* Record when search took place?
|
||||
|
||||
**Release v.2**
|
||||
|
||||
* * *
|
||||
|
||||
* Download Manager
|
||||
* Download manager can fetch commentaries
|
||||
|
||||
* Footnotes/Commentaries
|
||||
* UI design finalized
|
||||
* Frame on bottom of Bible Viewer a la [this](http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/)?
|
||||
* Switch between footnotes/commentaries by swiping on panel?
|
||||
* Right-side nav drawer like FB?
|
||||
* Can we synchronize scroll between commentaries/footnotes?
|
||||
* Should Bible search also search commentaries?
|
||||
* Implement/Show commentaries/footnotes
|
||||
* Synchronize scrolling Bible to footnotes/commentaries
|
||||
* Is this possible?
|
||||
* Implement it!
|
||||
* Clicking on note in text opens commentary
|
||||
|
||||
**Release v.3**
|
||||
|
||||
* * *
|
||||
|
||||
* Settings Manager
|
||||
* Night mode?
|
||||
* Automatic night mode?
|
||||
* Text font/size
|
||||
* Clear searches?
|
||||
* Disable red-letter?
|
||||
* Send feedback
|
||||
|
||||
* Home screen
|
||||
* Allow access to settings, download manager, and Bible Viewer
|
||||
|
||||
**Release v1.0**
|
||||
**Party!**
|
||||
|
||||
* * *
|
||||
|
||||
Feature Addition
|
||||
----------------
|
||||
|
||||
These are features I want to add, but are not considered part of the "core" product. Many (most) are necessary features of a modern app, but follow after the first major release.
|
||||
|
||||
### Usage statistics
|
||||
* Include usage statistics?
|
||||
* Only send statistics on WiFi?
|
||||
* Disable by default? Prompt user?
|
||||
|
||||
### Sharing
|
||||
* UI Design finalized
|
||||
* Click on text to select it, then share?
|
||||
* Long-click text to share?
|
||||
* Share currently active text?
|
||||
* Dialog to select what range of text is included?
|
||||
* Share commentary/footnotes?
|
||||
* Intent filter created to share via FB, email, etc.
|
||||
* Settings
|
||||
* Share link to app alongside text? Allow disabling?
|
||||
|
||||
* * *
|
||||
|
||||
### Highlighting
|
||||
* UI Design finalized
|
||||
* Click on text to select like share?
|
||||
* Highlight colors / custom colors?
|
||||
* Multiple highlight colors?
|
||||
* Remove highlights?
|
||||
|
||||
* Database backing
|
||||
* First feature to need a database! Success!
|
||||
* How to store sections of highlighted material?
|
||||
* Store start/end range, along with highlight color?
|
||||
* Store when highlight was created?
|
||||
|
||||
* Bible Viewer
|
||||
* How to show highlights?
|
||||
* More specifically, how does showing highlights impact performance on start?
|
||||
* Show text first, then highlights after loaded?
|
||||
|
||||
* * *
|
||||
|
||||
### Notes
|
||||
* UI Design finalized
|
||||
* Likely very similar to highlighting
|
||||
|
||||
* Database backing
|
||||
* Likely very similar to highlighting
|
||||
* Store note instead of highlight color?
|
||||
* Store when note was created / updated?
|
||||
|
||||
* Bible Viewer
|
||||
* Same concerns as highlighting, how does it impact speed?
|
||||
* How do we display notes? Highlighting changes background color, have a separate link for our notes?
|
||||
* Do notes get added to a panel on bottom? Can user browse notes?
|
||||
|
||||
* Home Screen
|
||||
* Notes browser
|
||||
|
||||
* * *
|
||||
|
||||
### Widgets
|
||||
|
||||
* Text to display here?
|
||||
* Shortcut to specific verse/chapter?
|
||||
* How to create shortcuts?
|
||||
|
||||
* * *
|
||||
|
||||
### Cloud support
|
||||
|
||||
* Backup notes/highlights to cloud service?
|
||||
* Just backup entire app database to cloud?
|
||||
* Google Drive/Dropbox?
|
||||
* Settings
|
||||
* Automated backups?
|
||||
* Backup on WiFi only?
|
||||
|
||||
* * *
|
||||
|
||||
Plenty to get done!
|
83
MinimalBible/build.gradle
Normal file
@ -0,0 +1,83 @@
|
||||
apply plugin: 'android'
|
||||
apply plugin: 'android-apt'
|
||||
//apply plugin: 'retrolambda'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(path: ':jsword-minimalbible', configuration: 'buildJSword')
|
||||
compile project(':appcompat_v7')
|
||||
apt 'com.squareup.dagger:dagger-compiler:1.2.0'
|
||||
compile 'com.squareup.dagger:dagger:1.2.0'
|
||||
apt 'com.jakewharton:butterknife:5.0.1'
|
||||
compile 'com.jakewharton:butterknife:5.0.1'
|
||||
compile 'de.devland.esperandro:esperandro-api:1.1.2'
|
||||
apt 'de.devland.esperandro:esperandro:1.1.2'
|
||||
// compile 'com.f2prateek.dart:dart:1.1.0'
|
||||
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
|
||||
compile 'com.netflix.rxjava:rxjava-android:0.19.0'
|
||||
|
||||
// Handled by appcompat
|
||||
// compile 'com.google.android:support-v4:r7'
|
||||
|
||||
// And our unit testing needs some specific stuff (and specific stuff included again)
|
||||
androidTestCompile 'junit:junit:4.11+'
|
||||
androidTestCompile 'com.jayway.awaitility:awaitility:1.6.0'
|
||||
androidTestProvided 'com.squareup.dagger:dagger-compiler:1.2.0'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 19
|
||||
buildToolsVersion '20'
|
||||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile 'src/main/AndroidManifest.xml'
|
||||
java.srcDirs = ['src/main/java']
|
||||
resources.srcDirs = ['src/main/res']
|
||||
aidl.srcDirs = ['src']
|
||||
renderscript.srcDirs = ['src']
|
||||
res.srcDirs = ['src/main/res']
|
||||
assets.srcDirs = ['src/main/assets']
|
||||
}
|
||||
|
||||
// Move the tests to tests/java, tests/res, etc...
|
||||
androidTest {
|
||||
manifest.srcFile 'src/test/AndroidManifest.xml'
|
||||
java.srcDirs = ['src/test/java']
|
||||
resources.srcDirs = ['src/test/res']
|
||||
assets.srcDirs = ['src/test/assets']
|
||||
}
|
||||
|
||||
// Move the build types to build-types/<type>
|
||||
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
|
||||
// This moves them out of them default location under src/<type>/... which would
|
||||
// conflict with src/ being used by the main source set.
|
||||
// Adding new build types or product flavors should be accompanied
|
||||
// by a similar customization.
|
||||
debug.setRoot('build-types/debug')
|
||||
release.setRoot('build-types/release')
|
||||
}
|
||||
packagingOptions {
|
||||
exclude 'META-INF/LICENSE.txt'
|
||||
exclude 'LICENSE.txt'
|
||||
exclude 'META-INF/NOTICE.txt'
|
||||
exclude 'META-INF/DEPENDENCIES'
|
||||
exclude 'META-INF/LICENSE'
|
||||
exclude 'META-INF/NOTICE'
|
||||
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
BIN
MinimalBible/ic_launcher-web.png
Normal file
After Width: | Height: | Size: 23 KiB |
1
MinimalBible/libs/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.jar
|
20
MinimalBible/proguard-project.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
15
MinimalBible/project.properties
Normal file
@ -0,0 +1,15 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-19
|
||||
android.library.reference.1=../appcompat_v7
|
34
MinimalBible/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.bspeice.minimalbible"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:targetSdkVersion="20" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:name="org.bspeice.minimalbible.MinimalBible" >
|
||||
<activity
|
||||
android:name="org.bspeice.minimalbible.activities.viewer.BibleViewer"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="org.bspeice.minimalbible.activities.downloader.DownloadActivity"
|
||||
android:label="@string/title_activity_download" >
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
11
MinimalBible/src/main/assets/book.html
Normal file
@ -0,0 +1,11 @@
|
||||
<html>
|
||||
<body>
|
||||
<div id="content" />
|
||||
|
||||
<script type="text/javascript">
|
||||
function set_content(content) {
|
||||
document.getElementById("content").innerHTML = content;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,530 @@
|
||||
package com.todddavies.components.progressbar;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import org.bspeice.minimalbible.R;
|
||||
|
||||
|
||||
/**
|
||||
* An indicator of progress, similar to Android's ProgressBar.
|
||||
* Can be used in 'spin mode' or 'increment mode'
|
||||
*
|
||||
* @author Todd Davies
|
||||
* <p/>
|
||||
* Licensed under the Creative Commons Attribution 3.0 license see:
|
||||
* http://creativecommons.org/licenses/by/3.0/
|
||||
*/
|
||||
public class ProgressWheel extends View {
|
||||
|
||||
//Sizes (with defaults)
|
||||
private int layout_height = 0;
|
||||
private int layout_width = 0;
|
||||
private int fullRadius = 100;
|
||||
private int circleRadius = 80;
|
||||
private int barLength = 60;
|
||||
private int barWidth = 20;
|
||||
private int rimWidth = 20;
|
||||
private int textSize = 20;
|
||||
private float contourSize = 0;
|
||||
|
||||
//Padding (with defaults)
|
||||
private int paddingTop = 5;
|
||||
private int paddingBottom = 5;
|
||||
private int paddingLeft = 5;
|
||||
private int paddingRight = 5;
|
||||
|
||||
//Colors (with defaults)
|
||||
private int barColor = 0xAA000000;
|
||||
private int contourColor = 0xAA000000;
|
||||
private int circleColor = 0x00000000;
|
||||
private int rimColor = 0xAADDDDDD;
|
||||
private int textColor = 0xFF000000;
|
||||
|
||||
//Paints
|
||||
private Paint barPaint = new Paint();
|
||||
private Paint circlePaint = new Paint();
|
||||
private Paint rimPaint = new Paint();
|
||||
private Paint textPaint = new Paint();
|
||||
private Paint contourPaint = new Paint();
|
||||
|
||||
//Rectangles
|
||||
@SuppressWarnings("unused")
|
||||
private RectF rectBounds = new RectF();
|
||||
private RectF circleBounds = new RectF();
|
||||
private RectF circleOuterContour = new RectF();
|
||||
private RectF circleInnerContour = new RectF();
|
||||
|
||||
//Animation
|
||||
//The amount of pixels to move the bar by on each draw
|
||||
private int spinSpeed = 2;
|
||||
//The number of milliseconds to wait inbetween each draw
|
||||
private int delayMillis = 0;
|
||||
private Handler spinHandler = new Handler() {
|
||||
/**
|
||||
* This is the code that will increment the progress variable
|
||||
* and so spin the wheel
|
||||
*/
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
invalidate();
|
||||
if (isSpinning) {
|
||||
progress += spinSpeed;
|
||||
if (progress > 360) {
|
||||
progress = 0;
|
||||
}
|
||||
spinHandler.sendEmptyMessageDelayed(0, delayMillis);
|
||||
}
|
||||
//super.handleMessage(msg);
|
||||
}
|
||||
};
|
||||
int progress = 0;
|
||||
boolean isSpinning = false;
|
||||
|
||||
//Other
|
||||
private String text = "";
|
||||
private String[] splitText = {};
|
||||
|
||||
/**
|
||||
* The constructor for the ProgressWheel
|
||||
*
|
||||
* @param context
|
||||
* @param attrs
|
||||
*/
|
||||
public ProgressWheel(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
parseAttributes(context.obtainStyledAttributes(attrs,
|
||||
R.styleable.ProgressWheel));
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
//Setting up stuff
|
||||
//----------------------------------
|
||||
|
||||
/*
|
||||
* When this is called, make the view square.
|
||||
* From: http://www.jayway.com/2012/12/12/creating-custom-android-views-part-4-measuring-and-how-to-force-a-view-to-be-square/
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
// The first thing that happen is that we call the superclass
|
||||
// implementation of onMeasure. The reason for that is that measuring
|
||||
// can be quite a complex process and calling the super method is a
|
||||
// convenient way to get most of this complexity handled.
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
// We can’t use getWidth() or getHight() here. During the measuring
|
||||
// pass the view has not gotten its final size yet (this happens first
|
||||
// at the start of the layout pass) so we have to use getMeasuredWidth()
|
||||
// and getMeasuredHeight().
|
||||
int size = 0;
|
||||
int width = getMeasuredWidth();
|
||||
int height = getMeasuredHeight();
|
||||
int widthWithoutPadding = width - getPaddingLeft() - getPaddingRight();
|
||||
int heigthWithoutPadding = height - getPaddingTop() - getPaddingBottom();
|
||||
|
||||
// Finally we have some simple logic that calculates the size of the view
|
||||
// and calls setMeasuredDimension() to set that size.
|
||||
// Before we compare the width and height of the view, we remove the padding,
|
||||
// and when we set the dimension we add it back again. Now the actual content
|
||||
// of the view will be square, but, depending on the padding, the total dimensions
|
||||
// of the view might not be.
|
||||
if (widthWithoutPadding > heigthWithoutPadding) {
|
||||
size = heigthWithoutPadding;
|
||||
} else {
|
||||
size = widthWithoutPadding;
|
||||
}
|
||||
|
||||
// If you override onMeasure() you have to call setMeasuredDimension().
|
||||
// This is how you report back the measured size. If you don’t call
|
||||
// setMeasuredDimension() the parent will throw an exception and your
|
||||
// application will crash.
|
||||
// We are calling the onMeasure() method of the superclass so we don’t
|
||||
// actually need to call setMeasuredDimension() since that takes care
|
||||
// of that. However, the purpose with overriding onMeasure() was to
|
||||
// change the default behaviour and to do that we need to call
|
||||
// setMeasuredDimension() with our own values.
|
||||
setMeasuredDimension(size + getPaddingLeft() + getPaddingRight(), size + getPaddingTop() + getPaddingBottom());
|
||||
}
|
||||
|
||||
/**
|
||||
* Use onSizeChanged instead of onAttachedToWindow to get the dimensions of the view,
|
||||
* because this method is called after measuring the dimensions of MATCH_PARENT & WRAP_CONTENT.
|
||||
* Use this dimensions to setup the bounds and paints.
|
||||
*/
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
|
||||
// Share the dimensions
|
||||
layout_width = w;
|
||||
layout_height = h;
|
||||
|
||||
setupBounds();
|
||||
setupPaints();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties of the paints we're using to
|
||||
* draw the progress wheel
|
||||
*/
|
||||
private void setupPaints() {
|
||||
barPaint.setColor(barColor);
|
||||
barPaint.setAntiAlias(true);
|
||||
barPaint.setStyle(Style.STROKE);
|
||||
barPaint.setStrokeWidth(barWidth);
|
||||
|
||||
rimPaint.setColor(rimColor);
|
||||
rimPaint.setAntiAlias(true);
|
||||
rimPaint.setStyle(Style.STROKE);
|
||||
rimPaint.setStrokeWidth(rimWidth);
|
||||
|
||||
circlePaint.setColor(circleColor);
|
||||
circlePaint.setAntiAlias(true);
|
||||
circlePaint.setStyle(Style.FILL);
|
||||
|
||||
textPaint.setColor(textColor);
|
||||
textPaint.setStyle(Style.FILL);
|
||||
textPaint.setAntiAlias(true);
|
||||
textPaint.setTextSize(textSize);
|
||||
|
||||
contourPaint.setColor(contourColor);
|
||||
contourPaint.setAntiAlias(true);
|
||||
contourPaint.setStyle(Style.STROKE);
|
||||
contourPaint.setStrokeWidth(contourSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bounds of the component
|
||||
*/
|
||||
private void setupBounds() {
|
||||
// Width should equal to Height, find the min value to steup the circle
|
||||
int minValue = Math.min(layout_width, layout_height);
|
||||
|
||||
// Calc the Offset if needed
|
||||
int xOffset = layout_width - minValue;
|
||||
int yOffset = layout_height - minValue;
|
||||
|
||||
// Add the offset
|
||||
paddingTop = this.getPaddingTop() + (yOffset / 2);
|
||||
paddingBottom = this.getPaddingBottom() + (yOffset / 2);
|
||||
paddingLeft = this.getPaddingLeft() + (xOffset / 2);
|
||||
paddingRight = this.getPaddingRight() + (xOffset / 2);
|
||||
|
||||
int width = getWidth(); //this.getLayoutParams().width;
|
||||
int height = getHeight(); //this.getLayoutParams().height;
|
||||
|
||||
rectBounds = new RectF(paddingLeft,
|
||||
paddingTop,
|
||||
width - paddingRight,
|
||||
height - paddingBottom);
|
||||
|
||||
circleBounds = new RectF(paddingLeft + barWidth,
|
||||
paddingTop + barWidth,
|
||||
width - paddingRight - barWidth,
|
||||
height - paddingBottom - barWidth);
|
||||
circleInnerContour = new RectF(circleBounds.left + (rimWidth / 2.0f) + (contourSize / 2.0f), circleBounds.top + (rimWidth / 2.0f) + (contourSize / 2.0f), circleBounds.right - (rimWidth / 2.0f) - (contourSize / 2.0f), circleBounds.bottom - (rimWidth / 2.0f) - (contourSize / 2.0f));
|
||||
circleOuterContour = new RectF(circleBounds.left - (rimWidth / 2.0f) - (contourSize / 2.0f), circleBounds.top - (rimWidth / 2.0f) - (contourSize / 2.0f), circleBounds.right + (rimWidth / 2.0f) + (contourSize / 2.0f), circleBounds.bottom + (rimWidth / 2.0f) + (contourSize / 2.0f));
|
||||
|
||||
fullRadius = (width - paddingRight - barWidth) / 2;
|
||||
circleRadius = (fullRadius - barWidth) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the attributes passed to the view from the XML
|
||||
*
|
||||
* @param a the attributes to parse
|
||||
*/
|
||||
private void parseAttributes(TypedArray a) {
|
||||
barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth,
|
||||
barWidth);
|
||||
|
||||
rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth,
|
||||
rimWidth);
|
||||
|
||||
spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_spinSpeed,
|
||||
spinSpeed);
|
||||
|
||||
delayMillis = a.getInteger(R.styleable.ProgressWheel_delayMillis,
|
||||
delayMillis);
|
||||
if (delayMillis < 0) {
|
||||
delayMillis = 0;
|
||||
}
|
||||
|
||||
barColor = a.getColor(R.styleable.ProgressWheel_barColor, barColor);
|
||||
|
||||
barLength = (int) a.getDimension(R.styleable.ProgressWheel_barLength,
|
||||
barLength);
|
||||
|
||||
textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize,
|
||||
textSize);
|
||||
|
||||
textColor = (int) a.getColor(R.styleable.ProgressWheel_textColor,
|
||||
textColor);
|
||||
|
||||
//if the text is empty , so ignore it
|
||||
if (a.hasValue(R.styleable.ProgressWheel_text)) {
|
||||
setText(a.getString(R.styleable.ProgressWheel_text));
|
||||
}
|
||||
|
||||
rimColor = (int) a.getColor(R.styleable.ProgressWheel_rimColor,
|
||||
rimColor);
|
||||
|
||||
circleColor = (int) a.getColor(R.styleable.ProgressWheel_circleColor,
|
||||
circleColor);
|
||||
|
||||
contourColor = a.getColor(R.styleable.ProgressWheel_contourColor, contourColor);
|
||||
contourSize = a.getDimension(R.styleable.ProgressWheel_contourSize, contourSize);
|
||||
|
||||
|
||||
// Recycle
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
//Animation stuff
|
||||
//----------------------------------
|
||||
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
//Draw the inner circle
|
||||
canvas.drawArc(circleBounds, 360, 360, false, circlePaint);
|
||||
//Draw the rim
|
||||
canvas.drawArc(circleBounds, 360, 360, false, rimPaint);
|
||||
canvas.drawArc(circleOuterContour, 360, 360, false, contourPaint);
|
||||
canvas.drawArc(circleInnerContour, 360, 360, false, contourPaint);
|
||||
//Draw the bar
|
||||
if (isSpinning) {
|
||||
canvas.drawArc(circleBounds, progress - 90, barLength, false,
|
||||
barPaint);
|
||||
} else {
|
||||
canvas.drawArc(circleBounds, -90, progress, false, barPaint);
|
||||
}
|
||||
//Draw the text (attempts to center it horizontally and vertically)
|
||||
float textHeight = textPaint.descent() - textPaint.ascent();
|
||||
float verticalTextOffset = (textHeight / 2) - textPaint.descent();
|
||||
|
||||
for (String s : splitText) {
|
||||
float horizontalTextOffset = textPaint.measureText(s) / 2;
|
||||
canvas.drawText(s, this.getWidth() / 2 - horizontalTextOffset,
|
||||
this.getHeight() / 2 + verticalTextOffset, textPaint);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the wheel is currently spinning
|
||||
*/
|
||||
|
||||
public boolean isSpinning() {
|
||||
if(isSpinning){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the count (in increment mode)
|
||||
*/
|
||||
public void resetCount() {
|
||||
progress = 0;
|
||||
setText("0%");
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off spin mode
|
||||
*/
|
||||
public void stopSpinning() {
|
||||
isSpinning = false;
|
||||
progress = 0;
|
||||
spinHandler.removeMessages(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Puts the view on spin mode
|
||||
*/
|
||||
public void spin() {
|
||||
isSpinning = true;
|
||||
spinHandler.sendEmptyMessage(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the progress by 1 (of 360)
|
||||
*/
|
||||
public void incrementProgress() {
|
||||
isSpinning = false;
|
||||
progress++;
|
||||
if (progress > 360)
|
||||
progress = 0;
|
||||
// setText(Math.round(((float) progress / 360) * 100) + "%");
|
||||
spinHandler.sendEmptyMessage(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the progress to a specific value
|
||||
*/
|
||||
public void setProgress(int i) {
|
||||
isSpinning = false;
|
||||
progress = i;
|
||||
spinHandler.sendEmptyMessage(0);
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
//Getters + setters
|
||||
//----------------------------------
|
||||
|
||||
/**
|
||||
* Set the text in the progress bar
|
||||
* Doesn't invalidate the view
|
||||
*
|
||||
* @param text the text to show ('\n' constitutes a new line)
|
||||
*/
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
splitText = this.text.split("\n");
|
||||
}
|
||||
|
||||
public int getCircleRadius() {
|
||||
return circleRadius;
|
||||
}
|
||||
|
||||
public void setCircleRadius(int circleRadius) {
|
||||
this.circleRadius = circleRadius;
|
||||
}
|
||||
|
||||
public int getBarLength() {
|
||||
return barLength;
|
||||
}
|
||||
|
||||
public void setBarLength(int barLength) {
|
||||
this.barLength = barLength;
|
||||
}
|
||||
|
||||
public int getBarWidth() {
|
||||
return barWidth;
|
||||
}
|
||||
|
||||
public void setBarWidth(int barWidth) {
|
||||
this.barWidth = barWidth;
|
||||
}
|
||||
|
||||
public int getTextSize() {
|
||||
return textSize;
|
||||
}
|
||||
|
||||
public void setTextSize(int textSize) {
|
||||
this.textSize = textSize;
|
||||
}
|
||||
|
||||
public int getPaddingTop() {
|
||||
return paddingTop;
|
||||
}
|
||||
|
||||
public void setPaddingTop(int paddingTop) {
|
||||
this.paddingTop = paddingTop;
|
||||
}
|
||||
|
||||
public int getPaddingBottom() {
|
||||
return paddingBottom;
|
||||
}
|
||||
|
||||
public void setPaddingBottom(int paddingBottom) {
|
||||
this.paddingBottom = paddingBottom;
|
||||
}
|
||||
|
||||
public int getPaddingLeft() {
|
||||
return paddingLeft;
|
||||
}
|
||||
|
||||
public void setPaddingLeft(int paddingLeft) {
|
||||
this.paddingLeft = paddingLeft;
|
||||
}
|
||||
|
||||
public int getPaddingRight() {
|
||||
return paddingRight;
|
||||
}
|
||||
|
||||
public void setPaddingRight(int paddingRight) {
|
||||
this.paddingRight = paddingRight;
|
||||
}
|
||||
|
||||
public int getBarColor() {
|
||||
return barColor;
|
||||
}
|
||||
|
||||
public void setBarColor(int barColor) {
|
||||
this.barColor = barColor;
|
||||
}
|
||||
|
||||
public int getCircleColor() {
|
||||
return circleColor;
|
||||
}
|
||||
|
||||
public void setCircleColor(int circleColor) {
|
||||
this.circleColor = circleColor;
|
||||
}
|
||||
|
||||
public int getRimColor() {
|
||||
return rimColor;
|
||||
}
|
||||
|
||||
public void setRimColor(int rimColor) {
|
||||
this.rimColor = rimColor;
|
||||
}
|
||||
|
||||
|
||||
public Shader getRimShader() {
|
||||
return rimPaint.getShader();
|
||||
}
|
||||
|
||||
public void setRimShader(Shader shader) {
|
||||
this.rimPaint.setShader(shader);
|
||||
}
|
||||
|
||||
public int getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
|
||||
public void setTextColor(int textColor) {
|
||||
this.textColor = textColor;
|
||||
}
|
||||
|
||||
public int getSpinSpeed() {
|
||||
return spinSpeed;
|
||||
}
|
||||
|
||||
public void setSpinSpeed(int spinSpeed) {
|
||||
this.spinSpeed = spinSpeed;
|
||||
}
|
||||
|
||||
public int getRimWidth() {
|
||||
return rimWidth;
|
||||
}
|
||||
|
||||
public void setRimWidth(int rimWidth) {
|
||||
this.rimWidth = rimWidth;
|
||||
}
|
||||
|
||||
public int getDelayMillis() {
|
||||
return delayMillis;
|
||||
}
|
||||
|
||||
public void setDelayMillis(int delayMillis) {
|
||||
this.delayMillis = delayMillis;
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.crosswire.jsword.book.sword.SwordBookPath;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import dagger.ObjectGraph;
|
||||
|
||||
public class MinimalBible extends Application {
|
||||
|
||||
/**
|
||||
* The graph used by Dagger to track dependencies
|
||||
*/
|
||||
private ObjectGraph graph;
|
||||
|
||||
/**
|
||||
* A singleton reference to the Application currently being run.
|
||||
* Used mostly so we have a fixed point to get the App Context from
|
||||
*/
|
||||
private static MinimalBible instance;
|
||||
|
||||
private String TAG = "MinimalBible";
|
||||
|
||||
/**
|
||||
* Create the application, and persist the application Context
|
||||
*/
|
||||
public MinimalBible() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Application Context. Please note, all attempts to get the App Context should come
|
||||
* through here, and please be sure that the Application won't satisfy what you need.
|
||||
* @return The Application Context
|
||||
*/
|
||||
public static Context getAppContext() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Application, rather than just the Application Context. You likely should be using
|
||||
* this, rather than {@link #getAppContext()}
|
||||
* @return The MinimalBible {@link android.app.Application} object
|
||||
*/
|
||||
public static MinimalBible getApplication() {
|
||||
return (MinimalBible)getAppContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the {@link android.app.Application}. Responsible for building and
|
||||
* holding on to the master ObjectGraph.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
//TODO: Is this necessary?
|
||||
inject(this);
|
||||
setJswordHome();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject a Dagger object
|
||||
* @param o The object to be injected
|
||||
*/
|
||||
public void inject(Object o) {
|
||||
getObjGraph().inject(o);
|
||||
}
|
||||
|
||||
public ObjectGraph getObjGraph() {
|
||||
if (graph == null) {
|
||||
graph = ObjectGraph.create(MinimalBibleModules.class);
|
||||
}
|
||||
return graph;
|
||||
}
|
||||
|
||||
public void plusObjGraph(Object... modules) {
|
||||
graph = graph.plus(modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify jSword that it needs to store files in the Android internal directory
|
||||
* NOTE: Android will uninstall these files if you uninstall MinimalBible.
|
||||
*/
|
||||
@SuppressWarnings("null")
|
||||
private void setJswordHome() {
|
||||
// We need to set the download directory for jSword to stick with
|
||||
// Android.
|
||||
String home = MinimalBible.getAppContext().getFilesDir().toString();
|
||||
Log.d(TAG, "Setting jsword.home to: " + home);
|
||||
System.setProperty("jsword.home", home);
|
||||
System.setProperty("sword.home", home);
|
||||
SwordBookPath.setDownloadDir(new File(home));
|
||||
Log.d(TAG, "Sword download path: " + SwordBookPath.getSwordDownloadDir());
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import org.bspeice.minimalbible.activities.ActivityModules;
|
||||
|
||||
import dagger.Module;
|
||||
|
||||
/**
|
||||
* Master module for MinimalBible
|
||||
*/
|
||||
@Module(
|
||||
injects = {
|
||||
MinimalBible.class
|
||||
},
|
||||
includes = {
|
||||
ActivityModules.class
|
||||
}
|
||||
)
|
||||
public class MinimalBibleModules {
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package org.bspeice.minimalbible.activities;
|
||||
|
||||
import org.bspeice.minimalbible.activities.downloader.ActivityDownloaderModule;
|
||||
import org.bspeice.minimalbible.activities.viewer.ActivityViewerModule;
|
||||
|
||||
import dagger.Module;
|
||||
|
||||
/**
|
||||
* Modules for all activities
|
||||
*/
|
||||
@Module(
|
||||
includes = {
|
||||
ActivityDownloaderModule.class,
|
||||
ActivityViewerModule.class
|
||||
}
|
||||
)
|
||||
public class ActivityModules {
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.bspeice.minimalbible.activities;
|
||||
|
||||
import org.bspeice.minimalbible.R;
|
||||
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
/**
|
||||
* Wrapper for activities in MinimalBible to make sure we can support
|
||||
* common functionality between them all.
|
||||
*/
|
||||
public class BaseActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Only set the tint if the device is running KitKat or above
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(this);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintColor(getResources().getColor(
|
||||
R.color.statusbar));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package org.bspeice.minimalbible.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.View;
|
||||
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
|
||||
/**
|
||||
* Base class that defines all behavior common to Fragments in MinimalBible
|
||||
*/
|
||||
public class BaseFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* Calculate the offset we need to display properly if the System bar is translucent
|
||||
* @param context The {@link android.app.Activity} we are displaying in
|
||||
* @param view The {@link android.view.View} we need to calculate the offset for.
|
||||
*/
|
||||
protected static void setInsets(Activity context, View view) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(context);
|
||||
SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
|
||||
view.setPadding(0, config.getPixelInsetTop(true), config.getPixelInsetRight(), config.getPixelInsetBottom());
|
||||
}
|
||||
}
|
@ -0,0 +1,302 @@
|
||||
package org.bspeice.minimalbible.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.ActionBarDrawerToggle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
|
||||
import org.bspeice.minimalbible.R;
|
||||
|
||||
/**
|
||||
* Fragment used for managing interactions for and presentation of a navigation
|
||||
* drawer. See the <a href=
|
||||
* "https://developer.android.com/design/patterns/navigation-drawer.html#Interaction"
|
||||
* > design guidelines</a> for a complete explanation of the behaviors
|
||||
* implemented here.
|
||||
*/
|
||||
public class BaseNavigationDrawerFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* Remember the position of the selected item.
|
||||
*/
|
||||
private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
|
||||
|
||||
/**
|
||||
* Per the design guidelines, you should show the drawer on launch until the
|
||||
* user manually expands it. This shared preference tracks this.
|
||||
*/
|
||||
private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
|
||||
|
||||
/**
|
||||
* A pointer to the current callbacks instance (the Activity).
|
||||
*/
|
||||
private NavigationDrawerCallbacks mCallbacks;
|
||||
|
||||
/**
|
||||
* Helper component that ties the action bar to the navigation drawer.
|
||||
*/
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
|
||||
private DrawerLayout mDrawerLayout;
|
||||
protected ListView mDrawerListView;
|
||||
private View mFragmentContainerView;
|
||||
|
||||
protected int mCurrentSelectedPosition = 0;
|
||||
private boolean mFromSavedInstanceState;
|
||||
private boolean mUserLearnedDrawer;
|
||||
|
||||
public BaseNavigationDrawerFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Read in the flag indicating whether or not the user has demonstrated
|
||||
// awareness of the
|
||||
// drawer. See PREF_USER_LEARNED_DRAWER for details.
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences(getActivity());
|
||||
mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mCurrentSelectedPosition = savedInstanceState
|
||||
.getInt(STATE_SELECTED_POSITION);
|
||||
mFromSavedInstanceState = true;
|
||||
}
|
||||
|
||||
// Select either the default item (0) or the last selected item.
|
||||
selectItem(mCurrentSelectedPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
// Indicate that this fragment would like to influence the set of
|
||||
// actions in the action bar.
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
public boolean isDrawerOpen() {
|
||||
return mDrawerLayout != null
|
||||
&& mDrawerLayout.isDrawerOpen(mFragmentContainerView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Users of this fragment must call this method to set up the navigation
|
||||
* drawer interactions.
|
||||
*
|
||||
* @param fragmentId
|
||||
* The android:id of this fragment in its activity's layout.
|
||||
* @param drawerLayout
|
||||
* The DrawerLayout containing this fragment's UI.
|
||||
*/
|
||||
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
|
||||
mFragmentContainerView = getActivity().findViewById(fragmentId);
|
||||
mDrawerLayout = drawerLayout;
|
||||
|
||||
// set a custom shadow that overlays the main content when the drawer
|
||||
// opens
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
|
||||
GravityCompat.START);
|
||||
// set up the drawer's list view with items and click listener
|
||||
|
||||
ActionBar actionBar = getActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
|
||||
// ActionBarDrawerToggle ties together the the proper interactions
|
||||
// between the navigation drawer and the action bar app icon.
|
||||
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
|
||||
mDrawerLayout, /* DrawerLayout object */
|
||||
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
|
||||
R.string.navigation_drawer_open, /*
|
||||
* "open drawer" description for
|
||||
* accessibility
|
||||
*/
|
||||
R.string.navigation_drawer_close /*
|
||||
* "close drawer" description for
|
||||
* accessibility
|
||||
*/
|
||||
) {
|
||||
@Override
|
||||
public void onDrawerClosed(View drawerView) {
|
||||
super.onDrawerClosed(drawerView);
|
||||
if (!isAdded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getActivity().supportInvalidateOptionsMenu(); // calls
|
||||
// onPrepareOptionsMenu()
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
if (!isAdded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mUserLearnedDrawer) {
|
||||
// The user manually opened the drawer; store this flag to
|
||||
// prevent auto-showing
|
||||
// the navigation drawer automatically in the future.
|
||||
mUserLearnedDrawer = true;
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences(getActivity());
|
||||
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true)
|
||||
.commit();
|
||||
}
|
||||
|
||||
getActivity().supportInvalidateOptionsMenu(); // calls
|
||||
// onPrepareOptionsMenu()
|
||||
}
|
||||
};
|
||||
|
||||
// If the user hasn't 'learned' about the drawer, open it to introduce
|
||||
// them to the drawer,
|
||||
// per the navigation drawer design guidelines.
|
||||
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
|
||||
mDrawerLayout.openDrawer(mFragmentContainerView);
|
||||
}
|
||||
|
||||
// Defer code dependent on restoration of previous instance state.
|
||||
mDrawerLayout.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mDrawerToggle.syncState();
|
||||
}
|
||||
});
|
||||
|
||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||
}
|
||||
|
||||
public void selectItem(int position) {
|
||||
mCurrentSelectedPosition = position;
|
||||
if (mDrawerListView != null) {
|
||||
mDrawerListView.setItemChecked(position, true);
|
||||
}
|
||||
if (mDrawerLayout != null) {
|
||||
mDrawerLayout.closeDrawer(mFragmentContainerView);
|
||||
}
|
||||
if (mCallbacks != null) {
|
||||
mCallbacks.onNavigationDrawerItemSelected(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
mCallbacks = (NavigationDrawerCallbacks) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(
|
||||
"Activity must implement NavigationDrawerCallbacks.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mCallbacks = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
// Forward the new configuration the drawer toggle component.
|
||||
mDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// If the drawer is open, show the global app actions in the action bar.
|
||||
// See also
|
||||
// showGlobalContextActionBar, which controls the top-left area of the
|
||||
// action bar.
|
||||
if (mDrawerLayout != null && isDrawerOpen()) {
|
||||
inflater.inflate(R.menu.global, menu);
|
||||
showGlobalContextActionBar();
|
||||
}
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (mDrawerToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Per the navigation drawer design guidelines, updates the action bar to
|
||||
* show the global app 'context', rather than just what's in the current
|
||||
* screen.
|
||||
*/
|
||||
private void showGlobalContextActionBar() {
|
||||
ActionBar actionBar = getActionBar();
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
// actionBar.setTitle(R.string.app_name);
|
||||
}
|
||||
|
||||
protected ActionBar getActionBar() {
|
||||
return ((ActionBarActivity) getActivity()).getSupportActionBar();
|
||||
}
|
||||
|
||||
public void setInsets(View view) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
|
||||
return;
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(getActivity());
|
||||
SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
|
||||
view.setPadding(0, config.getPixelInsetTop(true),
|
||||
config.getPixelInsetRight(), config.getPixelInsetBottom());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
// This could also be a ScrollView
|
||||
ListView list = (ListView) view.findViewById(R.id.list_nav_drawer);
|
||||
// This could also be set in your layout, allows the list items to
|
||||
// scroll through the bottom padded area (navigation bar)
|
||||
list.setClipToPadding(false);
|
||||
// Sets the padding to the insets (include action bar and navigation bar
|
||||
// padding for the current device and orientation)
|
||||
setInsets(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callbacks interface that all activities using this fragment must
|
||||
* implement.
|
||||
*/
|
||||
public static interface NavigationDrawerCallbacks {
|
||||
/**
|
||||
* Called when an item in the navigation drawer is selected.
|
||||
*/
|
||||
void onNavigationDrawerItemSelected(int position);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadManager;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadThread;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import de.devland.esperandro.Esperandro;
|
||||
|
||||
/**
|
||||
* Module mappings for the classes under the Download Activity
|
||||
*/
|
||||
@Module(
|
||||
injects = {
|
||||
BookListFragment.class,
|
||||
BookItemHolder.class,
|
||||
BookDownloadManager.class,
|
||||
BookDownloadThread.class,
|
||||
RefreshManager.class
|
||||
}
|
||||
)
|
||||
public class ActivityDownloaderModule {
|
||||
|
||||
@Provides //@Singleton
|
||||
DownloadPrefs provideDownloadPrefs() {
|
||||
return Esperandro.getPreferences(DownloadPrefs.class, MinimalBible.getAppContext());
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.todddavies.components.progressbar.ProgressWheel;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadManager;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.DLProgressEvent;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
import rx.Subscription;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 5/20/14.
|
||||
*/
|
||||
public class BookItemHolder {
|
||||
|
||||
// TODO: The holder should register and unregister itself for DownloadProgress events
|
||||
// so that we can display live updates.
|
||||
|
||||
@InjectView(R.id.download_txt_item_acronym) TextView acronym;
|
||||
@InjectView(R.id.txt_download_item_name) TextView itemName;
|
||||
@InjectView(R.id.download_ibtn_download) ImageButton isDownloaded;
|
||||
@InjectView(R.id.download_prg_download) ProgressWheel downloadProgress;
|
||||
|
||||
@Inject BookDownloadManager bookDownloadManager;
|
||||
@Inject InstalledManager installedManager;
|
||||
|
||||
private final Book b;
|
||||
private Subscription subscription;
|
||||
|
||||
public BookItemHolder(View v, Book b) {
|
||||
ButterKnife.inject(this, v);
|
||||
MinimalBible.getApplication().inject(this);
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public void bindHolder() {
|
||||
acronym.setText(b.getInitials());
|
||||
itemName.setText(b.getName());
|
||||
DLProgressEvent dlProgressEvent = bookDownloadManager.getInProgressDownloadProgress(b);
|
||||
if (dlProgressEvent != null) {
|
||||
displayProgress((int) dlProgressEvent.toCircular());
|
||||
} else if (installedManager.isInstalled(b)) {
|
||||
displayInstalled();
|
||||
}
|
||||
//TODO: Refactor
|
||||
subscription = bookDownloadManager.getDownloadEvents()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.filter(new Func1<DLProgressEvent, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(DLProgressEvent event) {
|
||||
return event.getB().getInitials().equals(b.getInitials());
|
||||
}
|
||||
})
|
||||
.subscribe(new Action1<DLProgressEvent>() {
|
||||
@Override
|
||||
public void call(DLProgressEvent event) {
|
||||
BookItemHolder.this.displayProgress((int) event.toCircular());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displayInstalled() {
|
||||
isDownloaded.setImageResource(R.drawable.ic_action_cancel);
|
||||
}
|
||||
|
||||
@OnClick(R.id.download_ibtn_download)
|
||||
public void onDownloadItem(View v) {
|
||||
if (installedManager.isInstalled(b)) {
|
||||
// Remove the book
|
||||
installedManager.removeBook(b);
|
||||
isDownloaded.setImageResource(R.drawable.ic_action_download);
|
||||
} else {
|
||||
bookDownloadManager.installBook(this.b);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current progress of this download
|
||||
* @param progress The progress out of 360 (degrees of a circle)
|
||||
*/
|
||||
private void displayProgress(int progress) {
|
||||
|
||||
|
||||
if (progress == DLProgressEvent.PROGRESS_BEGINNING) {
|
||||
// Download starting
|
||||
RelativeLayout.LayoutParams acronymParams =
|
||||
(RelativeLayout.LayoutParams)acronym.getLayoutParams();
|
||||
acronymParams.addRule(RelativeLayout.LEFT_OF, downloadProgress.getId());
|
||||
|
||||
RelativeLayout.LayoutParams nameParams =
|
||||
(RelativeLayout.LayoutParams)itemName.getLayoutParams();
|
||||
nameParams.addRule(RelativeLayout.LEFT_OF, downloadProgress.getId());
|
||||
|
||||
isDownloaded.setVisibility(View.GONE);
|
||||
downloadProgress.setVisibility(View.VISIBLE);
|
||||
|
||||
downloadProgress.spin();
|
||||
} else if (progress < 360) {
|
||||
// Download in progress
|
||||
RelativeLayout.LayoutParams acronymParams =
|
||||
(RelativeLayout.LayoutParams)acronym.getLayoutParams();
|
||||
acronymParams.addRule(RelativeLayout.LEFT_OF, downloadProgress.getId());
|
||||
|
||||
RelativeLayout.LayoutParams nameParams =
|
||||
(RelativeLayout.LayoutParams)itemName.getLayoutParams();
|
||||
nameParams.addRule(RelativeLayout.LEFT_OF, downloadProgress.getId());
|
||||
|
||||
isDownloaded.setVisibility(View.GONE);
|
||||
downloadProgress.setVisibility(View.VISIBLE);
|
||||
|
||||
downloadProgress.stopSpinning();
|
||||
downloadProgress.setProgress(progress);
|
||||
} else {
|
||||
// Download complete
|
||||
subscription.unsubscribe();
|
||||
RelativeLayout.LayoutParams acronymParams =
|
||||
(RelativeLayout.LayoutParams)acronym.getLayoutParams();
|
||||
acronymParams.addRule(RelativeLayout.LEFT_OF, isDownloaded.getId());
|
||||
|
||||
RelativeLayout.LayoutParams nameParams =
|
||||
(RelativeLayout.LayoutParams)itemName.getLayoutParams();
|
||||
nameParams.addRule(RelativeLayout.LEFT_OF, isDownloaded.getId());
|
||||
|
||||
isDownloaded.setVisibility(View.VISIBLE);
|
||||
downloadProgress.setVisibility(View.GONE);
|
||||
displayInstalled();
|
||||
}
|
||||
}
|
||||
|
||||
public void onScrollOffscreen() {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Adapter to inflate list_download_items.xml
|
||||
*/
|
||||
public class BookListAdapter extends BaseAdapter implements AbsListView.RecyclerListener {
|
||||
private final List<Book> bookList;
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
|
||||
public BookListAdapter(LayoutInflater inflater, List<Book> bookList) {
|
||||
this.bookList = bookList;
|
||||
this.inflater = inflater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return bookList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Book getItem(int position) {
|
||||
return bookList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
BookItemHolder viewHolder;
|
||||
// Nasty Android issue - if you don't check the getTag(), Android will start recycling,
|
||||
// and you'll get some really strange issues
|
||||
if (convertView == null || convertView.getTag() == null) {
|
||||
convertView = inflater.inflate(R.layout.list_download_items, parent, false);
|
||||
viewHolder = new BookItemHolder(convertView, getItem(position));
|
||||
} else {
|
||||
viewHolder = (BookItemHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
viewHolder.bindHolder();
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMovedToScrapHeap(View view) {
|
||||
BookItemHolder holder = (BookItemHolder) view.getTag();
|
||||
holder.onScrollOffscreen();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,191 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.BaseFragment;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.BookCategory;
|
||||
import org.crosswire.jsword.book.BookComparators;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
import rx.functions.Func2;
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
|
||||
public class BookListFragment extends BaseFragment {
|
||||
/**
|
||||
* The fragment argument representing the section number for this fragment.
|
||||
* Not a candidate for Dart (yet) because I would have to write a Parcelable around it.
|
||||
*/
|
||||
protected static final String ARG_BOOK_CATEGORY = "book_category";
|
||||
|
||||
private final String TAG = "BookListFragment";
|
||||
|
||||
@InjectView(R.id.lst_download_available)
|
||||
ListView downloadsAvailable;
|
||||
|
||||
@Inject RefreshManager refreshManager;
|
||||
@Inject protected DownloadPrefs downloadPrefs;
|
||||
|
||||
protected ProgressDialog refreshDialog;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section number.
|
||||
* TODO: Switch to AutoFactory/@Provides rather than inline creation.
|
||||
*/
|
||||
public static BookListFragment newInstance(BookCategory c) {
|
||||
BookListFragment fragment = new BookListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_BOOK_CATEGORY, c.toString());
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
MinimalBible.getApplication().inject(this); // Injection for Dagger goes here, not ctor
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
this.inflater = inflater;
|
||||
View rootView = inflater.inflate(R.layout.fragment_download, container,
|
||||
false);
|
||||
ButterKnife.inject(this, rootView);
|
||||
displayModules();
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
((DownloadActivity) activity).onSectionAttached(getArguments()
|
||||
.getString(ARG_BOOK_CATEGORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the functionality to display a list of modules. Prompts user if downloading
|
||||
* from the internet is allowable.
|
||||
*/
|
||||
protected void displayModules() {
|
||||
boolean dialogDisplayed = downloadPrefs.hasShownDownloadDialog();
|
||||
|
||||
if (!dialogDisplayed) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
DownloadDialogListener dialogListener = new DownloadDialogListener();
|
||||
builder.setMessage(
|
||||
"About to contact servers to download content. Continue?")
|
||||
.setPositiveButton("Yes", dialogListener)
|
||||
.setNegativeButton("No", dialogListener)
|
||||
.setCancelable(false).show();
|
||||
} else {
|
||||
refreshModules();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the work of refreshing modules (download manager handles using cached copy vs. actual
|
||||
* refresh), and then displaying them when ready.
|
||||
*/
|
||||
private void refreshModules() {
|
||||
// Check if the downloadManager has already refreshed everything
|
||||
if (!refreshManager.isRefreshComplete()) {
|
||||
// downloadManager is in progress of refreshing
|
||||
refreshDialog = new ProgressDialog(getActivity());
|
||||
refreshDialog.setMessage("Refreshing available modules...");
|
||||
refreshDialog.setCancelable(false);
|
||||
refreshDialog.show();
|
||||
}
|
||||
|
||||
// Listen for the books!
|
||||
refreshManager.getAvailableModulesFlattened()
|
||||
.filter(new Func1<Book, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Book book) {
|
||||
return book.getBookCategory() ==
|
||||
BookCategory.fromString(BookListFragment.this.getArguments()
|
||||
.getString(ARG_BOOK_CATEGORY));
|
||||
}
|
||||
})
|
||||
// Repack all the books
|
||||
.toSortedList(new Func2<Book, Book, Integer>() {
|
||||
@Override
|
||||
public Integer call(Book book1, Book book2) {
|
||||
return BookComparators.getInitialComparator().compare(book1, book2);
|
||||
}
|
||||
})
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Action1<List<Book>>() {
|
||||
@Override
|
||||
public void call(List<Book> books) {
|
||||
downloadsAvailable.setAdapter(new BookListAdapter(inflater, books));
|
||||
if (BookListFragment.this.getActivity() != null) {
|
||||
// On a screen rotate, getActivity() will be null. But, the activity will
|
||||
// already have been set up correctly, so we don't need to worry about it.
|
||||
// If not null, we need to set it up now.
|
||||
setInsets(BookListFragment.this.getActivity(), downloadsAvailable);
|
||||
}
|
||||
if (refreshDialog != null) {
|
||||
refreshDialog.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class DownloadDialogListener implements
|
||||
DialogInterface.OnClickListener {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
downloadPrefs.hasShownDownloadDialog(true);
|
||||
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
// Clicked ready to continue - allow downloading in the future
|
||||
downloadPrefs.hasEnabledDownload(true);
|
||||
|
||||
// And warn them that it has been enabled in the future.
|
||||
Toast.makeText(getActivity(),
|
||||
"Downloading now enabled. Disable in settings.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
refreshModules();
|
||||
break;
|
||||
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
// Clicked to not download - Permanently disable downloading
|
||||
downloadPrefs.hasEnabledDownload(false);
|
||||
Toast.makeText(getActivity(),
|
||||
"Disabling downloading. Re-enable it in settings.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
refreshModules();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.BaseActivity;
|
||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
||||
|
||||
public class DownloadActivity extends BaseActivity implements
|
||||
BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
|
||||
/**
|
||||
* Fragment managing the behaviors, interactions and presentation of the
|
||||
* navigation drawer.
|
||||
*/
|
||||
private DownloadNavDrawerFragment mNavigationDrawerFragment;
|
||||
|
||||
/**
|
||||
* Used to store the last screen title. For use in
|
||||
* {@link #restoreActionBar()}.
|
||||
*/
|
||||
private CharSequence mTitle;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_download);
|
||||
|
||||
mNavigationDrawerFragment = (DownloadNavDrawerFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.navigation_drawer);
|
||||
mTitle = getTitle();
|
||||
|
||||
// Set up the drawer.
|
||||
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
|
||||
(DrawerLayout) findViewById(R.id.drawer_layout));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNavigationDrawerItemSelected(int position) {
|
||||
// update the main content by replacing fragments
|
||||
//TODO: Switch to AutoFactory pattern, rather than newInstance()
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager
|
||||
.beginTransaction()
|
||||
.replace(R.id.container,
|
||||
BookListFragment.newInstance(DownloadManager.VALID_CATEGORIES[position])).commit();
|
||||
}
|
||||
|
||||
public void onSectionAttached(String category) {
|
||||
mTitle = category;
|
||||
}
|
||||
|
||||
public void restoreActionBar() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setTitle(mTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
if (!mNavigationDrawerFragment.isDrawerOpen()) {
|
||||
// Only show items in the action bar relevant to this screen
|
||||
// if the drawer is not showing. Otherwise, let the drawer
|
||||
// decide what to show in the action bar.
|
||||
getMenuInflater().inflate(R.menu.download, menu);
|
||||
restoreActionBar();
|
||||
return true;
|
||||
}
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class DownloadNavDrawerFragment extends BaseNavigationDrawerFragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
mDrawerListView = (ListView) inflater.inflate(
|
||||
R.layout.fragment_navigation_drawer, container, false);
|
||||
mDrawerListView
|
||||
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
selectItem(position);
|
||||
}
|
||||
});
|
||||
|
||||
String[] sCategories = new String[DownloadManager.VALID_CATEGORIES.length];
|
||||
for (int i = 0; i < DownloadManager.VALID_CATEGORIES.length; i++) {
|
||||
sCategories[i] = DownloadManager.VALID_CATEGORIES[i].toString();
|
||||
}
|
||||
|
||||
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
|
||||
.getThemedContext(), android.R.layout.simple_list_item_1,
|
||||
android.R.id.text1, sCategories));
|
||||
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
|
||||
return mDrawerListView;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import de.devland.esperandro.annotations.SharedPreferences;
|
||||
|
||||
/**
|
||||
* SharedPreferences interface to be built by Esperandro
|
||||
*/
|
||||
@SharedPreferences(name="DownloadPrefs")
|
||||
public interface DownloadPrefs {
|
||||
|
||||
boolean hasEnabledDownload();
|
||||
void hasEnabledDownload(boolean hasEnabledDownload);
|
||||
|
||||
boolean hasShownDownloadDialog();
|
||||
void hasShownDownloadDialog(boolean hasShownDownloadDialog);
|
||||
|
||||
long downloadRefreshedOn();
|
||||
void downloadRefreshedOn(long downloadRefreshedOn);
|
||||
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.crosswire.common.progress.JobManager;
|
||||
import org.crosswire.common.progress.Progress;
|
||||
import org.crosswire.common.progress.WorkEvent;
|
||||
import org.crosswire.common.progress.WorkListener;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.Books;
|
||||
import org.crosswire.jsword.book.BooksEvent;
|
||||
import org.crosswire.jsword.book.BooksListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
/**
|
||||
* Wrapper to convert JSword progress events to MinimalBible EventBus-based
|
||||
*/
|
||||
//TODO: Make sure that jobs have the correct name
|
||||
//TODO: Install indexes for Bibles
|
||||
@Singleton
|
||||
public class BookDownloadManager implements WorkListener, BooksListener {
|
||||
|
||||
/**
|
||||
* Mapping of Job ID to the EventBus we should trigger progress on
|
||||
*/
|
||||
private final Map<String, Book> bookMappings;
|
||||
|
||||
/**
|
||||
* Cached copy of downloads in progress so views displaying this info can get it quickly.
|
||||
*/
|
||||
private final Map<Book, DLProgressEvent> inProgressDownloads;
|
||||
|
||||
private final PublishSubject<DLProgressEvent> downloadEvents = PublishSubject.create();
|
||||
|
||||
@Inject
|
||||
Provider<BookDownloadThread> dlThreadProvider;
|
||||
|
||||
public BookDownloadManager() {
|
||||
bookMappings = new HashMap<String, Book>();
|
||||
inProgressDownloads = new HashMap<Book, DLProgressEvent>();
|
||||
JobManager.addWorkListener(this);
|
||||
MinimalBible.getApplication().inject(this);
|
||||
Books.installed().addBooksListener(this);
|
||||
}
|
||||
|
||||
public void installBook(Book b) {
|
||||
BookDownloadThread dlThread = dlThreadProvider.get();
|
||||
dlThread.downloadBook(b);
|
||||
addJob(BookDownloadThread.getJobId(b), b);
|
||||
downloadEvents.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b));
|
||||
}
|
||||
|
||||
public void addJob(String jobId, Book b) {
|
||||
bookMappings.put(jobId, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void workProgressed(WorkEvent ev) {
|
||||
Progress job = ev.getJob();
|
||||
Log.d("BookDownloadManager", "Download in progress: " + job.getJobID() + " - " + job.getJobName() + " " + job.getWorkDone() + "/" + job.getTotalWork());
|
||||
if (bookMappings.containsKey(job.getJobID())) {
|
||||
Book b = bookMappings.get(job.getJobID());
|
||||
|
||||
if (job.getWorkDone() == job.getTotalWork()) {
|
||||
// Download is complete
|
||||
inProgressDownloads.remove(bookMappings.get(job.getJobID()));
|
||||
bookMappings.remove(job.getJobID());
|
||||
downloadEvents.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_COMPLETE, b));
|
||||
} else {
|
||||
// Track the ongoing download
|
||||
DLProgressEvent event = new DLProgressEvent(job.getWorkDone(),
|
||||
job.getTotalWork(), b);
|
||||
inProgressDownloads.put(b, event);
|
||||
downloadEvents.onNext(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the status of a book download in progress.
|
||||
* @param b The book to get the current progress of
|
||||
* @return The most recent DownloadProgressEvent for the book, or null if not downloading
|
||||
*/
|
||||
public DLProgressEvent getInProgressDownloadProgress(Book b) {
|
||||
if (inProgressDownloads.containsKey(b)) {
|
||||
return inProgressDownloads.get(b);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public PublishSubject<DLProgressEvent> getDownloadEvents() {
|
||||
return downloadEvents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void workStateChanged(WorkEvent ev) {
|
||||
Log.d("BookDownloadManager", ev.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bookAdded(BooksEvent booksEvent) {
|
||||
// It's possible the install finished before we received a progress event for it,
|
||||
// we handle that case here.
|
||||
Book b = booksEvent.getBook();
|
||||
Log.d("BookDownloadManager", "Book added: " + b.getName());
|
||||
if (inProgressDownloads.containsKey(b)) {
|
||||
inProgressDownloads.remove(b);
|
||||
}
|
||||
// Not sure why, but the inProgressDownloads might not have our book,
|
||||
// so we always trigger the PROGRESS_COMPLETE event.
|
||||
// TODO: Make sure all books get to the inProgressDownloads
|
||||
downloadEvents.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_COMPLETE, b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bookRemoved(BooksEvent booksEvent) {
|
||||
// Not too worried about this just yet.
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.install.InstallException;
|
||||
import org.crosswire.jsword.book.install.Installer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Thread that handles downloading a book
|
||||
*/
|
||||
//TODO: Refactor to BookDownloadManager, downloadBook() creates its own thread
|
||||
public class BookDownloadThread {
|
||||
|
||||
private final String TAG = "BookDownloadThread";
|
||||
|
||||
@Inject
|
||||
BookDownloadManager bookDownloadManager;
|
||||
@Inject
|
||||
RefreshManager refreshManager;
|
||||
|
||||
public BookDownloadThread() {
|
||||
MinimalBible.getApplication().inject(this);
|
||||
}
|
||||
|
||||
public void downloadBook(final Book b) {
|
||||
// So, the JobManager can't be injected, but we'll make do
|
||||
|
||||
// First, look up where the Book came from
|
||||
refreshManager.installerFromBook(b)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(new Action1<Installer>() {
|
||||
@Override
|
||||
public void call(Installer installer) {
|
||||
try {
|
||||
installer.install(b);
|
||||
} catch (InstallException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
}
|
||||
|
||||
bookDownloadManager.getDownloadEvents()
|
||||
.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Build what the installer creates the job name as.
|
||||
* Likely prone to be brittle.
|
||||
* TODO: Make sure to test that this is an accurate job name
|
||||
*
|
||||
* @param b The book to predict the download job name of
|
||||
* @return The name of the job that will/is download/ing this book
|
||||
*/
|
||||
|
||||
public static String getJobId(Book b) {
|
||||
return "INSTALL_BOOK-" + b.getInitials();
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
/**
|
||||
* Used for notifying that a book's download progress is ongoing
|
||||
*/
|
||||
public class DLProgressEvent {
|
||||
private final int progress;
|
||||
private final Book b;
|
||||
|
||||
public static final int PROGRESS_COMPLETE = 100;
|
||||
public static final int PROGRESS_BEGINNING = 0;
|
||||
|
||||
public DLProgressEvent(int workDone, int totalWork, Book b) {
|
||||
if (totalWork == 0) {
|
||||
this.progress = 0;
|
||||
} else {
|
||||
this.progress = (int)((float) workDone / totalWork * 100);
|
||||
}
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public DLProgressEvent(int workDone, Book b) {
|
||||
this.progress = workDone;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public float toCircular() {
|
||||
return ((float)progress) * 360 / 100;
|
||||
}
|
||||
|
||||
public Book getB() {
|
||||
return this.b;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.crosswire.jsword.book.BookCategory;
|
||||
import org.crosswire.jsword.book.install.InstallManager;
|
||||
import org.crosswire.jsword.book.install.Installer;
|
||||
import org.crosswire.jsword.book.sword.SwordBookPath;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
// TODO: Listen to BookInstall events?
|
||||
@Singleton
|
||||
public class DownloadManager {
|
||||
|
||||
private final String TAG = "DownloadManager";
|
||||
|
||||
public static final BookCategory[] VALID_CATEGORIES = { BookCategory.BIBLE,
|
||||
BookCategory.COMMENTARY, BookCategory.DICTIONARY,
|
||||
BookCategory.MAPS };
|
||||
|
||||
/**
|
||||
* Set up the DownloadManager, and notify jSword of where it should store files at
|
||||
*/
|
||||
@Inject
|
||||
public DownloadManager() {
|
||||
setDownloadDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the installers available to jSword - this is how we get access to the actual modules
|
||||
* @return All available {@link org.crosswire.jsword.book.install.Installer}s
|
||||
*/
|
||||
public Map<String, Installer> getInstallers() {
|
||||
return new InstallManager().getInstallers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify jSword that it needs to store files in the Android internal directory
|
||||
* NOTE: Android will uninstall these files if you uninstall MinimalBible.
|
||||
*/
|
||||
@SuppressWarnings("null")
|
||||
private void setDownloadDir() {
|
||||
// We need to set the download directory for jSword to stick with
|
||||
// Android.
|
||||
String home = MinimalBible.getAppContext().getFilesDir().toString();
|
||||
Log.d(TAG, "Setting jsword.home to: " + home);
|
||||
System.setProperty("jsword.home", home);
|
||||
System.setProperty("sword.home", home);
|
||||
SwordBookPath.setDownloadDir(new File(home));
|
||||
Log.d(TAG, "Sword download path: " + SwordBookPath.getSwordDownloadDir());
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.BookException;
|
||||
import org.crosswire.jsword.book.Books;
|
||||
import org.crosswire.jsword.book.BooksEvent;
|
||||
import org.crosswire.jsword.book.BooksListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Manager to keep track of which books have been installed
|
||||
*/
|
||||
@Singleton
|
||||
public class InstalledManager implements BooksListener {
|
||||
|
||||
private Books installedBooks;
|
||||
private List<Book> installedBooksList;
|
||||
private String TAG = "InstalledManager";
|
||||
|
||||
@Inject InstalledManager() {}
|
||||
|
||||
/**
|
||||
* Register our manager to receive events on Book install
|
||||
* This is a relatively expensive operation,
|
||||
* so we don't put it in the constructor.
|
||||
*/
|
||||
public void initialize() {
|
||||
//TODO: Move this to a true async, rather than separate initialize() function
|
||||
installedBooks = Books.installed();
|
||||
installedBooksList = installedBooks.getBooks();
|
||||
installedBooks.addBooksListener(this);
|
||||
}
|
||||
|
||||
public boolean isInstalled(Book b) {
|
||||
if (installedBooks == null) {
|
||||
initialize();
|
||||
}
|
||||
return installedBooksList.contains(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bookAdded(BooksEvent booksEvent) {
|
||||
Log.d(TAG, "Book added: " + booksEvent.getBook().toString());
|
||||
Book b = booksEvent.getBook();
|
||||
if (!installedBooksList.contains(b)) {
|
||||
installedBooksList.add(b);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bookRemoved(BooksEvent booksEvent) {
|
||||
Log.d(TAG, "Book removed: " + booksEvent.getBook().toString());
|
||||
Book b = booksEvent.getBook();
|
||||
if (installedBooksList.contains(b)) {
|
||||
installedBooksList.remove(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeBook(Book b) {
|
||||
if (installedBooks == null) {
|
||||
initialize();
|
||||
}
|
||||
// Not sure why we need to call this multiple times, but...
|
||||
while (Books.installed().getBooks().contains(b)) {
|
||||
try {
|
||||
// This worked in the past, but isn't now...
|
||||
// installedBooks.remove(b);
|
||||
Book realBook = installedBooks.getBook(b.getInitials());
|
||||
b.getDriver().delete(realBook);
|
||||
} catch (BookException e) {
|
||||
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.install.Installer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.functions.Action0;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
import rx.functions.Func2;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Handle refreshing the list of books available as needed
|
||||
*/
|
||||
@Singleton
|
||||
public class RefreshManager {
|
||||
|
||||
@Inject DownloadManager downloadManager;
|
||||
@Inject InstalledManager installedManager;
|
||||
|
||||
/**
|
||||
* Cached copy of modules that are available so we don't refresh for everyone who requests it.
|
||||
*/
|
||||
private Observable<Map<Installer, List<Book>>> availableModules;
|
||||
private final AtomicBoolean refreshComplete = new AtomicBoolean();
|
||||
|
||||
public RefreshManager() {
|
||||
MinimalBible.getApplication().inject(this);
|
||||
refreshModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the work of kicking off the AsyncTask to refresh books, and make sure we know
|
||||
* when it's done.
|
||||
* TODO: Should I have a better way of scheduling than Schedulers.io()?
|
||||
*/
|
||||
private void refreshModules() {
|
||||
if (availableModules == null) {
|
||||
availableModules = Observable.from(downloadManager.getInstallers().values())
|
||||
.map(new Func1<Installer, Map<Installer, List<Book>>>() {
|
||||
@Override
|
||||
public Map<Installer, List<Book>> call(Installer installer) {
|
||||
Map<Installer, List<Book>> map = new HashMap<Installer, List<Book>>();
|
||||
map.put(installer, installer.getBooks());
|
||||
return map;
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.cache();
|
||||
|
||||
// Set refresh complete when it is.
|
||||
availableModules.observeOn(Schedulers.io())
|
||||
.subscribe(new Action1<Map<Installer, List<Book>>>() {
|
||||
@Override
|
||||
public void call(Map<Installer, List<Book>> onNext) {}
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable onError) {}
|
||||
}, new Action0() {
|
||||
@Override
|
||||
public void call() {
|
||||
refreshComplete.set(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public Observable<Map<Installer, List<Book>>> getAvailableModules() {
|
||||
return availableModules;
|
||||
}
|
||||
|
||||
public Observable<Book> getAvailableModulesFlattened() {
|
||||
return availableModules
|
||||
// First flatten the Map to its lists
|
||||
.flatMap(new Func1<Map<Installer, List<Book>>, Observable<? extends List<Book>>>() {
|
||||
@Override
|
||||
public Observable<? extends List<Book>> call(Map<Installer, List<Book>> books) {
|
||||
return Observable.from(books.values());
|
||||
}
|
||||
})
|
||||
// Then flatten the lists
|
||||
.flatMap(new Func1<List<Book>, Observable<? extends Book>>() {
|
||||
@Override
|
||||
public Observable<? extends Book> call(List<Book> t1) {
|
||||
return Observable.from(t1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cached book list
|
||||
* @return The cached book list, or null
|
||||
*/
|
||||
public List<Book> getBookList() {
|
||||
List<Book> availableList = new ArrayList<Book>();
|
||||
availableModules.reduce(availableList,
|
||||
new Func2<List<Book>, Map<Installer, List<Book>>, List<Book>>() {
|
||||
@Override
|
||||
public List<Book> call(List<Book> books, Map<Installer, List<Book>> installerListMap) {
|
||||
for (List<Book> l : installerListMap.values()) {
|
||||
books.addAll(l);
|
||||
}
|
||||
return books;
|
||||
}
|
||||
});
|
||||
return availableList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the installer that a Book comes from.
|
||||
* @param b The book to search for
|
||||
* @return The Installer that should be used for this book.
|
||||
*/
|
||||
public Observable<Installer> installerFromBook(final Book b) {
|
||||
return availableModules.filter(new Func1<Map<Installer, List<Book>>, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Map<Installer, List<Book>> installerListMap) {
|
||||
for (List<Book> element : installerListMap.values()) {
|
||||
if (element.contains(b)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.first()
|
||||
.map(new Func1<Map<Installer, List<Book>>, Installer>() {
|
||||
@Override
|
||||
public Installer call(Map<Installer, List<Book>> element) {
|
||||
return element.entrySet().iterator().next().getKey();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isRefreshComplete() {
|
||||
return refreshComplete.get();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package org.bspeice.minimalbible.activities.viewer;
|
||||
|
||||
import dagger.Module;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 6/18/14.
|
||||
*/
|
||||
@Module(
|
||||
injects = {
|
||||
BibleViewer.class,
|
||||
BookFragment.class
|
||||
}
|
||||
)
|
||||
public class ActivityViewerModule {
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
package org.bspeice.minimalbible.activities.viewer;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.BaseActivity;
|
||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
||||
import org.bspeice.minimalbible.activities.downloader.DownloadActivity;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
|
||||
public class BibleViewer extends BaseActivity implements
|
||||
BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
|
||||
@Inject BookManager bookManager;
|
||||
|
||||
/**
|
||||
* Fragment managing the behaviors, interactions and presentation of the
|
||||
* navigation drawer.
|
||||
*/
|
||||
private ViewerNavDrawerFragment mNavigationDrawerFragment;
|
||||
|
||||
/**
|
||||
* Used to store the last screen title. For use in
|
||||
* {@link #restoreActionBar()}.
|
||||
*/
|
||||
private CharSequence mTitle;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
MinimalBible.getApplication().inject(this);
|
||||
|
||||
// If no books are installed, we need to download one first.
|
||||
int count = bookManager.getInstalledBooks()
|
||||
.count()
|
||||
.toBlocking()
|
||||
.last();
|
||||
if (count <= 0) {
|
||||
Intent i = new Intent(this, DownloadActivity.class);
|
||||
startActivityForResult(i, 0);
|
||||
finish();
|
||||
} else {
|
||||
bookManager.getInstalledBooks()
|
||||
.first()
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Action1<Book>() {
|
||||
@Override
|
||||
public void call(Book book) {
|
||||
Log.d("BibleViewer", "Subscribed to display book: " + book.getName());
|
||||
displayMainBook(book);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_bible_viewer);
|
||||
|
||||
mNavigationDrawerFragment = (ViewerNavDrawerFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.navigation_drawer);
|
||||
mTitle = getTitle();
|
||||
|
||||
// Set up the drawer.
|
||||
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
|
||||
(DrawerLayout) findViewById(R.id.drawer_layout));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNavigationDrawerItemSelected(int position) {
|
||||
// Handle a navigation movement
|
||||
}
|
||||
|
||||
public void setActionBarTitle(String title) {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
mTitle = title;
|
||||
actionBar.setTitle(title);
|
||||
}
|
||||
|
||||
public void restoreActionBar() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setTitle(mTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
if (!mNavigationDrawerFragment.isDrawerOpen()) {
|
||||
// Only show items in the action bar relevant to this screen
|
||||
// if the drawer is not showing. Otherwise, let the drawer
|
||||
// decide what to show in the action bar.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
restoreActionBar();
|
||||
return true;
|
||||
}
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
} else if (id == R.id.action_downloads) {
|
||||
startActivity(new Intent(this, DownloadActivity.class));
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void displayMainBook(Book b) {
|
||||
Log.d("BibleViewer", "Initializing main book: " + b.getName());
|
||||
Log.d("MainThread?", Boolean.toString(Looper.myLooper() == Looper.getMainLooper()));
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
Fragment f = BookFragment.newInstance(b.getName());
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.container, f)
|
||||
.commit();
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
package org.bspeice.minimalbible.activities.viewer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.BaseFragment;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public class BookFragment extends BaseFragment {
|
||||
|
||||
@Inject BookManager bookManager;
|
||||
|
||||
@InjectView(R.id.book_content)
|
||||
WebView mainContent;
|
||||
|
||||
private static final String ARG_BOOK_NAME = "book_name";
|
||||
|
||||
private Book mBook;
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section number.
|
||||
*/
|
||||
public static BookFragment newInstance(String bookName) {
|
||||
BookFragment fragment = new BookFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_BOOK_NAME, bookName);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public BookFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
MinimalBible.getApplication().inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_viewer_main, container,
|
||||
false);
|
||||
ButterKnife.inject(this, rootView);
|
||||
mainContent.getSettings().setJavaScriptEnabled(true);
|
||||
|
||||
// TODO: Load initial text from SharedPreferences
|
||||
|
||||
// And due to Observable async, we can kick off fetching the actual book asynchronously!
|
||||
bookManager.getInstalledBooks()
|
||||
.first(new Func1<Book, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Book book) {
|
||||
String mBookName = getArguments().getString(ARG_BOOK_NAME);
|
||||
return book.getName().equals(mBookName);
|
||||
}
|
||||
})
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Action1<Book>() {
|
||||
@Override
|
||||
public void call(Book book) {
|
||||
BookFragment.this.mBook = book;
|
||||
displayBook(book);
|
||||
}
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
Log.d("BookFragment", "No books installed?");
|
||||
}
|
||||
});
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
// TODO: Remove?
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
private void displayBook(Book b) {
|
||||
Log.d("BookFragment", b.getName());
|
||||
((BibleViewer)getActivity()).setActionBarTitle(b.getInitials());
|
||||
mainContent.loadUrl(getString(R.string.content_page));
|
||||
mainContent.setWebViewClient(new WebViewClient(){
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
invokeJavascript("set_content", BookFragment.this.mBook.getName());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void invokeJavascript(String function, Object arg) {
|
||||
mainContent.loadUrl("javascript:" + function + "('" + arg.toString() + "')");
|
||||
}
|
||||
|
||||
private void invokeJavascript(String function, List<Object> args) {
|
||||
mainContent.loadUrl("javascript:" + function + "(" + joinString(",", args.toArray()) + ")");
|
||||
}
|
||||
|
||||
// Convenience from http://stackoverflow.com/a/17795110/1454178
|
||||
public static String joinString(String join, Object... strings) {
|
||||
if (strings == null || strings.length == 0) {
|
||||
return "";
|
||||
} else if (strings.length == 1) {
|
||||
return strings[0].toString();
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(strings[0]);
|
||||
for (int i = 1; i < strings.length; i++) {
|
||||
sb.append(join).append(strings[i].toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.bspeice.minimalbible.activities.viewer;
|
||||
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.Books;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.functions.Action0;
|
||||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 6/18/14.
|
||||
*/
|
||||
@Singleton
|
||||
public class BookManager {
|
||||
|
||||
private Observable<Book> installedBooks;
|
||||
private Boolean refreshComplete;
|
||||
|
||||
@Inject
|
||||
BookManager() {
|
||||
installedBooks = Observable.from(Books.installed().getBooks())
|
||||
.cache();
|
||||
installedBooks.subscribeOn(Schedulers.io())
|
||||
.subscribe(new Action1<Book>() {
|
||||
@Override
|
||||
public void call(Book book) {}
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {}
|
||||
}, new Action0() {
|
||||
@Override
|
||||
public void call() {
|
||||
BookManager.this.refreshComplete = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Observable<Book> getInstalledBooks() {
|
||||
return installedBooks;
|
||||
}
|
||||
|
||||
public Boolean isRefreshComplete() {
|
||||
return refreshComplete;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package org.bspeice.minimalbible.activities.viewer;
|
||||
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class ViewerNavDrawerFragment extends BaseNavigationDrawerFragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
mDrawerListView = (ListView) inflater.inflate(
|
||||
R.layout.fragment_navigation_drawer, container, false);
|
||||
mDrawerListView
|
||||
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
selectItem(position);
|
||||
}
|
||||
});
|
||||
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
|
||||
.getThemedContext(), android.R.layout.simple_list_item_1,
|
||||
android.R.id.text1, new String[] {
|
||||
getString(R.string.title_section1),
|
||||
getString(R.string.title_section2),
|
||||
getString(R.string.title_section3)}));
|
||||
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
|
||||
return mDrawerListView;
|
||||
}
|
||||
}
|
BIN
MinimalBible/src/main/res/drawable-hdpi/drawer_shadow.9.png
Normal file
After Width: | Height: | Size: 161 B |
BIN
MinimalBible/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
After Width: | Height: | Size: 438 B |
BIN
MinimalBible/src/main/res/drawable-hdpi/ic_action_download.png
Normal file
After Width: | Height: | Size: 398 B |
BIN
MinimalBible/src/main/res/drawable-hdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 702 B |
BIN
MinimalBible/src/main/res/drawable-hdpi/ic_drawer.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
MinimalBible/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
MinimalBible/src/main/res/drawable-mdpi/drawer_shadow.9.png
Normal file
After Width: | Height: | Size: 142 B |
BIN
MinimalBible/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
After Width: | Height: | Size: 328 B |
BIN
MinimalBible/src/main/res/drawable-mdpi/ic_action_download.png
Normal file
After Width: | Height: | Size: 324 B |
BIN
MinimalBible/src/main/res/drawable-mdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 479 B |
BIN
MinimalBible/src/main/res/drawable-mdpi/ic_drawer.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
MinimalBible/src/main/res/drawable-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
MinimalBible/src/main/res/drawable-xhdpi/drawer_shadow.9.png
Normal file
After Width: | Height: | Size: 174 B |
BIN
MinimalBible/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
After Width: | Height: | Size: 513 B |
BIN
MinimalBible/src/main/res/drawable-xhdpi/ic_action_download.png
Normal file
After Width: | Height: | Size: 552 B |
BIN
MinimalBible/src/main/res/drawable-xhdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 900 B |
BIN
MinimalBible/src/main/res/drawable-xhdpi/ic_drawer.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
MinimalBible/src/main/res/drawable-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
MinimalBible/src/main/res/drawable-xxhdpi/drawer_shadow.9.png
Normal file
After Width: | Height: | Size: 208 B |
BIN
MinimalBible/src/main/res/drawable-xxhdpi/ic_action_cancel.png
Normal file
After Width: | Height: | Size: 567 B |
BIN
MinimalBible/src/main/res/drawable-xxhdpi/ic_action_download.png
Normal file
After Width: | Height: | Size: 650 B |
BIN
MinimalBible/src/main/res/drawable-xxhdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
MinimalBible/src/main/res/drawable-xxhdpi/ic_drawer.png
Normal file
After Width: | Height: | Size: 202 B |
BIN
MinimalBible/src/main/res/drawable-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 5.4 KiB |
42
MinimalBible/src/main/res/layout/activity_bible_viewer.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.bspeice.minimalbible.activities.viewer.BibleViewer" >
|
||||
|
||||
<!--
|
||||
As the main content view, the view below consumes the entire
|
||||
space available using match_parent in both dimensions.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:clipToPadding="false" />
|
||||
|
||||
<!--
|
||||
android:layout_gravity="start" tells DrawerLayout to treat
|
||||
this as a sliding drawer on the left side for left-to-right
|
||||
languages and on the right side for right-to-left languages.
|
||||
If you're not building against API 17 or higher, use
|
||||
android:layout_gravity="left" instead.
|
||||
-->
|
||||
<!--
|
||||
The drawer is given a fixed width in dp and extends the full height of
|
||||
the container.
|
||||
-->
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_drawer"
|
||||
android:name="org.bspeice.minimalbible.activities.viewer.ViewerNavDrawerFragment"
|
||||
android:layout_width="@dimen/navigation_drawer_width"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:clipToPadding="false"
|
||||
android:layout_gravity="start" />
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
38
MinimalBible/src/main/res/layout/activity_download.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.bspeice.minimalbible.activities.downloader.DownloadActivity" >
|
||||
|
||||
<!--
|
||||
As the main content view, the view below consumes the entire
|
||||
space available using match_parent in both dimensions.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<!--
|
||||
android:layout_gravity="start" tells DrawerLayout to treat
|
||||
this as a sliding drawer on the left side for left-to-right
|
||||
languages and on the right side for right-to-left languages.
|
||||
If you're not building against API 17 or higher, use
|
||||
android:layout_gravity="left" instead.
|
||||
-->
|
||||
<!--
|
||||
The drawer is given a fixed width in dp and extends the full height of
|
||||
the container.
|
||||
-->
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_drawer"
|
||||
android:name="org.bspeice.minimalbible.activities.downloader.DownloadNavDrawerFragment"
|
||||
android:layout_width="@dimen/navigation_drawer_width"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start" />
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
15
MinimalBible/src/main/res/layout/fragment_download.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.bspeice.minimalbible.DownloadActivity$PlaceholderFragment" >
|
||||
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/lst_download_available"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:clipToPadding="false" />
|
||||
</RelativeLayout>
|
@ -0,0 +1,11 @@
|
||||
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/list_nav_drawer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#cccccc"
|
||||
android:choiceMode="singleChoice"
|
||||
android:divider="@android:color/transparent"
|
||||
android:dividerHeight="0dp"
|
||||
tools:context="org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment" />
|
||||
|
12
MinimalBible/src/main/res/layout/fragment_viewer_main.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.bspeice.minimalbible.MainActivity$PlaceholderFragment" >
|
||||
|
||||
<WebView
|
||||
android:id="@+id/book_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
</RelativeLayout>
|
45
MinimalBible/src/main/res/layout/list_download_items.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/txt_download_item_name"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_toLeftOf="@+id/download_ibtn_download"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/download_txt_item_acronym"
|
||||
android:paddingTop="4dp"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/txt_download_item_name"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_action_download"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:id="@+id/download_ibtn_download"
|
||||
style="@style/AppBaseTheme.Borderless" />
|
||||
|
||||
<com.todddavies.components.progressbar.ProgressWheel
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/download_prg_download"
|
||||
app:rimWidth="0dp"
|
||||
app:barWidth="4dp" />
|
||||
|
||||
</RelativeLayout>
|
16
MinimalBible/src/main/res/menu/download.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="org.bspeice.minimalbible.DownloadActivity" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_example"
|
||||
android:title="@string/action_example"
|
||||
app:showAsAction="withText|ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
9
MinimalBible/src/main/res/menu/downloader.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/action_settings"/>
|
||||
|
||||
</menu>
|
10
MinimalBible/src/main/res/menu/global.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
17
MinimalBible/src/main/res/menu/main.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="org.bspeice.minimalbible.MainActivity" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_downloads"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/title_activity_downloader" />
|
||||
|
||||
</menu>
|
8
MinimalBible/src/main/res/values-sw600dp/dimens.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Customize dimensions originally defined in res/values/dimens.xml (such as
|
||||
screen margins) for sw600dp devices (e.g. 7" tablets) here.
|
||||
-->
|
||||
|
||||
</resources>
|
9
MinimalBible/src/main/res/values-sw720dp-land/dimens.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Customize dimensions originally defined in res/values/dimens.xml (such as
|
||||
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
|
||||
-->
|
||||
<dimen name="activity_horizontal_margin">128dp</dimen>
|
||||
|
||||
</resources>
|
17
MinimalBible/src/main/res/values-v11/styles.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 11+. This theme completely replaces
|
||||
AppBaseTheme from res/values/styles.xml on API 11+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
|
||||
|
||||
<!-- API 11 theme customizations can go here. -->
|
||||
<item name="android:actionBarStyle">@style/ActionBar</item>
|
||||
</style>
|
||||
|
||||
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
|
||||
<item name="android:background">@color/actionbar</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
18
MinimalBible/src/main/res/values-v14/styles.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 14+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 14+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
|
||||
<!-- API 14 theme customizations can go here. -->
|
||||
<item name="android:actionBarStyle">@style/ActionBar</item>
|
||||
</style>
|
||||
|
||||
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
|
||||
<item name="android:background">@color/actionbar</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
20
MinimalBible/src/main/res/values-v19/styles.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 19+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 19+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
|
||||
|
||||
<!-- API 19 theme customizations can go here. -->
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
<item name="android:windowTranslucentNavigation">true</item>
|
||||
<item name="android:actionBarStyle">@style/ActionBar</item>
|
||||
</style>
|
||||
|
||||
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
|
||||
<item name="android:background">@color/actionbar</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
10
MinimalBible/src/main/res/values-w820dp/dimens.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
|
||||
-->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
|
||||
</resources>
|
19
MinimalBible/src/main/res/values/attrs.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="ProgressWheel">
|
||||
<attr name="text" format="string" />
|
||||
<attr name="textColor" format="color" />
|
||||
<attr name="textSize" format="dimension" />
|
||||
<attr name="barColor" format="color" />
|
||||
<attr name="rimColor" format="color" />
|
||||
<attr name="rimWidth" format="dimension" />
|
||||
<attr name="spinSpeed" format="dimension" />
|
||||
<attr name="delayMillis" format="integer" />
|
||||
<attr name="circleColor" format="color" />
|
||||
<attr name="radius" format="dimension" />
|
||||
<attr name="barWidth" format="dimension" />
|
||||
<attr name="barLength" format="dimension" />
|
||||
<attr name="contourColor" format="color"/>
|
||||
<attr name="contourSize" format="dimension"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
5
MinimalBible/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="statusbar">#dddddd</color>
|
||||
<color name="actionbar">#dddddd</color>
|
||||
</resources>
|
13
MinimalBible/src/main/res/values/dimens.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<resources>
|
||||
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
|
||||
<!--
|
||||
Per the design guidelines, navigation drawers should be between 240dp and 320dp:
|
||||
https://developer.android.com/design/patterns/navigation-drawer.html
|
||||
-->
|
||||
<dimen name="navigation_drawer_width">240dp</dimen>
|
||||
|
||||
</resources>
|
4
MinimalBible/src/main/res/values/html_strings.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="content_page">file:///android_asset/book.html</string>
|
||||
</resources>
|
15
MinimalBible/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Minimal Bible</string>
|
||||
<string name="title_section1">Section 1</string>
|
||||
<string name="title_section2">Section 2</string>
|
||||
<string name="title_section3">Section 3</string>
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
<string name="action_example">Example action</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="title_activity_downloader">Downloads</string>
|
||||
<string name="title_activity_download">DownloadActivity</string>
|
||||
|
||||
</resources>
|
33
MinimalBible/src/main/res/values/styles.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
backward-compatibility can go here.
|
||||
-->
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<!-- Application theme. -->
|
||||
<style name="AppTheme" parent="AppBaseTheme">
|
||||
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||
</style>
|
||||
|
||||
<!-- Almost re-use style from Widget.Holo.Button.Borderless -->
|
||||
<style name="AppBaseTheme.Borderless">
|
||||
<item name="android:background">?android:attr/selectableItemBackground</item>
|
||||
<item name="android:paddingLeft">4dip</item>
|
||||
<item name="android:paddingRight">4dip</item>
|
||||
<!-- Requires API 17
|
||||
<item name="android:paddingStart">4dip</item>
|
||||
<item name="android:paddingEnd">4dip</item>
|
||||
-->
|
||||
</style>
|
||||
|
||||
</resources>
|
19
MinimalBible/src/test/AndroidManifest.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.bspeice.minimalbible">
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:targetSdkVersion="20" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:name="org.bspeice.minimalbible.test.MinimalBibleTest" >
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,20 @@
|
||||
package org.bspeice.minimalbible.test;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||
|
||||
import dagger.Module;
|
||||
|
||||
/**
|
||||
* Master module for MinimalBible
|
||||
*/
|
||||
@Module(
|
||||
injects = {
|
||||
MinimalBible.class
|
||||
},
|
||||
includes = {
|
||||
MinimalBibleModules.class
|
||||
}
|
||||
)
|
||||
public class MinimalBibleModulesTest {
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package org.bspeice.minimalbible.test;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
|
||||
import dagger.ObjectGraph;
|
||||
|
||||
public class MinimalBibleTest extends MinimalBible {
|
||||
|
||||
/**
|
||||
* The graph used by Dagger to track dependencies
|
||||
*/
|
||||
private ObjectGraph graph;
|
||||
|
||||
/**
|
||||
* A singleton reference to the Application currently being run.
|
||||
* Used mostly so we have a fixed point to get the App Context from
|
||||
*/
|
||||
private static MinimalBibleTest instance;
|
||||
|
||||
private String TAG = "MinimalBibleTest";
|
||||
|
||||
/**
|
||||
* Create the application, and persist the application Context
|
||||
*/
|
||||
public MinimalBibleTest() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Application Context. Please note, all attempts to get the App Context should come
|
||||
* through here, and please be sure that the Application won't satisfy what you need.
|
||||
* @return The Application Context
|
||||
*/
|
||||
public static Context getAppContext() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Application, rather than just the Application Context. You likely should be using
|
||||
* this, rather than {@link #getAppContext()}
|
||||
* @return The MinimalBible {@link android.app.Application} object
|
||||
*/
|
||||
public static MinimalBibleTest getApplication() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the {@link android.app.Application}. Responsible for building and
|
||||
* holding on to the master ObjectGraph.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
//TODO: Is this necessary?
|
||||
inject(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject a Dagger object
|
||||
* @param o The object to be injected
|
||||
*/
|
||||
@Override
|
||||
public void inject(Object o) {
|
||||
getObjGraph().inject(o);
|
||||
}
|
||||
|
||||
public ObjectGraph getObjGraph() {
|
||||
if (graph == null) {
|
||||
graph = ObjectGraph.create(MinimalBibleModulesTest.class);
|
||||
}
|
||||
return graph;
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package org.bspeice.minimalbible.test.activities.downloader;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.activities.downloader.BookListFragment;
|
||||
import org.bspeice.minimalbible.activities.downloader.DownloadActivity;
|
||||
import org.bspeice.minimalbible.activities.downloader.DownloadPrefs;
|
||||
import org.bspeice.minimalbible.test.MinimalBibleModulesTest;
|
||||
import org.crosswire.jsword.book.BookCategory;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import dagger.Module;
|
||||
import de.devland.esperandro.Esperandro;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 6/23/14.
|
||||
*/
|
||||
public class BookListFragmentTest extends ActivityInstrumentationTestCase2<DownloadActivity> {
|
||||
|
||||
@Module(injects = TestDialogDisplayedIfFirstTimeFragment.class,
|
||||
addsTo = MinimalBibleModulesTest.class
|
||||
)
|
||||
protected static class BookListFragmentTestModule{}
|
||||
|
||||
public BookListFragmentTest() {
|
||||
super(DownloadActivity.class);
|
||||
}
|
||||
|
||||
FragmentManager mFragmentManager;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
mFragmentManager = getActivity().getSupportFragmentManager();
|
||||
assertNotNull(mFragmentManager);
|
||||
}
|
||||
|
||||
|
||||
public <F extends Fragment> F startFragment(F fragment) {
|
||||
try {
|
||||
mFragmentManager.beginTransaction()
|
||||
.replace(android.R.id.content, fragment)
|
||||
.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final CountDownLatch signal = new CountDownLatch(1);
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mFragmentManager.executePendingTransactions();
|
||||
signal.countDown();
|
||||
}
|
||||
});
|
||||
try {
|
||||
signal.await();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return (F)(mFragmentManager.findFragmentById(android.R.id.content));
|
||||
}
|
||||
|
||||
|
||||
protected class TestDialogDisplayedIfFirstTimeFragment extends BookListFragment {
|
||||
/**
|
||||
* If the refresh dialog is blank after calling display, it must be showing the warning
|
||||
* @return Whether the warning dialog is showing
|
||||
*/
|
||||
public boolean callDisplayModules(DownloadPrefs prefs) {
|
||||
// Inject the new preferences...
|
||||
this.downloadPrefs = prefs;
|
||||
displayModules();
|
||||
return (refreshDialog == null);
|
||||
}
|
||||
|
||||
public void setArgs(BookCategory c) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_BOOK_CATEGORY, c.toString());
|
||||
this.setArguments(args);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDialogDisplayedIfFirstTime() {
|
||||
((MinimalBible)getActivity().getApplication()).plusObjGraph(BookListFragmentTestModule.class);
|
||||
TestDialogDisplayedIfFirstTimeFragment f = new TestDialogDisplayedIfFirstTimeFragment();
|
||||
f.setArgs(BookCategory.BIBLE);
|
||||
startFragment(f);
|
||||
|
||||
DownloadPrefs prefs = Esperandro.getPreferences(DownloadPrefs.class, getActivity());
|
||||
prefs.hasShownDownloadDialog(false);
|
||||
|
||||
assertNotNull(f);
|
||||
assertTrue(f.callDisplayModules(Esperandro.getPreferences(DownloadPrefs.class, getActivity())));
|
||||
}
|
||||
|
||||
public void testRefreshDisplayedAfterFirstTime() {
|
||||
((MinimalBible)getActivity().getApplication()).plusObjGraph(BookListFragmentTestModule.class);
|
||||
|
||||
TestDialogDisplayedIfFirstTimeFragment f = new TestDialogDisplayedIfFirstTimeFragment();
|
||||
f.setArgs(BookCategory.BIBLE);
|
||||
startFragment(f);
|
||||
|
||||
DownloadPrefs prefs = Esperandro.getPreferences(DownloadPrefs.class, getActivity());
|
||||
prefs.hasShownDownloadDialog(true);
|
||||
|
||||
assertNotNull(f);
|
||||
assertFalse(f.callDisplayModules(Esperandro.getPreferences(DownloadPrefs.class, getActivity())));
|
||||
}
|
||||
}
|
7
README.md
Normal file
@ -0,0 +1,7 @@
|
||||
MinimalBible
|
||||
============
|
||||
|
||||
A Bible app for android designed to be more focused in both UI and feature set. If you want to keep
|
||||
track of the ongoing progress, check out the blog [over here](http://minimalbible.github.io/)!
|
||||
|
||||
![Travis Build Status](https://travis-ci.org/MinimalBible/MinimalBible.svg?branch=master)
|
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
68
app/app.iml
Normal file
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="MinimalBible2" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
|
||||
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/../../MinimalBible2/app/src/main/res" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 20, L preview Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-19.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
25
app/build.gradle
Normal file
@ -0,0 +1,25 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 'android-L'
|
||||
buildToolsVersion "20.0.0"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "org.bspeice.minimalbible"
|
||||
minSdkVersion 8
|
||||
targetSdkVersion 'L'
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
runProguard false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:appcompat-v7:19.+'
|
||||
}
|
17
app/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in C:\Users\Bradlee Speice\AppData\Local\Android\android-studio\sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
@ -0,0 +1,13 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
21
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.bspeice.minimalbible" >
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name=".DownloadActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
146
app/src/main/java/org/bspeice/minimalbible/DownloadActivity.java
Normal file
@ -0,0 +1,146 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class DownloadActivity extends ActionBarActivity
|
||||
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
|
||||
/**
|
||||
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
|
||||
*/
|
||||
private NavigationDrawerFragment mNavigationDrawerFragment;
|
||||
|
||||
/**
|
||||
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
|
||||
*/
|
||||
private CharSequence mTitle;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_download);
|
||||
|
||||
mNavigationDrawerFragment = (NavigationDrawerFragment)
|
||||
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
|
||||
mTitle = getTitle();
|
||||
|
||||
// Set up the drawer.
|
||||
mNavigationDrawerFragment.setUp(
|
||||
R.id.navigation_drawer,
|
||||
(DrawerLayout) findViewById(R.id.drawer_layout));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNavigationDrawerItemSelected(int position) {
|
||||
// update the main content by replacing fragments
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
|
||||
.commit();
|
||||
}
|
||||
|
||||
public void onSectionAttached(int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
mTitle = getString(R.string.title_section1);
|
||||
break;
|
||||
case 2:
|
||||
mTitle = getString(R.string.title_section2);
|
||||
break;
|
||||
case 3:
|
||||
mTitle = getString(R.string.title_section3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreActionBar() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setTitle(mTitle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
if (!mNavigationDrawerFragment.isDrawerOpen()) {
|
||||
// Only show items in the action bar relevant to this screen
|
||||
// if the drawer is not showing. Otherwise, let the drawer
|
||||
// decide what to show in the action bar.
|
||||
getMenuInflater().inflate(R.menu.download, menu);
|
||||
restoreActionBar();
|
||||
return true;
|
||||
}
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public static class PlaceholderFragment extends Fragment {
|
||||
/**
|
||||
* The fragment argument representing the section number for this
|
||||
* fragment.
|
||||
*/
|
||||
private static final String ARG_SECTION_NUMBER = "section_number";
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section
|
||||
* number.
|
||||
*/
|
||||
public static PlaceholderFragment newInstance(int sectionNumber) {
|
||||
PlaceholderFragment fragment = new PlaceholderFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public PlaceholderFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_download, container, false);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
((DownloadActivity) activity).onSectionAttached(
|
||||
getArguments().getInt(ARG_SECTION_NUMBER));
|
||||
}
|
||||
}
|
||||
|
||||
}
|