18 Aug 2009, 03:15
Generic-user-small

Win Myo Htet (31 posts)

The best way to learn Android is to learn it from the source. Here is a bit of strategy on how to use the source.

I want to have a persistent AlertDialog that won’t crash on screen orientation change. I have been hunting the way to do that for a while. One time, I notice that the AlertDialog with the title “No network connection” when I am browsing. I try to see if that Dialog will crash when the screen rotate. It doesn’t of course. So, I want to look at the code for that. I have asked where I can find that code in #android-dev channel. One person (non googler, I believe) told me that it was in the browser code! (Before, I thought that it might be in System level source code). He suggest to grep string id of “No network connection” in the res/values/Sting.xml and then hunt that id in the java code! So I follow his instruction and found the code. I still have to do more code digging (Remember the XML!) before I finally get my code working. I have even posted my finding on how to create a persistent AlertDialog for on Orientation change here http://www.anddev.org/viewtopic.php?p=25696#25696

Here is the browser source code where I learn that http://android.git.kernel.org/?p=platform/packages/apps/Browser.git;a=blob;f=src/com/android/browser/BrowserActivity.java

.
.
.
.
.
public class BrowserActivity extends Activity
    implements KeyTracker.OnKeyTracker,
        View.OnCreateContextMenuListener,
        DownloadListener {
.
.
.
.
.
            mInLoad = true;
            updateInLoadMenuItems();
            if (!mIsNetworkUp) {
                if ( mAlertDialog == null) {
                    mAlertDialog = new AlertDialog.Builder(BrowserActivity.this)
                        .setTitle(R.string.loadSuspendedTitle)
                        .setMessage(R.string.loadSuspended)
                        .setPositiveButton(R.string.ok, null)
                        .show();
                }
                if (view != null) {
                    view.setNetworkAvailable(false);
                }
            }
.
.
.
.
.

   /**
     * connectivity manager says net has come or gone... inform the user
     * @param up true if net has come up, false if net has gone down
     */
    public void onNetworkToggle(boolean up) {
        if (up == mIsNetworkUp) {
            return;
        } else if (up) {
            mIsNetworkUp = true;
            if (mAlertDialog != null) {
                mAlertDialog.cancel();
                mAlertDialog = null;
            }
        } else {
            mIsNetworkUp = false;
            if (mInLoad && mAlertDialog == null) {
                mAlertDialog = new AlertDialog.Builder(this)
                        .setTitle(R.string.loadSuspendedTitle)
                        .setMessage(R.string.loadSuspended)
                        .setPositiveButton(R.string.ok, null)
                        .show();
            }
        }
        WebView w = mTabControl.getCurrentWebView();
        if (w != null) {
            w.setNetworkAvailable(up);
        }
    }
.
.
.
.
.


    /* hold a ref so we can auto-cancel if necessary */
    private AlertDialog mAlertDialog;
.
.
.
.
.}
22 Aug 2009, 03:04
Generic-user-small

Win Myo Htet (31 posts)

In android, XML is the way to construct button, view, radiobutton,… everything. Learning XML once and you will be using it everytime.

You can use tool like droiddraw to visualize what is available and to generate the XML codes. The eclipse plugin can do that also. For now, the plugin does not have an easy to visualize icons. The next version of plugin will have icons like droiddraw. However the most powerful tool for XML stay inside the SDK/tool folder ( android-sdk-linux_x86-1.5_r3/tools/hierarchyviewer ). It is a XML debugger.

If you have problem with your XML, debug it with hierarchyviewer.

17 Mar 2012, 00:01
Generic-user-small

Adam J Johansson (1 post)

Appreciated. Thanks

  You must be logged in to comment