├── .gitignore ├── .idea ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── id │ │ └── agusibrahim │ │ └── qrwebtest │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── id │ │ │ └── agusibrahim │ │ │ └── qrwebtest │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── id │ └── agusibrahim │ └── qrwebtest │ └── ExampleUnitTest.java ├── build.gradle ├── 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 | 11 | # Built application files 12 | *.apk 13 | *.ap_ 14 | 15 | # Files for the ART/Dalvik VM 16 | *.dex 17 | 18 | # Java class files 19 | *.class 20 | 21 | # Generated files 22 | bin/ 23 | gen/ 24 | out/ 25 | 26 | # Gradle files 27 | .gradle/ 28 | build/ 29 | 30 | # Local configuration file (sdk path, etc) 31 | local.properties 32 | 33 | # Proguard folder generated by Eclipse 34 | proguard/ 35 | 36 | # Log Files 37 | *.log 38 | 39 | # Android Studio Navigation editor temp files 40 | .navigation/ 41 | 42 | # Android Studio captures folder 43 | captures/ 44 | 45 | # IntelliJ 46 | *.iml 47 | .idea/workspace.xml 48 | .idea/tasks.xml 49 | .idea/gradle.xml 50 | .idea/dictionaries 51 | .idea/libraries 52 | 53 | # Keystore files 54 | # Uncomment the following line if you do not want to check your keystore files in. 55 | #*.jks 56 | 57 | # External native build folder generated in Android Studio 2.2 and later 58 | .externalNativeBuild 59 | 60 | # Google Services (e.g. APIs or Firebase) 61 | google-services.json 62 | 63 | # Freeline 64 | freeline.py 65 | freeline/ 66 | freeline_project_description.json 67 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 1.8 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /.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 | # Membuat QR Code Scanner ala WhatsApp Web 2 | > please refer to https://medium.com/@agusibrahim/membuat-qr-code-scanner-ala-whatsapp-web-13b4705a921b 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "id.agusibrahim.qrwebtest" 7 | minSdkVersion 16 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:design:26.1.0' 24 | implementation 'com.google.firebase:firebase-database:11.6.2' 25 | compile 'com.google.firebase:firebase-auth:11.6.2' 26 | compile 'com.google.android.gms:play-services-auth:11.6.2' 27 | compile 'com.journeyapps:zxing-android-embedded:3.5.0' 28 | compile 'com.karumi:dexter:4.2.0' 29 | } 30 | 31 | 32 | apply plugin: 'com.google.gms.google-services' -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/id/agusibrahim/qrwebtest/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package id.agusibrahim.qrwebtest; 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 | * Instrumented 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("id.agusibrahim.qrwebtest", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/id/agusibrahim/qrwebtest/MainActivity.java: -------------------------------------------------------------------------------- 1 | package id.agusibrahim.qrwebtest; 2 | 3 | import android.*; 4 | import android.Manifest; 5 | import android.content.Intent; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.os.Bundle; 9 | import android.util.Log; 10 | import android.view.View; 11 | import android.widget.Button; 12 | import android.widget.Toast; 13 | 14 | import com.google.android.gms.auth.api.Auth; 15 | import com.google.android.gms.auth.api.signin.GoogleSignIn; 16 | import com.google.android.gms.auth.api.signin.GoogleSignInAccount; 17 | import com.google.android.gms.auth.api.signin.GoogleSignInClient; 18 | import com.google.android.gms.auth.api.signin.GoogleSignInOptions; 19 | import com.google.android.gms.auth.api.signin.GoogleSignInResult; 20 | import com.google.android.gms.tasks.OnCompleteListener; 21 | import com.google.android.gms.tasks.Task; 22 | import com.google.firebase.auth.AuthCredential; 23 | import com.google.firebase.auth.AuthResult; 24 | import com.google.firebase.auth.FirebaseAuth; 25 | import com.google.firebase.auth.FirebaseUser; 26 | import com.google.firebase.auth.GoogleAuthProvider; 27 | import com.google.firebase.database.DatabaseReference; 28 | import com.google.firebase.database.FirebaseDatabase; 29 | import com.google.zxing.ResultPoint; 30 | import com.journeyapps.barcodescanner.BarcodeCallback; 31 | import com.journeyapps.barcodescanner.BarcodeResult; 32 | import com.journeyapps.barcodescanner.DecoratedBarcodeView; 33 | import com.karumi.dexter.Dexter; 34 | import com.karumi.dexter.MultiplePermissionsReport; 35 | import com.karumi.dexter.PermissionToken; 36 | import com.karumi.dexter.listener.PermissionRequest; 37 | import com.karumi.dexter.listener.multi.MultiplePermissionsListener; 38 | 39 | import java.util.HashMap; 40 | import java.util.List; 41 | import java.util.Map; 42 | 43 | public class MainActivity extends AppCompatActivity { 44 | private static final int RC_SIGN_IN = 1111; 45 | private static final String TAG = "errs"; 46 | private static final int REQ_CODE = 1222; 47 | private FirebaseAuth mAuth; 48 | private GoogleSignInOptions gso; 49 | private GoogleSignInClient mGoogleSignInClient; 50 | private Button btn_login; 51 | private DatabaseReference mDatabase; 52 | private DecoratedBarcodeView qr_view; 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | setContentView(R.layout.activity_main); 58 | btn_login=findViewById(R.id.btn_login); 59 | qr_view=findViewById(R.id.qr_view); 60 | 61 | gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 62 | .requestIdToken(getString(R.string.default_web_client_id)) 63 | .requestEmail() 64 | .requestProfile() 65 | .build(); 66 | mAuth=FirebaseAuth.getInstance(); 67 | mDatabase= FirebaseDatabase.getInstance().getReference(); 68 | mGoogleSignInClient = GoogleSignIn.getClient(this, gso); 69 | qr_view.decodeContinuous(new BarcodeCallback() { 70 | @Override 71 | public void barcodeResult(BarcodeResult result) { 72 | String res=result.getText(); 73 | qr_view.setVisibility(View.INVISIBLE); 74 | qr_view.pause(); 75 | Map data=new HashMap<>(); 76 | data.put("name", mAuth.getCurrentUser().getDisplayName()); 77 | data.put("pic", mAuth.getCurrentUser().getPhotoUrl().toString()); 78 | data.put("email", mAuth.getCurrentUser().getEmail()); 79 | data.put("id", mAuth.getCurrentUser().getUid()); 80 | mDatabase.child("/qrcode/"+result).setValue(data); 81 | Toast.makeText(MainActivity.this, "Got it!", Toast.LENGTH_SHORT).show(); 82 | } 83 | 84 | @Override 85 | public void possibleResultPoints(List resultPoints) { 86 | 87 | } 88 | }); 89 | btn_login.setOnClickListener(new View.OnClickListener() { 90 | @Override 91 | public void onClick(View view) { 92 | if(mAuth.getCurrentUser()== null) signIn(); 93 | else{ 94 | Dexter.withActivity(MainActivity.this) 95 | .withPermissions( 96 | android.Manifest.permission.CAMERA, 97 | Manifest.permission.WRITE_EXTERNAL_STORAGE 98 | ).withListener(new MultiplePermissionsListener() { 99 | @Override public void onPermissionsChecked(MultiplePermissionsReport report) { 100 | if(!report.areAllPermissionsGranted()){ 101 | Toast.makeText(MainActivity.this, "Permission are denied.", Toast.LENGTH_LONG).show(); 102 | }else{ 103 | qr_view.setVisibility(View.VISIBLE); 104 | qr_view.resume(); 105 | } 106 | } 107 | @Override public void onPermissionRationaleShouldBeShown(List permissions, PermissionToken token) { 108 | Toast.makeText(MainActivity.this, "Permission denied, please goto App settings and grant the permissions.", Toast.LENGTH_LONG).show(); 109 | } 110 | }).check(); 111 | } 112 | } 113 | }); 114 | if(mAuth.getCurrentUser()!=null){ 115 | btn_login.setText("Scan QR Code"); 116 | } 117 | } 118 | private void signIn() { 119 | Intent signInIntent = mGoogleSignInClient.getSignInIntent(); 120 | startActivityForResult(signInIntent, RC_SIGN_IN); 121 | } 122 | 123 | @Override 124 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 125 | super.onActivityResult(requestCode, resultCode, data); 126 | 127 | // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); 128 | if (requestCode == RC_SIGN_IN) { 129 | GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 130 | if (result.isSuccess()) { 131 | // Google Sign In was successful, authenticate with Firebase 132 | GoogleSignInAccount account = result.getSignInAccount(); 133 | firebaseAuthWithGoogle(account); 134 | } else { 135 | // Google Sign In failed, update UI appropriately 136 | // ... 137 | } 138 | } 139 | } 140 | private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { 141 | Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); 142 | 143 | AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); 144 | mAuth.signInWithCredential(credential) 145 | .addOnCompleteListener(this, new OnCompleteListener() { 146 | @Override 147 | public void onComplete(@NonNull Task task) { 148 | if (task.isSuccessful()) { 149 | // Sign in success, update UI with the signed-in user's information 150 | Log.d(TAG, "signInWithCredential:success"); 151 | FirebaseUser user = mAuth.getCurrentUser(); 152 | updateUI(user); 153 | } else { 154 | // If sign in fails, display a message to the user. 155 | Log.w(TAG, "signInWithCredential:failure", task.getException()); 156 | Toast.makeText(MainActivity.this, "Authentication failed.", 157 | Toast.LENGTH_SHORT).show(); 158 | updateUI(null); 159 | } 160 | 161 | // ... 162 | } 163 | }); 164 | } 165 | 166 | private void updateUI(FirebaseUser user) { 167 | if(user!=null){ 168 | Toast.makeText(MainActivity.this, "Welcome "+user.getDisplayName(), Toast.LENGTH_LONG).show(); 169 | } 170 | if(mAuth.getCurrentUser()!=null){ 171 | btn_login.setText("Scan QR Code"); 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 14 |