Socket请求网页

Java Socket现实简单的HTTP服务 http://jiangzhengjun.iteye.com/blog/512380 Java socket 访问网页 http://blog.csdn.net/yilip/article/details/45195713 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.Socket; public class WebpageSocket { private static int port = 80; private static String hostname = “www.iteye.com”; public static void main(String[] args) throws Exception{ Socket socket = new Socket(hostname, port); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), “utf-8”)); writer.write(“GET ” + “/ask” + ” HTTP/1.0\r\n”); writer.write(“HOST:” + hostname + “\r\n”); writer.write(“Accept:*/*\r\n”); writer.write(“\r\n”); writer.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), “utf-8”)); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } reader.close(); writer.close(); socket.close(); } } ...

2017年1月4日 · 3 分钟 · 天边的星星

高德地图知识汇总

//设置缩放级别 aMap.moveCamera(CameraUpdateFactory.zoomTo(17)); //将地图移动到定位点 aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude()))); //点击定位按钮 能够将地图的中心移动到定位点 mListener.onLocationChanged(amapLocation); //添加图钉 aMap.addMarker(getMarkerOptions(amapLocation)); //获取定位信息 StringBuffer buffer = new StringBuffer(); buffer.append(amapLocation.getCountry() + “” + amapLocation.getProvince() + “” + amapLocation.getCity() + “” + amapLocation.getProvince() + “” + amapLocation.getDistrict() + “” + amapLocation.getStreet() + “” + amapLocation.getStreetNum()); Toast.makeText(getApplicationContext(), buffer.toString(), Toast.LENGTH_LONG).show(); isFirstLoc = false; //定位的小图标 默认是蓝点 这里自定义一团火,其实就是一张图片 MyLocationStyle myLocationStyle = new MyLocationStyle(); myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.firetwo)); myLocationStyle.radiusFillColor(android.R.color.transparent); myLocationStyle.strokeColor(android.R.color.transparent); aMap.setMyLocationStyle(myLocationStyle); //定位 private void initLoc() { //初始化定位 mLocationClient = new AMapLocationClient(getApplicationContext()); //设置定位回调监听 mLocationClient.setLocationListener(this); //初始化定位参数 mLocationOption = new AMapLocationClientOption(); //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式 mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); //设置是否返回地址信息(默认返回地址信息) mLocationOption.setNeedAddress(true); //设置是否只定位一次,默认为false mLocationOption.setOnceLocation(false); //设置是否强制刷新WIFI,默认为强制刷新 mLocationOption.setWifiActiveScan(true); //设置是否允许模拟位置,默认为false,不允许模拟位置 mLocationOption.setMockEnable(false); //设置定位间隔,单位毫秒,默认为2000ms mLocationOption.setInterval(2000); //给定位客户端对象设置定位参数 mLocationClient.setLocationOption(mLocationOption); //启动定位 mLocationClient.startLocation(); } ...

2016年12月18日 · 4 分钟 · 天边的星星

高德地图,定位 ,中间固定点拖动获取位置

import android.graphics.Color; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.ViewTreeObserver; import android.view.animation.LinearInterpolator; import android.widget.TextView; import android.widget.Toast; import com.amap.api.location.AMapLocation; import com.amap.api.location.AMapLocationClient; import com.amap.api.location.AMapLocationClientOption; import com.amap.api.location.AMapLocationListener; import com.amap.api.maps.AMap; import com.amap.api.maps.CameraUpdateFactory; import com.amap.api.maps.LocationSource; import com.amap.api.maps.MapView; import com.amap.api.maps.UiSettings; import com.amap.api.maps.model.CameraPosition; import com.amap.api.maps.model.LatLng; import com.amap.api.maps.model.Marker; import com.amap.api.maps.model.MarkerOptions; import com.amap.api.maps.model.animation.Animation; import com.amap.api.maps.model.animation.RotateAnimation; import com.amap.api.services.core.LatLonPoint; import com.amap.api.services.geocoder.GeocodeResult; import com.amap.api.services.geocoder.GeocodeSearch; import com.amap.api.services.geocoder.RegeocodeQuery; import com.amap.api.services.geocoder.RegeocodeResult; import com.tlh.gczp.R; import com.tlh.gczp.mvp.view.BaseUIActivity; import butterknife.BindView; import butterknife.ButterKnife; /** * 地图选点 */ public class AMapSelectPointActivity extends BaseUIActivity implements LocationSource { public static String TITLE_TAG = "title_str";//标题key public static String RESULT_TAG = "result_str";//返回数据key String titleStr = "地图";//标题 @BindView(R.id.activity_amapselectpoint_map) MapView mMapView; @BindView(R.id.activity_amapselectpoint_text) TextView addressTxtView;//位置 AMap aMap;//地图 private UiSettings mUiSettings;//定义一个UiSettings对象 //声明AMapLocationClient类对象 public AMapLocationClient mLocationClient = null; //声明定位回调监听器 public AMapLocationListener mLocationListener; //声明AMapLocationClientOption对象 public AMapLocationClientOption mLocationOption = null; OnLocationChangedListener listener; MarkerOptions markerCenter = new MarkerOptions();//中心点 Marker marker;//中间 GeocodeSearch geocodeSearch;//地理位置查询 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentViewItem(R.layout.activity_amapselectpont); ButterKnife.bind(this); //在activity执行onCreate时执行mMapView.onCreate(savedInstanceState),实现地图生命周期管理 mMapView.onCreate(savedInstanceState); rightBtn.setTextColor(Color.parseColor("#fcc900")); initData(); showPage(); } /** * 实例化数据 */ private void initData() { initMap(); titleStr = getIntent().getStringExtra(TITLE_TAG); if (TextUtils.isEmpty(titleStr)){ titleStr = "地图"; } setPageName(titleStr); currentPageName = titleStr; setRightTxt(getString(R.string.str_common_finish), new View.OnClickListener() { @Override public void onClick(View view) { searchAddressByLat(marker.getPosition()); } }); } private void initMap() {//实例化Map geocodeSearch = new GeocodeSearch(this); //初始化地图变量 if (aMap == null) { aMap = mMapView.getMap(); } aMap.setMapType(AMap.MAP_TYPE_NORMAL); mUiSettings = aMap.getUiSettings();//实例化UiSettings类 mUiSettings.setZoomControlsEnabled(true); //定位按钮 aMap.setLocationSource(this);// 设置定位监听 mUiSettings.setMyLocationButtonEnabled(true); // 显示默认的定位按钮 aMap.setMyLocationEnabled(true);// 可触发定位并显示定位层 mUiSettings.setScaleControlsEnabled(true);//显示比例尺控件 mUiSettings.setAllGesturesEnabled(true); mUiSettings.setCompassEnabled(true);//指南针 // LatLng latLng = new LatLng(39.906901, 116.397972); // final Marker marker = aMap.addMarker(new MarkerOptions(). // position(latLng). // title("北京"). // snippet("DefaultMarker")); // final Marker marker = aMap.addMarker(new MarkerOptions()); // MarkerOptions markeroptions = new MarkerOptions(); // markeroptions.position(latLng); // markeroptions.title("当前位置"); // markeroptions.visible(true); // BitmapDescriptor bitmapDescriptor= BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(),R.mipmap.positioning_normal)); // markeroptions.icon(bitmapDescriptor); // aMap.addMarker(markeroptions); mMapView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Log.e("mMapView","onGlobalLayout===---123"); marker = aMap.addMarker(new MarkerOptions()); Animation animation = new RotateAnimation(marker.getRotateAngle(), marker.getRotateAngle() + 720, 0, 0, 0); long duration = 1000L; animation.setDuration(duration); animation.setInterpolator(new LinearInterpolator()); marker.setAnimation(animation); marker.startAnimation(); marker.setPositionByPixels(mMapView.getWidth()/2, mMapView.getHeight()/2); } }); LatLng ll = new LatLng(34.6006623972045,108.97923588752748); markerCenter.position(ll); markerCenter.visible(true); markerCenter.title("中心点"); // BitmapDescriptor bitmapDescriptor= BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(),R.mipmap.icon_nearby)); // markerCenter.icon(bitmapDescriptor); aMap.addMarker(markerCenter); //初始化AMapLocationClientOption对象 mLocationOption = new AMapLocationClientOption(); //设置定位模式为AMapLocationMode.Hight_Accuracy,高精度模式。 // mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving); mLocationListener = new AMapLocationListener() { @Override public void onLocationChanged(AMapLocation aMapLocation) { if (aMapLocation != null) { if (listener != null) { listener.onLocationChanged(aMapLocation); } if (aMapLocation.getErrorCode() == 0) { //可在其中解析amapLocation获取相应内容。 Log.e("AMapSelectPointActivity", "aMapLocation=" + aMapLocation.getCity()); Log.e("AMapSelectPointActivity", "aMapLocation address=" + aMapLocation.getAddress()); } else { //定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。 Log.e("AmapError", "location Error, ErrCode:" + aMapLocation.getErrorCode() + ", errInfo:" + aMapLocation.getErrorInfo()); } } Log.e("AMapSelectPointActivity", "aMapLocation run onLocationChanged"); } }; //初始化定位 mLocationClient = new AMapLocationClient(getApplicationContext()); //设置定位回调监听 mLocationClient.setLocationListener(mLocationListener); mLocationClient.setLocationOption(mLocationOption);//设置模式 aMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition cameraPosition) { LatLng target = cameraPosition.target; System.out.println(target.latitude + "jinjin------" + target.longitude); } @Override public void onCameraChangeFinish(CameraPosition cameraPosition) { LatLng target = cameraPosition.target; System.out.println("changeFinish="+target.latitude + "jinjin------" + target.longitude); LatLng ll = new LatLng(target.latitude,target.longitude); markerCenter.position(ll); searchAddressByLat(ll); // markerCenter.visible(true); // markerCenter.title("中心点"); // BitmapDescriptor bitmapDescriptor= BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(),R.mipmap.icon_nearby)); // markerCenter.icon(bitmapDescriptor); // aMap.addMarker(markerCenter); } }); } @Override protected void onDestroy() { super.onDestroy(); //在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理 mMapView.onDestroy(); mLocationClient.onDestroy(); } @Override protected void onResume() { super.onResume(); //在activity执行onResume时执行mMapView.onResume (),实现地图生命周期管理 mMapView.onResume(); //启动定位 mLocationClient.startLocation(); } @Override protected void onPause() { super.onPause(); //在activity执行onPause时执行mMapView.onPause (),实现地图生命周期管理 mMapView.onPause(); mLocationClient.stopLocation(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState),实现地图生命周期管理 mMapView.onSaveInstanceState(outState); } @Override public void activate(OnLocationChangedListener onLocationChangedListener) { Log.e("AMapSelectPointActivity", "activate is run"); listener = onLocationChangedListener; } @Override public void deactivate() {//高德地图位置监听 listener = null; } private void searchAddressByLat(final LatLng latLng){ geocodeSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() { @Override public void onRegeocodeSearched(RegeocodeResult result, int rCode) { if (rCode == 1000) { if (result != null && result.getRegeocodeAddress() != null && result.getRegeocodeAddress().getFormatAddress() != null) { String addressName = result.getRegeocodeAddress().getFormatAddress() + "附近"; aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15)); addressTxtView.setText(result.getRegeocodeAddress().getFormatAddress()); Toast.makeText(AMapSelectPointActivity.this, addressName,Toast.LENGTH_LONG).show(); } else { Toast.makeText(AMapSelectPointActivity.this, "未找到",Toast.LENGTH_LONG).show(); } } else { Toast.makeText(AMapSelectPointActivity.this, "失败",Toast.LENGTH_LONG).show(); } } @Override public void onGeocodeSearched(GeocodeResult geocodeResult, int i) { } }); LatLonPoint point = new LatLonPoint(latLng.latitude,latLng.longitude); RegeocodeQuery query = new RegeocodeQuery(point, 200,GeocodeSearch.AMAP); geocodeSearch.getFromLocationAsyn(query); } }

2016年12月15日 · 3 分钟 · 天边的星星

在Android Studio中有六种依赖

Compile,Provided,APK,Test compile,Debug compile,Release compile Compile compile是对所有的build type以及favlors都会参与编译并且打包到最终的apk文件中。 Provided Provided是对所有的build type以及favlors只在编译时使用,类似eclipse中的external-libs,只参与编译,不打包到最终apk。 APK 只会打包到apk文件中,而不参与编译,所以不能再代码中直接调用jar中的类或方法,否则在编译时会报错 Test compile Test compile 仅仅是针对单元测试代码的编译编译以及最终打包测试apk时有效,而对正常的debug或者release apk包不起作用。 Debug compile Debug compile 仅仅针对debug模式的编译和最终的debug apk打包。 Release compile Release compile 仅仅针对Release 模式的编译和最终的Release apk打包。 转自:http://www.cnblogs.com/kangyi/p/4449857.html [AndroidStudio中多个Module依赖同一个jar的解决方案](http://blog.csdn.net/u013134391/article/details/51538511) **方案****:** 将任意一个Module中的jar依赖为compile files(‘your jar name’),其他需要依赖的地方改为provided files(‘your jar name’)并且删除compile fileTree(include: [‘*.jar’], dir: ‘libs)。即可 下面详细介绍为什么这样做以及案例 **案例介绍** 如 环信Module和自己app的Module都要用到定位sdk **1、**在自己app的gradle中以compile引入如: compile files(‘libs/AMap_Location_V2.4.1_20160414.jar’) **2、**在环信的Module的gradle中以provided的方式引入如: provided files(‘libs/AMap_Location_V2.4.1_20160414.jar’) **3、**而且环信的gradle中不能存在compile fileTree(include: [‘*.jar’], dir: ‘libs’) ==========================分割线================================= AndroidStudio中Module相当于Eclispe中的Library,这里不做过多介绍 多个Module依赖同一个jar,直接把jar放入对应需要的Module会导致编译报类冲突 这里就要讲一讲AndroidStudio中的依赖的几种方式 compile compile是对所有的build type以及favlors都会参与编译并且打包到最终的apk文件中。 Provided Provided是对所有的build type以及favlors只在编译时使用,类似eclipse中的external-libs,只参与编译,不打包到最终apk。 APK 只会打包到apk文件中,而不参与编译,所以不能再代码中直接调用jar中的类或方法,否则在编译时会报错 Test compile Test compile 仅仅是针对单元[测试](http://lib.csdn.net/base/softwaretest)代码的编译编译以及最终打包测试apk时有效,而对正常的debug或者release apk包不起作用。 Debug compile Debug compile 仅仅针对debug模式的编译和最终的debug apk打包 Release compile Release compile 仅仅针对Release 模式的编译和最终的Release apk打包。 我们需要用的是Provided,这样在写代码的时候可以在Module中正常使用jar中的类,但是要有一个Module以compile的方式依赖这个jar,这样编译的时候只有一个jar编译进apk。 注:使用Provided必须删除compile fileTree(include: [‘*.jar’], dir: ‘libs’) 不然lib下的jar均按照compile方式引入到Module 搞定!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 转自:http://blog.csdn.net/u013134391/article/details/51538511

2016年12月8日 · 1 分钟 · 天边的星星

Android插件化开发之用DexClassLoader加载未安装的APK来实现app切换背景皮肤

第一步、先制做一个有我们需要的图片资源的APK 如下图,这里有个about_log.png,我们需要生成apk文件。 生成的apk文件如果你不到项目的文件夹里面去取apk,想通过命令放到手机里面去可以快速用下面命令 1)、在手机里面通过包名找到apk路径,一定不要忘记有 -f - adb shell pm list package -f | grep com.example.testclassloader 得到如下结果 - package:/data/app/com.example.testclassloader-2/<span class="attribute">base.apk</span>=<span class="attribute-value">com</span>.example.testclassloader 2)、把base.apk拉到本地然后改名字,命令如下 - adb shell pull /data/app/com.example.testclassloader-2/base.apk testClassLoader.apk 3)、把testClassLoader.apk放到手机里面去,命令如下 - adb shell push testClassLoader.apk /sdcard/ 4)、去手机文件管理器里面找看是否有testClassLoader.apk文件 ...

2016年11月23日 · 5 分钟 · 天边的星星

AS中Git与GitHub的使用入门

一直想把自己的写的开源小项目放到github中,这两天才花时间来学学Git。遇到些问题,百度了很多才解决。跟SVN一样,值得写一篇总结记录下,虽然上资源很多,但作为入门,自己遇到的写出来完全不一样。 一、 Git与GitHub的简单介绍 Git是一个开源的分布式版本控制工具。 GitHub是一个使用Git作为版本控制的项目托管平台,它是一个网站。 详细请参考:http://www.cnblogs.com/cocowool/archive/2012/02/17/2356125.html 二、 Git的安装 下载地址:https://git-scm.com/download/win 或 https://git-for-windows.github.io/ 安装时,全部默认选择即可。 三、 AS中配置Git与GitHub 1. Git的配置 在Settings设置中。 Path to Git executable: 【Git安装后的路径】 然后“Test”测试一下,成功才可以。 2. GitHub的配置 Host: github.com Login: 【你的github用户名】 Password: 【github登录密码】 填好后,也进行“Test”测试一下,同样成功才可以。 测试完后按确定,会提示你是否设置密码,看个人需求。 四、 上传代码到GitHub 1. 创建GitHub仓库 在Github上创建一个仓库: 创建好后,将是这个样子,里面包括一个.gitignore忽略配置文件和一个README.md git地址如下: 2. 创建Git本地仓库 选择工程 —— VCS —— …… 此时,VCS的5个图标显示出来了,且要提交的文件名都是暗红色 3. 把工程add添加到仓库 选择工程 —— 右键 —— Git —— Add Add后待提交的文件名是绿色 4. commit提交 CommitMessage:填入提交说明信息。主要用于说明你做了哪些修改。 按Commit提交即可。 注:我每次都无法提交,commit后,进度对话框走到一半就立马消失了。解决办法见下面常见问题的“无法commit”。 提交后的文件颜色是灰白色。修改过的文件时淡蓝色 5. push推送到GitHub Commit后会自动弹出Push推送窗口,点“Define remote”。 Name:默认origin URL:就是github的网页地址,上面已提供获取方法 ...

2016年11月22日 · 1 分钟 · 天边的星星

Android webview使用详解

打开网页时不调用系统浏览器, 而是在本WebView中显示: ![复制代码](http://common.cnblogs.com/images/copycode.gif) mWebView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); ![复制代码](http://common.cnblogs.com/images/copycode.gif) 通过java代码调用javascript ![复制代码](http://common.cnblogs.com/images/copycode.gif) WebSettings webSettings = mWebView .getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.addJavascriptInterface(new Object() { public void clickOnAndroid() { mHandler.post(new Runnable() { public void run() { webview.loadUrl("javascript:wave()"); } }); } }, "demo"); ![复制代码](http://common.cnblogs.com/images/copycode.gif) 按返回键时, 不退出程序而是返回上一浏览页面: ![复制代码](http://common.cnblogs.com/images/copycode.gif) public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { mWebView.goBack(); return true; } return super.onKeyDown(keyCode, event); } ![复制代码](http://common.cnblogs.com/images/copycode.gif) 打开页面时, 自适应屏幕: WebSettings webSettings = mWebView .getSettings(); webSettings.setUseWideViewPort(true);//设置此属性,可任意比例缩放 webSettings.setLoadWithOverviewMode(true); 便页面支持缩放: WebSettings webSettings = mWebView .getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); 6.如果webView中需要用户手动输入用户名、密码或其他,则webview必须设置支持获取手势焦点。 ...

2016年11月21日 · 5 分钟 · 天边的星星

Android23以上动态鉴权实现的方法及思路

直接上代码了,主要使用到onRequestPermissionsResult、requestPermissions和checkSelfPermission 方法 @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case REQUEST_CODE_ASK_PERMISSIONS: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Permission Granted scanIntent(); } else { // Permission Denied Toast.makeText(getActivity(), “您拒绝了权限(请到设置中设置权限)”, Toast.LENGTH_SHORT) .show(); } break; case 300: test2(); break; default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); } } public void checkPermission() { if (Build.VERSION.SDK_INT >= 23) { // int write = getActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); // int read = getActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE); int write = ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.WRITE_EXTERNAL_STORAGE); int read = ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.READ_EXTERNAL_STORAGE); if (write != PackageManager.PERMISSION_GRANTED || read != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 300); } else { test2(); } } else { test2(); } } ...

2016年11月18日 · 1 分钟 · 天边的星星

在html页面中判断本地app是否安装并打开

html中其实是无法判断应用是否安装,除非在webview中通过js bridge,这里通过一种方式达到此目的。 1、编辑AndroidManifest.xml: 主要是增加第二个,myapp用来标识schema,最好能保证手机系统唯一,那样就可以打开应用,而不是弹出一个选择框。 Android:pathPrefix标识url的path,可以附带自己的数据通过string传递到activity,比如完整url为 myapp://xxx/openwith?data=mydata **[html]** [view plain](http://blog.csdn.net/vinrex/article/details/38082759#) [copy](http://blog.csdn.net/vinrex/article/details/38082759#) <div> <embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash" width="18" height="18" align="middle" name="ZeroClipboardMovie_1" data-mce-fragment="1"> </embed> </div> </div> - <span class="tag"><</span><span class="tag-name">activity</span> - <span class="attribute">android:name</span>=<span class="attribute-value">&#8220;com.abc.MainActivity&#8221;</span> - <span class="attribute">android:configChanges</span>=<span class="attribute-value">&#8220;orientation|keyboardHidden|navigation|screenSize&#8221;</span> - <span class="attribute">android:screenOrientation</span>=<span class="attribute-value">&#8220;landscape&#8221;</span> - <span class="attribute">android:theme</span>=<span class="attribute-value">&#8220;@android:style/Theme.NoTitleBar.Fullscreen&#8221;</span> <span class="tag">></span> - <span class="tag"><</span><span class="tag-name">intent-filter</span><span class="tag">></span> - <span class="tag"><</span><span class="tag-name">action</span> <span class="attribute">android:name</span>=<span class="attribute-value">&#8220;android.intent.action.MAIN&#8221;</span> <span class="tag">/></span> - <span class="tag"><</span><span class="tag-name">category</span> <span class="attribute">android:name</span>=<span class="attribute-value">&#8220;android.intent.category.LAUNCHER&#8221;</span> <span class="tag">/></span> - <span class="tag"></</span><span class="tag-name">intent-filter</span><span class="tag">></span> - <span class="tag"><</span><span class="tag-name">intent-filter</span><span class="tag">></span> - <span class="tag"><</span><span class="tag-name">action</span> <span class="attribute">android:name</span>=<span class="attribute-value">&#8220;android.intent.action.VIEW&#8221;</span> <span class="tag">/></span> - <span class="tag"><</span><span class="tag-name">category</span> <span class="attribute">android:name</span>=<span class="attribute-value">&#8220;android.intent.category.BROWSABLE&#8221;</span> <span class="tag">/></span> - <span class="tag"><</span><span class="tag-name">category</span> <span class="attribute">android:name</span>=<span class="attribute-value">&#8220;android.intent.category.DEFAULT&#8221;</span><span class="tag">/></span> - <span class="tag"><</span><span class="tag-name">data</span> <span class="attribute">android:scheme</span>=<span class="attribute-value">&#8220;myapp&#8221;</span> <span class="attribute">android:pathPrefix</span>=<span class="attribute-value">&#8220;/xxx/openwith&#8221;</span> <span class="tag">/></span> - <span class="tag"></</span><span class="tag-name">intent-filter</span><span class="tag">></span> - t;/activity<span class="tag">></span> 然后通过activity获得data数据: ...

2016年11月15日 · 1 分钟 · 天边的星星

Android获取点击的图片的颜色

获取图片中点击的颜色 import android.os.Bundle; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Matrix; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.TextView; public class MainActivity extends Activity { TextView touchedXY, invertedXY, imgSize, colorRGB; ImageView imgSource1, imgSource2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); touchedXY = (TextView)findViewById(R.id.xy); invertedXY = (TextView)findViewById(R.id.invertedxy); imgSize = (TextView)findViewById(R.id.size); colorRGB = (TextView)findViewById(R.id.colorrgb); imgSource1 = (ImageView)findViewById(R.id.source1); imgSource2 = (ImageView)findViewById(R.id.source2); imgSource1.setOnTouchListener(imgSourceOnTouchListener); imgSource2.setOnTouchListener(imgSourceOnTouchListener); } OnTouchListener imgSourceOnTouchListener = new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { float eventX = event.getX(); float eventY = event.getY(); float[] eventXY = new float[] {eventX, eventY}; Matrix invertMatrix = new Matrix(); ((ImageView)view).getImageMatrix().invert(invertMatrix); invertMatrix.mapPoints(eventXY); int x = Integer.valueOf((int)eventXY[0]); int y = Integer.valueOf((int)eventXY[1]); touchedXY.setText( “touched position: ” + String.valueOf(eventX) + ” / ” + String.valueOf(eventY)); invertedXY.setText(“touched position: ” + String.valueOf(x) + ” / ” + String.valueOf(y)); Drawable imgDrawable = ((ImageView)view).getDrawable(); Bitmap bitmap = ((BitmapDrawable)imgDrawable).getBitmap(); imgSize.setText(“drawable size: “+ String.valueOf(bitmap.getWidth()) + ” / “+ String.valueOf(bitmap.getHeight())); //Limit x, y range within bitmap if(x < 0){x = 0; } else if(x > bitmap.getWidth()-1) { x = bitmap.getWidth()-1; } if(y < 0){ y = 0; }else if(y > bitmap.getHeight()-1) { y = bitmap.getHeight()-1; } int touchedRGB = bitmap.getPixel(x, y); colorRGB.setText(“touched color: ” + “#” + Integer.toHexString(touchedRGB)); colorRGB.setTextColor(touchedRGB); return true; ...

2016年11月13日 · 2 分钟 · 天边的星星