ACN Android Framework
ACN Android Framework is being developed to reduce application development effort and time providing custom...
- Application and Activity classes that encapsulate general configuration of application and initialization of many widely-used third-party libraries.
- View classes with sophisticated, yet easy-to-use features, powered by default views of Android and other third-party views shared on GitHub.
See test
module for sample usage of the framework.
Table of Contents
1. Context classes
The following classes can be found under context
package:
AcnApplication (abstract class, extends Application)
- Application class that extends AcnApplication needs to provide required params inside constructor method:
super.build()
.cacheSize(1024 * 1024 * 5) // in bytes -- default: 1 kB
.appFont("MyFont.ttf")
// located in the directory "assets/fonts/"
.imageCacheInMemory(true)
// default: false
.imageCacheOnDisk(true)
// default: false
.imageFadeInDuration(300);
// in ms -- default: 0 ms
- Initializes the following libraries:
- AndroidBaseUtils
- LeakCanary
- Reservoir
- Calligraphy
- Universal Image Loader
- Iconify (required to support Font Awesome icons inside AcnTextView)
- ReactiveNetwork (required to observe the Internet connectivity status)
AcnActivity (abstract class, extends AppCompatActivity)
- Activity class that extends AcnActivity needs to provide required params inside constructor method:
super.build(this)
.contentRes(R.layout.my_activity)
// required
.toolbarRes(R.id.toolbar)
// required
.backButtonRes(R.id.back_button)
// nullable
.backButtonVisible(true)
// default: false
.statusBarColor(R.color.statusBar) // nullable
.usesButterKnife(true)
// default: false -- required to use Butter Knife(https://github.com/JakeWharton/butterknife) features
.usesOttoEventBus(true)
// default: false -- registers/unregisters Otto Event Bus(https://github.com/square/otto) at onResume()/onPause()
.internetStatusListener(new InternetStatusListener() {
@Subscribe
public void onInternetStatusChanged(ConnectivityStatus status) {
/*DO SOMETHING HERE*/
}
}
);
2. View classes
The following classes can be found under view
package:
AcnImageView (extends FrameLayout)
- Includes the following UI components:
- ImageView
- LoadingView (default loading animation)
- GifImageView (custom loading animation)
- Supports loading image from URL, drawable, and assets
acn_imageview.setImageFromURL("http://goo.gl/T59s3M", zoomable);
acn_imageview.setImageFromDrawable(R.drawable.image, zoomable);
acn_imageview.setImageFromAssets("image.jpg", zoomable);
(located in the directoryassets/
)
- Supports zoomable images
- Set the second param of above methods to
true
- Set the second param of above methods to
- Supports custom GIF image for loading animation
- Set the following attributes in XML:
app:loadingGifSrc="loading.gif"
(located in the directoryassets/
)app:loadingGifSize="80dp"
- Set the following attributes in XML:
- Custom XML attributes:
scaleType
(enum)fitCenter
(default)centerCrop
fitXY
loadingGifSrc
(string)loadingGifSize
(dimension)
AcnViewPager (extends LinearLayout)
- Includes the following UI components:
- SlidingTabLayout & SlidingTabStrip (customized versions of them)
- ViewPager
- Set fragments and tab titles with one line of code:
acn_viewpager.setContent(fragments, tabTitles);
- Supports using Font Awesome icons inside tab titles
- Custom XML attributes:
indicatorColor
(color)dividerColor
(color)selectedTitleColor
(color)unselectedTitleColor
(color)tabBackgroundColor
(color)tabTitleSize
(dimension)
- Screenshot
AcnImagePager (extends RelativeLayout)
- Includes the following UI components:
- SliderLayout (Has no functionality -- just to be able to use PagerIndicator)
- HackyViewPager
- PagerIndicator
- Supports loading images from URL list
acn_imagepager.setImagesFromURLList(imageURLs, zoomable);
- Supports zoomable images
- Set the second param of above method to
true
- Set the second param of above method to
- Supports custom GIF image for loading animation
- Set the following attributes in XML:
app:loadingGifSrc="loading.gif"
(located in the directoryassets/
)app:loadingGifSize="80dp"
- Set the following attributes in XML:
- Custom XML attributes:
selectedIndicatorColor
(color)unselectedIndicatorColor
(color)selectedIndicatorSize
(dimension)unselectedIndicatorSize
(dimension)indicatorBottomMargin
(dimension)loadingGifSrc
(string)loadingGifSize
(dimension)
- Screenshot
AcnImageGallery (extends LinearLayout)
- Includes two or three AcnImageView components at each row, depending on
columnType
attribute- Each image has an aspect ratio of 3:2 if
columnType
is set topair
- Each image has an aspect ratio of 1:1 if
columnType
is set totriplet
- No limit for number of rows
- Each image has an aspect ratio of 3:2 if
- Supports loading images from URL list
acn_imagegallery.setImagesFromURLList(imageURLs);
- Set ImageClickHandler to handle image clicks
acn_imagegallery.setImageClickHandler(new ImageClickHandler() { ... } );
- Supports custom GIF image for loading animation
- Set the following attributes in XML:
app:loadingGifSrc="loading.gif"
(located in the directoryassets/
)app:loadingGifSize="80dp"
- Set the following attributes in XML:
- Custom XML attributes:
spacing
(dimension)columnType
(enum)pair
(default)triplet
loadingGifSrc
(string)loadingGifSize
(dimension)
- Screenshot
AcnInfiniteListView (extends FrameLayout)
- Includes the following UI components:
- SwipeRefreshLayout
- ListView
- Initialize it as follows:
acn_infinitelistview.init(adapter, maxNumOfItems, loadingView);
adapter
( InfiniteListAdapter)- Extend it to create your own adapter
- Override its
onNewLoadRequired()
method to load new items when required - Override its
onRefresh()
method to set what to do on swipe-to-refresh
- Override its
- Extend it to create your own adapter
maxNumOfItems
(int)- To make listview prevent loading more when item count reaches this number
loadingView
(View)- Footer view to be displayed while loading new items
- Includes the following methods:
acn_infinitelistview.addNewItem(item);
-> adds new item to listacn_infinitelistview.clearList();
-> clears entire list (and triggersonNewLoadRequired()
)acn_infinitelistview.startLoading();
-> call this before item loading startsacn_infinitelistview.stopLoading();
-> call this after item loading ends
- Screenshot
AcnImageSlideshow (extends AcnImageView)
- Supports loading images from URL list
acn_imageslideshow.setImagesAndStartAnimation(imageURLs, delayInMs);
delayInMs
-> duration of time for each image displayed
- You need to call
acn_imageslideshow.stopAnimation();
atonDestroy()
of your Activity or Fragment
AcnButton (extends FancyButton)
- Can do anything that FancyButton does
AcnTextView (extends IconTextView)
- Can do anything that IconTextView does
- Allows to use Font Awesome icons inside text
android:text="Hello world { fa-globe } "
3. Util classes
The following classes can be found under util
package:
BusProvider
- Includes static instance of Otto Event Bus
- Use this class to register/unregister Otto Event Bus
BusProvider.getInstance().register(this);
BusProvider.getInstance().unregister(this);
InternetStatusListener (abstract class)
- Includes abstract method
onInternetStatusChanged(ConnectivityStatus status)
ImageClickHandler (abstract class)
- Includes abstract method
onImageClicked(int position, String imageURL)
InfiniteListAdapter (abstract class, extends ArrayAdapter)
- Constructor takes the following params:
activity
(Activity)itemLayoutRes
(int)- e.g.,
R.layout.item_text
- e.g.,
itemList
(ArrayList)
- Includes abstract methods
onNewLoadRequired()
andonRefresh()
4. How to use
Step 1. Add the JitPack repository in your root build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven {
url "https://jitpack.io"
}
}
}
Step 2. Add the dependency:
dependencies {
compile 'com.github.ugurcany:acn-android-framework:X.Y.Z'
}
Step 3. To be able to use all features of the framework, add the corresponding dependencies for the following libraries:
- Otto Event Bus
- AndroidBaseUtils
- Reservoir
- Butter Knife
- ReactiveNetwork
- Iconify -> required for AcnTextView
- FancyButton -> required for AcnButton
5. License
The MIT License (MIT) Copyright (c) 2016 Ugurcan Yildirim Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.