All Projects → KaustubhPatange → SwipeDismissImage

KaustubhPatange / SwipeDismissImage

Licence: Apache-2.0 license
A component for Android to display image on a view with features like swipe to dismiss, zooming, panning, etc.

Programming Languages

kotlin
9241 projects

SwipeDismissImage

build Maven Central

A custom view for Android to display image with features like swipe to dismiss, zooming, pinning, etc.

Q. Why I made this?

TL;DR... It all started when I got curious how gestures (specifically dragging) are implementated. Looking at the source code of some libraries which responds to such touch events, I was keen that I had to make something to learn/practice ;)

So I started making an activity which shows an image with various features despite not unique, (considering various alternatives) but I had to learn it. So anyways, after it become solid (IMO) I made it as a library. There are still some improvements needed which I'll keep on working as I improve my knowledge.

Usage

You can check out the sample which show this usage in action, along with some more advance usage as well.

A short summary on how-to use,

  • Create an activity with the following layout as the contentView.
<com.kpstv.dismiss.image.SwipeDismissImageLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sdl_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    ...
</com.kpstv.dismiss.image.SwipeDismissImageLayout>
class ImageActivity : AppCompatActivity() {
   override fun onCreate(...) {
      ...
      sdl_layout.setSwipeDismissListener { finish() }
   }
}
  • Delcare a translucent NoActionBar theme for that activity. Make sure to set this theme for the activity.
<style name="Theme.Translucent" parent="...">
   <item name="android:windowBackground">@android:color/transparent</item>
   <item name="android:windowIsTranslucent">true</item>
   <item name="android:colorBackgroundCacheHint">@null</item>
   <item name="android:statusBarColor" tools:targetApi="l">@android:color/transparent</item>
</style>
  • Finally start the activity and get reference to SwipeDismissImageLayout from which you can get ImageView using getRootImageView() function.
Attributes
app:swipeDismissEnabled Sets if swipe to dismiss action is enabled or not, default true.
app:affectOpacity Sets if by translation it should produce a fade/alpha effect, default true.
app:swipeOffsetDistance Sets the offset distance which when crossed will invoke SwipeDistanceListener, default 1/3 * screenHeight.
android:drawable Sets a drawable on the ImageView.
app:rootBackground Sets the default background color of the layout, default android.R.color.black.
app:imageTransitionName Can be used for shared element transition (see sample).

Download

Library is available at MavenCentral().

implementation 'io.github.kaustubhpatange:swipe-dismiss-image:<version>'

License

Copyright 2020 Kaustubh Patange

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

   https://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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].