CropImageView


Source link: https://github.com/cesards/CropImageView

CropImageView

An ImageView that supports different kind of cropping rather than the only Android is currently supporting: centerCrop

Using this library, you can crop your desired image by sides described below:

Development idea borns at the point in [Kerad Games] we needed images cropped by somewhere no matter the image size.

The original images we had to deal with (we wanted the half size of the ball shown whatever screen size), below

Here are some screenshots what we got thanks to this widget :-)

Usage

Step 1

Gradle
dependencies {

 compile 'com.cesards.android:cropimageview:1.0.2.1' 
}
Maven
<dependency>
 <groupId>com.cesards.android</groupId>
 <artifactId>CropImageView</artifactId>
 <version>1.0.2</version>
 <type>aar</type> </dependency>

Step 2

Define in xml:

<com.cesards.cropimageview.CropImageView
 xmlns:custom="http://schemas.android.com/apk/res-auto"
 android:id="@+id/imageView1"
 android:src="@drawable/photo1"
 custom:crop="value" />

where value can take values

topLeft|centerLeft|bottomLeft|topRight|centerRight|bottomRight|centerTop|centerBottom

Or in code:

final CropImageView cropImageView = new CropImageView(CropActivity.this);
 final Resources res = getResources();
 cropImageView.setImageDrawable(res.getDrawable(images[position]));
 final CropImageView.CropType cropType = imageCrops[position]; cropImageView.setCropType(cropType);

Performance tests (using Hugo)

Center Crop Sample (ImageView)

V/TestForegroundImageView? ? setFrame(l=0, t=0, r=1080, b=1557) V/TestForegroundImageView? ? setFrame [0ms] = true V/TestForegroundImageView? ? setFrame(l=1080, t=0, r=2160, b=1557) V/TestForegroundImageView? ? setFrame [0ms] = true V/TestForegroundImageView? ? setFrame(l=0, t=0, r=1080, b=1557) V/TestForegroundImageView? ? setFrame [0ms] = false V/TestForegroundImageView? ? setFrame(l=1080, t=0, r=2160, b=1557) V/TestForegroundImageView? ? setFrame [0ms] = false V/TestForegroundImageView? ? setFrame(l=0, t=0, r=1080, b=1701) V/TestForegroundImageView? ? setFrame [0ms] = true V/TestForegroundImageView? ? setFrame(l=1080, t=0, r=2160, b=1701) V/TestForegroundImageView? ? setFrame [0ms] = true` 

Custom Crop Sample (CropImageView)

V/TestForegroundCropImageView? ? setFrame(l=0, t=0, r=1080, b=1557) V/TestForegroundCropImageView? ? setFrame [0ms] = true V/TestForegroundCropImageView? ? setFrame(l=1080, t=0, r=2160, b=1557) V/TestForegroundCropImageView? ? setFrame [0ms] = true V/TestForegroundCropImageView? ? setFrame(l=0, t=0, r=1080, b=1557) V/TestForegroundCropImageView? ? setFrame [0ms] = false V/TestForegroundCropImageView? ? setFrame(l=1080, t=0, r=2160, b=1557) V/TestForegroundCropImageView? ? setFrame [0ms] = false V/TestForegroundCropImageView? ? setFrame(l=0, t=0, r=1080, b=1701) V/TestForegroundCropImageView? ? setFrame [0ms] = true V/TestForegroundCropImageView? ? setFrame(l=1080, t=0, r=2160, b=1701) V/TestForegroundCropImageView? ? setFrame [0ms] = true 

Results: code used does not cause overhead in the UI thread.

ChangeLog

  • 1.0.2.1 (2015-10-22)
    • ImageView crashes in devices with API < 18 due to a @TargetApi annotation
  • 1.0.2 (2015-10-22)
    • Changed minSdkVersion to 7
    • Solved a bug related with ImageView and API < 18.
  • 1.0.1 (2015-02-17)
    • Changed Samples UI and removed unused resources.
    • Added performance tests to Samples.
    • Added code styles for contributions.
    • Improved CropImageView widget. Removed onLayout() overhead. ImageView onLayout() is empty, so we only need logic in setFrame() method.
  • 1.0.0 (2015-02-15)
    • Initial release. ( minSdkVersion="14").

Developed By

Who's using it

Do you want to contribute?

I'm pretty sure you there are some awesome hidden features you need in your daily dev life. Just let me know or collaborate to improve this librar

I'd like to improve this library with your help, there are some new features to implement waiting for you ;)

If you want to contribute, you should use my code styles available in the root of the project!


License

The MIT License (MIT)

Copyright (c) 2016 César Díez Sánchez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Resources

An Android Parallax ListView item (this effect inspired by sound cloud android app).

Android comes with a few "wrapper" classes, like CursorWrapper, that make it relatively easy for you to add just a bit of functionality to an existing object. The wrapper delegates all behaviors to the wrapped object; you just override the specific behaviors you need. This works well in cases where there are many possible underlying implementations, so you could not robustly accomplish these ends by subclassing.

Android lacks such a wrapper for ListAdapter, though. There is a WrappedListAdapter entry in the SDK, but it is an interface, not an implementation.

So, CWAC offers an AdapterWrapper to fill this void.

Sometimes, you want your users to pick a color. A simple approach is to give the user a fixed roster of a handful of colors -- easy, but limited. A fancy approach is to use some form of color wheel, but these can be difficult to use on a touchscreen and perhaps impossible without a touchscreen.

ColorMixer is a widget that provides a simple set of SeekBars to let the user mix red, green, and blue to pick an arbitrary color. It is not very big, so it is easy to fit on a form, and it is still fairly finger-friendly.

It is also packaged as a dialog (ColorMixerDialog), a dialog-themed activity (ColorMixerActivity), and a preference (ColorPreference).

This project has a handful of Android containers (ViewGroup implementations) designed to handle specific scenarios:

  • AspectLockedFrameLayout that resizes itself, and its children, to fit within a specific aspect ratio
  • MirroringFrameLayout and an associated Mirror that duplicates and scales the contents of the MirroringFrameLayout onto the Mirror

Android BounceProgressBar Widget.

Library for handling Kiosk Mode in your Android Application. It restricts device to be using only one activity without possibility to switch to other app.

Features:

  • Run activity of you choice in kiosk mode
  • Blocks every application from going into foreground with activity manager
  • Handles home button by being a Launcher App

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes