├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── tdscientist
│ │ └── shelfview
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── cover.jpg
│ ├── java
│ │ └── com
│ │ │ └── tdscientist
│ │ │ └── shelfviewSample
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable
│ │ └── cover.png
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── tdscientist
│ └── shelfview
│ └── ExampleUnitTest.java
├── build.gradle
├── desc.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── landscape.png
├── portrait.png
├── settings.gradle
└── shelfview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── tdscientist
│ └── shelfview
│ └── ApplicationTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── tdscientist
│ │ └── shelfview
│ │ ├── BookModel.java
│ │ ├── ShelfAdapter.java
│ │ ├── ShelfModel.java
│ │ ├── ShelfView.java
│ │ └── Utils.java
└── res
│ ├── drawable-hdpi
│ ├── grid_item_background_center.9.png
│ ├── grid_item_background_left.9.png
│ └── grid_item_background_right.9.png
│ ├── drawable-mdpi
│ ├── grid_item_background_center.9.png
│ ├── grid_item_background_left.9.png
│ └── grid_item_background_right.9.png
│ ├── drawable-xhdpi
│ ├── grid_item_background_center.9.png
│ ├── grid_item_background_left.9.png
│ └── grid_item_background_right.9.png
│ ├── drawable-xxhdpi
│ ├── grid_item_background_center.9.png
│ ├── grid_item_background_left.9.png
│ └── grid_item_background_right.9.png
│ ├── drawable
│ ├── book_spine_grey_blend.xml
│ └── book_spine_white_blend.xml
│ ├── layout
│ ├── book_cover.xml
│ └── book_shelf_grid_item.xml
│ └── values
│ ├── dimens.xml
│ └── strings.xml
└── test
└── java
└── com
└── tdscientist
└── shelfview
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Shelf View
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://android-arsenal.com/details/1/5299) [](https://material.uplabs.com/posts/shelfview)
2 |
3 |
4 | ## ShelfView ##
5 |
6 | *Android custom view to display books on shelf* ` ` **([iOS version is available here](https://github.com/tdscientist/ShelfView-iOS))**
7 |
8 |
9 |
10 |
11 |
12 |
13 | #### How to use ####
14 | ----
15 |
16 | **build.gradle**
17 | ```
18 | allprojects {
19 | repositories {
20 | maven {
21 | url 'https://jitpack.io'
22 | }
23 | }
24 | }
25 | ```
26 |
27 |
28 | ```
29 | dependencies {
30 | compile 'com.github.tdscientist:ShelfView:v1.0'
31 | }
32 | ```
33 |
34 | **Layout**
35 | ```
36 |
40 |
41 | ```
42 |
43 |
44 | **Activity**
45 | ```
46 | import com.tdscientist.shelfview.BookModel;
47 | import com.tdscientist.shelfview.ShelfView;
48 | import java.util.ArrayList;
49 |
50 | public class MainActivity extends AppCompatActivity implements ShelfView.BookClickListener {
51 |
52 | @Override
53 | protected void onCreate(Bundle savedInstanceState) {
54 | super.onCreate(savedInstanceState);
55 | setContentView(R.layout.activity_main);
56 |
57 | ShelfView shelfView = (ShelfView) findViewById(R.id.shelfView);
58 | shelfView.setOnBookClicked(this);
59 | ArrayList models = new ArrayList<>();
60 |
61 | models.add(new BookModel("http://eurodroid.com/pics/beginning_android_book.jpg", "1", "Beginning Android"));
62 |
63 | shelfView.loadData(models, ShelfView.BOOK_SOURCE_URL);
64 |
65 |
66 | }
67 |
68 | @Override
69 | public void onBookClicked(int position, String bookId, String bookTitle) {
70 | // handle click events here
71 | //Toast.makeText(this, bookTitle, Toast.LENGTH_SHORT).show();
72 | }
73 | }
74 |
75 | ```
76 |
77 |
78 |
79 | #### Loading book covers from other sources ####
80 | ----
81 |
82 | * Internal/External directory in the device
83 | ```
84 | model.add(new BookModel("/path/to/android_book_cover.jpg", "1", "Let's Talk About Android"));
85 | shelfView.loadData(model, ShelfView.BOOK_SOURCE_FILE);
86 | ```
87 |
88 |
89 |
90 | * Assets folder
91 | ```
92 | model.add(new BookModel("android.jpg", "1", "Android for Experts"));
93 | shelfView.loadData(model, ShelfView.BOOK_SOURCE_ASSETS_FOLDER);
94 | ```
95 |
96 |
97 |
98 | * Drawable folder
99 | ```
100 | model.add(new BookModel("alice", "1", "Alice in Wonderland"));
101 | shelfView.loadData(model, ShelfView.BOOK_SOURCE_DRAWABLE_FOLDER);
102 | ```
103 |
104 |
105 | #### Permissions ####
106 | ----
107 | ```
108 |
109 |
110 | ```
111 |
112 |
113 |
114 | #### License ####
115 | ----
116 | ```
117 | Copyright 2017 Adeyinka Adediji
118 |
119 | Licensed under the Apache License, Version 2.0 (the "License");
120 | you may not use this file except in compliance with the License.
121 | You may obtain a copy of the License at
122 |
123 | http://www.apache.org/licenses/LICENSE-2.0
124 |
125 | Unless required by applicable law or agreed to in writing, software
126 | distributed under the License is distributed on an "AS IS" BASIS,
127 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128 | See the License for the specific language governing permissions and
129 | limitations under the License.
130 | ```
131 |
132 |
133 | #### Contributions & Bug Reporting ####
134 | ---
135 | tdscientist@gmail.com
136 |
137 |
138 |
139 | #### Credits ####
140 | ---
141 | * [Picasso](https://github.com/square/picasso)
142 |
143 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.tdscientist.shelfviewTest"
9 | minSdkVersion 17
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | generatedDensities = []
14 | }
15 | aaptOptions {
16 | additionalParameters "--no-version-vectors"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(include: ['*.jar'], dir: 'libs')
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.android.support:appcompat-v7:25.1.0'
30 | compile project(':shelfview')
31 | }
32 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Scientist/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tdscientist/shelfview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/assets/cover.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/app/src/main/assets/cover.jpg
--------------------------------------------------------------------------------
/app/src/main/java/com/tdscientist/shelfviewSample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfviewSample;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.Toast;
6 |
7 | import com.tdscientist.shelfview.BookModel;
8 | import com.tdscientist.shelfview.ShelfView;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Copyright (c) 2017 Adediji Adeyinka(tdscientist)
14 | * All rights reserved
15 | * Created on 16-Feb-2017
16 | */
17 |
18 | public class MainActivity extends AppCompatActivity implements ShelfView.BookClickListener {
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 |
25 | ShelfView shelfView = (ShelfView) findViewById(R.id.shelfView);
26 | shelfView.setOnBookClicked(this);
27 | ArrayList model = new ArrayList<>();
28 |
29 | model.add(new BookModel(getString(R.string.url_smashing_android_ui), "1", getString(R.string.title_smashing_android_ui)));
30 | model.add(new BookModel(getString(R.string.url_android_app_dev_for_dummies), "2", getString(R.string.title_android_app_dev_for_dummies)));
31 | model.add(new BookModel(getString(R.string.url_beginning_android), "3", getString(R.string.title_beginning_android)));
32 | model.add(new BookModel(getString(R.string.url_professional_android_programming), "4", getString(R.string.title_professional_android_programming)));
33 | model.add(new BookModel(getString(R.string.url_android_programming_pshing_the_limits), "5", getString(R.string.title_android_programming_pshing_the_limits)));
34 | model.add(new BookModel(getString(R.string.url_100_q_and_a), "6", getString(R.string.title_100_q_and_a)));
35 | model.add(new BookModel(getString(R.string.url_android_programming_for_beginners), "7", getString(R.string.title_android_programming_for_beginners)));
36 | model.add(new BookModel(getString(R.string.url_android_programming), "8", getString(R.string.title_android_programming)));
37 |
38 | shelfView.loadData(model, ShelfView.BOOK_SOURCE_URL);
39 |
40 |
41 | }
42 |
43 |
44 | @Override
45 | public void onBookClicked(int position, String bookId, String bookTitle) {
46 | Toast.makeText(this, bookTitle, Toast.LENGTH_SHORT).show();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/app/src/main/res/drawable/cover.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Shelf View
3 | http://3.bp.blogspot.com/-aDUhP55KerE/UGbxmCkyKOI/AAAAAAAAKM8/Ms7Hs6Ln524/s1600/cover.png
4 | https://raw.githubusercontent.com/emmby/android-for-dummies-v3/master/assets/book-cover.png
5 | http://eurodroid.com/pics/beginning_android_book.jpg
6 | http://devproconnections.com/site-files/devproconnections.com/files/uploads/2014/06/Riley%20DCM1061%20Pro_Android_book_cover.jpg
7 | http://whatpixel.com/images/2016/08/android-programming-pushing-the-limits.jpg
8 | http://www.lopez-manas.com/wp-content/uploads/2015/07/cover-Kopie-212x300.png
9 | https://www.packtpub.com/sites/default/files/9781785883262.png
10 | http://www.informit.com/ShowCover.aspx?isbn=0672336286
11 | SMASHING Android UI
12 | Android App Development for DUMMIES
13 | Beginning Android
14 | Professional Android Programming
15 | ANDROID PROGRAMMING PUSHING THE LIMITS
16 |
17 | Android Programming for Beginners
18 | Android Programming
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tdscientist/shelfview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | jcenter()
16 | }
17 | }
18 |
19 | task clean(type: Delete) {
20 | delete rootProject.buildDir
21 | }
22 |
--------------------------------------------------------------------------------
/desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/desc.png
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/landscape.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/landscape.png
--------------------------------------------------------------------------------
/portrait.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/portrait.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':shelfview'
2 |
--------------------------------------------------------------------------------
/shelfview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/shelfview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.tdscientist'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion "25.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 16
11 | targetSdkVersion 25
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | testCompile 'junit:junit:4.12'
26 | compile 'com.android.support:appcompat-v7:25.1.0'
27 | compile 'com.android.support:cardview-v7:25.1.0'
28 | compile 'com.squareup.picasso:picasso:2.5.2'
29 | }
30 |
--------------------------------------------------------------------------------
/shelfview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Scientist/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/shelfview/src/androidTest/java/com/tdscientist/shelfview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/shelfview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/shelfview/src/main/java/com/tdscientist/shelfview/BookModel.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 |
4 | /**
5 | * Copyright (c) 2017 Adediji Adeyinka(tdscientist)
6 | * All rights reserved
7 | * Created on 11-Feb-2017
8 | */
9 |
10 | public class BookModel {
11 |
12 | private String bookCoverSource;
13 | private String bookId;
14 | private String bookTitle;
15 |
16 | public BookModel(String bookCoverSource, String bookId, String bookTitle) {
17 | this.bookCoverSource = bookCoverSource;
18 | this.bookId = bookId;
19 | this.bookTitle = bookTitle;
20 | }
21 |
22 | public String getBookCoverSource() {
23 | return bookCoverSource;
24 | }
25 |
26 | public void setBookCoverSource(String bookCoverSource) {
27 | this.bookCoverSource = bookCoverSource;
28 | }
29 |
30 | public String getBookId() {
31 | return bookId;
32 | }
33 |
34 | public void setBookId(String bookId) {
35 | this.bookId = bookId;
36 | }
37 |
38 | public String getBookTitle() {
39 | return bookTitle;
40 | }
41 |
42 | public void setBookTitle(String bookTitle) {
43 | this.bookTitle = bookTitle;
44 | }
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/shelfview/src/main/java/com/tdscientist/shelfview/ShelfAdapter.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 | import android.content.Context;
4 | import android.os.Environment;
5 | import android.support.v7.widget.CardView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 | import android.widget.ImageView;
11 | import android.widget.ProgressBar;
12 |
13 | import com.squareup.picasso.Callback;
14 | import com.squareup.picasso.Picasso;
15 |
16 | import java.io.File;
17 | import java.util.ArrayList;
18 |
19 |
20 | /**
21 | * Copyright (c) 2017 Adediji Adeyinka(tdscientist)
22 | * All rights reserved
23 | * Created on 11-Feb-2017
24 | */
25 |
26 | public class ShelfAdapter extends BaseAdapter {
27 |
28 | Context context;
29 | Utils utils;
30 | ArrayList model;
31 | int bookSource = 999;
32 | String internalStorage;
33 |
34 |
35 | public ShelfAdapter(Context context, ArrayList model) {
36 | this.context = context;
37 | this.model = model;
38 | this.utils = new Utils(context);
39 | this.internalStorage = Environment.getExternalStorageDirectory().toString();
40 | }
41 |
42 | @Override
43 | public int getCount() {
44 | return model.size();
45 | }
46 |
47 | @Override
48 | public Object getItem(int position) {
49 | return model.get(position);
50 | }
51 |
52 | @Override
53 | public long getItemId(int position) {
54 | return 0L;
55 | }
56 |
57 |
58 | private class ViewHolder {
59 |
60 | ImageView shelfBackground, bookCover;
61 | CardView bookBackground;
62 | ProgressBar progressBar;
63 | View spine_grey, spine_white;
64 | }
65 |
66 | @Override
67 | public View getView(int position, View convertView, ViewGroup parent) {
68 |
69 | final ViewHolder holder;
70 | LayoutInflater mInflater = LayoutInflater.from(context);
71 |
72 | if (convertView == null) {
73 | convertView = mInflater.inflate(R.layout.book_shelf_grid_item, null);
74 | holder = new ViewHolder();
75 | convertView.setTag(holder);
76 | } else {
77 | holder = (ViewHolder) convertView.getTag();
78 | }
79 |
80 | holder.shelfBackground = (ImageView) convertView.findViewById(R.id.shelf_background);
81 | holder.bookCover = (ImageView) convertView.findViewById(R.id.book_cover);
82 | holder.bookBackground = (CardView) convertView.findViewById(R.id.book_background);
83 | holder.progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
84 | holder.spine_grey = convertView.findViewById(R.id.spine_grey);
85 | holder.spine_white = convertView.findViewById(R.id.spine_white);
86 |
87 | final ShelfModel pos = model.get(position);
88 |
89 | holder.progressBar.setVisibility(!pos.getShow() ? View.GONE : View.VISIBLE);
90 |
91 | switch (pos.getType()) {
92 | case "start":
93 | holder.shelfBackground.setImageResource(R.drawable.grid_item_background_left);
94 | break;
95 | case "end":
96 | holder.shelfBackground.setImageResource(R.drawable.grid_item_background_right);
97 | break;
98 | default:
99 | holder.shelfBackground.setImageResource(R.drawable.grid_item_background_center);
100 | break;
101 | }
102 |
103 | String bookCover = pos.getBookCoverSource().trim();
104 |
105 | switch (bookSource) {
106 | case 1:
107 | if (pos.getShow() && !bookCover.equals("")) {
108 | Picasso.with(context)
109 | .load(new File(internalStorage + bookCover))
110 | .resize(utils.dpToPixels(context.getResources().getInteger(R.integer.book_width)),
111 | utils.dpToPixels(context.getResources().getInteger(R.integer.book_height)))
112 | .into(holder.bookCover, new Callback() {
113 | @Override
114 | public void onSuccess() {
115 | holder.bookBackground.setVisibility(!pos.getShow() ? View.GONE : View.VISIBLE);
116 | holder.progressBar.setVisibility(View.GONE);
117 | holder.spine_grey.setVisibility(View.VISIBLE);
118 | holder.spine_white.setVisibility(View.VISIBLE);
119 | }
120 |
121 | @Override
122 | public void onError() {
123 |
124 | }
125 | });
126 | }
127 | break;
128 | case 2:
129 | if (pos.getShow() && !bookCover.equals("")) {
130 | Picasso.with(context)
131 | .load(bookCover)
132 | .resize(utils.dpToPixels(context.getResources().getInteger(R.integer.book_width)),
133 | utils.dpToPixels(context.getResources().getInteger(R.integer.book_height)))
134 | .into(holder.bookCover, new Callback() {
135 | @Override
136 | public void onSuccess() {
137 | holder.bookBackground.setVisibility(!pos.getShow() ? View.GONE : View.VISIBLE);
138 | holder.progressBar.setVisibility(View.GONE);
139 | holder.spine_grey.setVisibility(View.VISIBLE);
140 | holder.spine_white.setVisibility(View.VISIBLE);
141 | }
142 |
143 | @Override
144 | public void onError() {
145 |
146 | }
147 | });
148 | }
149 | break;
150 | case 3:
151 | if (pos.getShow() && !bookCover.equals("")) {
152 | Picasso.with(context)
153 | .load("file:///android_asset/" + bookCover)
154 | .resize(utils.dpToPixels(context.getResources().getInteger(R.integer.book_width)),
155 | utils.dpToPixels(context.getResources().getInteger(R.integer.book_height)))
156 | .into(holder.bookCover, new Callback() {
157 | @Override
158 | public void onSuccess() {
159 | holder.bookBackground.setVisibility(!pos.getShow() ? View.GONE : View.VISIBLE);
160 | holder.progressBar.setVisibility(View.GONE);
161 | holder.spine_grey.setVisibility(View.VISIBLE);
162 | holder.spine_white.setVisibility(View.VISIBLE);
163 | }
164 |
165 | @Override
166 | public void onError() {
167 |
168 | }
169 | });
170 | }
171 | break;
172 | case 4:
173 | if (pos.getShow() && !bookCover.equals("")) {
174 | ;
175 | Picasso.with(context)
176 | .load(context.getResources().getIdentifier(bookCover, "drawable", context.getPackageName()))
177 | .resize(utils.dpToPixels(context.getResources().getInteger(R.integer.book_width)),
178 | utils.dpToPixels(context.getResources().getInteger(R.integer.book_height)))
179 | .into(holder.bookCover, new Callback() {
180 | @Override
181 | public void onSuccess() {
182 | holder.bookBackground.setVisibility(!pos.getShow() ? View.GONE : View.VISIBLE);
183 | holder.progressBar.setVisibility(View.GONE);
184 | holder.spine_grey.setVisibility(View.VISIBLE);
185 | holder.spine_white.setVisibility(View.VISIBLE);
186 | }
187 |
188 | @Override
189 | public void onError() {
190 |
191 | }
192 | });
193 | }
194 | break;
195 | default:
196 | if (pos.getShow() && !bookCover.equals("")) {
197 | Picasso.with(context)
198 | .load(pos.getBookCoverSource())
199 | .resize(utils.dpToPixels(context.getResources().getInteger(R.integer.book_width)),
200 | utils.dpToPixels(context.getResources().getInteger(R.integer.book_height)))
201 | .into(holder.bookCover, new Callback() {
202 | @Override
203 | public void onSuccess() {
204 | holder.bookBackground.setVisibility(!pos.getShow() ? View.GONE : View.VISIBLE);
205 | holder.progressBar.setVisibility(View.GONE);
206 | holder.spine_grey.setVisibility(View.VISIBLE);
207 | holder.spine_white.setVisibility(View.VISIBLE);
208 | }
209 |
210 | @Override
211 | public void onError() {
212 |
213 | }
214 | });
215 | }
216 | break;
217 | }
218 |
219 |
220 | return convertView;
221 | }
222 |
223 | public void setBookSource(int bookSource) {
224 | this.bookSource = bookSource;
225 | }
226 |
227 | }
--------------------------------------------------------------------------------
/shelfview/src/main/java/com/tdscientist/shelfview/ShelfModel.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 |
4 | /**
5 | * Copyright (c) 2017 Adediji Adeyinka(tdscientist)
6 | * All rights reserved
7 | * Created on 11-Feb-2017
8 | */
9 |
10 | public class ShelfModel {
11 |
12 | private String bookCoverSource;
13 | private String bookId;
14 | private String bookTitle;
15 | private Boolean show;
16 | private String type;
17 |
18 | public ShelfModel(String bookCoverSource, String bookId, String bookTitle, Boolean show, String type) {
19 | this.bookCoverSource = bookCoverSource;
20 | this.bookId = bookId;
21 | this.bookTitle = bookTitle;
22 | this.show = show;
23 | this.type = type;
24 | }
25 |
26 | public String getBookCoverSource() {
27 | return bookCoverSource;
28 | }
29 |
30 | public void setBookCoverSource(String bookCoverSource) {
31 | this.bookCoverSource = bookCoverSource;
32 | }
33 |
34 | public String getBookId() {
35 | return bookId;
36 | }
37 |
38 | public void setBookId(String bookId) {
39 | this.bookId = bookId;
40 | }
41 |
42 | public String getBookTitle() {
43 | return bookTitle;
44 | }
45 |
46 | public void setBookTitle(String bookTitle) {
47 | this.bookTitle = bookTitle;
48 | }
49 |
50 | public Boolean getShow() {
51 | return show;
52 | }
53 |
54 | public void setShow(Boolean show) {
55 | this.show = show;
56 | }
57 |
58 | public String getType() {
59 | return type;
60 | }
61 |
62 | public void setType(String type) {
63 | this.type = type;
64 | }
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/shelfview/src/main/java/com/tdscientist/shelfview/ShelfView.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.os.Handler;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 | import android.view.ViewTreeObserver;
10 | import android.widget.AdapterView;
11 | import android.widget.GridView;
12 |
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * Copyright (c) 2017 Adediji Adeyinka(tdscientist)
17 | * All rights reserved
18 | * Created on 11-Feb-2017
19 | */
20 |
21 | public class ShelfView extends GridView implements AdapterView.OnItemClickListener {
22 |
23 |
24 | Utils utils;
25 | private ShelfAdapter shelfAdapter;
26 | private ArrayList bookModel = new ArrayList<>();
27 | private ArrayList shelfModel;
28 | private int numberOfTilesPerRow;
29 | private int shelfHeight;
30 | private int shelfWidth;
31 | private int gridViewColumnWidth = getContext().getResources().getInteger(R.integer.shelf_column_width);
32 | private int gridItemHeight = getContext().getResources().getInteger(R.integer.shelf_list_item);
33 | public static int BOOK_SOURCE_FILE = 1;
34 | public static int BOOK_SOURCE_URL = 2;
35 | public static int BOOK_SOURCE_ASSETS_FOLDER = 3;
36 | public static int BOOK_SOURCE_DRAWABLE_FOLDER = 4;
37 |
38 |
39 | public ShelfView(Context context) {
40 | super(context);
41 | init(context);
42 | }
43 |
44 | public ShelfView(Context context, AttributeSet attrs) {
45 | super(context, attrs);
46 | init(context);
47 | }
48 |
49 | public ShelfView(Context context, AttributeSet attrs, int defStyleAttr) {
50 | super(context, attrs, defStyleAttr);
51 | init(context);
52 | }
53 |
54 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
55 | public ShelfView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
56 | super(context, attrs, defStyleAttr, defStyleRes);
57 | init(context);
58 | }
59 |
60 | private void init(Context context) {
61 | this.utils = new Utils(context);
62 | this.shelfModel = new ArrayList<>();
63 | this.shelfAdapter = new ShelfAdapter(context, shelfModel);
64 | setAdapter(shelfAdapter);
65 | setOnItemClickListener(this);
66 | initData(bookModel);
67 | }
68 |
69 | /**
70 | * Populate shelf with books
71 | *
72 | * @param bookModel
73 | * @param bookSource
74 | */
75 |
76 | public void loadData(final ArrayList bookModel, int bookSource) {
77 | this.shelfAdapter.setBookSource(bookSource);
78 | new Handler().postDelayed(new Runnable() {
79 | @Override
80 | public void run() {
81 | processData(bookModel);
82 | }
83 | }, 300);
84 | }
85 |
86 |
87 | /**
88 | * Actual book population on the shelf
89 | *
90 | * @param bookModel
91 | */
92 |
93 | private void processData(final ArrayList bookModel) {
94 | this.bookModel.clear();
95 | this.bookModel.addAll(bookModel);
96 | this.shelfModel.clear();
97 | for (int i = 0; i < bookModel.size(); i++) {
98 | String bookCoverSource = bookModel.get(i).getBookCoverSource();
99 | String bookId = bookModel.get(i).getBookId();
100 | String bookTitle = bookModel.get(i).getBookTitle();
101 |
102 | if ((i % numberOfTilesPerRow) == 0) {
103 | shelfModel.add(new ShelfModel(bookCoverSource, bookId, bookTitle, true, "start"));
104 | } else if ((i % numberOfTilesPerRow) == (numberOfTilesPerRow - 1)) {
105 | shelfModel.add(new ShelfModel(bookCoverSource, bookId, bookTitle, true, "end"));
106 | } else {
107 | shelfModel.add(new ShelfModel(bookCoverSource, bookId, bookTitle, true, ""));
108 | }
109 | }
110 |
111 |
112 | int sizeOfModel = bookModel.size();
113 | int numberOfRows = sizeOfModel / numberOfTilesPerRow;
114 | int remainderTiles = sizeOfModel % numberOfTilesPerRow;
115 |
116 | if (remainderTiles > 0) {
117 | numberOfRows = numberOfRows + 1;
118 | int fillUp = numberOfTilesPerRow - remainderTiles;
119 | for (int i = 0; i < fillUp; i++) {
120 | if (i == (fillUp - 1)) {
121 | shelfModel.add(new ShelfModel("", "", "", false, "end"));
122 | } else {
123 | shelfModel.add(new ShelfModel("", "", "", false, ""));
124 | }
125 | }
126 | }
127 |
128 | if ((numberOfRows * gridItemHeight) < shelfHeight) {
129 | int remainderRowHeight = (shelfHeight - (numberOfRows * gridItemHeight)) / gridItemHeight;
130 |
131 | if (remainderRowHeight == 0) {
132 | for (int i = 0; i < numberOfTilesPerRow; i++) {
133 | if (i == 0) {
134 | shelfModel.add(new ShelfModel("", "", "", false, "start"));
135 | } else if (i == (numberOfTilesPerRow - 1)) {
136 | shelfModel.add(new ShelfModel("", "", "", false, "end"));
137 | } else {
138 | shelfModel.add(new ShelfModel("", "", "", false, ""));
139 | }
140 |
141 | }
142 | } else if (remainderRowHeight > 0) {
143 | int fillUp = numberOfTilesPerRow * (remainderRowHeight + 1);
144 | for (int i = 0; i < fillUp; i++) {
145 | if ((i % numberOfTilesPerRow) == 0) {
146 | shelfModel.add(new ShelfModel("", "", "", false, "start"));
147 | } else if ((i % numberOfTilesPerRow) == (numberOfTilesPerRow - 1)) {
148 | shelfModel.add(new ShelfModel("", "", "", false, "end"));
149 | } else {
150 | shelfModel.add(new ShelfModel("", "", "", false, ""));
151 | }
152 |
153 | }
154 | }
155 | }
156 |
157 | shelfAdapter.notifyDataSetChanged();
158 | }
159 |
160 | /**
161 | * Create an empty shelf, in preparation for the books
162 | *
163 | * @param bookModel
164 | */
165 |
166 | private void initData(final ArrayList bookModel) {
167 | this.bookModel.clear();
168 | this.bookModel.addAll(bookModel);
169 | this.shelfModel.clear();
170 | setColumnWidth(utils.dpToPixels(getResources().getInteger(R.integer.shelf_column_width)));
171 | setHorizontalSpacing(0);
172 | setVerticalSpacing(0);
173 | setNumColumns(AUTO_FIT);
174 | setVerticalScrollBarEnabled(false);
175 | setHorizontalScrollBarEnabled(false);
176 |
177 | // width & height of the shelfView will always return 0 because view is yet to be "shown" after creation;
178 | // Their actual values need to be captured here
179 | getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
180 | @Override
181 | public void onGlobalLayout() {
182 |
183 | getViewTreeObserver().removeOnGlobalLayoutListener(this);
184 | shelfWidth = utils.pixelsToDp(getWidth());
185 | shelfHeight = utils.pixelsToDp(getHeight());
186 | numberOfTilesPerRow = shelfWidth / gridViewColumnWidth;
187 |
188 | int sizeOfModel = bookModel.size();
189 | int numberOfRows = sizeOfModel / numberOfTilesPerRow;
190 | int remainderTiles = sizeOfModel % numberOfTilesPerRow;
191 |
192 | if (remainderTiles > 0) {
193 | numberOfRows = numberOfRows + 1;
194 | int fillUp = numberOfTilesPerRow - remainderTiles;
195 | for (int i = 0; i < fillUp; i++) {
196 | if (i == (fillUp - 1)) {
197 | shelfModel.add(new ShelfModel("", "", "", false, "end"));
198 | } else {
199 | shelfModel.add(new ShelfModel("", "", "", false, ""));
200 | }
201 | }
202 | }
203 |
204 | if ((numberOfRows * gridItemHeight) < shelfHeight) {
205 | int remainderRowHeight = (shelfHeight - (numberOfRows * gridItemHeight)) / gridItemHeight;
206 |
207 | if (remainderRowHeight == 0) {
208 | for (int i = 0; i < numberOfTilesPerRow; i++) {
209 | if (i == 0) {
210 | shelfModel.add(new ShelfModel("", "", "", false, "start"));
211 | } else if (i == (numberOfTilesPerRow - 1)) {
212 | shelfModel.add(new ShelfModel("", "", "", false, "end"));
213 | } else {
214 | shelfModel.add(new ShelfModel("", "", "", false, ""));
215 | }
216 |
217 | }
218 | } else if (remainderRowHeight > 0) {
219 | int fillUp = numberOfTilesPerRow * (remainderRowHeight + 1);
220 | for (int i = 0; i < fillUp; i++) {
221 | if ((i % numberOfTilesPerRow) == 0) {
222 | shelfModel.add(new ShelfModel("", "", "", false, "start"));
223 | } else if ((i % numberOfTilesPerRow) == (numberOfTilesPerRow - 1)) {
224 | shelfModel.add(new ShelfModel("", "", "", false, "end"));
225 | } else {
226 | shelfModel.add(new ShelfModel("", "", "", false, ""));
227 | }
228 |
229 | }
230 | }
231 | }
232 |
233 |
234 | }
235 | });
236 |
237 |
238 | shelfAdapter.notifyDataSetChanged();
239 | }
240 |
241 |
242 | public interface BookClickListener {
243 |
244 | /**
245 | * Callback when book is clicked from the shelf
246 | *
247 | * @param position
248 | * @param bookId
249 | * @param bookTitle
250 | */
251 | void onBookClicked(int position, String bookId, String bookTitle);
252 | }
253 |
254 | private BookClickListener bookClickListener;
255 |
256 | public void setOnBookClicked(BookClickListener bookClickListener) {
257 | this.bookClickListener = bookClickListener;
258 | }
259 |
260 | @Override
261 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
262 | if (shelfModel.get(position).getShow()) {
263 | if (bookClickListener != null) {
264 | bookClickListener.onBookClicked(position, shelfModel.get(position).getBookId(),
265 | shelfModel.get(position).getBookTitle());
266 | }
267 | }
268 | }
269 |
270 | }
271 |
--------------------------------------------------------------------------------
/shelfview/src/main/java/com/tdscientist/shelfview/Utils.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Copyright (c) 2017 Adediji Adeyinka(tdscientist)
7 | * All rights reserved
8 | * Created on 11-Feb-2017
9 | */
10 |
11 | public class Utils {
12 |
13 | Context mContext;
14 |
15 | public Utils(Context mContext) {
16 | this.mContext = mContext;
17 | }
18 |
19 | public int dpToPixels(int dp) {
20 | float scale = mContext.getResources().getDisplayMetrics().density;
21 | return (int) (dp * scale + 0.5f);
22 | }
23 |
24 | public int pixelsToDp(int pixels) {
25 | float scale = mContext.getResources().getDisplayMetrics().density;
26 | return (int) (pixels / scale + 0.5f);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-hdpi/grid_item_background_center.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-hdpi/grid_item_background_center.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-hdpi/grid_item_background_left.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-hdpi/grid_item_background_left.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-hdpi/grid_item_background_right.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-hdpi/grid_item_background_right.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-mdpi/grid_item_background_center.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-mdpi/grid_item_background_center.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-mdpi/grid_item_background_left.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-mdpi/grid_item_background_left.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-mdpi/grid_item_background_right.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-mdpi/grid_item_background_right.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-xhdpi/grid_item_background_center.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-xhdpi/grid_item_background_center.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-xhdpi/grid_item_background_left.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-xhdpi/grid_item_background_left.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-xhdpi/grid_item_background_right.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-xhdpi/grid_item_background_right.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-xxhdpi/grid_item_background_center.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-xxhdpi/grid_item_background_center.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-xxhdpi/grid_item_background_left.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-xxhdpi/grid_item_background_left.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable-xxhdpi/grid_item_background_right.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tdscientist/ShelfView/59314a024fae5b12192c9282289db53aee21d9ec/shelfview/src/main/res/drawable-xxhdpi/grid_item_background_right.9.png
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable/book_spine_grey_blend.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/shelfview/src/main/res/drawable/book_spine_white_blend.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/shelfview/src/main/res/layout/book_cover.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
15 |
16 |
19 |
20 |
21 |
27 |
28 |
35 |
36 |
44 |
45 |
46 |
47 |
48 |
49 |
55 |
--------------------------------------------------------------------------------
/shelfview/src/main/res/layout/book_shelf_grid_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
15 |
16 |
17 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/shelfview/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 | 150dp
7 | 150
8 | 200
9 | 230dp
10 | 0dp
11 | 140dp
12 | 190dp
13 | -10dp
14 | 140
15 | 190
16 |
17 |
18 |
--------------------------------------------------------------------------------
/shelfview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ShelfView
3 |
4 |
--------------------------------------------------------------------------------
/shelfview/src/test/java/com/tdscientist/shelfview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tdscientist.shelfview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------