Skip to content

Commit

Permalink
1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
elegidocodes committed Jan 9, 2025
1 parent 94556c7 commit f0edfad
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 14 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies {
implementation(libs.activity)
implementation(libs.constraintlayout)
implementation(libs.swiperefreshlayout)
implementation("com.github.elegidocodes:util:1.0.0")

testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/java/com/elegidocodes/android/util/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
package com.elegidocodes.android.util;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.elegidocodes.android.util.theme.ThemeUtil;


public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView textView = findViewById(R.id.textView);

if (ThemeUtil.isDarkModeEnabled(this)) {
textView.setText("Dark Mode is Enabled");
} else {
textView.setText("Dark Mode is Disabled");
}

}

}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ material = "1.12.0"
activity = "1.9.3"
constraintlayout = "2.2.0"
swiperefreshlayout = "1.1.0"
zxingAndroidEmbedded = "4.3.0"

[libraries]
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
Expand All @@ -20,6 +21,7 @@ material = { group = "com.google.android.material", name = "material", version.r
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "swiperefreshlayout" }
zxing-android-embedded = { module = "com.journeyapps:zxing-android-embedded", version.ref = "zxingAndroidEmbedded" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
4 changes: 3 additions & 1 deletion util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ publishing {
register<MavenPublication>("release") {
groupId = "com.github.elegidocodes"
artifactId = "util"
version = "1.0.7"
version = "1.0.8"

// Include AAR file in the publication
afterEvaluate {
Expand All @@ -68,6 +68,8 @@ dependencies {
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.swiperefreshlayout)
implementation(libs.zxing.android.embedded)


implementation(libs.gson)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.elegidocodes.android.util.network;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class UrlUtil {

/**
* Determines if the given string is a valid URL starting with "http://" or "https://".
*
* <p>This method checks if the input string is non-null and starts with a valid HTTP or HTTPS prefix.</p>
*
* <p>Example usage:
* <pre>{@code
* String data = "https://www.example.com";
* boolean isValidUrl = UrlUtils.isUrl(data); // Returns true
* }</pre>
* </p>
*
* @param data The string to be checked.
* @return {@code true} if the string is a valid URL, {@code false} otherwise.
*/
public static boolean isUrl(String data) {
return data != null && (data.startsWith("http://") || data.startsWith("https://"));
}

/**
* Opens the specified URL in the default browser or associated app on the user's device.
*
* <p>This method constructs an intent with the given URL and starts an activity to handle the URL.
* Ensure that the URL is valid before calling this method.</p>
*
* <p>Example usage:
* <pre>{@code
* String url = "https://www.example.com";
* UrlUtils.openUrl(context, url); // Opens the URL
* }</pre>
* </p>
*
* @param context The context used to start the activity.
* @param url The URL to be opened.
* @throws IllegalArgumentException if the provided URL is null or empty.
*/
public static void openUrl(Context context, String url) {
if (url == null || url.isEmpty()) {
throw new IllegalArgumentException("URL cannot be null or empty");
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
context.startActivity(intent);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.elegidocodes.android.util.zxing;

import android.graphics.Bitmap;
import android.graphics.Color;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;

import java.io.ByteArrayOutputStream;

public class QRCodeUtil {

/**
* Generates a QR Code from the provided URL as a Bitmap.
*
* <p>This method uses the {@link MultiFormatWriter} to encode the given URL into a QR code
* and creates a Bitmap representation of it.</p>
*
* @param url The URL to encode in the QR code.
* @return A {@link Bitmap} containing the QR code.
* @throws WriterException If the QR code encoding fails.
*/
public static Bitmap generateQRCodeBitmap(String url) throws WriterException {
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
BitMatrix bitMatrix = multiFormatWriter.encode(url, BarcodeFormat.QR_CODE, 200, 200);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
bitmap.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
}
}

return bitmap;
}

/**
* Generates a QR Code from the provided URL as a byte array in PNG format.
*
* <p>This method uses the {@link MultiFormatWriter} to encode the given URL into a QR code,
* converts it to a Bitmap, and then compresses it into a PNG byte array.</p>
*
* @param url The URL to encode in the QR code.
* @return A byte array containing the QR code image in PNG format.
* @throws WriterException If the QR code encoding fails.
*/
public static byte[] generateQRCodeBytes(String url) throws WriterException {
Bitmap bitmap = generateQRCodeBitmap(url);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}

}

0 comments on commit f0edfad

Please sign in to comment.