Tuesday, 24 July 2012

Setup Android SDK With Eclipse
I started using Android SDK recently and I like it a lot. In this article I tell you how to setup the SDK to work in combination with the Eclipse ADT plugin.


1)If you want to download Eclipse you can download it from http://www.eclipse.org/downloads/.
2)You can download Android SDK for your system
3)You will need latest version of JDK to be able to use Android SDK with Eclipse.
   You can download the latest JDK from JAVA's website at        
    http://java.sun.com/javase/downloads/index.jsp.

Installing Android SDK

 Lets see how it works out when we click Lets see how it works out when we click 'installer_r20.0.1-windows.exe' installer for windows
1. When you click the '.exe' installer windows will ask you if you want to save the file or cancel download as seen in the figure below. Select Save File and wait for the file to download.




2. After the file has downloaded run the setup file. You will be shown the welcome screen. Press Next on this screen.




3. If Jave SE Development Kit (JDK) is not found on your system you will be asked to download it from the Java website. Click on Visit java.oracle.com to install the JDK. Without the JDK you cannot continue with the installation. If you already have JDK installed you can proceed to Step 4.




4. After Installing the JDK you can press the Back button and then click Next button on the Android SDK installer. Now you will see that the previously disabled 'Next' button is enabled. Click the Next button to proceed forward.
5. You will now be asked to choose the directory where you want to install Android SDK tools. Remember the name and location of the SDK directory on your system as you will need to refer to the SDK directory later, when setting up the ADT plugin and when using the SDK tools from command line. In this article we use the default SDK location C:\Program Files\Android\android-sdk.




After choosing the location where the SDK will be installed press Next.
6. Next you will be asked to Choose if you want to make a Start Menu Folder. If you do not want to make a Start Menu Folder select the box Do not create shortcuts. If you want to create Start Menu Folder than just click Install.




The Installation will start and after installation you will be asked to press Next button to proceed to the Finish page where you can decide to Start SDK Manager

lets install Android Development Tools in Eclipse.

Installing the ADT Plugin for Eclipse

As stated on the Android's Developer website "Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment in which to build Android applications. It extends the capabilites of Eclipse to let you quickly set up new Android projects, create an application UI, debug your applications using the Android SDK tools, and even export signed (or unsigned) APKs in order to distribute your application. In general, developing in Eclipse with ADT is a highly recommended approach and is the fastest way to get started with Android."

Follow the steps below to install the ADT plugin in Eclipse:
1. Eclipse must be installed on your system to preoceed further from here

2. I use Eclipse 3.6 (Helios). Start Eclipse and then select Help > Install New Software...


3. Click Add, on the top right corner. A small Add Repository Dialog appears. In this Dialog enter "ADT Plugin" for the Name and the following URL for the Location:
https://dl-ssl.google.com/android/eclipse/
If you have trouble downloading the plugin, try using 'http' in the Location URL, instead of 'https'. Now ClickOK.
4. Next you will be back in the Available Software dialog. In this dialog select the checkbox next to Developer Tools and click Next.
5. Eclipse will look for dependencies and then show you the next window. Here you can see a list of the tools to be downloaded. Click Next.
6. Next you will be shown the license agreements. Read and accept the license agreements, then clickFinish.
7. After the installation finishes, restart Eclipse.

Configuring the ADT Plugin

The next step is to modify the ADT preferences in Eclipse to point to the Android SDK. 
1. Start Eclipse. Select Window > Preferences... to open the Preferences panel.




2. In the left panel you can see Android. Select Android. You can now click Browse... to locate the folder where you have downloaded the Android SDK. Select the folder which contains the tools folder.
3. Now you are all done to move to the final step before you can start development for Android SDK. ClickApply, then OK.

Adding Platforms and Other Components

This is the last step before you can start developing your apps for Android SDK. In this step we will see how to use Android SDK and AVD Manager to download the important SDK components for the development environment. The steps involved are
1. Start Eclipse, select Window > Android SDK and AVD Manager or we can go to the root directory (in this tutorial 'C:\Program Files\Android\android-sdk')where we have installed the Android SDK and double-click the 'SDK Manager.exe' file.
2. You can now use the graphical user interface to browse through the SDK repository and select new or updated components. The Android SDK and AVD manager then installs the selected components in your SDK environment. This can be seen as in the image below:







Monday, 23 July 2012

                              Flex

I am going to begin another tutorial that deals with Flash. However, since I am a big advocate of open source, I am going to use a combination of flex_sdk, ActionScript, and Eclipse 3.4 Ganymede. LuminicBox is also suppose to work for logging, but currently I haven't got that to work yet with Eclipse 3.4. I am also using Windows Vista for this tutorial.

First, you need to download the needed software:

1) Download Flex 4-Beta 1.

2)Unzip the Flex 4 and place it in a good location.  Select the right mouse button on your MyComputer icon, and open the advanced system and environmental variables section. Add this to your Class Path or Path variable: C:\flex_4\bin. This path should point to the location where your bin directory is in of the flex sdk files you just unzipped.

3) You should create a new variable called FLEX_HOME and put this as the valueC:\flex_4. That path should also be to the location to your flex sdk directory.

4) After you set these variables, press okay. If you want to compile from the command prompt, you can use this command. mxmlc Flex4App.mxml where Flex4App.mxml is the file you are compiling. After your swf file is created, you can view it by typing: Flash Player Flex4App.swf in your command prompt. You can also right click the file and open it with a browser. The browser might have a warning before allowing you to view the file, but if you press okay and you have flash installed in your browser, you should also see the output.

5)You also need to have eclipse 3.4 Ganymede installed. You can see my prior posts on installing eclipse.

6) After you have opened up eclipse, you should go to help->software updates and select the available software tab. Select Add Site and input this url:http://aseclipseplugin.sourceforge.net/updates/. Select the needed files and press install.

7) You should also download Luminicbox for logging.

8)To develop in the Action Script environment using Eclipse, you should open the Window Action Script window by selecting window->open perspective-> other in eclipse. Then select the ActionScript2 perspective and hit okay.

9) You should now create an ActionScript Project and you can do this by selecting File->new ActionScript Project. Call the project Action2Project and Click Next. To use the flex 4 sdk, you can select Add Linked Folder. You can browse to the lib directory of your flex_4 and add it as a linked folder. Click Finish when you are done.

10) Now you need to create your build.xml file.  Select on the Action2Project with the right mouse button and select New->Other.  Under the general folder, select file and then select next. Give the file the name of build.xml and click finish.

11) You need to tell this project to use the build file we just created. You can do this by right clicking on the Action2Project Name and select properties. Select the Builders section on the left and click new. From here, select Ant Build and then hit okay. In this window, give it a name like Action2Project builder. Now for the build file field in the main tab, simply browse the workspace and select the Action2Project. You'll see the build file that you just created show up in the right pane. Select that file and hit okay. The base directory needs to be setup similarly. Browse the workspace, select the Action2Project, and hit okay. Press Okay to finalize your changes.You'll now see that you have two builders specified. You can deselect the AS2 Builder and it will warn you that it could have bad side-effects but it won't so just hit OK. Then close the builders window by clicking OK. Eclipse may try to build the file but it will fail. The console output in the bottom will be your friend when reporting problems with compiling.

12) Now we need to create a class. Right click on the src directory and select File -> New ActionScript Class. Give it a name of TestActionScript and click finish. For ActionScript files, you have to wrap the code with package{ }. So your code should look like this:

package {
public class TestActionScript{

}
}


If you see a red line under package, you can ignore this. Apparently the plugin doesn't recognize this yet.

13) Create another file called test.mxml in the src file. I am going to show you how you can use your build.xml file to compile both of these type of files to convert them to swf files.

14) Paste the following code in your test.mxml file:

test.mxml

<?xml version="1.0" encoding="utf-8"?>
<fx:Application
xmlns="http://ns.adobe.com/mxml/2009"
xmlns:fx="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo">

<mx:VBox>
<fx:Button label="Gumbo Button"/>
<mx:Button label="Halo Button" />

<fx:ButtonBar id="orangeToggleBar" requiresSelection="true">
<fx:dataProvider>
<fx:ArrayCollection source="[Flash, Director, Catalyst,
ColdFusion]" />
</fx:dataProvider>
</fx:ButtonBar>
</mx:VBox>
</fx:Application>


15)Paste the following code in your TestActionScript.as class:

TestActionScript.as

package {
import com.luminicbox.log.*;
import flash.display.Sprite;
import flash.display.Graphics;
import flash.display.Shape;

public class TestActionScript extends Sprite{

public var log:Logger;

public function TestActionScript(){

log = new Logger("Tester");
log.addPublisher( new ConsolePublisher() );

var child:Shape = new Shape();
child.graphics.beginFill(0xccffff);
child.graphics.drawRoundRect(0, 0, 100, 100,20);
child.graphics.endFill();
this.addChild(child);

log.log( "Hello world log" );
log.debug( "Hello debug" );
log.info( "Hello info" );
log.warn( "Hello warn" );
log.error( "Hello error" );
log.fatal( "Hello fatal" );

log.log(["test","test2"]);
}
}
}


16) Paste the following code in your build.xml file:

build.xml

<project name="Action2Project" default="Compile Swf" basedir=".">
<property environment="env" />
<property name="mxmlc" location="${env.FLEX_HOME}\bin\mxmlc.exe"/>

<target name="Compile Swf" depends="Compile MXML">
<exec executable="${mxmlc}" dir="." failonerror="true">
<arg line="src/TestActionScript.as"/>
<arg line="-source-path C:\LuminicBox\LB.Log"/>
<arg line="-default-size 400 300"/>
<arg line="-output bin/Action2Project.swf"/>
</exec>
</target>

<target name="Compile MXML">
<exec executable="${mxmlc}" dir="." failonerror="true">
<arg line="src/test.mxml"/>
<arg line="-source-path C:\LuminicBox\LB.Log"/>
<arg line="-default-size 400 300"/>
<arg line="-output bin/test.swf"/>
</exec>
</target>

</project>


In your build.xml file, you have to make sure your source-path points to your LuminicBox directory.

17) To make ant aware of your build.xml file, Click on Window > Show View > Other.
Then expand the Ant folder and select Ant in it. Then click OK.
In the bottom, select the Ant tab and then drag the build.xml file from the left window in to the tab down to the Ant window. You'll see the items we specified show up in a nice tree view in that viewer.

18)Click on the build.xml file in the ant view and your code should compile.

19)In eclipse you can view your .swf file by opening the bin folder. You might have to refresh the directory first. You can refresh it by selecting the right mouse button and selecting refresh. You should see two swf files. Select them and you should see their output.

You are suppose to see your your logs in the LuminicBox, but that isn't working yet. 



Wednesday, 11 July 2012


             -:PHP List:-
Installation steps:-
First of all
->install Wamp server 2.2
in this section we will learn how to start, restart the WAMP server and test a simple php program. You will be familiarized with the WAMP server directories and the different configuration options it provides.After successful installation you can see a folder inside the C:\ drive named wamp. Inside the folder there will be many files and folders like: alias, apps, bin, lang, logs, scripts, tmp etc. We will develop PHP programs inside the www folder e.g C:\wamp\www. Now start the wamp server either by double click on the icon appear on the desktop or go to start option and then select wamp server. After selecting the wamp server you can see an icon will appear (which looks like a speedometer of vehicle) on the tray (extreme right side of the task bar) as shown in the figure below.

Initially the icon will be partially red, it means no service is currently running, click on it and a popup menu will appear, select the start all services option. Now the color of the icon should change to white that means all services are running, if the color of the icon appears half yellow then all services are not running then follow either of these steps:
  • Left click on the icon, select apache, go to service option, click start/resume service
  • Left click on the icon, select MySQL, go to service option, click start/resume service

Another option is left click on the icon and select restart all services.
To check whether the server is running or not again click on the icon of wamp server and select Localhost option. Home page of the server will be displayed in Internet Browser.  



Unpack the downloaded zip file, This will create a directory called phplist-x.y.x where x.y.z is the version you unpacked.
In this directory, there will be a directory public_html which contains the directory lists. Upload the "lists" directory into a directory that can be accessed via the web. The rest of the files are for reference only and are not needed for phplist to work.
Create a database for phpList to use. phpList needs the name of that database during the installation process.
Configure phpList by opening the config.php file in the lists/config directory in your preferred text editor

Begin with these settings: config.php file in the lists/config 
1.     $database_host: where is the mySQL database installed (on what server)? The most common (and simple) installation has the database on the same server (computer) as the web site's server. Therefore, the default value of "localhost" is probably ok.
2.     $database_name: on the host (above) what is the name of the database where phpList's tables have been installed?
3.     $database_user: what is the name of the database user that has Insert, Update, Delete privileges on the above database?
4.     $database_password: what is this user's password?
phpList gives you the option during installation of choosing a table prefix. This means that should more than one of your applications require a table named "user" the database will not be confused by an ambiguous name; there's only one "user" table. By default phpList prefixes all of its tables: phplist_
This also makes 
backups easier.

Note :- These are some important settings
define ("TEST",0);

define ("MANUALLY_PROCESS_QUEUE",1);

define("MAILQUEUE_BATCH_SIZE",0);

define("MAILQUEUE_BATCH_PERIOD",2700);
(note: I have found 2700 helps more than the default of 3600 to keep things running longer when you have a large batch)

define('MAILQUEUE_THROTTLE',0);

define("USE_LIST_EXCLUDE",0);

define('MAILQUEUE_AUTOTHROTTLE',0);

define("PHPMAILERHOST",'mail.yourdomain.com'); 
define ("MANUALLY_PROCESS_BOUNCES",1);
define('CLICKTRACK',1);
define('CLICKTRACK_SHOWDETAIL',1);
note
·         Make sure your php extensions can be loaded
o    Open your php.ini file.
o    Search for 'extension_dir'.
o    You should find something like : extension_dir = "C:/wamp/bin/php/php5.2.6/ext/"
o    If this line has been commented out (;extension_dir = "C:/wamp/bin/php/php5.2.6/ext/") , please uncomment the line by removing the semi-colon ';' from the beginning of the line.
o    If you don't find this line, please add this line with the path of your extension directory in there.
·         Load the IMAP Extension
o    Check your extension folder and make sure the php_imap.dll is there.
o    Open your php.ini file.
o    Search for 'extension=php_imap.dll'
o    If this line has been commented out (;extension=php_imap.dll), please uncomment the line by removing the semi-colon ';' from the beginning of the line.
o    If you don't find this line, please add it under the extension_dir line.
·         Restart your server

Wednesday, 4 July 2012

JFree Chart Portlet In Liferay 
note:-
image
these are two important jars


This example uses resource serving to generate PNG image from a portlet




ChartPortlet.java:

import java.io.IOException;
import java.io.OutputStream;

import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.ResourceURL;

import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 * Portlet implementation class ChartPortlet
 */
public class ChartPortlet extends GenericPortlet {

    public void init() {
        viewJSP = getInitParameter("view-jsp");
    }
    
    
    @Override
 public void serveResource(ResourceRequest request, ResourceResponse response)
   throws PortletException, IOException {
 
  // super.serveResource(request, response);
     String resourceID = request.getResourceID();
      
        if (resourceID.equals("chart-image")) {
         response.setContentType("image/png");
            OutputStream out = response.getPortletOutputStream();
     
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            dataset.addValue(1.0, "Row 1", "Column 1");
            dataset.addValue(2.0, "Row 1", "Column 2");
            dataset.addValue(3.0, "Row 1", "Column 3");
     
            dataset.addValue(4.0, "Row 2", "Column 1");
            dataset.addValue(5.0, "Row 2", "Column 2");
            dataset.addValue(6.0, "Row 2", "Column 3");
     
            try {
                JFreeChart chart = ChartFactory.createBarChart("Bar Chart", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, false);
     
                if (chart != null) {
                    CategoryPlot plot = (CategoryPlot) chart.getPlot();
                    BarRenderer renderer = (BarRenderer) plot.getRenderer();
                    renderer.setItemMargin(0.0);
                    ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
                }
            } catch (Exception e) {
                System.err.println(e.toString());
            } finally {
                out.close();
            }
     

        }

 }



 public void doView(
            RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {
        
  // Pass the resource URL as a Java bean named resourceUrl to the view JSP
        ResourceURL chartUrl = renderResponse.createResourceURL();
        chartUrl.setResourceID("chart-image");
        String resourceUrl = chartUrl.toString();
        renderRequest.setAttribute("resourceUrl", resourceUrl);

  
        include(viewJSP, renderRequest, renderResponse);
    }

    protected void include(
            String path, RenderRequest renderRequest,
            RenderResponse renderResponse)
        throws IOException, PortletException {

        PortletRequestDispatcher portletRequestDispatcher =
            getPortletContext().getRequestDispatcher(path);
        

        portletRequestDispatcher.include(renderRequest, renderResponse);
        
    }
 
    protected String viewJSP;

}




view.jsp:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ page import="javax.portlet.*"%>

<portlet:defineObjects />
<img src="${resourceUrl}"/>




portlet.xml:
<?xml version="1.0"?>

<portlet-app
 version="2.0"
 xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
>
 
 <portlet>
  <portlet-name>chartportlet</portlet-name>
  <display-name>ChartPortlet</display-name>
  <portlet-class>ChartPortlet</portlet-class>
  <init-param>
   <name>view-jsp</name>
   <value>/html/chartportlet/view.jsp</value>
  </init-param>
  <expiration-cache>0</expiration-cache>
  <supports>
   <mime-type>text/html</mime-type>
   <portlet-mode>VIEW</portlet-mode>
  </supports>
  <portlet-info>
   <title>ChartPortlet</title>
   <short-title>ChartPortlet</short-title>
   <keywords></keywords>
  </portlet-info>
  <security-role-ref>
   <role-name>administrator</role-name>
  </security-role-ref>
  <security-role-ref>
   <role-name>guest</role-name>
  </security-role-ref>
  <security-role-ref>
   <role-name>power-user</role-name>
  </security-role-ref>
  <security-role-ref>
   <role-name>user</role-name>
  </security-role-ref>
 </portlet>
</portlet-app>