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.

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.