Outdoor Clone Chameleon Launcher

    About two or three years ago, I accidentally found out about an interesting launcher for android chameleon launcher . I bought and for some time even successfully used it, until the creator lost interest in him.

    What attracted me to this launcher was that it allowed me to turn the tablet’s home screen into an information board - here there are rss tapes, twitter, and weather, etc. Everything looks beautiful and convenient, and the screen space is not wasted (and it’s on the screen always small). In addition, he allowed to write his own widgets in js.

    But the creator lost interest in his creation (at one time he collected money for it through kickstarter) and at first the widgets stopped working (they use the server to work), there were bugs that did not fix. As a result, recently the application was completely removed from the Play Market.

    Gradually, my desire began to appear to write a similar launcher - I was asking about technology, but did not want to mess with Java. But this weekend I decided to try my hand at writing a clone of this launcher. In this article I will talk about the current state of affairs. Perhaps someone else will be interested in the project and join it.

    Main screen:
    image


    List of applications:
    image

    The goal was to do something more or less similar in the shortest time: for starters, without any baubles - animations, drag & drop, etc., in order to gradually bring the functional to the desired state. Also, I practically did not bother with cross-device layout and I have no idea how well this will be displayed on devices other than seven-inch tablets (1024x600) in a horizontal position. Minimum means minimum, otherwise you can get stuck for a long time. I wanted to make at least some prototype for development, and in general - to feel the technology.

    I also made one important change for me in the concept of widget architecture. Now you do not need to host them on the server to make cross-domain requests. They can be done without using scripts on the server.

    The beginning of the way


    Before starting development, I once again checked to see if someone started writing a clone before me (I periodically monitored this) and making sure that it was still not there, I started looking for html launcher projects. Immediately found github.com/Aricwithana/DOMLauncher2 . But the basis didn’t seem very suitable, a lot of superfluous, and deleting the code (almost everything) is a waste of time. Therefore, I decided to start from scratch. I decided not to use PhoneGap, because It seemed to me that the launcher thing is not simple and suddenly something is not enough for me in it and I have to start again on a clean Android SDK.

    After installing the Android SDK, I generated a default project with the following command:
    android create project -n Launcher -t 'android-16' -p . -k com.longerdev.launcher -a LauncherActivity
    

    note
    I’ll digress right away, here I indicated the version of API 16, thinking about the phone on which I have android 4.1 now, I didn’t yet know that because of this I would lose 20 minutes trying to understand why the project wasn’t building with JavaScriptInterface (about that it will be further).

    I built the project and installed the application:
    ant debug && ant installd
    

    The first thing I wanted to do was get rid of the window title. After searching and various experiments, I came to the conclusion that the best way to do this is to register for the application. To do this, create a res / values ​​/ styles.xml file and edit AndroidManifest.xml a little:
    <application......android:theme="@style/AppTheme"><resources><stylename="AppTheme"parent="android:Theme.Holo.Wallpaper"><itemname="android:windowActionBar">false</item><itemname="android:windowNoTitle">true</item></style></resources>

    The theme name Wallpaper is not accidental; if you remove it, the application background will be black. But since if it is, then the application tightens the wallpaper from the system settings (and this eliminates the need to write a large amount of code).

    Turn into a launcher


    Any application can be easily turned into a “launcher”. To do this, add 2 lines to AnroidManifest.xml and the application will be available by the home button:
    <application...
        <activity...
            <intent-filter>
                ...
                <categoryandroid:name="android.intent.category.HOME" /><categoryandroid:name="android.intent.category.DEFAULT" /></intent-filter>


    Now, after assembly and installation, the application will be available by pressing the home button.

    Creation and animation of WebView


    In android, in order to be able to use html and js, you need to add a WebView element to the application. To do this, edit the main layout (res / layout / main.xml):
    <?xml version="1.0" encoding="utf-8"?><WebViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/webview"android:layout_width="match_parent"android:layout_height="match_parent"
        />

    After that, I created assets / www / index.html with some small text and connected its display in LauncherActivity.java:
    publicvoidonCreate(Bundle savedInstanceState){
        ...
        WebView mainWebView = (WebView) findViewById(R.id.webview);
        mainWebView.loadUrl("file:///android_asset/www/index.html");
    

    Now if you run the application, you can see the contents of the file, but if you try to write some js code, it will not work. It must be included separately:
    WebSettings webSettings = mainWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);
    

    The last 2 lines allow cross-domain requests from js, which is part of the application.

    Throwing in js functions from java


    Over time, it became necessary to access the android api. While searching for how to do this, I found out that you can create a class whose methods will be accessible from js almost like native ones (you have to use JSON.parse when passing objects). I will not describe the

    entire class code , I will describe only key points.

    If you create a function in the class and write @JavascriptInterface in front of it, it will be available in js. Application Launch Function:
    @JavascriptInterfacepublic String echo(String name)throws Exception{
        return name;
    }
    

    In fact, you still need to connect this class to the WebView:
    MyJavaScriptInterface myInterface = new MyJavaScriptInterface(mainWebView, LauncherActivity.this);
    mainWebView.addJavascriptInterface(myInterface, "AndroidAPI");
    

    Now from js you can get to the code like this:
    AndroidAPI.echo();
    


    Conclusion


    I described the most interesting / difficult stages of development. I did not paint everything, because the article would be too long. And not the fact that interesting. Better ask, I will answer.

    What is already there:
    - one home screen (so far it’s not possible, but this is one of the following steps, I’ll clean up the code in the process)
    - widgets - rss (only supports rss 2.0), weather
    - a simple list of applications without paging
    - customizable panel of quick shortcuts (there is, a temporary refresh button for debug convenience) Immediate

    plans:
    - somehow make the settings in the config (this is what I need first of all with help, because this is my first application for android and still do not quite understand the ecosystem. I conducted a small experiment on this issue, but so far disabled it in the code)
    - several home screens
    - a more convenient API for widgets
    - rewrite rss and weather widgets
    - write a widget for twitter, clock (with alarm function),
    - cross-device layout (if there are devices for testing)

    First of all, I want to implement a version for the tablet and only then maybe I’ll take up the phone. Support for standard android widgets is not planned. The minimum required version of android 4.2 (API 17).

    I would be grateful for comments, advice and those wishing to participate in the project.
    Sources - github.com/Longer/ClawLauncher ( build ).

    Also popular now: