//
// Copyright (c) 2017, weidian.com
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
package com.weidian.lib.hera.page;
import android.animation.LayoutTransition;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.weidian.lib.hera.R;
import com.weidian.lib.hera.config.AppConfig;
import com.weidian.lib.hera.interfaces.IBridgeHandler;
import com.weidian.lib.hera.interfaces.OnEventListener;
import com.weidian.lib.hera.model.TabItemInfo;
import com.weidian.lib.hera.page.view.NavigationBar;
import com.weidian.lib.hera.page.view.PageWebView;
import com.weidian.lib.hera.page.view.TabBar;
import com.weidian.lib.hera.trace.HeraTrace;
import com.weidian.lib.hera.utils.ColorUtil;
import com.weidian.lib.hera.utils.FileUtil;
import com.weidian.lib.hera.utils.UIUtil;
import com.weidian.lib.hera.web.HeraWebViewClient;
import com.weidian.lib.hera.widget.ToastView;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.List;
import java.util.Set;
/**
* Page层,即小程序view展示层
*/
public class Page extends LinearLayout implements IBridgeHandler,
TabBar.OnSwitchTabListener, PageWebView.OnHorizontalSwipeListener {
public static final String TAG = "Page";
public static final String APP_LAUNCH = "appLaunch";
public static final String NAVIGATE_TO = "navigateTo";
public static final String NAVIGATE_BACK = "navigateBack";
public static final String REDIRECT_TO = "redirectTo";
public static final String SWITCH_TAB = "switchTab";
private FrameLayout mWebLayout;
private NavigationBar mNavigationBar;
private PageWebView mCurrentWebView;
private TabBar mTabBar;
private ToastView mToastView;
private AppConfig mAppConfig;
private OnEventListener mEventListener;
private String mPageOpenType;
private String mPagePath;
private boolean isHomePage;
public Page(Context context, String pagePath, AppConfig appConfig,boolean isHomePage) {
super(context);
this.mAppConfig = appConfig;
this.isHomePage=isHomePage;
init(context, pagePath);
}
private void init(Context context, String url) {
inflate(context, R.layout.hera_page, this);
LinearLayout topLayout = (LinearLayout) findViewById(R.id.top_layout);
LinearLayout bottomLayout = (LinearLayout) findViewById(R.id.bottom_layout);
mWebLayout = (FrameLayout) findViewById(R.id.web_layout);
mToastView = (ToastView) findViewById(R.id.toast_view);
mNavigationBar = new NavigationBar(context);
//添加导航栏
topLayout.addView(mNavigationBar, new LayoutParams(LayoutParams.MATCH_PARENT,
mNavigationBar.getMaximumHeight()));
if (mAppConfig.isTabPage(url)) {
initTabPage(context, topLayout, bottomLayout);
} else {
initSinglePage(context);
}
}
private void initTabPage(Context context, LinearLayout topLayout, LinearLayout bottomLayout) {
//添加tab栏
mTabBar = new TabBar(context, mAppConfig);
mTabBar.setOnSwitchTabListener(this);
if (mAppConfig.isTopTabBar()) {
bottomLayout.setVisibility(GONE);
topLayout.addView(mTabBar, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
} else {
bottomLayout.setVisibility(VISIBLE);
bottomLayout.addView(mTabBar, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
}
//添加web页面
List<TabItemInfo> list = mAppConfig.getTabItemList();
int len = (list == null ? 0 : list.size());
for (int i = 0; i < len; i++) {
TabItemInfo info = list.get(i);
String url = info != null ? info.pagePath : null;
mWebLayout.addView(createSwipeRefreshWebView(context, url),
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
}
}
private void initSinglePage(Context context) {
mWebLayout = (FrameLayout) findViewById(R.id.web_layout);
mWebLayout.addView(createSwipeRefreshWebView(context, null),
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
}
/**
* 创建封装下拉刷新功能的WebView包装视图
*
* @param context 上下文
* @param url 页面路径
* @return 封装下拉刷新功能的WebView包装视图
*/
private SwipeRefreshLayout createSwipeRefreshWebView(Context context, String url) {
SwipeRefreshLayout refreshLayout = new SwipeRefreshLayout(context);
refreshLayout.setEnabled(mAppConfig.isEnablePullDownRefresh(url));
refreshLayout.setColorSchemeColors(Color.GRAY);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
HeraTrace.d(TAG, "start onPullDownRefresh");
onPageEvent("onPullDownRefresh", "{}");
}
});
PageWebView webView = new PageWebView(context);
webView.setTag(url);
webView.setWebViewClient(new HeraWebViewClient(mAppConfig));
webView.setJsHandler(this);
if (!isHomePage){
webView.setSwipeListener(this);
}
refreshLayout.addView(webView, 0, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mCurrentWebView = webView;
return refreshLayout;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
HeraTrace.d(TAG, String.format("view@%s onAttachedToWindow()", getViewId()));
//设置标题栏背景色(通过应用配置信息获取)
String textColor = mAppConfig.getNavigationBarTextColor();
String bgColor = mAppConfig.getNavigationBarBackgroundColor();
mNavigationBar.setTitleTextColor(ColorUtil.parseColor(textColor));
int naviBgColor=ColorUtil.parseColor(bgColor);
mNavigationBar.setBackgroundColor(nav
lly202406
- 粉丝: 3212
- 资源: 5564
最新资源
- 基于stm32F1的气体监测.zip
- stm32f407 硬件SPI TFT 1.44 st7735.rar
- STM32F407核心板资料(型号FK407M1).rar
- ADI的ADC采集芯片AD7190驱动,主控IC STM32F407,通过外使SPI进行读写
- java-jsp毕业生论文管理系统计算机毕业设计程序.zip
- java-jsp毕业生信息管理系统计算机毕业设计程序.zip
- 基于java的毕业设计(源代码+论文)3套(14)
- 500kW三相光伏并网逆变器的仿真模型: 1. DC DC采用MPPT最大功率点跟踪控制; 2. DC AC采用功率外环电流内环的双闭环控制,有功功率和无功功率解耦控制+前馈补偿,SVPWM空间电压矢
- 基于java的毕业设计(源代码+论文)3套(12)
- 1_6020222704吕锡振-实验五代码.ipynb
- 台达AS228T实际案例伺服步进程序 六个步进,昆仑通态触摸屏, FB功能块实用,多次调用 注释清洗,逻辑实用
- readslc代码需要的数据文件
- 基于can总线的dsp28335升级方案 包括bootloader源码,app源码,上位机 上位机用c#,vs2013 升级过程见视频 示例工程为62kb
- jh_flutter_demo.apk
- 半桥LLC仿真模型,基于MATLAB Simulink建模仿真 可以进行LLC暂态、稳态仿真,仿真zvs特性、软启动等 仿真模型使用MATLAB 2017b搭建
- 西门子1200PLC博图自动称重配料系统程序例程,组态画面采用KTP1200触摸屏 具体为1200和变频器Modbus RTU 通 讯,托利多电子称modbus RTU通讯,带 PID 温度控制程序
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈