-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c4286e3
Showing
37 changed files
with
1,103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Android Link Preview | ||
|
||
An Android Library with demo application, to fetch meta-data from url, like Facebook and Whatsapp .... | ||
|
||
## Installation | ||
|
||
Add it in your root build.gradle at the end of repositories: | ||
|
||
``` | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
``` | ||
Add the dependency | ||
``` | ||
dependencies { | ||
compile 'com.github.omegaes:Android-Link-Preview:1.0.0' | ||
} | ||
```` | ||
## Usage | ||
Request metadata for url, it will execute in background thread, you will get an instance from LinkPreview | ||
or an exception, keep in your mind that onSuccess, onFailed execute in background thread, use handler to access UI objects | ||
``` | ||
LinkUtil.getInstance().getLinkPreview(Context, String url,GetLinkPreviewListener) | ||
``` | ||
LinkPreview | ||
``` | ||
class LinkPreview { | ||
|
||
String title; | ||
String description; | ||
String link; | ||
String siteName; | ||
File imageFile; | ||
|
||
} | ||
``` | ||
GetLinkPreviewListener | ||
``` | ||
interface { | ||
void onSuccess(LinkPreview link); | ||
void onFailed(Exception e); | ||
} | ||
``` | ||
## Contributing | ||
1. Fork it! | ||
2. Create your feature branch: `git checkout -b my-new-feature` | ||
3. Commit your changes: `git commit -am 'Add some feature'` | ||
4. Push to the branch: `git push origin my-new-feature` | ||
5. Submit a pull request :D | ||
## History | ||
Not yet | ||
## Author | ||
* **Abdulrahman Babil** - *Software engineer* - [Mega4Tech](http://mega4tech.com) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.0" | ||
defaultConfig { | ||
applicationId "com.mega4tech.androidlinkpreview" | ||
minSdkVersion 14 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() // jcenter() works as well because it pulls from Maven Central | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:25.2.0' | ||
testCompile 'junit:junit:4.12' | ||
compile project(':linkpreview') | ||
|
||
compile 'com.github.bumptech.glide:glide:3.7.0' | ||
compile 'com.android.support:support-v4:25.2.0' | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/aboodba/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class title to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/mega4tech/androidlinkpreview/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mega4tech.androidlinkpreview; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.mega4tech.androidlinkpreview", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.mega4tech.androidlinkpreview"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
98 changes: 98 additions & 0 deletions
98
app/src/main/java/com/mega4tech/androidlinkpreview/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.mega4tech.androidlinkpreview; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
import android.widget.LinearLayout; | ||
import android.widget.ProgressBar; | ||
import android.widget.RelativeLayout; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.bumptech.glide.Glide; | ||
import com.mega4tech.linkpreview.GetLinkPreviewListener; | ||
import com.mega4tech.linkpreview.LinkPreview; | ||
import com.mega4tech.linkpreview.LinkUtil; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private LinearLayout activityMain; | ||
private EditText linkEt; | ||
private Button linkFetchBtn; | ||
private RelativeLayout previewGroup; | ||
private ImageView imgPreviewIv; | ||
private TextView titleTv; | ||
private TextView descTv; | ||
private TextView siteTv; | ||
private ProgressBar progress; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
initView(); | ||
|
||
linkFetchBtn.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
progress.setVisibility(View.VISIBLE); | ||
previewGroup.setVisibility(View.GONE); | ||
LinkUtil.getInstance().getLinkPreview(MainActivity.this, linkEt.getText().toString(), new GetLinkPreviewListener() { | ||
@Override | ||
public void onSuccess(final LinkPreview link) { | ||
|
||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
progress.setVisibility(View.GONE); | ||
previewGroup.setVisibility(View.VISIBLE); | ||
titleTv.setText(link.getTitle() != null ? link.getTitle() : "" ); | ||
|
||
descTv.setText(link.getDescription() != null ? link.getDescription() : "" ); | ||
siteTv.setText(link.getSiteName() != null ? link.getSiteName() : "" ); | ||
previewGroup.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link.getLink())); | ||
startActivity(browserIntent); | ||
} | ||
}); | ||
if(link.getImageFile() != null) | ||
Glide.with(MainActivity.this).load(link.getImageFile()).into(imgPreviewIv); | ||
else | ||
Glide.with(MainActivity.this).load(R.mipmap.ic_launcher).into(imgPreviewIv); | ||
} | ||
}); | ||
|
||
} | ||
|
||
@Override | ||
public void onFailed(Exception e) { | ||
|
||
progress.setVisibility(View.GONE); | ||
previewGroup.setVisibility(View.VISIBLE); | ||
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
private void initView() { | ||
activityMain = (LinearLayout) findViewById(R.id.activity_main); | ||
linkEt = (EditText) findViewById(R.id.link_et); | ||
linkFetchBtn = (Button) findViewById(R.id.link_fetch_btn); | ||
previewGroup = (RelativeLayout) findViewById(R.id.preview_group); | ||
imgPreviewIv = (ImageView) findViewById(R.id.img_preview_iv); | ||
titleTv = (TextView) findViewById(R.id.title_tv); | ||
descTv = (TextView) findViewById(R.id.desc_tv); | ||
siteTv = (TextView) findViewById(R.id.site_tv); | ||
progress = (ProgressBar) findViewById(R.id.progress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/activity_main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context="com.mega4tech.androidlinkpreview.MainActivity"> | ||
|
||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<EditText | ||
android:id="@+id/link_et" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1"/> | ||
|
||
<Button | ||
android:id="@+id/link_fetch_btn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Fetch"/> | ||
|
||
</LinearLayout> | ||
|
||
|
||
<RelativeLayout | ||
android:id="@+id/preview_group" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:visibility="gone"> | ||
|
||
<ImageView | ||
android:id="@+id/img_preview_iv" | ||
android:layout_width="200dp" | ||
android:layout_height="200dp" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentTop="true" | ||
android:padding="20dp"/> | ||
|
||
<TextView | ||
android:id="@+id/title_tv" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
|
||
android:layout_toRightOf="@id/img_preview_iv" | ||
android:text="ti" | ||
android:textSize="20sp"/> | ||
|
||
<TextView | ||
android:id="@+id/desc_tv" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/title_tv" | ||
android:layout_marginTop="12dp" | ||
android:layout_toRightOf="@id/img_preview_iv" | ||
android:text="desc" | ||
android:textSize="12sp"/> | ||
|
||
<TextView | ||
android:id="@+id/site_tv" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/desc_tv" | ||
android:layout_marginTop="12dp" | ||
android:layout_toRightOf="@id/img_preview_iv" | ||
android:text="desc" | ||
android:textSize="12sp"/> | ||
|
||
</RelativeLayout> | ||
|
||
|
||
<ProgressBar | ||
android:id="@+id/progress" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:visibility="gone"/> | ||
|
||
</LinearLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
Oops, something went wrong.