Working with Augmented reality – ARCore


What is ARCore

ARCore is Google’s platform for building augmented reality experiences. Using different APIs, ARCore enables your phone to sense its environment, understand the world and interact with information. Some of the APIs are available across Android and iOS to enable shared AR experiences.


Capabilities 

ARCore uses three key capabilities to integrate virtual content with the real world as seen through your phone’s camera:

  • Motion tracking allows the phone to understand and track its position relative to the world.
  • Environmental understanding allows the phone to detect the size and location of all type of surfaces: horizontal, vertical and angled surfaces like the ground, a coffee table or walls.
  • Light estimation allows the phone to estimate the environment’s current lighting conditions.

Supported Devices

ARCore is designed to work on a wide variety of qualified Android phones running Android 7.0 (Nougat) and later. A full list of all supported devices is available here.

Working With ARCore For Android

Create an Android project and paste these code to the gradle(app) file


Create an Android project and paste these code to the gradle(app) file

implementation ‘com.google.ar.sceneform.ux:sceneform-ux:1.6.0’
implementation ‘com.google.ar.sceneform:core:1.6.0’
implementation ‘com.google.ar.sceneform:assets:1.6.0’


IOS progress dialog in swift 4

Step : 1 Create a swift class that can be used as reusable

[java]

import UIKit

class ProgressHUD: UIVisualEffectView {

var text: String? {
didSet {
label.text = text
}
}

let activityIndictor: UIActivityIndicatorView = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray)
let label: UILabel = UILabel()
let blurEffect = UIBlurEffect(style: .light)
let vibrancyView: UIVisualEffectView

init(text: String) {
self.text = text
self.vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect))
super.init(effect: blurEffect)
self.setup()
}

required init?(coder aDecoder: NSCoder) {
self.text = ""
self.vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect))
super.init(coder: aDecoder)
self.setup()
}

func setup() {
contentView.addSubview(vibrancyView)
contentView.addSubview(activityIndictor)
contentView.addSubview(label)
activityIndictor.startAnimating()
}

override func didMoveToSuperview() {
super.didMoveToSuperview()

if let superview = self.superview {

let width = superview.frame.size.width / 2.3
let height: CGFloat = 50.0
self.frame = CGRect(x: superview.frame.size.width / 2 – width / 2,
y: superview.frame.height / 2 – height / 2,
width: width,
height: height)
vibrancyView.frame = self.bounds

let activityIndicatorSize: CGFloat = 40
activityIndictor.frame = CGRect(x: 5,
y: height / 2 – activityIndicatorSize / 2,
width: activityIndicatorSize,
height: activityIndicatorSize)

layer.cornerRadius = 8.0
layer.masksToBounds = true
label.text = text
label.textAlignment = NSTextAlignment.center
label.frame = CGRect(x: activityIndicatorSize + 5,
y: 0,
width: width – activityIndicatorSize – 15,
height: height)
label.textColor = UIColor.gray
label.font = UIFont.boldSystemFont(ofSize: 16)
}
}

func show() {
self.isHidden = false
}

func hide() {
self.isHidden = true
}
}

[/java]

Step 2 : Now call the class and method from Controller Class .

– show the progress dialog

[java]
let progressHUD = ProgressHUD(text: "Please wait")
self.view.addSubview(progressHUD)
progressHUD.show()
[/java]

– hide the progress dialog

[java]
progressHUD.show()
[/java]

Convert millisecond/ Unix date time format to actual date time in swift 4

1 . From millisecond to date time format and show on a label

[java]
let date = Date(timeIntervalSince1970: (yourDateValue / 1000.0))

let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "GMT") //Set timezone that you want
dateFormatter.locale = NSLocale.current
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm" //Specify your format that you want
let strDate = dateFormatter.string(from: date)

publishedDate.text = strDate

[/java]

2 . From unix to date time format and show on a label

[java]
let date = Date(timeIntervalSince1970: (yourDateValue))

let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "GMT") //Set timezone that you want
dateFormatter.locale = NSLocale.current
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm" //Specify your format that you want
let strDate = dateFormatter.string(from: date)

publishedDate.text = strDate

[/java]

Android touch swipe detection on left , right , top , bottom java and kotlin

Step 1 : Create a java class

[java]
import android.content.Context;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class OnSwipeTouchListener implements OnTouchListener {

private final GestureDetector gestureDetector;

public OnSwipeTouchListener (Context ctx){
gestureDetector = new GestureDetector(ctx, new GestureListener());
}

@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}

private final class GestureListener extends SimpleOnGestureListener {

private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;

@Override
public boolean onDown(MotionEvent e) {
return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() – e1.getY();
float diffX = e2.getX() – e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
result = true;
}
}
else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeBottom();
} else {
onSwipeTop();
}
result = true;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}

public void onSwipeRight() {
}

public void onSwipeLeft() {
}

public void onSwipeTop() {
}

public void onSwipeBottom() {
}
}
[/java]

Step 2 : Implement in activity

[java]

yourView.setOnTouchListener(new OnSwipeTouchListener(MyActivity.this) {
public void onSwipeTop() {
Toast.makeText(MyActivity.this, "top", Toast.LENGTH_SHORT).show();
}
public void onSwipeRight() {
Toast.makeText(MyActivity.this, "right", Toast.LENGTH_SHORT).show();
}
public void onSwipeLeft() {
Toast.makeText(MyActivity.this, "left", Toast.LENGTH_SHORT).show();
}
public void onSwipeBottom() {
Toast.makeText(MyActivity.this, "bottom", Toast.LENGTH_SHORT).show();
}

});

[/java]

In Kotlin 

Step 1 :

[java]

import android.view.GestureDetector
import android.view.MotionEvent
import android.view.View

/**
* Created by ARIF HASNAT on 1/19/19.
*/

open class OnSwipeTouchListener : View.OnTouchListener {

private val gestureDetector = GestureDetector(GestureListener())

fun onTouch(event: MotionEvent): Boolean {
return gestureDetector.onTouchEvent(event)
}

private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {

private val SWIPE_THRESHOLD = 100
private val SWIPE_VELOCITY_THRESHOLD = 100

override fun onDown(e: MotionEvent): Boolean {
return true
}

override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
onTouch(e)
return true
}

override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
val result = false
try {
val diffY = e2.y – e1.y
val diffX = e2.x – e1.x
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
//onSwipeRight()
onSwipeLeft()
} else {
//onSwipeLeft()
onSwipeRight()
}
}
} else {
// onTouch(e);
}
} catch (exception: Exception) {
exception.printStackTrace()
}

return result
}
}

override fun onTouch(v: View, event: MotionEvent): Boolean {
return gestureDetector.onTouchEvent(event)
}

open fun onSwipeRight() {}

open fun onSwipeLeft() {}

open fun onSwipeTop() {}

open fun onSwipeBottom() {}
}
[/java]

Step 2 : 

[java]
/***
* Swipe left and right activity
*/

yourView.setOnTouchListener(object : OnSwipeTouchListener() {

override fun onSwipeLeft() {
Log.e("ViewSwipe", "Left")
//toast("Left!")

val intent = Intent(this@MainPage, LeftActivity::class.java);
startActivity(intent)
}

override fun onSwipeRight() {
Log.e("ViewSwipe", "Right")
// toast("Right!")
val intent = Intent(this@MainPage, RightActivity::class.java);
startActivity(intent)
}
})
[/java]