Menus

Saturday, 24 February 2018

Always On Top for YouTube Video in Google Chrome


First select Google Chrome Settings and click to Extension menu.

Check Extension for app Always On Top for YouTube.







Launch icon your browser.




Click this icon and show your video always on top.





Thank You



Wednesday, 7 February 2018

Android Menu

Menus

Menus are a common user interface component in many types of applications.

This guide shows how to create the three fundamental types of menus or action presentations on all versions of Android:

Options menu and app bar
The options menu is the primary collection of menu items for an activity. It's where you should place actions that have a global impact on the app, such as "Search," "Compose email," and "Settings."

Context menu and contextual action mode
A context menu is a floating menu that appears when the user performs a long-click on an element. It provides actions that affect the selected content or context frame.

Popup menu
A popup menu displays a list of items in a vertical list that's anchored to the view that invoked the menu.


Android Option Menu Example

Defining a Menu in XML


It contains three items as show below. It is created automatically inside the res/menu directory.


menu with the following elements:

<menu>
Defines a Menu, which is a container for menu items. A <menu> element must be the root node for the file and can hold one or more <item> and<group> elements.
<item>
Creates a MenuItem, which represents a single item in a menu. This element may contain a nested <menu> element in order to create a submenu.
<group>
An optional, invisible container for <item> elements. It allows you to categorize menu items so they share properties such as active state and visibility. For more information, see the section about Creating Menu Groups.

<menu xmlns:androclass="http://schemas.android.com/apk/res/android" >      <item  android:id="@+id/item1"  
        android:title="Item 1"/> 
   <item  android:id="@+id/item2"  
        android:title="Item 2"/>  
    <item  android:id="@+id/item3"  
        android:title="Item 3"/>  
</menu>  


More Details

Write a Program to create menu with three menu items


Example





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.myapplication.MainActivity">

    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Menu Program" />
</RelativeLayout>


main.xml   //main.xml file in res/menu

<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/item1"    android:title="item1" />
<item android:id="@+id/item2"    android:title="item2" />
<item android:id="@+id/item3"    android:title="item3" />

</menu>


MainActivity.java


package com.example.root.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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

    @Override    public boolean onCreateOptionsMenu(Menu menu){

        getMenuInflater().inflate(R.menu.main,menu);
        return true;
    }

    @Override    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.item1) {
            Toast.makeText(getApplicationContext(), "First Item Selected!",
                    Toast.LENGTH_SHORT).show();
        }
        if (id == R.id.item2) {
            Toast.makeText(getApplicationContext(), "Second Item Selected!", Toast.LENGTH_SHORT).show();
        }
        if (id == R.id.item3) {
            Toast.makeText(getApplicationContext(), "Third Item Selected!",
                    Toast.LENGTH_SHORT).show();
        }
        return true;
    }


}



Problem - res/menu and res/xml are not there


If it is in android studio 2.1.1, to create a res/menu folder follow these steps.
right click on res -> new -> Android resource directory -> change the resource type to 'menu' in the dropdown menu -> click ok
to create menu file in menu folder right click on menu folder -> new -> menu resource file ->give the file name -> click ok.


Saturday, 13 January 2018

Yii2 dropdown multiple selected



MultiSelect Widget for Yii2

It supports searching, remote data sets, and infinite scrolling of results.

https://github.com/kartik-v/yii2-widget-select2

Kartik Multiselect widget


in _form.php

use kartik\select2\Select2;



<?php
    echo Select2::widget([
        'model' => $model,
        'name' => 'certificates',
        'attribute' => 'certificates',
        'data' => ArrayHelper::map(Mulcertificates::find()->orderBy('description')->all(),'id','description'),  //['1'=>'1','2'=>2],
        'options' => [
            'placeholder' => 'Select certificates ...',
            'multiple' => true
    ],
    ]);
    ?>


Controller.php

public function actionCreate()
    {
        $model = new Mulselect();

        if ($model->load(Yii::$app->request->post())) {
         
            $model->certificates = implode(",",$model->certificates);
            
            $model->save();
            return $this->redirect(['view', 'id' => $model->id]);
         
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }


 public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            $model->certificates= explode(',', $model->certificates);
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }


Links

Select2 Widget 

Tuesday, 9 January 2018

PHP - MySQL - Connection


MySQL Connection Using PHP Script

PHP provides mysql_connect() function to open a database connection.

Syntax

connection mysql_connect(server,user,passwd,new_link,client_flag);


Returns a MySQL link identifier on success or FALSE on failure.


Example

<?php
         $dbhost = 'localhost';
         $dbuser = 'test';
         $dbpass = 'Ii@21!abg';
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
         }
         echo 'Connected successfully<br>';

         $sql = 'SELECT id, name, course FROM std';

         mysql_select_db('ellorahs_test');
         $retval = mysql_query( $sql, $conn );
   
         if(! $retval ) {
              die('Could not get data: ' . mysql_error());
         }
   
         while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
            echo "ID :{$row['id']}  <br> ".
                 "Name : {$row['name']} <br> ".
                 "Course : {$row['course']} <br> ".
                 "--------------------------------<br>";
         } 
         echo "Fetched data successfully\n";

         mysql_close($conn);
?>


mysql_close()


Disconnect from the MySQL database anytime using another PHP function mysql_close().


SELECT command is used to fetch data from the MySQL database. 


Selecting a MySQL Database Using PHP

mysql_select_db to select a database. 
It returns TRUE on success or FALSE on failure.

Fetching Data Using a PHP


The SQL SELECT command is used to fetch data from the MySQL database.

SELECT command into a PHP function mysql_query().


mysql_fetch_array() can be used to fetch all the selected data. 






Wednesday, 27 December 2017

How to format pen drive in Ubuntu



Graphical Method

Open Disks program 



Then choose your device from left. 
Click more options button and click onformat as below:







Command-Line

How to format pen drive in ubuntu any version.


Open the Terminal (Ctrl + Alt + T)

fdisk -l

umount /dev/sdc*

mkfs.vfat /dev/sdc*




Thank You


Thursday, 14 December 2017

How to completely uninstall android studio in ubuntu


Open Terminal

Ctrl + Alt + T

sudo su  //login to superuser

Run the following commands in the terminal:
rm -Rf /Applications/Android\ Studio.app  
rm -Rf ~/Library/Preferences/AndroidStudio*  
rm -Rf ~/Library/Preferences/com.google.android.*  
rm -Rf ~/Library/Preferences/com.android.*  
rm -Rf ~/Library/Application\ Support/AndroidStudio*  
rm -Rf ~/Library/Logs/AndroidStudio*  
rm -Rf ~/Library/Caches/AndroidStudio*  
rm -Rf ~/.AndroidStudio*  
rm -Rf ~/.gradle  
rm -Rf ~/.android  
rm -Rf ~/Library/Android*  
rm -Rf /usr/local/var/lib/android-sdk/  
rm -Rf ~/.AndroidStudio*  
To delete all projects:
rm -Rf ~/AndroidStudioProjects  

Uninstall Android Studio











Monday, 11 December 2017

Yii2 CheckBox

LIKE | COMMENT | SHARE | SUBSCRIBE
LIKE | COMMENT | SHARE | SUBSCRIBE

Yii2 - Display checkbox for boolean database field on active form


<?= $form->field($model, 'mon')->checkBox(['selected' => $model->mon])?>

Change Label


<?= $form->field($model, 'mon')->checkBox(['label'=> 'Monday',  'selected' => $model->mon])?>



Required Checkbox

Add this code your rules function on model class

           [['mon''], 'compare',
                'compareValue' => true,
                'operator' => '==',
                'message' => "Check to Continue",
                'when' => function ($data) {
                    return $data->mon== 1;
                }
            ],



Example

Model class

<?php

namespace backend\modules\test\models;

use Yii;

/**
 * This is the model class for table "studentsdetails".
 *
 * @property integer $id
 * @property string $name
 * @property string $address
 * @property integer $isverified
 */
class Studentsdetails extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'studentsdetails';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'isverified'], 'required'],
            [['isverified'], 'integer'],
            [['name'], 'string', 'max' => 300],
            [['address'], 'string', 'max' => 500],
         
            [['isverified'], 'compare',
                'compareValue' => true,
                'operator' => '==',
                'message' => "Check to Continue",
                'when' => function ($data) {
                    return $data->isverified== 1;
                }
            ],

         
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'address' => 'Address',
            'isverified' => 'Isverified',
        ];
    }
}

View file
_form.php

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\modules\test\models\Studentsdetails */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="studentsdetails-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>

 
    <?= $form->field($model, 'isverified')->checkBox(['selected' => $model->isverified])?>
 
 
    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>