Saturday 13 September 2014

HB Blog 20: Working on some project? Have a look on some helpful websites.

1) 1000Projects
Click here : http://1000projects.org/
Description : This website is developed by WikiHands.This site provides complete project with source codes as well as gives a platform for students to upload there own projects as well.This site also have its own forum for Q&A.

2) Java2s
Click here : http://www.java2s.com/
Description : This site is useful when you are looking for some examples regarding any specific concept especially related to java.  

3)J2EEBrain.com | Java J2EE Tutorials
Click here : http://www.j2eebrain.com/
Description : The large collection of tutorials,references,source codes, projects and PDF study materials about Java & J2EE.

4)Vogella
Click here : http://www.vogella.com/
Description : Vogella provides training and support in the area of Eclipse, Java and Android development and well as the Git version control system.There are free tutorials to learn about these topics.

5) CodeProject - For those who code
Click here : http://www.codeproject.com/
Description : CodeProject site is formed to provide developers with a place to meet and exchange ideas.It is a good site for professional developers.

Friday 12 September 2014

HB Blog 19: Sample code for converting "Speech" to "Text" and vice-versa.

       Speech technology allows hands free use of the mobile.Android APIs provide us a large number of packages which includes class and methods that makes easy to convert "Speech" to "Text" and vice-versa.I have shown a sample of both speech to text as well as text to speech conversion.

Refer the below link for complete sample code(Speech To Text):-
Download Sample Code
Download Apk File
Refer the below link for complete sample code(Text To Speech):-
Download Sample Code
Download Apk File

Speech To Text
 
Have a look on few code snippets,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
//Just,fire an intent to start the speech recognition activity.
//This Starts an activity that will prompt the user for speech and send it through //a speech recognizer. 
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
startActivityForResult(intent, RESULT_SPEECH);
//get the result using onActivityResult and set to required text view
//you can also provide pending intent if one is provided.
ArrayList<String> text = data.
getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
textView.setText(text.get(0));
Text To Speech
 
Have a look on few code snippets,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
//Use OnInitListener of to signal the completion of the TextToSpeech engine initialization  
textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener(){
            @Override
            public void onInit(int status){
                if(status != TextToSpeech.ERROR){
                    textToSpeech.setLanguage(Locale.UK);
                }
            }
        });
//Then use "speak" method that speaks the string using the specified queuing strategy and speech parameters.
public void speakText(View view){
        String toSpeak = et_txt.getText().toString();
        textToSpeech.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
    }

Tuesday 9 September 2014

HB Blog 18: Famous Personalities.

         We can't imagine life without these people and their successful journey of work. I personally idolize them.
Charles Babbage,(December 26, 1791 – October 18, 1871) - Father of the computer
He was an English polymath.He was a mathematician, philosopher, inventor and mechanical engineer, who is best remembered now for originating the concept of a programmable computer.He is considered as "father of the computer".

Alexander Graham Bell (March 3, 1847 – August 2, 1922)  - Telephone Inventor
He was an eminent Scottish-born scientist, inventor, engineer and innovator who is credited with inventing the first practical telephone.

Sir Timothy John "Tim" Berners-Lee (born 8 June 1955) - World Wide Web Inventor
He also known as "TimBL", is an English computer scientist, best known as the inventor of the World Wide Web.

Lawrence Gordon Tesler (born April 24, 1945) - Copy and Paste Inventor
He also known as "Larry Tesler", is a computer scientist who works in the field of human–computer interaction.Copy and paste was first implemented in 1973-1976 by Tesler and Tim Mott, while they were working for Xerox Palo Alto Research Center.

Lawrence "Larry" Page (born March 26, 1973) - Google co-founder
He is an American business magnate and computer scientist who is the co-founder of Google, alongside Sergey Brin.
Page is the inventor of PageRank, the foundation of Google's search ranking algorithm.

Sergey Mikhaylovich Brin (born August 21, 1973)  - Google co-founder
He is an American computer scientist and internet entrepreneur who, together with Larry Page, co-founded Google.

William Henry "Bill" Gates,(born October 28, 1955) - Microsoft co-founder
He is an American business magnate, philanthropist, investor, computer programmer, and inventor.Gates is the former chief executive and chairman of Microsoft, the world’s largest personal-computer software company, which he co-founded with Paul Allen.

Mark Elliot Zuckerberg (born May 14, 1984)  - Facebook co-founder
He is an American computer programmer and Internet entrepreneur. He is best known as one of five co-founders of the social networking website Facebook. 

Andrew E. "Andy" Rubin - Android Inc co-founder
He is the co-founder and former CEO of both Danger Inc. and Android Inc. He was formerly Senior Vice President of Mobile and Digital Content at Google until March 2013, where he oversaw development of Android, an open-source operating system for smart phones.Rubin has seventeen patents for his inventions.

Steven Paul "Steve" Jobs (February 24, 1955 – October 5, 2011) - Apple Inc co-founder
He was an American entrepreneur, marketer, and inventor, who was the co-founder, chairman, and CEO of Apple Inc.

Sunday 7 September 2014

HB Blog 17: Basics of Web Services.

Firstly, a very basic but an important question is what is a Web services?
A Web service is a method of communication between two electronic devices over a network.They are the integral part of Mobile development.
Web service are of various types SOAP, REST, and XML-RPC.
Have a look over below component diagram of web services,
There are 3 major interface Client,Server,Database.
  • Client can be anything mobile,browser,script .In short who can make a request to server is client.
  • Server can be any machine that have facility to execute server pages.All the web services files are stored at server.
  • Database is storing the data provided by client or already filled in.

Lets see, SOAP Vs REST Vs XML-RPC,

SOAP – "Simple Object Access Protocol"

  • Accessing a SOAP web service is super easy with any language that has SOAP libraries to help you.
  • All you have to do is point your code to the url of the web service’s WSDL, and you’re off and running, making remote calls as you would to a local object.
  • PHP5 has a SOAP library that will handle your client and server, but you have to create your own WSDL.

REST – "Representational State Transfer"

  • REST Web Services consist of using plain HTTP to make method calls and you get XML or JSON in response.
  • The RESTful way is to use GET, POST, PUT, and DELETE calls to implement CRUD (Create, Read, Update, Delete) operations on an object.
    • GET : Read
    • POST : Create
    • PUT : Update
    • DELETE : Delete
  • It accepts HTTP parameters, either in the query string request, or in the query string of a POST request.
  • REST style web services are what power AJAX applications. The browser makes a request to a REST web service via JavaScript’s XMLHttpRequest object. The browser then parses the xml and replaces elements in the page with the data.
  • REST is really quite simple. If you would like to connect to some REST Web Services below in article.

XML-RPC – "Remote Procedure Call uses XML"

  • XML-RPC protocol is really simple. You pass requests which contain the method name, and parameters formatted in xml that defines their data types. The response comes back with similar xml data.
  • XML-RPC servers are easier to implement than SOAP when using scripting languages such as php which have very loose data typing.
  • PHP-PEAR library that you use to handle XML-RPC client and server scripting.

Thursday 4 September 2014

HB Blog 16: Simple Android Widgets. [Tutorial]

Widgets are an essential aspect of home screen customization.
Widgets could be of many types such as information widgets, collection widgets, control widgets and hybrid widgets. App Widgets are miniature application views that can be embedded in other applications (such as the Home screen) and receive periodic updates. These views are referred to as Widgets in the user interface, and you can publish one with an App Widget provider. An application component that is able to hold other App Widgets is called an App Widget host.
The screenshot below shows the Music App Widget.
Refer the below link for complete sample code:-
Download Sample Code
Download Apk File

The below screenshots shows my sample widget.I prefer less graphical UI for my sample widget as it makes more understandable and code remains simple.But,at the same time remember to have attractive UI for your widget,as it attracts user more.
Creation of application widgets needs following files:-
1)Widget - XML file
2)Widget - Layout file
3)Widget - Java file
4)Widget - Manifest file

Though, I have provide complete sample code, I will still give some important code snippets.

1)Widget - XML file
1
2
3
4
5
6
7
8
9
//Place Xml file into res->Xml folder.
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:minWidth="146dp"
   android:updatePeriodMillis="0"
   android:minHeight="146dp"
   android:initialLayout="@layout/activity_main">
</appwidget-provider>

2)Widget - Layout file
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
//The layout that you want to design for widget
 <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="@string/website"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="18dp"
        android:text="@string/btn_follow" />

3)Widget - Java file
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
//Extend AppWidgetProvider class and override one or more of the onUpdate(Context, AppWidgetManager, int[]), onDeleted(Context, int[]), onEnabled(Context) or onDisabled(Context) methods to implement your own AppWidget functionality. 
 @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
    {
        for(int i = 0; i < appWidgetIds.length; i++){
            int currentWidgetId = appWidgetIds[i];
            String url = "http://www.harshalbenake.blogspot.com";
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse(url));
            PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);
            views.setOnClickPendingIntent(R.id.button1, pending);
            appWidgetManager.updateAppWidget(currentWidgetId, views);
            Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();
        }
    }

4)Widget - Manifest file

1
2
3
4
5
6
7
8
9
//most important change in manifest file is that, there is not need for any activity, only receiver will be needed.
 <receiver android:name="MainActivity" >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/mywidget" />
        </receiver>
After completing your coding and running it on your device, you can go to your widget section and add your created widget to the dsktop or homescreen.

Now if you are using above sample, just tap on the widget button that appears , to launch the browser. But before that please make sure that you are connected to the internet.

Wednesday 3 September 2014

HB Blog 15: Few helpful websites for those who are addicted to IT.

1) Android Asset Studio
Click here : http://romannurik.github.io/AndroidAssetStudio/
Description : This website allow to quickly and easily generate icons from existing source images, clipart, or text in all required density  sizes.

2) Pulse
Click here : http://www.pulse.me
Description : Pulse allows one to customize the news reading experience, easily explore compelling professional content, and share stories to the favorite social networks.
3) Hack Forums
Click here : http://www.hackforums.net/
Description : Hack Forums is a hacking as well as programming related forum & blogging site.
4) Tutorialspoint
Click here : http://www.tutorialspoint.com/
Description : Free tutorials and reference manuals online site with thousands of working examples, which you can use in your day to day software development.
5) MakeUseOf
Click here : http://www.makeuseof.com/
Description : MakeUseOf is an online site for technology magazine featuring cool websites, cool software and internet tips on a daily basis.

HB Blog 14: Use Android Sensors To Detect Noise/Sound.

How to detect noise and set a noise threshold , when this noise/sound frequency cross threshold in Android?

Refer the below link for complete sample code:-
Download Sample Code
Download Apk File


Have a look on few code snippets,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//Define runnable thread again and again detect noise
 private Runnable mSleepTask = new Runnable() {
               public void run() {
                   //Log.i("Noise", "runnable mSleepTask");
                   start();
               }
       };

  //Create runnable thread to Monitor Voice
       private Runnable mPollTask = new Runnable() {
               public void run() {
                       double amp = mSensor.getAmplitude();
                       //Log.i("Noise", "runnable mPollTask");
                       updateDisplay("Monitoring Voice...", amp);
                       if ((amp > mThreshold)) {
                             callForHelp();
                             //Log.i("Noise", "==== onCreate ===");
                       }
                       // Runnable(mPollTask) will again execute after POLL_INTERVAL
                       mHandler.postDelayed(mPollTask, POLL_INTERVAL);
               }
       };
       
  //onCreate
       @Override
       public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               // Defined SoundLevelView in main.xml file
               setContentView(R.layout.activity_main);
               mStatusView = (TextView) findViewById(R.id.status);
               // Used to record voice
               mSensor = new SoundMeter();
               mDisplay = (SoundLevelView) findViewById(R.id.volume);
               PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
               mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "NoiseAlert");
       }

//start Noise monitoring
   private void start() {
               mSensor.start();
               if (!mWakeLock.isHeld()) {
                       mWakeLock.acquire();
               }
               //Noise monitoring start
               // Runnable(mPollTask) will execute after POLL_INTERVAL
               mHandler.postDelayed(mPollTask, POLL_INTERVAL);
       }

Tuesday 2 September 2014

HB Blog 13: Wireless Printing Using Google Cloud Print Integration.

How to add printing functionality to any Android application by integrating with Google Cloud Print?

Note:- The instructions below are for incorporating Google Cloud Print into your app when run on Android 4.3 and below.
When on Android 4.4 and above, your app should instead use the Android Print Framework, which includes support for Google Cloud Print.

It requires to include simple GCP Dialog intent implementation code in the project, start the intent from the code and pass the document to be printed.

Refer the below link for complete sample code:-
Download Sample Code
Download Apk File

Begin by creating two new files in the Android project, print_dialog.xml and PrintDialogActivity.java, as per the above sample code.
Next, add <uses-permission android:name="android.permission.INTERNET" /> to the application manifest.
Finally, add the following intent,
1
2
3
4
Intent printIntent = new Intent(this, PrintDialogActivity.class);
printIntent.setDataAndType(docUri, docMimeType);
printIntent.putExtra("title", docTitle);
startActivity(printIntent);
In the code above, replace the three parameters as follows:
  • docUri - URI of the document to be printed
  • docMimeType - MIME type of the document to be printed.
  • docTitle - title of the printed document, arbitrary string that will be shown on the GCP management console as the print job's title

Monday 1 September 2014

HB Blog 12: Facebook - what happens in just 60 seconds.[Infographic]

As Facebook keeps on growing fast, and more and more social media users log on every day, the flow of data generated by Facebook becomes even more bigger.

What happens in the world of Facebook in just 60 short seconds?
  • 500 new users join Facebook
  • - 100,000 friend requests are sent
  • 243,000 photos are uploaded on Facebook
  • - 50,000 links are shared on Facebook
  • - 3,3 million items are shared on Facebook
  • - More than 3 million likes happen on Facebook
  • - And more than 15 million likes happen on other websites (like buttons, share, …)
  • Facebook now has 1.28 Billion users.
  • 30 Million business now have a Facebook Page.
  • Almost 400 million mobile users only.
  • Twice as many people now watch videos on Facebook in their feed compared to just six months ago.
  • GAAP Income of $791 Million.
  • 829 Million daily active users.
  • Businesses spent $2.66 billion on Facebook advertising, an increase from $2.27 billion last quarter.

HB Blog 11: Google - what happens in just 60 seconds.[Infographic]

For most people, Google is a part of their everyday lives. Whether you are searching for something, checking your email, downloading an app or uploading a video YouTube, it’s all with the help of Google.

What happens in the world of Google in just 60 short seconds?
  • $123,109 earned in revenue
  • 1,157,407 Google Play app downloads
  • $2,283 in Android app revenue
  • 694 Clock-to-calls (Clicking a number to call directly from an ad)
  • 642 Google+ new users
  • 4 Chromebooks shipped
  • 20,653,660 ad impressions
  • 199 people search for a coupon
  • $16,404 spent on research and development
  • 2,400,000 search queries