Skip to main content

Posts

Material ripple effect on Android Buttons

If you observe the buttons in recent apps, they all have ripple effect when you touch the buttons. How do you achieve it in your own app? Solution 1:  Change the foreground of the button to selectableItemBackground as shown below. <button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:foreground="?android:atrr/selectableItemBackground"        android:background="@color/buttonColor"  /> Works for : API 23 and above Solution 2:  Set the value for backgroundTint instead of changing the background. Works for : API 21 and above <button        android:layout_width="wrap_content"        android:layout_height="wrap_content”       android:backgroundTint="@color/buttonColor" ...

Introduction to awk

awk is  a popular text processing utility in Unix operating system. It is useful in analyzing the text files, especially those which are organized into rows and columns. By the way, awk stands for the names of its inventors Alfred V. A ho, Peter J. W einberger, and Brian W. K ernighan who wrote it in 1977 at Bell Laboratories. Using awk Let us use a file empl.txt for the first few examples, which has names of employees, their (dummy) ids and departments $cat empl.txt Suresh 1 ADM Ramesh 2 TECH Sita 3 TECH Maran 4 ADM Shreya 5 SAL Partha 6 SAL Vandana 7 ADM Nandini 8 ADM Sudama 9 SAL First let us use awk to print only employees from ADM department. $ awk '/ADM/' empl.txt Suresh 1 ADM Maran 4 ADM Vandana 7 ADM Nandini 8 ADM Here  the parameters for awk command must be written in single quotes. This should be followed by input file on which awk command must be applied. Output of the command is displayed on screen. The command '/string/' filters only those ...

VI editor

I consulted my team regarding the inclusion of vi editor in this blog. (this sounds cooler than I wasted 2 days dillydallying about this topic). I will just give enough introduction to the most popular text editor in Linux editor, enough for you to create/open a file, make changes and save the file.  To start vi editor, you give vi and filename. Modes  The editor has two modes insert mode and command mode. Insert mode is for you to type the content and command mode is for manipulation. i - key starts insert mode esc - key exits the insert mode You can use even the following keys for starting insert mode a - append at the end of word o - start a new line below the cursor O - start a new line above the cursor. While typing remember the fact that, cursor keys are not allowed in insert mode. Quitting the editor First come out of the insert mode by typing esc key and use any of the following combinations - which appear at the bottom of screen :w - s...

Some more file commands

touch command We have seen how to copy, rename or delete a file. But how would we create a file? Using a text editor? touch command lets you create an empty file. touch file1.txt creates an empty file as can be seen from the above screen shot. But touch command with an existing file will change the access date of a file without opening the file or modifying it in any way.  It just touches the file. more or less? We have seen earlier that cat command will display the contents of a file (similar to type command in Windows) But what happens if the file is large?  cat in that case just displays the entire file and shows back the command prompt without us having time to view the complete file. In these situations, we can use more or less command to display the file, one screen at a time.  more command will display one screen and pause and by pressing Enter key it will scroll by one line.   less command does the same thing. But le...

Shell and bash

Shell and bash You hear the term shell, shell script etc. quite frequently in ubuntu world. So what is a shell? Shell is a command interpreter. It accepts commands from user and interacts with the kernel of the operating system and gives you the output.  A shell can be either a text shell or a graphical shell. All of us use the graphical shell - which lets us create, copy, delete files and many other operations. A graphical shell is easier to use. A text shell or a CLI (command line interface) is a text based command interpreter. When we talk about shell, normally we mean this text based CLI. Linux systems have different shells available for the users. Bourne shell, C shell, bash etc. are the more common ones.  bash - (bourne again shell) is a shell we use very often in Ubuntu systems. To know available shells in your system, just cat /etc/shells We have earlier seen that to start a terminal or a shell we need to press CTRL+ALT+T command. This ope...

File Commands

Redirecting output and piping Before we see file commands, let us see two operations which are quite useful. These are redirecting output (and input) and piping the output. We know that ls command lists the files in current directory. Can we save this listing to a file? Yes. That can be done using > - redirection operator. ls>a.txt redirects the output of ls command to a file called a.txt. Remember that is exactly how we created our file earlier - by redirecting output of cat command to a file. So what we see in screen shot is - output of echo command is redirected to cc.txt. And of course cc.txt has complete path information of our system. Next we pipe the output of echo $PATH  command to cat, so that it gets displayed. Piping is done using "|". It sends the output of a command as input to another command. So output of echo command is sent as input to cat. In the next line we are piping output of echo command to wc command. wc is word count c...

User commands in Ubuntu

Echo command echo command is not exactly related to users. But it just echoes whatever you type. So if you say echo hello - it will display that The first echo line just displays hello.  The second echo command displays my home directory. $HOME is an environment variable which stores current user's home directory. The third echo command displays another environment variable $PATH . PATH indicates path of executable files. Whenever you type some command, the executable file with this command name is searched in the directories given by PATH variable. If the command is not found in any of the paths specified, then we get an error message - command not found.  Now let us put these commands together in a text file and try to run the file. To create a file, we can use vi editor or GUI editor called gedit. Since I am running a web terminal in a windows system, I do not have access to GUI editor.  I use cat command instead. Cat command it displays t...