Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragments are not switching smoothly - Slow change in login to signup fragment and vice-versa #7

Open
PalakJainAndroidDeveloper opened this issue Jul 12, 2018 · 1 comment

Comments

@PalakJainAndroidDeveloper

when i click on sign in textView on login fragment then Logcat is showing warning

W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
finishComposingText on inactive InputConnection

and the page is not switching. problem might be i use textUtils

 private Boolean  validate() {
        //for email validation
        Pattern pattern;
        Matcher matcher;
        final String EMAIL_PATTERN="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
        pattern=Pattern.compile(EMAIL_PATTERN);
        matcher=pattern.matcher(email_id.getText().toString());
        if (TextUtils.isEmpty(email_id.getText())) {
            email_id.setError("Please enter username");
            email_id.requestFocus();
        }else if (TextUtils.isEmpty(password.getText())) {
            password.setError("Please enter your password");
            password.requestFocus();
        }else if (TextUtils.isEmpty(confirmPassword.getText().toString())) {
            confirmPassword.setError("Please enter your password");
            confirmPassword.requestFocus();
        }else if(!password.getText().equals(confirmPassword.getText()) ){
            //Passward and confirm password is not same
            Toast.makeText(getContext(),"Confirm Password should be same as Password", Toast.LENGTH_SHORT).show();
        } else if(!matcher.matches()){
            //email is validate
            Toast.makeText(getContext(),"Please Enter a Valid Email address like example@gmail.com ", Toast.LENGTH_SHORT).show();
        } else{
            return true;
        }
        return false;
    }

on button click event. so please tell me what else i can do so that this error is removed and fragment will move smoothly . I am attaching signup fragment code with this question.

`package in.branmark.websitedemo;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import com.transitionseverywhere.ChangeBounds;
import com.transitionseverywhere.Transition;
import com.transitionseverywhere.TransitionManager;
import com.transitionseverywhere.TransitionSet;

import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;

import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.support.annotation.Nullable;
import android.annotation.TargetApi;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindViews;
import butterknife.ButterKnife;


public class SignUpFragment extends AuthFragment{

    @BindViews(value = {R.id.email_input_edit,
            R.id.password_input_edit,
            R.id.confirm_password_edit})
    protected List<TextInputEditText> views;

    VerticalTextView signin;
    TextInputEditText email_id;
    TextInputEditText password;
    TextInputEditText confirmPassword;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if(views!=null){
            view.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.color_sign_up));
            caption.setText(getString(R.string.sign_up_label));
            for(TextInputEditText editText:views){
                if(editText.getId()==R.id.password_input_edit){
                    final TextInputLayout inputLayout= ButterKnife.findById(view,R.id.password_input);
                    final TextInputLayout confirmLayout=ButterKnife.findById(view,R.id.confirm_password);
                    Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);
                    inputLayout.setTypeface(boldTypeface);
                    confirmLayout.setTypeface(boldTypeface);
                    editText.addTextChangedListener(new TextWatcherAdapter(){
                        @Override
                        public void afterTextChanged(Editable editable) {
                            inputLayout.setPasswordVisibilityToggleEnabled(editable.length()>0);
                        }
                    });
                }
                editText.setOnFocusChangeListener((temp,hasFocus)->{
                    if(!hasFocus){
                        boolean isEnabled=editText.getText().length()>0;
                        editText.setSelected(isEnabled);
                    }
                });
            }
            caption.setVerticalText(true);
            foldStuff();
            caption.setTranslationX(getTextPadding());

            signin = view.findViewById(R.id.caption);
            email_id=view.findViewById(R.id.email_input_edit);
            password=view.findViewById(R.id.password_input_edit);
            confirmPassword=view.findViewById(R.id.confirm_password_edit);

            //check if password is equal to confirm password
            //password.getText().toString()==confirmPassword.getText().toString()

            signin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (validate()) {
                        JSONObject postData = new JSONObject();
                        try {
                            postData.put("uid", email_id.getText().toString());
                            postData.put("pass", password.getText().toString());

                            new SendDeviceDetails().execute("http://cp.foxymark.com/test-a.php", postData.toString());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
        }
    }

    private Boolean  validate() {
        //for email validation
        Pattern pattern;
        Matcher matcher;
        final String EMAIL_PATTERN="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
        pattern=Pattern.compile(EMAIL_PATTERN);
        matcher=pattern.matcher(email_id.getText().toString());
        if (TextUtils.isEmpty(email_id.getText())) {
            email_id.setError("Please enter username");
            email_id.requestFocus();
        }else if (TextUtils.isEmpty(password.getText())) {
            password.setError("Please enter your password");
            password.requestFocus();
        }else if (TextUtils.isEmpty(confirmPassword.getText().toString())) {
            confirmPassword.setError("Please enter your password");
            confirmPassword.requestFocus();
        }else if(!password.getText().equals(confirmPassword.getText()) ){
            //Passward and confirm password is not same
            Toast.makeText(getContext(),"Confirm Password should be same as Password", Toast.LENGTH_SHORT).show();
        } else if(!matcher.matches()){
            //email is validate
            Toast.makeText(getContext(),"Please Enter a Valid Email address like example@gmail.com ", Toast.LENGTH_SHORT).show();
        } else{
            return true;
        }
        return false;
    }
    @Override
    public int authLayout() {
        return R.layout.fragment_sign_up;
    }

    @Override
    public void clearFocus() {
        for(View view:views) view.clearFocus();
    }

    @Override
    public void fold() {
        lock=false;
        Rotate transition = new Rotate();
        transition.setEndAngle(-90f);
        transition.addTarget(caption);
        TransitionSet set=new TransitionSet();
        set.setDuration(getResources().getInteger(R.integer.duration));
        ChangeBounds changeBounds=new ChangeBounds();
        set.addTransition(changeBounds);
        set.addTransition(transition);
        TextSizeTransition sizeTransition=new TextSizeTransition();
        sizeTransition.addTarget(caption);
        set.addTransition(sizeTransition);
        set.setOrdering(TransitionSet.ORDERING_TOGETHER);
        set.addListener(new Transition.TransitionListenerAdapter(){
            @Override
            public void onTransitionEnd(Transition transition) {
                super.onTransitionEnd(transition);
                caption.setTranslationX(getTextPadding());
                caption.setRotation(0);
                caption.setVerticalText(true);
                caption.requestLayout();

            }
        });
        TransitionManager.beginDelayedTransition(parent,set);
        foldStuff();
        caption.setTranslationX(-caption.getWidth()/8+getTextPadding());
    }

    private void foldStuff(){
        caption.setTextSize(TypedValue.COMPLEX_UNIT_PX,caption.getTextSize()/2f);
        caption.setTextColor(Color.WHITE);
        ConstraintLayout.LayoutParams params=getParams();
        params.rightToRight=ConstraintLayout.LayoutParams.UNSET;
        params.verticalBias=0.5f;
        caption.setLayoutParams(params);
    }

    private float getTextPadding(){
        return getResources().getDimension(R.dimen.folded_label_padding)/2.1f;
    }

    private class SendDeviceDetails extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {

            String data = "";

            HttpURLConnection httpURLConnection = null;
            try {

                httpURLConnection = (HttpURLConnection) new URL(params[0]).openConnection();
                httpURLConnection.setRequestMethod("POST");

                httpURLConnection.setDoOutput(true);

                OutputStream os = httpURLConnection.getOutputStream();
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                String pd = URLEncoder.encode("uid", "UTF-8") + "=" + URLEncoder.encode(email_id.getText().toString(), "UTF-8") + "&" +
                        URLEncoder.encode("pass", "UTF-8") + "=" + URLEncoder.encode(password.getText().toString(), "UTF-8");
                bw.write(pd);
                bw.flush();
                bw.close();

                InputStream in = httpURLConnection.getInputStream();
                InputStreamReader inputStreamReader = new InputStreamReader(in);

                int inputStreamData = inputStreamReader.read();
                while (inputStreamData != -1) {
                    char current = (char) inputStreamData;
                    inputStreamData = inputStreamReader.read();
                    data += current;
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
            }

            return data;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            Log.e("TAG", result); // this is expecting a response code to be sent from your server upon receiving the POST data
        }
    }

    @Override
    public void onPause() {

        // hide the keyboard in order to avoid getTextBeforeCursor on inactive InputConnection
        InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

        inputMethodManager.hideSoftInputFromWindow(email_id.getWindowToken(), 0);
        inputMethodManager.hideSoftInputFromWindow(password.getWindowToken(), 0);
        inputMethodManager.hideSoftInputFromWindow(confirmPassword.getWindowToken(), 0);

        super.onPause();
    }
}

`

Please help me out. and thanks in advance.

@ghost
Copy link

ghost commented Aug 30, 2018

am also facing the same problem, transition is slow and sometimes its hanging then later the app crashes what could be the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants