Skip to content

Commit 86c7ff0

Browse files
committed
demo app
1 parent ec34cd8 commit 86c7ff0

30 files changed

+452
-130
lines changed
Binary file not shown.
Binary file not shown.
4.35 KB
Binary file not shown.
0 Bytes
Binary file not shown.
646 Bytes
Binary file not shown.
1.25 MB
Binary file not shown.
31.8 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
33.3 KB
Binary file not shown.

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/codeStyles/codeStyleConfig.xml

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Gradle__com_android_support_exifinterface_27_1_0_aar.xml

-12
This file was deleted.

.idea/libraries/Gradle__com_android_support_support_annotations_27_1_0_jar.xml

-11
This file was deleted.

.idea/libraries/Gradle__com_squareup_picasso_picasso_2_71828_aar.xml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app.iml

+29-4
Large diffs are not rendered by default.

app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ dependencies {
2828
implementation 'androidx.appcompat:appcompat:1.0.2'
2929
implementation 'androidx.core:core-ktx:1.0.2'
3030
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31+
implementation 'com.android.support:appcompat-v7:28.0.0'
32+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
3133
testImplementation 'junit:junit:4.12'
3234
androidTestImplementation 'androidx.test:runner:1.1.1'
3335
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

app/src/main/AndroidManifest.xml

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.imagekit.android">
3+
package="com.imagekit.android">
44

55
<application
6-
android:allowBackup="true"
7-
android:icon="@mipmap/ic_launcher"
8-
android:label="@string/app_name"
9-
android:roundIcon="@mipmap/ic_launcher_round"
10-
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
12+
<activity android:name=".UploadImageActivity"></activity>
13+
<activity android:name=".FetchImageActivity"></activity>
1214
<activity android:name=".MainActivity">
1315
<intent-filter>
14-
<action android:name="android.intent.action.MAIN"/>
16+
<action android:name="android.intent.action.MAIN" />
1517

16-
<category android:name="android.intent.category.LAUNCHER"/>
18+
<category android:name="android.intent.category.LAUNCHER" />
1719
</intent-filter>
1820
</activity>
1921
</application>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.imagekit.android
2+
3+
object Constants {
4+
val CLIENT_PUBLIC_KEY = "amJ0i84qqCLLbOl25vqSozezhuc="
5+
val IMAGEKIT_ID = "bowstring"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.imagekit.android
2+
3+
import android.os.Bundle
4+
import android.view.View
5+
import androidx.appcompat.app.AppCompatActivity
6+
import com.imagekit.android.entity.CropMode
7+
import com.squareup.picasso.Picasso
8+
import kotlinx.android.synthetic.main.activity_fetch_image.*
9+
10+
class FetchImageActivity : AppCompatActivity(), View.OnClickListener {
11+
12+
override fun onCreate(savedInstanceState: Bundle?) {
13+
super.onCreate(savedInstanceState)
14+
setContentView(R.layout.activity_fetch_image)
15+
16+
btTran1.setOnClickListener(this)
17+
btTran2.setOnClickListener(this)
18+
btTran3.setOnClickListener(this)
19+
btTran4.setOnClickListener(this)
20+
btTran5.setOnClickListener(this)
21+
}
22+
23+
override fun onClick(v: View?) {
24+
showImage(when (v!!.id) {
25+
R.id.btTran1 -> {
26+
//https://ik.imagekit.io/demo/img/plant.jpeg?tr=w-300,h-200,cm-pad_resize,bg-F3F3F3
27+
ImagekitUrlConstructor(this, "https://ik.imagekit.io/demo/img", "plant.jpeg")
28+
.width(300f)
29+
.height(200f)
30+
.cropMode(CropMode.PAD_RESIZE)
31+
.backgroundHexColor("F3F3F3")
32+
.create()
33+
}
34+
R.id.btTran2 -> {
35+
//https://ik.imagekit.io/demo/img/tr:h-400,ar-3-2/default-image.jpg
36+
ImagekitUrlConstructor(this, "https://ik.imagekit.io/demo/img", "default-image.jpg")
37+
.height(400f)
38+
.aspectRatio(3, 2)
39+
.create()
40+
}
41+
R.id.btTran3 -> {
42+
//https://ik.imagekit.io/demo/tr:oi-logo-white_SJwqB4Nfe.png,ox-10,oy-20/medium_cafe_B1iTdD0C.jpg
43+
ImagekitUrlConstructor(this, "https://ik.imagekit.io/demo", "medium_cafe_B1iTdD0C.jpg")
44+
.overlayImage("logo-white_SJwqB4Nfe.png")
45+
.overlayPosX(10)
46+
.overlayPosY(20)
47+
.create()
48+
49+
}
50+
R.id.btTran4 -> {
51+
//https://ik.imagekit.io/demo/tr:oi-logo-white_SJwqB4Nfe.png,ox-N10,oy-20/medium_cafe_B1iTdD0C.jpg
52+
ImagekitUrlConstructor(this, "https://ik.imagekit.io/demo", "medium_cafe_B1iTdD0C.jpg")
53+
.overlayImage("logo-white_SJwqB4Nfe.png")
54+
.overlayNegX(-10)
55+
.overlayPosY(20)
56+
.create()
57+
}
58+
R.id.btTran5 -> {
59+
//https://ik.imagekit.io/demo/img/tr:ot-Hand%20with%20a%20green%20plant,otc-264120,ots-30,ox-10,oy-10/plant.jpeg
60+
ImagekitUrlConstructor(this, "https://ik.imagekit.io/demo/img", "plant.jpeg")
61+
.overlayText("Hand with a green plant")
62+
.overlayTextColor("264120")
63+
.overlayTextSize(30)
64+
.overlayPosX(10)
65+
.overlayPosY(10)
66+
.create()
67+
}
68+
else ->
69+
ImagekitUrlConstructor(this, "https://ik.imagekit.io/demo/img", "plant.jpeg")
70+
.create()
71+
})
72+
}
73+
74+
private fun showImage(imagePath: String) {
75+
tvConstructedUrl.text = "Image Url: $imagePath"
76+
77+
Picasso.get()
78+
.load(imagePath)
79+
.into(ivImage)
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,20 @@
11
package com.imagekit.android
22

3+
import android.content.Intent
34
import android.os.Bundle
4-
import android.util.Log
55
import androidx.appcompat.app.AppCompatActivity
6-
import com.imagekit.android.entity.UploadError
7-
import com.imagekit.android.entity.UploadResponse
8-
import com.squareup.picasso.Picasso
96
import kotlinx.android.synthetic.main.activity_main.*
107

11-
class MainActivity : AppCompatActivity(), ImageKitCallback {
12-
private val CLIENT_PUBLIC_KEY = "amJ0i84qqCLLbOl25vqSozezhuc="
13-
private val IMAGEKIT_ID = "bowstring"
8+
class MainActivity : AppCompatActivity() {
149

1510
override fun onCreate(savedInstanceState: Bundle?) {
1611
super.onCreate(savedInstanceState)
1712
setContentView(R.layout.activity_main)
1813

19-
ImageKit.init(applicationContext, CLIENT_PUBLIC_KEY, IMAGEKIT_ID)
14+
ImageKit.init(applicationContext, Constants.CLIENT_PUBLIC_KEY, Constants.IMAGEKIT_ID)
2015

21-
// val filename = "icLauncher.png"
22-
// val timestamp = System.currentTimeMillis()
23-
// ImageKit.getInstance().uploadImage(
24-
// filename
25-
// , SignatureUtil.sign("apiKey=$CLIENT_PUBLIC_KEY&filename=$filename&timestamp=$timestamp")
26-
// , timestamp
27-
// , true
28-
// , arrayOf("nice", "copy", "books")
29-
// , "/rishabh/folder/"
30-
// , (ResourcesCompat.getDrawable(resources, R.drawable.ic_agronomist, null) as BitmapDrawable).bitmap
31-
// , this
32-
// )
16+
btUploadImage.setOnClickListener { startActivity(Intent(this@MainActivity, UploadImageActivity::class.java)) }
3317

34-
val imagePath = ImagekitUrlConstructor(this, "https://ik.imagekit.io/bowstring", "icLauncher.png")
35-
.width(600f)
36-
.aspectRatio(4,3)
37-
.create()
38-
39-
Log.d("Image Path Constructed", imagePath)
40-
41-
Picasso.get()
42-
.load(imagePath)
43-
.into(iv_imagekit)
44-
}
45-
46-
override fun onError(uploadError: UploadError) {
47-
Log.d(MainActivity::class.simpleName, "ERROR")
48-
}
49-
50-
override fun onSuccess(uploadResponse: UploadResponse) {
51-
Log.d(MainActivity::class.simpleName, "SUCCESS")
18+
btUrlConstruct.setOnClickListener { startActivity(Intent(this@MainActivity, FetchImageActivity::class.java)) }
5219
}
5320
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.imagekit.android
2+
3+
import android.app.Activity
4+
import android.content.Intent
5+
import android.graphics.Bitmap
6+
import android.graphics.BitmapFactory
7+
import android.os.Bundle
8+
import android.util.Log
9+
import android.view.View
10+
import android.widget.Toast
11+
import androidx.appcompat.app.AppCompatActivity
12+
import com.imagekit.android.Constants.CLIENT_PUBLIC_KEY
13+
import com.imagekit.android.entity.UploadError
14+
import com.imagekit.android.entity.UploadResponse
15+
import kotlinx.android.synthetic.main.activity_upload_image.*
16+
import java.io.FileNotFoundException
17+
18+
19+
class UploadImageActivity : AppCompatActivity(), ImageKitCallback, View.OnClickListener {
20+
private var bitmap: Bitmap? = null
21+
22+
override fun onClick(v: View?) {
23+
when (v!!.id) {
24+
R.id.btSelect -> selectImage()
25+
else -> uploadImage()
26+
}
27+
}
28+
29+
private val RESULT_LOAD_IMG = 109
30+
31+
override fun onCreate(savedInstanceState: Bundle?) {
32+
super.onCreate(savedInstanceState)
33+
setContentView(R.layout.activity_upload_image)
34+
35+
btSelect.setOnClickListener(this)
36+
btUpload.setOnClickListener(this)
37+
}
38+
39+
private fun selectImage() {
40+
val photoPickerIntent = Intent(Intent.ACTION_PICK)
41+
photoPickerIntent.type = "image/*"
42+
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMG)
43+
}
44+
45+
private fun uploadImage() {
46+
bitmap?.let {
47+
val filename = "icLauncher.png"
48+
val timestamp = System.currentTimeMillis()
49+
ImageKit.getInstance().uploadImage(
50+
bitmap!!
51+
, filename
52+
, SignatureUtil.sign("apiKey=$CLIENT_PUBLIC_KEY&filename=$filename&timestamp=$timestamp")
53+
, timestamp
54+
, true
55+
, arrayOf("nice", "copy", "books")
56+
, "/rishabh/folder/"
57+
, this
58+
)
59+
}
60+
}
61+
62+
override fun onActivityResult(reqCode: Int, resultCode: Int, data: Intent?) {
63+
super.onActivityResult(reqCode, resultCode, data)
64+
65+
66+
if (resultCode == Activity.RESULT_OK) {
67+
try {
68+
val imageUri = data!!.data
69+
val imageStream = contentResolver.openInputStream(imageUri!!)
70+
val selectedImage = BitmapFactory.decodeStream(imageStream)
71+
ivImage.setImageBitmap(selectedImage)
72+
73+
bitmap = selectedImage
74+
} catch (e: FileNotFoundException) {
75+
e.printStackTrace()
76+
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show()
77+
}
78+
79+
} else {
80+
Toast.makeText(this, "You haven't picked Image", Toast.LENGTH_LONG).show()
81+
}
82+
}
83+
84+
override fun onError(uploadError: UploadError) {
85+
Log.d(MainActivity::class.simpleName, "ERROR")
86+
}
87+
88+
override fun onSuccess(uploadResponse: UploadResponse) {
89+
Log.d(MainActivity::class.simpleName, "SUCCESS")
90+
}
91+
}
-40.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)