Example usage for android.text TextWatcher TextWatcher

List of usage examples for android.text TextWatcher TextWatcher

Introduction

In this page you can find the example usage for android.text TextWatcher TextWatcher.

Prototype

TextWatcher

Source Link

Usage

From source file:com.ritul.truckshare.RegisterActivity.DriverLicenseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_driver_license);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ProgDialog = new Prog_Dialog(this);
    setSupportActionBar(toolbar);/* ww  w. j  av a 2 s. co  m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    preview = (ImageView) findViewById(R.id.imgLicence);
    Button b = (Button) findViewById(R.id.BtnDriverBrowse);
    staticSpinner = (Spinner) findViewById(R.id.txtLicenseIssue);

    txtLicenseNumber = (EditText) findViewById(R.id.txtLicenseNumber);
    txtLicenseExpire = (EditText) findViewById(R.id.txtLicenseExpire);

    userHierarchy = new ArrayList<>();
    if (AppConstant.isNetworkAvailable(this)) {
        try {
            state_spiner();
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    } else {
        AppConstant.showNetworkError(this);
    }
    staticSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            //CountryPosition = (userHierarchy.get(position).toString());
            countryPosition = userHierarchy.get(position).getStateId();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            /*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();*/
            if (CheckValidation()) {
                LicenseIssuedStateId = countryPosition;
                LicenseNumber = txtLicenseNumber.getText().toString();
                LicenseExpiryDate = txtLicenseExpire.getText().toString();
                LicenseImageBase64String = imagedata;

                Intent intent = new Intent(getApplicationContext(), TruckActivity.class);
                startActivity(intent);
            }
        }
    });

    txtLicenseExpire.addTextChangedListener(new TextWatcher() {
        int prevL = 0;

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            prevL = txtLicenseExpire.getText().toString().length();
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            int length = editable.length();
            if ((prevL < length) && (length == 2 || length == 5)) {
                editable.append("/");
            }
        }
    });

    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Image_Picker_Dialog();
        }
    });

}

From source file:com.janardhan.blood2life.CommentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_comments, container, false);
    Log.d("mPostRef", mPostRef);
    db = new SQLiteHandler(getActivity());
    user_ = db.getUserDetails();//from   www  .j  a  v  a 2s.  c  o m
    RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list);
    mEditText = (EditText) rootView.findViewById(R.id.editText);
    final Button sendButton = (Button) rootView.findViewById(R.id.send_comment);

    final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef);
    mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item,
            CommentViewHolder.class, commentsRef) {
        @Override
        protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) {
            String aurth = comment.getAuthor();

            viewHolder.commentAuthor.setText(comment.getAuthor());
            GlideUtil.loadProfileIcon(comment.getUser_propic(), viewHolder.commentPhoto);

            viewHolder.authorRef = comment.getUser_id();
            viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp()));
            viewHolder.commentText.setText(comment.getText());
        }
    };
    sendButton.setEnabled(false);
    mEditText.setHint(R.string.new_comment_hint);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) });
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                sendButton.setEnabled(true);
            } else {
                sendButton.setEnabled(false);
            }
        }
    });
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Clear input box and hide keyboard.
            final Editable commentText = mEditText.getText();
            mEditText.setText("");
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user == null) {
                Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show();
            }

            Comment comment = new Comment(user.getDisplayName(), commentText.toString(), ServerValue.TIMESTAMP,
                    user_.get("uid"), user_.get("profile_pic_url"));
            commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError error, DatabaseReference firebase) {
                    if (error != null) {
                        Log.w(TAG, getString(R.string.error_posting) + error.getMessage());
                        Toast.makeText(getActivity(), R.string.error_posting, Toast.LENGTH_SHORT).show();
                        mEditText.setText(commentText);
                    }
                }
            });
        }
    });
    mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mCommentsView.setAdapter(mAdapter);
    return rootView;
}

From source file:com.madgag.agit.CloneLauncherActivity.java

/**
 * Called when the activity is first created.
 *//* w ww .  j a v  a 2  s.  co m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    fixImageTilingOn(getSupportActionBar());
    setContentView(R.layout.clone_launcher);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(clone_launcher_activity_title);

    button.setOnClickListener(goCloneButtonListener);
    OnCheckedChangeListener checkBoxChangeListener = new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateUIWithValidation();
        }
    };
    useDefaultGitDirLocationButton.setOnCheckedChangeListener(checkBoxChangeListener);
    bareRepoCheckbox.setOnCheckedChangeListener(checkBoxChangeListener);
    TextWatcher watcher = new TextWatcher() {
        public void onTextChanged(CharSequence text, int arg1, int arg2, int arg3) {
        }

        public void beforeTextChanged(CharSequence text, int arg1, int arg2, int arg3) {
        }

        public void afterTextChanged(Editable gitDirEditText) {
            updateUIWithValidation();
        }
    };
    cloneUrlEditText.addTextChangedListener(watcher);
    gitDirEditText.addTextChangedListener(watcher);
}

From source file:com.activiti.android.ui.fragments.comment.CommentsFoundationFragment.java

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

    init(getRootView(), R.string.task_help_add_comment);

    commentText = (EditText) viewById(R.id.comment_value);

    bAdd = (ImageButton) viewById(R.id.send_comment);
    bAdd.setEnabled(false);//from  w ww  .j ava  2s  .c o  m

    bAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addcomment();
        }
    });

    commentText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            activateSend();
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    commentText.setImeOptions(EditorInfo.IME_ACTION_SEND);
    commentText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                    && ((actionId == EditorInfo.IME_ACTION_SEND))) {
                addcomment();
                return true;
            }
            return false;
        }
    });

    gv.setSelector(android.R.color.transparent);
    gv.setCacheColorHint(getResources().getColor(android.R.color.transparent));

    return getRootView();
}

From source file:com.fimo_pitch.fragments.SearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    try {/*from  w  ww .j  a v  a2s  . c o m*/
        View view = inflater.inflate(R.layout.fragment_search, container, false);
        okHttpClient = new OkHttpClient();
        directionSteps = new ArrayList<>();
        polylines = new ArrayList<>();
        listSystemPitch = new ArrayList<>();
        tmpList = new ArrayList<>();
        resultLatLng = new LatLng(0.0, 0.0);

        //            bt_search  =  (RoundedImageView) view.findViewById(R.id.bt_search);
        bt_currentLocation = (ImageView) view.findViewById(R.id.bt_currentLocation);
        bt_clear = (ImageView) view.findViewById(R.id.bt_clear);
        bt_clear.setOnClickListener(this);
        bt_currentLocation.setOnClickListener(this);
        spinner_location = (Spinner) view.findViewById(R.id.spn_location);

        edt_search = (EditText) view.findViewById(R.id.edt_search);
        edt_search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                try {
                    drawMarker(filterByText(s.toString()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                tmpList = filterByAddress(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        spinner_location.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), R.layout.spinner_item2,
                getActivity().getResources().getStringArray(R.array.listProvince));
        spinner_location.setAdapter(adapter);
        spinner_location.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position != 0) {
                    try {
                        drawMarker(filterByAddress(spinner_location.getItemAtPosition(position).toString()));
                    } catch (Exception e) {
                        Utils.openDialog(getContext(), "? c li xy ra. Vui lng th li sau");
                        e.printStackTrace();
                    }
                    tmpList = filterByAddress(spinner_location.getItemAtPosition(position).toString());
                } else
                    try {
                        drawMarker(listSystemPitch);
                    } catch (Exception e) {
                        e.printStackTrace();
                        Utils.openDialog(getContext(), "? c li xy ra. Vui lng th li sau");
                    }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        mapFragment = new SupportMapFragment();
        if (mapFragment != null) {
            mapFragment.getMapAsync(this);
        }
        getChildFragmentManager().beginTransaction().add(R.id.fragment_map, mapFragment).commit();
        return view;
    } catch (Exception e) {
        Utils.openDialog(getContext(), "? c li xy ra. Vui lng th li sau");
        e.printStackTrace();
        return inflater.inflate(R.layout.empty, container, false);
    }
}

From source file:app.CT.BTCCalculator.fragments.ProfitFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    View view = getView();//from   w w  w.jav a  2 s .com
    BusProvider.getInstance().register(this);

    // Initialize text fields.
    assert view != null;
    btcBought = (EditText) view.findViewById(R.id.btcBought);
    btcBoughtPrice = (EditText) view.findViewById(R.id.btcBoughtPrice);
    btcSell = (EditText) view.findViewById(R.id.btcSell);
    btcSellPrice = (EditText) view.findViewById(R.id.btcSellPrice);
    transPercent = (EditText) view.findViewById(R.id.transPercent);

    feeTransResult = (TextView) view.findViewById(R.id.transFeeCost);
    subtotalResult = (TextView) view.findViewById(R.id.subtotal);
    totalProfitResult = (TextView) view.findViewById(R.id.totalProfit);

    Button calculate = (Button) view.findViewById(R.id.calculate);

    // EditText element is clicked in order to enable and show the keyboard to the user.
    // The corresponding XML element has android:imeOptions="actionNext".
    // All EditText elements below are now programmed to show keyboard when pressed.
    btcBought.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcBoughtPrice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcSell.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcSellPrice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcBoughtPrice.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            containsCurrentRate[0] = false;
        }
    });

    btcSellPrice.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            containsCurrentRate[1] = false;
        }
    });

    calculate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            float buyAmount, buyCost, sellAmount, sellPrice, subtotalCost, subtotalPrice, subtotal, fee, total;

            boolean validTrans = true;
            boolean didItWork = true;

            // Error checking to prevent crashes.
            try {
                // Gets the input entered from the user.
                buyAmount = Float.valueOf(btcBought.getText().toString());
                buyCost = Float.valueOf(btcBoughtPrice.getText().toString());
                sellAmount = Float.valueOf(btcSell.getText().toString());
                sellPrice = Float.valueOf(btcSellPrice.getText().toString());

                feePercent = (Float.valueOf(transPercent.getText().toString())) / 100.0f;

                if (sellAmount > buyAmount) {
                    // Create new dialog popup.
                    final AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());

                    alertDialog.setTitle("Error");
                    alertDialog.setMessage("You cannot sell more than you own.");
                    alertDialog.setCancelable(false);
                    alertDialog.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // If this button is clicked, close current dialog.
                            dialog.cancel();
                        }
                    });
                    alertDialog.show();

                    validTrans = false;
                }

                // Calculations to output.
                subtotalCost = buyAmount * buyCost;
                subtotalPrice = sellPrice * sellAmount;
                subtotal = subtotalPrice - subtotalCost;

                fee = subtotalPrice * feePercent;
                total = subtotal - fee;

                if (validTrans) {
                    feeTransResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(fee))));
                    subtotalResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(subtotal))));
                    totalProfitResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(total))));
                }
            } catch (Exception e) {
                // Sets bool to false in order to execute "finally" block below.
                didItWork = false;
            } finally {
                if (!didItWork) {
                    // Creates new dialog popup.
                    final AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(getActivity());

                    alertDialog2.setTitle("Error");
                    alertDialog2.setMessage("Please fill in all fields.");
                    alertDialog2.setCancelable(false);
                    alertDialog2.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // If this button is clicked, close current dialog.
                            dialog.cancel();
                        }
                    });

                    // Show the dialog.
                    alertDialog2.show();
                }
            }
        }
    });

}

From source file:mp.paschalis.BookSearchActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    resultsShowing = false;//from  w w  w . j  a v a2 s.  c  om

    app = (App) getApplication();
    setContentView(R.layout.activity_book_search);

    app.selectedBook = null;

    linearLayoutSearchLayout = (LinearLayout) findViewById(R.id.linearLayoutSearchLayout);
    editTextSearchKeyword = (EditText) findViewById(R.id.editTextSearchKeyword);
    spinnerColumnSelect = (Spinner) findViewById(R.id.spinnerSearchSelectColumn);
    buttonSearch = (Button) findViewById(R.id.buttonSearchBookSearch);
    progressBarSearchButton = (ProgressBar) findViewById(R.id.progressBarSearchSearchButton);
    listViewBookResults = (ListView) findViewById(R.id.listViewBookResults);
    textViewSearchResults = (TextView) findViewById(R.id.textViewSearchSearchResults);
    arrayListSearchResultBooks = new ArrayList<Book>();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Create adapter for the Spinner
    adapterSearchColumns = ArrayAdapter.createFromResource(this, R.array.ArraySearchColumns,
            android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapterSearchColumns.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner

    spinnerColumnSelect.setAdapter(adapterSearchColumns);

    isItemChecked = false;

    editTextSearchKeyword.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == 0) {
                buttonSearch.setEnabled(false);
            } else {
                buttonSearch.setEnabled(true);
            }

        }
    });

    // When button is pressed
    buttonSearch.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            dataClassSearch = new DataClassSearch();
            dataClassSearch.column = getResources().getStringArray(
                    R.array.ArraySearchColumnValues)[spinnerColumnSelect.getSelectedItemPosition()];
            dataClassSearch.keyword = editTextSearchKeyword.getText().toString();

            // Re-init results
            arrayListSearchResultBooks = new ArrayList<Book>();

            new AsyncTaskSearchBooks().execute(dataClassSearch);
        }
    });

    listViewBookResults.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
            app.selectedBook = (Book) (listViewBookResults.getItemAtPosition(pos));

            listViewBookResults.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
            listViewBookResults.setItemChecked(pos, true);

            isItemChecked = true;

            // Recreate the menu
            invalidateOptionsMenu();

        }
    });

    listViewBookResults.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {

            app.selectedBook = (Book) (listViewBookResults.getItemAtPosition(pos));

            // Open Book
            {
                // If user owns that book, open edit book
                if (app.selectedBook.status != App.BOOK_STATE_USER_DONT_OWNS) {
                    // Workaround - Change the status of
                    // book, to users
                    // specific status
                    for (Book.DataClassUser u : app.selectedBook.owners) {
                        // Find real status for that book
                        if (u.username.equalsIgnoreCase(app.user.username)) {
                            app.selectedBook.status = u.status;
                            break;
                        }
                    }

                    Intent intent = new Intent(BookSearchActivity.this, EditBookActivity.class);

                    intent.putExtra(App.ExtrasForEditBookActivityFromBookSearch, true);

                    openedEditBook = true;

                    startActivity(intent);
                } else {
                    Boolean isAvail = false;

                    // Find all users who lent this book
                    for (Book.DataClassUser u : app.selectedBook.owners) {
                        if (u.status == App.BOOK_STATE_USER_AVAILABLE) {
                            isAvail = true;
                        }
                    }

                    Intent intent = new Intent(BookSearchActivity.this, WatchBookActivity.class);

                    intent.putExtra(App.ExtrasForWatchBookActivityFromBookSearch, isAvail);

                    startActivity(intent);
                }

            }

            return true;

        }

    });

}

From source file:com.devgmail.mitroshin.totutu.controllers.ListFragment.java

@Nullable
@Override// w  ww. j a  v a  2 s.  com
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_list, container, false);

    mListView = (ListView) view.findViewById(R.id.list_list_view);
    mListView.setOnItemClickListener(this);

    mSearchEditText = (EditText) view.findViewById(R.id.list_edit_search);

    //          ??    ?    ,   ??
    //          . ? ? ?  ?? ?  
    mDirectionType = (String) getActivity().getIntent().getSerializableExtra(EXTRA_DIRECTION_TYPE);

    //         ? ?    ? ?  ? ??  
    //         ,   ?? ? ?   
    //         ?  ? Info.
    mCursor = mDatabaseHelper.database.rawQuery(generateDefaultQuery(mDirectionType), null);

    //          ? ?  ?  .
    //         ? ?  ,   ?   ??.
    stationsCursorAdapter = new StationCursorAdapter(getActivity().getApplicationContext(), mCursor);

    if (!mSearchEditText.getText().toString().isEmpty()) {
        stationsCursorAdapter.getFilter().filter(mSearchEditText.getText().toString());
    }

    mSearchEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        //   ?   ,  ??? ?
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            System.out.println("    *** Text Change *** ");
            stationsCursorAdapter.getFilter().filter(s.toString());
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    stationsCursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {
        @Override
        public Cursor runQuery(CharSequence constraint) {

            System.out.println("    *** Run Query *** ");

            if (constraint == null || constraint.length() == 0) {

                System.out.println("    *** Constraint == null || or length == 0 *** ");

                return mDatabaseHelper.database.rawQuery(generateDefaultQuery(mDirectionType), null);
            } else {

                System.out.println("    *** Constraint != null *** ");

                return mDatabaseHelper.database.rawQuery(generateSearchQuery(mDirectionType),
                        new String[] { "%" + constraint.toString() + "%" });
            }
        }
    });

    mListView.setAdapter(stationsCursorAdapter);

    return view;
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.holder.MessageComposerHolder.java

public void bindView(final MessageCenterFragment fragment, final MessageCenterRecyclerViewAdapter adapter,
        final Composer composer) {
    title.setText(composer.title);//from  ww w .  j a va2  s  .  co  m

    closeButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (!TextUtils.isEmpty(message.getText().toString().trim()) || !images.isEmpty()) {
                Bundle bundle = new Bundle();
                bundle.putString("message", composer.closeBody);
                bundle.putString("positive", composer.closeDiscard);
                bundle.putString("negative", composer.closeCancel);
                ApptentiveAlertDialog.show(fragment, bundle,
                        Constants.REQUEST_CODE_CLOSE_COMPOSING_CONFIRMATION);
            } else {
                if (adapter.getListener() != null) {
                    adapter.getListener().onCancelComposing();
                }
            }
        }
    });

    sendButton.setContentDescription(composer.sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (adapter.getListener() != null) {
                adapter.getListener().onFinishComposing();
            }
        }
    });

    message.setHint(composer.messageHint);

    message.removeTextChangedListener(textWatcher);
    textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            if (adapter.getListener() != null) {
                adapter.getListener().beforeComposingTextChanged(charSequence);
            }
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            if (adapter.getListener() != null) {
                adapter.getListener().onComposingTextChanged(charSequence);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (adapter.getListener() != null) {
                adapter.getListener().afterComposingTextChanged(editable.toString());
            }
            Linkify.addLinks(editable,
                    Linkify.WEB_URLS | Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.MAP_ADDRESSES);
        }
    };
    message.addTextChangedListener(textWatcher);

    attachButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (adapter.getListener() != null) {
                adapter.getListener().onAttachImage();
            }
        }
    });

    attachments.setupUi();
    attachments.setupLayoutListener();
    attachments.setListener(new ApptentiveImageGridView.ImageItemClickedListener() {
        @Override
        public void onClick(int position, ImageItem image) {
            if (adapter.getListener() != null) {
                adapter.getListener().onClickAttachment(position, image);
            }
        }
    });
    attachments.setAdapterIndicator(R.drawable.apptentive_ic_remove_attachment);

    attachments.setImageIndicatorCallback(fragment);
    //Initialize image attachments band with empty data
    clearImageAttachmentBand();
    attachments.setVisibility(View.GONE);
    attachments.setData(new ArrayList<ImageItem>());
    setAttachButtonState();

    if (adapter.getListener() != null) {
        adapter.getListener().onComposingViewCreated(this, message, attachments);
    }
}

From source file:com.bjerva.tsplex.fragments.PagerFragment.java

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
    final Locale swedishLocale = new Locale("sv", "SE");
    InputMethodManager imm;/*  w w  w.j  a v a  2  s .  c  o m*/
    switch (item.getItemId()) {
    case MainActivity.ID_SEARCH_BUTTON:
        search = (EditText) item.getActionView();

        final SignListFragment signListFragment = (SignListFragment) mAdapter.getItem(0);
        search.requestFocus();
        search.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable s) {
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void onTextChanged(CharSequence cs, int start, int before, int count) {
                signListFragment.getmAdapter().getFilter().filter(cs);
                try {
                    String word = ((SimpleGson) signListFragment.getListView().getItemAtPosition(0)).getWord();
                    signListFragment.getTextHeader().setText(word.substring(0, 1).toUpperCase(swedishLocale));
                } catch (IndexOutOfBoundsException e) {
                    Log.w("IndexErr", "IndexErr after change text");
                }
                signListFragment.setOldSearch(cs.toString());
            }

        });
        search.setText("");
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        break;
    case MainActivity.ID_COLLAPSE_BUTTON:
        ((SignCategoryFragment) mAdapter.getItem(1)).collapseaAll();
        break;
    case MainActivity.ID_EDIT_BUTTON:
        FavouritesFragment favFrag = (FavouritesFragment) mAdapter.getItem(2);
        mMenu.clear();
        if (!favFrag.checkBoxesVisible()) {
            mMenu.add(0, MainActivity.ID_EDIT_BUTTON, 1, R.string.edit_favs).setIcon(R.drawable.recyclebin)
                    .setShowAsAction(
                            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
            ;
        } else {
            favFrag.deleteChecked();
            mMenu.add(0, MainActivity.ID_EDIT_BUTTON, 1, R.string.edit_favs).setIcon(R.drawable.edit_query)
                    .setShowAsAction(
                            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
            ;
        }
        ma.onPrepareOptionsMenu(mMenu);
        favFrag.toggleCheckBoxes();
        break;
    }
    return true;
}