Tuesday, 16 May 2017

Navigation Drawer Code Example using html ,css & jquery code

(1)write jquery code for  jquery.hamburger.js :


/* global jQuery */
(function ($) {
  'use strict';

  var action = $('.hamburger-action'),
    hamburger = $('#hamburger'),
    content = $('#content'),
    overlay = $('<div>').attr({
      id: 'hamburger-overlay',
    }).insertAfter(content),
    nav = $('nav'),

    onClick = function() {
      var contentWidth = content.width(),
        current = nav.css('margin-left'),
        val = '0%',
        layer = 'block',
        opacity = 0.5,
        ham = -10;

      content.css('width', contentWidth);
      if(current === '0px') {
        val = '-70%';
        layer = 'none';
        opacity = 0;
        ham = 0;
      } else {
        overlay.css('display', layer);
      }

      nav.animate({'margin-left': [val]}, {
        duration: 700
      });

      hamburger.animate({'left': [ham]}, {
        duration: 700
      });

      overlay.animate({'opacity': [opacity]}, {
        duration: 700,
        complete: function() {
          overlay.css('display', layer);
        }
      });
    };

  action.click(onClick);
  overlay.click(onClick);
  hamburger.click(onClick);
}(jQuery));


(2) write code for style.css file:

body {
  margin: 0;
  padding: 0;
  background: #eee;
  overflow-x: hidden;
}

a { text-decoration: none; }

.title {
  float: left;
  color: #fff;
  position: relative;
  top: 1px;
}

.clear { clear: 'both'; }

#circle {
  margin-top: 20px;
  display: table-cell;
  text-align: center;
  vertical-align: middle;
  width: 300px;
  height: 300px;
  background: #f86057;
  -webkit-border-radius: 150px;
  -moz-border-radius: 150px;
  border-radius: 150px;
  color: #fff;
  font-size: 60px;
}

header {
  background-color: #5EA97F;
  padding: 10px 10px 10px 0px;
  text-decoration: none;
  position: fixed;
  width: 100%;
  z-index: 5;
}

#content {
  background-color: #eee;
  padding: 52px 10px 10px 10px;
  position: relative;
  width: auto;
  min-height: 1000px;
  -webkit-box-shadow: -10px 0px 9px 0px rgba(0, 0, 0, 0.4);
  box-shadow: -10px 0px 9px 0px rgba(0, 0, 0, 0.4);
}

nav {
  top: 40px;
  margin-left: -70%;
  position: fixed;
  z-index: 2;
  width: 70%;
  height: 100%;
  background: #FFF;
}

nav ul {
  list-style: none;
  margin: 0;
  width: 100%;
  padding: 0;
}

nav li {
  position: relative;
  padding: 25px;
}

nav li a {
  color: #222;
  text-decoration: none;
}

#hamburger {
  cursor: pointer;
  display: block;
  height: 20px;
  position: relative;
  width: 20px;
  float: left;
  padding-right: 10px;
}

#hamburger div {
  background-color: #fff;
  height: 3px;
  margin-top: 3px;
  width: 90%;
}

.hamburger-action { cursor: pointer; }

#hamburger-overlay {
  display: none;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  position: absolute;
  right: 0;
  top: 0;
  width: 100%;
  z-index: 1;
  opacity: 0;
  background: #000;
}

(3)write code for  index.html file:
<!DOCTYPE html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale = 1.0, maximum-scale=1.0, user-scalable=no" />
    <meta charset="utf-8"> 
    <link rel="stylesheet" type="text/css" media="all" href="style.css" />
    <title>jQuery  Plugin Demo</title>
</head>

<body>
    <div id="container">
        <header>
            <div id="hamburger">
                <div></div>
                <div></div>
                <div></div>
            </div>
            <div class="title hamburger-action" data-i18n='app-title'>Android Tutorials</div>
        </header>
        <nav class="clear">
  <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="androidlayout.html">Android Layout</a></li>
    <li><a href="eventhandling.html">Event Handling</a></li>
    <li><a href="intent.html">Intent</a></li>
    <li><a href="fragment.html">Fragment</a></li>
  </ul>
</nav>
        <div id="content">
         <h1>What is Android?</h1>
<p><h3>Before learning all topics of android, it is required to know what is android.
Android is a software package and linux based operating system for mobile devices such as tablet computers and smartphones.
It is developed by Google and later the OHA (Open Handset Alliance). Java language is mainly used to write the android code even though other languages can be used.
The goal of android project is to create a successful real-world product that improves the mobile experience for end users.
There are many code names of android such as Lollipop, Kitkat, Jelly Bean, Ice cream Sandwich, Froyo, Ecliar, Donut etc which is covered in next page.</h3></p>


</script></div>
        </div>
    </div>

   
     <script src="jquery.min.js"></script>
    <script src="jquery.hamburger.js"></script>

</body>
</html>

Output:



Tuesday, 10 January 2017

How to pass form data from Android to PHP CODE EXAMPLE

(1)write code for Main2Activity.java file:
package com.guru.login;

import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Main2Activity extends AppCompatActivity {

   
// CONNECTION_TIMEOUT and READ_TIMEOUT are in milliseconds

   
public static final int CONNECTION_TIMEOUT=10000;
   
public static final int READ_TIMEOUT=15000;
   
private EditText etEmail;
   
private EditText etEmail1;
   
private EditText etPassword;

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main2);

       
// Get Reference to variables
       
etEmail = (EditText) findViewById(R.id.email);
       
etEmail1 = (EditText) findViewById(R.id.email1);
       
etPassword = (EditText) findViewById(R.id.password);

    }

   
// Triggers when LOGIN Button clicked
   
public void checkLogin(View arg0) {

       
// Get text from email and passord field
       
final String email = etEmail.getText().toString();
       
final String email1 = etEmail1.getText().toString();
       
final String password = etPassword.getText().toString();

       
// Initialize  AsyncLogin() class with email and password
       
new AsyncLogin().execute(email,email1, password);

    }

   
private class AsyncLogin extends AsyncTask<String, String, String>
    {
        ProgressDialog
pdLoading = new ProgressDialog(Main2Activity.this);
        HttpURLConnection
conn;
        URL
url = null;

       
@Override
       
protected void onPreExecute() {
            
super.onPreExecute();

           
//this method will be running on UI thread
           
pdLoading.setMessage("\tLoading...");
           
pdLoading.setCancelable(false);
           
pdLoading.show();

        }
       
@Override
       
protected String doInBackground(String... params) {
           
try {

               
// Enter URL address where your php file resides
               
url = new URL("http://funmoviemasti.com/om/insert.php");

            }
catch (MalformedURLException e) {
                
// TODO Auto-generated catch block
               
e.printStackTrace();
               
return "exception";
            }
           
try {
               
// Setup HttpURLConnection class to send and receive data from php and mysql
                
conn = (HttpURLConnection)url.openConnection();
               
conn.setReadTimeout(READ_TIMEOUT);
               
conn.setConnectTimeout(CONNECTION_TIMEOUT);
               
conn.setRequestMethod("POST");

               
// setDoInput and setDoOutput method depict handling of both send and receive
               
conn.setDoInput(true);
               
conn.setDoOutput(true);

               
// Append parameters to URL
               
Uri.Builder builder = new Uri.Builder()
                        .appendQueryParameter(
"email", params[0])
                        .appendQueryParameter(
"email1", params[1])
                        .appendQueryParameter(
"password", params[2]);
                String query = builder.build().getEncodedQuery();

               
// Open connection for sending data
               
OutputStream os = conn.getOutputStream();
                BufferedWriter writer =
new BufferedWriter(
                       
new OutputStreamWriter(os, "UTF-8"));
                writer.write(query);
                writer.flush();
                writer.close();
                os.close();
               
conn.connect();

            }
catch (IOException e1) {
               
// TODO Auto-generated catch block
               
e1.printStackTrace();
                
return "exception";
            }

           
try {

               
int response_code = conn.getResponseCode();

               
// Check if successful connection made
               
if (response_code == HttpURLConnection.HTTP_OK) {

                    
// Read data sent from server
                   
InputStream input = conn.getInputStream();
                    BufferedReader reader =
new BufferedReader(new InputStreamReader(input));
                    StringBuilder result =
new StringBuilder();
                    String line;

                   
while ((line = reader.readLine()) != null) {
                        result.append(line);
                    }

                   
// Pass data to onPostExecute method
                   
return(result.toString());

                }
else{

                   
return("unsuccessful");
                }

            }
catch (IOException e) {
                e.printStackTrace();
               
return "exception";
            }
finally {
                
conn.disconnect();
            }


        }

       
@Override
       
protected void onPostExecute(String result) {

           
//this method will be running on UI thread

           
pdLoading.dismiss();

           
if(result.equalsIgnoreCase("true"))
            {
               
/* Here launching another activity when login successful. If you persist login state
                use sharedPreferences of Android. and logout button to clear sharedPreferences.
                 */

               
Intent intent = new Intent(Main2Activity.this,SuccessActivity.class);
                startActivity(intent);
                Main2Activity.
this.finish();

            }
else if (result.equalsIgnoreCase("false")){

               
// If username and password does not match display a error message
               
Toast.makeText(Main2Activity.this, "Invalid email or password", Toast.LENGTH_LONG).show();

            }
else if (result.equalsIgnoreCase("exception") || result.equalsIgnoreCase("unsuccessful")) {

                Toast.makeText(Main2Activity.
this, "OOPs! Something went wrong. Connection Problem.", Toast.LENGTH_LONG).show();

            }
        }

    }
}

(2)write code for  activity_main2.xml file:
<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"

    android:layout_height="match_parent" android:fitsSystemWindows="true"

    tools:context="com.guru.login.Main2Activity">



    <android.support.design.widget.AppBarLayout
 android:layout_height="wrap_content"

        android:layout_width="match_parent"
 android:theme="@style/AppTheme.AppBarOverlay">



        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"

            android:layout_width="match_parent"
 android:layout_height="?attr/actionBarSize"

            android:background="?attr/colorPrimary"
 app:popupTheme="@style/AppTheme.PopupOverlay" />



    </android.support.design.widget.AppBarLayout>



    <include layout="@layout/content_main2" />



    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"

        android:layout_width="wrap_content" 
android:layout_height="wrap_content"

        android:layout_gravity="bottom|end" 
android:layout_margin="@dimen/fab_margin"

        android:src="@android:drawable/ic_dialog_email" />



</android.support.design.widget.CoordinatorLayout>

(3)write code for content_main2.xml file:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent"

    android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context=".Main2Activity">



    <EditText

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:inputType="textEmailAddress"

        android:ems="10"

        android:id="@+id/email"

        android:layout_alignParentTop="true"

        android:layout_alignParentLeft="true"

        android:layout_alignParentStart="true"

        android:hint="Email"

        android:layout_marginTop="100dp"/>

    <EditText

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:inputType="textEmailAddress"

        android:ems="10"

        android:id="@+id/email1"

        android:layout_alignParentTop="true"

        android:layout_alignParentLeft="true"

        android:layout_alignParentStart="true"

        android:hint="Email1"

        android:layout_marginTop="130dp"/>



    <EditText

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:inputType="textPassword"

        android:ems="10"

        android:id="@+id/password"

        android:layout_below="@+id/email"

        android:hint="Password"

        android:layout_marginTop="10dp"/>



    <Button

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="LOGIN"

        android:id="@+id/button"

        android:layout_below="@+id/password"

        android:layout_marginTop="10dp"

        android:onClick="checkLogin"/>



</RelativeLayout>

(4)write code for SuccessActivity.java file:
 
package com.guru.login;



import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;



public class SuccessActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_success);

    }

}

(5)write  code for  activity_success.xml  file:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent"

    android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin">



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceLarge"

        android:text="WELCOME"

        android:id="@+id/textView"

        android:layout_alignParentTop="true"

        android:layout_centerHorizontal="true"

        android:layout_marginTop="62dp" />



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceMedium"

        android:text="Successfully LoggedIn"

        android:id="@+id/textView2"

        android:layout_marginTop="46dp"

        android:layout_below="@+id/textView"

        android:layout_centerHorizontal="true" />



</RelativeLayout>

(6)write code for php server side:
<?php

$email = $_POST['email'];
$email1 = $_POST['email1'];
$password=$_POST['password'];

if($email=="email" && $email1=="email1" && $password="password")
{
echo "true";
}
else
{
echo " false";
}


?>

Recent Posts

Powered by Blogger.

Pages

About Me

My Photo
B.E.(COMPUTER ENGINEER) PHP Web developer & Provide Training for Web Development , Digital Marketing ,Android Mobile Apps Development

 

© 2013 ANDROID TRAINING IN MUMBAI BY OM SIR. All rights resevered. Designed by Templateism

Back To Top