Touch Less Elevator New Norms of Life

We at Neudeep Technologies Pvt. Ltd. continue to innovate and as part of our innovations we are happy to announce launch of touchless elevator for your needs. This is part of one of our product series  #IEC1000 (Intelligent Elevator Controller). We are proud to say “made in India” by startup company in Pune, India.

As we continue to navigate with new norms of life during these pandemic times, the vertical transport industry has continued to innovate new products and features. One of such feature is, touch less technology. Touch less technology is especially attractive options in this current pandemic environment. An example of touch less technology is our own product ie touch less elevator. This enables passengers to use their cell phone as their personal elevator call button. This is also sometimes called eCall. This eCall helps minimize use of public access to elevator buttons.

This QR code based touch less elevator/lift can act as destination dispatching system, which can help minimize the number of stops per trip, reduce car crowding and decrease travel times and saves energy.

This QR code based system is ready to integrate with security and community management app for gated premises like MyGate, ApnaComplex and NoBrokerHOOD. Neudeep’s IEC1000 touchless elevator software with mobile app integrated with MyGate, ApnaComplx or NoBrokerHOOD will help residents as well as the management committee in handling gate security for visitors. When integrated with these apps Neudeep’s touchless elevator system will act as access system, where visitors movement will be restricted to their destination floor only.

Below is short video of our invention.

Thank you for watching. If you are looking for such solution to be implemented at your place email your details at info@blog.neudeep.com

Reference links:

Flutter Dart:

Flutter 3D Buttons:

https://medium.com/flutterpub/anatomy-of-material-buttons-in-flutter-first-part-40eb790979a6

Flutter Latest news:

https://medium.com/flutter/two-months-of-fluttergoodnewswednesday-a12e60bab782

Build flutter app:

https://www.youtube.com/watch?v=x0uinJvhNxIhttps://flutter.dev/docs/get-started/codelab

Flutter toggle color after click:

https://stackoverflow.com/questions/50863681/flutter-how-do-i-toggle-the-color-of-a-raisedbutton-upon-click

Flutter on codePen:

https://codepen.io/flutter

Flutter gridlist examples:

https://flutter.dev/docs/cookbook/lists/grid-lists

Fetch data from server in flutter:

https://flutter.dev/docs/cookbook/networking/background-parsing

https://medium.com/flutterdevs/parsing-complex-json-in-flutter-b7f991611d3e

UX Design in flutter:

https://uxdesign.cc/flutter-design-challenge-onboarding-concept-1f5774d55646

Get the data from API:

https://medium.com/flutter-community/parsing-complex-json-in-flutter-747c46655f51

Flutter time series:

https://stackoverflow.com/questions/51739064/flutter-json-and-time-series-charts

Flutter dart packages:

https://www.w3adda.com/dart-tutorial/dart-packages

Flutter dart introduction:

https://www.w3adda.com/dart-tutorial/dart-introduction

https://openlibrary.org/works/OL17556930W/Android_Fully_Loaded

https://archive.org/details/unlockingandroid0000able/page/n5?q=Build+android+os

Create mock server using postman:

https://learning.postman.com/docs/postman/mock-servers/setting-up-mock/

Web Socket examples:

https://www.websocket.org/echo.html

Energy consumption calculator:

https://www.rapidtables.com/calc/electric/energy-consumption-calculator.html

Git hub basic course:

https://www.udemy.com/course/git-and-github-crash-course-creating-a-repository-from-scratch/

Install svn on ubuntu:

https://linuxtechlab.com/simple-guide-to-install-svn-on-ubuntu

Flutter line chart,bar & pie chart:

https://pub.dev/packages/fl_chart

https://google.github.io/charts/flutter/example/bar_charts/simple.html

https://www.digitalocean.com/community/tutorials/flutter-bar-charts

https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/pie_chart.md#sample-1-source-code

Flutter list & grid view link:

https://medium.com/@vignesh_prakash/flutter-listview-and-gridview-with-tabbar-221516518c75

Flutter Page color link:

https://medium.com/flutter-community/a-deep-dive-into-pageview-in-flutter-with-custom-transitions-581d9ea6dded

Flutter page control link:

https://api.flutter.dev/flutter/widgets/PageController-class.html

STM32 ABSTRACT

STM 32 MCU and MPU Roadmap contains:

1. MPU (STM32MP1):

– MPU with Arm Cortex-A7 650 MHz, Arm Cortex-M4 real-time coprocessor, TFT display, – Secure boot and Cryptography.

– Combination of audio and real time processing with cortex A and M architecture.

-STM32Cube AI tool running on cortex M4.

– Camera and audio interfaces to simplify input device integration.

Application: Used for real time and low power application and also graphic and communication high performance processing. Provide cloud based , making Smart home gateway with advance HMI and HD video.

2. High Performance MCUs(STM32F2, STM32F4, STM32FH7, STM32F7):

These MCUs are available in single core as well as dual core. A7 type having large of flash and Ram is provided.

STM32H7 having 280 Mhz embedding 2 MB flash ,1.4 MB RAM

Application: graphics applications, could connectivity, lot of security features.

Industry – Inverters, Communication gateway, Human Machine Interface

Health and Wellness- Individual assistance(hearing, Respiratory) , Measurements and Data logger.

Consumer – IOT gateway (Large Memory and rich communication peripherals), Access Control (Chrome-ART accelerator and display interfaces for TFT and MIPI-DSI), Drones(High Processing architecture with dual core option, advance timers and analog peripherals, small packages).

3. Mainstream MCUs(STM32F0,STM32G0,STM32F1,STM32F3,STM32G4):

– These are used for general purpose application having main feature as low power consumption which can take <100uA current.

– Main features is:

Efficient: Compact Cost,Best RAM/Flash Ratio, Smallest posiible package down to 8 pin,low power consumption, Accurate internal high speed clock best optimization

Robust: Low electromagnetic susceptibility, clock monitoring and 2 Watchdog, Error correct on flash, IOT ready with embedded security, Safe firmware upgrade/Install

Simple: Easy to configure with STM32CubeMx, Graphics, Easy to develop based on hardware abstraction library(HAL) or low layer library (LL).

Application:(STM32G0)

Lighting: High temperature, Advance timers, fast comparators ADC, DAC, AES and Security

Consumer Objects(Smart phones, IoT devices, Rechargeable connected devices,Drones,toys):

Low consumption in run and low power,USB type C power delivery, 64 Mhz CPU with DMA.

Smart Home(Home Appliances, Alarm and safety, Advance User Interfaces): High temp, safety monitoring feature, more RAM for flash , low consumption.

Industrial devices Motor control, Advance control(Air conditioning, E-bikes, Industrial Equipment): High temp, CANFD support, SPI,USART,I2C,Advance timers, RTC with backup register, AES and upgrade security

STM32G4: Having Se-curable memory area with configurable size, can be secured once exiting(no more access nor debug possible), Good fit to store critical data (critical routines, keys)

4. Ultra low power MCUs(STM32L0,STM32L1,STM32L5,STM32L4,STM32L4+):

STM32L0 (Cost Smart ULP champion):8/16 bit application,wide range of pin counts, 3 Product lines, Cost-effective, small packages, USB, LCD,Analog 8 to 192 kbytes of Flash, upto 20 kbytes of SRAM .

STM32L1(Broad Range Foundation): wide choice of memory sizes, 3 product lines, USB, LCD, AES rich analog EEPROM , Dual bank flash memory , 32-512 kbytes of flash up to 60 kbytes of SRAM.

STM32L4(ULP with performance) : High performance advance analog circuit, 5 product lines, 5 MSPS ADC, compare,DAC, Op-Amp,USB, OTG,LCD, AES, 64 kbytes to 1 mbyte up to 320 kbytes of SRAM.STM32L4+(ULP with More performance): Wide choice of memory size,3 product lines, 5 MSPS ADC, compare, DAC, Op-Amp,USB, OTG,LCD, AES, 1 to 2 mbyte of flash upto 640 kbytes of SRAM.

STM32L5(Advance Security): Wide choice of memory size,1 product lines, 5 MSPS ADC, compare, DAC, Op-Amp,USB type C, AES, 256 to 512 kbyte of flash upto 2560 kbytes of SRAM.

Type of Security:

Logical attack:

-malicious code injection

-Malware replacing the genuine program

-Man-in-the-middle attack

Board level attack:

-Cloning attack

-Fault injection

-Side channel attack

For such type of attack STM32L5 provided Hardware isolation, Secure key storage, Encryption, Authentication, IP protection, read out protection, active tempering, certified crypto library.

Application:

Smart peripherals ( fitnes tracker-wristband): ADC, OPAmp, DAC, SAI, SPI/UART, I2C, Display.

Smart peripherals (industrial sensors): High temp, SPI,UART, SPI/UART, I2C, TRNG and AES, FSMC, I/Os, CAN, Motor control, Display.

5. Wireless MCUs(STM32WL,STM32WB):

-Fully certified Bluetooth 5.0 radio

-2x faster speed with 2 mbps capable mode

-Extend network coverage with BLE mesh

-open Thread, zigbee 3.0

STM32WB:

Provides open 2.4 Ghz radio multi protocol, Dual core/ full cobtrol ultra power , IoT protection ready, Massive integration, cost saving, Advance RF tool, Energy control with C code generation.

Flash/RAM memory: 1 M/128 k

Application(LPWAN technology selection): Agriculture, Low value object tracking, lighting smart meter, utility maintenance, smart parking, smart building, smart grid, smart watch, High value object tracking, Connected Cars

STM32GO Architecture:

Why STM32G0 ?

1)Thinner technology,more integration & enhanced technologies.
2)Bigger flash in small packages.
3)1% internal clock.
4)1 power supply: Less external capacitors.
5)IO Maximization: smallest package eligible.

STM32G0 Subsystems::

Following are the features of STM32G0 :

1)Maximum speed upto 64Mbps
2)Flash memory interface of 1kb
3)32 timers each of 16 bit.
4)USB Power delivery.
5)Error code correction for 8 bits long for a 64-bit word.
6)12 bit ADC.
7)2 KBYTE of page granularity
8)Pre-fetch & instruction cache.(To improve performance)

Boot Pin configuration::

Boot configuration is selected as per areas given below:
1)Main flash memory
2)System memory
3)Embedded SRAM
4)Main Flash memory
5)System memory
6)Embedded SRAM.
7)Main Flash memory forced.

Note:It is possible to force booting from flash memory.

Reset Sources:

No external components are needed due to internal filter and power monitoring.System Reset sources can reset external components.

System Reset:

Resets all registers except certain RCC Registers and the RTC domain.
The reset Source flag is in the RCC_CSR register.

DMA Configuration :

1)DMA support for timers, ADC, and communication peripherals.
2)Offloads CPU from data transfer management.
3)Simple Integration.

ADC Overview :

1)12 bit ADC with 19 input channels.
2)Over-sampler.
3)2.5 Msample/sec max (12 bit resolution)
4)Interrupt generation.

Application benefits:
1)Ultra-low power consumption: 118uA @ 1 Msample/s.
2)Flexible trigger,data management to offload CPU.

System Clock :

1)Selected between HSI16,HSE,PLL,LSI and LSE.
2)System clock AHB nad APB maximum frequency:64 MHZ

RNG(Random Number Generator) overview:
1)Used when producing an unpredictable result is desirable.
2)32-bit Random number generator based on a noise source.

Application benefits:
1)Increase the randomness of numbers.
2)Strongly decrease the possibility of guessing values.

Application examples are :
Cryptography and games.

AES overview:

Transforms original text called plaintext to unreadable text called ciphertext using a secure encryption key.Supports many standard operation modes and two key sizes(128 or 256 bits).

Application benefits:
1)Protects confidentiality and /or authenticity of data.
2)Reduces cpu processing time.

Securable memory area:
The main purpose of securable memory area is to protect some part of the flash memory against undesired access.

USART

Can be configured as:
i)UART
ii)SPI master/slave
iii) Smartcard
iv)IrDA SIR
v)LIN
vi)Modbus

Application benefits:
1)Multipurpose communication peripheral.
2)Simple hardware,Only a few pins needed.
3)Wakes from low power mode.
4)Transmit and Receive FIFOs, with capability to transmit and receive in stop modes.

LPUART
Low Power Universal Asynchronous Receiver/Transmitter.Full UART communication at 9600 baud with wake up from stop modes capability when using the low speed 32.768kHz external oscillator. Higher baud rates are available with other clock sources.

Application benefits:
Inexpensive communication link between devices.
Simple hardware,only a few pins needed.
Wakes from low power STOP modes.
Transmit and receive FIFO’s ,with capability to transmit and receive in stop modes.

ART Accelerator:

Pefetch queue and branch cache principle:
Stores the first instruction and constant of branches and interrupts events.
Push them in the prefetch queue in the next time those events occur,with no execution penalty.

Chrome ART:

Provides hardware acceleration for graphical operations.

Application benefits:
Offloads CPU for graphical operations.
One pixel per cycle calculation.
Integrated pixel format converter and blender
Simple integration through graphical stack.

Batch Acquisition mode:
Only the needed communication peripheral + 1DMA +1 SRAM are configured with clock enables in sleep mode.
Flash memory is put in power down mode and flash clock is gated off during sleep mode.
Enter either sleep or Low-power sleep mode.

STM32 Cube IDE:

(Integrated Development Platform for STM32 Embedded Solutions)

STMicroelectronics is a semiconductor provider

• STM32 is μC & μP general purpose brand

• Arm© 32b CPU(s) based

• Part of worldwide top 3 μC vendors

• More than x32 μC unit sold per second

• STM32 devices are augmenting our daily life

• Kitchen appliances, power plugs, audio headsets,white appliances, car facilities, energy smart grid, E-city facilities, E-toys, E-cigarettes, E-bicycles, E-watches, …

JSON libraries

 JSON libraries
1.frozen 
Output JSON objects in C as JSON formatted strings and parse 
JSON formatted strings back into the C presentation of 
the JSON objects.
FEATUES:
• C and C++ complaint portable.
• Several extra format specifiers supported.
JSON token:
This stucture contains-
Pointer pointing to beginning of the value.
Value length 
Type of the token
Token types are string,number,true,false,null,
object start, object end,array start and array end.
API’s:
• json_scanf
Scans json string directly into c/c++ variables.
• json_printf
Print c/c++ variables directly into output stream.
• json_setf
Modifies existing json_string.
• json_fread
Reads json from a file.
• json_fprintf
Writes json to a file.
• json_scanf_array_elem
Scan array element with given path and index
• json_printf_array
prints contiguous C arrays.
References:https://github.com/cesanta/frozen
SIZE of object file is 42 kBytes.
2.JSMN
Minimalistic JSON parser in C.
FEATURES:
Compatible with C89
Single head library
easily integrated into resource limited or
emb projects
API contains only 2 functions.
JSON token:
This structure contains-
type
start position in JSON data string
end position in JSON data string
size
Token types are-object,array,string,
primitive(number/boolean/true-false/null)
API’s:
•  jsmn_init
Create JSON parser over array of tokens.
•  jsmn_parse
Parses JSON data string into array of tokens,
each describing JSON object.
References:https://github.com/zserge/jsmn
SIZE of object file is upto 26 kBytes.
3.JSON-C
JSON-C implements referrence counting object that 
allows you to easily construct JSON objects in c,
output them as JSON formatted strings and parse 
JSON formatted strings back into c 
representation of JSON objects.
FEATURES:
JSON token:
Token types are boolean,double,int,object,array,string.
API’s:
• json_object_to_json_string
Stringify object to JSON format grabbing the 
shared ownership of object.
• json_object_get
Increament reference count of json_object.
• json_object_put
Decrement reference count of json_object,and free 
it if reaches to zero.
• json_object_userdata_to_json_string
Copy the userdata string to over the 
destination buffer.
• json_object_new_array
Create a new empty json_object of type 
json_type_array.
• json_object_get_array
Get the arraylist of json_object of type 
json_type_array.
• json_object_array_add
Add an element to the end of json_object 
of type json_type_array.
• json_obect_array_put_idx
Insert or replace an element at a specified 
index of the array.
• json_object_array_get_idx
Get the element at specifies index of the 
array.
All these functions for array are also defined for 
following json_types- 
boolean,double,int,int64,object .
References:https://github.com/json-c/json-c
SIZE of object file is upto 300 kBytes.

Login App in Android

To Create any application in android we have to deal with three files:

  • AndroidManifest.xml
  • activity_main.xml
  • MainActivity.java

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.login.login">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>

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"
tools:context = ".MainActivity">
<TextView android:text = "Login" android:layout_width="wrap_content"
android:layout_height = "wrap_content"
android:id = "@+id/textview"
android:textSize = "35dp"
android:layout_alignParentTop = "true"
android:layout_centerHorizontal = "true" />
<EditText
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id = "@+id/editText"
android:hint = "Enter Name"
android:focusable = "true"
android:textColorHighlight = "#ff7eff15"
android:textColorHint = "#ffff25e6"
android:layout_marginTop = "46dp"
android:layout_alignParentLeft = "true"
android:layout_alignParentStart = "true"
android:layout_alignParentRight = "true"
android:layout_alignParentEnd = "true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:textColorHint="#ffff299f"
android:hint="Password" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attempts Left:"
android:id="@+id/textView2"
android:layout_below="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView3"
android:layout_alignTop="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/textView2"
android:layout_toEndOf="@+id/textview"
android:textSize="25dp"
android:layout_toRightOf="@+id/textview" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/textview"
android:layout_toStartOf="@+id/textview" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/textview"
android:layout_toEndOf="@+id/textview" />
</RelativeLayout>

MainActivity.java

package com.login.login;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity  {
Button b1,b2;
EditText ed1,ed2;
TextView tx1;
int counter = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.button);
ed1 = (EditText)findViewById(R.id.editText);
ed2 = (EditText)findViewById(R.id.editText2);
b2 = (Button)findViewById(R.id.button2);
tx1 = (TextView)findViewById(R.id.textView3);
tx1.setVisibility(View.GONE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(ed1.getText().toString().equals("manasi") &&
ed2.getText().toString().equals("abc")) {
Toast.makeText(getApplicationContext(),
"Redirecting...",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(),"Wrong Credentials",Toast.LENGTH_SHORT).show();
tx1.setVisibility(View.VISIBLE);
tx1.setBackgroundColor(Color.RED);
counter--;
tx1.setText(Integer.toString(counter));
if (counter == 0) {
b1.setEnabled(false);
}
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}

Output:

Navigation from one screen to another screen in android

Functionality:

How to interact with activity,when a button is clicked,navigate from current screen(current activity) to another screen(another activity).

Activity:

In android,an activity is representing a single screen.Most applications have multiple activities to represent different screens.for example,one activity to display a list of the application settings,another to display application status.

To Create any application in android we have to deal with three files:

  • AndroidManifest.xml
  • activity_main.xml
  • MainActivity.java

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nav.navigation"
>
<application
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Second_screen"></activity>
</application>
</manifest>

Strings.xml:

<resources>
<string name="app_name">Navigation</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="button_name">Go to second screen</string>
<string name="title1">Welcome to Navigation (First screen)</string>
<string name="title2">Welcome to Navigation (second screen)</string>
</resources>

In this example,we have to navigate from one to another screen so we need to create two layout files and two java files.

activity_main.xml:

This is layout file which represents first screen.First screen contains one textview and button.Textview is texted as “Welcome to Navigation” and button texted as “Go To second screen”.

<?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"
tools:context=".MainActivity">
<TextView
android:id="@+id/head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="@string/title1"  />
<Button
android:id="@+id/first_screen_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/head"
android:layout_marginTop="16dp"
android:text="@string/button_name"
/>
</RelativeLayout>

MainActivity.java:

This java file contains code to navigate to second screen.file has OnClickListener which make Button click to go to second screen.

package com.nav.navigation;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
private Button nextScreen;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nextScreen = (Button) findViewById(R.id.first_screen_button);
nextScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent agn = new Intent(MainActivity.this, Second_screen.class);
startActivity(agn);
}
});
}
public void onClick(View v) {
}
}

second_screen.xml:

This is layout file which represents second screen.second screen contains one textview.Textview is texted as “Welcome to Second Screen”.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/title2"/>
</RelativeLayout>

Second_screen.java

This java file contains code of action to be performed after clicking on button in first screen.

package com.nav.navigation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class Second_screen extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_screen);
TextView tv = new TextView(this);
tv.setText("Welcome to Second screen");
setContentView(tv);
}
public void onClick(View v) {
}
}

Output:

First screen
Second screen

Calculator App in Android

Here ,we are creating simple and basic functions calculator App. This app can help you to understand the layouts, buttons and action handling. To create this app we need to use different widgets such as TextView, button, EditText etc.This app is able to perform following basic four mathematical functions :

  • Addition
  • Subtraction
  • Multiplication
  • Division

To Create any application in android we have to deal with three files:

  • AndroidManifest.xml
  • activity_main.xml
  • MainActivity.java

AndroidManifest.xml

The AndroidManifest.xml contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.calculator.calculator2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>

activity_main.xml

The activity is a Java class, and the layout is an XML file, so the names we’ve given here will create a Java class file called MainActivity.java and an XML file called activity_main.xml. layout containing two EditTexts,4 Buttons and one textview. Give them id according to their name so that when we’ll write java code, it will be helpful to understand which buttons we are dealing with.To arrange these widgets we need to use different layouts.Here,we used linear layout to display EditText, Buttons and TextView in linear fashion.Use of widgets is as follows:

  • EditText:we used two EditTexts to get two input values from user.
  • Buttons: we used four Buttons which performs functions of addition,subtraction,multiplication and division.
  • TextView:TextView is used to display result.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1"
android:layout_marginLeft="10pt"
android:layout_marginRight="10pt"
android:layout_marginTop="3pt">
<EditText
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5pt"
android:id="@+id/etNum1"
android:layout_width="match_parent"
android:inputType="numberDecimal">
</EditText>
<EditText
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5pt"
android:id="@+id/etNum2"
android:layout_width="match_parent"
android:inputType="numberDecimal">
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_marginTop="3pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="+"
android:textSize="8pt"
android:id="@+id/btnAdd">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="-"
android:textSize="8pt"
android:id="@+id/btnSub">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="*"
android:textSize="8pt"
android:id="@+id/btnMult">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="/"
android:textSize="8pt"
android:id="@+id/btnDiv">
</Button>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt"
android:textSize="12pt"
android:layout_marginTop="3pt"
android:id="@+id/tvResult"
android:gravity="center_horizontal">
</TextView>
</LinearLayout>

MainActivity.java

The main activity code is a Java file MainActivity.java. This is the actual application file which ultimately gets converted to a Dalvik executable and runs your application.

OnClick Listener:

Tis listener is used to get get result once we click on button.In this example,to get input from user we used getText() method.Once user input two values to perform operation user need to press any button.switch case is used to give functionality to buttons.Suppose user clicked on Addition button control goes to case R.id.btnAdd and it performs ‘+’ operation

package com.calculator.calculator2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class MainActivity extends AppCompatActivity implements OnClickListener {
EditText etNum1;
EditText etNum2;
Button btnAdd;
Button btnSub;
Button btnMult;
Button btnDiv;
TextView tvResult;
String oper = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etNum1 = (EditText) findViewById(R.id.etNum1);
etNum2 = (EditText) findViewById(R.id.etNum2);
btnAdd = (Button) findViewById(R.id.btnAdd);
btnSub = (Button) findViewById(R.id.btnSub);
btnMult = (Button) findViewById(R.id.btnMult);
btnDiv = (Button) findViewById(R.id.btnDiv);
tvResult = (TextView) findViewById(R.id.tvResult);
btnAdd.setOnClickListener(this);
btnSub.setOnClickListener(this);
btnMult.setOnClickListener(this);
btnDiv.setOnClickListener(this);
}
@Override
public void onClick(View v) {
float num1 = 0;
float num2 = 0;
float result = 0;
// check if the fields are empty
if (TextUtils.isEmpty(etNum1.getText().toString())
|| TextUtils.isEmpty(etNum2.getText().toString())) {
return;
}
num1 = Float.parseFloat(etNum1.getText().toString());
num2 = Float.parseFloat(etNum2.getText().toString());
switch (v.getId()) {
case R.id.btnAdd:
oper = "+";
result = num1 + num2;
break;
case R.id.btnSub:
oper = "-";
result = num1 - num2;
break;
case R.id.btnMult:
oper = "*";
result = num1 * num2;
break;
case R.id.btnDiv:
oper = "/";
result = num1 / num2;
break;
default:
break;
}
// form the output line
tvResult.setText(num1 + " " + oper + " " + num2 + " = " + result);
}
}

Output:

USB Communication

About Android USB

Android supports USB devices through two modes:

  • Android Accessory: In this mode external USB device acts as host.
  • Android Host: In this mode Android Device acts as host and powers the external device.

Manifest File for USB connection

We want to be notified when an external USB device is attached to the Android device.This can be done adding a new intent filter entry to the Activity that should be started by the system when a USB device is plugged in.

<activity  
.......
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
<meta-data  android:name=
"android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />    
<meta-data android:name=
"android.hardware.usb.action.USB_DEVICE_DETACHED"
android:resource="@xml/device_filter" />
</activity>  

In above code, MainActivity registers to be informed when a USB device is connected (USB_DEVICE_ATTACHED) or disconnected (USB_DEVICE_DETACHED). If we want to restrict the type of devices, we can include a device filter XML file indicated in the meta-data element.This file is stored in /res/xml folder and lists combinations of vendor id , product id ,manufacturer,version etc.

USB Configuration in java file

To receive the USB events, we need to create a BroadcastReceiver and then register it. In this case, the events will be received via the onReceive() method of BroadcastReceiver.

private static final String ACTION_USB_ATTACHED  = "android.hardware.usb.action.USB_DEVICE_ATTACHED";  
private static final String ACTION_USB_DETACHED  = "android.hardware.usb.action.USB_DEVICE_DETACHED"; 
BroadcastReceiver bReceiver= new BroadcastReceiver() {...};  
IntentFilter filter = new IntentFilter();  
filter.addAction(ACTION_USB_ATTACHED);  
filter.addAction(ACTION_USB_DETACHED);  
registerReceiver(bReceiver,filter); 
public void onReceive(Context context, Intent intent) {  
String action = intent.getAction();          
if (action.equalsIgnoreCase(ACTION_USB_DETACHED)) {...}         ...
}

Permission

Before communicating with the USB accessory, your application must have permission from your users.If you want to obtain permission explicitly, then you need to call requestPermission(). In onCreate() you need to create permission intent and pass that to requestPermission().

openAccessory()

Once permission granted openAccessory() method will be called.This method is used to communicate with accessory.file descriptor can be used to set up input and output streams to read and write data to descriptor.The streams represent the accessory’s input and output endpoints.

Display selected item of ListView using toast in android

ListView

In Android, List of scroll-able items can be displayed using ListView. Users can select any list item by clicking on it.

Problem Statement:

Develop an application to create list of fruits using ListView and display selected fruit of ListView using toast. How to get the selected item from ListView?

Several Ways to create ListView:

There 2 ways to create ListView:

  • we can assign ListView by giving values in main.xml.
  • we can assign values in string.xml.

Sample Code:

Here is sample code for ListView using toast in android, Created two files to develop an application.

  • Layout file(activity_main.xml):This file contains code to design an GUI of an application. In this we have used widget ListView to display list and TextView to display text on lists.
  • Activity file(MainActivity.java): This file contains code to perform activity on listview.In this we have created Array, ArrayList, Adapter and ListView. We have added created Array into ArrayList then ArrayList into Adapter and then Adapter into ListView.

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="#000000"
tools:context=".MainActivity">
<ListView
android:id="@+id/listViewID"
android:layout_width="match_parent"
android:layout_height="495dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

MainActivity.java

package com.toast.listviewe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.view.ViewGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity{
ListView fruitView;
String[] fruits = new String[]
{
"Mango",
"Orange",
"Guava",
"Banana",
"Pineapple",
"Apple"
};
List<String> fruitList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fruitView = (ListView) findViewById(R.id.listViewID);
fruitList = new ArrayList<String>(Arrays.asList(fruits));
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, android.R.id.text1, fruitList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView ListItemShow = (TextView) view.findViewById(android.R.id.text1);
ListItemShow.setTextColor(Color.parseColor("#ffffff"));
return view;
}
};
fruitView.setAdapter(adapter);
fruitView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this, "clicked item is " +fruits[position], Toast.LENGTH_SHORT).show();
}
});
}
}

Output:

Hello World in android studio using activity,service & broadcastReceiver

Problem Statement:

Printing Hello World text using activity,service and broadcast receiver.

This program demonstrates how to call any activity from service and service from broadcast receiver. The application starts from broadcast receiver then control goes to service and service call activity to print “Hello World”.

Several ways To create an application:

  • LocalBroadcastManager:This can be used ,If you want to send broadcasts to your application.
  • BroadcastReceiver:This can be used,If you want to send broadcasts across applications.

About Code:

I have created 3 java classes namely broadcast,MyService,MyActivity.

  • broadcast.java :This class inherits BroadcastReceiver class and contains method onReceive(Context context, Intent intent) to create an intent and to call startService() method.
  • MyService.java:This class inherits Service class and contains method onBind(Intent intent) to create intent and to call startActivity().
  • MainActivity.java:This class inherits Activity class and contains method onCreate() to create an application.

Output:

Output

Manifest File:AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.all.ActivityServiceBroadcast">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<receiver android:name=".broadcast">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
</receiver>
<service
android:name=".MyService"
android:enabled="false"
android:exported="true"></service>
<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>

Layout file:activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

BroadcastReceiver file:broadcast.java

package com.all.ActivityServiceBroadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class broadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
String action = intent.getAction();
}
}

Service file:MyService.java

package com.all.ActivityServiceBroadcast;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
Intent ActivityIntent = new Intent(this,MainActivity.class);
startActivity(ActivityIntent);
throw new UnsupportedOperationException("Not yet implemented");
}
}

Activity file:MainActivity.java

package com.all.ActivityServiceBroadcast;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle SavedInstanceState) {
super.onCreate(null);
setContentView(R.layout.activity_main);
}
}