Some rundowns on Intent

1. What is an intent?

Intent comes from the word “Intention”. In Android, intents are used to communicate asynchronous messages between Android components, either from same application or from other applications.

Example:

  • An activity on interaction with user can request for another activity.
  • An activity of one app can request for taking pictures using inbuilt camera app of your phone.

The Intent class (android.content.intent) in Android is used to display and show our intentions.

We create an object of Intent, passing arguments what we want to do (moving from one activity to another) and pass it to ActivityManager. It will decide when to  start the activity.

Intents can be used to start activities, services, broadcast receivers.

2. How to request for another activity from one activity in code?

Intent has a lot of overloaded constructors.
Intent i = new Intent(source, destination)

source ⇒current context (MyActivity.this)
destination ⇒ requested class (NewActivity.class)

Intent i = new Intent(MyActivity.this, NewActivity.class);
startActivity(i);

Activities which are started by other Android activities are called sub-activities.

3. How to pass messages via intent in code?

An intent can pass data via Bundle.

Example: You want to send the username from one Android activity to next activity.These data can be passed via Bundle by intent.

The reuse of other application components in Android is known as task.

Example: From component of your application, you may need to access Phone Book app of you phone. From your application, you open the PhoneBook app, select one contact, and then return the selected data to your application again.

4. What are the types of intent?

There are two types of intents. These are:-

  • Implicit Intent

Calling using Intents:


Uri num = Uri.parse(“tel:”+phNum)
Intent i = new Intent(Intent.ACTION_CALL, num)
startActivity(i)
Sending sms Intents:


Uri num = Uri.parse(“sms:”+phNum)
Intent i = new Intent(Intent.ACTION_SENDTO, num)
i.putExtra(“sms_body”, “…..”)
startActivity(i)

Accessing Web Links


Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(“fordoxblog.wordpress.com”));
startActivity(i);

  • Explicit Intent
Advertisements

RSentiment

Every system needs continuous improvement. Feedback, positive or negative, plays an important role in that improvement. Humans are fairly instinctive in interpreting the tone of the feedback. But, to teach a machine to understand the same, is highly complex. Various algorithms and tools are available today to automatically identify and categorize opinions of any textual feedback.

The application of sentiment analysis is wide and useful. It gives us a wide overview of opinion regarding various topics. Sentiment analysis provides the ability to quickly understand the impact of any product or system and react accordingly.

In one of my works, I applied sentiment analysis to predict the opinion of students regarding various academic dimensions of an institute. It is published at Springer. I used R for the purpose and was playing around with various packages already existing at CRAN but none of them was working according to my need. So, I conceptualized a tool, which applies text mining techniques to elicit insights from textual data and  published it as an open source package (RSentiment) to CRAN.

Continue reading

Scientifically Beautiful Indian Traditions

For years, Indians have followed innumerable traditions and rituals , majorly religiously but there are beautiful scientific and logical reasons behind these rituals.These logical meanings are ignored as the rituals are passed from generation to generation, sometimes leading us to criticize them as superstitions.These traditions are still in practice by us in day -to-day households. Some of them are listed in this blog post.

 

  • Namaste – Indian way of greeting people

While greeting people, Indian join their palm together to wish “Namaste”. Pressing our palm together presses all the tips of our fingers which in turn creates pressure at ear, eyes and mind and helps us to remember that person.

Namaste-Logo2-890x420

  • Burning Agarbattis during ritual practices

Buring of Agarbattis or incense sticks are part of our Indian culture for years. Ever wondered why? The aura  of these burning sticks not only refreshes our mind and soul, but also cleanses the surrounding air by fighting against germs, bacteria etc.

stick.jpg

  • Eating at floor

Many people used to sit in Sukashan position during lunch and dinner on the floor. This is one the important exercise in yoga where we sit cross legged. This position helps in digestion.

picnic.png

  • Blowing of Shankhas

    The shankha or conch is the shell of sea snail (scientific name Turbinella Pyrum) . In ancient India, the conch was inevitably blown during arati or worship of the deity. The sound of conch would fill the village then, and those who could not make to the temples or were debarred from entering the same could stop by hearing the sound and pray to the Almighty.

It is believed that person who blows the Shanka never develops any respiratory problem. Eminent scientist Acharya Jagadish Chandra Bose has proved that the sound of shankha replaces negativity of the surrounding with serenity.  Shankas are blown during sunrise and sunset so that strong rays of sun don’t obstruct the sound waves. These waves destroy the bacteria and cleanses the surrounding.

shankha

Continue reading

Android Dictionary

Learning a new language is hard because it requires new cognitive frameworks. While learning a new language, you will come across new terms and words whose meaning you need to learn along with it’s usage. With age and experience, your vocabulary will develop and that will serve as a fundamental tool in communication.

Developing Android apps is similar to leaning a new language all together. Although it primarily uses the Java language for coding, one also has to know the underlying Android framework, the structure on which it is based. Following is a list of some of the online available dictionaries which you may refer to whenever required during your learning or implementation process. The more you use it, you’ll reinforce your knowledge and your memory.

 

Introducing Views

Views are the rectangular shaped, basic building block of a layout or user interface that assures some content on the screen. Views – as the name suggests – is used to view any content on the screen. Without it, it is not possible to display anything on the screen. Thus it is the most essential element of any UI screen.

Views can me of various geometric shapes and sizes. These can be combined to form advanced views. All of these views and combinations form the layout of a screen. Here, I give an example of a view, complete with markings for easier understanding.

WhatsApp Image 2016-08-17 at 8.33.00 PM (1)

WordBin Login Page

This is a screenshot of one of our published apps, WordBin. Here I have marked the views in black. These views when grouped together, formed the Login page (layout). Any such combination forms different layouts.

Here, it is clearly visible that the bounds of the views can both me transparent (view marked “1”) due to it’s background, and can also be clearly distinguished (view marked “2”). Using the various properties of the views and using its features we can design any view as per our requirement.

Talking from a more programmatic point of view, View is an Android Base class from which all other types of views inherit.

Most Commonly Used Android Views:

  • TextView
  • EditText
  • Button
  • ImageView
  • ImageButton
  • CheckBox
  • RadioButton
  • RadioGroup
  • ListView
  • Spinner
  • AutoCompleteTextView

Since in Java, the norm is to follow Camel Case, the above classes follow such specifications. The above are just a few library classes of the vast Android library. Developers can define custom views and layouts as well on XML files. These custom views must be bound by some Android rules, but mostly they are flexible.

XML (Extensible Markup Language) files store the design of each user interface and  Java is required to implement it’s interactivity with other Java files. Android Studio is the most commonly used IDE to design the entire application.

The intention of this post was to give a basic idea of the View element of Android. Professional developers don’t memorize everything. Looking up information and implementing them properly is a key part of the job. But to implement properly, one should have their concepts clear. There are online sources which I found very useful while developing applications and which I used to refer to for implementing codes. But most of these concepts were not clearly stated in those sources. I learnt these over time after developing many applications. Hope this helps you.

Subscribe and keep checking for more posts soon.

Thank You.

Reading multiple files.

By now, we all are familiar with reading csv file into R. But, what if there is a block of operations that we need to perform on multiple files? I think that will be a quite tiring job to include each csv every time and run the script.

The best and the easiest way will be to automate the whole process for which we need to design a Rscript.

Step 1:  We begin by listing all the files in my working directory. We have specified the file format by mentioning “.csv ” as pattern.

file_list <- list.files(pattern="*.csv")

Step 2:  After listing, it’s time to find the number of csv files in the directory.

l <- length(file_list)

Step 3: Now, by running a loop, we can access the content of each csv file.

for (i in 1:l) {
  x <- read.csv(temp[i])
}

Yeah! by now we can read the contents of all the files automatically by running the  script.

Now, if you have the csv files with different number of columns and you want to work with specific columns of all the csv files, but the column number of that column is different in different csv file, it will be a quite difficult situation to handle.

Say, for an example, I have three files names “A.csv”, “B.csv” and “C.csv” and I want to work with “Entropy” Column of all the csv files, but it occurs as 3rd column in “A.csv”, 5th column in “B.csv” and and 9th column in “C.csv”. As there is no uniformity in the column number, it cannot be accessed dynamically as desired. This will be a great fallback in automating the process. So, what I would do is:

## checking if the name of the column is "Entropy"
if(collnames(x)[j]=="Entropy") {

  ## saving the original column name for future use
  y[j]<-colnames(x)[j]

  ## changing the name of the jth column
  colnames(x)[j]<-'test'

  ## accessing the column by it's name
  ent [q]<-entropy(table(x$test))

  ## again assigning the original column name to the jth column
  colnames(x)[j]<-y[j]
}

So, finally my RScript looks like this :

file_list <- list.files(pattern="*.csv")
l<-length(file_list)

for (i in 1:l) {
    
  x <- read.csv(temp[i])
  y <- names(x)

for( j in 1:ncol(x)) {

  if(collnames(x)[j]=="Entropy") {
     y[j]<-colnames(x)[j]
     csv<-c(csv,temp[i])
     colnames(x)[j]<-'test'
     ent [q]<-entropy(table(x$test))
     colnames(x)[j]<-y[j]
  }
  q<-q+1
}

df <- data.frame(csv=character(), entropy=character() , stringsAsFactors=FALSE)
df <- cbind(csv,attribute)

Hope this helps and saves lots of time and effort. Happy Mining!

Output Text To Console

There are various ways to output text in RStudio.

 

Without New Line:

cat("#9....")
cat("times")

Output:

#9....times

With New Line:

print("Happy Birthday")
print("dearie")

Output:

Happy Birthday
dearie

If you want to add any more methods to the list, please leave a comment below.

Adding Multiple Comments in R

We all will accept the fact that we all have required at least once in our life to comment the previously written codes.

To comment a single line in RStudio, we can put “#” before each line.

But when we want to comment multiple lines at one go, we can use following in RStuido:-

  • In Windows: CTRL + SHIFT + C

  • In OS-X: COMMAND + SHIFT + C