Code Monkey home page Code Monkey logo

swipedismissimage's Introduction

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.

swipedismissimage's People

Contributors

kaustubhpatange avatar

Stargazers

Abd Nezar avatar beprogressive avatar Rikard Teodorsson avatar Alex avatar Nisarg avatar Raghunandan Kavi avatar Pranav Lathigara avatar Erik Teel avatar Taras Okunev avatar Steve Ray avatar Vlad Korzun avatar  avatar Alexander Medvedev avatar Alexey Egin avatar Denis Balchugov avatar Yersultan Utemissov  avatar Roman avatar feodott avatar Elyseev Vladimir avatar HudZah avatar  avatar Oliver Fox avatar KSaid avatar Caner Gülgeç avatar ysf.cyln avatar Ogulcan avatar İbrahim Süren avatar  avatar Josip Parać avatar Alessandro Valenza avatar Dave avatar Mete Soydaş avatar Tito Moyela avatar Sebastian Schäf avatar

Watchers

James Cloos avatar Roman avatar  avatar  avatar

Forkers

kdsaid

swipedismissimage's Issues

Tap listener

Would it be possible to add a single tap listener (like the setSwipeDismissListener(...))? Like adding finish() when the user taps on the image.
It is a bit annoying to have to zoom out before being able to swipe it away :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.