There are 4 libraries in this project: Starter, Drag-Exit, Permission, Picker, SAFR
This is a quick start package, including BaseActivity, BaseFragment and utils classes;
implementation 'com.github.boybeak:starter:x.y.z'
package | class | description |
---|---|---|
activity | BaseActivity,BaseDragExitActivity,DataBindingActivity,DataBindingToolbarActivity,DragExitToolbarActivity, SrlRvActivity, ToolbarActivity,ToolbarViewPagerActivity | Some basic activities |
adapter | DataBindingAdapter,FooterAdapter,BaseLayoutImpl,AbsDataBindingHolder, DataChange | Only some main class a presented |
broadcast | AbsReceiver, BroadcastUtils | Add isRegistered state in AbsReceiver.Use this with BroadcastUtils |
fragment | BaseFragment, BaseDialogFragment, BaseBottomDialogFragment, RefreshListFragment, PaginationFragment | |
mvc | It's not too useful | |
retrofit | SimpleCallback, SimpleListCallback, SafeCallback, SafeListCallback | Some quick retrofit callback |
utils | AssetUtil, Connectivity, FileUtil, ImeUtil | Some useful utils |
widget | BottomHideBehavior, Chip, EmptyView, OnScrollBottomListener, PagerStateAdapter, ProgressBar, RatioCardView, RatioImageView,RatioViewPager, SearchBar, SimpleViewPagerFragmentAdapter | |
Others | CrashHandler, GetNothingImpl, ILife, Intents, Memory, Router, SafeHandler |
implementation 'com.github.boybeak:drag-exit:x.y.z'
There's only one FrameLayout's sub class DragExitLayout. Use the layout like this:
<?xml version="1.0" encoding="utf-8"?>
<com.github.boybeak.de.DragExitLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drag_exit_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:lazy="0.25"
app:stuckEffect="true"
app:activeEdges="left">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</WebView>
</com.github.boybeak.de.DragExitLayout>
class DragExitActivity : AppCompatActivity() {
private val dragListener = object : DragExitLayout.OnExitListener {
override fun onExit() {
finish()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
super.setContentView(R.layout.activity_drag_exit)
drag_exit_layout.setOnExitListener(dragListener)
web_view.webViewClient = WebViewClient()
web_view.webChromeClient = WebChromeClient()
web_view.loadUrl("https://github.com/boybeak/Starter")
}
}
Some attributes as below:
- activeEdges - enum: 3 values are available, left, right and both, which edge can active the drag gesture.
- exitLineRatio - float: Available values in range (0, 1), the exit action trigger ratio of layout width.
- stuckEffect - boolean: Whether should the child view stuck at exitLineRation position or not.
- lazy - float: Available values in range (0, 1). If set to 0.5, your finger move 100 pixels, the child view actually move 50 pixels.
- alphaEffect - boolean: Whether the child view change its alpha when moving.
- alphaMin - float: The minimum value of the child view can be. Once the child view moves to exitLineRation position, the alpha will be alphaMin.
- scaleEffect - boolean, same as alphaEffect
- scaleMin - float: same as alphaMin
More about exitLineRatio see the image below:
If set exitLineRation to 0.25.
Don't forget use a transparent theme to your activity if you want a drag-exit activity. Or you can use BaseDragExitActivity or DragExitToolbarActivity in the Starter library.
This is a permission helper. Quickly grant permissions.
implementation 'com.github.boybeak:permission:x.y.z'
PH.ask(Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO).go(this, object : Callback {
override fun onGranted(permissions: MutableList<String>) {
//TODO do what you want
}
override fun onDenied(permission: String) {
//TODO do what you want
}
})
PH is short for Permission Helper.
A helper library for getting images and videos quickly.
implementation 'com.github.boybeak:picker:x.y.z'
// Get multiple images from gallery
Picker.gallery().image().multiple(true)
.go(this@PickerActivity, object : MultipleCallback {
override fun onGet(id: String, uris: MutableList<Uri>, files: MutableList<File>) {
adapter!!.addAll(files, Converter<File, FileImpl> { data, _ -> FileImpl(data) }).autoNotify()
}
override fun onCancel(id: String) {
}
})
// Get one image from camera
val dir = File(externalCacheDir, "images")
if (!dir.exists()) {
dir.mkdirs()
}
val cameraTempFile = File(dir, System.currentTimeMillis().toString() + ".jpg")
val uri = FileProvider.getUriForFile(this@PickerActivity, "$packageName.provider", cameraTempFile)
Picker.camera().image().output(uri, cameraTempFile)
.go(this@PickerActivity, object : SingleCallback {
override fun onGet(id: String, uri: Uri, file: File) {
adapter!!.add(FileImpl(file)).autoNotify()
}
override fun onCancel(id: String) {
}
})
With this library, you can get images easily from gallery and camera. Support getting multiple images and videos from gallery, and getting one image or video from camera.
implementation 'com.github.boybeak:safr:x.y.z'
SAFR is short for startActivityForResult.
SAFR.newInstance().extras {
//fill data here
}.byAction(Intent.ACTION_GET_CONTENT)
.startActivityForResult(this, 100, object : Callback {
override fun onResult(requestCode: Int, resultCode: Int, data: Intent?) {
}
})