Menus

Thursday, 8 August 2019

Introduction to Codelgniter



Welcome to CodeIgniter



CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.





Download

CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.

Who is CodeIgniter For?

CodeIgniter is right for you if:
  • You want a framework with a small footprint.
  • You need exceptional performance.
  • You need broad compatibility with standard hosting accounts that run a variety of PHP versions and configurations.
  • You want a framework that requires nearly zero configuration.
  • You want a framework that does not require you to use the command line.
  • You want a framework that does not require you to adhere to restrictive coding rules.
  • You are not interested in large-scale monolithic libraries like PEAR.
  • You do not want to be forced to learn a templating language (although a template parser is optionally available if you desire one).
  • You eschew complexity, favoring simple solutions.
  • You need clear, thorough documentation.

Installation Instructions

Tutorial


Thursday, 25 July 2019

how to get the number of days of the current month in PHP ?




cal_days_in_month — Return the number of days in a month for a given year and calendar

Description 

cal_days_in_month ( int $calendar , int $month , int $year ) : int
This function will return the number of days in the month of year for the specified calendar.
The length in days of the selected month in the given calendar

More details


example

             $m1=date('Y-m-d',strtotime($date_of_join));            
           
             $mon_num = date("m",strtotime($m1));
             $curr_year = date("Y",strtotime($m1));

            $num = cal_days_in_month(CAL_GREGORIAN, $mon_num, $curr_year);



PHP code for find number of days form given month and year ?



<?php

$month = 2;
$year = 2020;

$days = $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);

echo $days;

?>




Monday, 1 July 2019

Android Scrolling text in Textview


Android auto scrolling text

This tutorial explain to scroll text message on activity.

How to make Marquee text in Android?


Property as marquee
android:ellipsize = "marquee"
android:fadingEdge = "horizontal"
android:marqueeRepeatLimit = "marquee_forever"
android:scrollHorizontally = "true"
android:singleLine = "true"






Add the following code to res/layout/activity_main.xml.

<?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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.root.scrolling.MainActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >



                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hello World!" />

                <TextView
                    android:id="@+id/txtScroll"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="30dp"
                    android:background="#D0D0D0"
                    android:text="http://yii2ideas.blogspot.com/"

                    android:focusable="true"

                    android:focusableInTouchMode="true"
                    android:singleLine="true"
                    android:scrollHorizontally="true"
                    android:ellipsize="marquee"
                    android:marqueeRepeatLimit="marquee_forever"
                    />
             
        </LinearLayout>
     
</RelativeLayout>




Useful Links
Android Drop Down List Tutorial

Android date picker dialog



Tuesday, 4 June 2019

Android Drop Down List Tutorial



Spinner in Android application is equivalent of ComboBox

Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.


You can add a spinner to your layout with the spinner.

For example

    <Spinner
        android:id="@+id/spnCountry"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </Spinner>



List of Items in Spinner

Open “res/values/strings.xml” file, define the list of items that will display in Spinner 

File : res/values/strings.xml
<resources>
    <string name="app_name">Layouts</string>

    <string name="prompt_country">Select a Country</string>

    <string-array name="country_list">
        <item>India</item>
        <item>United States</item>
        <item>Singapore</item>
        <item>Malaysia</item>>
        <item>France</item>
        <item>Italy</item>
        <item>New Zealand</item>
    </string-array>

</resources>


Spinner  selection items will be defined in xml file


<Spinner
        android:id="@+id/spnCountry"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/country_list"
         >
</Spinner>

Other method :

<Spinner
        android:id="@+id/spnCountry"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/prompt_country"
        android:entries="@array/country_list"
        android:spinnerMode="dialog"
         >

 </Spinner>

Spinner selection items will be defined in code

add code in onCreate method

public class MainActivity extends AppCompatActivity {

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

        Spinner spnCountry = (Spinner) findViewById(R.id.spnCountry);

        ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(MainActivity.this,
                android.R.layout.simple_list_item_1,getResources().getStringArray(R.array.country_list));
        myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        spnCountry.setAdapter(myAdapter);


    }
}


Video





How to set selected item of Spinner programmatically in Android

Get spinner selected items text?

This example enplane value display on button click 

Java code
       Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                         Toast.makeText(TestActivity.this,String.valueOf(spnCountry.getSelectedItem()),Toast.LENGTH_LONG).show();
            }

        });

Example 2


Spinner spnCountry = (Spinner)findViewById(R.id.spnCountry);
String text = spnCountry.getSelectedItem().toString();


Handle spinner click event 


Spinner setOnItemSelectedListener


           spnCountry.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                Toast.makeText(TestActivity.this,parent.getItemAtPosition(position) + " Selected",Toast.LENGTH_LONG).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });


Set Key and Value in spinner

SpinnerCountry.java

package com.example.root.spinner;

/**
 * Created by root on 8/6/19.
 */
public class SpinnerCountry {

    public String id;
    public String country;

    public SpinnerCountry(String id,String country) {
        this.country = country;
        this.id = id;
    }

    @Override
    public String toString() {
        return country;
    }

}


MainActivity.java


package com.example.root.spinner;
import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Spinner;import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {

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

        Spinner spnCountry = (Spinner) findViewById(R.id.spnCountry);

        ArrayList<SpinnerCountry> countryList = new ArrayList<SpinnerCountry>();
        //add coutries        countryList.add(new SpinnerCountry("1","India"));
        countryList.add(new SpinnerCountry("2","France"));
        countryList.add(new SpinnerCountry("3","United States"));

        //fill data in spinner
        ArrayAdapter<SpinnerCountry> spinnerAdapter = new ArrayAdapter<SpinnerCountry>(MainActivity.this,
                android.R.layout.simple_spinner_dropdown_item,countryList);
        spnCountry.setAdapter(spinnerAdapter);

// And this is how we can retrieve it upon item selection

        spnCountry.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
            @Override            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                SpinnerCountry spn = (SpinnerCountry) parent.getItemAtPosition(position);

                Toast.makeText(MainActivity.this,spn.id,Toast.LENGTH_LONG).show();
        
            }

            @Override            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });


    }
}


Video





Sunday, 19 May 2019

Android date picker dialog



Android App to Choosing a date from Datepicker dialog

How to popup datepicker when click on edittext




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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.root.datedialogpopup.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Birthday" />

        <EditText
            android:id="@+id/edtBirthday"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Click to enter Birthday"
            />

    </LinearLayout>


</RelativeLayout>


Java Code:

package com.example.root.datedialogpopup;

import android.app.DatePickerDialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.icu.util.Calendar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CalendarView;
import android.widget.DatePicker;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


    private EditText edtBirthday;
    private DatePickerDialog.OnDateSetListener dateSetListener;

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

        edtBirthday = (EditText)findViewById(R.id.edtBirthday);

        edtBirthday.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {

                Calendar cal = Calendar.getInstance();
                //get current date and to set popup date picker

                int year = cal.get(Calendar.YEAR);
                int month = cal.get(Calendar.MONTH);
                int day = cal.get(Calendar.DAY_OF_MONTH);

                DatePickerDialog dialog = new DatePickerDialog(
                        MainActivity.this,
                        android.R.style.Theme_Holo_Light_Dialog_MinWidth,
                        dateSetListener,
                        year,month,day
                );

                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                dialog.show();

            }
        });


        dateSetListener = new DatePickerDialog.OnDateSetListener(){
            @Override
            public void onDateSet(DatePicker datePicker, int year, int month, int day) {

                month=month+1;
                String date = month + "/" + day + "/" + year;

                edtBirthday.setText(date);

            }
        };


    }
}







Wednesday, 15 May 2019

Android App to Add Two Numbers



Create simple application for Add or Subtract two numbers using android studio.

User Interface




Layout File

activity_add.xml
Here is the XML code for the design.

<?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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.root.layouts.AddActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#fadcdc"
        android:layout_centerVertical="true"
        >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:orientation="horizontal"
            >

            <TextView
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Number 1"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#000"
                android:textSize="20sp"
                />
            <EditText
                android:id="@+id/edtNumber1"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textSize="20sp"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:orientation="horizontal"
            >

            <TextView
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Number 2"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#000"
                android:textSize="20sp"
                />
            <EditText
                android:id="@+id/edtNumber2"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textSize="20sp"
                />
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            >

            <Button
                android:id="@+id/btnPlus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="+"
                android:textColor="#000"
                />

            <Button
                android:id="@+id/btnMinus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="-"
                android:textColor="#000"
                />

        </LinearLayout>


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:orientation="horizontal"
            >

            <TextView
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Result"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#000"
                android:textSize="20sp"
                />
            <EditText
                android:id="@+id/edtResult"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textSize="20sp"
                android:focusable="false"
                />
        </LinearLayout>


    </LinearLayout>

</RelativeLayout>


Activity java file

AddActivity.java


package com.example.root.layouts;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddActivity extends AppCompatActivity {

    EditText edtNumber1;
    EditText edtNumber2;
    EditText edtResult;
    Double num1,num2,result;

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


        edtNumber1 = (EditText)findViewById(R.id.edtNumber1);
        edtNumber2 = (EditText)findViewById(R.id.edtNumber2);
        edtResult = (EditText)findViewById(R.id.edtResult);




        Button btnPlus = (Button)findViewById(R.id.btnPlus);
        btnPlus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                num1=Double.parseDouble(edtNumber1.getText().toString());
                num2=Double.parseDouble(edtNumber2.getText().toString());

                result = num1+num2;

                edtResult.setText(Double.toString(result));


            }
        });

        Button btnMinus = (Button)findViewById(R.id.btnMinus);
        btnMinus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                num1=Double.parseDouble(edtNumber1.getText().toString());
                num2=Double.parseDouble(edtNumber2.getText().toString());

                result = num1-num2;

                edtResult.setText(Double.toString(result));
            }
        });

    }
}


Video for this tutorials