Tuesday, 14 January 2014

Android code to zoom an image in ImageView

 Java Code
-----------------------------------------------------------------------------------

package com.example.calender;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class April extends Activity {
 ImageView imageDetail;
 Matrix matrix1 = new Matrix();
 Matrix savedMatrix = new Matrix();
 PointF startPoint = new PointF();
 PointF midPoint = new PointF();
 float oldDist = 1f;
 static final int NONE = 0;
 static final int DRAG = 1;
 static final int ZOOM = 2;
 int mode = NONE;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.april);
  imageDetail = (ImageView) findViewById(R.id.imageView1);
  /**
   * set on touch listner on image
   */
  imageDetail.setOnTouchListener(new View.OnTouchListener() {

   @Override
   public boolean onTouch(View v, MotionEvent event) {

    ImageView view = (ImageView) v;
    System.out.println("matrix=" + savedMatrix.toString());
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:

     savedMatrix.set(matrix1);
     startPoint.set(event.getX(), event.getY());
     mode = DRAG;
     break;

    case MotionEvent.ACTION_POINTER_DOWN:

     oldDist = spacing(event);

     if (oldDist > 10f) {
      savedMatrix.set(matrix1);
      midPoint(midPoint, event);
      mode = ZOOM;
     }
     break;

    case MotionEvent.ACTION_UP:

    case MotionEvent.ACTION_POINTER_UP:
     mode = NONE;

     break;

    case MotionEvent.ACTION_MOVE:
     if (mode == DRAG) {
      matrix1.set(savedMatrix);
      matrix1.postTranslate(event.getX() - startPoint.x,
        event.getY() - startPoint.y);
     } else if (mode == ZOOM) {
      float newDist = spacing(event);
      if (newDist > 10f) {
       matrix1.set(savedMatrix);
       float scale = newDist / oldDist;
       matrix1.postScale(scale, scale, midPoint.x, midPoint.y);
      }
     }
     break;

    }
    view.setImageMatrix(matrix1);

    return true;
   }

   @SuppressLint("FloatMath")
   private float spacing(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return FloatMath.sqrt(x * x + y * y);
   }

   private void midPoint(PointF point, MotionEvent event) {
    float x = event.getX(0) + event.getX(1);
    float y = event.getY(0) + event.getY(1);
    point.set(x / 2, y / 2);
   }
  });

 }

}

Thursday, 9 January 2014

Code to make a phone call in Android


Java code:

  Intent callIntent = new Intent(Intent.ACTION_CALL);
                                    callIntent.setData(Uri.parse("tel:0123456789"));
                                    startActivity(callIntent);




Add  Code to AndroidManifest.xml :

<uses-permission android:name="android.permission.CALL_PHONE" />

After the code :
 <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

Android code to open a URL in Browser

 Intent intent = new Intent(Intent.ACTION_VIEW,
                                 Uri.parse("http://www.techwizardblog.blogspot.com"));
                                 startActivity(intent);

How to Create Option Menu In Android



We can create an Option Menu with following :

  1. Create a menu xml
  2. Register the menu in Activity
  3. Write code to Handle the Clicks on menu items

1: Create xml for menu


     Create a new folder named "menu" in res folder (if menu folder is not there in res folder)
     inside this  Menu folder create .xml    file

here I have created option.xml   xml for the option menu in  above  Image

           <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
   
     <item android:id="@+id/ChangeColor"
          android:icon="@drawable/setting"
          android:title="Settings"
          />
    <item android:id="@+id/phoneInformation"
          android:icon="@drawable/phone"
          android:title="My Phone Information" />
   
    <item android:id="@+id/callInfo"
          android:icon="@drawable/callinfo"
          android:title="In and Out Call Info" />

   
    <item android:id="@+id/email"
          android:icon="@drawable/mail"
          android:title="Mail to Developer" />
   
 </menu>

android:id
A resource ID that's unique to the item, which allows the application can recognize the item when the user selects it.
android:icon
An image  to use as the item's icon.
android:title
A tittle to show.


2: Register In Activity


Override onCreateOptionMenu   method and inflate the .xml (here options.xml) inside method

            @Override
                     public boolean onCreateOptionsMenu(Menu menu) {
                            MenuInflater inflater = getMenuInflater();
                            inflater.inflate(R.menu.options, menu);
                            return true;
                     }


3: Handle Click Events



When the user selects an item from the options menu (including action items in the action bar), the system calls your activity's onOptionsItemSelected() method. This method passes the MenuItem selected. You can identify the item by calling getItemId(), which returns the unique ID for the menu item (defined by the android:id attribute in the menu resource

 To Handle click events override  onOptionsItemSelected  method


                               @Override
                     public boolean onOptionsItemSelected(MenuItem item) {
                         // Handle item selection
                        
                      
                         switch (item.getItemId()) {
                             case R.id.ChangeColor:
                                                              // write code to execute when clicked on this option
                                                                return true;   


                             case R.id.phoneInformation:
                                                             // write code to execute when clicked on this option
                                                             return true;
                            
                              case R.id.callInfo:
                                                              // write code to execute when clicked on this option
                                                             return true;
                                
                             case R.id.email:
                                                            // write code to execute when clicked on this option
                                                              return true;
                                
                               default:
                                                   return super.onOptionsItemSelected(item);
                         }
                     }


                    

Option Menu Full Source Code


public classMainActivity extends Activity
{
            @Override
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
        }


       // Create Option Menu
     @Override
        public boolean onCreateOptionsMenu(Menu menu) 

        {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.options, menu);
            return true;
        }


         // Handle click events
         @Override
          public boolean onOptionsItemSelected(MenuItem item) 

           {
                         // Handle item selection
                        
                      
                         switch (item.getItemId()) {
                             case R.id.ChangeColor:
                                                              // write code to execute when clicked on this option
                                                                return true;   


                             case R.id.phoneInformation:
                                                             // write code to execute when clicked on this option
                                                             return true;
                            
                              case R.id.callInfo:
                                                              // write code to execute when clicked on this option
                                                             return true;
                                
                             case R.id.email:
                                                            // write code to execute when clicked on this option
                                                              return true;
                                
                               default:
                                                   return super.onOptionsItemSelected(item);
                         }
                     }

}

Sending Email In Android



Intent i = new Intent(Intent.ACTION_SEND);
                                   i.setType("message/rfc822");
                                   i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"gbss.mumbai@gmail.com"});
                                   i.putExtra(Intent.EXTRA_SUBJECT, "Inquiry");
                                   i.putExtra(Intent.EXTRA_TEXT   , "I will be glad if you respond on my email");
                                   try {
                                             startActivity(Intent.createChooser(i, "Sending mail..."));
                                          
                                     }
                                   finally {
                                      
                                            // Code to execute when unable to send Email
                                        }

Thursday, 31 October 2013

Install Postgres & PgAdmin3 in UBUNTU

INSTALLATION
----------------------------------------------------------------------------------------------------------------------
STEP 1 : Before we install postgres,  perform a quick update of the apt-get repository :

apt-get update

(Type these commands in terminal)

STEP 2 : Once apt-get has updated go ahead and download Postgres :

sudo apt-get install postgresql postgresql-contrib


STEP 3 : Install pgadmin3 from UBUNTU Software Center
           
YOU ARE READY TO BEGIN....!!!
 ----------------------------------------------------------------------------------------------------------------------
USAGE :
  
STEP 4 : Open Terminal
  
 sudo su postgres

Enter your pc password

createdb database-name

psql database-name

create user kiran with password  'kiran';

(Add your own username & password in place of kiran)
 

STEP 5 : Open Another Terminal

pgadmin3 

 STEP 6 : Click Add a Connection to server(First Button in GUI)

  Name      : database-name
  Host        : localhost
  Port         : 5432
 Maintdb   : postgres
 username : kiran
 password : kiran
   
   YOU ARE DONE......!!!



 

Sunday, 27 October 2013

Install TASM in Ubuntu

Step 1 : First we will install an windows emulator called dosbox.

sudo apt-get install dosbox


Step 2 :

Download the packages for  


Create a directory for tasm in your home directory and extract files into that directory.If you are unable to extract type this in your terminal and try again

sudo apt-get install unrar


Install Java in Ubuntu

Just run the following command & you can easily get java installed..

REQUIREMENTS :
  • Internet Connection
  • Superuser Login

Command :

sudo apt-get install openjdk-7-jdk

Thursday, 24 October 2013

Easiest way to install NS2 in Ubuntu

For NS2 installation I browsed a lot on net but  found very lengthy time consuming procedures.Also some of them didnt worked out for me.Then I somehow succeded in installating NS2 through terminal with only two commands.Hereis a very simple procedure to install NS2 in Ubuntu.

REQUIREMENTS :
SuperUser Login
Internet Connection

PROCEDURE :

STEP 1: Installation of NS2

sudo apt-get install ns2

STEP 2: Installation of NAM(GUI)

 sudo apt-get install nam

Install Xampp in Ubuntu

* Step 1: Download
Xampp for linux : http://www.apachefriends.org/en/xampp-linux.html
(Check out which version you are downloading & respectively make changes in the version names in the following commands )
----------------------------------------------------------------------------
* Step 2: Installation
After downloading simply type in the following commands:

    Go to a Linux shell and login as the system administrator root:

    sudo su (or just su for lower versions than ubuntu 13.04)

    Change the permissions to the installer

    chmod 755 xampp-linux-1.8.3-1-installer.run

    Run the installer

    ./xampp-linux-1.8.3-1-installer.run

That's all. XAMPP is now installed below the /opt/lampp directory.
----------------------------------------------------------------------------
* Step 3: Start
To start XAMPP simply call this command:

/opt/lampp/lampp start

You should now see something like this on your screen:

Starting XAMPP 1.8.3...
LAMPP: Starting Apache...
LAMPP: Starting MySQL...
LAMPP started.

Ready. Apache and MySQL are running.


----------------------------------------------------------------------------
* Step 4: Test
OK, that was easy but how can you check that everything really works? Just type in the following URL at your favourite web browser:

http://localhost

Now you should see the start page of XAMPP containing some links to check the status of the installed software and some small programming examples.

----------------------------------------------------------------------------
* Step 5: Copy & read rights to htdocs folder :
sudo chmod 777 /opt/lampp/htdocs
chmod -R 777 /opt/lampp/htdocs/




      CONGRATS...Your Job Is Done...!!!!
----------------------------------------------------------------------------
Start  Xampp Service :
 /opt/lampp/lampp start

Stop  Xampp Service :
 /opt/lampp/lampp stop

----------------------------------------------------------------------------

For PhpMyAdmin: Type in browser
 localhost/phpmyadmin


----------------------------------------------------------------------------

Tuesday, 8 October 2013

Contact Form & Admin Login to view Contact details

--------------------------------------------------------------------------------------
DATABASE
---------------------------------------------------------------------------------------
Create a database with name tour . Now copy paste the code below in a text file and save it with the name tour.sql .Import the sql file in your database created.

---------------------------------------------------------------------------------------------------------------
 -- phpMyAdmin SQL Dump
-- version 3.5.2.2
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Oct 06, 2013 at 03:39 PM
-- Server version: 5.5.27
-- PHP Version: 5.4.7

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `tour`
--

-- --------------------------------------------------------

--
-- Table structure for table `admin`
--

CREATE TABLE IF NOT EXISTS `admin` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(30) DEFAULT NULL,
  `passcode` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `admin`
--

INSERT INTO `admin` (`id`, `username`, `passcode`) VALUES
(1, 'test', 'test');

-- --------------------------------------------------------

--
-- Table structure for table `contact`
--

CREATE TABLE IF NOT EXISTS `contact` (
  `name` varchar(30) NOT NULL,
  `email` varchar(30) NOT NULL,
  `message` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `contact`
--

INSERT INTO `contact` (`name`, `email`, `message`) VALUES
('Kiran Shinde', 'djkiru07@gmail.com', 'A good Website...Keep it up!'),
('Rupesh Shinde', 'djruki007@gmail.com', 'Excellent...try to improve user interace'),
('Prasad Mane', 'pmane@gmail.com', 'I liked it.'),
('Durvesh Shinde', 'dshinde@gmail.com', 'Helped me to plan my trip..good effort.');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
--------------------------------------------------------------------------------------------------------------- 


--------------------------------------------------------------------------------------
CONFIG.PHP(config.php)
---------------------------------------------------------------------------------------

<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "tour";

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");

?>

---------------------------------------------------------------------------------------------------------------   
--------------------------------------------------------------------------------------
CONTACTS.HTML : (contacts.html)
---------------------------------------------------------------------------------------

<!DOCTYPE html>
<html lang="en">
<head>
  <title>TourDeMumbai</title>
  <meta charset="utf-8">
<style type="text/css">
label
{
font-weight:bold;

width:100px;
font-size:14px;

}
.box
{
border:#666666 solid 1px;

}
</style>
<script type="text/javascript">
function validateForm()
{
var name=document.forms["contact"]["name"].value;
var email=document.forms["contact"]["email"].value;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var message=document.forms["contact"]["message"].value;


if (name==null || name=="")
  {
  alert("First name must be filled out");
  name.focus;
  return false;
  }
if (!filter.test(email))
  {
    alert('Please provide a valid email address');
    email.focus;
    return false;
  }
 if (message==null || message=="")
  {
  alert("Message must be filled out");
  message.focus;
  return false;
  }
}
</script>

</head>
 <body>
<div align="center">
<div style="width:400px; border: solid 1px #333333; " align="left">
<div style="background-color:#333333; color:#FFFFFF; padding:3px;"><b>Contact Form</b></div>


<div style="margin:30px">

<form id="contacts-form" name="contact" action="contact.php" method="post" onSubmit="return validateForm()";>
    <table>
     <tr>
      <td>Your Name:</td>
      <td><input type="text" name="name" value=""/></td>
     </tr>
     <tr>
       <td>Your E-mail:</td>
       <td><input type="text" name="email" value=""/></td>
      </tr>
     <tr>
       <td>Your Message:</td>
       <td><textarea name="message"></textarea></td>
     </tr>
    </table>
     <div align="center"><input type="submit" value="Send">
       <input type="reset" value="Clear"></div>
     </form>
<div style="font-size:11px; color:#cc0000; margin-top:10px" align="center"><?php echo $error; ?></div>
</div>

</body>
</html>

--------------------------------------------------------------------------------------------------------------- 

--------------------------------------------------------------------------------------
CONTACT.PHP : (contact.php)
---------------------------------------------------------------------------------------

<?php
// Create connection
$con=mysqli_connect("127.0.0.1","root","","tour");

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


$sql="INSERT INTO contact (name, email, message)
VALUES
('$_POST[name]','$_POST[email]','$_POST[message]')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "Thank you for contacting us.";



mysqli_close($con);

?> 
--------------------------------------------------------------------------------------------------------------- 

--------------------------------------------------------------------------------------
LOGIN.PHP : (login.php)
---------------------------------------------------------------------------------------

<?php

include("config.php");
session_start();
$error="Enter your Credentials";

if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from form

$myusername=addslashes($_POST['username']);
$mypassword=addslashes($_POST['password']);


$sql="SELECT id FROM admin WHERE username='$myusername' and passcode='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$error="Enter Credentials";
$count=mysql_num_rows($result);


// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
$_SESSION['login_user']=$myusername;

header("location: welcome.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Tour The Mumbai</title>
  <meta charset="utf-8">
 
  <style type="text/css">
label
{ font-weight:bold;
  width:100px;
  font-size:14px;
}
.box
{border:#666666 solid 1px;}
</style>
</head>
 <body>
<div align="center">
<div style="width:300px; border: solid 1px #333333; " align="left">
<div style="background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>


<div style="margin:30px">

<form action="" method="post">
<table cellspacing="10" cellpadding="5"><tr>
<td>UserName  </td><td><input type="text" name="username" class="box"/></td><tr/><br>
<tr><td>Password  </td><td><input type="password" name="password" class="box" /></td></tr>
</table><br>
<div align="center"><input type="submit" value=" Submit "/></div>

</form>
<div style="font-size:11px; color:#cc0000; margin-top:10px" align="center"><?php echo $error; ?></div>
</div>
 
</body>
</html>
---------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------
WELCOME.PHP : (welcome.php)
---------------------------------------------------------------------------------------
<?php
include('lock.php');
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>TourDeMumbai</title>
  <meta charset="utf-8">
  </head>
 
 <body>
   <a href="logout.php"><input type="button" style=" background-color:#999" border="1" value="Logout"/></a>
   <h2>Contact <span>Details</span></h2>

  <?php
    $con=mysqli_connect("127.0.0.1","root","","tour");
    // Check connection
    if (mysqli_connect_errno())
     {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }

    $result = mysqli_query($con,"SELECT * FROM contact");

    echo "<table border='5' cellspacing='5' cellpadding='5' bordercolor='#000000' >
    <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Message</th>
    </tr>";

    while($row = mysqli_fetch_array($result))
    {
     echo "<tr>";
     echo "<td>" . $row['name'] . "</td>";
     echo "<td>" . $row['email'] . "</td>";
     echo "<td>" . $row['message'] . "</td>";
     echo "</tr>";
    }
    echo "</table>";

    mysqli_close($con);
 ?>
          
</body>
</html>

---------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------
LOGOUT.PHP : (logout.php)
---------------------------------------------------------------------------------------

<?php
session_start();
if(session_destroy())
{
header("Location: login.php");
}
?>

---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
LOCK.PHP : (lock.php)
---------------------------------------------------------------------------------------

<?php
include('config.php');
session_start();
$user_check=$_SESSION['login_user'];

$ses_sql=mysql_query("select username from admin where username='$user_check' ");

$row=mysql_fetch_array($ses_sql);

$login_session=$row['username'];

if(!isset($login_session))
{
header("Location: login.php");
}
?>
---------------------------------------------------------------------------------------------------------------









Friday, 27 September 2013

Touch Counter Android App




  ----------------------------------------------------------------
                 XML CODE
 ----------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Total is : 0"
    android:textSize="45dp"
    android:layout_gravity="center"
    android:gravity="center"
     android:id="@+id/tvDisplay"
    />


<Button
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:id="@+id/bAdd"
    android:text="Add"
    android:layout_gravity="center"
    android:textSize="20dp"
    android:onClick="perfrom"
    />
<Button
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:id="@+id/bSub"
    android:layout_gravity="center"
    android:text="Sub"
    android:textSize="20dp"
    android:onClick="perfrom"
    />
</LinearLayout>




  ----------------------------------------------------------------
              JAVA CODE
 ----------------------------------------------------------------



package com.example.newapp;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
  
       int counter;
       Button add ,sub;
       TextView display;
       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              counter=0;
              add = (Button) findViewById(R.id.bAdd);
              sub = (Button) findViewById(R.id.bSub);
              display = (TextView) findViewById(R.id.tvDisplay);
             
              add.setOnClickListener(new View.OnClickListener() {
                    
                     @Override
                     public void onClick(View v) {
                           // TODO Auto-generated method stub
                           counter++;
                           display.setText("Total : "+counter);
                     }
              });
             
        sub.setOnClickListener(new View.OnClickListener() {
                    
                     @Override
                     public void onClick(View v) {
                           // TODO Auto-generated method stub
                           counter--;
                           display.setText("Total : "+counter);
                     }
              });
       }

       @Override
       public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.main, menu);
              return true;
       }

}


  ----------------------------------------------------------------
OUTPUT
 ----------------------------------------------------------------



 



Total Pageviews

DjKiRu Initative. Powered by Blogger.