Git Product home page Git Product logo

android-service's Introduction

Android系统服务解析

网上很多源码分析都不是6.0的,虽然大致流程一样,但还是有些许不同,所以自己记录下来流程,也更好的理解Android.

FINISHED:

  • AlarmManagerService
  • 自启动管理

ONGOING:

  • 权限控制

TODO:

  • PowerManagerService
  • ActivityManagerService

TIPS:

  • 修改默认加密手机:修改fstab.in中的flag FLAG_FDE_TYPE /或修改device\mediatek\ [project]\ fstab.{ro.hardware} forceencrypt->encrypt

  • 自定义控件属性时: TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.TopBar); obtainStyledAttributes需要调用两个参数的函数,不然自定义属性不起作用

  • onDraw方法中调用画布canvastranslate方法将绘制的位置进行平移(+width为左,+height为下)

  • LinearGradient渐变器中

    public LinearGradient(
            float x0,//渐变器x起始线
            float y0,//渐变器y起始线
            float x1,//渐变器x终止线 x1-x0为渐变器宽度
            float y1,//渐变器y终止线 y1-y0为渐变器高度
            int color0,//靠近起始线颜色
            int color1,//靠近终止线颜色
            TileMode tile)//平铺形式 有CLAMP,REPEAT,MIRROR

    图像渲染(Shader)

  • 为控件添加触摸水波纹效果,在style中配置了material主题后在xml布局文件中增加属性

    • android:background="?android:attr/selectableItemBackground"

    • android:background="?android:attr/selectableItemBackgroundBorderless"

    • <item name="android:colorControlHighlight">@color/colorAccent</item> 可以更改波纹的颜色

    • 为自定义背景添加水波纹效果

      <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@android:color/white"><!-- 水波纹颜色 必须-->
        <item>
          <!-- 原block-->
        </item>
      </ripple>
  • 给英文设置粗体的方法:

    • xmlandroid:textStyle="bold"
    • 在代码中,tv.getPaint().setFakeBoldText(true);
  • hasOverLapping 自定义 View 时重写 hasOverlappingRendering 方法指定 View 是否有 Overlapping 的情况,提高渲染性能.

      @Override
      public boolean hasOverlappingRendering() {
          return false;
      }
  • View.getLocationInWindow()View.getLocationOnScreen()区别

// location [0]--->x坐标,location [1]--->y坐标
int[] location = new  int[2];
// 获取在当前窗口内的绝对坐标,getLeft,getTop,getBottom,getRight 这一组是获取相对在它父窗口里的坐标.
view.getLocationInWindow(location); 
// 获取在整个屏幕内的绝对坐标,注意这个值是要从屏幕顶端算起,也就是包括了通知栏的高度.
view.getLocationOnScreen(location);
  1. 如果在ActivityOnCreate()事件输出那些参数,是全为0,要等UI控件都加载完了才能获取到这些.在onWindowFocusChanged(boolean hasFocus)中获取为好.
  2. View.getLocationInWindow()View.getLocationOnScreen()window占据全部screen时,返回值相同. 不同的典型情况是在Dialog中时,当Dialog出现在屏幕中间时,View.getLocationOnScreen()取得的值要比View.getLocationInWindow()取得的值要大
  • cardview加上点击效果(水波纹) layout中增加android:foreground="?attr/selectableItemBackground"
  • Gson解析json数据的时候,如果jsonkey是动态的,可以用Map<String T>来保存

Android Studio Tips

  1. 自动导包失效 清除缓存並重启(File-->Invalidate Cache\Restart...)  2. Android studio最实用快捷键

Material Icon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.