Листинг программы Barcode Scanner Library



Download 40,3 Kb.
bet1/3
Sana28.01.2021
Hajmi40,3 Kb.
#56941
  1   2   3
Bog'liq
Kod Kodirov



Листинг программы
Barcode Scanner Library







compile 'com.google.android.gms:play-services-vision:11.0.2'

build.gradle




dependencies {

    // barcode reader library

    implementation 'info.androidhive:barcode-reader:1.1.5'

 

    // google vision library



    implementation 'com.google.android.gms:play-services-vision:11.0.2'

}

        android:id="@+id/barcode_scanner"

        android:name="info.androidhive.barcode.BarcodeReader"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        app:auto_focus="true"

        app:use_flash="false" />


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.SparseArray;

import com.google.android.gms.vision.barcode.Barcode;

import java.util.List;

 

import info.androidhive.barcode.BarcodeReader;



 

public class MainActivity extends AppCompatActivity implements BarcodeReader.BarcodeReaderListener {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_scan);

    }

 

    @Override



    public void onScanned(Barcode barcode) {

        // single barcode scanned

    }

 

    @Override



    public void onScannedMultiple(List list) {

        // multiple barcodes scanned

    }

 

    @Override



    public void onBitmapScanned(SparseArray sparseArray) {

        // barcode scanned from bitmap image

    }

 

    @Override



    public void onScanError(String s) {

        // scan error

    }

 

    @Override



    public void onCameraPermissionDenied() {

        // camera permission denied

    }

}


    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="#44000000"

    app:line_color="#7323DC"

    app:line_speed="6"

    app:line_width="4"

    app:square_height="200"

    app:square_width="200"/>


{

    "name": "Dunkirk",

    "poster": "https://api.androidhive.info/barcodes/dunkirk.jpg",

    "duration": "1hr 46min",

    "rating": 4.6,

    "released": true,

    "genre": "Action",

    "price": "₹200",

    "director": "Christopher Nolan"

}


app/build.gradle

dependencies {

    implementation 'com.google.android.gms:play-services-vision:11.0.2'

 

    // vision barcode scanner



    implementation 'info.androidhive:barcode-reader:1.1.2'

 

    // glide image library



    implementation 'com.github.bumptech.glide:glide:4.0.0-RC1'

    annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC1'

 

    implementation 'com.android.volley:volley:1.0.0'



    implementation 'com.google.code.gson:gson:2.6.2'

}


strings.xml

    Movie Tickets

    Book Ticket

    DURATION

    GENRE

    RATING

    PRICE

    BUY NOW

    COMING SOON

    No ticket found. Try scanning the QR Codes from http://api.androidhive.info/qrcodes/













dimens.xml





    20dp

    10dp

    16dp

    14dp

    28dp

    220dp

    40dp





colors.xml



    #6d0094

    #6d0094

    #ff2068

    #ad1a7f

    #f8f8f8

    #999

    #222222







MyApplication.java

import android.app.Application;

import android.text.TextUtils;

 

import com.android.volley.Request;



import com.android.volley.RequestQueue;

import com.android.volley.toolbox.Volley;

 

/**


 * Created by ravi on 31/07/17.

 */


 

public class MyApplication extends Application {

 

    public static final String TAG = MyApplication.class



            .getSimpleName();

 

    private RequestQueue mRequestQueue;



 

    private static MyApplication mInstance;

 

    @Override



    public void onCreate() {

        super.onCreate();

        mInstance = this;

    }


 

    public static synchronized MyApplication getInstance() {

        return mInstance;

    }


 

    public RequestQueue getRequestQueue() {

        if (mRequestQueue == null) {

            mRequestQueue = Volley.newRequestQueue(getApplicationContext());

        }

 

        return mRequestQueue;



    }

 

    public void addToRequestQueue(Request req, String tag) {



        // set the default tag if tag is empty

        req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);

        getRequestQueue().add(req);

    }


 

    public void addToRequestQueue(Request req) {

        req.setTag(TAG);

        getRequestQueue().add(req);

    }

 

    public void cancelPendingRequests(Object tag) {



        if (mRequestQueue != null) {

            mRequestQueue.cancelAll(tag);

        }

    }


}

AndroidManifest.xml



    package="info.androidhive.movietickets">

 

    



 

    

        android:name=".MyApplication"

        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">

        

            android:name=".MainActivity"

            android:screenOrientation="portrait"

            android:theme="@style/AppTheme.NoActionBar">

            

                

 

                



            

        

        

            android:name=".ScanActivity"

            android:screenOrientation="portrait" />

        

            android:name=".TicketActivity"

            android:label="@string/title_activity_ticket"

            android:screenOrientation="portrait"

            android:theme="@style/AppTheme.NoActionBar">

    





    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/bg_gradient"

    tools:context="info.androidhive.movietickets.MainActivity">

 

    

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_centerHorizontal="true"

        android:layout_centerInParent="true"

        android:gravity="center"

        android:orientation="vertical"

        android:paddingLeft="40dp"

        android:paddingRight="40dp">

 

        

            android:id="@+id/icon"

            android:layout_width="100dp"

            android:layout_height="100dp"

            android:layout_centerHorizontal="true"

            android:clickable="true"

            android:foreground="?attr/selectableItemBackground"

            android:src="@drawable/qrcode"

            android:tint="@android:color/white" />

 

        

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginTop="30dp"

            android:fontFamily="sans-serif-light"

            android:gravity="center"

            android:text="Scan the QR code on the poster and book your movie tickets"

            android:textColor="@android:color/white"

            android:textSize="16dp" />

    

 

    

        android:id="@+id/btn_scan"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"

        android:layout_centerHorizontal="true"

        android:layout_marginBottom="40dp"

        android:background="@android:color/transparent"

        android:foreground="?attr/selectableItemBackground"

        android:paddingLeft="20dp"

        android:paddingRight="20dp"

        android:fontFamily="sans-serif-medium"

        android:text="Scan QR Code"

        android:textColor="@android:color/white"

        android:textSize="18sp" />

 



MainActivityavaz.java

import android.app.Activity;

import android.content.Intent;

import android.graphics.Color;

import android.os.Build;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.SparseArray;

import android.view.View;

import android.view.Window;

import android.view.WindowManager;

 

import com.google.android.gms.vision.barcode.Barcode;



 

import java.util.List;

 

import info.androidhive.barcode.BarcodeReader;



 

public class MainActivity extends AppCompatActivity {

 

    @Override



    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

 

        // making toolbar transparent



        transparentToolbar();

 

        setContentView(R.layout.activity_main);



 

        findViewById(R.id.btn_scan).setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                startActivity(new Intent(MainActivity.this, ScanActivity.class));

            }

        });

    }


 

    private void transparentToolbar() {

        if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {

            setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, true);

        }

        if (Build.VERSION.SDK_INT >= 19) {

            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

        }

        if (Build.VERSION.SDK_INT >= 21) {

            setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false);

            getWindow().setStatusBarColor(Color.TRANSPARENT);

        }

    }

 

    private void setWindowFlag(Activity activity, final int bits, boolean on) {



        Window win = activity.getWindow();

        WindowManager.LayoutParams winParams = win.getAttributes();

        if (on) {

            winParams.flags |= bits;

        } else {

            winParams.flags &= ~bits;

        }

        win.setAttributes(winParams);

    }

}




Download 40,3 Kb.

Do'stlaringiz bilan baham:
  1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish