Search in sources :

Example 1 with TextWatcherAdapter

use of com.github.pockethub.android.ui.TextWatcherAdapter in project PocketHub by pockethub.

the class CreateGistActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gist_create);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    descriptionText = finder.find(R.id.et_gist_description);
    nameText = finder.find(R.id.et_gist_name);
    contentText = finder.find(R.id.et_gist_content);
    publicCheckBox = finder.find(R.id.cb_public);
    final AppBarLayout appBarLayout = finder.find(R.id.appbar);
    // Fully expand the AppBar if something in it gets focus
    View.OnFocusChangeListener expandAppBarOnFocusChangeListener = new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                appBarLayout.setExpanded(true);
            }
        }
    };
    nameText.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
    descriptionText.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
    publicCheckBox.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
    // Fully expand the AppBar if something in it changes its value
    TextWatcher expandAppBarTextWatcher = new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            appBarLayout.setExpanded(true);
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            appBarLayout.setExpanded(true);
        }

        @Override
        public void afterTextChanged(Editable s) {
            appBarLayout.setExpanded(true);
        }
    };
    nameText.addTextChangedListener(expandAppBarTextWatcher);
    descriptionText.addTextChangedListener(expandAppBarTextWatcher);
    publicCheckBox.addTextChangedListener(expandAppBarTextWatcher);
    publicCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            appBarLayout.setExpanded(true);
        }
    });
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    String text = ShareUtils.getBody(getIntent());
    if (!TextUtils.isEmpty(text)) {
        contentText.setText(text);
    }
    String subject = ShareUtils.getSubject(getIntent());
    if (!TextUtils.isEmpty(subject)) {
        descriptionText.setText(subject);
    }
    contentText.addTextChangedListener(new TextWatcherAdapter() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateCreateMenu(s);
        }
    });
    updateCreateMenu();
}
Also used : TextWatcherAdapter(com.github.pockethub.android.ui.TextWatcherAdapter) View(android.view.View) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AppBarLayout(android.support.design.widget.AppBarLayout) CompoundButton(android.widget.CompoundButton) ActionBar(android.support.v7.app.ActionBar)

Example 2 with TextWatcherAdapter

use of com.github.pockethub.android.ui.TextWatcherAdapter in project PocketHub by pockethub.

the class RawCommentFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    commentText = finder.find(R.id.et_comment);
    addImageFab = finder.find(R.id.fab_add_image);
    addImageFab.setOnClickListener(new View.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                Fragment fragment = RawCommentFragment.this;
                String permission = Manifest.permission.READ_EXTERNAL_STORAGE;
                if (ContextCompat.checkSelfPermission(getActivity(), permission) != PackageManager.PERMISSION_GRANTED) {
                    PermissionsUtils.askForPermission(fragment, READ_PERMISSION_REQUEST, permission, R.string.read_permission_title, R.string.read_permission_content);
                } else {
                    startImagePicker();
                }
            } else {
                startImagePicker();
            }
        }
    });
    commentText.addTextChangedListener(new TextWatcherAdapter() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            Activity activity = getActivity();
            if (activity != null) {
                activity.invalidateOptionsMenu();
            }
        }
    });
    commentText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            commentText.requestFocusFromTouch();
            return false;
        }
    });
    setText(initComment);
}
Also used : TextWatcherAdapter(com.github.pockethub.android.ui.TextWatcherAdapter) Activity(android.app.Activity) View(android.view.View) TargetApi(android.annotation.TargetApi) DialogFragment(com.github.pockethub.android.ui.DialogFragment) Fragment(android.support.v4.app.Fragment) MotionEvent(android.view.MotionEvent)

Example 3 with TextWatcherAdapter

use of com.github.pockethub.android.ui.TextWatcherAdapter in project PocketHub by pockethub.

the class EditIssueActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_issue_edit);
    titleText = finder.find(R.id.et_issue_title);
    bodyText = finder.find(R.id.et_issue_body);
    milestoneGraph = finder.find(R.id.ll_milestone_graph);
    milestoneText = finder.find(R.id.tv_milestone);
    milestoneClosed = finder.find(R.id.v_closed);
    assigneeAvatar = finder.find(R.id.iv_assignee_avatar);
    assigneeText = finder.find(R.id.tv_assignee_name);
    labelsText = finder.find(R.id.tv_labels);
    addImageFab = finder.find(R.id.fab_add_image);
    Intent intent = getIntent();
    if (savedInstanceState != null) {
        issue = savedInstanceState.getParcelable(EXTRA_ISSUE);
    }
    if (issue == null) {
        issue = intent.getParcelableExtra(EXTRA_ISSUE);
    }
    if (issue == null) {
        issue = Issue.builder().build();
    }
    repository = InfoUtils.createRepoFromData(intent.getStringExtra(EXTRA_REPOSITORY_OWNER), intent.getStringExtra(EXTRA_REPOSITORY_NAME));
    checkCollaboratorStatus();
    setSupportActionBar((android.support.v7.widget.Toolbar) findViewById(R.id.toolbar));
    ActionBar actionBar = getSupportActionBar();
    if (issue.number() != null && issue.number() > 0) {
        if (IssueUtils.isPullRequest(issue)) {
            actionBar.setTitle(getString(R.string.pull_request_title) + issue.number());
        } else {
            actionBar.setTitle(getString(R.string.issue_title) + issue.number());
        }
    } else {
        actionBar.setTitle(R.string.new_issue);
    }
    actionBar.setSubtitle(InfoUtils.createRepoId(repository));
    avatars.bind(actionBar, (User) intent.getParcelableExtra(EXTRA_USER));
    titleText.addTextChangedListener(new TextWatcherAdapter() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            super.onTextChanged(s, start, before, count);
            updateSaveMenu(s);
        }
    });
    addImageFab.setOnClickListener(new View.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                Activity activity = EditIssueActivity.this;
                String permission = Manifest.permission.READ_EXTERNAL_STORAGE;
                if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) {
                    PermissionsUtils.askForPermission(activity, READ_PERMISSION_REQUEST, permission, R.string.read_permission_title, R.string.read_permission_content);
                } else {
                    startImagePicker();
                }
            } else {
                startImagePicker();
            }
        }
    });
    updateSaveMenu();
    titleText.setText(issue.title());
    bodyText.setText(issue.body());
}
Also used : TextWatcherAdapter(com.github.pockethub.android.ui.TextWatcherAdapter) BaseActivity(com.github.pockethub.android.ui.BaseActivity) Activity(android.app.Activity) Intent(android.content.Intent) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TargetApi(android.annotation.TargetApi) ActionBar(android.support.v7.app.ActionBar)

Aggregations

View (android.view.View)3 TextWatcherAdapter (com.github.pockethub.android.ui.TextWatcherAdapter)3 TargetApi (android.annotation.TargetApi)2 Activity (android.app.Activity)2 ActionBar (android.support.v7.app.ActionBar)2 Intent (android.content.Intent)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 Fragment (android.support.v4.app.Fragment)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 MotionEvent (android.view.MotionEvent)1 OnClickListener (android.view.View.OnClickListener)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BaseActivity (com.github.pockethub.android.ui.BaseActivity)1 DialogFragment (com.github.pockethub.android.ui.DialogFragment)1