mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Added some experimental changes to keep the webview on orientation changes
This commit is contained in:
parent
e7f74eb08d
commit
305a40c8c5
5 changed files with 83 additions and 7 deletions
|
@ -54,6 +54,7 @@
|
|||
android:name=".activity.MainActivity"
|
||||
android:launchMode="singleInstance"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:label="@string/diaspora">
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -52,6 +53,7 @@ import android.support.v7.widget.Toolbar;
|
|||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -64,6 +66,7 @@ import android.webkit.WebChromeClient;
|
|||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -145,7 +148,9 @@ public class MainActivity extends AppCompatActivity
|
|||
@BindView(R.id.toolbar2)
|
||||
ActionMenuView toolbarBottom;
|
||||
|
||||
@BindView(R.id.webView)
|
||||
@BindView(R.id.placeholder_webview)
|
||||
FrameLayout webviewPlaceholder;
|
||||
|
||||
ContextMenuWebView webView;
|
||||
|
||||
@BindView(R.id.main__navigaion_view)
|
||||
|
@ -169,10 +174,10 @@ public class MainActivity extends AppCompatActivity
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.d(App.TAG, "onCreate");
|
||||
|
||||
// Bind UI
|
||||
setContentView(R.layout.main__activity);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
app = (App) getApplication();
|
||||
appSettings = app.getSettings();
|
||||
|
@ -189,8 +194,23 @@ public class MainActivity extends AppCompatActivity
|
|||
resetProxy();
|
||||
}
|
||||
|
||||
setupWebView(savedInstanceState);
|
||||
setupUI(savedInstanceState);
|
||||
}
|
||||
|
||||
private void setupUI(Bundle savedInstanceState) {
|
||||
boolean newWebView = (webView == null);
|
||||
if(newWebView) {
|
||||
Log.d(App.TAG, "Webview was null. Create new one.");
|
||||
View webviewHolder = getLayoutInflater().inflate(R.layout.webview, null);
|
||||
webView = (ContextMenuWebView) webviewHolder.findViewById(R.id.webView);
|
||||
((LinearLayout)webView.getParent()).removeView(webView);
|
||||
setupWebView(savedInstanceState);
|
||||
}
|
||||
ButterKnife.bind(this);
|
||||
if (webviewPlaceholder.getChildCount() != 0) {
|
||||
webviewPlaceholder.removeAllViews();
|
||||
}
|
||||
webviewPlaceholder.addView(webView);
|
||||
// Setup toolbar
|
||||
setSupportActionBar(toolbarTop);
|
||||
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
|
||||
|
@ -231,8 +251,9 @@ public class MainActivity extends AppCompatActivity
|
|||
progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
||||
|
||||
String url = urls.getPodUrl();
|
||||
if (savedInstanceState == null) {
|
||||
if (newWebView) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
Log.d(App.TAG, "setupUI: reload url");
|
||||
webView.loadData("", "text/html", null);
|
||||
webView.loadUrlNew(url);
|
||||
} else {
|
||||
|
@ -248,6 +269,24 @@ public class MainActivity extends AppCompatActivity
|
|||
handleIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig)
|
||||
{
|
||||
if (webView != null)
|
||||
{
|
||||
// Remove the WebView from the old placeholder
|
||||
webviewPlaceholder.removeView(webView);
|
||||
}
|
||||
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// Load the layout resource for the new configuration
|
||||
setContentView(R.layout.main__activity);
|
||||
|
||||
// Reinitialize the UI
|
||||
setupUI(null);
|
||||
}
|
||||
|
||||
private void setupWebView(Bundle savedInstanceState) {
|
||||
|
||||
webSettings = webView.getSettings();
|
||||
|
@ -519,6 +558,7 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
||||
Helpers.printBundle(savedInstanceState,"");
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
webView.restoreState(savedInstanceState);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
||||
|
@ -31,8 +33,10 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Helpers {
|
||||
|
||||
|
@ -97,4 +101,22 @@ public class Helpers {
|
|||
public static String hexColorFromRessourceColor(Context context, int idColor){
|
||||
return "#" + Integer.toHexString(context.getResources().getColor(idColor) & 0x00ffffff);
|
||||
}
|
||||
|
||||
public static void printBundle(Bundle savedInstanceState, String k) {
|
||||
if(savedInstanceState != null) {
|
||||
for (String key : savedInstanceState.keySet()) {
|
||||
Log.d("SAVED", key + " is a key in the bundle "+k);
|
||||
Object bun = savedInstanceState.get(key);
|
||||
if(bun != null) {
|
||||
if (bun instanceof Bundle) {
|
||||
printBundle((Bundle) bun, k + "." + key);
|
||||
} else if (bun instanceof byte[]) {
|
||||
Log.d("SAVED", "Key: "+k + "." + key+": "+ Arrays.toString((byte[])bun));
|
||||
} else {
|
||||
Log.d("SAVED", "Key: "+k + "." + key+": "+ bun.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
tools:context=".activity.MainActivity"
|
||||
tools:showIn="@layout/main__app_bar">
|
||||
|
||||
<com.github.dfa.diaspora_android.ui.ContextMenuWebView
|
||||
android:id="@+id/webView"
|
||||
<FrameLayout
|
||||
android:id="@+id/placeholder_webview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
|
|
13
app/src/main/res/layout/webview.xml
Normal file
13
app/src/main/res/layout/webview.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<com.github.dfa.diaspora_android.ui.ContextMenuWebView
|
||||
android:id="@+id/webView"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue