It makes a preview from an url, grabbing all the information such as title, relevant texts and images. This a version for Android of my web link preview https://github.com/LeonardoCardoso/Link-Preview

Overview

LeoCardz Link Preview for Android

Android Arsenal

It makes a preview from an url, grabbing all the information such as title, relevant texts and images.

Visual Examples

Preview

Sample App

For a sample app, please install it from Android Link Preview on Google Play.

Requirements

  • jsoup is a smart lib to get the html code.

Installation

gradle

Simply add the repository to your build.gradle file:

repositories {
	jcenter()
	maven { url 'https://github.com/leonardocardoso/mvn-repo/raw/master/maven-deploy' }
}

And you can use the artifacts like this:

dependencies {
    compile 'org.jsoup:jsoup:1.8.3' // required
	compile 'com.leocardz:link-preview:2.0.0@aar'
	// ...
}

ProGuard

If you use ProGuard, it is advised that you keep the jsoup dependencies by adding

-keeppackagenames org.jsoup.nodes

to your ProGuard rules file.

Usage

Instantiating

import com.leocardz.link.preview.library.TextCrawler;
// ...
// Create an instance of the TextCrawler to parse your url into a preview.
TextCrawler textCrawler = new TextCrawler();

// ..

// Create the callbacks to handle pre and post exicution of the preview generation.
LinkPreviewCallback linkPreviewCallback = new LinkPreviewCallback() {
    @Override
    public void onPre() {
        // Any work that needs to be done before generating the preview. Usually inflate 
        // your custom preview layout here.
    }

    @Override
    public void onPos(SourceContent sourceContent, boolean b) {
        // Populate your preview layout with the results of sourceContent.
    }
};

Generate Preview

textCrawler.makePreview( linkPreviewCallback, url);

Cancel unfinished tasks when views are destroied.

If you are using Android Link Preview inside of an Activity, it is important to cancel unfinished Preview activites at the end of the Activity's lifecycle.

 @Override
    protected void onDestroy() {
        super.onDestroy();
        textCrawler.cancel();
    }

Apps using Android Link Preview

  1. Unshorten It

  2. ...

Information and Contact

Developed by @LeonardoCardoso.

Contact me either by Twitter @leocardz or emailing me to [email protected].

Related Projects

License

Copyright 2013 Leonardo Cardoso

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

   http://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.
Comments
  • Cancelable AsyncTask

    Cancelable AsyncTask

    This allows for the developer to cancel a TextCrawler's task. This allows for better usage inside of a list view as well as preventing Activity lifecycle related crashes.

    opened by aleedy 6
  • Add ability for library users to specify how to extract URLs from the…

    Add ability for library users to specify how to extract URLs from the…

    … passed text

    I updated TextCrawler to allow users of the library to specify how they want to pull URLs from the passed in text. Users who choose not to do this still get the old behavior by default. I added a few tests and the Mockito library to support better tests in the future. I also added some performance enhancements in the form of eliminating unnecessary string creation/manipulation.

    opened by jdonmoyer 1
  • Add ability for library user to change how the library retrieves images

    Add ability for library user to change how the library retrieves images

    This PR consists of two commits.

    The first updates the project so that it can be built with the latest version of Android Studio and updates the JSoup version.

    The second commit adds the notion of an 'ImagePickingStrategy' this gives the library user the capability of overriding the default logic that is used in determining which images are returned by the crawling process. This commit also has some optimizations in image picking and some scoping changes to make modifying the library in the future without negatively impacting backwards compatibility. Tests were provided for the new functionality.

    opened by jdonmoyer 1
  • Handle catastrophic JSoup errors

    Handle catastrophic JSoup errors

    • Add the Internet permission at the library level since any user of the library will need it
    • Add the Google maven repository so that the Android testing libraries can be pulled down
    • Bump the minSdkVersion so that the Google testing library can be used
    • Add the Android Testing library and JUnit
    • Refactor some methods in TextCrawler to facilitate testing
    • Add a test for TextCrawler to replicate what occurs when JSoup has a catastrophic error
    opened by jdonmoyer 1
  • Updating jsoup

    Updating jsoup

    My users were seeing some NullPointerExceptions originating from the jsoup library. Looking at the issues list for jsoup, several issues have been resolved in 1.10.3 so I updated Link-Preview to use that instead.

    opened by aleedy 1
  • README update with usage details

    README update with usage details

    I recently started using your library in a project of mine. Thanks for putting it out there, it definitely does the trick. I felt like the docs were severely lacking with implementation details so I added some updates and tried to stick to the format you use on the swift version.
    Hope you find it helpful.

    opened by aleedy 1
  • Tiny Improvements on Methods - TextCrawler class

    Tiny Improvements on Methods - TextCrawler class

    a. On the for loops, we can improve them by getting the termination condition once. In the loops edited, they (termination conditions) were constantly being called every time the loop ended.

    b. On the boolean methods, we can just return the value of the statements instead of asking for their value first and then returning the value.

    opened by wching 1
  • Enhancements to image resolution capabilities

    Enhancements to image resolution capabilities

    Currently sharing an image URL that does not end in a file extension (e.g. https://cdn.shopify.com/s/files/1/1400/5075/files/website_logo2_720x_6cdc3363-fec0-4d60-a5bd-5236869352bf_720x.png?v=1533741874) results in a failed preview rather than pulling back the correct image.

    This occurs because these URLs do not match the regex used in isImage(). This results in an attempt by JSoup to process the image as an HTML document which results in an exception due to a check on the response mime type. I added code to detect this error and process the url as if it were an image if the returned mimetype is an image.

    I also updated the project to work with the newest Android Studio version and refactored DefaultImagePickingStrategy so that subclasses of BaseImagePickingStrategy can reuse the code for getting the image url from the meta tags and/or from scraping the HTML document.

    The sample app was also updated to refer to the library project rather than pull the release artifact.

    opened by jdonmoyer 0
  • ReadMe updates to include cancellation and pro guard settings

    ReadMe updates to include cancellation and pro guard settings

    Updating docs to reference the new cancel() method of the text crawler. Also adding references for necessary ProGuard settings for users that may have minify enabled in their apps.

    opened by aleedy 0
  • Bug fix for wrong URL redirection on click.

    Bug fix for wrong URL redirection on click.

    Commit: "Bug fix for wrong URL redirection on click."

    This is the fix for the bug of wrong URL opening while clicking the previews. I have checked it multiple times and its working 100%.

    opened by srujanb 0
  • Meta Tag Handling Improvements

    Meta Tag Handling Improvements

    • Add performance improvement to only convert meta tag match to lowercase once in the for loop
    • Add an updateMetaTag method that will only store the meta tag value if it is non-null and non-empty; This fixed issues where bad descriptions were being pulled in cases where multiple 'description' meta tags were found and the last one had no value. See www.fandango.com for an example case where this occurs.
    opened by jdonmoyer 0
  • Deprecate AsyncTask. Add RxJava variant of TextCrawler.makePreview()

    Deprecate AsyncTask. Add RxJava variant of TextCrawler.makePreview()

    Type of change

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • Add RxJava variant of makePreview() to TextCrawler
    • [x] Refactor
    • Move crawler network call and parsing logic to an abstraction
    • Move async task implementation to a separate class
    • [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • TextCrawler.extendedTrim(String) requires reference via TextCrawler.Companion.extendedTrim(String), when called from Java.
    • [x] This change requires a documentation update

    Checklist:

    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] My changes generate no new warnings
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing unit tests pass locally with my changes
    • [x] Any dependent changes have been merged and published in downstream modules
    opened by dhruvnagarajan 0
Releases(1.1)
Owner
Leonardo Cardoso
Leonardo Cardoso
This application will provide information about almost all currently plugged-in USB devices.

USB Device Info Android 3.1 introduced USB host mode which allows the user to plug USB devices to your Android tablet in the same way as a Desktop PC

Alexandros Schillings 153 Nov 18, 2022
Automated-build-android-app-with-github-action - CI/CD Automated Build Android App Bundle / APK / Signed With Github Action

Automated Build Android With Using Github Action Project Github Action Script Us

Faisal Amir 34 Dec 19, 2022
Library that makes it possible to read, edit and write CSV files

AdaptiveTableLayout Welcome the new CSV Library AdaptiveTableLayout for Android by Cleveroad Pay your attention to our new library that makes it possi

Cleveroad 1.9k Jan 6, 2023
Tool for create complex morphing animations using VectorDrawables (allows morphing between any pair of SVG images)

VectAlign VectAlign (a.k.a. VectorDrawableAlign) is a developer's tool which automagically aligns two VectorDrawable "pathData" strings (or SVG images

Stefano Bonetta 2k Dec 29, 2022
Android Resource Manager application to manage and analysis your app resources with many features like image resize, Color, Dimens and code Analysis

Android Resource Manager application to manage and analysis your app resources with many features like image resize, Color, Dimens and code Analysis

Amr Hesham 26 Nov 16, 2022
A tool to install components of the Android SDK into a Maven repository or repository manager to use with the Android Maven Plugin, Gradle and other tools.

Maven Android SDK Deployer Original author including numerous fixes and changes: Manfred Moser [email protected] at simpligility technologies i

simpligility 1.4k Dec 27, 2022
A tool to install components of the Android SDK into a Maven repository or repository manager to use with the Android Maven Plugin, Gradle and other tools.

Maven Android SDK Deployer Original author including numerous fixes and changes: Manfred Moser [email protected] at simpligility technologies i

simpligility 1.4k Dec 27, 2022
Simple library to generate and view PDF in Android

PDFCreatorAndroid Simple library to generate and view PDF in Android A simple library to create and view PDF with zero dependency Or native code. Add

Tej Pratap Singh 234 Dec 11, 2022
Android Material Design Theme UI and Tool Library. Support: 4.0.3~O

GitHub OSChina 中文 English Genius-Android Genius-Android: by Material Design style and some commonly used packages. Starting in 2015, The divided into

Qiujuer 2.3k Dec 27, 2022
Analytics Tools for Kotlin Multiplatform Mobile iOS and android

Index Features Example Introduce Architecture Installation Configure Using Screen Mapper Initialization Implementation Delegate Parameters ATEventPara

LINE 16 Dec 5, 2022
Android USB host serial driver library for CDC, FTDI, Arduino and other devices.

usb-serial-for-android This is a driver library for communication with Arduinos and other USB serial hardware on Android, using the Android USB Host M

mike w 3.8k Dec 30, 2022
Modulearchive - Improve the efficiency of compiling Android.Package module as AAR and cache it

ModuleArchive 一个可以提升Android编译效率的Gradle小插件 在多module工程下,大多数情况我们若干子module是不会变动的 但是在当前gradle版本偶尔会触发联动编译进而影响编译效率。 本插件会自动缓存编译后的子模块生产物(xxx.aar),且会自动替换依赖为aar依

JackFan 3 Feb 11, 2022
A library which will save you a lot of time from writing the same intent creation code. it consist of many intent creation codes like Share, Contacts, Email and etc, which you can easily use.

Android-Intent-Library A library which will save you a lot of time from writing the same intent creation code. it consist of many intent creation code

Next 67 Aug 24, 2022
Enhance the adb shell using busybox, supporting vi、grep and awk etc. No need root.

super-adb 用busybox加持的功能更加强大的adb shell;不需要root。 使用方法 准备工作 安装 python,注意选择安装python 2.x 安装pexpect这个python库: pip install pexpect 下载super_adb,把它放到系统路径 cp su

weishu 273 Dec 7, 2022
Taskbar puts a start menu and recent apps tray on top of your screen that's accessible at any time

Taskbar puts a start menu and recent apps tray on top of your screen that's accessible at any time, increasing your productivity and turning your Andr

Braden Farmer 551 Dec 31, 2022
An easy to use translation / localization api written in Kotlin that can be used with Java and Kotlin

KTranslate KTranslate is an easy to use TranslationAPI written in Kotlin, with currently 26 supported languages. It is very easy to use in Kotlin and

Felix Beinssen 0 Sep 2, 2022