Skip to content

Commit

Permalink
0.2.0 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaytumal committed Aug 21, 2024
1 parent 0bc117b commit e95f7c1
Show file tree
Hide file tree
Showing 23 changed files with 606 additions and 143 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId = "web.bmdominatezz.gravy"
minSdk = 26
targetSdk = 34
versionCode = 12 //011
versionName = "0.1.2-beta.1"
versionCode = 20 //011
versionName = "0.2.0-beta.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|uiMode|screenSize"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
227 changes: 225 additions & 2 deletions android/app/src/main/java/web/bmdominatezz/gravy/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,86 @@
package web.bmdominatezz.gravy;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.icu.text.SimpleDateFormat;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.util.Log;
import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.io.File;
import java.io.IOException;
import java.util.Date;

public class MainActivity extends AppCompatActivity {
public WebEvents webEvents;
public GrooveWebView webView;
public PackageManager packageManager;
private static final int INPUT_FILE_REQUEST_CODE = 66;
private static final int FILECHOOSER_RESULTCODE = 66;
private Handler handler;
private Runnable pauseRunnable;
private ValueCallback<Uri> mUploadMessage;
private Uri mCapturedImageURI = null;
private ValueCallback<Uri[]> mFilePathCallback;
private String mCameraPhotoPath;
private final static String TAG = "groovelauncher";
Boolean activityPaused = false;
Boolean activityDispatchEvent = true;

@Override
protected void onPause() {
webEvents.dispatchEvent(WebEvents.events.activityPause, null);
pauseRunnable = new Runnable() {
@Override
public void run() {
activityPaused = true;
if (activityDispatchEvent)
webEvents.dispatchEvent(WebEvents.events.activityPause, null);
Log.d("groovelauncher", "onPause: ");
}
};
handler.postDelayed(pauseRunnable, 10); // Delay of 10ms
super.onPause();
}

@Override
protected void onResume() {
webEvents.dispatchEvent(WebEvents.events.activityResume, null);
if (pauseRunnable != null) {
handler.removeCallbacks(pauseRunnable);
if (activityPaused) {
if (activityDispatchEvent)
webEvents.dispatchEvent(WebEvents.events.activityResume, null);
activityPaused = false;
}
webEvents.dispatchEvent(WebEvents.events.homeButtonPress, null);
Log.d("groovelauncher", "homeButtonPress: ");
} else {
if (activityDispatchEvent)
webEvents.dispatchEvent(WebEvents.events.activityResume, null);
activityPaused = false;
Log.d("groovelauncher", "onResume: ");
}
super.onResume();
}

Expand All @@ -41,7 +98,10 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
webView = (GrooveWebView) findViewById(R.id.webview);
packageManager = getPackageManager();
handler = new Handler();
webView.init(packageManager, this);
webView.setWebChromeClient(new ChromeClient());

webEvents = webView.webEvents;
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
Expand All @@ -52,4 +112,167 @@ protected void onCreate(Bundle savedInstanceState) {
return insets;
});
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
Uri[] results = null;
// Check that the response is a good one
if (resultCode == Activity.RESULT_OK) {
if (data == null) {
// If there is not data, then we may have taken a photo
if (mCameraPhotoPath != null) {
results = new Uri[]{Uri.parse(mCameraPhotoPath)};
}
} else {
String dataString = data.getDataString();
if (dataString != null) {
results = new Uri[]{Uri.parse(dataString)};
}
}
}
mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
if (requestCode != FILECHOOSER_RESULTCODE || mUploadMessage == null) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
if (requestCode == FILECHOOSER_RESULTCODE) {
if (null == this.mUploadMessage) {
return;
}
Uri result = null;
try {
if (resultCode != RESULT_OK) {
result = null;
} else {
// retrieve from the private variable if the intent is null
result = data == null ? mCapturedImageURI : data.getData();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "activity :" + e,
Toast.LENGTH_LONG).show();
}
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
}
return;
}

private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
return imageFile;
}

public class ChromeClient extends WebChromeClient {
// For Android 5.0
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
// Double check that we don't have any existing callbacks
if (mFilePathCallback != null) {
mFilePathCallback.onReceiveValue(null);
}
mFilePathCallback = filePath;
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
// Error occurred while creating the File
Log.e(TAG, "Unable to create Image File", ex);
}
// Continue only if the File was successfully created
if (photoFile != null) {
mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
} else {
takePictureIntent = null;
}
}
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType("image/*");
Intent[] intentArray;
if (takePictureIntent != null) {
intentArray = new Intent[]{takePictureIntent};
} else {
intentArray = new Intent[0];
}
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
activityDispatchEvent = false;
startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
activityDispatchEvent = true;
return true;
}

// openFileChooser for Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
mUploadMessage = uploadMsg;
// Create AndroidExampleFolder at sdcard
// Create AndroidExampleFolder at sdcard
File imageStorageDir = new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)
, "AndroidExampleFolder");
if (!imageStorageDir.exists()) {
// Create AndroidExampleFolder at sdcard
imageStorageDir.mkdirs();
}
// Create camera captured image file path and name
File file = new File(
imageStorageDir + File.separator + "IMG_"
+ String.valueOf(System.currentTimeMillis())
+ ".jpg");
mCapturedImageURI = Uri.fromFile(file);
// Camera capture image intent
final Intent captureIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
// Create file chooser intent
Intent chooserIntent = Intent.createChooser(i, "Image Chooser");
// Set camera intent to file chooser
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
, new Parcelable[]{captureIntent});
// On select image call onActivityResult method of activity
activityDispatchEvent = false;
startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
activityDispatchEvent = true;
}

// openFileChooser for Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
openFileChooser(uploadMsg, "");
}

//openFileChooser for other Android versions
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType,
String capture) {
openFileChooser(uploadMsg, acceptType);
}
}
}
21 changes: 21 additions & 0 deletions android/app/src/main/java/web/bmdominatezz/gravy/WebInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,25 @@ public String getAppVersion() {
}
}

@JavascriptInterface
public String getWebViewVersion() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // API Level 26
PackageInfo webViewPackageInfo = mainActivity.webView.getCurrentWebViewPackage();
if (webViewPackageInfo != null) {
String versionName = webViewPackageInfo.versionName;
int versionCode = webViewPackageInfo.versionCode;
// Use versionName and versionCode as needed
System.out.println("WebView version: " + versionName + " (code: " + versionCode + ")");
return versionName + " (code: " + versionCode + ")";
} else {
System.out.println("WebView package info is not available");
return "Unknown";
}
} else {
// Fallback for older Android versions
System.out.println("API level is lower than 26. WebView version not directly accessible.");
return "Unknown";
}
}

}
14 changes: 12 additions & 2 deletions src/apps/groove.internal.settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h1 class="app-title">Accent Color</h1>
</p>
<div class="group">
<p class="group-title">Background</p>
<div class="metro-dropdown-menu" selected="1">
<div class="metro-dropdown-menu" id="theme-chooser" selected="1">
<div class="metro-dropdown-option">Light</div>
<div class="metro-dropdown-option">Dark</div>
</div>
Expand All @@ -80,6 +80,15 @@ <h1 class="app-title">Accent Color</h1>
<div class="picker-option">color</div>
</div>
</div>
<div class="group" id="wallpaper-group">
<div id="wallpaper-thumbnail"></div>
<p class="group-title">Home background</p>
<button class="metro-button" id="choose-wallpaper">
choose photo
<input hidden type="file" accept="image/*" />
</button>
<button class="metro-button link" id="remove-wallpaper">remove</button>
</div>
<p class="text" style="margin-top: 40px;">
You can change the size and number of tiles available on your home screen.
</p>
Expand Down Expand Up @@ -136,7 +145,7 @@ <h1 class="app-title">Accent Color</h1>
<div class="metro-dropdown-option">125%</div>
</div>
</div>
<div class="group">
<div class="group" style="display:none;">
<p class="group-title">Font</p>
<div id="font-chooser" class="metro-dropdown-menu" selected="0">
<div class="metro-dropdown-option">Open Sans</div>
Expand All @@ -153,6 +162,7 @@ <h1 class="app-title">Accent Color</h1>
<div class="scrollable article-f" style="perspective: var(--flow-perspective);">
<h1 id="about-app-name">Groove Launcher</h1>
<h2 id="about-app-version">Version: Loading...</h2>
<h2 id="about-webview-version">WebView Version: Loading...</h2>
<p>
<strong>Groove Launcher</strong> is a metro-styled launcher
designed for a customizable and sleek user experience. Users can
Expand Down
Loading

0 comments on commit e95f7c1

Please sign in to comment.