Thursday, May 9, 2013

Useful "Run" (windows+R) commands for windows lovers.

1. Accessibility Controls - access.cpl
2. Accessibility Wizard - accwiz
3. Add Hardware Wizard - hdwwiz.cpl
4. Add/Remove Programs - appwiz.cpl
5. Administrative Tools - control admintools
6. Automatic Updates - wuaucpl.cpl
7. Bluetooth Transfer Wizard - fsquirt
8. Calculator - calc
9. Certificate Manager - certmgr.msc
10. Character Map - charmap
11. Check Disk Utility - chkdsk
12. Clipboard Viewer - clipbrd
13. Command Prompt - cmd
14. Component Services - dcomcnfg
15. Computer Management - compmgmt.msc
16. Control Panel - control
17. Date and Time Properties - timedate.cpl
18. DDE Shares - ddeshare
19. Device Manager - devmgmt.msc
20. Direct X Troubleshooter - dxdiag
21. Disk Cleanup Utility - cleanmgr
22. Disk Defragment - dfrg.msc
23. Disk Management - diskmgmt.msc
24. Disk Partition Manager - diskpart
25. Display Properties - control desktop
26. Display Properties - desk.cpl
27. Dr. Watson System Troubleshooting­ Utility - drwtsn32
28. Driver Verifier Utility - verifier
29. Event Viewer - eventvwr.msc
30. Files and Settings Transfer Tool - migwiz
31. File Signature Verification Tool - sigverif
32. Findfast - findfast.cpl
33. Firefox - firefox
34. Folders Properties - control folders
35. Fonts - control fonts
36. Fonts Folder - fonts
37. Free Cell Card Game - freecell
38. Game Controllers - joy.cpl
39. Group Policy Editor (for xp professional) - gpedit.msc
40. Hearts Card Game - mshearts
41. Help and Support - helpctr
42. HyperTerminal - hypertrm
43. Iexpress Wizard - iexpress
44. Indexing Service - ciadv.msc
45. Internet Connection Wizard - icwconn1
46. Internet Explorer - iexplore
47. Internet Properties - inetcpl.cpl
48. Keyboard Properties - control keyboard
49. Local Security Settings - secpol.msc
50. Local Users and Groups - lusrmgr.msc
51. Logs You Out Of Windows - logoff
52. Malicious Software Removal Tool - mrt
53. Microsoft Chat - winchat
54. Microsoft Movie Maker - moviemk
55. Microsoft Paint - mspaint
56. Microsoft Syncronization Tool - mobsync
57. Minesweeper Game - winmine
58. Mouse Properties - control mouse
59. Mouse Properties - main.cpl
60. Netmeeting - conf
61. Network Connections - control netconnections
62. Network Connections - ncpa.cpl
63. Network Setup Wizard - netsetup.cpl
64. Notepad - notepad
65. Object Packager - packager
66. ODBC Data Source Administrator - odbccp32.cpl
67. On Screen Keyboard - osk
68. Outlook Express - msimn
69. Paint - pbrush
70. Password Properties - password.cpl
71. Performance Monitor - perfmon.msc
72. Performance Monitor - perfmon
73. Phone and Modem Options - telephon.cpl
74. Phone Dialer - dialer
75. Pinball Game - pinball
76. Power Configuration - powercfg.cpl
77. Printers and Faxes - control printers
78. Printers Folder - printers
79. Regional Settings - intl.cpl
80. Registry Editor - regedit
81. Registry Editor - regedit32
82. Remote Access Phonebook - rasphone
83. Remote Desktop - mstsc
84. Removable Storage - ntmsmgr.msc
85. Removable Storage Operator Requests - ntmsoprq.msc
86. Resultant Set of Policy (for xp professional) - rsop.msc
87. Scanners and Cameras - sticpl.cpl
88. Scheduled Tasks - control schedtasks
89. Security Center - wscui.cpl
90. Services - services.msc
91. Shared Folders - fsmgmt.msc
92. Shuts Down Windows - shutdown
93. Sounds and Audio - mmsys.cpl
94. Spider Solitare Card Game - spider
95. SQL Client Configuration - cliconfg
96. System Configuration Editor - sysedit
97. System Configuration Utility - msconfig
98. System Information - msinfo32
99. System Properties - sysdm.cpl
100. Task Manager - taskmgr
101. TCP Tester - tcptest
102. Telnet Client - telnet
103. User Account Management - nusrmgr.cpl
104. Utility Manager - utilman
105. Windows Address Book - wab
106. Windows Address Book Import Utility - wabmig
107. Windows Explorer - explorer
108. Windows Firewall - firewall.cpl
109. Windows Magnifier - magnify
110. Windows Management Infrastructure - wmimgmt.msc
111. Windows Media Player - wmplayer
112. Windows Messenger - msmsgs
113. Windows System Security Tool - syskey
114. Windows Update Launches - wupdmgr
115. Windows Version - winver
116. Wordpad - write

Tuesday, January 3, 2012

Android Views – TextView



Text view is most commonly used control across applications. It is used to display texts. In android, not only text, you can also display html text in text view. Texts in Text views can be modified and formatted easily.  

There are two ways how you can add text view into a layout,

1.       Through designer, by drag and drop onto layout or just edit xml file and type it manually.
2.       Add text view on the fly through code.

What all you can do with text view? Well, here is the list of few important things.

1.       Change font type – use built-in font types (limited) or refer to external font file. To use external font file, add font file (.ttf) into assets folder and import into text view using TypeFace object.            
      ex:  Typeface newtypeface = Typeface.createFromAsset(getAssets(), "Amazone BT.ttf");

2.       Change font style – bold, normal, italic (anyone at a time, multiple style only through text as html).

3.       Change font size – using a float value and unit to use.When no unit is specified, android defaults to pixels. Preferred units are dp/dip and sp. (pixels are not preferred in android as it varies across devices).

4.       Change text color – you can change text color and text background color. Text color attribute accepts only hexadecimal values when assigned in layout file. If you are adding color from code, it’s better to use Color class of android or manually create your color using hexadecimal values and add it. Text background accepts both color values and images.

5.       Text appearances – create your own style and refer it or use android built-in text appearances.

6.       Modify text dynamically through code.

7.       Bind events and act accordingly. Ex: click event, touch event, focus event etc...

Text appearance defines how your text should look to user. There are few ways how you can modify your text.

1.       Styled and formatted in layout file.
2.       If needs are simple, android’s built-in styles can be used.
3.       If you want to make some really attractive formatting and re-use it, then define the style by yourself in style.xml file and refer it either in layout file or through code using resource id. Ex: R.style.yourstyle 

Here is an example of how you can use text view in android.

TextViewDemoActivity.java

package com.coffeewithtechie.textviewdemo;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TextViewDemoActivity extends Activity {

                TextView tv4;
                TextView tv5;
                TextView tv6;
               
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
         tv4 = (TextView)findViewById(R.id.textView4);       
        Typeface newtypeface = Typeface.createFromAsset(getAssets(), "Amazone BT.ttf"); // font file referred from assests folder
         tv4 .setTypeface(newtypeface);
       
         tv5 = (TextView)findViewById(R.id.textView5);
         tv5 .setText(Html.fromHtml("
this is html string
")); // html text, only basic html tags works, styles doesn't work
       
         tv6 = (TextView)findViewById(R.id.textView6);
//        tv6.setOnClickListener(new OnClickListener() {
//                                           
//                                            @Override
//                                            public void onClick(View v) {
//                                                            // TODO Auto-generated method stub
//                                                            String text = tv6.getText().toString(); // get textview text value
//                                                            text = "you clicked me!";
//                                                            tv6.setText(text); // modify text dynamically
//                                            }
//                            });
       
         tv6.setOnTouchListener(new OnTouchListener() {
                                               
                                                @Override
                                                public boolean onTouch(View v, MotionEvent event) {                                                                
                                                                String text =  tv6.getText().toString(); // get textview text value
                                                                text = "you touched me! at x:"+ event.getX()+" y:"+ event.getY()+" positions";
                                                                 tv6.setText(text); // modify text dynamically
                                                                return true;
                                                }
                                });
       
        //dynamic textview
        TextView tvDynamic = new TextView(this);
        tvDynamic.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tvDynamic.setText("Dynamic text view, styled from code");
        tvDynamic.setTextColor(Color.MAGENTA);      
        tvDynamic.setTextSize(TypedValue.COMPLEX_UNIT_MM, 5f); // font size in millimeter
       
        LinearLayout layoutparent = (LinearLayout)findViewById(R.id.layoutparent);
        layoutparent.addView(tvDynamic); //adding newly created text view to layout
       
        tvDynamic.setTextAppearance(this, R.style.CustomTextViewStyle);
       
    }
}

Main.xml

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/layoutparent"
    android:orientation="vertical" >

    <TextView android:background="#aaaaaa"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"  />

    <TextView
        android:background="@drawable/backgroun"
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="styled in xml"
        android:textColor="#887722"
        android:textSize="30dp"  
        android:textStyle="italic"
        android:typeface="serif"  
         />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Styled with built in android styles"
        android:textAppearance="@android:style/TextAppearance.Widget.TextView.PopupMenu" />
       
       <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Styled with custom styles"
        android:textAppearance="@style/CustomTextViewStyle" />
           
       <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text with font type from external source"
        android:textSize="25dp"
        /> 

       <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"       
        /> 
       <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"     
        android:text="Touch me!"        
        />
</LinearLayout>

Values/styles.xml

create a style.xml file under values folder and the below code

xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTextViewStyle">
    <item name="android:textColor">#ff0000<item>
    <item name="android:textSize">26sp<item>  
    <item name="android:textStyle">bold<item>        
style>   
resources>

This is how it looks when executed.
output - before touch event

Text modifies dynamically after touching “Touch me!” text view.

output - after executing touch event 

Monday, January 2, 2012

Creating your first android application – Hello Android



It’s easy and simple to create android application using eclipse. To begin with,

1.       Open eclipse.

2.       Click on file - > new project, you should see options something similar to the image.



If not don’t panic, it doesn’t mean you can’t create android project. Select Other… from the list or just press Ctrl+N, eclipse opens a new project creation wizard.
New Project Wizard
Expand Android , select Android Project option and click Next                                                                                                         
3.       Enter name of the project say, HelloAndroid  and leave the remaining options untouched. Once you are done with giving name to project click Next.                                          

wizard - project name


4.       Now in the list of android SDKs available, select the android sdk you want to target your project and click Next.

wizard - target android sdk


5.      In this final stage of project creation, eclipse asks you to give a package name for your project. Give your  package name, for ex, to my project am gonna use “com.coffeewithtechie.helloandroid” as package name. Leave the default launcher activity name and Minimum SDK, which by default is your target build version  (you can always change by selecting one from the dropdown), untouched.Once you are done with your changes click on Finish. Eclipse creates a project for you in its workspace.

Note  : Do not create any test project at this time.

wizard - final screen, package name
  

Click expand your project in project explorer, each project you create will have default folders and files necessary for the android project.

android project - folder structure

Src –  all your source code goes into src folder.

Gen – contains system generated R.java file, which holds id’s of all your project resources.

Assests – contains files and folders which are part of your project but not used as embedded resources. Android doesn’t generate any id for the asset folder contents. It behaves like a file system, they can be iterated over, listed and discovered just like files. You have to use path to access files in assets folder or AssetManager is used to get list of files and folders in assets folder.

Bin – contains class file, dex file, compressed resource file and generated apk file. Your application will be compiled into apk file and it is uploaded in market place for distribution so that users can download and install your application.

Res – all your application resources will be dumped in this folder, this is further divided to different type of resources. All image resources will go into drawable folders, applications UI will go into layout folder (layout defines how your app should look to user), color values, text values goes into values folder. An id will be generated for whatever included in resources folder in R.java file, so that it can be referred in code using id.

AndroidManifest.xml – it is a configuration file for the project, all project wide settings are done in this file, features and permissions required are specified in this file. It also specifies min and max sdk version to support, targeting sdk, supporting device types, version name, version code etc.. an entire post will be dedicated for configuring manifest file.

Proguard.cfg – if your application uses obfuscation, android provides code obfuscator proguard to use for obfuscation. Any configuration specific to obfuscation goes into this file, and this file will be referred from default.properties file

Project.properties – it’s a system generated file and will be modified whenever you do changes to your project in eclipse say, adding a project reference, jar reference etc.

Whenever a project is created, eclipse creates launcher activity, if specified, and a layout file used by launcher activity.

HelloAndroidActivity.java
package com.coffeewithtechie.helloandroid;
import android.app.Activity;
import android.os.Bundle;

public class HelloAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); // main layout set as default for launcher activity
    }
}

Main.xml
xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

LinearLayout>



All the String resources goes into String.xml file. Double click Open strings.xml file in values folder under res. Select the resource element hello(String). Edit its value in the right side of the designer to “Hello Android!” and save (Ctrl+s). you can also edit the xml file directly (if you are comfortable editing xml file), to do so, click on tab strings.xml next to Resources tab and edit xml values. Refer fig below to find string.xml tab.
String.xml 
Now, it’s time to run our project.
Right click on project -> point to Rus as and select Android application



If there are no emulators running, eclipse starts a new emulator which is compatible with the project if any exists, else you need to create an emulator before running the project. check out this link To know how to create emulator, http://coffeewithtechie.blogspot.com/2011/12/creating-and-running-android-emulator.html .
If everything goes right, project gets deployed into emulator successfully and you can see the output similar to the image.

Emulator - Project output

Wait for the series of posts on using different types of views and layouts in android.





Thursday, December 29, 2011

Creating and Running Android Emulator from Eclipse


Emulators are good to test our android project when there is no device available with us. Emulator will emulate the actual android operating system but with certain limitations. How do we create and run them?

Am gonna write in detail about creating and running emulator from eclipse. If you have already installed ADT plugin in eclipse (if not see my post http://coffeewithtechie.blogspot.com/2011/12/install-and-configure-android-in.html) you must see AVD Manager under Windows menu.

1.       Click on the AVD Manager to open Android Virtual Device (AVD) Manager Window.




2.       Click on New button. It opens AVD creator window similar to the image below.

3.       Type in the Name for your emulator.
4.       Select the Android version you are going to target for your emulator, when you click on target dropdown it gives you a list of available sdk’s from your system to select. Choose anyone and proceed to next field.     
                

5.       CPU/ABI option is disabled by default, but when you select target sdk, it gets filled with the cpu associated with that sdk, usually (ARM(armeabi)).

6.       Specify the size of your sd card to be created for your emulator. Value must be integer eg, 1024 and you can select any one of the units (KiB, MiB, GiB) from the dropdown next to it. Skip the file option.

7.       If you want to take snapshot from your emulator check snapshot enable option. Am gonna leave unchecked for this post.

8.       Size determines the size of your emulator to be created in pixels. Either you can choose from built in size options which corresponds to real device screen sizes, else if you want bigger or smaller than that, always feel free to choose Resolution option and enter your own width and height. Built in size options varies based on the target platform selected. See the table below for available built in options.



Note: creating emulators of big size can go out of your monitor’s range. Make sure that emulator fits your window screen.

9.       Hardware lets you modify default hardware properties of your emulator. When you choose target sdk it’ll be filled with the default values for that platform. New option at the corner lets you add some more properties based on your requirement and availability.



10.   Click on Create AVD to create emulator.

Eclipse takes some time to create emulator and when done, newly created emulator will be listed in AVD Manger. Select your emulator and click Start to run emulator. When clicked on start, launch options pop-up appears, you can configure your launch options using this pop-up, just ignore it and click on launch for now to run emulator.

Emulator booting


Emulator after booting - in portrait mode

To change emulator’s orientation,

a.       Turn on numlock.

b.      Press and hold numlock and press number 7 from num keys.


Emulator – landscape mode



Wednesday, December 28, 2011

Install and Configure Android in Eclipse


To all curious programmers and newbies, who wants to get their hands dirty in android platform must have these things mentioned below in your system.

a.     Android SDK.
b.     Eclipse - one of the recommended IDE for android development.
c.      JDK - to compile your android code (which will be in java).
d.     ADT plugin for eclipse.

So, how do we get these things into our system?? Ok, will explain step by step about installing and configuring android. First let me detail about downloading android sdk.

Downloading Android SDK

Android sdk requires windows xp and higher versions of xp. Once you are ready with this, you can go ahead and download android sdk from android developers site, here is the link to download http://developer.android.com/sdk/index.html

You can either download zip or .exe file, .exe file is recommended for windows users. Make sure to install it in right path, as we need this path to configure eclipse. Once you are done with downloading SDK move to next step downloading eclipse.

Downloading Eclipse for Android

Eclipse is an IDE used to develop android applications. It provides an easy to use interface and lots and lots of features which makes developer life easy. I am gonna write about using eclipse in another post, for now lets concentrate on downloading eclipse into our system. You can download eclipse from this link 
When you click on this link, you’ll be taken to eclipse website and a list of available eclipse will be displayed. Now here is the confusion. Which IDE to download? To solve the confusion here is the solution. Android recommends few packages,

1.     Eclipse IDE for Java Developers
2.     Eclipse Classic
3.     Eclipse IDE for Java EE Developers

Download any one of the above packages and install. We completed half of the task. Next is to install our favorite JDK.

Downloading JDK (Java Development Kit)

(Skip this step if you already have java in your system. To test, open command prompt and type java –version command. If you are able to see java, then java is already installed in your system and you can save some Bandwidth by skipping this step)
Most of them may be familiar with java, for those who are new to java can download jdk from Oracle site, http://www.oracle.com/technetwork/java/javase/downloads/index.html .

Download the latest available jdk and install in your system. Once done with installation, go to command prompt and type java –version command. If you are able to see java, then java is installed successfully in your system. If you see any error message, don’t panic, if you know that java is installed in your system the error message might simple indicate that path variable is not set for java. Set the path variable and you are done.

Finally we are at the final step of downloading things. Remember we have not yet configured android sdk in eclipse which you guys are waiting for. 

Downloading ADT (Android Development Tools) for Eclipse

ADT is a plugin for eclipse which is essential to use eclipse for android development. How do we download it into eclipse?? We already have eclipse in our system (if not, refer downloading eclipse section above). Open eclipse by clicking ecplise.exe icon from your eclipse installation path. For the first time, it asks for workspace with pre-populated path, if you are happy with that location click ok else change the path and click ok. Eclipse opens and a nice welcome page welcomes you. We are not concerned with this now. What we need is to install ADT plugin. It involves series of steps,

1.     In menu bar, click on help -> install new software.

2.     Install window opens, which looks like this                 

                                                                           

3.     Copy and paste this url, https://dl-ssl.google.com/android/eclipse/ in the text box before “Add” button and click on “Add”.            
        

4.     A pop-up opens and give a name to this url and click ok.                              
Note: If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).



5.         In the Available Software dialog, select the checkbox next to Developer Tools and click Next. If you expand developer tools, you can see what are the addins are being installed into eclipse.

6.       In the next window, you'll see a list of the tools to be downloaded. Click Next.

7.       Read and accept the license agreements, then click Finish.
Note: If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
    
    8. When the installation completes, restart Eclipse.

After restarting eclipse click on windows menu, you should see something similar to this.           
               

If you can see Android SDK Manager and AVD Manager options, then we are in the right path.
We are done with installing all the softwares and tools necessary for android development. Now lets configure eclipse to use android sdk.

Configuring Eclipse for Android

It involves modifying the ADT preference to point to the Android SDK Directory.
 1.     Select Window > Preferences... to open the Preferences panel.



 2.  Now you should see Android in your preferences. Eclipse sometime tries to point to android sdk path automatically, if it is not pointing to sdk location then add your sdk location.

 
 
3.     If everything goes right, you will see all the available versions of sdk listed.

4.     Click Apply and ok to save and close preferences.

We are done with installing and configuring android in eclipse. Let’s try and create one simple android application in next post.