Android Rich Link Preview
Android library is being more popular as it provides so much for developers to work freely on a thing rather than having to build everything. We have again come up with a useful android library for your android application.
Rich Link Preview library, the library provides a function to display a preview of the URL before having to open the actual URL. These short description or link preview comes a lot in handy as it attracts more users toward the link. The java library aims to reduce the burden and makes it easy to implement the link preview feature in your application.
The library has been developed fully using Java. The RichLink-Preview comes in handy when it comes to displaying articles, news or promotes applications inside your android application.
Sample
You can rely on the snapshot provided below on how the default layout for the RichLink-Preview id is made and on how the preview is being displayed inside the application.
Usage
Without wasting your time, let us provide you with the usage method:
Import using Gradle
compile 'io.github.ponnamkarthik:richlinkpreview:1.0.9'
implementation 'io.github.ponnamkarthik:richlinkpreview:1.0.9'
To implement existing layout using XML
The following code below will guide you to implement existing layout with the use of XML
For that, you will have to 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>
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
Instead of having the default layout, you can also implement the layout of your preference using the code below:
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 metadata to view:
richLinkView.setLinkFromMeta(metaData)
or
MetaData metaData = new MetaData();
metaData.setTitle("Title");
metaData.setDescription("Custom Meta Data");
metaData.setFavicon("http://favicon url");
metaData.setImageurl("http://image url");
metaData.setSitename("Custom Meta data site");
richLinkView.setLinkFromMeta(metaData);
As per your requirement/preference you are also able to set your own ClickListener. Just follow the code below:
//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();