首页 文章 精选 留言 我的

精选列表

搜索[android wear],共10000篇文章
优秀的个人博客,低调大师

android:http

使用org.apache.http //生成一个请求对象 HttpGet httpGet = new HttpGet("http://www.baidu.com"); //生成一个Http客户端对象 HttpClient httpClient = new DefaultHttpClient(); //使用Http客户端发送请求对象 InputStream inputStream = null; try { httpResponse = httpClient.execute(httpGet); httpEntity = httpResponse.getEntity(); inputStream = httpEntity.getContent(); //文件流操作 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String result = ""; String line = ""; // StringBuilder builder = new StringBuilder();while((line = reader.readLine()) != null){ result = result + line; // builder.append(s); } System.out.println(result); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try{ inputStream.close(); } catch(Exception e){ e.printStackTrace(); } } }/* JSONObject jsonObject = new JSONObject(builder.toString());String re_username = jsonObject.getString("username");String re_password = jsonObject.getString("password");int re_user_id = jsonObject.getInt("user_id"); */ GET和POST方式: GET:即在baseUrl后“ ?” “ &”加一些参数即可 POST方式: NameValuePair nameValuePair1 = new BasicNameValuePair("name",name); //name为读取的值 NameValuePair nameValuePair2 = new BasicNameValuePair("age",age); //age为读取的值 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(nameValuePair1); nameValuePairs.add(nameValuePair2); //生成Entity对象 HttpEntity requestHttpEntity = new UrlEncodedFormEntity(nameValuePairs); HttpPost httpPost = new HttpPost(url); //这里的url是baseUrl 不用拼上?key=value... httpPost.setEntity(requestHttpEntity ); //之后的操作一样 本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/archive/2012/05/18/2508400.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android 动画

1.闪烁动画 AlphaAnimation 1 2 3 4 5 6 7 8 9 privatevoid startFlickerAnimation(ImageView img) { final Animation animation = new AlphaAnimation(1f, 0)f; animation.setDuration(500); animation.setInterpolator( new LinearInterpolator()); // do not alter animation rate animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely animation.setRepeatMode(Animation.REVERSE); // img.setAnimation(animation); animation.start(); } 本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/p/3567661.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android -- DiskLruCache

DiskLruCache 创建一个磁盘缓存对象: public static DiskLruCache open(File directory, int appVersion, int valueCount, long maxSize); open()方法接收四个参数,第一个参数是数据的缓存文件地址,第二个参数是当前应用程序的版本号,第三个参数是同一个key可以对应多少个缓存文件,一般都是传1,第四个参数是最多可以缓存多少字节的数据。 //创建磁盘缓存文件,首选sdcard,如果sdcard没有挂载或者没有sdcard则获取应用默认的cache目录 public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use external cache dir // otherwise use internal cache dir final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); } 获取软件版本号 public int getAppVersion(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return 1; } Java DiskLruCache mDiskLruCache = null; try { File cacheDir = getDiskCacheDir(context, "thumbnails"); if (!cacheDir.exists()) { cacheDir.mkdirs(); } mDiskLruCache = DiskLruCache.open(cacheDir, getAppVersion(context), 1, 10 * 1024 * 1024); } catch (IOException e) { e.printStackTrace(); } 磁盘缓存 //添加缓存 public void addBitmapToCache(String key, Bitmap bitmap) { // Add to memory cache as before,把缓存放到内存缓存中 if (getBitmapFromMemCache(key) == null) { mMemoryCache.put(key, bitmap); } // Also add to disk cache,把缓存放入磁盘缓存 synchronized (mDiskCacheLock) { if (mDiskLruCache != null && mDiskLruCache.get(key) == null) { mDiskLruCache.put(key, bitmap); } } } //获取缓存 public Bitmap getBitmapFromDiskCache(String key) { synchronized (mDiskCacheLock) { // Wait while disk cache is started from background thread while (mDiskCacheStarting) { try { mDiskCacheLock.wait(); } catch (InterruptedException e) {} } if (mDiskLruCache != null) { return mDiskLruCache.get(key); } } return null; } 总结 以上是磁盘缓存的创建和使用方法。在实际操作中内存缓存和磁盘缓存是配合起来使用的,一般先从内存缓存中读取数据,如果没有再从磁盘缓存中读取。 本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/4660669.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android -- onAttachedToWindow()

onAttachedToWindow在Activity生命周期中的位置 放大招: onAttachedToWindow不能在onCreate中哟~ View view = getWindow().getDecorView(); WindowManager.LayoutParams lp = (WindowManager.LayoutParams)view.getLayoutParams(); lp.gravity = Gravity.CENTER; lp.width = (dm.widthPixels * 4) / 5; lp.height = (dm.widthPixels * 4) / 5; getWindowManager().updateViewLayout(view,lp); 放到onCreate中进行测试,结果在lp.gravity = Gravity.CENTER;这行报了空指针异常,所以view.getLayoutParams()获取的LayoutParams是空。 public final class ActivityThread { ...... final void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward) { ...... ActivityClientRecord r = performResumeActivity(token, clearHide); if (r != null) { final Activity a = r.activity; ...... // If the window hasn't yet been added to the window manager, // and this guy didn't finish itself or start another activity, // then go ahead and add the window. boolean willBeVisible = !a.mStartedActivity; if (!willBeVisible) { try { willBeVisible = ActivityManagerNative.getDefault().willActivityBeVisible( a.getActivityToken()); } catch (RemoteException e) { } } if (r.window == null && !a.mFinished && willBeVisible) { r.window = r.activity.getWindow(); View decor = r.window.getDecorView(); decor.setVisibility(View.INVISIBLE); ViewManager wm = a.getWindowManager(); WindowManager.LayoutParams l = r.window.getAttributes(); a.mDecor = decor; l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; ...... if (a.mVisibleFromClient) { a.mWindowAdded = true; wm.addView(decor, l); } } ...... } ...... } ...... } 原来在ActivityThread执行handleResumeActivity时就会为PhoneWindow(r.activity.getWindow)中的DecorView设置LayoutParam,并且通过源码发现handleResumeActivity函数首先会执行performResumeActivity,此时会调用Activity的onResume()生命周期函数,这时问题就比较清晰了,看来只要在Activity的onResume生命周期后就能获取DecorView的LayoutParam,进而可以设置高度和宽度了。根据上面贴出的生命周期图,onResume()后面是onAttachedToWindow(),并且onAttachedToWindow只会调用一次,不会受用户操作行为影响。所以在onAttachedToWindow中进行窗口尺寸的修改再合适不过了。 干货 onAttachedToWindow运行在onResume之后; DecorView的LayoutParams是在ActivityThread的handleResumeActivity中设置的,并且该函数会调用Activity的onResume生命周期,所以在onResume之后可以设置窗体尺寸; 我是天王盖地虎的分割线 本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/4471984.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android -- isInEditMode

解释 Indicates whether this View is currently in edit mode. A View is usually in edit mode when displayed within a developer tool. For instance, if this View is being drawn by a visual user interface builder, this method should return true. Subclasses should check the return value of this method to provide different behaviors if their normal behavior might interfere with the host environment. For instance: the class spawns a thread in its constructor, the drawing code relies on device-specific features, etc. This method is usually checked in the drawing code of custom widgets. 如果在自定义控件的构造函数或者其他绘制相关地方使用系统依赖的代码,会导致可视化编辑器无法报错并提示:Use View.isInEditMode() in your custom views to skip code when shown inEclipse code public class LockRelativeLayout extends RelativeLayout { private Handler mainHandler = null; //与主Activity通信的Handler对象 public LockRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs, 0); mContext = context; if (isInEditMode()) { return; } mainHandler = ((MainActivity)mContext).getMHandler(); } } 如果不加上if (isInEditMode()) { return; },标红处代码会导致可视化编辑报错 我是天王盖地虎的分割线 本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/4456722.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android -- DisplayMetrics

干货 DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels; screenHeight = dm.heightPixels; density = dm.density; densityDpi = dm.densityDpi; scaledDensity = dm.scaledDensity; DisplayMetrics metrics = dm; Log.i("yydcdut", "metrics::density=" + metrics.density +", densityDpi="+metrics.densityDpi +", heightPixels="+metrics.heightPixels +", widthPixels="+metrics.widthPixels +", scaledDensity="+metrics.scaledDensity +", xdpi="+metrics.xdpi +", ydpi="+metrics.ydpi); Log打印出来: metrics::density=1.5, densityDpi=240, heightPixels=854, widthPixels=480, scaledDensity=1.5, xdpi=239.05882, ydpi=243.72585 metrics.widthPixels 屏幕宽 metrics.heightPixels 屏幕高 metrics.density 屏幕密度 构造函数 DisplayMetrics 不需要传递任何参数;调用 getWindowManager() 之后,会取得 现有 Activity 的 Handle ,此时,getDefaultDisplay() 方法将取得的宽高维度存放于 DisplayMetrics 对象中,而取得的宽高维度是以像素为单位(Pixel) ,“像素”所指的是“绝对像素” 而非“相对像素”。 我是天王盖地虎的分割线 本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/4254599.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码