Android Open Source - aInstagram Login Dialog






From Project

Back to project page aInstagram.

License

The source code is released under:

GNU General Public License

If you think the Android project aInstagram listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.jackbeasley.aInstagram;
//  w  ww. jav  a2s .  com
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import net.jackbeasley.ainstagram.R;

/**
 * TODO: Doc
 */
public class LoginDialog extends DialogFragment {
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_AUTHURL = "authURL";
    private static final String ARG_CALLBACKURL = "callbackURL";

    private String authURL;
    private String callbackURL;


    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param authURL Url for instagram authorization.
     * @return A new instance of fragment LoginDialog.
     */
    public static LoginDialog newInstance(String authURL, String callbackURL) {
        LoginDialog fragment = new LoginDialog();
        Bundle args = new Bundle();
        args.putString(ARG_AUTHURL, authURL);
        args.putString(ARG_CALLBACKURL, callbackURL);
        args.put
        fragment.setArguments(args);
        return fragment;
    }
    public LoginDialog() {
        // Required empty public constructor
    }

    public interface LoginDialogListener{
        /**
         * Returns the auth token recieved from instagram after login.
         * @param accessToken Instagram session token
         */
        void onAccessTokenRecieved(String accessToken);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            authURL = getArguments().getString(ARG_AUTHURL);
            callbackURL = getArguments().getString(ARG_CALLBACKURL);
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        //Get LayoutInflator
        LayoutInflater inflater = getActivity().getLayoutInflater();
        //Get the view so a findViewById can be called
        View v = inflater.inflate(R.layout.login_dialog, null);
        final WebView wv = (WebView) v.findViewById(R.id.signinDialogWebView);
        builder.setView(v);
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        final AlertDialog alertDialog = builder.create();

        wv.setVerticalScrollBarEnabled(false);
        wv.setHorizontalScrollBarEnabled(false);
        wv.loadUrl(authURL);
        wv.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.startsWith(callbackURL)) {
                    //Code comes after the only equals sign at the end of the callbackurl.
                    String parts[] = url.split("=");
                    String accessToken = parts[1];
                    Log.i(accessToken, "OAuth");
                    //Call listener

                    alertDialog.dismiss();
                    return true;
                }
                return false;
            }
        });


        return alertDialog;

    }

}




Java Source Code List

net.jackbeasley.aInstagram.LoginDialog.java
net.jackbeasley.aInstagram.SignIn.java
net.jackbeasley.aInstagram.aInstagram.java
net.jackbeasley.ainstagram.ApplicationTest.java