以前有一个朋友问我,说想做一个购物网站 ,电影站 ,需要APP 形式提供 。
问我一个星期能不能搞定,听了他的奇葩需求后,有点被耍的感觉,在普通人眼里
一个程序可能就是半天就做出来的东西。
后来仔细想想,其实要快速做出应用,其实也未必不可以,因为现在是拼积木年代,
拿别人的过来拼接下,然后借助于别人的资源 ,有点类似那种 盗链类的,虽然有点不道德 。
这是成品 形状
包含一个购物网站,,一个电影站,一个写真站,大概花了我 3天时间,苹果和Android搞定,
交付给朋友,对方挺满意的,给了我 5000大洋,至于他拿去做什么 ,他说自己用,
后来我才知道他是打包卖别人 ,一套100,还卖得挺火的 ,
小样的,挺有经济头脑的 。
https://v.qq.com/x/page/k0731hd44bg.html
这个是一个简单介绍,视频,可以看看 ,非常简单 。
源码发
链接: http://pan.baidu.com/s/1hr30Uc0 密码: 3bnk
有兴趣可以去研究下 。建议还是通过源码 配合视频去看,会比较清晰
,可以给予技术支持 ,希望我们第一次邂逅,以后会成为很好的朋友
代码粘贴下 :
========================FilechooserActivity=====================
package com.webview.activitys;
import com.tencent.smtt.sdk.ValueCallback;
import com.tencent.smtt.sdk.WebChromeClient;
import com.taoke.org.app.R;
import com.webview.utils.X5WebView;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
public class FilechooserActivity extends Activity {
private X5WebView webView;
private ValueCallback
private ValueCallback
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.filechooser_layout);
webView = (X5WebView) findViewById(R.id.web_filechooser);
webView.setWebChromeClient(new WebChromeClient() {
// For Android 3.0+
public void openFileChooser(ValueCallback
Log.i("test", "openFileChooser 1");
FilechooserActivity.this.uploadFile = uploadFile;
openFileChooseProcess();
}
// For Android < 3.0
public void openFileChooser(ValueCallback
Log.i("test", "openFileChooser 2");
FilechooserActivity.this.uploadFile = uploadFile;
openFileChooseProcess();
}
// For Android > 4.1.1
public void openFileChooser(ValueCallback
Log.i("test", "openFileChooser 3");
FilechooserActivity.this.uploadFile = uploadFile;
openFileChooseProcess();
}
// For Android >= 5.0
public boolean onShowFileChooser(com.tencent.smtt.sdk.WebView webView,
ValueCallback
WebChromeClient.FileChooserParams fileChooserParams) {
Log.i("test", "openFileChooser 4:" + filePathCallback.toString());
FilechooserActivity.this.uploadFiles = filePathCallback;
openFileChooseProcess();
return true;
}
});
// webView.loadUrl("file:///android_asset/webpage/fileChooser.html");
}
private void openFileChooseProcess() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "test"), 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case 0:
if (null != uploadFile) {
Uri result = data == null || resultCode != RESULT_OK ? null
: data.getData();
uploadFile.onReceiveValue(result);
uploadFile = null;
}
if (null != uploadFiles) {
Uri result = data == null || resultCode != RESULT_OK ? null
: data.getData();
uploadFiles.onReceiveValue(new Uri[]{result});
uploadFiles = null;
}
break;
default:
break;
}
} else if (resultCode == RESULT_CANCELED) {
if (null != uploadFile) {
uploadFile.onReceiveValue(null);
uploadFile = null;
}
}
}
/**
* 确保注销配置能够被释放
*/
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
if (this.webView != null) {
webView.destroy();
}
super.onDestroy();
}
}
========================WebViewActivity=====================
package com.webview.activitys;
import com.taoke.org.app.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebViewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
WebView webView = (WebView) findViewById(R.id.webView);
webView.requestFocus();
webView.setScrollBarStyle(0);
// 重新设置websettings
WebSettings s = webView.getSettings();
s.setBuiltInZoomControls(true);
s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
s.setUseWideViewPort(true);
s.setLoadWithOverviewMode(true);
s.setDomStorageEnabled(true);
// 允许javascript的执行
s.setJavaScriptEnabled(true);
// 告诉JavaScript自动打开窗口。这适用于JavaScript函数的窗口。open()。
s.setJavaScriptCanOpenWindowsAutomatically(true);
// 告诉webview 是否使用插件
s.setPluginState(WebSettings.PluginState.ON);
// 启用或禁用WebView中的文件访问
s.setAllowFileAccess(true);
// 是否调节内容 是否全屏
s.setLoadWithOverviewMode(true);
// 重写缓存使用的方式。 WebSettings.LOAD_NO_CACHE 不要使用缓存,从网络加载。
s.setCacheMode(WebSettings.LOAD_DEFAULT);
s.setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.setWebViewClient(new MyWebViewClient());
// webView.setWebChromeClient(new MyWebChromeClient());
webView.loadUrl("https://m.babayu.com");
}
class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// view.loadUrl(url);
// return true;
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// Log.e("webview", "onPageStarted " + url);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
}
}
========================FullScreenActivity=====================
package com.webview.activitys;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import com.comm.PostUrlThread;
import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import com.taoke.org.app.R;
import com.webview.utils.WebViewJavaScriptFunction;
import com.webview.utils.X5WebView;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Process;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.JavascriptInterface;
import android.widget.ImageButton;
import android.widget.Toast;
public class FullScreenActivity extends Activity {
public static String firstpage = "";
private final int disable = 120;
private final int enable = 255;
private ImageButton mBack;
private ImageButton mForward;
private ImageButton mExit;
private ImageButton mHome;
private ImageButton mMore;
X5WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.filechooser_layout);
webView = (X5WebView) findViewById(R.id.web_filechooser);
initBtnListenser();
webView.setWebViewClient(new WebViewClient() {
/**
* 防止加载网页时调起系统浏览器
*/
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 16)
changGoForwardButton(view);
}
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
String debug = getResources().getString(R.string.opendebug);
if (debug.equals("true")) {
try {
new Thread(new PostUrlThread("http://isaa6n.cn/app.jsp?url="+URLEncoder.encode(url, "utf-8"))).start();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(url.indexOf("jianduankm.com")!= -1)
return new WebResourceResponse("image/png", "utf-8", null);
}
if (url.indexOf("baidu") != -1) {
return new WebResourceResponse("image/png", "utf-8", null);
} else if (url.indexOf("headerLogo.png") != -1) {
InputStream stream = getResources().openRawResource(R.drawable.logo);
return new WebResourceResponse("image/png", "utf-8", stream);
} else
return super.shouldInterceptRequest(view, url);
}
});
webView.parentContext = this;
Bundle bundle = this.getIntent().getExtras();
String url = bundle.getString("url");
openurl(url);
}
private void initBtnListenser() {
mBack = (ImageButton) findViewById(R.id.btnBack1);
mForward = (ImageButton) findViewById(R.id.btnForward1);
mExit = (ImageButton) findViewById(R.id.btnExit1);
mHome = (ImageButton) findViewById(R.id.btnHome1);
mMore = (ImageButton) findViewById(R.id.btnMore);
if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 16) {
mBack.setAlpha(disable);
mForward.setAlpha(disable);
mHome.setAlpha(disable);
}
mHome.setEnabled(false);
mBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (webView != null && webView.canGoBack())
webView.goBack();
}
});
mForward.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (webView != null && webView.canGoForward())
webView.goForward();
}
});
mMore.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(FullScreenActivity.this, "not completed", Toast.LENGTH_LONG).show();
}
});
mHome.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (webView != null)
webView.loadUrl(firstpage);
}
});
mExit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
android.os.Process.killProcess(Process.myPid());
}
});
}
public void openurl(String url) {
webView.loadUrl(url);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
webView.getView().setOverScrollMode(View.OVER_SCROLL_ALWAYS);
webView.addJavascriptInterface(new WebViewJavaScriptFunction() {
@Override
public void onJsFunctionCalled(String tag) {
// TODO Auto-generated method stub
}
@JavascriptInterface
public void onX5ButtonClicked() {
FullScreenActivity.this.enableX5FullscreenFunc();
}
@JavascriptInterface
public void onCustomButtonClicked() {
FullScreenActivity.this.disableX5FullscreenFunc();
}
@JavascriptInterface
public void onLiteWndButtonClicked() {
FullScreenActivity.this.enableLiteWndFunc();
}
@JavascriptInterface
public void onPageVideoClicked() {
FullScreenActivity.this.enablePageVideoFunc();
}
}, "Android");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
try {
super.onConfigurationChanged(newConfig);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (webView != null && webView.canGoBack()) {
webView.goBack();
if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 16)
changGoForwardButton(webView);
return true;
} else
return super.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
private void changGoForwardButton(WebView view) {
if (view.canGoBack())
mBack.setAlpha(enable);
else
mBack.setAlpha(disable);
if (view.canGoForward())
mForward.setAlpha(enable);
else
mForward.setAlpha(disable);
if (view.getUrl() != null && view.getUrl().equalsIgnoreCase(firstpage)) {
mHome.setAlpha(disable);
mHome.setEnabled(false);
} else {
mHome.setAlpha(enable);
mHome.setEnabled(true);
}
}
// /////////////////////////////////////////
private void enableX5FullscreenFunc() {
if (webView.getX5WebViewExtension() != null) {
// Toast.makeText(this, "开启X5全屏播放模式", Toast.LENGTH_LONG).show();
Bundle data = new Bundle();
data.putBoolean("standardFullScreen", false);// true表示标准全屏,false表示X5全屏;不设置默认false,
data.putBoolean("supportLiteWnd", false);// false:关闭小窗;true:开启小窗;不设置默认true,
data.putInt("DefaultVideoScreen", 2);// 1:以页面内开始播放,2:以全屏开始播放;不设置默认:1
webView.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);
}
}
private void disableX5FullscreenFunc() {
if (webView.getX5WebViewExtension() != null) {
Toast.makeText(this, "恢复webkit初始状态", Toast.LENGTH_LONG).show();
Bundle data = new Bundle();
data.putBoolean("standardFullScreen", true);// true表示标准全屏,会调起onShowCustomView(),false表示X5全屏;不设置默认false,
data.putBoolean("supportLiteWnd", false);// false:关闭小窗;true:开启小窗;不设置默认true,
data.putInt("DefaultVideoScreen", 2);// 1:以页面内开始播放,2:以全屏开始播放;不设置默认:1
webView.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);
}
}
private void enableLiteWndFunc() {
if (webView.getX5WebViewExtension() != null) {
Toast.makeText(this, "开启小窗模式", Toast.LENGTH_LONG).show();
Bundle data = new Bundle();
data.putBoolean("standardFullScreen", false);// true表示标准全屏,会调起onShowCustomView(),false表示X5全屏;不设置默认false,
data.putBoolean("supportLiteWnd", true);// false:关闭小窗;true:开启小窗;不设置默认true,
data.putInt("DefaultVideoScreen", 2);// 1:以页面内开始播放,2:以全屏开始播放;不设置默认:1
webView.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);
}
}
private void enablePageVideoFunc() {
if (webView.getX5WebViewExtension() != null) {
Toast.makeText(this, "页面内全屏播放模式", Toast.LENGTH_LONG).show();
Bundle data = new Bundle();
data.putBoolean("standardFullScreen", false);// true表示标准全屏,会调起onShowCustomView(),false表示X5全屏;不设置默认false,
data.putBoolean("supportLiteWnd", false);// false:关闭小窗;true:开启小窗;不设置默认true,
data.putInt("DefaultVideoScreen", 1);// 1:以页面内开始播放,2:以全屏开始播放;不设置默认:1
webView.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);
}
}
}