Example usage for android.widget TextView requestFocus

List of usage examples for android.widget TextView requestFocus

Introduction

In this page you can find the example usage for android.widget TextView requestFocus.

Prototype

public final boolean requestFocus() 

Source Link

Document

Call this to try to give focus to a specific view or to one of its descendants.

Usage

From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java

void createAccountWithFbId() {
    mPrefs = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor editor = mPrefs.edit();
    editor.putString("access_token", facebook.getAccessToken());
    editor.putLong("access_expires", facebook.getAccessExpires());
    editor.commit();// w  w  w . j  a  v  a  2  s  .c o  m
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);
    if (access_token != null) {
        facebook.setAccessToken(access_token);
    }
    if (expires != 0) {
        facebook.setAccessExpires(expires);
    }

    /*
     * Only call authorize if the access_token has expired.
     */
    if (facebook.isSessionValid()) {
        Log.i(tag, "Session is valid");
        JSONObject json;
        try {
            json = Util.parseJson(facebook.request("me", new Bundle()));
            Log.i(tag, "json: " + json);
            fbId = json.getString("id");
            String username = json.getString("id");
            JSONArray existingUser = new Cloud(getApplicationContext(), fbId, null).findExistingFbUser(fbId,
                    countryCode + mPhone);

            Log.i(tag, "existingUser: " + existingUser.getString(0));
            LayoutInflater factory = LayoutInflater.from(this);
            textEntryView = factory.inflate(R.layout.facebook_email_layout, null);
            TextView fbUsername = (TextView) textEntryView.findViewById(R.id.facebookLogin_email);
            TextView fbPassword = (TextView) textEntryView.findViewById(R.id.facebookLogin_password);
            Button fbAccountButton = (Button) textEntryView.findViewById(R.id.facebookLogin);

            if (existingUser.getString(0).trim().length() == 0) {
                Log.i(tag, "email: " + Text.isEmail(username));
                if (!(Text.isEmail(username))) {
                    AlertDialog.Builder newBuilder = new AlertDialog.Builder(this);
                    newBuilder.setTitle("FbLogin to Phonebook");
                    newBuilder.setView(textEntryView);
                    Button existingFbAccount = (Button) textEntryView
                            .findViewById(R.id.existingAccountfacebookLogin);
                    existingFbAccount.setVisibility(View.GONE);
                    AlertDialog newAlert = newBuilder.create();
                    newAlert.show();
                }
            } else {
                fbAccountButton.setVisibility(View.GONE);
                fbUsername.setText(existingUser.getString(0));
                fbUsername.setEnabled(false);
                fbPassword.requestFocus();

                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("FbLogin to Phonebook");
                builder.setView(textEntryView);
                AlertDialog alert = builder.create();
                alert.show();
            }
            //mPhone = mPhoneEdit.getText().toString();
            //new Cloud(getApplicationContext(), userId, userId).loginWithFacebook(countryCode + mPhone);
            /*mUsername = userName;
            mPassword = userId;*/
            //finishLogin();
            // mUsernameEdit.setText(userName);
            // mPasswordEdit.setText(userId);
            Log.i(tag, "userName: " + username + " userId: " + fbId);
            Log.i(tag, "response:" + json);
        } catch (Exception e1) {
            Log.e(tag, "Exception logging on with Facebook: " + e1);
            e1.printStackTrace();
        } catch (FacebookError e) {
            Log.e(tag, "Facebook error logging on with Facebook: " + e);
            e.printStackTrace();
        }
    }
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.view.survey.SurveyInteractionView.java

@Override
public void doOnCreate(final Activity activity, Bundle savedInstanceState) {

    if (savedInstanceState != null) {
        surveySubmitted = savedInstanceState.getBoolean(KEY_SURVEY_SUBMITTED, false);
    }/*from   www .  j  ava  2s.  co  m*/

    if (interaction == null || surveySubmitted) {
        activity.finish();
        return;
    }

    activity.setContentView(R.layout.apptentive_survey);

    // Hide branding if needed.
    final View branding = activity.findViewById(R.id.apptentive_branding_view);
    if (branding != null) {
        if (Configuration.load(activity).isHideBranding(activity)) {
            branding.setVisibility(View.GONE);
        }
    }

    TextView title = (TextView) activity.findViewById(R.id.title);
    title.setFocusable(true);
    title.setFocusableInTouchMode(true);
    title.setText(interaction.getName());

    String descriptionText = interaction.getDescription();
    if (descriptionText != null) {
        TextView description = (TextView) activity.findViewById(R.id.description);
        description.setText(descriptionText);
        description.setVisibility(View.VISIBLE);
    }

    final Button send = (Button) activity.findViewById(R.id.send);
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Util.hideSoftKeyboard(activity, view);
            surveySubmitted = true;
            if (interaction.isShowSuccessMessage() && interaction.getSuccessMessage() != null) {
                SurveyThankYouDialog dialog = new SurveyThankYouDialog(activity);
                dialog.setMessage(interaction.getSuccessMessage());
                dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        activity.finish();
                    }
                });
                dialog.show();
            } else {
                activity.finish();
            }

            EngagementModule.engageInternal(activity, interaction, EVENT_SUBMIT, data.toString());
            ApptentiveDatabase.getInstance(activity).addPayload(new SurveyResponse(interaction, surveyState));
            Log.d("Survey Submitted.");
            callListener(true);

            cleanup();
        }
    });

    LinearLayout questions = (LinearLayout) activity.findViewById(R.id.questions);
    questions.removeAllViews();

    // Then render all the questions
    for (final Question question : interaction.getQuestions()) {
        if (question.getType() == Question.QUESTION_TYPE_SINGLELINE) {
            TextSurveyQuestionView textQuestionView = new TextSurveyQuestionView(activity, surveyState,
                    (SinglelineQuestion) question);
            textQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() {
                public void onAnswered() {
                    sendMetricForQuestion(activity, question);
                    send.setEnabled(isSurveyValid());
                }
            });
            questions.addView(textQuestionView);
        } else if (question.getType() == Question.QUESTION_TYPE_MULTICHOICE) {
            MultichoiceSurveyQuestionView multichoiceQuestionView = new MultichoiceSurveyQuestionView(activity,
                    surveyState, (MultichoiceQuestion) question);
            multichoiceQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() {
                public void onAnswered() {
                    sendMetricForQuestion(activity, question);
                    send.setEnabled(isSurveyValid());
                }
            });
            questions.addView(multichoiceQuestionView);
        } else if (question.getType() == Question.QUESTION_TYPE_MULTISELECT) {
            MultiselectSurveyQuestionView multiselectQuestionView = new MultiselectSurveyQuestionView(activity,
                    surveyState, (MultiselectQuestion) question);
            multiselectQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() {
                public void onAnswered() {
                    sendMetricForQuestion(activity, question);
                    send.setEnabled(isSurveyValid());
                }
            });
            questions.addView(multiselectQuestionView);
        }
    }

    send.setEnabled(isSurveyValid());

    // Force the top of the survey to be shown first.
    title.requestFocus();
}