├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro ├── release │ ├── app-release.apk │ ├── fastest_barcode_and_qr_code_V_2.0.apk │ ├── fastest_barcode_and_qr_code_v_2.1.apk │ └── output.json └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── nextinnovation │ │ └── pt │ │ └── barcodereaderforplaystore │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── nextinnovation │ │ │ └── pt │ │ │ └── barcodescanner │ │ │ ├── activity │ │ │ ├── MainActivity.java │ │ │ ├── SplashActivity.java │ │ │ └── WebViewActivity.java │ │ │ ├── adapter │ │ │ └── ProductAdapter.java │ │ │ ├── database │ │ │ └── DatabaseHelper.java │ │ │ ├── fragment │ │ │ ├── BarcodeFragment.java │ │ │ ├── LicenseFragment.java │ │ │ └── ProductListFragment.java │ │ │ ├── model │ │ │ └── Product.java │ │ │ └── utils │ │ │ ├── ClipBoardManager.java │ │ │ └── Utils.java │ └── res │ │ ├── drawable │ │ ├── barcode_icon_2_png.png │ │ ├── button_background.xml │ │ ├── button_focus.xml │ │ ├── button_press.xml │ │ ├── button_unfocus.xml │ │ ├── ic_access_time_black_24dp.xml │ │ ├── ic_barcode.xml │ │ ├── ic_content_copy_white_24dp.xml │ │ ├── ic_search_white_24dp.xml │ │ ├── ic_share_black_24dp.xml │ │ ├── ic_warning_black_24dp.xml │ │ ├── splash_drawable.xml │ │ └── style_toggle_button.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_splash.xml │ │ ├── activity_web_view.xml │ │ ├── fragment_barcode_scanner.xml │ │ ├── fragment_license.xml │ │ ├── fragment_prduct_list.xml │ │ ├── row_barcode.xml │ │ └── row_native_express_add.xml │ │ ├── menu │ │ └── main_menu.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── nextinnovation │ └── pt │ └── barcodereaderforplaystore │ └── ExampleUnitTest.java ├── build.gradle ├── google_play_screenshots ├── copy_share_search.png ├── home_screen.png ├── scan_result_screen.png ├── scan_screen.png └── web_search.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BarcodeAndQRReaderAndroid 2 | ## Best Barcode And QR Code Reder for Android . ## 3 | ### Google Play - https://play.google.com/store/apps/details?id=com.nextinnovation.pt.barcodescanner 4 | #### Android Fastest Barcode & QR Code Reader is the best tool for scanning Barcode & QR code instantly within 2-5 Seconds. Below are some features of this app #### 5 | 6 | 1. Scan QR Code faster than other tool. 7 | 2. Scan Barcode faster than other tool. 8 | 3. Flashlight support for night scanning. 9 | 4. Save result for future use. 10 | 5. Share your Barcode or QR Code. 11 | 6. Search for your barcode result or Direct link opening. 12 | 7. Copy as a plain text to use. 13 | 8. Can able to scan different formats of QR Codes, Data Matrix, PDF-417, and Aztec values 14 | 9. Supports 1D barcodes: EAN-13, EAN-8, UPC-A, UPC-E, Code-39, Code-93, Code-128, ITF, Codabar 15 | 10. Supports 2D barcodes: QR Code, Data Matrix, PDF-417, Aztec 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | ### For developer preview Fastest Barcode & QR Code Reader covered different Android Topics & Library. ### 26 | 27 | #### Android Topics Covered in This App: #### 28 | 29 | 1. Activity & Fragment 30 | 2. Android Material Design Cocepts 31 | 3. Android View Pager With TAB . 32 | 4. Using RecylerView & CardView. 33 | 5. Toolbar Menu 34 | 6. Android WebView 35 | 7. Android Share Intent & Copy To Clipboard 36 | 37 | #### Usages Library & Purpose #### 38 | 39 | **1. Material Barcode Scanner** - For Barcode & QR Code Scan. 40 | 41 | Dependency : `com.edwardvanraak:MaterialBarcodeScanner:0.0.6-ALPHA` 42 | 43 | GitHub : https://github.com/EdwardvanRaak/MaterialBarcodeScanner 44 | 45 | **2. Firebase Core & Ads** - For analytics & Google Adsense 46 | 47 | Dependecies : 48 | 49 | `compile 'com.google.firebase:firebase-core:11.6.0'` 50 | 51 | `compile 'com.google.firebase:firebase-ads:11.6.0'` 52 | 53 | Firebase : https://firebase.google.com/ 54 | 55 | **3. Fabric Crash Analytics** : For reporting crash. 56 | 57 | Dependency : `com.crashlytics.sdk.android:crashlytics:2.7.1@aar` 58 | 59 | Fabric : https://fabric.io/ 60 | 61 | 62 | ### Follow Me : ### 63 | 64 | Github : https://github.com/Piashsarker 65 | 66 | Linkedin : https://www.linkedin.com/in/piashsarker/ 67 | 68 | Quora : https://www.quora.com/profile/Piash-Sarker-1 69 | 70 | Twitter : https://twitter.com/PiashSarker 71 | 72 | Gmail : sarkerpt@gmail.com 73 | 74 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'io.fabric' 3 | 4 | 5 | repositories { 6 | maven { url 'https://maven.fabric.io/public' } 7 | } 8 | 9 | android { 10 | compileSdkVersion 26 11 | buildToolsVersion '26.0.2' 12 | defaultConfig { 13 | applicationId "com.nextinnovation.pt.barcodescanner" 14 | minSdkVersion 15 15 | targetSdkVersion 26 16 | versionCode 3 17 | versionName "2.1" 18 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 31 | exclude group: 'com.android.support', module: 'support-annotations' 32 | }) 33 | compile 'com.android.support:appcompat-v7:26.1.0' 34 | compile 'com.android.support:cardview-v7:26.1.0' 35 | compile 'com.android.support:recyclerview-v7:26.1.0' 36 | compile 'com.android.support:design:26.1.0' 37 | compile 'com.edwardvanraak:MaterialBarcodeScanner:0.0.6-ALPHA' 38 | compile 'com.google.firebase:firebase-core:11.6.0' 39 | compile 'com.google.firebase:firebase-ads:11.6.0' 40 | compile 'com.google.android.gms:play-services-base:11.6.0' 41 | compile 'com.google.android.gms:play-services-vision:11.6.0' 42 | testCompile 'junit:junit:4.12' 43 | compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') { 44 | transitive = true 45 | } 46 | 47 | } 48 | apply plugin: 'com.google.gms.google-services' -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "54135562732", 4 | "firebase_url": "https://publishedappsplay.firebaseio.com", 5 | "project_id": "publishedappsplay", 6 | "storage_bucket": "publishedappsplay.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:54135562732:android:dd94de8c2fb5d640", 12 | "android_client_info": { 13 | "package_name": "com.nextinnovation.pt.barcodescanner" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "54135562732-lgmk1l24ceq7qi4kicr7in3siee7537m.apps.googleusercontent.com", 19 | "client_type": 1, 20 | "android_info": { 21 | "package_name": "com.nextinnovation.pt.barcodescanner", 22 | "certificate_hash": "44fe06ab8398f0835871e42ec35418f40a4fbc9e" 23 | } 24 | }, 25 | { 26 | "client_id": "54135562732-cjohia0msut8qrisfuh0ta707bulfki2.apps.googleusercontent.com", 27 | "client_type": 3 28 | } 29 | ], 30 | "api_key": [ 31 | { 32 | "current_key": "AIzaSyCrkEgM5RYDCegLKzrR9N4nfnGoMELbdFw" 33 | } 34 | ], 35 | "services": { 36 | "analytics_service": { 37 | "status": 1 38 | }, 39 | "appinvite_service": { 40 | "status": 2, 41 | "other_platform_oauth_client": [ 42 | { 43 | "client_id": "54135562732-cjohia0msut8qrisfuh0ta707bulfki2.apps.googleusercontent.com", 44 | "client_type": 3 45 | } 46 | ] 47 | }, 48 | "ads_service": { 49 | "status": 2 50 | } 51 | } 52 | } 53 | ], 54 | "configuration_version": "1" 55 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\PT\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/release/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piashsarker/BarcodeAndQRReaderAndroid/1ec33217d55016c726d5a1a5f3a62963edfdcac1/app/release/app-release.apk -------------------------------------------------------------------------------- /app/release/fastest_barcode_and_qr_code_V_2.0.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piashsarker/BarcodeAndQRReaderAndroid/1ec33217d55016c726d5a1a5f3a62963edfdcac1/app/release/fastest_barcode_and_qr_code_V_2.0.apk -------------------------------------------------------------------------------- /app/release/fastest_barcode_and_qr_code_v_2.1.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piashsarker/BarcodeAndQRReaderAndroid/1ec33217d55016c726d5a1a5f3a62963edfdcac1/app/release/fastest_barcode_and_qr_code_v_2.1.apk -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3},"path":"app-release.apk","properties":{"packageId":"com.nextinnovation.pt.barcodescanner","split":"","minSdkVersion":"15"}}] -------------------------------------------------------------------------------- /app/src/androidTest/java/com/nextinnovation/pt/barcodereaderforplaystore/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodereaderforplaystore; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.pt.barcodereaderforplaystore", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 34 | 35 | 36 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.activity; 2 | 3 | import android.Manifest; 4 | import android.content.ActivityNotFoundException; 5 | import android.content.Context; 6 | import android.content.DialogInterface; 7 | import android.content.Intent; 8 | import android.content.pm.PackageManager; 9 | import android.net.Uri; 10 | import android.os.Bundle; 11 | import android.support.annotation.NonNull; 12 | import android.support.design.widget.Snackbar; 13 | import android.support.design.widget.TabLayout; 14 | import android.support.v4.app.ActivityCompat; 15 | import android.support.v4.app.Fragment; 16 | import android.support.v4.app.FragmentManager; 17 | import android.support.v4.app.FragmentPagerAdapter; 18 | import android.support.v4.content.ContextCompat; 19 | import android.support.v4.view.ViewPager; 20 | import android.support.v7.app.AlertDialog; 21 | import android.support.v7.app.AppCompatActivity; 22 | import android.support.v7.widget.Toolbar; 23 | import android.util.Log; 24 | import android.view.Menu; 25 | import android.view.MenuItem; 26 | import android.widget.Toast; 27 | 28 | import com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScanner; 29 | import com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScannerBuilder; 30 | import com.google.android.gms.vision.barcode.Barcode; 31 | import com.nextinnovation.pt.barcodescanner.R; 32 | import com.nextinnovation.pt.barcodescanner.database.DatabaseHelper; 33 | import com.nextinnovation.pt.barcodescanner.fragment.BarcodeFragment; 34 | import com.nextinnovation.pt.barcodescanner.fragment.LicenseFragment; 35 | import com.nextinnovation.pt.barcodescanner.fragment.ProductListFragment; 36 | import com.nextinnovation.pt.barcodescanner.model.Product; 37 | 38 | import java.text.DateFormat; 39 | import java.text.SimpleDateFormat; 40 | import java.util.ArrayList; 41 | import java.util.Date; 42 | import java.util.List; 43 | import java.util.Locale; 44 | 45 | public class MainActivity extends AppCompatActivity implements BarcodeFragment.ScanRequest { 46 | 47 | private Context context ; 48 | private Toolbar toolbar; 49 | private TabLayout tabLayout; 50 | private ViewPager viewPager; 51 | public static final String BARCODE_KEY = "BARCODE"; 52 | private Barcode barcodeResult; 53 | private final String TAG = MainActivity.class.getSimpleName() ; 54 | private final int MY_PERMISSION_REQUEST_CAMERA = 1001; 55 | private ItemScanned itemScanned ; 56 | 57 | 58 | 59 | 60 | 61 | @Override 62 | protected void onCreate(Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | setContentView(R.layout.activity_main); 65 | context = this; 66 | toolbar = findViewById(R.id.toolbar); 67 | setSupportActionBar(toolbar); 68 | viewPager = findViewById(R.id.viewpager); 69 | setupViewPager(viewPager); 70 | tabLayout = findViewById(R.id.tabs); 71 | tabLayout.setupWithViewPager(viewPager); 72 | 73 | } 74 | 75 | @Override 76 | protected void onResume() { 77 | super.onResume(); 78 | 79 | } 80 | 81 | 82 | private void setupViewPager(ViewPager viewPager) { 83 | ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 84 | adapter.addFragment(new BarcodeFragment(), "Barcode Scanner"); 85 | adapter.addFragment(new ProductListFragment(), "Scan Item"); 86 | viewPager.setAdapter(adapter); 87 | } 88 | 89 | public String getScanTime() { 90 | DateFormat timeFormat = new SimpleDateFormat("hh:mm a" , Locale.getDefault()); 91 | return timeFormat.format(new Date()); 92 | } 93 | 94 | public String getScanDate() { 95 | DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy",Locale.getDefault()); 96 | return dateFormat.format(new Date()); 97 | } 98 | 99 | @Override 100 | public void scanBarcode() { 101 | /** This method will listen the button clicked passed form the fragment **/ 102 | checkPermission(); 103 | } 104 | 105 | class ViewPagerAdapter extends FragmentPagerAdapter { 106 | private final List mFragmentList = new ArrayList<>(); 107 | private final List mFragmentTitleList = new ArrayList<>(); 108 | 109 | public ViewPagerAdapter(FragmentManager manager) { 110 | super(manager); 111 | } 112 | 113 | 114 | @Override 115 | public Fragment getItem(int position) { 116 | return mFragmentList.get(position); 117 | } 118 | 119 | 120 | @Override 121 | public int getCount() { 122 | return mFragmentList.size(); 123 | } 124 | 125 | public void addFragment(Fragment fragment, String title) { 126 | mFragmentList.add(fragment); 127 | mFragmentTitleList.add(title); 128 | } 129 | 130 | @Override 131 | public CharSequence getPageTitle(int position) { 132 | return mFragmentTitleList.get(position); 133 | } 134 | } 135 | @Override 136 | public boolean onCreateOptionsMenu(Menu menu) { 137 | getMenuInflater().inflate(R.menu.main_menu,menu); 138 | return true ; 139 | } 140 | 141 | @Override 142 | public boolean onOptionsItemSelected(MenuItem item) { 143 | 144 | int id = item.getItemId(); 145 | switch (id){ 146 | case R.id.item_share: 147 | openShare(); 148 | break; 149 | case R.id.item_rate_app: 150 | openRate(); 151 | break ; 152 | case R.id.item_submit_bug: 153 | openSubmitBug(); 154 | break ; 155 | case R.id.item_license: 156 | openLisence(); 157 | break; 158 | } 159 | 160 | return super.onOptionsItemSelected(item); 161 | } 162 | 163 | private void openSubmitBug() { 164 | String to = "sarkerpt@gmail.com"; 165 | String subject = "Barcode Reader For Android - Bug Report"; 166 | 167 | Intent email = new Intent(Intent.ACTION_SEND); 168 | email.putExtra(Intent.EXTRA_EMAIL, new String[]{to}); 169 | email.putExtra(Intent.EXTRA_SUBJECT, subject); 170 | email.setType("message/rfc822"); 171 | startActivity(Intent.createChooser(email, "Choose an Email client :")); 172 | } 173 | 174 | private void openRate() { 175 | Uri uri = Uri.parse("market://details?id=" + context.getPackageName()); 176 | Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); 177 | goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | 178 | Intent.FLAG_ACTIVITY_NEW_DOCUMENT | 179 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 180 | try { 181 | startActivity(goToMarket); 182 | } catch (ActivityNotFoundException e) { 183 | startActivity(new Intent(Intent.ACTION_VIEW, 184 | Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName()))); 185 | } 186 | } 187 | 188 | private void openShare() { 189 | Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 190 | String appLink = "https://play.google.com/store/apps/details?id="+context.getPackageName(); 191 | sharingIntent.setType("text/plain"); 192 | String shareBodyText = "Check Out The Cool Barcode Reader App \n Link: "+appLink +" \n" + 193 | " #Barcode #Android"; 194 | sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Barcode Reader Android App"); 195 | sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText); 196 | startActivity(Intent.createChooser(sharingIntent, "Share")); 197 | } 198 | 199 | private void openLisence() { 200 | LicenseFragment licensesFragment = new LicenseFragment(); 201 | licensesFragment.show(getSupportFragmentManager().beginTransaction(), "dialog_licenses"); 202 | } 203 | 204 | private void showDialog(final String scanContent, final String currentTime, final String currentDate) { 205 | AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 206 | 207 | builder.setMessage(scanContent) 208 | .setTitle(R.string.dialog_title); 209 | builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 210 | public void onClick(DialogInterface dialog, int id) { 211 | DatabaseHelper databaseHelper = new DatabaseHelper(context); 212 | databaseHelper.addProduct(new Product(scanContent,currentTime,currentDate)); 213 | Toast.makeText(MainActivity.this, "Saved", Toast.LENGTH_SHORT).show(); 214 | viewPager.setCurrentItem(1); 215 | 216 | 217 | } 218 | }); 219 | builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 220 | public void onClick(DialogInterface dialog, int id) { 221 | Toast.makeText(MainActivity.this, "Not Saved", Toast.LENGTH_SHORT).show(); 222 | } 223 | }); 224 | 225 | builder.show(); 226 | } 227 | 228 | @Override 229 | public void onBackPressed() { 230 | AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 231 | builder.setMessage("Are You Sure? ") 232 | .setTitle(R.string.exit_title); 233 | builder.setPositiveButton(R.string.ok_title, new DialogInterface.OnClickListener() { 234 | public void onClick(DialogInterface dialog, int id) { 235 | MainActivity.this.finish(); 236 | } 237 | }); 238 | builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 239 | public void onClick(DialogInterface dialog, int id) { 240 | dialog.dismiss(); 241 | } 242 | }); 243 | 244 | builder.show(); 245 | } 246 | 247 | private void checkPermission() { 248 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { 249 | Log.d(TAG , getResources().getString(R.string.camera_permission_granted)); 250 | startScanningBarcode(); 251 | } else { 252 | requestCameraPermission(); 253 | 254 | } 255 | } 256 | 257 | private void requestCameraPermission() { 258 | if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { 259 | 260 | ActivityCompat.requestPermissions(MainActivity.this, new String[] {Manifest.permission.CAMERA}, MY_PERMISSION_REQUEST_CAMERA); 261 | 262 | } else{ 263 | ActivityCompat.requestPermissions(MainActivity.this,new String[] {Manifest.permission.CAMERA}, MY_PERMISSION_REQUEST_CAMERA); 264 | } 265 | } 266 | 267 | private void startScanningBarcode() { 268 | /** 269 | * Build a new MaterialBarcodeScanner 270 | */ 271 | final MaterialBarcodeScanner materialBarcodeScanner = new MaterialBarcodeScannerBuilder() 272 | .withActivity(MainActivity.this) 273 | .withEnableAutoFocus(true) 274 | .withBleepEnabled(true) 275 | .withBackfacingCamera() 276 | .withCenterTracker() 277 | .withText("Scanning...") 278 | .withResultListener(new MaterialBarcodeScanner.OnResultListener() { 279 | @Override 280 | public void onResult(Barcode barcode) { 281 | barcodeResult = barcode; 282 | showDialog(barcode.rawValue , getScanTime(),getScanDate()); 283 | } 284 | }) 285 | .build(); 286 | materialBarcodeScanner.startScan(); 287 | } 288 | 289 | @Override 290 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 291 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 292 | if (requestCode==MY_PERMISSION_REQUEST_CAMERA && grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 293 | startScanningBarcode(); 294 | } else { 295 | Snackbar.make(findViewById(android.R.id.content), getResources().getString(R.string.sorry_for_not_permission), Snackbar.LENGTH_SHORT) 296 | .show(); 297 | } 298 | 299 | } 300 | 301 | 302 | public interface ItemScanned{ 303 | void itemUpdated(); 304 | } 305 | 306 | } 307 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/activity/SplashActivity.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.activity; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | 7 | import com.crashlytics.android.Crashlytics; 8 | import com.google.android.gms.ads.MobileAds; 9 | import com.nextinnovation.pt.barcodescanner.R; 10 | 11 | import io.fabric.sdk.android.Fabric; 12 | 13 | public class SplashActivity extends Activity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_splash); 19 | /** Initialize Fabrice **/ 20 | Fabric.with(SplashActivity.this , new Crashlytics()); 21 | /** Initialize Firebase Ads **/ 22 | MobileAds.initialize(this, getResources().getString(R.string.app_ad_id)); 23 | startMainActivity(); 24 | finish(); 25 | } 26 | 27 | private void startMainActivity() { 28 | Intent intent = new Intent(SplashActivity.this, MainActivity.class); 29 | startActivity(intent); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/activity/WebViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.webkit.WebView; 8 | import android.webkit.WebViewClient; 9 | import android.widget.Button; 10 | import android.widget.Toast; 11 | 12 | import com.google.android.gms.ads.AdRequest; 13 | import com.google.android.gms.ads.AdView; 14 | import com.nextinnovation.pt.barcodescanner.R; 15 | import com.nextinnovation.pt.barcodescanner.utils.Utils; 16 | 17 | public class WebViewActivity extends AppCompatActivity { 18 | Button btnRetry ; 19 | String barCode = "" ; 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_web_view); 24 | btnRetry = findViewById(R.id.btnRetry); 25 | loadAdd(); 26 | 27 | Intent intent = getIntent(); 28 | if(intent.getExtras()!=null){ 29 | barCode= intent.getStringExtra("product_id"); 30 | loadWebView(barCode); 31 | } 32 | 33 | btnRetry.setOnClickListener(new View.OnClickListener() { 34 | @Override 35 | public void onClick(View v) { 36 | loadWebView(barCode); 37 | } 38 | }); 39 | 40 | } 41 | 42 | private void loadAdd() { 43 | AdView mAdView = findViewById(R.id.adView); 44 | AdRequest adRequest = new AdRequest.Builder().build(); 45 | mAdView.loadAd(adRequest); 46 | 47 | } 48 | 49 | 50 | private void loadWebView(String barCode) { 51 | if(Utils.isNetworkAvailable(this)){ 52 | btnRetry.setVisibility(View.INVISIBLE); 53 | WebView myWebView = findViewById(R.id.google_webview); 54 | myWebView.setWebViewClient(new WebViewClient()); 55 | myWebView.getSettings().setJavaScriptEnabled(true); 56 | 57 | if(Utils.isValidURL(barCode)){ 58 | myWebView.loadUrl(barCode); 59 | }else{ 60 | myWebView.loadUrl("https://www.google.com/search?q="+barCode); 61 | } 62 | 63 | } 64 | else{ 65 | btnRetry.setVisibility(View.VISIBLE); 66 | Toast.makeText(this, "No Internet Connection", Toast.LENGTH_SHORT).show(); 67 | } 68 | 69 | 70 | 71 | } 72 | 73 | 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/adapter/ProductAdapter.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.adapter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | import android.widget.LinearLayout; 12 | import android.widget.RelativeLayout; 13 | import android.widget.TextView; 14 | 15 | import com.google.android.gms.ads.NativeExpressAdView; 16 | import com.nextinnovation.pt.barcodescanner.R; 17 | import com.nextinnovation.pt.barcodescanner.activity.WebViewActivity; 18 | import com.nextinnovation.pt.barcodescanner.model.Product; 19 | import com.nextinnovation.pt.barcodescanner.utils.ClipBoardManager; 20 | 21 | import java.util.ArrayList; 22 | 23 | /** 24 | * Created by PT on 2/9/2017. 25 | */ 26 | 27 | public class ProductAdapter extends RecyclerView.Adapter { 28 | private Context context; 29 | private ArrayList productArrayList; 30 | private static final int PRODUCT_ITEM_VIEW_TYPE = 0 ; 31 | private static final int AD_VIEW_TYPE = 1; 32 | public ProductAdapter(Context context, ArrayList productArrayList) { 33 | this.context = context; 34 | this.productArrayList = productArrayList; 35 | } 36 | 37 | 38 | @Override 39 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 40 | switch (viewType){ 41 | case PRODUCT_ITEM_VIEW_TYPE : 42 | default: 43 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_barcode,parent,false); 44 | return new ProductViewHolder(view); 45 | case AD_VIEW_TYPE: 46 | View nativeExpressLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_native_express_add, parent , false); 47 | return new NativeExpressAdViewHolder(nativeExpressLayoutView); 48 | } 49 | } 50 | 51 | @Override 52 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 53 | int viewType = getItemViewType(position); 54 | switch (viewType){ 55 | case PRODUCT_ITEM_VIEW_TYPE: 56 | default : 57 | ProductViewHolder productViewHolder = (ProductViewHolder)holder; 58 | setProductView(productViewHolder , position); 59 | break ; 60 | case AD_VIEW_TYPE: 61 | /** Now set the add view in the cardview of adViewHolder **/ 62 | NativeExpressAdViewHolder nativeExpressAdViewHolder = (NativeExpressAdViewHolder) holder; 63 | NativeExpressAdView adView = (NativeExpressAdView)productArrayList.get(position); 64 | ViewGroup adCardView = (ViewGroup)nativeExpressAdViewHolder.itemView; 65 | adCardView.removeAllViews(); 66 | if(adView.getParent()!=null){ 67 | ((ViewGroup)adView.getParent()).removeView(adView); 68 | } 69 | adCardView.addView(adView); 70 | break ; 71 | 72 | } 73 | } 74 | 75 | private void setProductView(ProductViewHolder holder, final int position) { 76 | final Product product = (Product)productArrayList.get(position); 77 | holder.txtScanResult.setText(product.getProductBarcodeNo()); 78 | holder.txtScanTime.setText(product.getScanDate()+" "+product.getScanTime()); 79 | holder.txtScanNo.setText(String.valueOf(position+1)); 80 | 81 | if(position%2==0){ 82 | holder.layoutRightButtons.setBackgroundColor(context.getResources().getColor(R.color.card_right_blue)); 83 | } 84 | if(position%3==0){ 85 | holder.layoutRightButtons.setBackgroundColor(context.getResources().getColor(R.color.card_right_purple)); 86 | } 87 | 88 | 89 | holder.layoutSearch.setOnClickListener(new View.OnClickListener() { 90 | @Override 91 | public void onClick(View v) { 92 | Intent intent = new Intent(context, WebViewActivity.class); 93 | intent.putExtra("product_id",product.getProductBarcodeNo()); 94 | context.startActivity(intent); 95 | } 96 | }); 97 | holder.layoutCopy.setOnClickListener(new View.OnClickListener() { 98 | @Override 99 | public void onClick(View v) { 100 | ClipBoardManager clipBoardManager = new ClipBoardManager(); 101 | clipBoardManager.copyToClipboard(context,product.getProductBarcodeNo()); 102 | Snackbar.make(v,"Copied To Clipboard",Snackbar.LENGTH_SHORT).show(); 103 | } 104 | }); 105 | holder.btnShare.setOnClickListener(new View.OnClickListener() { 106 | @Override 107 | public void onClick(View view) { 108 | openShareDialog(product.getProductBarcodeNo()); 109 | } 110 | }); 111 | } 112 | 113 | private void openShareDialog(String result) { 114 | Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 115 | String appLink = "https://play.google.com/store/apps/details?id="+context.getPackageName(); 116 | sharingIntent.setType("text/plain"); 117 | String shareBodyText = "Scan Result: "+ result+"."+ 118 | "\nCheck Out The Cool & Fastest Barcode Reader App \n " + 119 | "Link: "+appLink +" \n" + 120 | " #Barcode #Android"; 121 | sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Barcode Reader Android App"); 122 | sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText); 123 | context.startActivity(Intent.createChooser(sharingIntent, "Share")); 124 | } 125 | 126 | @Override 127 | public int getItemViewType(int position) { 128 | if((position%4 ==0) && productArrayList.get(position) instanceof NativeExpressAdView){ 129 | return AD_VIEW_TYPE ; 130 | } 131 | else{ 132 | return PRODUCT_ITEM_VIEW_TYPE; 133 | } 134 | 135 | } 136 | 137 | 138 | 139 | @Override 140 | public int getItemCount() { 141 | return productArrayList.size(); 142 | } 143 | 144 | public class ProductViewHolder extends RecyclerView.ViewHolder { 145 | private LinearLayout layoutRightButtons ; 146 | private RelativeLayout layoutCopy , layoutSearch ; 147 | private TextView txtScanResult , txtScanNo , txtScanTime ; 148 | private Button btnShare ; 149 | 150 | public ProductViewHolder(View itemView) { 151 | super(itemView); 152 | layoutRightButtons = itemView.findViewById(R.id.layout_right_buttons); 153 | layoutCopy = itemView.findViewById(R.id.layout_copy); 154 | layoutSearch = itemView.findViewById(R.id.layout_search); 155 | txtScanNo = itemView.findViewById(R.id.txt_scan_no); 156 | txtScanResult = itemView.findViewById(R.id.txt_scan_result); 157 | txtScanTime = itemView.findViewById(R.id.txt_date_time); 158 | btnShare = itemView.findViewById(R.id.btn_share); 159 | 160 | } 161 | } 162 | 163 | public class NativeExpressAdViewHolder extends RecyclerView.ViewHolder{ 164 | public NativeExpressAdViewHolder(View itemView) { 165 | super(itemView); 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/database/DatabaseHelper.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.database; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.database.sqlite.SQLiteOpenHelper; 8 | 9 | import com.nextinnovation.pt.barcodescanner.model.Product; 10 | 11 | import java.util.ArrayList; 12 | 13 | /** 14 | * Created by PT on 2/3/2017. 15 | */ 16 | 17 | public class DatabaseHelper extends SQLiteOpenHelper { 18 | private static final String LOG = "DatabaseHelper"; 19 | private static final int DATABASE_VERSION = 1; 20 | private static final String DATABASE_NAME = "EmployeDatabase"; 21 | private static final String TABLE_PRODUCT = "product"; 22 | 23 | 24 | private static final String CREATE_TABLE_INSTRUCTOR = "create table if not exists " 25 | + TABLE_PRODUCT 26 | + " (id integer primary key autoincrement," 27 | + " product_code varchar(30)," + " scan_time varchar(30), " + " scan_date varchar(30));"; 28 | 29 | public DatabaseHelper(Context context) { 30 | super(context, DATABASE_NAME, null, DATABASE_VERSION); 31 | // TODO Auto-generated constructor stub 32 | } 33 | 34 | @Override 35 | public void onCreate(SQLiteDatabase db) { 36 | // TODO Auto-generated method stub 37 | db.execSQL(CREATE_TABLE_INSTRUCTOR); 38 | 39 | 40 | } 41 | 42 | @Override 43 | public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) { 44 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_PRODUCT); 45 | 46 | 47 | onCreate(db); 48 | 49 | } 50 | 51 | public void addProduct(Product product) { 52 | SQLiteDatabase db = this.getReadableDatabase(); 53 | ContentValues values = new ContentValues(); 54 | values.put("product_code", product.getProductBarcodeNo()); 55 | values.put("scan_time", product.getScanTime()); 56 | values.put("scan_date", product.getScanDate()); 57 | db.insert(TABLE_PRODUCT, null, values); 58 | db.close(); 59 | 60 | } 61 | 62 | 63 | public ArrayList getAllProduct() { 64 | ArrayList productArrayList = new ArrayList(); 65 | // Select All Query 66 | String selectQuery = "SELECT * FROM " + TABLE_PRODUCT+" ORDER BY id DESC"; 67 | 68 | SQLiteDatabase db = this.getWritableDatabase(); 69 | Cursor cursor = db.rawQuery(selectQuery, null); 70 | 71 | // looping through all rows and adding to list 72 | if (cursor.moveToFirst()) { 73 | do { 74 | Product product = new Product(); 75 | product.setProductNo(cursor.getString(0)); 76 | product.setProductBarcodeNo(cursor.getString(1)); 77 | product.setScanTime(cursor.getString(2)); 78 | product.setScanDate(cursor.getString(3)); 79 | // Adding contact to list 80 | productArrayList.add(product); 81 | } while (cursor.moveToNext()); 82 | } 83 | 84 | // return contact list 85 | return productArrayList; 86 | } 87 | 88 | 89 | } 90 | // Getting contacts Count 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/fragment/BarcodeFragment.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.fragment; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | 12 | import com.google.android.gms.ads.AdRequest; 13 | import com.google.android.gms.ads.AdView; 14 | import com.nextinnovation.pt.barcodescanner.R; 15 | 16 | /** 17 | * Created by PT on 2/9/2017. 18 | */ 19 | 20 | public class BarcodeFragment extends Fragment implements View.OnClickListener { 21 | 22 | private static final String TAG= "BarcodeFragment"; 23 | private Button btnScan ; 24 | private ScanRequest scanRequest ; 25 | 26 | public BarcodeFragment(){ 27 | 28 | } 29 | 30 | @Override 31 | public void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | } 34 | 35 | @Nullable 36 | @Override 37 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 38 | 39 | return inflater.inflate(R.layout.fragment_barcode_scanner, container, false); 40 | 41 | 42 | } 43 | 44 | @Override 45 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 46 | super.onViewCreated(view, savedInstanceState); 47 | btnScan = view.findViewById(R.id.btnScan); 48 | btnScan.setOnClickListener(this); 49 | loadAdd(view); 50 | 51 | } 52 | 53 | private void loadAdd(View view) { 54 | AdView mAdView = view.findViewById(R.id.adView); 55 | AdRequest adRequest = new AdRequest.Builder().build(); 56 | mAdView.loadAd(adRequest); 57 | 58 | } 59 | @Override 60 | public void onAttach(Context context) { 61 | super.onAttach(context); 62 | try { 63 | scanRequest = (ScanRequest) context; 64 | } 65 | catch (ClassCastException e) { 66 | throw new ClassCastException(context.toString() 67 | + " must implement retryConnectionListener"); 68 | } 69 | 70 | } 71 | 72 | 73 | @Override 74 | public void onClick(View v) { 75 | switch (v.getId()){ 76 | case R.id.btnScan : 77 | // Pass the click event to activity to start the scanner . 78 | scanRequest.scanBarcode(); 79 | break ; 80 | } 81 | } 82 | 83 | 84 | public interface ScanRequest{ 85 | void scanBarcode(); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/fragment/LicenseFragment.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.fragment; 2 | 3 | import android.app.AlertDialog; 4 | import android.app.Dialog; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.v4.app.DialogFragment; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | 11 | import com.nextinnovation.pt.barcodescanner.R; 12 | 13 | 14 | public class LicenseFragment extends DialogFragment { 15 | 16 | @NonNull 17 | @Override 18 | public Dialog onCreateDialog(Bundle savedInstanceState) { 19 | LayoutInflater dialogInflater = getActivity().getLayoutInflater(); 20 | View openSourceLicensesView = dialogInflater.inflate(R.layout.fragment_license, null); 21 | 22 | AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()); 23 | dialogBuilder.setView(openSourceLicensesView) 24 | .setTitle((getString(R.string.dialog_title_licenses))) 25 | .setNeutralButton(android.R.string.ok, null); 26 | 27 | return dialogBuilder.create(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/fragment/ProductListFragment.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.fragment; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.widget.SwipeRefreshLayout; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.RelativeLayout; 14 | 15 | import com.google.android.gms.ads.AdRequest; 16 | import com.google.android.gms.ads.AdSize; 17 | import com.google.android.gms.ads.NativeExpressAdView; 18 | import com.nextinnovation.pt.barcodescanner.R; 19 | import com.nextinnovation.pt.barcodescanner.activity.MainActivity; 20 | import com.nextinnovation.pt.barcodescanner.adapter.ProductAdapter; 21 | import com.nextinnovation.pt.barcodescanner.database.DatabaseHelper; 22 | import com.nextinnovation.pt.barcodescanner.utils.Utils; 23 | 24 | import java.util.ArrayList; 25 | 26 | /** 27 | * Created by PT on 2/9/2017. 28 | */ 29 | 30 | public class ProductListFragment extends Fragment implements MainActivity.ItemScanned { 31 | 32 | private RecyclerView mRecyclerView; 33 | private ProductAdapter mAdapter; 34 | private SwipeRefreshLayout swipeRefresh; 35 | ArrayList productArrayList; 36 | private RelativeLayout mainLayout , emptyLayout ; 37 | DatabaseHelper db ; 38 | public ProductListFragment(){ 39 | 40 | } 41 | 42 | @Override 43 | public void onAttach(Context context) { 44 | super.onAttach(context); 45 | } 46 | 47 | @Nullable 48 | @Override 49 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 50 | View view = inflater.inflate(R.layout.fragment_prduct_list,container,false); 51 | mRecyclerView = view.findViewById(R.id.product_list_recycler_view); 52 | swipeRefresh = view.findViewById(R.id.swipe_refresh_layout); 53 | mainLayout = view.findViewById(R.id.main_layout); 54 | emptyLayout = view.findViewById(R.id.empty_layout); 55 | swipeRefresh.setColorSchemeColors(getResources().getColor(R.color.green),getResources().getColor(R.color.blue),getResources().getColor(R.color.orange)); 56 | swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 57 | @Override 58 | public void onRefresh() { 59 | loadProductList(); 60 | } 61 | }); 62 | 63 | 64 | loadProductList(); 65 | return view; 66 | } 67 | 68 | private void loadProductList() { 69 | db= new DatabaseHelper(getContext()); 70 | productArrayList = db.getAllProduct(); 71 | if(Utils.isNetworkAvailable(getContext())){ 72 | addNativeExpressAd(); 73 | } 74 | 75 | if(!productArrayList.isEmpty()){ 76 | mAdapter = new ProductAdapter(getContext(), productArrayList); 77 | mRecyclerView.setHasFixedSize(true); 78 | RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext()); 79 | mRecyclerView.setLayoutManager(mLayoutManager); 80 | mRecyclerView.setAdapter(mAdapter); 81 | swipeRefresh.setRefreshing(false); 82 | emptyLayout.setVisibility(View.GONE); 83 | } 84 | else{ 85 | emptyLayout.setVisibility(View.VISIBLE); 86 | swipeRefresh.setRefreshing(false); 87 | } 88 | 89 | } 90 | 91 | private void addNativeExpressAd() { 92 | /** Setting adViewItem dynamically into the **/ 93 | for(int i=0 ; i 0) { 120 | builder.append(buffer, 0, len); 121 | } 122 | return builder.toString(); 123 | 124 | } catch (FileNotFoundException e) { 125 | // Unable to open content URI as text... not really an 126 | // error, just something to ignore. 127 | 128 | } catch (IOException e) { 129 | // Something bad has happened. 130 | Log.w("ClippedData", "Failure loading text", e); 131 | return e.toString(); 132 | 133 | } finally { 134 | if (stream != null) { 135 | try { 136 | stream.close(); 137 | } catch (IOException e) { 138 | } 139 | } 140 | } 141 | 142 | // If we couldn't open the URI as a stream, then the URI itself 143 | // probably serves fairly well as a textual representation. 144 | return uri.toString(); 145 | } 146 | 147 | // Finally, if all we have is an Intent, then we can just turn that 148 | // into text. Not the most user-friendly thing, but it's something. 149 | Intent intent = item.getIntent(); 150 | if (intent != null) { 151 | return intent.toUri(Intent.URI_INTENT_SCHEME); 152 | } 153 | 154 | // Shouldn't get here, but just in case... 155 | return ""; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /app/src/main/java/com/nextinnovation/pt/barcodescanner/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.nextinnovation.pt.barcodescanner.utils; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | import java.net.URI; 8 | 9 | /** 10 | * Created by piashsarker on 11/29/17. 11 | */ 12 | 13 | public class Utils { 14 | public static boolean isNetworkAvailable(Context context) { 15 | 16 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 17 | NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); 18 | return activeNetworkInfo != null && activeNetworkInfo.isConnected(); 19 | } 20 | 21 | public static boolean isValidURL(String urlStr) { 22 | try { 23 | URI uri = new URI(urlStr); 24 | return uri.getScheme().equals("http") || uri.getScheme().equals("https"); 25 | } catch (Exception e) { 26 | return false; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/barcode_icon_2_png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piashsarker/BarcodeAndQRReaderAndroid/1ec33217d55016c726d5a1a5f3a62963edfdcac1/app/src/main/res/drawable/barcode_icon_2_png.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 9 | 10 | 11 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_focus.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_unfocus.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_access_time_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_barcode.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_content_copy_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_share_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_warning_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/splash_drawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/style_toggle_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 19 | 20 | 26 | 27 | 28 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_web_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 |