Skip to content

Commit 797d95e

Browse files
committed
Add Load Image from URL Project files
1 parent 7398423 commit 797d95e

File tree

34 files changed

+705
-0
lines changed

34 files changed

+705
-0
lines changed

LoadImageURL/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

LoadImageURL/.idea/compiler.xml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoadImageURL/.idea/copyright/profiles_settings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoadImageURL/.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoadImageURL/.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoadImageURL/.idea/misc.xml

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoadImageURL/.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoadImageURL/.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoadImageURL/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

LoadImageURL/app/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 24
5+
buildToolsVersion "24.0.3"
6+
defaultConfig {
7+
applicationId "com.learn2crack.loadimageurl"
8+
minSdkVersion 19
9+
targetSdkVersion 24
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:24.2.1'
28+
testCompile 'junit:junit:4.12'
29+
}

LoadImageURL/app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/rajamalw/android-sdk-linux/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.learn2crack.loadimageurl;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.learn2crack.loadimageurl", appContext.getPackageName());
25+
}
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.learn2crack.loadimageurl">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.learn2crack.loadimageurl;
2+
3+
import android.graphics.Bitmap;
4+
import android.graphics.BitmapFactory;
5+
import android.os.AsyncTask;
6+
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.net.URL;
10+
11+
public class LoadImageTask extends AsyncTask<String, Void, Bitmap> {
12+
13+
public LoadImageTask(Listener listener) {
14+
15+
mListener = listener;
16+
}
17+
18+
public interface Listener{
19+
20+
void onImageLoaded(Bitmap bitmap);
21+
void onError();
22+
}
23+
24+
private Listener mListener;
25+
@Override
26+
protected Bitmap doInBackground(String... args) {
27+
28+
try {
29+
30+
return BitmapFactory.decodeStream((InputStream)new URL(args[0]).getContent());
31+
32+
} catch (IOException e) {
33+
e.printStackTrace();
34+
}
35+
return null;
36+
}
37+
38+
@Override
39+
protected void onPostExecute(Bitmap bitmap) {
40+
41+
if (bitmap != null) {
42+
43+
mListener.onImageLoaded(bitmap);
44+
45+
} else {
46+
47+
mListener.onError();
48+
}
49+
}
50+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.learn2crack.loadimageurl;
2+
3+
import android.graphics.Bitmap;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.Button;
8+
import android.widget.ImageView;
9+
import android.widget.Toast;
10+
11+
public class MainActivity extends AppCompatActivity implements View.OnClickListener, LoadImageTask.Listener {
12+
13+
private ImageView mImageView;
14+
private Button mBtLoadImage;
15+
16+
public static final String IMAGE_URL = "https://api.learn2crack.com/android/images/donut.png";
17+
18+
@Override
19+
protected void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
setContentView(R.layout.activity_main);
22+
23+
mImageView = (ImageView) findViewById(R.id.image);
24+
mBtLoadImage = (Button) findViewById(R.id.btn_load_image);
25+
mBtLoadImage.setOnClickListener(this);
26+
}
27+
28+
@Override
29+
public void onClick(View view) {
30+
switch (view.getId()) {
31+
32+
case R.id.btn_load_image:
33+
new LoadImageTask(this).execute(IMAGE_URL);
34+
break;
35+
}
36+
}
37+
38+
@Override
39+
public void onImageLoaded(Bitmap bitmap) {
40+
41+
mImageView.setImageBitmap(bitmap);
42+
}
43+
44+
@Override
45+
public void onError() {
46+
Toast.makeText(this, "Error Loading Image !", Toast.LENGTH_SHORT).show();
47+
}
48+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/activity_main"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:paddingBottom="@dimen/activity_vertical_margin"
8+
android:paddingLeft="@dimen/activity_horizontal_margin"
9+
android:paddingRight="@dimen/activity_horizontal_margin"
10+
android:paddingTop="@dimen/activity_vertical_margin"
11+
tools:context="com.learn2crack.loadimageurl.MainActivity">
12+
13+
<Button
14+
android:id="@+id/btn_load_image"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:text="Load Image"
18+
android:layout_centerHorizontal="true"
19+
style="@style/Widget.AppCompat.Button.Colored"/>
20+
21+
<ImageView
22+
android:id="@+id/image"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:layout_below="@id/btn_load_image"/>
26+
</RelativeLayout>
Loading
Loading
Loading
Loading
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
3+
(such as screen margins) for screens with more than 820dp of available width. This
4+
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
5+
<dimen name="activity_horizontal_margin">64dp</dimen>
6+
</resources>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>

0 commit comments

Comments
 (0)