fbpx
Add Image to Android app

Add Image to Android app

Add PNG Icon to Android app

 

In this article, let discuss on

Add PNG Icon to Android app

Let us see how to Add PNG icon to Android App. In the end you your app will use the icon you have added for the android application.

 In this article I’m going to use the existing android project created as part of this article Make WordPress as Android App. This Follow the code repo used  ).

How to Add PNG Icon to Android App?

You can add Image assets by Right click on the location where the image or icon need to be placed.

See below screenshot for the Menu option in Android Studio.

  • After right-click drawable folder, Choose New > Image Assets
  • You need to choose the image or icon from the browse menu under Source Asset section of Foreground Layer Tab.
  • Adjust the Scaling according to the image or icon output.
  • Go to Background Layer tab and adjust the background color or image accordingly.
  • Once done, click Finish (Note: Try to keep the same name as the previous icon file name, if you are replacing the icon)
  • Run the App to see the new Icon changed.
intellij add image asset menu
Balamurugan T

Balamurugan T

October 22, 2021

Senior Developer | Java & C#.NET | 10++ years of IT experience.

Planning to learn ReactJS or Angular or Flutter.!

Make WordPress as Android App

Make WordPress as Android App

Make WordPress as Android App

In this article, let discuss on

Make WordPress as Android App

Make WordPress as Android App. Yes, follow the article from top to bottom and do not miss out anything. In the end you will see your website or WordPress blog in Android phone as an application.

You can also publish the app in Google Play Store or any eco-system for Android apps (Such as Amazon app store, Samsung galaxy app store, Honor/Huawei App Gallery and So on).

How to Make WordPress as Android App?

Converting WordPress blog or Website is easy if you have hands-on with Android Studio and Android SDKs.

               Yes, you need to know little bit of java coding knowledge and basics of Android application development. Do not worry if you have very little knowledge on these both should also be fine. If you follow this article carefully.

Balamurugan T

Balamurugan T

October 20, 2021

Senior Developer | Java & C#.NET | 10++ years of IT experience.

Planning to learn ReactJS or Angular or Flutter.!

Setup ReactJS to create your first hello world

ReactJS environment setup in Windows using NodeJS, npm and few modules

Setting up ReactJS Locally (Windows)

Preface:

In this article, we are going to see how to setup ReactJS locally (Windows).

Prerequisites:

  • NodeJS
  • npm & npx (if npx is not installed use the below command
    npm install -g npx

Using the create-react-app command:

npm command
npx create-react-app hello-world-react-app
npx command executed

Once the npx command is successfully executed, you will be seeing the screen as above image.

Now we are good to start our first ReactJS app.

we need to go inside our react application folder.

cd hello-world-react-app
npm start

once you are inside the reactjs application folder, start the web development server (webpack) using npm start command.

ReactJS App started and url is printed in terminal/command

Once you click on the link, it should open browser window with the URL clicked. http://localhost:3000/

ReactJS App Launched in Browser

Pro Tip:

You do not need to restart the webpack everytime, just make changes to your RectJS Application code and save it, it will be automatically rebuild and reloaded in the browser.

Balamurugan T

Balamurugan T

August 11, 2021

Java & C#.NET Developer with 10++ years of IT experience.

Planning to learn ReactJS or Angular or Flutter.!

Microsoft Windows Emoji keyboard shortcut

Microsoft Windows Emoji keyboard shortcut

Microsoft Windows Emoji keyboard shortcut Win + .

In this article, let discuss on

Microsoft Windows Emoji keyboard shortcut Win + .

Emoji’s 😊😂🤣😍😒👌😘💕😁👍🙌

Emoji’s plays vital role in everyone’s life now!

We express our thoughts usings these Emoji’s. Emojis were part of Phone and Handheld devices. Due to heavy usage of these Emoji now PCs and Laptops also needed those emojies.

For very long I used to search the emoji in Google and copy paste them where ever needed, But  Winodws has this Emoji pop-up integrated.

Keyboard Shortcut for Emoji in Windows

  • During text entry, type Windows logo key   + . (period). The emoji keyboard will appear.
  • Select an emoji with the mouse, or keep typing to search through the available emojis for one you like.

    By Pressing Windows + . (period) will bring up the Emoji popup (as shown below)

    Microsoft Windows Emoji keyboard shortcut

    Wanna try it now 👓

     


    🚩Pro Tip: Type all the symbols like a pro

    Sometimes you need to type a character that isn’t on your keyboard, like an em-dash (—) or the copyright symbol (©). If you have a numeric keypad on your keyboard, you don’t have to find one and copy and paste, you can just do it! Here’s how:

    1. Hold down the Alt key on your keyboard.
    2. With the Alt key held down, type the four-digit code on the numeric keypad for the character you want. (Include the leading 0 if that’s required.)

      Note: This only works on the numeric keypad. This won’t work on the row of numbers at the top of the keyboard.

    3. Release the Alt key.

    Here’s just a few of the characters you can type with the Alt key:

    Symbol

    Name

    Alt-code

    ©

    Copyright symbol

    Alt+0169

    ®

    Registered symbol

    Alt+0174

    Trademark

    Alt+0153

    List Dot

    Alt+0149

    §

    Section symbol

    Alt+0167

    Dagger

    Alt+0134

    Double dagger

    Alt+0135

    en-dash

    Alt+0150

    em-dash

    Alt+0151

    Paragraph symbol (Pilcrow)

    Alt+0182

    ¡

    Upside-down exclamation mark

    Alt+0161

    ¿

    Upside-down question mark

    Alt+0191

    ¢

    Cent sign

    Alt+0162

    £

    British Pound

    Alt+0163

    Є

    Euro currency

    Alt+0128

    ¥

    Japanese Yen

    Alt+0165

    Balamurugan T

    Balamurugan T

    August 08, 2021

    Java & C#.NET Developer with 10++ years of IT experience.

    Planning to learn ReactJS or Angular or Flutter.!

    Composite Key with JPA and Hibernate

    Composite Key with JPA and Hibernate

    In this article let discuss on

    How to map Composite Key  with JPA and Hibernate

    Domain Model

    A relational database composite key contains two or more columns which together for the primary key of a given table.

    Composite Key with JPA and Hibernate

    In the diagram above, the employee table has a Composite Key, which consists of two columns:

      • company_id
      • employee_number

    Every Employee can also have a Phone, which uses the same composite key to reference its owning Employee.

    Composite Primary Key with JPA and Hibernate

    To map this database table mapping, we need to isolate the compound key into an @Embeddable first:

    @Embeddable
    public class EmployeeId implements Serializable {
     
        @Column(name = "company_id")
        private Long companyId;
     
        @Column(name = "employee_number")
        private Long employeeNumber;
     
        public EmployeeId() {
        }
     
        public EmployeeId(Long companyId, Long employeeId) {
            this.companyId = companyId;
            this.employeeNumber = employeeId;
        }
     
        public Long getCompanyId() {
            return companyId;
        }
     
        public Long getEmployeeNumber() {
            return employeeNumber;
        }
     
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof EmployeeId)) return false;
            EmployeeId that = (EmployeeId) o;
            return Objects.equals(getCompanyId(), that.getCompanyId()) &&
                    Objects.equals(getEmployeeNumber(), that.getEmployeeNumber());
        }
     
        @Override
        public int hashCode() {
            return Objects.hash(getCompanyId(), getEmployeeNumber());
        }
    }
    

    The JPA specification says that all entity identifiers should be serializable and implement equals and hashCode.

    So, an Embeddable that is used as a composite identifier must be Serializable and implement equals and hashCode.

    The Employee mapping looks as follows:

    @Entity(name = "Employee")
    @Table(name = "employee")
    public class Employee {
     
        @EmbeddedId
        private EmployeeId id;
     
        private String name;
     
        public EmployeeId getId() {
            return id;
        }
     
        public void setId(EmployeeId id) {
            this.id = id;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
    }
    
    
    

    The @EmbeddedId is used to instruct Hibernate that theEmployeeentity uses a compound key.

    The Phone mapping is rather straightforward as well:

    @Entity(name = "Phone")
    @Table(name = "phone")
    public class Phone {
     
        @Id
        @Column(name = "`number`")
        private String number;
     
        @ManyToOne
        @JoinColumns({
            @JoinColumn(
                name = "company_id",
                referencedColumnName = "company_id"),
            @JoinColumn(
                name = "employee_number",
                referencedColumnName = "employee_number")
        })
        private Employee employee;
     
        public Employee getEmployee() {
            return employee;
        }
     
        public void setEmployee(Employee employee) {
            this.employee = employee;
        }
     
        public String getNumber() {
            return number;
        }
     
        public void setNumber(String number) {
            this.number = number;
        }
    }
    
    

    The Phone uses the number as an entity identifier since every phone number and the @ManyToOne mapping uses the two columns that are part of the compound key.

    Mapping relationships using the Composite Key

    We can even map relationships using the information provided within the Composite Key itself. In this particular example, the company_id references a Company entity which looks as follows:

    @Entity(name = "Company")
    @Table(name = "company")
    public class Company {
     
        @Id
        private Long id;
     
        private String name;
     
        public Long getId() {
            return id;
        }
     
        public void setId(Long id) {
            this.id = id;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
     
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Company)) return false;
            Company company = (Company) o;
            return Objects.equals(getName(), company.getName());
        }
     
        @Override
        public int hashCode() {
            return Objects.hash(getName());
        }
    }
    

    We can have the Composite Key mapping referencing the Company entity within the Employee entity:

    @Entity(name = "Employee")
    @Table(name = "employee")
    public class Employee {
     
        @EmbeddedId
        private EmployeeId id;
     
        private String name;
     
        @ManyToOne
        @JoinColumn(name = "company_id",insertable = false, updatable = false)
        private Company company;
     
        public EmployeeId getId() {
            return id;
        }
     
        public void setId(EmployeeId id) {
            this.id = id;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
    }
    

    Notice that the @ManyToOne association instructs Hibernate to ignore inserts and updates issued on this mapping since the company_idis controlled by the @EmbeddedId.

     

    Mapping a relationships inside @Embeddable

    But that’s not all. We can even move the @ManyToOne inside the @Embeddable itself:

    @Embeddable
    public class EmployeeId implements Serializable {
     
        @ManyToOne
        @JoinColumn(name = "company_id")
        private Company company;
     
        @Column(name = "employee_number")
        private Long employeeNumber;
     
        public EmployeeId() {
        }
     
        public EmployeeId(Company company, Long employeeId) {
            this.company = company;
            this.employeeNumber = employeeId;
        }
     
        public Company getCompany() {
            return company;
        }
     
        public Long getEmployeeNumber() {
            return employeeNumber;
        }
     
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof EmployeeId)) return false;
            EmployeeId that = (EmployeeId) o;
            return Objects.equals(getCompany(), that.getCompany()) &&
                    Objects.equals(getEmployeeNumber(), that.getEmployeeNumber());
        }
     
        @Override
        public int hashCode() {
            return Objects.hash(getCompany(), getEmployeeNumber());
        }
    }
    
    

    Now, the Employee mapping will no longer require the extra @ManyToOne association since it’s offered by the entity identifier:

    @Entity(name = "Employee")
    @Table(name = "employee")
    public class Employee {
     
        @EmbeddedId
        private EmployeeId id;
     
        private String name;
     
        public EmployeeId getId() {
            return id;
        }
     
        public void setId(EmployeeId id) {
            this.id = id;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
    }
    

    The persistence logic changes as follows:

    Company company = doInJPA(entityManager -> {
        Company _company = new Company();
        _company.setId(1L);
        _company.setName("vladmihalcea.com");
        entityManager.persist(_company);
        return _company;
    });
     
    doInJPA(entityManager -> {
        Employee employee = new Employee();
        employee.setId(new EmployeeId(company, 100L));
        employee.setName("Vlad Mihalcea");
        entityManager.persist(employee);
    });
     
    doInJPA(entityManager -> {
        Employee employee = entityManager.find(
            Employee.class,
            new EmployeeId(company, 100L)
        );
        Phone phone = new Phone();
        phone.setEmployee(employee);
        phone.setNumber("012-345-6789");
        entityManager.persist(phone);
    });
     
    doInJPA(entityManager -> {
        Phone phone = entityManager.find(Phone.class, "012-345-6789");
        assertNotNull(phone);
        assertEquals(new EmployeeId(company, 100L), phone.getEmployee().getId());
    });
    

    Conclusion

    Knowing how to map a Composite Key with JPA and Hibernate is very important because this is the way you’d map a many-to-many association.

    As demonstrated in this blog post, such a mapping is not complicated at all.

    Balamurugan T

    Balamurugan T

    August 05, 2021

    Java & C#.NET Developer with 10++ years of IT experience.

    Planning to learn ReactJS or Angular or Flutter.!