/*
Swisscom Safe Connect
Copyright (C) 2014 Swisscom
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.swisscom.safeconnect.fragment;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import com.swisscom.safeconnect.R;
/**
* Created by vadim on 25.09.14.
*/
public abstract class LogoFragment extends Fragment {
protected ImageView imgLogo;
protected void adjustLogoOnKeyboardShow(final View v) {
final int tablet = (getResources().getBoolean(R.bool.isTablet) ? 1 : 0);
v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
v.getWindowVisibleDisplayFrame(r);
int heightDiff = v.getRootView().getHeight() - (r.bottom - r.top);
// keyboard detection
if (heightDiff > 100) {
int orientation = getActivity().getResources().getConfiguration().orientation;
// Remove logo tablet landscape and phone portrait
if ((getActivity() != null && orientation == Configuration.ORIENTATION_LANDSCAPE) ||
(tablet == 0 && orientation == Configuration.ORIENTATION_PORTRAIT)) {
if (imgLogo != null) {
imgLogo.setVisibility(View.GONE);
}
}
} else {
if(imgLogo!=null) {
imgLogo.setVisibility(View.VISIBLE);
}
}
}
});
}
}