Of course, you can learn how to create a xposed module. So you can read this tutorial (the official tutorial) to learn how to solve this problem. This is not just about how to create a new module, how to write a module, we need to think deeper, why follow these steps, why create this class. If you are a "Dr. Tl" person, you can read the section "Making the Project an Xposed module" directly. If you want to read the entire tutorial then you need to be very good at understanding. You will take the time to read this article, because you cannot but solve any problem on your own.
here). Looking at the class Xposedbridge, you can see the main method. This is what I wrote above, and this class will be called before the process is started. At that time, some initialization and module loading was performed (I'll explain the module's loading later).
Download Xposedbridgeapi-.jar here. Copy it to the sub-folder named Lib directory. Then right-click on it and choose build Path = = Add to build path. You need to insert the version name into the declaration list of the xposedminversion. Turn from
You can choose how the library references. But make sure your API class is properly compiled into the apk file, otherwise you will get a illegalaccesserror. By referencing the Libs file (with "s"), the simple setup of Eclipse can be done without having to include the Xposedbridgeapi-.jar.
here) and browse him. But this official ROM may not be the same as yours, but in this case it is similar to even the same implementation. First, I want to see AOSP to see if it's the same. If I need more details, take a look at the actual anti-compilation code.
You can look for the "clock" class name or the class that contains the string. The next step is to look for the resources and layouts he uses. If you download the official AOSP code, you can start looking for it here: Frameworks/base/packages/systemui. You will find a lot of places where "clocks" appear. This is normal and there are different ways to implement the modification. Please remember that you can only hook the method. So, you have to find a place where you can insert some code before, after, or all of them. You should hook up to the exact way possible, not the ones that will be called thousands of ways to avoid performance problems and unexpected side effects.
In this case, you may find that the layout res/layout/status_bar.xml contains a custom view class: Com.android.systemui.statusbar.policy.Clock. Multiple ideas may be present in your mind. The text color is defined by the Textappearance property, so the simplest way to change it is to change the definition of the appearance. However, this may or may not be valid (because it may exist in a deeper native code). Changing the layout status bar will be possible, but you can only make the smallest changes to change him, instead, look at this class. There is a method called Updateclock, which looks like it will be called every minute to update the time
It looks perfect to modify because it is a very specific method that seems to be the only setting of the text clock. If we change the color or font of this clock, then any call to this method will be affected by this. As soon as we reach our needs, we act immediately.
(Separate text color, here's a better way.) See the example "Modify Layout" in "replacing resources".)
A method of the helper class. Note that it is statically imported and will be added automatically if you configure the link page that it describes. This method finds the clock class in the ClassLoader package through ClassLoader. Then, it looks for the Updateclock method inside. If this method has any parameters, you must list the types of these parameters. Different cases are treated differently, but our method does not have any parameters and can skip this hypothesis. As the last parameter, you need to provide an implementation of the Xc_methodhook class. For minor changes, you can use an anonymous class. If you have too much code, it's a good idea to create an ordinary class, just create an instance here. The helper will then hook up the above functions in every way.
You can rewrite the two methods of Xc_methodhook. You can overwrite and not even do the operation at the same time, but the latter is completely meaningless. These two methods are Beforehookedmethod and Afterhookedmethod. This is not too difficult to guess, and these two methods will be executed before and after the original method. You can use the Beforehookedmethod method to evaluate/tamper with the parameters of a method call (through Param.args), or even block the invocation of the original method (sending its own results). The Afterhookedmethod method can be used to do things based on the results of the original method. You can also use it to manipulate the results. Of course, you can add your own code, which will be executed exactly before or after the original method.
(If you want to completely replace the method, look at the subclass Xc_methodreplacement instead, you just need to overwrite Replacehookedmethod)
Xposedbridge retains a list of registered callback functions that record each function that has been hook. Those with the highest priority, such as the Hookmethod definition, are called first. The original method is always the lowest priority. So, if you hook a function and register a callback A (Prio high) and B (prio default), then whenever the hook method is called, the control flow will be this: A.before-> B.before-> Original Method-> B.after- > A.after. Therefore, a modifies the parameter, B is visible, so you can change it many steps before passing it to the original method. The result of the original method is first processed by B, but the result of the original method's final return is determined by a.
Ix. last step: Execute your own code before/after the method call
Well, you now have a method that will be called every time Updateclock is called, and can be exactly the same as before and after the original method (you are already in the systemui process). Now, let's change something.
The first thing to check: do we get a specific clock object? Yes, we have, it's in the Param.thisobject parameter. Therefore, if the method is called by Myclock.updateclock (), then Param.thisobject will make Myclock the object.
Next: What can we do with the clock? This clock class is not available, you can not convert param.thisobject into classes (don't even try). However, it inherits from the TextView. So, you can use the methods like Settext,gettext and SetTextColor once you've mapped the clock reference to TextView. These changes should be set to a new time after the original method call. Since there is nothing to do before the method call, we will not consider Beforehookedmethod. It is not necessary to call (empty) the "super" method. So don't rewrite this method.
This is the full source code:
Ten, satisfied with the result
Install/restart your application now. Just as you've enabled it in Xposedinstaller before you run it, you don't need to do it again, and restarting is enough. However, if you want to use it to deactivate the example of this red clock. Both use the default priority to their updateclock handlers, so you don't know which one will win (it actually depends on the string representation of the processing method, but it doesn't depend on it).
Xi. Conclusion
I know, this tutorial is very long. But I hope you can now not only achieve a green clock, but also can achieve with this completely different things. Finding a good way to hook is a matter of experience, so it's easier to start something. Try to use the logging feature at the beginning to ensure that the expected event is called. Now: Have fun!
Guide to creating modules in the Android xposed framework