Java Code Examples for android.app.Activity#setTaskDescription()

The following examples show how to use android.app.Activity#setTaskDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XposedApp.java    From EdXposedManager with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
    public static void setColors(ActionBar actionBar, Integer value, Activity activity) {
        int color = value;
        SharedPreferences prefs = activity.getSharedPreferences(activity.getPackageName() + "_preferences", MODE_PRIVATE);

        int drawable = iconsValues[Integer.parseInt(Objects.requireNonNull(prefs.getString("custom_icon", "0")))];

        if (actionBar != null)
            actionBar.setBackgroundDrawable(new ColorDrawable(color));

        ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(activity.getString(R.string.app_name),
                drawableToBitmap(activity.getDrawable(drawable)), color);
//        ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(activity.getString(R.string.app_name),
//                drawable, color);
        activity.setTaskDescription(tDesc);

        if (getPreferences().getBoolean("nav_bar", false)) {
            activity.getWindow().setNavigationBarColor(darkenColor(color, 0.85f));
        } else {
            int black = activity.getResources().getColor(android.R.color.black, null);
            activity.getWindow().setNavigationBarColor(black);
        }
    }
 
Example 2
Source File: PluginInstrumentation.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void fixTaskDescription(Activity activity, ActivityInfo targetInfo) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            PackageManager pm = mHostContext.getPackageManager();
            String lablel = String.valueOf(targetInfo.loadLabel(pm));
            Drawable icon = targetInfo.loadIcon(pm);
            Bitmap bitmap = null;
            if (icon instanceof BitmapDrawable) {
                bitmap = ((BitmapDrawable) icon).getBitmap();
            }
            if (bitmap != null) {
                activity.setTaskDescription(new android.app.ActivityManager.TaskDescription(lablel, bitmap));
            } else {
                activity.setTaskDescription(new android.app.ActivityManager.TaskDescription(lablel));
            }
        }
    } catch (Throwable e) {
        Log.w(TAG, "fixTaskDescription fail", e);
    }
}
 
Example 3
Source File: RecentTasksStyler.java    From v2ex with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void styleRecentTasksEntry(Activity activity) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return;
    }

    Resources resources = activity.getResources();
    String label = resources.getString(activity.getApplicationInfo().labelRes);
    int colorPrimary = resources.getColor(R.color.theme_primary);

    if (sIcon == null) {
        // Cache to avoid decoding the same bitmap on every Activity change
        sIcon = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher);
    }

    activity.setTaskDescription(new ActivityManager.TaskDescription(label, sIcon, colorPrimary));
}
 
Example 4
Source File: ATH.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public static void setTaskDescriptionColor(@NonNull Activity activity, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Task description requires fully opaque color
        color = ColorUtil.stripAlpha(color);
        // Sets color of entry in the system recents page
        activity.setTaskDescription(new ActivityManager.TaskDescription((String) activity.getTitle(), null, color));
    }
}
 
Example 5
Source File: ATH.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
public static void setTaskDescriptionColor(@NonNull Activity activity, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Task description requires fully opaque color
        color = ColorUtil.stripAlpha(color);
        // Sets color of entry in the system recents page
        activity.setTaskDescription(new ActivityManager.TaskDescription((String) activity.getTitle(), null, color));
    }
}
 
Example 6
Source File: Colors.java    From Colors with Apache License 2.0 5 votes vote down vote up
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private static void applyTaskDescription(Activity activity, @Nullable String taskName,
                                         @Nullable Bitmap taskIcon) {
    @ColorRes int primaryColorRes = sTheme.getPrimaryColor().getPrimaryColorRes();
    @ColorInt int primaryColor = ContextCompat.getColor(activity, primaryColorRes);

    TaskDescription taskDescription = new TaskDescription(taskName, taskIcon, primaryColor);
    activity.setTaskDescription(taskDescription);
}
 
Example 7
Source File: ActivityInjector.java    From springreplugin with Apache License 2.0 5 votes vote down vote up
/**
 * 可根据插件Activity的描述(android:label、android:icon)来设置Task在“最近应用程序”中的显示 <p>
 * 注意:Android 4.x及以下暂不支持 <p>
 * Author: Jiongxuan Zhang
 */
private static void injectTaskDescription(Activity activity, ActivityInfo ai) {
    // Android 4.x及以下暂不支持
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return;
    }

    if (activity == null || ai == null) {
        return;
    }

    if (LOG) {
        LogDebug.d(TAG, "activity = " + activity);
        LogDebug.d(TAG, "ai = " + ai);
    }

    // 获取 activity label
    String label = getLabel(activity, ai);
    // 如果获取 label 失败(可能性极小),则不修改 TaskDescription
    if (TextUtils.isEmpty(label)) {
        return;
    }

    // 获取 ICON
    Bitmap bitmap = getIcon(activity, ai);

    // FIXME color的透明度需要在Theme中的colorPrimary中获取,先不实现
    ActivityManager.TaskDescription td;
    if (bitmap != null) {
        td = new ActivityManager.TaskDescription(label, bitmap);
    } else {
        td = new ActivityManager.TaskDescription(label);
    }

    if (LOG) {
        LogDebug.d(TAG, "td = " + td);
    }

    activity.setTaskDescription(td);
}
 
Example 8
Source File: ATEUtils.java    From Muzesto with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void applyTaskDescription(@NonNull Activity activity, @Nullable String key, int color) {
    // Sets color of entry in the system recents page
    try {
        ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(
                (String) activity.getTitle(),
                ((BitmapDrawable) activity.getApplicationInfo().loadIcon(activity.getPackageManager())).getBitmap(),
                color);
        activity.setTaskDescription(td);
    } catch (Exception ignored) {

    }
}
 
Example 9
Source File: PresetThemeStore.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void applyTaskDescription(Activity activity) {
    String taskName = mContext.getString(R.string.app_name);
    int taskColor = getPrimaryColor();
    Bitmap taskIcon = getAppIcon();

    TaskDescription taskDescription = new TaskDescription(taskName, taskIcon, taskColor);
    activity.setTaskDescription(taskDescription);
}
 
Example 10
Source File: AppUtil.java    From droidkaigi2016 with Apache License 2.0 4 votes vote down vote up
public static void setTaskDescription(Activity activity, String label, int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.setTaskDescription(new ActivityManager.TaskDescription(label, null, color));
    }
}
 
Example 11
Source File: AppUtil.java    From droidkaigi2016 with Apache License 2.0 4 votes vote down vote up
public static void setTaskDescription(Activity activity, String label, int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.setTaskDescription(new ActivityManager.TaskDescription(label, null, color));
    }
}