Skip to content

Commit

Permalink
Recreate Base Gecko Activity.
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBRDeveloper committed Feb 18, 2023
1 parent 7474489 commit 90d4b2c
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,21 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
if (session == null){
GeckoRuntimeSettings.Builder settings = new GeckoRuntimeSettings.Builder();
settings = settings.arguments(new String[]{
"--profile", config.getProfileDir().getAbsolutePath()
"--profile", config.getProfileDir().getAbsolutePath(),
"-purgecaches"
});

session = new WebSession(this);
runtime = GeckoRuntime.create(this, settings.build());
GeckoRuntimeSettings build = settings.build();

build.setAboutConfigEnabled(true);

runtime = GeckoRuntime.create(this, build);

session.open(runtime);
session.loadUri(config.url);
} else {
((WebSession)session).resumeUI();
}

((GeckoView)findViewById(R.id.webview)).setSession(session);
Expand All @@ -100,6 +109,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
findViewById(R.id.header).setVisibility(View.INVISIBLE);
findViewById(R.id.content).setPadding(0,0,0,0);
}

setTaskDescription(new ActivityManager.TaskDescription(config.name));
if (new File(config.getSaveDir(), "icon.png").exists()){
loadIcon();
}
}

private void loadIcon() {
new Thread(()->{
try {
Bitmap icon = BitmapFactory.decodeFile(new File(config.getSaveDir(), "icon.png").getAbsolutePath());
if (icon.getWidth() > 1){
setTaskDescription(new ActivityManager.TaskDescription(config.name, icon));
}
}catch (Exception e){}
}).start();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package br.com.nullexcept.webappmanager.app.basewebapp;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import org.mozilla.geckoview.GeckoResult;
import org.mozilla.geckoview.WebExtension;

import java.util.List;

import br.com.nullexcept.webappmanager.R;
import br.com.nullexcept.webappmanager.app.BaseWebAppActivity;

public class DialogOptions {
private AlertDialog dialog;
private static int pluginCount = -1;
public DialogOptions(BaseWebAppActivity ctx){
ctx.getRuntime().getWebExtensionController().list().accept(webExtensions -> pluginCount = webExtensions.size());
ctx.runOnUiThread(()->{
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
View view = ctx.getLayoutInflater().inflate(R.layout.dialog_actions,null, false);
Expand All @@ -18,9 +27,11 @@ public DialogOptions(BaseWebAppActivity ctx){
dialog.dismiss();
ctx.loadUrl("https://addons.mozilla.org/pt-BR/android/");
});

((TextView)view.findViewById(R.id.desc)).setText("Plugin Count: "+pluginCount);
view.findViewById(R.id.opt_gecko_settings).setOnClickListener(v -> {
dialog.dismiss();
ctx.loadUrl("about:preferences");
ctx.loadUrl("about:config");
});
builder.setView(view);
dialog = builder.create();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package br.com.nullexcept.webappmanager.web;

import android.widget.TextView;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.MediaSession;

import br.com.nullexcept.webappmanager.R;
import br.com.nullexcept.webappmanager.app.BaseWebAppActivity;
import br.com.nullexcept.webappmanager.config.Config;
import br.com.nullexcept.webappmanager.web.delegates.ContentListener;
Expand All @@ -15,12 +18,19 @@ public class WebSession extends GeckoSession {
public WebSession(Object current){
this.current = current.getClass();
getSettings().setUserAgentOverride(config().user_agent);
getSettings().setUseTrackingProtection(true);

setProgressDelegate(new ProcessListener(this));
setContentDelegate(new ContentListener(this));
setNavigationDelegate(new NavigationListener(this));
setPromptDelegate(new PromptListener(this));
}

public void resumeUI(){
((TextView)context().findViewById(R.id.title)).setText(((ContentListener)getContentDelegate()).getTitle());
((TextView)context().findViewById(R.id.url)).setText(((NavigationListener)getNavigationDelegate()).getLocation());
}

public void log(Object... items){
context().log(items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class ContentListener implements GeckoSession.ContentDelegate {
private WebSession session;
private String TITLE = "WebApp";
public ContentListener(WebSession session){
this.session = session;
}
Expand All @@ -20,7 +21,12 @@ public ContentListener(WebSession session){
public void onTitleChange(@NonNull GeckoSession current, @Nullable String title) {
GeckoSession.ContentDelegate.super.onTitleChange(current, title);
session.context().runOnUiThread(()->{
TITLE = title;
((TextView)session.context().findViewById(R.id.title)).setText(title);
});
}

public String getTitle() {
return TITLE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

public class NavigationListener implements GeckoSession.NavigationDelegate {
private WebSession session;
private String LOCATION = "";
public NavigationListener(WebSession session){
this.session = session;
}
Expand All @@ -44,9 +45,14 @@ public GeckoResult<AllowOrDeny> onLoadRequest(@NonNull GeckoSession session, @No
return GeckoSession.NavigationDelegate.super.onLoadRequest(session, request);
}

public String getLocation() {
return LOCATION;
}

@Override
public void onLocationChange(@NonNull GeckoSession current, @Nullable String url, @NonNull List<GeckoSession.PermissionDelegate.ContentPermission> perms) {
GeckoSession.NavigationDelegate.super.onLocationChange(current, url, perms);
LOCATION = url;
session.context().runOnUiThread(()->{
((TextView)session.context().findViewById(R.id.url)).setText(url);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package br.com.nullexcept.webappmanager.web.delegates;

import android.view.View;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;

Expand All @@ -10,6 +9,7 @@
import br.com.nullexcept.webappmanager.R;
import br.com.nullexcept.webappmanager.web.WebSession;

import br.com.nullexcept.webappmanager.widget.ProgressBar;
public class ProcessListener implements GeckoSession.ProgressDelegate {
private WebSession session;
public ProcessListener(WebSession session){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package br.com.nullexcept.webappmanager.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class ProgressBar extends View {
private int value = 50;
private int max = 100;
private int COLOR = Color.rgb(0,112,255);
public ProgressBar(Context context) {
super(context);
}

public ProgressBar(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public ProgressBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public ProgressBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

public void setProgress(int progress){
value = Math.min(progress,max);
invalidate();
}


public void setMax(int max) {
max = Math.max(1, max);
this.max = max;
value = Math.min(value,max);
invalidate();
}

public int getProgress(){
return value = Math.min(value,max);
}

public int getMax(){
return max;
}

private Rect rect = new Rect();
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getWidth();
int height = getHeight();

int drawWith = (int) Math.round ((((double)width)/max)*value);
paint.setColor(COLOR);
rect.set(0,0, drawWith, height);
canvas.drawRect(rect, paint);

}
}
9 changes: 7 additions & 2 deletions app/src/main/res/layout/dialog_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="32dp">
android:layout_height="45dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -44,7 +44,7 @@

<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="32dp">
android:layout_height="45dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -71,5 +71,10 @@
android:alpha="0"/>
</AbsoluteLayout>

<TextView
android:id="@+id/desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"/>

</LinearLayout>
17 changes: 10 additions & 7 deletions app/src/main/res/layout/webapp_acitivity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,26 @@

</AbsoluteLayout>

<LinearLayout
<AbsoluteLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="45dp">

<ProgressBar
<org.mozilla.geckoview.GeckoView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<br.com.nullexcept.webappmanager.widget.ProgressBar
android:id="@+id/loading_bar"
android:layout_width="match_parent"
android:layout_height="4dp"
android:visibility="invisible"
android:progress="25"
android:background="#5000"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>

<org.mozilla.geckoview.GeckoView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</AbsoluteLayout>

</RelativeLayout>

0 comments on commit 90d4b2c

Please sign in to comment.