This article is reprinted from the WeChat public account "Guo Lin", author Guo Lin. Please contact Guo Lin's public account to reprint this article. Glance is an open source library developed by me for debugging Android databases. You can view the contents of the database in the current App directly on your mobile phone without the help of a computer or a data cable. Version 1.0 of Glance was launched in December last year. For specific functions, please refer to this article I have developed another very useful open source library. However, Glance has not been updated since the first version was released. The main reason is that I am too busy. I can only write blogs in my spare time. I also have to maintain 3 open source projects at the same time, so the time I can allocate to Glance is really limited. However, after writing code sporadically for more than 8 months, Glance has indeed become better than before. Although some of the new features added do not seem very important, after accumulating them, I think it is enough to release a new version. Glance 1.1.0 is officially released today. Let me show you what new features the new version of Glance has. / Support displaying Room database /Many friends have told me that some databases cannot be displayed in Glance, including databases created using Room. This happens because Glance simply uses the .db suffix as a criterion when searching for database files. This method has the advantage of being very efficient, but the disadvantage is also obvious, the search results are inaccurate. This is because some database files do not have a .db suffix, for example, the database created by Room has no suffix by default. Therefore, in the new version of Glance, I modified the search rules. Instead of simply judging by the suffix name, I actually judge whether the file is a database file. If you read a database file on Android in binary mode, its header must start with "SQLite format 3", so the following code can accurately determine whether a file is a database file:
Although performing such judgment on all files will inevitably affect the search efficiency to a certain extent, Glance also has a caching mechanism for database files, and the results of previous searches will be displayed quickly, thus making up for some efficiency issues in this regard. / Allows horizontal and vertical scrolling at the same time /The interface for viewing the database table contents through Glance is quite exquisite, as shown in the following figure: This interface is implemented using a horizontal ScrollView plus a vertical RecyclerView, so it supports sliding in both horizontal and vertical directions. However, at the same time, we can only slide horizontally or vertically, and it does not support sliding horizontally and vertically at the same time. Here I would like to give special thanks to ultimateHandsomeBoy666, who submitted a Pull request to Glance, which allows us to swipe horizontally and vertically to view data at the same time. The implementation principle is also very simple:
That is, in the outer horizontal ScrollView, we do not use the default onInterceptTouchEvent interception mechanism, but let it not intercept. Then when dispatchTouchEvent, in addition to handling the Touch event ourselves, we also distribute the event so that RecyclerView can handle the event together. The final effect is shown in the figure below: / Support multiple application entry distinctions /The entrance to Glance is to create a Glance icon on the mobile phone desktop. Click the icon to view the database files contained in your application. However, one problem I didn't expect is that if a mobile phone has many applications installed, and these applications have introduced the Glance library, then you will not be able to tell which application each Glance icon corresponds to. I only realized this problem when an enthusiastic netizen raised it: As you can see, there are a bunch of Glance icons on the desktop, and you have no idea which one is which. When I first saw this bug, I hadn't figured out how to fix it because I was busy writing another feature at the time. Unexpectedly, a few days later, I found that ultimateHandsomeBoy666 had submitted another Pull Request to fix this problem. The solution adopted by ultimateHandsomeBoy666 is that the entry icon of Glance on the desktop is no longer named Glance, but named the same as the main App, but the icon still maintains the style of Glance to distinguish it from the main App. In this way, even if more Apps reference Glance, it will not cause confusion. I think this modification method is very appropriate. Thanks again to my friend ultimateHandsomeBoy666 for his help. / Allow modification of database contents /Well, my main work in the past 8 months should be on this function. Previously, the main function of Glance was to help you find all databases included in the current application and display their contents. In other words, you can only take a look at the data inside. But if you want to modify the data, this is not allowed. Modifying data is a very useful function, and it has been a long-standing demand from many friends. Therefore, one of the most important features of Glance 1.1.0 is that it allows developers to modify the database data of the current application directly on the phone. As for the method of modifying data, it is also very simple. Just double-click the data you want to modify, as shown in the following figure: This convenient way of modifying data in a visual interface is believed to be very much needed by many developer friends. You don’t need a computer at all, and you can complete it all on your mobile phone. Another thing I want to say is that the function of Glance to display database content is implemented using Paging 3. When I was writing an article explaining the usage of Paging 3, many friends asked me how to modify data in Paging 3, which sounded like a very difficult task. Since I did not try to modify data at that time, I could not answer these friends' questions. However, after implementing the data modification function in Glance, I found that there is nothing impossible or difficult to understand about data modification in Paging 3, and the method of modifying data is almost the same as that of modifying data when using RecyclerView normally. Therefore, if you still have questions about modifying data when using Paging 3 in the future, you may wish to refer to the source code implementation of Glance. Finally, there is another limitation when using Glance to modify data, that is, there must be a primary key in the table, otherwise it cannot be modified. Because the primary key is the only constraint on a row of data, if there is no primary key, Glance cannot know which row of data the user wants to modify. / How to Upgrade/This is the end of the introduction to the changes in the new version of Glance. The upgrade method is very simple. Just modify the version number in the dependencies:
Note that you must use the MavenCentral repository now, and you can no longer use jcenter. For the reason, you can refer to my article about the upcoming shutdown of JCenter. If you are interested in the source code of Glance, you can visit the project homepage of Glance: https://github.com/guolindev/Glance |
<<: Detailed explanation of the underlying implementation and principle of LinkedList data structure
Compiled by Zhou Shuyi GPT-4's strongest riva...
Yesterday, Xiaomi officially launched the Redmi 2...
There are two types of Ali pregnancy and childbir...
Baidu's oCPC bidding is no longer a new thing...
This article is divided into two parts: The theor...
In recent years, more and more people have discov...
I once saw a short video in which a blogger serio...
How much does it cost to attract investment in th...
As of March 31, 2018, the Hundred-Day Financial F...
In the pursuit of mediocrity, Apple's iPhone ...
According to The Paper, Taiwanese actress, singer...
Recently, the space radiation biology exposure ex...
Chengdu Tea Tasting Broker: Senior broker Night V...
What is the cause of the current fog and haze wea...
There is a lot of common knowledge about SEO opti...