It is a ready to start development for an Android app project sample with base library.
Sample includes:
- Retrofit 2.0.2 with sample implementation for your rest calls.
- Dagger 2 based Dependency Injection with sample UtilitySingleton implementation.
- RX java sample implementation.
- Toolbar and Navigation drawer with RecyclerView.
- Custom fonts class with its implementation in XML file.
- LocationUtil based on fused location for getting current locations.
- GCM based push notification based on play services 8.4
- Marshmallow permission request sample.
- Google AutoComplete Places Widget for searching places.
- Clone or download this project.
- Import this project in Android Studio.
- Rename the packages as per your need.
- Use this project for your application development.
For getting current location single time:
LocationUtil.with(context).location().oneFix().start(new OnLocationUpdatedListener() {
@Override
public void getLocation(Location location) {
}
});
For getting current location (Periodic):
LocationConfig locationConfig = new LocationConfig();
locationConfig.setInterval(5000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationUtil.with(context).location().setConfig(locationConfig).start(new OnLocationUpdatedListener() {
@Override
public void getLocation(Location location) {
}
});
For stopping the location just use the stop method.
LocationUtil.with(context).location().stop();
// To get the human readable address
List<Address> address = LocationUtil.with(context).location().state().getAddress(location.getLatitude(), location.getLongitude());
// Check if the location services are enabled
LocationUtil.with(context).location().state().locationServicesEnabled();
// Check if any provider (network or gps) is enabled
LocationUtil.with(context).location().state().isAnyProviderAvailable();
// Check if GPS is available
LocationUtil.with(context).location().state().isGpsAvailable();
// Check if Network is available
LocationUtil.with(context).location().state().isNetworkAvailable();
// Check if the passive provider is available
LocationUtil.with(context).location().state().isPassiveAvailable();
// Check if the location is mocked
LocationUtil.with(context).location().state().isMockSettingEnabled();
GeofenceUtil helps in monitoring the geofences. we can define single as well as multiple geofences to monitor.
For Single Geofence
GeofenceModel janakpuri = new GeofenceModel.Builder("id_janakpuri") // this id should be unique for every GeofenceModel
.setTransition(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
.setLatitude(28.621127)
.setLongitude(77.081824)
.setRadius(2000)
.setExpiration(6000000)
.build();
GeoFenceUtil.INSTANCE.add(janakpuri).init(this).setOnGeoFenceStatusListener(new OnGeofenceStatusListener() {
@Override
public void onStatus(String id, int transitionType, Location location) {
Log.i(TAG, id + " " + transitionType);
}
});
For Multiple Geofence
GeoFenceUtil.INSTANCE.add(address1).add(address2).init(this).setOnGeoFenceStatusListener(new OnGeofenceStatusListener() {
@Override
public void onStatus(String id, int transitionType, Location location) {
Log.i(TAG, id + " " + transitionType);
}
});
GeoFenceUtil.INSTANCE.removeGeofence();
// initializes retrofit service in application class or via dependency injection (To be initialized once)
Headers.Builder builder = new Headers.Builder();
builder.add("OS", "ANDROID"); // add common headers here. Optional.
RetrofitConfigModel retrofitConfigModel = new RetrofitConfigModel.Builder()
.setBaseUrl(API_URL)
.setConnectOutTime(60)
.setReadOutTime(45)
.setLoggingEnabled(true)
.setHeaders(builder)
.build();
RetroFitSingleton.INSTANCE.setRetrofitConfig(retrofitConfigModel);
// create your own RestService class
RestService restService = RetroFitSingleton.INSTANCE.getRetrofit().create(RestService.class);
// download large files
retroFitUtil.downloadLargeFile("https://pubs.usgs.gov/dds/dds-057/ReadMe.pdf", "file name", "file extension", this);
// Multiple Image upload request generator
// Pass this requestMap to @PartMap in rest service interface.
Map<String, RequestBody> requestMap = uploadImagesRequestGenerator(fileArray, file extension, keyParam);
isOnline();
decompressZipFile(appname, fileName, password);
validateEmail(edittext);
getPath(uri, context);
hideSoftKeyboard(view)
Copyright 2016 Sanidhya Kumar
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.