Musings

And you thought you knew about Open Source


Popular opinion about open-source software – having access to the source code – does not adequately express the meaning of free software; it is even weaker than official definition of open-source as it includes lots of propriety and/or commercial programs.

Free software does not imply that software is available at zero cost; it is possible to pay money to buy open-source software; however you are FREE to modify and change it and even possibly sell copies! A free program must be available for commercial use, development and distribution. Strange? Think Red Hat Linux, Red Hat Linux is open-source software but not freeware.

Freeware expresses the concept of not charging for use; this is the meaning of “free as in free beer”; freeware however does not guarantee access to the source code :( . By not using open standards, it is easy to lock in users (who might be attracted by the zero cost) and prevent them from moving on to other software later.

On the other hand, “free as in free speech” means you get access to the source code and can change it as you will. According to Richard Stallman of FSF and GNU fame,  free software can be used, studied, distributed, changed, copied and improved by users. Fortunately, most open-source software are freeware. Users of open-source software don’t have to worry about what happens if their software gets bought out; it also assures of some form of updates as anyone can improve the software.

Here are some of the most widely-used licenses

  • General Public License (GPL)Anyone who obtains software licensed with the GPL has the right to get the source code along with the software, create anything they like and redistribute it under the same GPL.
  • Mozilla Public License – This gives users the right to modify your software. However ,they have to release all your files with their software but do not have to release the files they created from the scratch.
  • Lesser General Public License (LGPL) – Similar to the GPL, but gives people the flexibility to use open-source software in their own projects without releasing all the source code to the world.
  • Apache 2.0 LicenseUsers can use the source code as they will provided they include the copy of the license in their distributions and use the proper attributions.
  • BSD License – A very open license, allowing users to do practically anything with the software. All you have to do is include the copyright, conditions and disclaimer; also you can’t use the name of the originating organization to promote your edit without written consent.
  • MIT License – This is similar to the BSD License, but even more permissive.
  • Public Domain – This is completely permissive; anyone can do anything they like with these software as there is no copyright. SQLite is a popular example of public domain software.

Next time you get free software, find out what kind of ‘free’ it is!

Standard
Android

Access a webpage inside an Android Activity


While working on an Android app, I needed to get people to sign into Facebook however I didn’t want them to leave my app. The simple solution was to launch the browser through an intent; however, this was going to stop my activity which was unacceptable. I wanted a solution that enabled users to sign into the Facebook platform from inside the app. I had to embed a webview inside a dialog and pop up the required webview. How? Read on

Create the Activity that pops up the dialog

public class WebviewActivity extends Activity {
    private static final String REGISTRATION_URL = "http://10.0.2.2/test.php";
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.blog_learning);
        new blog(this, REGISTRATION_URL, new DialogListener() {
            @Override
            public void onComplete(JSONObject values) {
                // Do processing here with the JSONObject, you can change it if you so desire
                Log.d("Oncomplete","called");
            }
            @Override
            public void onError(DialogError e) {}
            @Override
            public void onStop() {}
        }).show();
    }
}

Create a Listener interface that links your Activity to the Dialog

public interface DialogListener {
    public void onComplete(JSONObject values);
    public void onError();
    public void onStop();
}

The listener provides a callback pathway that monitor the state of the dialog; you can use it to get responses, check errors and do similar activities.

The Dialog class

Also, one thing, the Layouts and buttons are declared programmatically in the code, I couldn’t find a way to automatically load layout files in the onCreate method of the Dialog. If you know how to do this, kindly explain in the comments. Making a call to shouldOverrideUrlLoading in the WebViewClient doesn’t seem to work either, so you should do your processing in onPageFinished. Here is the code:


public class blog extends Dialog {
static final FrameLayout.LayoutParams FILL = new FrameLayout.LayoutParams(
                 ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
    private static final String RESULT_URL = "XXX.php"; // Url for retrieving results
    private String mUrl; //URL you are making a request to
    private DialogListener mListener;
    private ProgressDialog mSpinner;
    private Button mButton;
    private WebView mWebView;
    private LinearLayout mWebViewContainer;
    public blog(Context context, String url, DialogListener listener) {
        super(context, android.R.style.Theme_NoTitleBar);
        mUrl = url;
        mListener = listener;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mSpinner = new ProgressDialog(getContext());
        mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mSpinner.setMessage("Loading...");
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mButton = new Button(getContext());
        mButton.setText("Close");
        mWebViewContainer = new LinearLayout(getContext());
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onStop();
                blog.this.dismiss();
            }
        });
        //Close button should only become visible after the webview is fully loaded
        mButton.setVisibility(View.INVISIBLE);
        mWebView = new WebView(getContext());
        mWebView.setVerticalScrollBarEnabled(false);
        mWebView.setHorizontalScrollBarEnabled(false);
        mWebView.setWebViewClient(new blog.blogWebViewClient());
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl(mUrl);
        mWebView.setVisibility(View.INVISIBLE);
        mWebViewContainer.addView(mButton);
        mWebViewContainer.addView(mWebView);
        addContentView(
            mWebViewContainer,
            new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)
        );
    }

    private class blogWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            mListener.onError(new DialogError(description, errorCode,failingUrl));
            blog.this.dismiss();
        }
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
             super.onPageStarted(view, url, favicon);
             mSpinner.show();
        }
        @Override
        public void onPageFinished(WebView view, String url) {
             super.onPageFinished(view, url);
             mSpinner.dismiss();
             mWebViewContainer.setBackgroundColor(Color.TRANSPARENT);
             mWebView.setVisibility(View.VISIBLE);
             mButton.setVisibility(View.VISIBLE);
             //Do result processing here
             if (url.contains(RESULT_URL)) {
                 JSONObject obj = null;
                 try { URL json = new URL(url); }
                 catch (IOException e) { e.printStackTrace(); }
                 mListener.onComplete(obj);
                 blog.this.dismiss();
             }
         }
    }
}

For more information on this, check this:

Standard
Computer Science, Miscellaneous, Version Control

Importing a remote Git project using Eclipse


Git is an open-source distributed version-control system and is similar to Subversion, Mercurial and similar version control software. While trying to get access to a Git remote repository on Eclipse, I encountered a lot of issues as I didn’t quite know how to go about it, so I decided to write about it.

This guide assumes you already have Eclipse and EGit installed. Eclipse 3.7 (Indigo) already bundles EGit, however if you are using an older version, go to help -> install new software and use the wizard to install the EGit plugin from http://download.eclipse.org/egit/updates.

Here goes:

Import a New project

Import a New project

Clone a project

Click clone a project

Enter your remote repository information

Enter your remote repository information

Select the branches you want to clone

Setup the local storage location for your remote git repository

Setup the local storage location for your remote git repository

Click finish

Click finish

Cloning process

Cloning process

Cloned branches

Cloned branches

Select a wizard to import projects

Select a wizard to import projects

Choosing this might not work

Choosing this might not work

Choosing "Import Existing projects" might lead to this

Choosing “Import Existing projects” might lead to this

Select a wizard to import projects

So choose “Import as General project”

Choose a project name

Choose a project name

Voila! Done!! :D

Notice

Given that your project might not be setup properly on Eclipse, here are some tips to do this:

Open up the filters option

Open up the filters option

Uncheck the resources checkbox

Uncheck the resources checkbox

Modify the project properties

Modify the project properties

And the classpath too...

And the classpath too…

The .gitignore file contains all files that are ignored by your git repository. Also, If you know a better way, kindly let me know.

Here are some resources for learning and trying out Git:

http://gitimmersion.com/

http://book.git-scm.com/

http://www.vogella.de/articles/EGit/article.html

 

Standard