1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-12-23 03:18:04 +01:00

fix keyboard. #4

This commit is contained in:
Gregor Santner 2016-06-04 21:46:54 +02:00
parent d60069253e
commit 945d617a52
7 changed files with 22 additions and 121 deletions

View file

@ -37,8 +37,7 @@
<activity
android:name=".activity.MainActivity"
android:launchMode="singleInstance"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan"
android:theme="@style/AppTheme.NoActionBar"
android:label="@string/diaspora">
</activity>

View file

@ -138,10 +138,11 @@ public class MainActivity extends AppCompatActivity
ContextMenuWebView webView;
@BindView(R.id.main__navigaion_view)
NavigationView navigationView;
NavigationView navView;
@BindView(R.id.main__layout)
DrawerLayout navDrawer;
@BindView(R.id.drawer_layout)
DrawerLayout drawer;
// NavHeader cannot be bound by Butterknife
private TextView navheaderTitle;
@ -171,6 +172,7 @@ public class MainActivity extends AppCompatActivity
this.registerForContextMenu(webView);
webView.setParentActivity(this);
webView.setOverScrollMode(WebView.OVER_SCROLL_ALWAYS);
// Setup toolbar
setSupportActionBar(toolbarTop);
@ -181,7 +183,6 @@ public class MainActivity extends AppCompatActivity
}
});
// Load app settings
setupNavigationSlider();
@ -191,6 +192,7 @@ public class MainActivity extends AppCompatActivity
swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary,
R.color.fab_big);
// Setup WebView
webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge");
if (savedInstanceState != null) {
webView.restoreState(savedInstanceState);
@ -313,14 +315,14 @@ public class MainActivity extends AppCompatActivity
private void setupNavigationSlider() {
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbarTop, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
this, navDrawer, toolbarTop, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
navDrawer.addDrawerListener(toggle);
toggle.syncState();
//NavigationView navigationView = ButterKnife.findById(this, R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//NavigationView navView = ButterKnife.findById(this, R.id.nav_view);
navView.setNavigationItemSelectedListener(this);
View navHeader = navigationView.getHeaderView(0);
View navHeader = navView.getHeaderView(0);
navheaderTitle = ButterKnife.findById(navHeader, R.id.navheader_title);
navheaderDescription = ButterKnife.findById(navHeader, R.id.podselection__podupti_notice);
navheaderImage = ButterKnife.findById(navHeader, R.id.navheader_user_image);
@ -342,7 +344,7 @@ public class MainActivity extends AppCompatActivity
@OnClick(R.id.toolbar)
public void onToolBarClicked(View view) {
onNavigationItemSelected(navigationView.getMenu().findItem(R.id.nav_stream));
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
}
private File createImageFile() throws IOException {
@ -403,8 +405,8 @@ public class MainActivity extends AppCompatActivity
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(navigationView)) {
drawer.closeDrawer(navigationView);
if (navDrawer.isDrawerOpen(navView)) {
navDrawer.closeDrawer(navView);
return;
}
@ -1035,7 +1037,7 @@ public class MainActivity extends AppCompatActivity
break;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.main__layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

View file

@ -20,9 +20,6 @@
package com.github.dfa.diaspora_android.activity;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
@ -33,8 +30,6 @@ import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
@ -50,7 +45,6 @@ import com.github.dfa.diaspora_android.util.Helpers;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class ShareActivity extends MainActivity {
@ -163,7 +157,7 @@ public class ShareActivity extends MainActivity {
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
// Error occurred while creating the File
Snackbar.make(getWindow().findViewById(R.id.drawer_layout), "Unable to get image", Snackbar.LENGTH_LONG).show();
Snackbar.make(getWindow().findViewById(R.id.main__layout), "Unable to get image", Snackbar.LENGTH_LONG).show();
}
// Continue only if the File was successfully created
@ -202,7 +196,7 @@ public class ShareActivity extends MainActivity {
if (Helpers.isOnline(ShareActivity.this)) {
webView.loadUrl("https://" + podDomain + "/status_messages/new");
} else {
Snackbar.make(getWindow().findViewById(R.id.drawer_layout), R.string.no_internet, Snackbar.LENGTH_LONG).show();
Snackbar.make(getWindow().findViewById(R.id.main__layout), R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}

View file

@ -1,95 +0,0 @@
package com.github.dfa.diaspora_android.listener;
/**
* Created by juergen on 25.03.16. Part of Diaspora for Android.
* solution found on: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
*/
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import java.util.LinkedList;
import java.util.List;
public class SoftKeyboardStateWatcher implements ViewTreeObserver.OnGlobalLayoutListener {
private final List<SoftKeyboardStateListener> listeners = new LinkedList<>();
private final View activityRootView;
private int lastSoftKeyboardHeightInPx;
private boolean isSoftKeyboardOpened;
public SoftKeyboardStateWatcher(View activityRootView) {
this(activityRootView, false);
}
public SoftKeyboardStateWatcher(View activityRootView, boolean isSoftKeyboardOpened) {
this.activityRootView = activityRootView;
this.isSoftKeyboardOpened = isSoftKeyboardOpened;
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(this);
}
@Override
public void onGlobalLayout() {
final Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
final int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (!isSoftKeyboardOpened && heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
isSoftKeyboardOpened = true;
notifyOnSoftKeyboardOpened(heightDiff);
} else if (isSoftKeyboardOpened && heightDiff < 100) {
isSoftKeyboardOpened = false;
notifyOnSoftKeyboardClosed();
}
}
public void setIsSoftKeyboardOpened(boolean isSoftKeyboardOpened) {
this.isSoftKeyboardOpened = isSoftKeyboardOpened;
}
public boolean isSoftKeyboardOpened() {
return isSoftKeyboardOpened;
}
/**
* Default value is zero {@code 0}.
*
* @return last saved keyboard height in px
*/
public int getLastSoftKeyboardHeightInPx() {
return lastSoftKeyboardHeightInPx;
}
public void addSoftKeyboardStateListener(SoftKeyboardStateListener listener) {
listeners.add(listener);
}
public void removeSoftKeyboardStateListener(SoftKeyboardStateListener listener) {
listeners.remove(listener);
}
private void notifyOnSoftKeyboardOpened(int keyboardHeightInPx) {
this.lastSoftKeyboardHeightInPx = keyboardHeightInPx;
for (SoftKeyboardStateListener listener : listeners) {
if (listener != null) {
listener.onSoftKeyboardOpened(keyboardHeightInPx);
}
}
}
private void notifyOnSoftKeyboardClosed() {
for (SoftKeyboardStateListener listener : listeners) {
if (listener != null) {
listener.onSoftKeyboardClosed();
}
}
}
public interface SoftKeyboardStateListener {
void onSoftKeyboardOpened(int keyboardHeightInPx);
void onSoftKeyboardClosed();
}
}

View file

@ -51,6 +51,8 @@ public class Helpers {
public static void hideTopBar(final WebView wv) {
wv.loadUrl("javascript: ( function() {" +
" document.documentElement.style.paddingBottom = '260px';" +
" document.getElementById('main').style.paddingTop = '5px';" +
" if(document.getElementById('main_nav')) {" +
" document.getElementById('main_nav').parentNode.removeChild(" +
" document.getElementById('main_nav'));" +

View file

@ -2,7 +2,7 @@
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:id="@+id/main__layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -26,7 +25,7 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_gravity="bottom|end"
android:layout_gravity="bottom"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">