Initial commit
This commit is contained in:
parent
c1bc64478c
commit
6ecb9aeddd
|
|
@ -1 +1 @@
|
|||
Plant Databse
|
||||
Plant Database
|
||||
|
|
@ -1,17 +1,25 @@
|
|||
package com.sultan.plantdatabse;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
public class WebViewActivity extends AppCompatActivity {
|
||||
public class WebViewActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
Button scanAgainButton;
|
||||
Button btnHome;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Override
|
||||
|
|
@ -19,6 +27,9 @@ public class WebViewActivity extends AppCompatActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_webview);
|
||||
|
||||
scanAgainButton = findViewById(R.id.scanAgain);
|
||||
btnHome = findViewById(R.id.btnHome);
|
||||
|
||||
// Retrieve the URL from the intent
|
||||
String url = getIntent().getStringExtra("url");
|
||||
|
||||
|
|
@ -29,19 +40,22 @@ public class WebViewActivity extends AppCompatActivity {
|
|||
assert url != null;
|
||||
webView.loadUrl(url);
|
||||
|
||||
// Set an OnClickListener for the "Scan QR" button
|
||||
Button scanAgainButton = findViewById(R.id.scanAgain);
|
||||
scanAgainButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// Handle button click, for example, initiate a new scan
|
||||
initiateScan();
|
||||
// Set click listeners
|
||||
scanAgainButton.setOnClickListener(this);
|
||||
btnHome.setOnClickListener(this);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.scanAgain) {
|
||||
initiateScan();
|
||||
} else if (v.getId() == R.id.btnHome) {
|
||||
navigateToMainActivity();
|
||||
}
|
||||
// Add conditions for other buttons if needed
|
||||
}
|
||||
|
||||
private void initiateScan() {
|
||||
// Initialize the IntentIntegrator and start the scan
|
||||
IntentIntegrator intentIntegrator = new IntentIntegrator(this);
|
||||
intentIntegrator.setPrompt(getString(R.string.scan_qr));
|
||||
intentIntegrator.setOrientationLocked(true);
|
||||
|
|
@ -49,4 +63,68 @@ public class WebViewActivity extends AppCompatActivity {
|
|||
intentIntegrator.initiateScan();
|
||||
}
|
||||
|
||||
private void navigateToMainActivity() {
|
||||
Intent mainActivityIntent = new Intent(this, MainActivity.class);
|
||||
startActivity(mainActivityIntent);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
|
||||
// Get the Vibrator service
|
||||
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
|
||||
|
||||
// if the intentResult is null, toast a message as "cancelled"
|
||||
if (intentResult != null) {
|
||||
if (intentResult.getContents() == null) {
|
||||
Toast.makeText(getBaseContext(), "Cancelled", Toast.LENGTH_SHORT).show();
|
||||
if (vibrator != null) {
|
||||
vibrator.vibrate(100);
|
||||
}
|
||||
} else {
|
||||
// if the intentResult is not null, extract the dynamic part from the URL
|
||||
String scannedContent = intentResult.getContents();
|
||||
|
||||
// Extract the dynamic part after "&" and display it in messageText
|
||||
String dynamicPart = extractDynamicPart(scannedContent);
|
||||
|
||||
// Construct the full URL by appending the dynamic part to the base URL
|
||||
String fullUrl = "https://bhalumni.in/view/plant-database/entry/" + dynamicPart;
|
||||
|
||||
// Open the WebView activity with the constructed URL
|
||||
openWebViewActivity(fullUrl);
|
||||
|
||||
// Vibrate for 200 milliseconds on successful read
|
||||
if (vibrator != null) {
|
||||
vibrator.vibrate(200);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom method to extract the dynamic part after "&" in the URL
|
||||
private String extractDynamicPart(String url) {
|
||||
int index = url.lastIndexOf("&");
|
||||
if (index != -1 && index < url.length() - 1) {
|
||||
return url.substring(index + 1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Custom method to open WebView activity with the specified URL
|
||||
private void openWebViewActivity(String url) {
|
||||
Intent webViewIntent = new Intent(this, WebViewActivity.class);
|
||||
webViewIntent.putExtra("url", url);
|
||||
startActivity(webViewIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
super.onPointerCaptureChanged(hasCapture);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#C5C5C5" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M11.67,3.87L9.9,2.1 0,12l9.9,9.9 1.77,-1.77L3.54,12z"/>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="#C5C5C5"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
|
||||
</vector>
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/app_background_14"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
|
|
@ -27,10 +28,11 @@
|
|||
|
||||
<com.airbnb.lottie.LottieAnimationView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="531dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:lottie_autoPlay="true"
|
||||
android:layout_marginTop="90dp"
|
||||
app:lottie_loop="true"
|
||||
app:lottie_rawRes="@raw/qr_scan_big_1" />
|
||||
app:lottie_rawRes="@raw/qr_scan_big_2" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/scanBtn"
|
||||
|
|
|
|||
|
|
@ -18,5 +18,24 @@
|
|||
android:layout_centerHorizontal="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:text="Scan QR"/>
|
||||
<Button
|
||||
android:id="@+id/btnBack"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:background="@drawable/ic_back_24"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_margin="4dp"
|
||||
android:backgroundTint="@color/black"
|
||||
android:visibility="gone"/>
|
||||
<Button
|
||||
android:id="@+id/btnHome"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:background="@drawable/ic_home_24"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_margin="4dp"
|
||||
android:backgroundTint="@color/black"/>
|
||||
|
||||
</RelativeLayout>
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue