-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return a wallet icon in authorize result (#906)
* wallet icon * doc * fix tests * oops missed file in previous commit * make icon optional * add checks for wallet icon data uri * fully deprecate AuthorizedAccount.icon * fix tests
- Loading branch information
1 parent
770f913
commit 04c5cdd
Showing
10 changed files
with
145 additions
and
17 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
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
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
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
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
29 changes: 29 additions & 0 deletions
29
...ain/java/com/solana/mobilewalletadapter/walletlib/scenario/DefaultWalletIconProvider.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,29 @@ | ||
package com.solana.mobilewalletadapter.walletlib.scenario; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.drawable.Drawable; | ||
import android.net.Uri; | ||
import android.util.Base64; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
public class DefaultWalletIconProvider implements WalletIconProvider{ | ||
private final Drawable mIconDrawable; | ||
public DefaultWalletIconProvider(Context context) { | ||
this.mIconDrawable = context.getPackageManager().getApplicationIcon(context.getApplicationInfo()); | ||
} | ||
|
||
@Override | ||
public Uri getWalletIconDataUri() { | ||
int width = mIconDrawable.getIntrinsicWidth(); | ||
int height = mIconDrawable.getIntrinsicHeight(); | ||
Bitmap iconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); | ||
mIconDrawable.setBounds(0, 0, width, height); | ||
mIconDrawable.draw(new Canvas(iconBitmap)); | ||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); | ||
iconBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); | ||
return Uri.parse("data:image/png;base64," + Base64.encodeToString(byteStream.toByteArray(), Base64.DEFAULT)); | ||
} | ||
} |
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
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
19 changes: 19 additions & 0 deletions
19
...b/src/main/java/com/solana/mobilewalletadapter/walletlib/scenario/WalletIconProvider.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,19 @@ | ||
package com.solana.mobilewalletadapter.walletlib.scenario; | ||
|
||
import android.net.Uri; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
/*package*/ interface WalletIconProvider { | ||
/** | ||
* Returns a base64 encoded data URI of the wallet icon. This will be the icon dapps display | ||
* for your wallet. The wallet icon must be an SVG, PNG, WebP, or GIF image. | ||
* <p> | ||
* You can use a tool like <a href="https://base64.guru/converter/encode/image">https://base64.guru/converter/encode/image</a> | ||
* to encode an image using the "Data URI" setting. It's a good idea to compress your image | ||
* losslessly with a tool like <a href="https://imageoptim.com">https://imageoptim.com</a> first. | ||
* | ||
* @return a base64 encoded data URI of an SVG, PNG, WebP, or GIF image, or null | ||
*/ | ||
@Nullable Uri getWalletIconDataUri(); | ||
} |
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