GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Android uses deprecated method to create Drawable from Bitmap · Issue #5887 · NativeScript/NativeScript

Android uses deprecated method to create Drawable from Bitmap #5887

New issue
Copy link
New issue
Copy link
Closed
#7009
Closed
Android uses deprecated method to create Drawable from Bitmap#5887
#7009
Copy link
Labels
action-baros: androidtab-view

Description

@manojdcoder
manojdcoder
opened on May 30, 2018
Issue body actions

Did you verify this is a real problem by searching the [NativeScript Forum]

https://discourse.nativescript.org/t/material-design-icons-in-action-bar/5793/18?u=manojdcoder

Tell us about the problem

ActionItem / TabView icon's resolution is too low when loaded from file system

Which platform(s) does your issue occur on?

Android

Please provide the following version numbers that your issue occurs with:

  • CLI: 4.0.2
  • Cross-platform modules: 4.0.0
  • Runtime(s): 4.0.1

Please tell us how to recreate the issue in as much detail as possible.

This playground example below generates an image from font icon, it is loaded perfectly when used in Image component but when used with icons in ActionItem / TabViewItem the resolution is very low. The problem seems to be the method we use to convert Bitmap into Drawable - It's deprecated and Android official docs suggests to use a different method to create Drawable instance with right resolution.

https://play.nativescript.org/?template=play-tsc&id=DYLgPA&v=1

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

Replace the code below in app.ts of the playground example above which fixes the resolution issues.

import * as app from 'application';
import { isIOS, isAndroid } from 'platform';
import { Color } from 'color';
import { ActionBar, ActionItem } from 'ui/action-bar';

declare var android, java;

if (isIOS) {
    (<any>ActionBar.prototype).originalUpdateColors = (<any>ActionBar.prototype).updateColors;
    (<any>ActionBar.prototype).updateColors = function (navigationBar) {
        this.originalUpdateColors(navigationBar);
        this.nativeView.tintColor = new Color('green').ios;
    };
}

if (isAndroid) {
    (<any>ActionBar.prototype)._1addActionItems = function () {
        let menu = this.nativeViewProtected.getMenu();
        let items = this.actionItems.getVisibleItems();

        menu.clear();
        for (let i = 0; i < items.length; i++) {
            let item = <ActionItem>items[i];
            let menuItem = menu.add(android.view.Menu.NONE, (<any>item)._getItemId(), android.view.Menu.NONE, item.text + "");
            let filePath = item.icon
            if (filePath) {
                const bitmap = android.graphics.BitmapFactory.decodeFile(filePath);
                menuItem.setIcon(new android.graphics.drawable.BitmapDrawable(app.android.context.getResources(), bitmap));
            }
            menuItem.setShowAsAction(android.view.MenuItem.SHOW_AS_ACTION_ALWAYS);
        }
    };
}

app.start({ moduleName: 'home/home-page' });

Reacted by Brad Martin, Nikolay Iliev and Yurii Cherniavskyi

Activity

  1. tsonevn
    added
    os: android
    on May 31, 2018
  2. tsonevn
    added
    feature
    on Jul 25, 2018
  3. NickIliev
    added
    tab-view
    action-bar
    bug
    and removed
    feature
    on Dec 11, 2018
  4. ghost assigned
    MartoYankov
    on Mar 8, 2019
  5. ghost added
    in progress
    on Mar 8, 2019
  6. SvetoslavTsenov
    closed this as completedin #7009on Mar 12, 2019
  7. ghost removed
    bug
    on Mar 12, 2019
  8. ghost removed
    in progress
    on Mar 12, 2019
  9. lock commented on Mar 11, 2020

    @lock
    lockBot
    on Mar 11, 2020
    More actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  10. lock
    unassigned
    MartoYankov
    on Mar 11, 2020
  11. lock
    locked and limited conversation to collaborators on Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    action-baros: androidtab-view

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.