Skip to content

Commit

Permalink
Merge pull request #2 from AlinaStepanova/feature/load-url
Browse files Browse the repository at this point in the history
load image from url with a help of picasso
  • Loading branch information
graphicstone authored Oct 13, 2020
2 parents 8aa84df + dabee12 commit 562a6d6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src/main/java/com/nullbyte/userinfoview/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val userInfoView: UserInfoView = findViewById(R.id.info)
userInfoView.loadImageFromUrl("https://i.dlpng.com/static/png/6750061_preview.png")
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:context=".MainActivity">

<com.nullbyte.userinfoview.UserInfoView
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:backgroundColor="@color/colorGrey"
Expand Down
6 changes: 6 additions & 0 deletions userinfoview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ dependencies {
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//picasso
implementation('com.squareup.picasso:picasso:2.71828', {
exclude group: 'com.android.support', module: 'exifinterface'
})
implementation 'jp.wasabeef:picasso-transformations:2.2.1'
}
2 changes: 2 additions & 0 deletions userinfoview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nullbyte.userinfoview">

<uses-permission android:name="android.permission.INTERNET" />

<application>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.view.View
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.user_info_view_layout.view.*

class UserInfoView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
Expand Down Expand Up @@ -53,4 +55,14 @@ class UserInfoView @JvmOverloads constructor(context: Context, attrs: AttributeS
typedArray.recycle()
}
}

fun loadImageFromUrl(url: String) {
val avatarSize = 80
Picasso.get()
.load(url)
.transform(RoundedCornersTransformation(avatarSize, 0))
.resize(avatarSize, avatarSize)
.centerCrop()
.into(iv_avatar)
}
}

0 comments on commit 562a6d6

Please sign in to comment.