RichLinkPreview

Additional

Language
Java
Version
N/A
Created
Jan 16, 2018
Updated
Mar 5, 2018
Owner
Karthik Ponnam (PonnamKarthik)
Contributor
Karthik Ponnam (PonnamKarthik)
1
Activity
Badge
Generate
Download
Source code
APK file

Advertising

RichLink-Preview

A Rich Link Preview Library for Android

Sample Image

Import using Gradle

compile 'io.github.ponnamkarthik:richlinkpreview:1.0.8'

for android studio 3.x

implementation 'io.github.ponnamkarthik:richlinkpreview:1.0.8'

To implement existing layout using XML

Add below code in activity_main.xml

<!--default view or whatsapp -->
<io.github.ponnamkarthik.richlinkpreview.RichLinkView
    android:id="@+id/richLinkView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkView>
<!-- Telegram -->
<io.github.ponnamkarthik.richlinkpreview.RichLinkViewTelegram
    android:id="@+id/richLinkView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkViewTelegram>
<!-- Skype -->
<io.github.ponnamkarthik.richlinkpreview.RichLinkViewSkype
    android:id="@+id/richLinkView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkViewSkype>
<!-- Twitter -->
<io.github.ponnamkarthik.richlinkpreview.RichLinkViewTwitter
    android:id="@+id/richLinkView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkViewTwitter>

In your MainActivity.java add below code

public class MainActivity extends AppCompatActivity {
    
    RichLinkView richLinkView; 
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // ...
        // 
        richLinkView = (RichLinkView) findViewById(R.id.richLinkView);
        
        
        
        richLinkView.setLink("https://stackoverflow.com", new ViewListener() {
            
            @Override
            public void onSuccess(boolean status) {
                
            }
            
            @Override
            public void onError(Exception e) {
                
            }
        });
        
    }
}
RichLinkView richLinkView;
RichLinkViewTelegram richLinkViewTelegram;
RichLinkViewSkype richLinkViewSkype;
RichLinkViewTwitter richLinkViewTwitter;

//Set Link is same as default

OR

If you want to implement your own layout.

private MetaData data;

RichPreview richPreview = new RichPreview(new ResponseListener() {
    @Override
    public void onData(MetaData metaData) {
        data = metaData;
       
        //Implement your Layout
    }
    
    @Override
    public void onError(Exception e) {
        //handle error
    }
});

if you want to set obtained meta data to view

richLinkView.setLinkFromMeta(metaData)

Set your own CickListener

//at first disable default click
richLinkView.setDefaultClickListener(false);

//set your own click listener
richLinkView.setClickListener(new RichLinkListener() {
    @Override
    public void onClicked(View view, MetaData meta) {
        //do stuff
        Toast.makeText(getApplicationContext(), meta.getTitle(), Toast.LENGTH_SHORT).show();
    }
});

MetaData

metaData.getTitle();

metaData.getImageurl();

metaData.getDescription();

metaData.getSitename();

metaData.getUrl();

metaData.getMediatype();