Skip to content

Commit 2c35dca

Browse files
committed
refactor: sdk
0 parents  commit 2c35dca

File tree

72 files changed

+2081
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2081
-0
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild

.idea/codeStyles/Project.xml

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

.idea/codeStyles/codeStyleConfig.xml

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

.idea/dictionaries/rishabhjain.xml

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

.idea/encodings.xml

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

.idea/gradle.xml

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

.idea/misc.xml

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

.idea/runConfigurations.xml

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

.idea/vcs.xml

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

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
android {
8+
compileSdkVersion 28
9+
defaultConfig {
10+
applicationId "com.imagekit.android"
11+
minSdkVersion 21
12+
targetSdkVersion 28
13+
versionCode 1
14+
versionName "1.0"
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: 'libs', include: ['*.jar'])
27+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28+
implementation 'androidx.appcompat:appcompat:1.0.2'
29+
implementation 'androidx.core:core-ktx:1.0.2'
30+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31+
testImplementation 'junit:junit:4.12'
32+
androidTestImplementation 'androidx.test:runner:1.1.1'
33+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
34+
35+
implementation 'com.squareup.picasso:picasso:2.71828'
36+
implementation project(":imagekit")
37+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.imagekit.android
2+
3+
import android.support.test.InstrumentationRegistry
4+
import android.support.test.runner.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getTargetContext()
22+
assertEquals("com.imagekit.android", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.imagekit.android">
4+
5+
<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">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN"/>
15+
16+
<category android:name="android.intent.category.LAUNCHER"/>
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.imagekit.android
2+
3+
import android.os.Bundle
4+
import android.util.Log
5+
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
9+
import kotlinx.android.synthetic.main.activity_main.*
10+
11+
class MainActivity : AppCompatActivity(), ImageKitCallback {
12+
private val CLIENT_PUBLIC_KEY = "amJ0i84qqCLLbOl25vqSozezhuc="
13+
private val IMAGEKIT_ID = "bowstring"
14+
15+
override fun onCreate(savedInstanceState: Bundle?) {
16+
super.onCreate(savedInstanceState)
17+
setContentView(R.layout.activity_main)
18+
19+
ImageKit.init(applicationContext, CLIENT_PUBLIC_KEY, IMAGEKIT_ID)
20+
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+
// )
33+
34+
val imagePath = ImagekitUrlConstructor("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")
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.imagekit.android;
2+
3+
import javax.crypto.Mac;
4+
import javax.crypto.spec.SecretKeySpec;
5+
import java.security.InvalidKeyException;
6+
import java.security.NoSuchAlgorithmException;
7+
import java.util.Formatter;
8+
import java.util.Locale;
9+
10+
public class SignatureUtil {
11+
private static final String PRIVATE_CLIENT_KEY = "dI7GuFhK/BrmAAzKOcm3JXdnJjc=";
12+
13+
public static String createSignature(String filename, Long timestamp, String apiKey) {
14+
try {
15+
String signature =
16+
String.format(Locale.getDefault(), "apikey=%s&filename=%s&timestamp=%d", apiKey, filename, timestamp);
17+
return hmacSha1(signature, PRIVATE_CLIENT_KEY);
18+
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
19+
e.printStackTrace();
20+
return null;
21+
}
22+
}
23+
24+
25+
private static String hmacSha1(String value, String key)
26+
throws NoSuchAlgorithmException,
27+
InvalidKeyException {
28+
String type = "HmacSHA1";
29+
SecretKeySpec secret = new SecretKeySpec(key.getBytes(), type);
30+
Mac mac = Mac.getInstance(type);
31+
mac.init(secret);
32+
byte[] bytes = mac.doFinal(value.getBytes());
33+
return bytesToHex(bytes);
34+
}
35+
36+
private final static char[] hexArray = "0123456789abcdef".toCharArray();
37+
38+
private static String bytesToHex(byte[] bytes) {
39+
char[] hexChars = new char[bytes.length * 2];
40+
int v;
41+
for (int j = 0; j < bytes.length; j++) {
42+
v = bytes[j] & 0xFF;
43+
hexChars[j * 2] = hexArray[v >>> 4];
44+
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
45+
}
46+
return new String(hexChars);
47+
}
48+
49+
private static final String ALGORITHM = "HmacSHA1";
50+
51+
public static String sign(String content) {
52+
String encoded;
53+
try {
54+
SecretKeySpec signingKey = new SecretKeySpec(PRIVATE_CLIENT_KEY.getBytes(), ALGORITHM);
55+
Mac mac = Mac.getInstance(ALGORITHM);
56+
mac.init(signingKey);
57+
encoded = toHexString(mac.doFinal(content.getBytes()));
58+
} catch (NoSuchAlgorithmException e) {
59+
throw new RuntimeException("Cannot create signature.", e);
60+
} catch (InvalidKeyException e) {
61+
throw new RuntimeException("Cannot create signature.", e);
62+
}
63+
return encoded;
64+
}
65+
66+
private static String toHexString(byte[] bytes) {
67+
Formatter formatter = new Formatter();
68+
for (byte b : bytes) {
69+
formatter.format("%02x", b);
70+
}
71+
return formatter.toString();
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportHeight="108"
6+
android:viewportWidth="108">
7+
<path
8+
android:fillType="evenOdd"
9+
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
10+
android:strokeColor="#00000000"
11+
android:strokeWidth="1">
12+
<aapt:attr name="android:fillColor">
13+
<gradient
14+
android:endX="78.5885"
15+
android:endY="90.9159"
16+
android:startX="48.7653"
17+
android:startY="61.0927"
18+
android:type="linear">
19+
<item
20+
android:color="#44000000"
21+
android:offset="0.0"/>
22+
<item
23+
android:color="#00000000"
24+
android:offset="1.0"/>
25+
</gradient>
26+
</aapt:attr>
27+
</path>
28+
<path
29+
android:fillColor="#FFFFFF"
30+
android:fillType="nonZero"
31+
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
32+
android:strokeColor="#00000000"
33+
android:strokeWidth="1"/>
34+
</vector>
40.5 KB
Loading

0 commit comments

Comments
 (0)