Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[Android]create a new module deviceInfo to enable full screen height #2578

Merged
merged 6 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList;
import com.taobao.weex.ui.component.richtext.WXRichText;
import com.taobao.weex.ui.config.AutoScanConfigRegister;
import com.taobao.weex.ui.module.WXDeviceInfoModule;
import com.taobao.weex.ui.module.WXLocaleModule;
import com.taobao.weex.ui.module.WXMetaModule;
import com.taobao.weex.ui.module.WXModalUIModule;
Expand Down Expand Up @@ -377,6 +378,7 @@ private static void register() {
registerModule("meta", WXMetaModule.class);
registerModule("webSocket", WebSocketModule.class);
registerModule("locale", WXLocaleModule.class);
registerModule("deviceInfo", WXDeviceInfoModule.class);
} catch (WXException e) {
WXLogUtils.e("[WXSDKEngine] register:", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan
private boolean mNeedReLoad = false;
private boolean mUseScroller = false;
private int mInstanceViewPortWidth = 750;
private boolean enableFullScreenHeight = false;
private WXInstanceApm mApmForInstance;
private @NonNull
FlatGUIContext mFlatGUIContext =new FlatGUIContext();
Expand Down Expand Up @@ -401,6 +402,10 @@ public void setNeedLoad(boolean load) {
mNeedReLoad = load;
}

public void setEnableFullScreenHeight(boolean fullScreenHeight){enableFullScreenHeight = fullScreenHeight;}
YorkShen marked this conversation as resolved.
Show resolved Hide resolved

public boolean isFullScreenHeightEnabled(){return enableFullScreenHeight;}
YorkShen marked this conversation as resolved.
Show resolved Hide resolved

public boolean isUseScroller() {
return mUseScroller;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void triggerEvent(String type, Map<String, Object> args) {
*/
@Override
protected MeasureOutput measure(int width, int height) {
int screenH = WXViewUtils.getScreenHeight(WXEnvironment.sApplication);
int screenH = WXViewUtils.getScreenHeight(getInstanceId());
int weexH = WXViewUtils.getWeexHeight(getInstanceId());
int outHeight = height > (weexH >= screenH ? screenH : weexH) ? weexH - getAbsoluteY() : height;
return super.measure(width, outHeight);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.taobao.weex.ui.module;

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.common.WXModule;
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXViewUtils;

import java.util.HashMap;

public class WXDeviceInfoModule extends WXModule {

@JSMethod(uiThread = false)
public void enableFullScreenHeight(JSCallback callback){
YorkShen marked this conversation as resolved.
Show resolved Hide resolved
if(mWXSDKInstance != null) {
mWXSDKInstance.setEnableFullScreenHeight(true);
long fullheight = WXViewUtils.getScreenHeight(mWXSDKInstance.getInstanceId());
long height = WXViewUtils.getScreenHeight(WXEnvironment.sApplication);
HashMap<String, String> ret = new HashMap();
WXLogUtils.d("jhy", String.valueOf(fullheight));
ret.put("fullheight", String.valueOf(fullheight));
ret.put("height", String.valueOf(height));
callback.invoke(ret);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
Expand All @@ -36,6 +37,8 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
Expand Down Expand Up @@ -204,10 +207,39 @@ public static int getScreenHeight() {
return getScreenHeight(WXEnvironment.sApplication);
}

public static int getScreenHeight(String instanceId){
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
return instance.isFullScreenHeightEnabled()?getFullScreenHeight(WXEnvironment.sApplication):getScreenHeight(WXEnvironment.sApplication);
}

public static int getFullScreenHeight(Context cxt) {
YorkShen marked this conversation as resolved.
Show resolved Hide resolved
if(cxt!=null){
WindowManager wm;
Resources res = cxt.getResources();
if(Build.VERSION.SDK_INT >= 17 && (wm = (WindowManager)cxt.getSystemService(Context.WINDOW_SERVICE)) != null
&& wm.getDefaultDisplay() != null){
Point size = new Point();
wm.getDefaultDisplay().getRealSize(size);
mScreenHeight = size.y;
}
else {
mScreenHeight = cxt.getResources().getDisplayMetrics().heightPixels;
}
if(WXEnvironment.SETTING_FORCE_VERTICAL_SCREEN){
mScreenWidth = res
.getDisplayMetrics()
.widthPixels;
mScreenHeight = mScreenHeight > mScreenWidth ? mScreenHeight : mScreenWidth;
}
} else if (WXEnvironment.isApkDebugable()){
throw new WXRuntimeException("Error Context is null When getScreenHeight");
}
return mScreenHeight;
}
public static int getScreenHeight(Context cxt) {
if(cxt!=null){
Resources res = cxt.getResources();
mScreenHeight =cxt.getResources().getDisplayMetrics().heightPixels;
mScreenHeight = res.getDisplayMetrics().heightPixels;
if(WXEnvironment.SETTING_FORCE_VERTICAL_SCREEN){
mScreenWidth = res
.getDisplayMetrics()
Expand All @@ -220,6 +252,7 @@ public static int getScreenHeight(Context cxt) {
return mScreenHeight;
}


/**
* Convert distance from JS,CSS to native. As the JS considers the width of the screen is 750px.
* There must be a transform when accessing distance from JS,CSS and use it.
Expand Down