Wednesday, October 4, 2017

Android AlertDialog

How to display a delete confirmation box?

A simple method is to use AlertDialog that quickly provides the "CANCEL" and "OK" along with your custom confirmation message.



An example within a Fragment class where a user click's the Delete button which calls the deleteConfirmation( ) function with the title or name of item to be delete.

1:  private void deleteConfirmation(String title){  
2:    AlertDialog.Builder alert = new AlertDialog.Builder(getContext());  
3:    alert.setTitle("Delete");  // Declare the title
4:    alert.setMessage("Are you sure you want to delete \n"+title+"?");  // Set message below title
5:    alert.setIcon(R.mipmap.ic_delete);  // Set the icon at top left
6:    alert.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {  
7:      public void onClick(DialogInterface dialog, int which) {  
8:        // continue with delete  
9:        MainActivity.confirmDelete=true;  
10:        delete();  
11:      }  
12:    });  
13:    alert.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {  
14:      public void onClick(DialogInterface dialog, int which) {  
15:        // close dialog  
16:      }  
17:    });  
18:    MainActivity.confirmDelete=false;  
19:    alert.show();  
20:  }  

Note 1:
The Dialog class is the base class to AlertDialog that makes the user take an action before returning back to the Fragment or Activity. This is known as a Modal Event. Other example of Dialog class are DatePickerDialog and TimePickerDialog.

If used for Android API 25 and onward, the import statement is

import android.app.AlertDialog;

for API 11 to below API 25 use

import android.support.v7.app.AlertDialog;

Note 2:
There are 3 type of buttons that can be added (in the example above, only 2 are added) to an AlertDialog. Only one of each type can be added using the following methods;

alert.setPositiveButton
alert.setNegativeButton
alert.setNeutralButton

List can be added to AlertDialog if required.

Note 3:
There are several ways to pass message or status to the Activity or Fragment that created/launched the AlertDialog. In the example above, a static variable is declared in the MainActivity and values are changed base on button clicked.

In MainActivity.java

public static boolean confirmDelete=false;

Note 4:
To further customise the AlertDialog look, a resource file (XML) can be created and assigned with the method

LayoutInflater inflater = getActivity().getLayoutInflater();
alert.setView( inflater.inflate(R.layout.customDialog, null) )


Done.

Tuesday, August 15, 2017

Raspberry Pi Workshop 2017 (Java)

Java is still very much alive today despite the many new programming languages sprouting. This portable language provides programming solution for a wide variety of computer systems including embedded devices.
As for the Raspberry Pi, the most common operating system being in use is Raspbian which comes default with Java installed. The Raspberry Pi provides a physical extension that connect to sensors and other electrical components. There are 2 most common Java libraries being used to accessed these extensions. Each having their own strengths.


In Malaysia, organisations can accelerate their learning path in this area through a 1 day fully hands-on comprehensive workshop. Details can be found the SHOP section of Harmony Shades or leave a message with details of your interest.

Wednesday, July 26, 2017

MySQL Console Pops Up Unexpectedly

MySQL database server provides an easy to implement and uses ANSI SQL syntax with wide implementation for many programming platforms. It is still open source licensed for the Community Edition as GPL (see details at mysql.com).

Current versions of MySQL Community Edition is available on Red Hat 6+, Centos 6+ and MS Window 10, for following versions;

  • MySQL 5.6 GA on 5.2.2013
  • MySQL 5.7 GA on 21.10.2015

Both versions are known to support current SQL standards, being SQL:2008.

Since using MySQL Community Edition version 5.6.21, something strange has been happening every midnight. A DOS like prompt pops up and very quickly does "something", which does NOT really allow me the time to read the messages and then it goes away (disappears). On one occasion I managed to capture that screen as the database it was trying to reach was not connected and here is how that screen looks like.


Apparently it was updating the MySQL catalogue, pretty harmless. The problem that I can see;
  • Takes up additional processing which is not good when I am running emulators or CPU intensive work
  • Distracts any on going work, such as when preparing documentation
  • Disrupts desktop on-going recordings
  • Disrupts benchmark operations

One could either disable the update process or assign it to another pre-defined time. On MS Windows 10, here are the steps to do either.

Step 1: Start MySQL Installer

Click the MS Windows Start and type; mysql installer
Click the Desktop App that appears. An upgrade my be required, proceed with the upgrade.


Step 2:  Edit Installer Options

In the installer option, click the Configure icon (Looks like a wrench).



  1. To disable the automatic catalog update; Uncheck "Should MySQL Installer update its catalog periodically?"
  2. To change the update time; Select a new time in "What time?" dropdown list.

Click Close.

Done.

Friday, July 14, 2017

Source code revision control with Git


Version control system is used to manage versions of files and is used widely with programming source codes. Common examples are SVN and Git.

Here is an example of the using GIT with Heroku (Working with GIT2). It demonstrates the git command for;
  • clone
  • branch
  • checkout
  • commit
  • status

Basic commands to manage a local version control repository

Typical process to prepare a folder where files are to be tracked/staged uses the commands init, status and add. It would be good to have created a folder with 4 or 5 files and try out the following commands.
 # Initialise Git repository   
  $ git init   
     
  # Identify status and which files are being track or untracked.   
  $ git status   
     
  # Add all files to the repository   
  $ git add .  
   
 # Identify files are being track as staged  
  $ git status   

At this time, a folder to manage the repository is created with the name ".git". Have a look at content of the files in this folder.

Filename: .git/HEAD
ref: refs/heads/master

Filename: .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly

Filename: .git/description
Unnamed repository; edit this file 'description' to name the repository.


To remove a file from being tracked.
 # Remove a file from list of staged files  
 $ git rm --cached somefile.txt.  

Process to place files into the repository.
 # Commit files to repository  
 $ git commit -m "Place comments here"  
   
 $ git status  

Retrieve tracked file from the repository. The latest thats found in the repository, that is.
 # Checkout a file from the repository  
 $ git checkout programming.txt  
   
 $ git status  

Cache and other files that should not be kept in the repository or tracked, can be listed in a file ".gitignore" within that folder. Example to ignore the folder "temp" and file "nofile.txt".

Filename: .gitignore
/temp
nofile.txt

end

Wednesday, June 21, 2017

Open Source Software Leads Growth of Deep Learning Community

Faster CPU and GPU computers have arrived and AI computing is becoming available to more people. Amazon and Google are already rolling out services that allow anyone access to the computational resources required for AI, in particular deep learning. I am looking forward at how this will be incorporated into the next gen of personal devices.


There are too many areas to discuss on this, but here I would like to mention that deep learning is catching up fast on the open source software (OSS) environment.

GPU deep learning with NVIDIA provides a good start. They even have a whole section devoted to deep learning;

https://www.nvidia.com/en-us/deep-learning-ai/education/

A quick guide on deep learning is available at Deep Learning Introduction.

Thursday, June 1, 2017

The Day British Airways System Crashed in 2017

Waiting to hear the cause of it. How difficult is it to start up the back up process?

Source https://www.thesun.co.uk/news/3669536/british-airway-it-failure-outsourced-staff/


Pentaho 7 Community Edition

Summary of their licenses.

With big data and increase interest in business intelligence, there seems to be many software out there to suit all your needs. As for OSS licensed, the name Pentaho have been around for a long time. Here is a little note on their licensing.

Pentaho Business Analytics Platform 2, Pentaho Reporting Engine and Pentaho Report Designer are licensed as GPL v2.

Pentaho Data Integration or Kettle is license as Apache version 2.0. Details are found at  their wiki.

There is an interesting and comforting public post on Kettle license at Pentaho Forum with regards to Pentaho licensing.

Community Edition

Pentaho 7.1 is currently available but there is still the community edition, and my notes on Howto install is available only for the Linux server.



The additional known components that enterprise have and community edition doesn't is the self service designer dashboard and interactive reporting. Still searching for comparison of the community edition and other BI tools in the market.

Thursday, April 20, 2017

Mouse Cursor Disappear in Chrome Web Browser

Google Chrome is among the web browsers that I use frequently on MS Windows 10. Chrome provide many standard web browser features, security and option to extend its capability via plugin extensions. Work productivity goes up a notch when many application windows are launched to run concurrently. The monitor screen is big enough to allow re-positioning of the windows, overlapping windows and minimizing of windows.

On 20th April (today), the mouse cursor disappears when its moved over the Chrome window. It appears back when the cursor is moved outside of the Chrome window area. Moving the cursor again on Chrome window area, its noticeable that an invisible cursor is moving as hyperlinks light up, menu and buttons get active and the standard windows minimise and maximise buttons can be accessed.

A quick search on the internet shows that this problem have occurred way back in June 2014. Its almost the same thing, and issue only started after a MS Windows update that had occurred the day before. Yes, there was a Windows 10 updated yesterday.

Solution is to disable the Hardware Acceleration in Chrome. Here is how to get that cute cursor back on Chrome.


Step 1: Open Chrome web browser (if its not already open).

Step 2: Click "Customise and control Google Chrome" or the "3 vertical dots" button. Its usually at same row as the URL bar. Choose "Settings", scroll down and click "Show advanced settings...".

In the section "System" uncheck Use hardware acceleration when available. Close Chrome and launch Chrome or restart Chrome.

I have not found out if its due to MS Windows change in its settings or Chrome settings changed. Maybe someone out there have an answer.