avaneeshkumarmaurya / Barcode-Reader

Barcode Reader Using Google Mobile Vision
Apache License 2.0
65 stars 40 forks source link

how to implement this precisely in android fragments ? #5

Open rogerkamal opened 5 years ago

rogerkamal commented 5 years ago

I'm new developer, I stuck up so heavily into vision api barcode?

can you tell me clean java code to how to get over into this ?

This is my main.xml

<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:layout_gravity="center"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="400dp"
        android:contentDescription="@null"
        android:foregroundGravity="center"
        android:padding="50dp"
        app:layout_editor_absoluteY="0dp"
        app:srcCompat="@drawable/sooperbuylogo"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" />

    <Button
        android:id="@+id/ButtonScan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/logo"
        android:layout_centerHorizontal="true"
        android:onClick="scan"
        android:background="#009688"
        android:padding="5dp"
        android:textColor="#ffffff"
        android:text="START SCANNING"
        android:textSize="20sp"/>

</RelativeLayout>

This is my activity_scan.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_weight="1"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <fragment
        android:id="@+id/barcode_fragment"
        android:name="com.notbytes.barcode_reader.BarcodeReaderFragment"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="300dp"
        app:auto_focus="true"
        app:use_flash="false" />

    <com.notbytes.barcode_reader.ScannerOverlay
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#44000000"
        app:line_color="#7323DC"
        app:line_speed="6"
        app:line_width="5"
        app:square_height="250"
        app:square_width="250" />

    <fragment
        android:id="@+id/result_fragment"
        android:layout_width="match_parent"
        android:layout_gravity="bottom"
        android:layout_height="500dp"
        android:layout_weight="1"
        tools:layout="@layout/activity_scan_result"/>

</LinearLayout>

Here is my activity_scan_result.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".scan_result">

    <RelativeLayout
        android:layout_width="match_parent"
        android:gravity="top"
        android:layout_height="match_parent"
        >

        <!--  ::::::  Adding a Toolbar  :::::::      -->
        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:gravity="top"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="Transparent"
            android:elevation="8dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        <ImageView
            android:layout_width="wrap_content"
            android:id="@+id/icon"
            android:src="@android:drawable/arrow_down_float"
            android:layout_height="match_parent" />

        </android.support.v7.widget.Toolbar>

        <!--::::::::::::    layout for data     ::::::::::::::::::::::::-->

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="20dp"
            android:id="@+id/srollover"
            android:layout_below="@+id/my_toolbar"
            >

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

<!--    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::   -->

                <TextView
                    android:id="@+id/tv1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="one"
                    />

                <TextView
                    android:id="@+id/tv2"
                    android:layout_below="@+id/tv1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="two"
                    />
                <TextView
                    android:id="@+id/tv3"
                    android:layout_below="@+id/tv2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="three"
                    />

            </RelativeLayout>

        </ScrollView>

<!--    ::::::: Layout for Buttons   :::::::::            -->

        <LinearLayout
            android:id="@+id/btns"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:foregroundGravity="center">

            <Button
                android:id="@+id/reset"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:textColor="#2196F3"
                android:textAllCaps="false"
                android:text="Reset"
                android:textSize="18sp"/>

            <Button
                android:id="@+id/confirm"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:textSize="18sp"
                android:text="Confirm"
                android:textAllCaps="false"
                android:textColor="#2196F3" />

        </LinearLayout>

        <LinearLayout
            android:layout_below="@id/btns"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:paddingTop="10dp"
                android:src="@drawable/sooperbuylogo" />

        </LinearLayout>

    </RelativeLayout>

</LinearLayout>
rogerkamal commented 5 years ago

I want to get fragment scanner's result into under my customised fragment layout's activity.. @ @avaneeshkumarmaurya