Example usage for android.view KeyEvent KEYCODE_ENTER

List of usage examples for android.view KeyEvent KEYCODE_ENTER

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_ENTER.

Prototype

int KEYCODE_ENTER

To view the source code for android.view KeyEvent KEYCODE_ENTER.

Click Source Link

Document

Key code constant: Enter key.

Usage

From source file:com.example.messaging.MessageActivity.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
        firebase.child(CHS + "/" + currentChannel + "/history").push()
                .setValue(new Message(messageText.getText().toString(), firebaseUser.getDisplayName()));

        return true;
    }//from  w w w.ja  v  a2 s  .  c o  m
    return false;
}

From source file:com.nttec.everychan.ui.NewTabFragment.java

@SuppressLint("ClickableViewAccessibility")
@Override//from  w ww.  ja v  a 2  s .  co m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    activity.setTitle(R.string.tabs_newtab);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        CompatibilityImpl.setActionBarDefaultIcon(activity);
    View v = inflater.inflate(R.layout.newtab_fragment, container, false);
    listView = (DragSortListView) v.findViewById(android.R.id.list);
    DragSortController controller = new DragSortController(listView, R.id.newtab_quickaccess_drag_handle,
            DragSortController.ON_DRAG, 0) {
        @Override
        public View onCreateFloatView(int position) {
            return adapter.getView(position, null, listView);
        }

        @Override
        public void onDragFloatView(View floatView, Point floatPoint, Point touchPoint) {
        }

        @Override
        public void onDestroyFloatView(View floatView) {
        }
    };
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
    listView.setDragEnabled(true);
    listView.setFloatViewManager(controller);
    listView.setOnTouchListener(controller);
    listView.setDropListener(new DragSortListView.DropListener() {
        @Override
        public void drop(int from, int to) {
            if (from != to) {
                QuickAccess.Entry moved = list.remove(from);
                list.add(to, moved);
                adapter.setDraggingItem(-1);
                saveQuickAccessToPreferences();
            }
        }
    });
    registerForContextMenu(listView);
    addressBar = v.findViewById(R.id.newtab_address_bar);
    openAddressBar = (Button) v.findViewById(R.id.newtab_open_address_bar);
    openAddressBar.setOnClickListener(this);
    addressField = (EditText) v.findViewById(R.id.newtab_address_field);
    addressField.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                onClick(v);
                return true;
            }
            return false;
        }
    });
    addressGo = (Button) v.findViewById(R.id.newtab_address_go);
    addressGo.setOnClickListener(this);
    openLocal = (Button) v.findViewById(R.id.newtab_open_local);
    openLocal.setOnClickListener(this);
    return v;
}

From source file:com.mercandalli.android.apps.files.user.ConversationActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conversation);

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);/*from  ww  w  .  jav  a 2 s  .  com*/
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        Log.e("" + getClass().getName(), "extras == null");
        this.finish();
        this.overridePendingTransition(R.anim.right_in, R.anim.right_out);
        return;
    }

    mInputEditText = (EditText) findViewById(R.id.input);

    mIdConversation = extras.getString("ID_CONVERSATION");
    mUrl = Constants.URL_DOMAIN + Config.ROUTE_USER_MESSAGE + "/" + mIdConversation;

    mProgressBar = (ProgressBar) findViewById(R.id.circularProgressBar);
    mMessageTextView = (TextView) findViewById(R.id.message);

    mRecyclerView = (RecyclerView) findViewById(R.id.listView);
    mRecyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setStackFromEnd(true);
    mRecyclerView.setLayoutManager(linearLayoutManager);

    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light, android.R.color.holo_orange_light,
            android.R.color.holo_red_light);

    this.mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshList();
        }
    });

    mAdapterModelConversationMessage = new AdapterModelConversationMessage(mUserConversationMessageModels);
    mRecyclerView.setAdapter(mAdapterModelConversationMessage);
    mRecyclerView.setItemAnimator(/*new SlideInFromLeftItemAnimator(mRecyclerView)*/new DefaultItemAnimator());
    mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));

    mAdapterModelConversationMessage
            .setOnItemClickListener(new AdapterModelConversationMessage.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {

                }
            });

    mAdapterModelConversationMessage
            .setOnItemLongClickListener(new AdapterModelConversationMessage.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(View view, int position) {

                    return true;
                }
            });

    mInputEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
                    || (actionId == EditorInfo.IME_ACTION_DONE)) {
                String url = Constants.URL_DOMAIN + Config.ROUTE_USER_MESSAGE + "/" + mIdConversation;
                List<StringPair> parameters = new ArrayList<>();
                parameters.add(new StringPair("message", "" + mInputEditText.getText().toString()));
                mInputEditText.setText("");

                new TaskPost(ConversationActivity.this, url, new IPostExecuteListener() {
                    @Override
                    public void onPostExecute(JSONObject json, String body) {
                        refreshList();
                    }
                }, parameters).execute();

                return true;
            }
            return false;
        }
    });

    refreshList();
}

From source file:com.polyvi.xface.extension.inappbrowser.XInAppBrowser.java

/**
 * /*from   ww w  .  ja v  a2 s  .c  o  m*/
 */
protected void buildEditText() {
    RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
    textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
    OnKeyListener keyListener = new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                navigate(mEditText.getText().toString());
                return true;
            }
            return false;
        }
    };
    mEditText = createEditText(EDITTEXT_ID, textLayoutParams, true, mUrl, InputType.TYPE_TEXT_VARIATION_URI,
            EditorInfo.IME_ACTION_GO, keyListener);
}

From source file:de.questmaster.fatremote.fragments.RemoteFragment.java

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

    /* start audio */
    mAudioManager = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.loadSoundEffects();// w  w w .j  a  v a 2 s.  c om

    /* read Settings */
    mSettings.readSettings(c);

    /* setup onClickListener for remote buttons */
    ((ImageView) c.findViewById(R.id.remote_button_power)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_up)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_home)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_left)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_ok)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_right)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_back)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_down)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_info)).setOnClickListener(this);

    ((ImageView) c.findViewById(R.id.textButton)).setOnClickListener(this);

    ((ImageView) c.findViewById(R.id.remote_button_rew)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_menu)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_fwd)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_prev)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_play)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_next)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_volup)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_stop)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_zoomup)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_voldown)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_mute)).setOnClickListener(this);
    ((ImageView) c.findViewById(R.id.remote_button_zoomdown)).setOnClickListener(this);

    /* setup key listener */
    EditText text = (EditText) c.findViewById(R.id.enterText);
    text.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                hideKeyboard();

                return true;
            }
            return false;
        }
    });
    text.addTextChangedListener(determineKeyboardTextChangedListener());
    text.setFocusable(true);

    // check if WIFI available
    if (!NetworkProxy.getInstance(c).isWifiEnabled()) {
        Toast.makeText(c, R.string.app_err_enwifi, Toast.LENGTH_LONG).show();
    }
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

protected void resetContent() {
    comicDef = makeComicDef();//from   w  ww .j  a va 2 s.  c  o  m
    provider = comicDef.getProvider();
    comicInfo = provider.createEmptyComicInfo();

    //Only hide the title bar if we're running an android less than Android 3.0
    if (VersionHacks.getSdkInt() < 11)
        requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);
    webview = (HackedWebView) findViewById(R.id.viewer);
    title = (TextView) findViewById(R.id.title);
    comicIdSel = (EditText) findViewById(R.id.comicIdSel);

    webview.requestFocus();
    zoom = webview.getZoomControls();

    webview.setClickable(true);
    webview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!"".equals(comicInfo.getAlt()))
                showDialog(DIALOG_SHOW_HOVER_TEXT);
        }
    });

    title.setText(comicInfo.getTitle());

    comicIdSel.setText(comicInfo.getId());
    if (comicDef.idsAreNumbers())
        comicIdSel.setInputType(InputType.TYPE_CLASS_NUMBER);
    comicIdSel.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            String text = comicIdSel.getText().toString();
            if (!text.equals("") && (actionId == EditorInfo.IME_ACTION_GO
                    || (actionId == EditorInfo.IME_NULL && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                loadComic(createComicUri(text));
                comicIdSel.setText("");
                return true;
            }
            return false;
        }
    });
    comicIdSel.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (hasFocus) {
                comicIdSel.setText("");
                imm.showSoftInput(comicIdSel, InputMethodManager.SHOW_IMPLICIT);
            } else {
                imm.hideSoftInputFromWindow(comicIdSel.getWindowToken(), 0);
            }
        }
    });

    ((Button) findViewById(R.id.firstBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToFirst();
        }
    });

    ((Button) findViewById(R.id.prevBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToPrev();
        }
    });

    ((Button) findViewById(R.id.nextBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToNext();
        }
    });

    ((Button) findViewById(R.id.finalBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToFinal();
        }
    });

    ((ImageView) findViewById(R.id.randomBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToRandom();
        }
    });

    bookmarkBtn = (ImageView) findViewById(R.id.bookmarkBtn);
    bookmarkBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            toggleBookmark();
        }
    });
    refreshBookmarkBtn();
}

From source file:net.olejon.mdapp.MedicationActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Intent//w ww .  ja  v a2s.co  m
    final Intent intent = getIntent();

    medicationId = intent.getLongExtra("id", 0);

    if (medicationId == 0) {
        mTools.showToast(getString(R.string.medication_could_not_find_medication), 1);

        finish();

        return;
    }

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout
    setContentView(R.layout.activity_medication);

    // View
    mRelativeLayout = (RelativeLayout) findViewById(R.id.medication_inner_layout);

    // Toolbar
    mToolbar = (Toolbar) findViewById(R.id.medication_toolbar);
    mToolbar.setTitle("");

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.medication_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.medication_toolbar_search);

    // View pager
    mViewPager = (ViewPager) findViewById(R.id.medication_pager);

    // Find in text
    mToolbarSearchEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            String find = mToolbarSearchEditText.getText().toString().trim();

            if (find.equals("")) {
                if (mWebView != null)
                    mWebView.clearMatches();
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    if (mWebView != null)
                        mWebView.findAllAsync(find);
                } else {
                    if (mWebView != null) {
                        //noinspection deprecation
                        mWebView.findAll(find);
                    }
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                return true;
            }

            return false;
        }
    });
}

From source file:com.lemon.lime.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getBatteryPercentage();//from   ww  w .ja  v a  2s .c o m
    setContentView(R.layout.activity_main);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    mWebView = (ObservableWebView) findViewById(R.id.activity_main_webview);
    mWebView.setScrollViewCallbacks(this);
    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflator.inflate(R.layout.bar, null);
    getSupportActionBar().setCustomView(v);

    WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());

    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mWebView.reload();
        }
    });
    swipeLayout.setColorSchemeResources(R.color.lili, R.color.colorPrimary, R.color.red);

    window = getWindow();
    favicon = (ImageView) findViewById(R.id.favicon);
    editurl = (EditText) findViewById(R.id.editurl);
    mWebView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {

            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }

    });

    favicon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (lili == 5) {
                lilimode();
                lili = 0;
                lilimode = true;
            } else {
                lili = lili + 1;
            }
        }
    });

    editurl.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                if (event.getAction() == KeyEvent.ACTION_UP) {
                    if (editurl.getText().toString().contains("file:///")) {
                        filemgr();
                    } else if (editurl.getText().toString().contains("gaymode")) {
                        gaymode();
                    } else if (editurl.getText().toString().contains("exitapp")) {
                        finish();
                    } else if (editurl.getText().toString().contains("light")) {
                        flash();
                    }

                    if (isconnected()) {
                        if (editurl.getText().toString().contains("http://")
                                || editurl.getText().toString().contains("https://")) {
                            mWebView.loadUrl(editurl.getText().toString());

                        } else if (editurl.getText().toString().contains(".com")
                                || editurl.getText().toString().contains(".net")
                                || editurl.getText().toString().contains(".org")
                                || editurl.getText().toString().contains(".gov")
                                || editurl.getText().toString().contains(".hu")
                                || editurl.getText().toString().contains(".sk")
                                || editurl.getText().toString().contains(".co.uk")
                                || editurl.getText().toString().contains(".co.in")
                                || editurl.getText().toString().contains(".cn")
                                || editurl.getText().toString().contains(".it")
                                || editurl.getText().toString().contains(".de")
                                || editurl.getText().toString().contains(".aus")
                                || editurl.getText().toString().contains(".hr")
                                || editurl.getText().toString().contains(".cz")
                                || editurl.getText().toString().contains(".xyz")
                                || editurl.getText().toString().contains(".pl")
                                || editurl.getText().toString().contains(".io")) {
                            mWebView.loadUrl("http://" + editurl.getText().toString());

                            InputMethodManager imm = (InputMethodManager) getSystemService(
                                    Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0);

                        } else {
                            mWebView.loadUrl("https://www.google.com/search?q=" + editurl.getText().toString());

                            InputMethodManager imm = (InputMethodManager) getSystemService(
                                    Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0);
                        }
                    }
                    return true;
                }
                return false;
            }

            return true;
        }
    });
    // Enable Javascript
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setSupportMultipleWindows(true);

    if (isconnected()) {
        mWebView.loadUrl("http://google.com");
    } else {

        final View coordinatorLayoutView = findViewById(R.id.snackbarPosition);
        mWebView.loadUrl("file:///android_asset/nonet.html");
        Snackbar snackbar = Snackbar.make(coordinatorLayoutView, R.string.offline, Snackbar.LENGTH_LONG);
        snackbar.show();

    }

    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onReceivedIcon(WebView mWebView, Bitmap icon) {
            super.onReceivedIcon(mWebView, icon);
            favicon.setImageBitmap(icon);
        }

        public void onProgressChanged(WebView view, int progress) {
            activity.setProgress(progress * 100);
            int a = progress;
            if (lilimode) {
                editurl.setText("Liling: " + Integer.toString(a) + "?");
            } else
                editurl.setText("Liming: " + Integer.toString(a) + "%");
            if (progress == 100) {

                editurl.setHint(view.getTitle());
                activity.setTitle(view.getTitle());
                editurl.setText(view.getUrl());

                fav();

                //battery
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    if (level <= 20) {
                        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                        window.setNavigationBarColor(Color.RED);
                        window.setStatusBarColor(Color.RED);
                        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.RED));
                    }
                }
            }
        }
    });

    mWebView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView mWebView, String url) {
            swipeLayout.setRefreshing(false);
        }
    });

}

From source file:io.github.prefanatic.cleantap.ui.BeerSearchActivity.java

private void searchViewEvent(TextViewEditorActionEvent event) {
    if (event.actionId() == EditorInfo.IME_ACTION_SEARCH
            || (event.keyEvent().getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.keyEvent().getAction() == KeyEvent.ACTION_UP)) {
        recyclerView.setNestedScrollingEnabled(false);
        presenter.searchForBeer(searchView.getText().toString());

        AnimUtils.show(progress);/*from   w w w . j  a  v  a2 s  .com*/
        AnimUtils.hide(helpText);
    }
}

From source file:com.todoroo.astrid.notes.EditNoteActivity.java

private void setUpInterface() {
    timerView = commentsBar.findViewById(R.id.timer_container);
    commentButton = commentsBar.findViewById(R.id.commentButton);
    commentField = (EditText) commentsBar.findViewById(R.id.commentField);

    final boolean showTimerShortcut = preferences.getBoolean(R.string.p_show_timer_shortcut, false);

    if (showTimerShortcut) {
        commentField.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override/*from w  w w.j  ava2s  .  co  m*/
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    timerView.setVisibility(View.GONE);
                    commentButton.setVisibility(View.VISIBLE);
                } else {
                    timerView.setVisibility(View.VISIBLE);
                    commentButton.setVisibility(View.GONE);
                }
            }
        });
    }
    commentField.setHorizontallyScrolling(false);
    commentField.setMaxLines(Integer.MAX_VALUE);
    commentField.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                AndroidUtilities.hideSoftInputForViews(activity, commentField);
                return true;
            }
            return false;
        }
    });
    commentField.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            commentField.setCursorVisible(true);
        }
    });

    commentField.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            commentButton.setVisibility(
                    (s.length() > 0 || pendingCommentPicture != null) ? View.VISIBLE : View.GONE);
            if (showTimerShortcut) {
                timerView.setVisibility(
                        (s.length() > 0 || pendingCommentPicture != null) ? View.GONE : View.VISIBLE);
            }
        }

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

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

    commentField.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (commentField.getText().length() > 0) {
                if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) {
                    //                        commentField.setCursorVisible(false);
                    addComment();
                }
            }
            return false;
        }
    });

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

    final ClearImageCallback clearImage = new ClearImageCallback() {
        @Override
        public void clearImage() {
            pendingCommentPicture = null;
            pictureButton.setImageResource(cameraButton);
        }
    };
    pictureButton = (ImageButton) commentsBar.findViewById(R.id.picture);
    pictureButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (pendingCommentPicture != null) {
                actFmCameraModule.showPictureLauncher(clearImage);
            } else {
                actFmCameraModule.showPictureLauncher(null);
            }
            respondToPicture = true;
        }
    });
    if (!TextUtils.isEmpty(task.getNotes())) {
        TextView notes = new TextView(getContext());
        notes.setLinkTextColor(Color.rgb(100, 160, 255));
        notes.setTextSize(18);
        notes.setText(task.getNotes());
        notes.setPadding(5, 10, 5, 10);
        Linkify.addLinks(notes, Linkify.ALL);
    }

    if (activity != null) {
        String uri = activity.getIntent().getStringExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS);
        if (uri != null) {
            pendingCommentPicture = Uri.parse(uri);
            setPictureButtonToPendingPicture();
        }
    }
}