Android Open Source - Wardrobe_app Signup Fragment






From Project

Back to project page Wardrobe_app.

License

The source code is released under:

Apache License

If you think the Android project Wardrobe_app 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 com.android.busolo.apps.wardrobe.engine;
/* www.j  av a  2s.  c o m*/
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.android.busolo.apps.wardrobe.utils.AccountUtils;
import com.android.busolo.apps.wardrobe.utils.PrefUtils;
import com.android.busolo.apps.wardrobe.utils.VolleyAppController;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import static com.android.busolo.apps.wardrobe.utils.LogUtils.LOGE;

/**
 * Created by james on 1/07/14.
 */
public class SignupFragment extends Fragment {

    static final String LOG_TAG = "SignupFragment";

    private EditText text_su_email;
    private EditText text_su_username;
    private EditText text_su_password1;
    private Button btn_su_sign_up;
    private ProgressBar loading;
    private View section_signup;

    private Activity activity;

    public SignupFragment() {
    }

    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.activity = activity;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_signup, container, false);

        text_su_email = (EditText) rootView.findViewById(R.id.text_su_email);
        text_su_username = (EditText) rootView.findViewById(R.id.text_su_username);
        text_su_password1 = (EditText) rootView.findViewById(R.id.text_su_password1);
        btn_su_sign_up = (Button) rootView.findViewById(R.id.btn_su_sign_up);
        loading = (ProgressBar) rootView.findViewById(R.id.loading);
        section_signup = (LinearLayout) rootView.findViewById(R.id.section_signup);
        btn_su_sign_up.setOnClickListener(onClickListener);

        return rootView;
    }

    boolean validateForm() {
        if (TextUtils.isEmpty(text_su_email.getText())) {
            text_su_email.setError(getResources().getString(R.string.lbl_err_email));
            text_su_email.requestFocus();
            return false;
        } else if (TextUtils.isEmpty(text_su_username.getText())) {
            text_su_username.setError(getResources().getString(R.string.lbl_err_username));
            text_su_username.requestFocus();
            return false;
        } else if (TextUtils.isEmpty(text_su_password1.getText())) {
            text_su_password1.setError(getResources().getString(R.string.lbl_err_password));
            text_su_password1.requestFocus();
            return false;
        } else{
            return true;
        }
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            switch (v.getId()) {
                case R.id.btn_su_sign_up:
                    UserAccountActivity activity = (UserAccountActivity) getActivity();
                    ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(activity.CONNECTIVITY_SERVICE);
                    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
                    if (activeNetwork == null || !activeNetwork.isConnected()) {
                        Toast.makeText(activity, R.string.no_connection_cant_login, Toast.LENGTH_SHORT).show();
                        return;
                    }
                    if (!validateForm()) {
                        LOGE(LOG_TAG, "Form not valid. check input");
                        return;
                    } else {
                        //TODO form valid..send to server
                        startSignUp();
                    }
                    break;

                default:
                    break;
            }
        }
    };

    void toast(final String text){
        Toast.makeText(this.activity, text, Toast.LENGTH_SHORT).show();
    }

    void startSignUp() {
        loading.setVisibility(View.VISIBLE);
        section_signup.setVisibility(View.GONE);

        final String tag_json_obj = "json_obj_req";
        //TODO change to backend URL
        String URL = "http://api.wardrobe.com";

        JsonObjectRequest jsonObjectReq = new JsonObjectRequest(Request.Method.POST, URL, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        Log.e(LOG_TAG, "response: " + response.toString());
                        //TODO process response

                        finishSignUp();
                        loading.setVisibility(View.GONE);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                VolleyLog.e(LOG_TAG, "Error: " + volleyError.getMessage());
                //TODO uncomment the following lines...to show error
//                loading.setVisibility(View.GONE);
//                section_signup.setVisibility(View.VISIBLE);
//                toast("Something's not right, please try again later :( ");

                //TODO remove this call...just for demo purposes
                finishSignUp();
            }
        }){
            @Override
            protected Map<String, String> getParams(){
                Map<String, String> params = new HashMap<String, String>();
                params.put("name", "Optimus");
                params.put("email", "jdoe@gmail.com");
                params.put("password", "jdoe_opt");
                return params;
            }
        };

        //add request to request queue
        VolleyAppController.getInstance().addToRequestQueue(jsonObjectReq, tag_json_obj);

    }

    void finishSignUp(){
//        AccountUtils.setChosenAccountName(this.activity, text_su_username.getText().toString());
        AccountUtils.setChosenAccountName(this.activity, "brian");
        PrefUtils.markSetupDone(this.activity);
        Intent intent = new Intent(this.activity, HomeActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        this.activity.startActivity(intent);
        this.activity.finish();
    }
}




Java Source Code List

com.android.busolo.apps.wardrobe.Config.java
com.android.busolo.apps.wardrobe.engine.BaseActivity.java
com.android.busolo.apps.wardrobe.engine.ColorPickerFragment.java
com.android.busolo.apps.wardrobe.engine.CommentsFragment.java
com.android.busolo.apps.wardrobe.engine.FollowActivity.java
com.android.busolo.apps.wardrobe.engine.HomeActivity.java
com.android.busolo.apps.wardrobe.engine.ItemDetailsActivity.java
com.android.busolo.apps.wardrobe.engine.LoginFragment.java
com.android.busolo.apps.wardrobe.engine.MatchFragment.java
com.android.busolo.apps.wardrobe.engine.NewPostActivity.java
com.android.busolo.apps.wardrobe.engine.PrivateStreamFragment.java
com.android.busolo.apps.wardrobe.engine.ProfileFragment.java
com.android.busolo.apps.wardrobe.engine.PublicStreamActivity.java
com.android.busolo.apps.wardrobe.engine.PublicStreamFragment.java
com.android.busolo.apps.wardrobe.engine.SignupFragment.java
com.android.busolo.apps.wardrobe.engine.StepOneFragment.java
com.android.busolo.apps.wardrobe.engine.StepTwoFragment.java
com.android.busolo.apps.wardrobe.engine.UserAccountActivity.java
com.android.busolo.apps.wardrobe.engine.adapter.ColorListAdapter.java
com.android.busolo.apps.wardrobe.engine.adapter.ColorSpinnerAdapter.java
com.android.busolo.apps.wardrobe.engine.adapter.FeedsListAdapter.java
com.android.busolo.apps.wardrobe.engine.adapter.GridViewPhotoAdapter.java
com.android.busolo.apps.wardrobe.engine.adapter.ViewInflaterBaseAdapter.java
com.android.busolo.apps.wardrobe.engine.model.ColorPicker.java
com.android.busolo.apps.wardrobe.engine.model.FilterParam.java
com.android.busolo.apps.wardrobe.engine.model.Follow.java
com.android.busolo.apps.wardrobe.engine.model.Stream.java
com.android.busolo.apps.wardrobe.sync.SyncHelper.java
com.android.busolo.apps.wardrobe.sync.SyncService.java
com.android.busolo.apps.wardrobe.utils.AccountUtils.java
com.android.busolo.apps.wardrobe.utils.BitmapCache.java
com.android.busolo.apps.wardrobe.utils.ImageLoader.java
com.android.busolo.apps.wardrobe.utils.LogUtils.java
com.android.busolo.apps.wardrobe.utils.LruBitmapCache.java
com.android.busolo.apps.wardrobe.utils.NetUtils.java
com.android.busolo.apps.wardrobe.utils.ParserUtils.java
com.android.busolo.apps.wardrobe.utils.PrefUtils.java
com.android.busolo.apps.wardrobe.utils.ServerResponse.java
com.android.busolo.apps.wardrobe.utils.UIUtils.java
com.android.busolo.apps.wardrobe.utils.VolleyAppController.java
com.android.busolo.apps.wardrobe.utils.model.FeedResult.java
com.android.busolo.apps.wardrobe.widget.BezelImageView.java
com.android.busolo.apps.wardrobe.widget.CheckableFrameLayout.java
com.android.busolo.apps.wardrobe.widget.EllipsizedTextView.java
com.android.busolo.apps.wardrobe.widget.ObservableScrollView.java
com.android.busolo.apps.wardrobe.widget.SquareImageView.java