Android Tips Round-Up

Ubuntu无桥接模式或连不上网(详细解决方法 目录 问题1:Ubuntu没有未桥接的主机网络适配器 解决方法 1.打开VMware安装目录下的文件 ​编辑2.右键安装以上三个文件 3.打开网络状态属性,找到VMware bridgeProtocol,点击安装 问题2.Ubuntu桥接模式连不上网 1.win+r打开cmd终端,输入ipconfig /all 2.记录以下数据 3.打开VMware网络设置 问题1:Ubuntu没有未桥接的主机网络适配器 VMWare安装之后,虚拟网络一直使用默认配置 VMnet0为... 阅读详情

转自:http://blog.danlew.net/2014/03/30/android-tips-round-up-part-1/


With my recent project I've been posting one Android class/method a day. People have been asking for an archive of these links, so every couple weeks I'm going to round them up here. I'll also be adding a bit of color commentary, but still the goal is for this not to be a ton of work for me. :)

Part 1 

Activity.startActivities() - Nice for launching to the middle of an app flow.

TextUtils.isEmpty() - Simple utility I use everywhere.

Html.fromHtml() - Quick method for formatting Html. It's not particularly fast so I wouldn't use it constantly (e.g., don't use it just to bold part of a string -construct the Spannable manually instead), but it's fine for rendering text obtained from the web.

TextView.setError() - Nice UI when validating user input.

Build.VERSION_CODES - Not only is it handy for routing code, it's also summarizes behavioral differences between each version of Android.

Log.getStackTraceString() - Convenience utility for logging.

LayoutInflater.from() - Wraps the long-winded getSystemService() call in a simple utility.

ViewConfiguration.getScaledTouchSlop() - Using the values provided in ViewConfiguration ensures all touch interaction feels consistent across the OS.

PhoneNumberUtils.convertKeypadLettersToDigits - Makes handling phone number data a snap, as some companies provide them as letters.

Context.getCacheDir() - Use the cache dir for caching data. Simple enough but some don't know it exists.

ArgbEvaluator - Transition from one color to another. As was pointed out by Chris Banes, this class creates a lot of autoboxing churn so it'd be better to just rip out the logic and run it yourself.

ContextThemeWrapper - Nice class for changing the theme of a Context on the fly.

Space - Lightweight View which skips drawing. Great for any situation that might require a placeholder.

ValueAnimator.reverse() - I love this for canceling animations smoothly.


Part 2 

DateUtils.formatDateTime() - One-stop shop for localized date/time strings.

AlarmManager.setInexactRepeating - Saves on battery life by grouping multiple alarms together. Even if you're only calling a single alarm this is better (just make sure to call AlarmManager.cancel() when done).

Formatter.formatFileSize() - A localized file size formatter.

ActionBar.hide()/.show() - Animates the action bar hiding/showing. Lets you switch to full-screen gracefully.

Linkify.addLinks() - If you need to control how links are added to text.

StaticLayout - Useful for measuring text that you're about to render into a custom View.

Activity.onBackPressed() - Easy way to manage the back button. While I wouldn't normally hijack back, sometimes it's necessary to make a flow work.

GestureDetector - Listens to motion events and fires listener events for common actions (like clicks, scrolls and flings). So much easier than implementing your own motion event system.

DrawFilter - Lets you manipulate a Canvas even if you're not calling the draw commands. For example, you could create a custom View which sets a DrawFilter which anti-aliases the draws of the parent View.

ActivityManager.getMemoryClass() - Gives you an idea of how much memory the device has. Great for figuring out how large to make your caches.

SystemClock.sleep() - Convenience method which guarantees sleeping the amount of time entered. I use it for debugging and simulating network delays.

ViewStub - A View that initially does nothing, but can later inflate a layout. This is a great placeholder for lazy-loading Views. Its only drawback is that it doesn't support <merge> tags, so it can create unnecessary nesting in the hierarchy if you're not careful.

DisplayMetrics.density - You can get the density of the screen this way. Most of the time you'll be better off letting the system scale dimensions automatically, but occasionally it's useful to have more control (especially with custom Views).

Pair.create() - Handy class, handy creator method.


Part 3 

UrlQuerySanitizer - Sanitize URLs with this handy utility.

Fragment.setArguments - Since you can't use a Fragment constructor w/ parameters this is the second best thing. Arguments set before creation last throughout the entire Fragment's lifecycle (even if it's destroyed/recreated due to a configuration change).

DialogFragment.setShowsDialog() - Neat trick - DialogFragments can act like normal Fragments! That way you can have the same Fragment do double-duty. I usually create a third View generation method that both onCreateView()and onCreateDialog() call into when creating a dual-purpose Fragment.

FragmentManager.enableDebugLogging() - Help when you need it when figuring out Fragments.

LocalBroadcastManager - Safer than global broadcasts. Simple and quick. Event buses like otto may make more sense for your use case though.

PhoneNumberUtils.formatNumber() - Let someone else figure out this problem for you.

Region.op() - I found this useful for comparing two generic areas before rendering. If I've got two Paths, do they overlap? I can figure that out with this method.

Application.registerActivityLifecycleCallbacks - Though lacking documentation I feel this is self-evident. Just a handy tool.

versionNameSuffix - This gradle setting lets you modify the versionName field in your manifest based on different build types. For example, I would setup my debug build type to end in "-SNAPSHOT"; that way you can easily tell if you're on a debug build or release build.

CursorJoiner - If you're using a single database then a join in SQL is the natural solution, but what if you've received data from two separate ContentProviders? In that case CursorJoiner can be helpful.

Genymotion - A much faster Android emulator. I use it all day.

-nodpi - Most qualifiers (-mdpi, -hdpi, -xhdpi, etc.) automatically scale assets/dimensions if you're on a device that isn't explicitly defined. Sometimes you just want something consistent though; in that case use -nodpi.

BroadcastRecevier.setDebugUnregister() - Another handy debugging tool.

Activity.recreate() - Forces an Activity to recreate itself for whatever reason.

PackageManager.checkSignatures() - You can use this to find out if two apps (presumably your own) are installed at the same time. Without checking signatures someone could imitate your app easily by just using the same package name.


Part 4 

Activity.isChangingConfigurations() - Often times you don't need to do quite as much saving of state if all that's happening is the configuration is changing.

SearchRecentSuggestionsProvider - A quick and easy way to create a recents suggestion provider.

ViewTreeObserver - This is an amazing utility; it can be grabbed from any View and used to monitor the state of the View hierarchy. My most often use for it is to determine when Views have been measured (usually for animation purposes).

org.gradle.daemon=true - Helps reduce the startup time of of Gradle builds. Only really applies to command-line builds as Android Studio already tries to use the daemon.

DatabaseUtils - A variety of useful tools for database operations.

android:weightSum (LinearLayout) - Want to use layout weights, but don't want them to fill the entire LinearLayout? That's what weightSum can do by defining the total weight.

android:duplicateParentState (View) - Makes the child duplicate the state of the parent - for example, if you've got a ViewGroup that is clickable, then you can use this to make its children change state when it is clicked.

android:clipChildren (ViewGroup) - If disabled, this lets the children of a ViewGroup draw outside their parent's bounds. Great for animations.

android:fillViewport (ScrollView) - Best explained in this post, this helps solve a problem with ScrollViews that may not always have enough content to actually fill the height of the screen.

android:tileMode (BitmapDrawable) - Lets you create repeated patterns with images.

android:enterFadeDuration/android:exitFadeDuration (Drawables) - For Drawables that have multiple states, this lets you define a fade before/after the drawable shows.

android:scaleType (ImageView) - Defines how to scale/crop a drawable within an ImageView. "centerCrop" and "centerInside" are regular settings for me.

<merge> - Lets you include a layout in another without creating a duplicate ViewGroup (more info). Also good for custom ViewGroups; you can inflate a layout with <merge> inside the constructor to define its children automatically.

AtomicFile - Manipulates a file atomically by using a backup file. I've written this myself before, it's good to have an official (and better-written) version of it.



Part 5

ViewDragHelper - Dragging Views is a complex problem and this class helps a lot. If you want an example, DrawerLayout uses it for swiping. Flavient Laurent also wrote an excellent article about it.

PopupWindow - Used all around Android without you even realizing it (action bars, autocomplete, edittext errors), this class is the primary method for creating floating content.

ActionBar.getThemedContext() - ActionBar theming is surprisingly complex (and can be different from the theming of the rest of the Activity). This gets you a Context so if you create your own Views they will be properly themed.

ThumbnailUtils - Helps create thumbnails; in general I'd just use whatever image library was already in place (e.g. Picasso or Volley), but it can also create video thumbnails!

Context.getExternalFilesDir() - While you do have permission to write anywhere on the SD card if you ask for it, it's much more polite to write your data in the correct designated folder. That way it gets cleaned up and users get a common experience. Additionally, as of Kit Kat you can write to this folder without permission, and each user has their own external files dir.

SparseArray - A more efficient version of Map<Integer, Object>. Be sure to check out sister classes SparseBooleanArray, SparseIntArray and SparseLongArray as well.

PackageManager.setComponentEnabledSetting() - Lets you enable/disable components in your app's manifest. What's nice here is being able to shut off unnecessary functionality - for example, a BroadcastReceiver that is unnecessary due to the current app configuration.

SQLiteDatabase.yieldIfContendedSafely() - Lets you temporarily stop a db transaction so you don't tie up too much of the system.

Environment.getExternalStoragePublicDirectory() - Again, users like a consistent experience with their SD card; using this method will grab the correct directory for placing typed files (music, pictures, etc.) on their drive.

View.generateViewId() - Every once in a while I've wanted to dynamically generate view IDs. The problem is ensuring you aren't clobbering existing IDs (or other generated ones).

ActivityManager.clearApplicationUserData() - A reset button for your app. Perhaps the easiest way to log out a user, ever.

Context.createConfigurationContext() - Customize your configuration context. Common problem I've run into: forcing part of an app to render in a particular locale (not that I normally condone this sort of behavior, but you never know). This would make it a lot easier to do so.

ActivityOptions - Nice custom animations when moving between Activities. ActivityOptionsCompat is good for backwards compatible functionality.

AdapterViewFlipper.fyiWillBeAdvancedByHostKThx() - Because it's funny and for no other reason. There are other amusing tidbits in AOSP (like GRAVITY_DEATH_STAR_I) but unlike those this one is actually useful.

ViewParent.requestDisallowInterceptTouchEvent() - The Android touch event system defaults handle what you want most of the time, but sometimes you need this method to wrest event control from parents. (By the way, if you want to know about the touch system, this talk is amazing.)


真正的工业级环形缓冲区(Circular Buffer)完整实现细节 永远不要永远不要ToArray()或AddRange()永远返回或两段Span永远用_head_tail% Capacity实现环形照着上面这套代码改,你的系统将彻底告别内存爆炸,从“实验室玩具”变成“产线战神”!需要我给你一个支持两段绘制的完整实现吗? 阅读详情

相关推荐

自动驾驶IDM与MOBIL模型

IDM模型,自动驾驶

不想学好数学的汽车工程师不是一个好的程序员 1万+

Android中数值的精确计算

Android中数值计算的精度 Java中有一个类是BigDecimal,该类是专门计算一些要求精度很高的算法,常用于银行金融类的计算,BigDecimal一共有4个够造方法,我们不关心用BigInteger来够造的那两个,那么还有两个, 它们是: BigDecimal(double val) Translates a double into a BigDecimal. BigDecimal(String val) Translates the String r

qq_42795723的博客 587

使用Xpath语法爬取豆瓣读书Top250

使用Xpath语法爬取豆瓣读书Top250 使用的软件是Spyder 网页地址:https://book.douban.com/top250?start=0 直接上代码: # -*- coding: utf-8 -*- """ Created on Thu Apr 30 18:35:17 2020 @author: ASUS """ import requests import csv fr...

weixin_43987253的博客 2086

android四则运算,Android 金钱计算 BigDecimal 的加减乘除计算

前言 :今天正好做了一个购物车的功能 ,涉及到了金钱的计算,当金钱计算时直接使用double,会损失精度,需要使用BigDecimal 来进行价格的计算。关于Bigdecimal,这里整理一下方便以后学习,也希望能帮助到其他人。BigDecimal的初始化初始化时有两种形式:第一种value,直接写int、double、long之类的数字,第二种写String,在这里推荐使用第二种。BigDeci...

weixin_28932441的博客 805

建行报专版报道建设银行金融科技发展历程

经过十多年的建设,总行前中后台部门都有了自己的业务系统,但系统“部门”特征显著,渠道、客户、产品的横向整合不足,产品系统层次化、结构化、参数化程度不高,渠道支持产品快速部署以及跨渠道服务能力不足,管理分析类系统建设相对滞后,系统较弱的可扩展能力在应对高速增长的交易量时已疲态尽显,同时安全稳定运行的压力和风险日益积聚。站在新的历史起点上,科技条线将聚焦主责主业,完善信息科技管理体系,紧紧围绕安全生产中心任务,持续推动技术能力复用共享和自主可控,为全行做好金融五篇大文章,推动业务高质量发展提供技术支撑。

银行信息系统应用架构详解 397

7、农业市场价格预测与K-Means聚类算法的综合研究

本文综合研究了农业市场价格预测与K-Means聚类算法的原理、应用及拓展。在农业领域,基于历史数据和供应信息的价格预测模型可为农民、政府和金融机构提供决策支持;在数据处理领域,K-Means算法通过合理选择初始质心和距离度量方法,实现高效聚类分析。文章还探讨了两种技术面临的挑战与解决方案,并展望了其在大数据、人工智能融合背景下的未来发展趋势,展示了跨领域技术协同的应用潜力。

ujm56789012的博客 76

Android Tips Round-Up by Dan Lew

1 round up Activity.startActivities() - Nice for launching to the middle of an app flow. TextUtils.isEmpty() - Simple utility I use everywhere. Html.fromHtml() - Quick method for formatting Htm

Pizza_Lawson的专栏 1049

基于RK3588与昇腾310B的异构K8s集群部署与NPU统一调度实战

本文介绍了基于RK3588与昇腾310B的异构K8s集群部署方案,通过HAMi+Volcano实现NPU统一调度。方案包含硬件配置、操作系统准备(银河麒麟/欧拉)、容器运行时部署及K8s集群搭建等关键步骤,支持多厂商NPU设备的统一抽象和精细化切分,为边缘AI计算提供高效资源管理能力。

huanghm88的专栏 285

Android double保留两位小数:截取 和 四舍五入

方式一: BigDecimal.setScale()方法用于格式化小数点 setScale(2);//表示保留2位小数,默认用四舍五入方式  setScale(2,BigDecimal.ROUND_DOWN);//直接删除多余的小数位  11.116约=11.11 setScale(2,BigDecimal.ROUND_UP);//临近位非零,则直接进位;临近位为零,不进位。11.11

Android移动开发者的专栏 4万+

车载 ECU 中的 Safety Linux 详解

车载 ECU 中的 Safety Linux 详解

天赐好车的博客 324

华为OD机考双机位C卷 - 构成正方形的数量 (Java & Python& JS & C/C++ & GO )

华为OD机考双机位C卷 - 成正方形的数量 (OD上机考试双机位C卷)。提供在线OJ刷题。Java、C++、Python、GO语言、C语言、JavaScript题解,并提供完整思路讲解。

算法大师! 5948

java BigDecimal.ROUND_UP和BigDecimal.ROUND_DOWN的用处

今天在工作中遇到了这样的一个需求, 一个小数,例如1.7777777,或者1.3333333,不管后面的位数是多少,只保留到小数点后第二位,但是不是四舍五入,1.7777777处理后就是1.77,1.3333333处理后就是1.33 这个就要用到BigDecimal#setScale的方法了。 具体看如下代码: ?View Code JAVA

2万+

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Android Tips Round-Up, Part 5

转自:http://blog.danlew.net/2014/05/28/android-tips-round-up-part-5/ Here's the final round-up of Android tips I've been posting. I've officially run out of things to post. If I ever come across somet

lxgwm2008的专栏 733

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Android Tips Round-Up, Part 3

转自:http://blog.danlew.net/2014/04/28/android-tips-round-up-part-3/ Here's the third round-up of Android tips I've been posting. More: Part 1 | Part 2 | Part 3 | Part 4 | Part 5 UrlQuerySaniti

lxgwm2008的专栏 782

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Android Tips Round-Up, Part 4

转自:http://blog.danlew.net/2014/05/12/android-tips-round-up-part-4/ Here's the fourth round-up of Android tips I've been posting. More: Part 1 | Part 2 | Part 3 | Part 4 | Part 5 Activity.isChangi

lxgwm2008的专栏 746

智能手表游戏开发实战:从《茶叶蛋大冒险》移植看强约束环境下的应用开发

在嵌入式系统与移动开发领域,资源受限环境下的应用开发是一个经典挑战。其核心原理在于如何在有限的计算能力、内存和电池续航条件下,通过架构设计、算法优化和交互重构,实现功能与性能的平衡。这一技术价值不仅体现在能拓展设备应用边界,更在于为物联网、边缘计算等场景提供了可复用的工程范式。典型的应用场景包括智能穿戴设备、工业控制终端和嵌入式娱乐系统。本文以《茶叶蛋大冒险》游戏向智能手表的移植为例,深入探讨了在**性能优化**和**交互适配**双重约束下的开发实践,展示了如何通过游戏引擎选型、输入重映射和渲染优化,在方寸

weixin_33895657的博客 352

【Linux公有云网站配置实战|企业网络管理课程溯源、完整实训、例题解析与故障排错】

文末整理配套学习网站、网课、专业书籍。早期网络依靠人工经验维护,没有标准化流程、统一配置规范,网络故障频繁,于是各大高校开设企业网络管理相关课程,目的是培养能够维护企业内网、服务器、对外业务网站的专业运维人员。本次实训基于公有云服务器,以Linux操作系统为基础,完整完成云服务器初始化、远程连接、Web服务安装、网站源码部署、防火墙与云安全组放行,最终实现公网用户通过IP访问企业网站。Linux系统凭借稳定、开源、免费的优势成为企业服务器首选,课程新增Linux命令、用户管理、服务部署、防火墙配置内容。

2501_92125808的博客 360

BigDecimal加减乘除运算、相关注意事项以及其他内容

一 加减乘除 加法:BigDecimal.add(BigDecimal); 减法:BigDecimal.subtract(BigDecimal); 乘法:BigDecimal.multiply(BigDecimal); 除法:BigDecimal.divide(BigDecimal); 绝对值:BigDecimal.abs(); 注意事项:BigDecimal做运算返回的是新BigDecimal对...

想到哪记到哪 4061

android 保留两位小数

BigDecimal bd = new BigDecimal(all + ""); bd = bd.setScale(2,BigDecimal.ROUND_HALF_UP);

代码界的萌新 2439

DoTween转换场景后不执行(Scene reloading stops tweening functionality)

// TODO Without Clear it won't work. DOTween.Clear(true); // TODO Reload current scene SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); https://github.com/Demigiant/dotw...

lvcoc的博客 1136

Android Studio提示模拟器错误:Could not initialize OpenglES emulation, use '-gpu off' to disable it.

安装之后,打开模拟器遇到以下错误提示 :并且有一些对应的文字提醒,上网搜索了很久,有各种各样的问题,但都不是同一个问题,有的还把英文搞反的。       在冷静下来之后,把每一个比较关键的错误提醒都拿去百度一下,用Could not initialize OpenglES emulation, use '-gpu off' to disable it. 终于发现了一个比较有用的博客,确实也是关于图...

I feel lost 8036

Android studio emulator warning----Emulator window was out of view and was recentred

1、如果skin的显示区域太大,键盘部分可能显示不全,给使用带来不便 模拟器还会报出警告: emulator window was out of view and was recentred 我们可以通过-scale ­­选项来解决这个问题,把auto 改为一个值.

tasty 687

android studio虚拟机启动报错

问题:android studio 虚拟机启动时遇到错误: emulator: ERROR: x86 emulation currently requires hardware acceleration!Please ensure Intel HAXM is properly installed and usable.CPU acceleration status: HAX kernel m

jianglei_love的专栏 4123

问题: Emulator: emulator: WARNING: System.cpp:1139: Ignoring invalid parameter detected in function: 0

问题: Emulator: emulator: WARNING: System.cpp:1139: Ignoring invalid parameter detected in function: 0-2020-4-5 解决 Tools->AVD Manager, selecting the device emulator I was working with and doing wipe ...

cloud 3955

Vertica常用操作总结

1.      修改列名称 alterTABLEnoas_app.DIM_TNES_CELL_RAT rename rat_name to CELL_RAT_NAME; 2.      Vertica导出自己测试 NOAS252:/tmp/vertica6.1.2# /opt/vertica/sbin/install_vertica -s NOAS252 -rvertica-6.1.2-0

DataFlow范式 2万+
上一篇: TextView预渲染研究
下一篇: Eclipse转Android Studio踩过的各种坑
ruyi366
博客等级 码龄15年 9粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值