Skip to content

Commit

Permalink
Merge branch 'feature/library'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacksgong committed Dec 14, 2015
2 parents a081eac + fbe64c0 commit ed35f2d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 27 deletions.
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
buildToolsVersion BUILD_TOOLS_VERSION as String

defaultConfig {
minSdkVersion 3
targetSdkVersion COMPILE_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
versionName VERSION_NAME as String
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@


/**
* Copyright (C) 2015 Jacks Blog
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created by Jacksgong on 9/1/15.
*/
public class KeyBoardSharedPreferences {
Expand Down
36 changes: 25 additions & 11 deletions library/src/main/java/cn/dreamtobe/kpswitch/util/KeyboardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
import cn.dreamtobe.kpswitch.R;

/**
* Copyright (C) 2015 Jacks Blog
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created by Jacksgong on 15/7/6.
*/
public class KeyboardUtil {
Expand All @@ -29,40 +43,40 @@ public static void hideKeyboard(final View view) {
}


private static int LAST_SAVE_KEYBORD_HEIGHT = 0;
private static int LAST_SAVE_KEYBOARD_HEIGHT = 0;

public static boolean saveKeyboardHeight(final Context context, int keyboardHeight) {
if (LAST_SAVE_KEYBORD_HEIGHT == keyboardHeight) {
if (LAST_SAVE_KEYBOARD_HEIGHT == keyboardHeight) {
return false;
}

if (keyboardHeight < 0) {
return false;
}

LAST_SAVE_KEYBORD_HEIGHT = keyboardHeight;
LAST_SAVE_KEYBOARD_HEIGHT = keyboardHeight;
Log.d("KeyBordUtil", String.format("save keyboard: %d", keyboardHeight));

return KeyBoardSharedPreferences.save(context, keyboardHeight);
}

public static int getKeybordHeight(final Context context) {
if (LAST_SAVE_KEYBORD_HEIGHT == 0) {
LAST_SAVE_KEYBORD_HEIGHT = KeyBoardSharedPreferences.get(context, getMinPanelHeight(context.getResources()));
public static int getKeyboardHeight(final Context context) {
if (LAST_SAVE_KEYBOARD_HEIGHT == 0) {
LAST_SAVE_KEYBOARD_HEIGHT = KeyBoardSharedPreferences.get(context, getMinPanelHeight(context.getResources()));
}

return LAST_SAVE_KEYBORD_HEIGHT;
return LAST_SAVE_KEYBOARD_HEIGHT;
}

public static int getValidPanelHeight(final Context context) {
final int maxPanelHeight = getMaxPanelHeight(context.getResources());
final int minPanelHeight = getMinPanelHeight(context.getResources());

int validPanelheight = getKeybordHeight(context);
int validPanelHeight = getKeyboardHeight(context);

validPanelheight = Math.max(minPanelHeight, validPanelheight);
validPanelheight = Math.min(maxPanelHeight, validPanelheight);
return validPanelheight;
validPanelHeight = Math.max(minPanelHeight, validPanelHeight);
validPanelHeight = Math.min(maxPanelHeight, validPanelHeight);
return validPanelHeight;


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public CustomRootLayout(Context context, AttributeSet attrs, int defStyleAttr, i
init();
}

private final static String STATUS_BAR_DEFPACKAGE = "android";
private final static String STATUS_BAR_DEFTYPE = "dimen";
private final static String STATUS_BAR_DEF_PACKAGE = "android";
private final static String STATUS_BAR_DEF_TYPE = "dimen";
private final static String STATUS_BAR_NAME = "status_bar_height";

private void init() {
getViewTreeObserver().addOnGlobalLayoutListener(this);

if (!mAlreadyGetStatusBarHeight) {
int resourceId = getResources().getIdentifier(STATUS_BAR_NAME, STATUS_BAR_DEFTYPE, STATUS_BAR_DEFPACKAGE);
int resourceId = getResources().getIdentifier(STATUS_BAR_NAME, STATUS_BAR_DEF_TYPE, STATUS_BAR_DEF_PACKAGE);
if (resourceId > 0) {
mStatusBarHeight = getResources().getDimensionPixelSize(resourceId);
mAlreadyGetStatusBarHeight = true;
Expand Down Expand Up @@ -171,7 +171,7 @@ private PanelLayout getPanelLayout(final View view) {

protected void onKeyboardShowing(final boolean isShowing) {
this.mIsKeyboardShowing = isShowing;
getPanelLayout(this).setIsKeybordShowing(isShowing);
getPanelLayout(this).setIsKeyboardShowing(isShowing);
}

private int maxBottom = 0;
Expand Down Expand Up @@ -217,7 +217,7 @@ public void onGlobalLayout() {

final int keyboardHeight = Math.abs(mLastHeight - height);
if (keyboardHeight == mStatusBarHeight) {
Log.w(TAG, String.format("On global layout change get keyboard hight just equal statusBar height %d", keyboardHeight));
Log.w(TAG, String.format("On global layout change get keyboard height just equal statusBar height %d", keyboardHeight));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class PanelLayout extends LinearLayout {
private boolean mIsHide = false;
private boolean mIsShow = true;

private final static String TAG = "JFrame.InputPanelLayout";

public PanelLayout(Context context) {
super(context);
init();
Expand Down Expand Up @@ -97,7 +95,7 @@ public void setVisibility(int visibility) {
}


if (mIsKeybordShowing && visibility == VISIBLE) {
if (mIsKeyboardShowing && visibility == VISIBLE) {
return;
}

Expand All @@ -118,10 +116,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
/**
* 这里只是一个状态,是在{@link #onMeasure}之前{@link CustomRootLayout#onLayout(boolean, int, int, int, int)}中获知
*/
private boolean mIsKeybordShowing = false;
private boolean mIsKeyboardShowing = false;

public void setIsKeybordShowing(final boolean isKeybordShowing) {
this.mIsKeybordShowing = isKeybordShowing;
public void setIsKeyboardShowing(final boolean isKeyboardShowing) {
this.mIsKeyboardShowing = isKeyboardShowing;
}


Expand Down
3 changes: 0 additions & 3 deletions library/src/main/res/values/strings.xml

This file was deleted.

0 comments on commit ed35f2d

Please sign in to comment.