Saturday, December 8, 2018

flashlight application for android, code

Description:
          This is android application developed in android studio using java and XML programming language.Here is ImageView which is used to get device camera permission after on click and a button which is used to ON/OFF the flash of device. 





  1. IDE used => Android studio 3.1.0
  2. photo used:
drawable

(i)photo
name =btn_switch_off.PNG


button off


(ii)photo
name =btn_switch_on.PNG
button on


(iii)photo
name =icon.PNG




(iv)photo
name =wall.PNG



  1. AndroidManifest.xml :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dell.flashlight">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />

    <application        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:roundIcon="@drawable/icon"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Java class

class 1 :MainActivity.class :

package com.example.dell.flashlight;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Button buttonEnable;
    private ImageView imageFlashlight;
    private static final int CAMERA_REQUEST = 50;
    private boolean flashLightStatus = false;

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

        buttonEnable =(Button)findViewById(R.id.buttonEnable);
        imageFlashlight =(ImageView)findViewById(R.id.imageFlashlight);


        final boolean hasCameraFlash = getPackageManager().
                hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
        boolean isEnabled = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
                == PackageManager.PERMISSION_GRANTED;

        buttonEnable.setEnabled(!isEnabled);
        imageFlashlight.setEnabled(isEnabled);

        buttonEnable.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                ActivityCompat.requestPermissions(MainActivity.this, new String[] {Manifest.permission.CAMERA}, CAMERA_REQUEST);
            }
        });



        imageFlashlight.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                if (hasCameraFlash) {
                    if (flashLightStatus)
                        flashLightOff();
                    else                        flashLightOn();
                } else {
                    Toast.makeText(MainActivity.this, "No flash available on your device",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });

    }


    private void flashLightOn() {
        CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

        try {
            String cameraId = cameraManager.getCameraIdList()[0];
            cameraManager.setTorchMode(cameraId, true);
            flashLightStatus = true;
            imageFlashlight.setImageResource(R.drawable.btn_switch_on);
        } catch (CameraAccessException e) {
        }
    }



    private void flashLightOff() {
        CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

        try {
            String cameraId = cameraManager.getCameraIdList()[0];
            cameraManager.setTorchMode(cameraId, false);
            flashLightStatus = false;
            imageFlashlight.setImageResource(R.drawable.btn_switch_off);
        } catch (CameraAccessException e) {
        }
    }


    @Override    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch(requestCode) {
            case CAMERA_REQUEST :
                if (grantResults.length > 0  &&  grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    buttonEnable.setEnabled(false);
                    buttonEnable.setText("Camera Enabled");
                    imageFlashlight.setEnabled(true);
                } else {
                    Toast.makeText(MainActivity.this, "Permission Denied for the Camera", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}

layout

layout 1:activity_main.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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:background="@drawable/wall"
    tools:context=".MainActivity">
    <ImageView        android:id="@+id/imageFlashlight"
        android:layout_width="wrap_content"
       android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/btn_switch_off"
        android:contentDescription="@string/todo" />
    <Button        android:id="@+id/buttonEnable"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
        android:textSize="20sp"
        android:text="@string/enable_camera"
        android:textStyle="bold|italic"
        android:background="#000000"
       android:textColor="#ffffff"
        android:layout_above="@id/imageFlashlight"
        android:layout_marginBottom="40dp"/>

</RelativeLayout>


values

1.color.xml

<?xml version="1.0" encoding="utf-8"?><resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>


2.strings.xml

<resources>
    <string name="app_name">flashlight</string>
    <string name="enable_camera">Enable Camera</string>
    <string name="todo">TODO</string>
</resources>

3.styles.xml

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>


dependencies

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'




Monday, August 20, 2018

Datatype in JAVA programming language?

Datatype in java programming language

There are mainly two type of  datatype:

  1.  Primitive
  2. Non-primitive

     Primitive:



              They are of two types: 

  •   Numeric 
  •   Non-numeric       
now,
                Numeric :
                   They are of two types:




  • Integer
  • Floating point



              Non-numeric:
            
                They are of two types:

  • Character
  • Boolean 

 Non-primitive:

        They are of three types:

  • Class 
  • Array 
  • Interface 


explanation 
              
                   INTEGER -Integer are whole number

Data type Size           Default                  Range                                                
byte                1 byte                 0                                               -128 to 127                                             
short               2 byte                 0                                             -32768 to 32767                                       
int                  4 byte                  0                                     -2147483648 to 2147483647                           
long                8 byte                 0                      -9223372036854775808 to 9223372036854775807      




             


                  FLOATING POINT-A number containing fractional part

Data type Size          Default                  Range                          
float                4 byte           0.0                      3.40282347 x 1038, 1.40239846 x 10-45            
double             8 byte           0.0    1.7976931348623157 x 10308, 4.9406564584124654 x 10-32


              
                    CHARACTER-A single character that is a letter ,a digit,a                                        punctuation mark,a tab,a space and some thing similar to it.                

Data type Size                   Default                  Range                 
char                2 byte                  \u0000                                 \u0000  to \uFFFF               



              
BOOLEAN-Boolean are logical variable which can contain either TRUE/FALSE  

  Data type             Value                                  Default                                  
        char                           TRUE(1)/FALSE(0)                             FALSE                        

Saturday, August 18, 2018

Type of SD cards

classification of SD cards


There are mainly three sized SD cards
   

  1. Macro SD card      
  2. Micro SD card
  3. Mini SD card


  Macro SD card

                These are larger in size then other and they are rarely used.

macro SD cards look like this
pic: Macro SD card



       Micro SD card

                           These are medium in size and normally used in mobile phone.

         These cards are further divided into three types on the basis of size:

  • SD card : There  size starts from 0 GB to 4 GB.

SD card with storage of 2GB
pic: SD card

                                               


  •  SD HC card: There size starts from 4 GB to 32 GB.Here, HC  stands for high capacity.
    example of SD HC card
    pic: micro SD HC
  •  SD XP card:  There size starts from 32 GB to 2 TB.Here, XC  stands for extended capacity.  
    example of SD extended capacity cards
    pic: SD XC card
     

         These cards are also further divided into different class on the basis of speed:
   
  • class 2
  • class 4
  • class 6
  • class 8
  • class 10
  • UHS 1 ( Ultra High Speed One)

  • UHS 2  ( Ultra High Speed Two)

  • UHS 3   ( Ultra High Speed Three)



The class of  SD cards are written inside circle on the  card.This class represent the maximum speed  with which you can write data on the memory card.for example: class 2 means 2 Megabytes per second with which data can be stored on the memory.Now, UHS 1 and 3 support maximum speeds up to 320 megabytes.


         Mini SD card

                                    These are smaller in size then other SD cards and they are not generally used in normal use.

    example of mini SD cards
    pic: Mini SD card

    Friday, August 17, 2018

    How to enable Intel VT-x in window 10  in Lenovo G series 




    Following step should be follow in order to enable VT-x setting 




    • You should shut down your PC.
    • Now, near charging port  there must be an small sized button,then click it.     
    • Menu appears, go to => BIOS setup =>  Configuration => Intel virtual technology ,then enable it if disabled.
    • You should use UP,DOWN,LEFT,RIGHT key from keyboard to move cursor.
    • If you want to select the option hit  ENTER key.
    • After this,you need to save this change by using shortcut key given in console.
    • In exit saving changes,hit "YES".
    • your computer begin start now automatically. 

                    for more: CLICK ME





         finally, you can enjoy VT-x enabled PC.


    About Android Version
        

    SOME OBSERVABLE POINTS ABOUT  VERSION OF ANDROID

                
    1. Name of Android version are taken in such a way that belongs to name of chocolates and fruits around us.
    2. The first letter of Android version name is kept in increasing alphabetical order as increasing the versions of android.
    3. first version of Android was released on September 23,2008 .Initially it was given no name officially but people called it Alpha.
    4. Recent version of Android is "Android P" called  "Pie" released on August 6,2018.



     LIST OF ANDROID VERSION WITH RELEASED DATE ORDERLY




    1.     Alpha 1.0 , released on 23-09-2008
    1.     Beta 1.1 , released on  09-02-2009
    1.     Cupcake 1.5 , released on 27-04-2009
    1.     Donut 1.6 , released on 15-09-2009
    1.     Eclair 2.0/2.1, released on 26-10-2008
    1.     Froyo 2.2/2.2.3 , released on 20-05-2010
    1.     Gingerbread 2.3/2.3.7 , released on 06-12-2010
    1.     Honeycomb 3.0/3.2 , released on 22-02-2011
    1.     Ice Cream Sandwich 4.0 / 4.0.4 , released on 18-10-2011
    1.     Jelly Bean 4.1 , released on 09-07-2012
    1.     Kitkat 4.4 , released on 31-10-2013
    1.     Lollipop 5.0 , released on 12-11-2014
    1.     Marshmallow 6.0 , released on 05-10-2010
    1.     Nougat 7.0 , released on 22-08-2016
    1.     Oreo 8.0/8.1 , released on 21-08-2017
    1.     Pie 9.0 , released on 06-08-2018

    Monday, August 13, 2018

    SNAKE GAME IN C


    Introduction:

    If you want to develop snake game using C programming language then this blog obviously helps you.Hi i am Basant and i developed this game in my first year first semester project.




    This is project initial page

                                                                 This is the project logo.



    THERE IS CODE FOR THIS PROJECT WITH DOCUMENTATION:


    Code:



    /* Developed by Basant Bhandari */
    /* Header file declaration */
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    /* Global variable declaration */
    int gameover;
    const int width= 80;
    const int height= 20;
    int x,y,fruitX,fruitY,score,i,j,k,flag;
    int tailX[100], tailY[100];
    int ntail;
    int prevX,prevY,prev2X,prev2Y;
    enum edirection {STOP=0,LEFT,RIGHT,UP,DOWN };
    enum edirection dir;
    /* Function prototype */
    void setup();
    void draw();
    void input();
    void logic();
    /* Main function starts here */
    void main(){
    setup();
    while (!gameover){
    draw();
    input();
    logic();
    /* Delay purpose */
    for(i= 0; i<55550000; i++){
    } /* For loop closing */
    } /* While loop closing */
    getch();
    } /* Main function closing */
    /* Function definition */
    void setup(){
    gameover=0;
    dir = STOP;
    x= width/2;
    y= height/2;
    fruitX= ( rand()%width );
    fruitY= ( rand()%height );
    score= 0;
    }
    void draw(){
    system("cls");
    /* DRAWING FRAME */
    /* Top horizontal */
    for(i=0; i<(width); i++){
    printf("#");
    }
    printf("\n");
    /* Left and right vertical */
    for( i=0; i<height ; i++){
    for( j=0; j<width ; j++){
    if( j==0 || j== (width-1) ){
    printf("#");
    }else if(i==y && j==x){
    printf("O");
    }else if(i==fruitY && j==fruitX ) {
    printf("F");
    }else{
    flag= 0;
    for( k= 0; k< ntail; k++){
    if( tailX[k]==j && tailY[k]==i ){
    printf("o");
    flag= 1;
    }
    }
    if(!flag){
    printf(" ");
    }
    }
    }
    printf("\n");
    }
    /* Bottom horizontal */
    for(i=0; i<(width); i++){
    printf("#");
    }
    printf("\n");
    printf("SCORE = %d",score);
    }
    void input(){
    if(kbhit()){
    switch(getch()){
    case 'a':
    dir= LEFT;
    break;
    case 'd':
    dir= RIGHT;
    break;
    case 'w':
    dir= UP;
    break;
    case 's':
    dir= DOWN;
    break;
    case 'x':
    gameover= 1;
    break;
    }
    }
    }
    void logic(){
    prevX= tailX[0];
    prevY= tailY[0];
    tailX[0]= x;
    tailY[0]= y;
    for( i=1; i<ntail; i++){
    prev2X= tailX[i];
    prev2Y= tailY[i];
    tailX[i]= prevX;
    tailY[i]= prevY;
    prevX = prev2X;
    prevY = prev2Y;
    }
    switch(dir){
    case LEFT:
    x--;
    break;
    case RIGHT:
    x++;
    break;
    case UP:
    y--;
    break;
    case DOWN:
    y++;
    break;
    default:
    break;
    }
    if( x > width || x < 0 || y > height || y < 0 ){
    gameover= 1;
    }
    for(i=0; i<ntail; i++ ){
    if(tailX[i]==x && tailY[i]==y){
    gameover= 1;
    }
    }
    fruitX= ( rand()% width);
    fruitY= ( rand()% height);
    ntail++;
    }
    } /* Ending of logic function */
    view raw snakeGame.html hosted with ❤ by GitHub





    Tools used:
    • Dev-C++   IDE                                  (Dev-Cpp 5.11 TDM-GCC 4.9.2 Setup)  
    • sublime text  text editor                      ( Sublime Text Build 3170 x64 Setup)

    Discussion:

    Finally i just want a say take only idea from this code it might show some error while running in your PC since it does not produce Byte code as produced by Java. 



    If you want to ask something then comment below.


    Watch in YouTube

    Friday, June 15, 2018

    What is wab and wab designing?

    Web

    Web means a kind of system service which  specially supports organized document written in a markup language called HTML.It is also known as WWW which stands for World Wide Web.
    example:web shopping,online study,online games etc.

    Web designing

     Web designing is the complete process of developing website with the help of different skill(like: knowledge of HTML,CSS,Java script,J-query,server,client,web hosting etc).