chinalwb / Android-Rich-text-Editor

Android Rich Text Editor With customized spans - 富文本编辑器 - Don't miss this one :)
Apache License 2.0
845 stars 167 forks source link

Fix crash when casting class extending activity #122

Closed starshipcoder closed 4 years ago

starshipcoder commented 4 years ago

Fix crash when casting class extending activity

Fix #102

chinalwb commented 4 years ago

@starshipcoder Thanks for this amazing PR! It works but I cannot fully understand how the below code works:

       ....
        while (!(context instanceof Activity)) {
            context = ((ContextWrapper)context).getBaseContext();
        }
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
       .....

Could you please help explain more about the code? Thanks!