Skip to content

Commit

Permalink
generate adaptive icons for launcher shortcuts and share targets on A…
Browse files Browse the repository at this point in the history
…ndroid O
  • Loading branch information
c99koder committed Aug 2, 2017
1 parent 759bc5c commit 0a90ef4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ android {
useLibrary 'org.apache.http.legacy'

defaultConfig {
versionCode 135
versionCode 136
versionName "3.27"
minSdkVersion 14
targetSdkVersion 26
Expand Down
1 change: 1 addition & 0 deletions irccloud-android.iml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-files" />
Expand Down
12 changes: 10 additions & 2 deletions src/com/irccloud/android/ConversationChooserTargetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.os.Bundle;
import android.service.chooser.ChooserTarget;
import android.service.chooser.ChooserTargetService;
import android.util.TypedValue;

import com.irccloud.android.activity.MainActivity;
import com.irccloud.android.data.collection.AvatarsList;
Expand All @@ -38,7 +39,9 @@

@TargetApi(Build.VERSION_CODES.M)
public class ConversationChooserTargetService extends ChooserTargetService {
private static final Icon channelIcon = Icon.createWithBitmap(Avatar.generateBitmap("#", 0xFFFFFFFF, 0xFFAAAAAA, false, 320, false));
private static final Icon channelIcon = Build.VERSION.SDK_INT < Build.VERSION_CODES.O ?
Icon.createWithBitmap(Avatar.generateBitmap("#", 0xFFFFFFFF, 0xFFAAAAAA, false, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 72, IRCCloudApplication.getInstance().getApplicationContext().getResources().getDisplayMetrics()), false)) :
Icon.createWithAdaptiveBitmap(Avatar.generateBitmap("#", 0xFFFFFFFF, 0xFFAAAAAA, false, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 108, IRCCloudApplication.getInstance().getApplicationContext().getResources().getDisplayMetrics()), false));

@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName componentName, IntentFilter intentFilter) {
Expand All @@ -53,7 +56,12 @@ public List<ChooserTarget> onGetChooserTargets(ComponentName componentName, Inte
}
Bundle extras = new Bundle();
extras.putInt("bid", c.bid);
targets.add(new ChooserTarget(c.name, c.type.equals("channel")?channelIcon:Icon.createWithBitmap(AvatarsList.getInstance().getAvatar(c.cid, c.name).getBitmap(false, 320)), 0.5f, cn, extras));
targets.add(new ChooserTarget(c.name, c.type.equals("channel")?
channelIcon:
(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ?
Icon.createWithBitmap(AvatarsList.getInstance().getAvatar(c.cid, c.name).getBitmap(false, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 72, IRCCloudApplication.getInstance().getApplicationContext().getResources().getDisplayMetrics()))) :
Icon.createWithAdaptiveBitmap(AvatarsList.getInstance().getAvatar(c.cid, c.name).getBitmap(false, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 108, IRCCloudApplication.getInstance().getApplicationContext().getResources().getDisplayMetrics()), false, false))
), 0.5f, cn, extras));
}

return targets;
Expand Down
6 changes: 3 additions & 3 deletions src/com/irccloud/android/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3884,16 +3884,15 @@ public void onClick(DialogInterface dialog, int which) {
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
moveTaskToBack(true);
} else {
ShortcutManager mShortcutManager = getSystemService(ShortcutManager.class);

if (mShortcutManager.isRequestPinShortcutSupported()) {
Icon icon = null;
if(buffer.isChannel()) {
icon = Icon.createWithBitmap(Avatar.generateBitmap("#", 0xFFFFFFFF, 0xFFAAAAAA, false, 320, false));
icon = Icon.createWithAdaptiveBitmap(Avatar.generateBitmap("#", 0xFFFFFFFF, 0xFFAAAAAA, false, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 108, getResources().getDisplayMetrics()), false));
} else if(buffer.isConversation()) {
icon = Icon.createWithBitmap(AvatarsList.getInstance().getAvatar(buffer.getCid(), buffer.getName()).getBitmap(ColorScheme.getInstance().isDarkTheme, 320));
icon = Icon.createWithAdaptiveBitmap(AvatarsList.getInstance().getAvatar(buffer.getCid(), buffer.getName()).getBitmap(false, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 108, getResources().getDisplayMetrics()), false, false));
}
ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(this, String.valueOf(buffer.getBid()))
.setIntent(shortcutIntent)
Expand All @@ -3905,6 +3904,7 @@ public void onClick(DialogInterface dialog, int which) {
mShortcutManager.requestPinShortcut(pinShortcutInfo, null);
}
}
moveTaskToBack(true);
} catch (Exception e) {
NetworkConnection.printStackTraceToCrashlytics(e);
}
Expand Down

0 comments on commit 0a90ef4

Please sign in to comment.