Example usage for android.text InputType TYPE_TEXT_FLAG_CAP_SENTENCES

List of usage examples for android.text InputType TYPE_TEXT_FLAG_CAP_SENTENCES

Introduction

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

Prototype

int TYPE_TEXT_FLAG_CAP_SENTENCES

To view the source code for android.text InputType TYPE_TEXT_FLAG_CAP_SENTENCES.

Click Source Link

Document

Flag for #TYPE_CLASS_TEXT : capitalize the first character of each sentence.

Usage

From source file:org.telegram.ui.Components.ShareAlert.java

public ShareAlert(final Context context, MessageObject messageObject, final String text, boolean publicChannel,
        final String copyLink) {
    super(context, true);

    shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow);

    linkToCopy = copyLink;/*from   w w w . ja v  a2s .  c  o  m*/
    sendingMessageObject = messageObject;
    searchAdapter = new ShareSearchAdapter(context);
    isPublicChannel = publicChannel;
    sendingText = text;

    if (publicChannel) {
        loadingLink = true;
        TLRPC.TL_channels_exportMessageLink req = new TLRPC.TL_channels_exportMessageLink();
        req.id = messageObject.getId();
        req.channel = MessagesController.getInputChannel(messageObject.messageOwner.to_id.channel_id);
        ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
            @Override
            public void run(final TLObject response, TLRPC.TL_error error) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        if (response != null) {
                            exportedMessageLink = (TLRPC.TL_exportedMessageLink) response;
                            if (copyLinkOnEnd) {
                                copyLink(context);
                            }
                        }
                        loadingLink = false;
                    }
                });
            }
        });
    }

    containerView = new FrameLayout(context) {

        private boolean ignoreLayout = false;

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) {
                dismiss();
                return true;
            }
            return super.onInterceptTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent e) {
            return !isDismissed() && super.onTouchEvent(e);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int height = MeasureSpec.getSize(heightMeasureSpec);
            if (Build.VERSION.SDK_INT >= 21) {
                height -= AndroidUtilities.statusBarHeight;
            }
            int size = Math.max(searchAdapter.getItemCount(), listAdapter.getItemCount());
            int contentSize = AndroidUtilities.dp(48)
                    + Math.max(3, (int) Math.ceil(size / 4.0f)) * AndroidUtilities.dp(100)
                    + backgroundPaddingTop;
            int padding = contentSize < height ? 0 : height - (height / 5 * 3) + AndroidUtilities.dp(8);
            if (gridView.getPaddingTop() != padding) {
                ignoreLayout = true;
                gridView.setPadding(0, padding, 0, AndroidUtilities.dp(8));
                ignoreLayout = false;
            }
            super.onMeasure(widthMeasureSpec,
                    MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            updateLayout();
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }

        @Override
        protected void onDraw(Canvas canvas) {
            shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(),
                    getMeasuredHeight());
            shadowDrawable.draw(canvas);
        }
    };
    containerView.setWillNotDraw(false);
    containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0);

    frameLayout = new FrameLayout(context);
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.background));
    frameLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    doneButton = new LinearLayout(context);
    doneButton.setOrientation(LinearLayout.HORIZONTAL);
    doneButton.setBackgroundDrawable(
            Theme.createBarSelectorDrawable(Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false));
    doneButton.setPadding(AndroidUtilities.dp(21), 0, AndroidUtilities.dp(21), 0);
    frameLayout.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
    doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (selectedDialogs.isEmpty() && (isPublicChannel || linkToCopy != null)) {
                if (linkToCopy == null && loadingLink) {
                    copyLinkOnEnd = true;
                    Toast.makeText(ShareAlert.this.getContext(),
                            LocaleController.getString("Loading", R.string.Loading), Toast.LENGTH_SHORT).show();
                } else {
                    copyLink(ShareAlert.this.getContext());
                }
                dismiss();
            } else {
                if (sendingMessageObject != null) {
                    ArrayList<MessageObject> arrayList = new ArrayList<>();
                    arrayList.add(sendingMessageObject);
                    for (HashMap.Entry<Long, TLRPC.TL_dialog> entry : selectedDialogs.entrySet()) {
                        SendMessagesHelper.getInstance().sendMessage(arrayList, entry.getKey());
                    }
                } else if (sendingText != null) {
                    for (HashMap.Entry<Long, TLRPC.TL_dialog> entry : selectedDialogs.entrySet()) {
                        SendMessagesHelper.getInstance().sendMessage(sendingText, entry.getKey(), null, null,
                                true, null, null, null);
                    }
                }
                dismiss();
            }
        }
    });

    doneButtonBadgeTextView = new TextView(context);
    doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    doneButtonBadgeTextView.setTextColor(Theme.SHARE_SHEET_BADGE_TEXT_COLOR);
    doneButtonBadgeTextView.setGravity(Gravity.CENTER);
    doneButtonBadgeTextView.setBackgroundResource(R.drawable.bluecounter);
    doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23));
    doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8),
            AndroidUtilities.dp(1));
    doneButton.addView(doneButtonBadgeTextView,
            LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0));

    doneButtonTextView = new TextView(context);
    doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    doneButtonTextView.setGravity(Gravity.CENTER);
    doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
    doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.search_share);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    imageView.setPadding(0, AndroidUtilities.dp(2), 0, 0);
    imageView.getDrawable().setTint(Theme.SHARE_SHEET_EDIT_PLACEHOLDER_TEXT_COLOR);
    frameLayout.addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.CENTER_VERTICAL));

    nameTextView = new EditText(context);
    nameTextView.setHint(LocaleController.getString("ShareSendTo", R.string.ShareSendTo));
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    nameTextView.setBackgroundDrawable(null);
    nameTextView.setHintTextColor(Theme.SHARE_SHEET_EDIT_PLACEHOLDER_TEXT_COLOR);
    nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    AndroidUtilities.clearCursorDrawable(nameTextView);
    nameTextView.setTextColor(Theme.SHARE_SHEET_EDIT_TEXT_COLOR);
    frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 48, 2, 96, 0));
    nameTextView.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) {
            String text = nameTextView.getText().toString();
            if (text.length() != 0) {
                if (gridView.getAdapter() != searchAdapter) {
                    topBeforeSwitch = getCurrentTop();
                    gridView.setAdapter(searchAdapter);
                    searchAdapter.notifyDataSetChanged();
                }
                if (searchEmptyView != null) {
                    searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
                }
            } else {
                if (gridView.getAdapter() != listAdapter) {
                    int top = getCurrentTop();
                    searchEmptyView.setText(LocaleController.getString("NoChats", R.string.NoChats));
                    gridView.setAdapter(listAdapter);
                    listAdapter.notifyDataSetChanged();
                    if (top > 0) {
                        layoutManager.scrollToPositionWithOffset(0, -top);
                    }
                }
            }
            if (searchAdapter != null) {
                searchAdapter.searchDialogs(text);
            }
        }
    });

    gridView = new RecyclerListView(context);
    gridView.setTag(13);
    gridView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
    gridView.setClipToPadding(false);
    gridView.setLayoutManager(layoutManager = new GridLayoutManager(getContext(), 4));
    gridView.setHorizontalScrollBarEnabled(false);
    gridView.setVerticalScrollBarEnabled(false);
    gridView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent,
                RecyclerView.State state) {
            Holder holder = (Holder) parent.getChildViewHolder(view);
            if (holder != null) {
                int pos = holder.getAdapterPosition();
                outRect.left = pos % 4 == 0 ? 0 : AndroidUtilities.dp(4);
                outRect.right = pos % 4 == 3 ? 0 : AndroidUtilities.dp(4);
            } else {
                outRect.left = AndroidUtilities.dp(4);
                outRect.right = AndroidUtilities.dp(4);
            }
        }
    });
    containerView.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));
    gridView.setAdapter(listAdapter = new ShareDialogsAdapter(context));
    gridView.setGlowColor(0xfff5f6f7);
    gridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position < 0) {
                return;
            }
            TLRPC.TL_dialog dialog;
            if (gridView.getAdapter() == listAdapter) {
                dialog = listAdapter.getItem(position);
            } else {
                dialog = searchAdapter.getItem(position);
            }
            if (dialog == null) {
                return;
            }
            ShareDialogCell cell = (ShareDialogCell) view;
            if (selectedDialogs.containsKey(dialog.id)) {
                selectedDialogs.remove(dialog.id);
                cell.setChecked(false, true);
            } else {
                selectedDialogs.put(dialog.id, dialog);
                cell.setChecked(true, true);
            }
            updateSelectedCount();
        }
    });
    gridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            updateLayout();
        }
    });

    searchEmptyView = new EmptyTextProgressView(context);
    searchEmptyView.setShowAtCenter(true);
    searchEmptyView.showTextView();
    searchEmptyView.setText(LocaleController.getString("NoChats", R.string.NoChats));
    gridView.setEmptyView(searchEmptyView);
    containerView.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));

    containerView.addView(frameLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));

    shadow = new View(context);
    shadow.setBackgroundResource(R.drawable.header_shadow);
    containerView.addView(shadow,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));

    updateSelectedCount();

    if (!DialogsActivity.dialogsLoaded) {
        MessagesController.getInstance().loadDialogs(0, 100, true);
        ContactsController.getInstance().checkInviteText();
        DialogsActivity.dialogsLoaded = true;
    }
    if (listAdapter.dialogs.isEmpty()) {
        NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogsNeedReload);
    }
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "onCreate()");

    m_app = (TodoApplication) getApplication();
    m_app.setActionBarStyle(getWindow());
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constants.BROADCAST_UPDATE_UI);
    intentFilter.addAction(Constants.BROADCAST_SYNC_START);
    intentFilter.addAction(Constants.BROADCAST_SYNC_DONE);

    localBroadcastManager = m_app.getLocalBroadCastManager();

    m_broadcastReceiver = new BroadcastReceiver() {
        @Override/*  w ww  .j av  a 2 s .  co  m*/
        public void onReceive(Context context, @NotNull Intent intent) {
            if (intent.getAction().equals(Constants.BROADCAST_SYNC_START)) {
                setProgressBarIndeterminateVisibility(true);
            } else if (intent.getAction().equals(Constants.BROADCAST_SYNC_DONE)) {
                setProgressBarIndeterminateVisibility(false);
            }
        }
    };
    localBroadcastManager.registerReceiver(m_broadcastReceiver, intentFilter);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    final Intent intent = getIntent();
    ActiveFilter mFilter = new ActiveFilter();
    mFilter.initFromIntent(intent);
    final String action = intent.getAction();
    // create shortcut and exit
    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        Log.d(TAG, "Setting up shortcut icon");
        setupShortcut();
        finish();
        return;
    } else if (Intent.ACTION_SEND.equals(action)) {
        Log.d(TAG, "Share");
        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            share_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT).toString();
        } else {
            share_text = "";
        }
        if (!m_app.hasShareTaskShowsEdit()) {
            if (!share_text.equals("")) {
                addBackgroundTask(share_text);
            }
            finish();
            return;
        }
    } else if ("com.google.android.gm.action.AUTO_SEND".equals(action)) {
        // Called as note to self from google search/now
        noteToSelf(intent);
        finish();
        return;
    } else if (Constants.INTENT_BACKGROUND_TASK.equals(action)) {
        Log.v(TAG, "Adding background task");
        if (intent.hasExtra(Constants.EXTRA_BACKGROUND_TASK)) {
            addBackgroundTask(intent.getStringExtra(Constants.EXTRA_BACKGROUND_TASK));
        } else {
            Log.w(TAG, "Task was not in extras");
        }
        finish();
        return;
    }

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    setContentView(R.layout.add_task);

    // text
    textInputField = (EditText) findViewById(R.id.taskText);
    m_app.setEditTextHint(textInputField, R.string.tasktexthint);

    if (share_text != null) {
        textInputField.setText(share_text);
    }

    Task iniTask = null;
    setTitle(R.string.addtask);

    m_backup = m_app.getTaskCache(this).getTasksToUpdate();
    if (m_backup != null && m_backup.size() > 0) {
        ArrayList<String> prefill = new ArrayList<String>();
        for (Task t : m_backup) {
            prefill.add(t.inFileFormat());
        }
        String sPrefill = Util.join(prefill, "\n");
        textInputField.setText(sPrefill);
        setTitle(R.string.updatetask);
    } else {
        if (textInputField.getText().length() == 0) {
            iniTask = new Task(1, "");
            iniTask.initWithFilter(mFilter);
        }

        if (iniTask != null && iniTask.getTags().size() == 1) {
            List<String> ps = iniTask.getTags();
            String project = ps.get(0);
            if (!project.equals("-")) {
                textInputField.append(" +" + project);
            }
        }

        if (iniTask != null && iniTask.getLists().size() == 1) {
            List<String> cs = iniTask.getLists();
            String context = cs.get(0);
            if (!context.equals("-")) {
                textInputField.append(" @" + context);
            }
        }
    }
    // Listen to enter events, use IME_ACTION_NEXT for soft keyboards
    // like Swype where ENTER keyCode is not generated.

    int inputFlags = InputType.TYPE_CLASS_TEXT;

    if (m_app.hasCapitalizeTasks()) {
        inputFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
    }
    textInputField.setRawInputType(inputFlags);
    textInputField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    textInputField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, @Nullable KeyEvent keyEvent) {

            boolean hardwareEnterUp = keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_UP
                    && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER;
            boolean hardwareEnterDown = keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN
                    && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER;
            boolean imeActionNext = (actionId == EditorInfo.IME_ACTION_NEXT);

            if (imeActionNext || hardwareEnterUp) {
                // Move cursor to end of line
                int position = textInputField.getSelectionStart();
                String remainingText = textInputField.getText().toString().substring(position);
                int endOfLineDistance = remainingText.indexOf('\n');
                int endOfLine;
                if (endOfLineDistance == -1) {
                    endOfLine = textInputField.length();
                } else {
                    endOfLine = position + endOfLineDistance;
                }
                textInputField.setSelection(endOfLine);
                replaceTextAtSelection("\n", false);

                if (hasCloneTags()) {
                    String precedingText = textInputField.getText().toString().substring(0, endOfLine);
                    int lineStart = precedingText.lastIndexOf('\n');
                    String line;
                    if (lineStart != -1) {
                        line = precedingText.substring(lineStart, endOfLine);
                    } else {
                        line = precedingText;
                    }
                    Task t = new Task(0, line);
                    LinkedHashSet<String> tags = new LinkedHashSet<String>();
                    for (String ctx : t.getLists()) {
                        tags.add("@" + ctx);
                    }
                    for (String prj : t.getTags()) {
                        tags.add("+" + prj);
                    }
                    replaceTextAtSelection(Util.join(tags, " "), true);
                }
                endOfLine++;
                textInputField.setSelection(endOfLine);
            }
            return (imeActionNext || hardwareEnterDown || hardwareEnterUp);
        }
    });

    setCloneTags(m_app.isAddTagsCloneTags());
    setWordWrap(m_app.isWordWrap());

    findViewById(R.id.cb_wrap).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setWordWrap(hasWordWrap());
        }
    });

    int textIndex = 0;
    textInputField.setSelection(textIndex);

    // Set button callbacks
    findViewById(R.id.btnContext).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showContextMenu();
        }
    });
    findViewById(R.id.btnProject).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTagMenu();
        }
    });
    findViewById(R.id.btnPrio).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showPrioMenu();
        }
    });

    findViewById(R.id.btnDue).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            insertDate(Task.DUE_DATE);
        }
    });
    findViewById(R.id.btnThreshold).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            insertDate(Task.THRESHOLD_DATE);
        }
    });

    if (m_backup != null && m_backup.size() > 0) {
        textInputField.setSelection(textInputField.getText().length());
    }
}

From source file:org.telegram.ui.ChannelEditActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from  w  w  w .  j  a v a2 s .  c o m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }
                if (nameTextView.length() == 0) {
                    Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                    if (v != null) {
                        v.vibrate(200);
                    }
                    AndroidUtilities.shakeView(nameTextView, 2, 0);
                    return;
                }
                donePressed = true;

                if (avatarUpdater.uploadingAvatar != null) {
                    createAfterUpload = true;
                    progressDialog = new ProgressDialog(getParentActivity());
                    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
                    progressDialog.setCanceledOnTouchOutside(false);
                    progressDialog.setCancelable(false);
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            LocaleController.getString("Cancel", R.string.Cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    createAfterUpload = false;
                                    progressDialog = null;
                                    donePressed = false;
                                    try {
                                        dialog.dismiss();
                                    } catch (Exception e) {
                                        FileLog.e("tmessages", e);
                                    }
                                }
                            });
                    progressDialog.show();
                    return;
                }
                if (!currentChat.title.equals(nameTextView.getText().toString())) {
                    MessagesController.getInstance().changeChatTitle(chatId, nameTextView.getText().toString());
                }
                if (info != null && !info.about.equals(descriptionTextView.getText().toString())) {
                    MessagesController.getInstance().updateChannelAbout(chatId,
                            descriptionTextView.getText().toString(), info);
                }
                if (signMessages != currentChat.signatures) {
                    currentChat.signatures = true;
                    MessagesController.getInstance().toogleChannelSignatures(chatId, signMessages);
                }
                if (uploadedAvatar != null) {
                    MessagesController.getInstance().changeChatAvatar(chatId, uploadedAvatar);
                } else if (avatar == null && currentChat.photo instanceof TLRPC.TL_chatPhoto) {
                    MessagesController.getInstance().changeChatAvatar(chatId, null);
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    LinearLayout linearLayout;

    fragmentView = new ScrollView(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);
    linearLayout = new LinearLayout(context);
    scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    linearLayout.setOrientation(LinearLayout.VERTICAL);

    actionBar.setTitle(LocaleController.getString("ChannelEdit", R.string.ChannelEdit));

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    FrameLayout frameLayout = new FrameLayout(context);
    linearLayout2.addView(frameLayout,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    avatarImage = new BackupImageView(context);
    avatarImage.setRoundRadius(AndroidUtilities.dp(32));
    avatarDrawable.setInfo(5, null, null, false);
    avatarDrawable.setDrawPhoto(true);
    frameLayout.addView(avatarImage,
            LayoutHelper.createFrame(64, 64,
                    Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                    LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
    avatarImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

            CharSequence[] items;

            if (avatar != null) {
                items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley),
                        LocaleController.getString("DeletePhoto", R.string.DeletePhoto) };
            } else {
                items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley) };
            }

            builder.setItems(items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (i == 0) {
                        avatarUpdater.openCamera();
                    } else if (i == 1) {
                        avatarUpdater.openGallery();
                    } else if (i == 2) {
                        avatar = null;
                        uploadedAvatar = null;
                        avatarImage.setImage(avatar, "50_50", avatarDrawable);
                    }
                }
            });
            showDialog(builder.create());
        }
    });

    nameTextView = new EditText(context);
    if (currentChat.megagroup) {
        nameTextView.setHint(LocaleController.getString("GroupName", R.string.GroupName));
    } else {
        nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
    }
    nameTextView.setMaxLines(4);
    nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    //nameTextView.setHintTextColor(0xff979797);
    nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
    InputFilter[] inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(100);
    nameTextView.setFilters(inputFilters);
    AndroidUtilities.clearCursorDrawable(nameTextView);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    frameLayout.addView(nameTextView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
                    Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0,
                    LocaleController.isRTL ? 96 : 16, 0));
    nameTextView.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) {
            avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null,
                    null, false);
            avatarImage.invalidate();
        }
    });

    View lineView = new View(context);
    lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider));
    linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));

    linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    descriptionTextView = new EditText(context);
    descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    //descriptionTextView.setHintTextColor(0xff979797);
    descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
    descriptionTextView.setBackgroundDrawable(null);
    descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
            | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(255);
    descriptionTextView.setFilters(inputFilters);
    descriptionTextView.setHint(LocaleController.getString("DescriptionOptionalPlaceholder",
            R.string.DescriptionOptionalPlaceholder));
    AndroidUtilities.clearCursorDrawable(descriptionTextView);
    linearLayout2.addView(descriptionTextView,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 17, 12, 17, 6));
    descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                doneButton.performClick();
                return true;
            }
            return false;
        }
    });
    descriptionTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

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

        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    ShadowSectionCell sectionCell = new ShadowSectionCell(context);
    sectionCell.setSize(20);
    linearLayout.addView(sectionCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    if (currentChat.megagroup || !currentChat.megagroup) {
        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        typeCell = new TextSettingsCell(context);
        updateTypeCell();
        typeCell.setForeground(R.drawable.list_selector);
        frameLayout.addView(typeCell,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        lineView = new View(context);
        lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider));
        linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));

        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        if (!currentChat.megagroup) {
            TextCheckCell textCheckCell = new TextCheckCell(context);
            textCheckCell.setForeground(R.drawable.list_selector);
            textCheckCell.setTextAndCheck(
                    LocaleController.getString("ChannelSignMessages", R.string.ChannelSignMessages),
                    signMessages, false);
            frameLayout.addView(textCheckCell,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            textCheckCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    signMessages = !signMessages;
                    ((TextCheckCell) v).setChecked(signMessages);
                }
            });

            TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
            //infoCell.setBackgroundResource(R.drawable.greydivider);
            infoCell.setText(
                    LocaleController.getString("ChannelSignMessagesInfo", R.string.ChannelSignMessagesInfo));
            linearLayout.addView(infoCell,
                    LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        } else {
            adminCell = new TextSettingsCell(context);
            updateAdminCell();
            adminCell.setForeground(R.drawable.list_selector);
            frameLayout.addView(adminCell,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            adminCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle args = new Bundle();
                    args.putInt("chat_id", chatId);
                    args.putInt("type", 1);
                    presentFragment(new ChannelUsersActivity(args));
                }
            });

            sectionCell = new ShadowSectionCell(context);
            sectionCell.setSize(20);
            linearLayout.addView(sectionCell,
                    LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            /*if (!currentChat.creator) {
            sectionCell.setBackgroundResource(R.drawable.greydivider_bottom);
            }*/
        }
    }

    if (currentChat.creator) {
        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        TextSettingsCell textCell = new TextSettingsCell(context);
        textCell.setTextColor(0xffed3d39);
        textCell.setBackgroundResource(R.drawable.list_selector);
        if (currentChat.megagroup) {
            textCell.setText(LocaleController.getString("DeleteMega", R.string.DeleteMega), false);
        } else {
            textCell.setText(LocaleController.getString("ChannelDelete", R.string.ChannelDelete), false);
        }
        frameLayout.addView(textCell,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        textCell.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                if (currentChat.megagroup) {
                    builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert));
                } else {
                    builder.setMessage(
                            LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert));
                }
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                NotificationCenter.getInstance().removeObserver(this,
                                        NotificationCenter.closeChats);
                                if (AndroidUtilities.isTablet()) {
                                    NotificationCenter.getInstance().postNotificationName(
                                            NotificationCenter.closeChats, -(long) chatId);
                                } else {
                                    NotificationCenter.getInstance()
                                            .postNotificationName(NotificationCenter.closeChats);
                                }
                                MessagesController.getInstance().deleteUserFromChat(chatId,
                                        MessagesController.getInstance().getUser(UserConfig.getClientUserId()),
                                        info);
                                finishFragment();
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
        });

        TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
        //infoCell.setBackgroundResource(R.drawable.greydivider_bottom);
        if (currentChat.megagroup) {
            infoCell.setText(LocaleController.getString("MegaDeleteInfo", R.string.MegaDeleteInfo));
        } else {
            infoCell.setText(LocaleController.getString("ChannelDeleteInfo", R.string.ChannelDeleteInfo));
        }
        linearLayout.addView(infoCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    }

    nameTextView.setText(currentChat.title);
    nameTextView.setSelection(nameTextView.length());
    if (info != null) {
        descriptionTextView.setText(info.about);
    }
    if (currentChat.photo != null) {
        avatar = currentChat.photo.photo_small;
        avatarImage.setImage(avatar, "50_50", avatarDrawable);
    } else {
        avatarImage.setImageDrawable(avatarDrawable);
    }

    return fragmentView;
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public void onClick(View view) {
    if (view == btnGoBack) {
        if (isAtFavorites) {
            isAtFavorites = false;/*from   w  ww. j  av  a  2s . com*/
            doSearch();
        } else {
            finish(0, view, true);
        }
    } else if (view == btnFavorite) {
        isAtFavorites = true;
        radioStationList.cancel();
        radioStationList.fetchFavorites(getApplication());
        updateButtons();
    } else if (view == btnSearch) {
        final Context ctx = getHostActivity();
        final LinearLayout l = (LinearLayout) UI.createDialogView(ctx, null);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        chkGenre = new RadioButton(ctx);
        chkGenre.setText(R.string.genre);
        chkGenre.setChecked(Player.lastRadioSearchWasByGenre);
        chkGenre.setOnClickListener(this);
        chkGenre.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        btnGenre = new Spinner(ctx);
        btnGenre.setContentDescription(ctx.getText(R.string.genre));
        btnGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad << 1;
        chkTerm = new RadioButton(ctx);
        chkTerm.setText(R.string.search_term);
        chkTerm.setChecked(!Player.lastRadioSearchWasByGenre);
        chkTerm.setOnClickListener(this);
        chkTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        txtTerm = new EditText(ctx);
        txtTerm.setContentDescription(ctx.getText(R.string.search_term));
        txtTerm.setText(Player.radioSearchTerm == null ? "" : Player.radioSearchTerm);
        txtTerm.setOnClickListener(this);
        txtTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        txtTerm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        txtTerm.setSingleLine();
        txtTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        p.bottomMargin = UI._DLGsppad;
        final TextView lbl = new TextView(ctx);
        lbl.setAutoLinkMask(0);
        lbl.setLinksClickable(true);
        //http://developer.android.com/design/style/color.html
        lbl.setLinkTextColor(new BgColorStateList(UI.isAndroidThemeLight() ? 0xff0099cc : 0xff33b5e5));
        lbl.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._14sp);
        lbl.setGravity(Gravity.CENTER_HORIZONTAL);
        lbl.setText(SafeURLSpan.parseSafeHtml(getText(R.string.by_dir_xiph_org)));
        lbl.setMovementMethod(LinkMovementMethod.getInstance());
        lbl.setLayoutParams(p);

        l.addView(chkGenre);
        l.addView(btnGenre);
        l.addView(chkTerm);
        l.addView(txtTerm);
        l.addView(lbl);

        btnGenre.setAdapter(this);
        btnGenre.setSelection(getValidGenre(Player.radioLastGenre));
        defaultTextColors = txtTerm.getTextColors();

        UI.prepareDialogAndShow((new AlertDialog.Builder(ctx)).setTitle(getText(R.string.search)).setView(l)
                .setPositiveButton(R.string.search, this).setNegativeButton(R.string.cancel, this)
                .setOnCancelListener(this).create());
    } else if (view == btnGoBackToPlayer) {
        finish(-1, view, false);
    } else if (view == btnAdd) {
        addPlaySelectedItem(false);
    } else if (view == btnPlay) {
        addPlaySelectedItem(true);
    } else if (view == chkGenre || view == btnGenre) {
        chkGenre.setChecked(true);
        chkTerm.setChecked(false);
    } else if (view == chkTerm || view == txtTerm) {
        chkGenre.setChecked(false);
        chkTerm.setChecked(true);
    } else if (view == list) {
        if (!isAtFavorites && !loading && (radioStationList == null || radioStationList.getCount() == 0))
            onClick(btnFavorite);
    }
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    // Scan NFC Tag dialog, inflate image
    LayoutInflater factory = LayoutInflater.from(MainActivity.this);
    final View view = factory.inflate(R.layout.scan_tag_image, null);

    // Ask for tagTitle (tagName) in dialog
    final EditText tagTitle = new EditText(this);
    tagTitle.setHint(getResources().getString(R.string.set_tag_name_dialog_hint));
    tagTitle.setSingleLine(true);//from  ww w .  j ava 2  s.  co  m
    tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

    // Set tagTitle maxLength
    int maxLength = 50;
    InputFilter[] array = new InputFilter[1];
    array[0] = new InputFilter.LengthFilter(maxLength);
    tagTitle.setFilters(array);

    final LinearLayout l = new LinearLayout(this);

    l.setOrientation(LinearLayout.VERTICAL);
    l.addView(tagTitle);

    // Dialog that shows scan tag image
    if (id == DIALOG_READ) {
        return new AlertDialog.Builder(this).setTitle(R.string.scan_tag_dialog_title).setView(view)
                .setCancelable(false)
                .setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialogCancelled = true;
                        killForegroundDispatch();
                        dialog.cancel();
                    }
                }).create();
    }

    // Dialog that asks for tagName and stores it after 'Ok' pressed
    else if (id == DIALOG_SET_TAGNAME) {
        tagTitle.requestFocus();
        return new AlertDialog.Builder(this).setTitle(R.string.set_tag_name_dialog_title).setView(l)
                .setCancelable(false)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JSONObject newTag = new JSONObject();

                        try {
                            newTag.put("tagName", tagTitle.getText());
                            newTag.put("tagID", tagID);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        tags.put(newTag);

                        writeToJSON();

                        adapter.notifyDataSetChanged();

                        updateListViewHeight(listView);

                        if (tags.length() == 0)
                            noTags.setVisibility(View.VISIBLE);

                        else
                            noTags.setVisibility(View.INVISIBLE);

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_added,
                                Toast.LENGTH_SHORT);
                        toast.show();

                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);

                        tagID = "";
                        tagTitle.setText("");
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        tagID = "";
                        tagTitle.setText("");
                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);
                        dialog.cancel();
                    }
                }).create();
    }

    return null;
}

From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealSearchFragment.java

/**
 * Set the text based on google voice then implement search
 *//*from   w w  w  .  j av  a  2 s  .  c  o  m*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQ_CODE_SPEECH_INPUT) {
        if (resultCode == Activity.RESULT_OK && null != data) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            mEtSearch.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
            mEtSearch.setText(result.get(0));
            searchFood(mEtSearch.getText().toString(), 0);
            mItem.clear();
            mEtSearchAdapter.notifyDataSetChanged();
            mEtSearch.clearFocus();
        }
    }
}

From source file:com.facebook.react.views.textinput.ReactTextInputManager.java

@ReactProp(name = "autoCapitalize")
public void setAutoCapitalize(ReactEditText view, int autoCapitalize) {
    updateStagedInputTypeFlag(view, InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_CAP_WORDS
            | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS, autoCapitalize);
}

From source file:onion.chat.MainActivity.java

void changeContactName(final String address, final String name) {
    final FrameLayout view = new FrameLayout(this);
    final EditText editText = new EditText(this);
    editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    editText.setSingleLine();//from w w w  .  j  a  va 2 s  . com
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PERSON_NAME
            | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    view.addView(editText);
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());
    ;
    view.setPadding(padding, padding, padding, padding);
    editText.setText(name);
    new AlertDialog.Builder(this).setTitle(R.string.title_change_alias).setView(view)
            .setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    db.setContactName(address, editText.getText().toString());
                    update();
                    snack(getString(R.string.snack_alias_changed));
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
}

From source file:org.telegram.ui.ChannelCreateActivity.java

@Override
public View createView(Context context) {
    searching = false;/*from   ww  w .  j av  a2  s  .  c  o  m*/
    searchWas = false;

    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (currentStep == 0) {
                    if (donePressed) {
                        return;
                    }
                    if (nameTextView.length() == 0) {
                        Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                        if (v != null) {
                            v.vibrate(200);
                        }
                        AndroidUtilities.shakeView(nameTextView, 2, 0);
                        return;
                    }
                    donePressed = true;
                    if (avatarUpdater.uploadingAvatar != null) {
                        createAfterUpload = true;
                        progressDialog = new ProgressDialog(getParentActivity());
                        progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
                        progressDialog.setCanceledOnTouchOutside(false);
                        progressDialog.setCancelable(false);
                        progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                                LocaleController.getString("Cancel", R.string.Cancel),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        createAfterUpload = false;
                                        progressDialog = null;
                                        donePressed = false;
                                        try {
                                            dialog.dismiss();
                                        } catch (Exception e) {
                                            FileLog.e("tmessages", e);
                                        }
                                    }
                                });
                        progressDialog.show();
                        return;
                    }
                    final int reqId = MessagesController.getInstance().createChat(
                            nameTextView.getText().toString(), new ArrayList<Integer>(),
                            descriptionTextView.getText().toString(), ChatObject.CHAT_TYPE_CHANNEL,
                            ChannelCreateActivity.this);
                    progressDialog = new ProgressDialog(getParentActivity());
                    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
                    progressDialog.setCanceledOnTouchOutside(false);
                    progressDialog.setCancelable(false);
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            LocaleController.getString("Cancel", R.string.Cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    ConnectionsManager.getInstance().cancelRequest(reqId, true);
                                    donePressed = false;
                                    try {
                                        dialog.dismiss();
                                    } catch (Exception e) {
                                        FileLog.e("tmessages", e);
                                    }
                                }
                            });
                    progressDialog.show();
                } else if (currentStep == 1) {
                    if (!isPrivate) {
                        if (nameTextView.length() == 0) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setMessage(LocaleController.getString("ChannelPublicEmptyUsername",
                                    R.string.ChannelPublicEmptyUsername));
                            builder.setPositiveButton(LocaleController.getString("Close", R.string.Close),
                                    null);
                            showDialog(builder.create());
                            return;
                        } else {
                            if (!lastNameAvailable) {
                                Vibrator v = (Vibrator) getParentActivity()
                                        .getSystemService(Context.VIBRATOR_SERVICE);
                                if (v != null) {
                                    v.vibrate(200);
                                }
                                AndroidUtilities.shakeView(checkTextView, 2, 0);
                                return;
                            } else {
                                MessagesController.getInstance().updateChannelUserName(chatId, lastCheckName);
                            }
                        }
                    }
                    Bundle args = new Bundle();
                    args.putInt("step", 2);
                    args.putInt("chat_id", chatId);
                    presentFragment(new ChannelCreateActivity(args), true);
                } else {
                    ArrayList<TLRPC.InputUser> result = new ArrayList<>();
                    for (Integer uid : selectedContacts.keySet()) {
                        TLRPC.InputUser user = MessagesController
                                .getInputUser(MessagesController.getInstance().getUser(uid));
                        if (user != null) {
                            result.add(user);
                        }
                    }
                    MessagesController.getInstance().addUsersToChannel(chatId, result, null);
                    NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                    Bundle args2 = new Bundle();
                    args2.putInt("chat_id", chatId);
                    presentFragment(new ChatActivity(args2), true);
                }
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    if (currentStep != 2) {
        fragmentView = new ScrollView(context);
        ScrollView scrollView = (ScrollView) fragmentView;
        scrollView.setFillViewport(true);
        linearLayout = new LinearLayout(context);
        scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    } else {
        fragmentView = new LinearLayout(context);
        fragmentView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        linearLayout = (LinearLayout) fragmentView;
    }
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    if (currentStep == 0) {
        actionBar.setTitle(LocaleController.getString("NewChannel", R.string.NewChannel));
        fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        FrameLayout frameLayout = new FrameLayout(context);
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        avatarImage = new BackupImageView(context);
        avatarImage.setRoundRadius(AndroidUtilities.dp(32));
        avatarDrawable.setInfo(5, null, null, false);
        avatarDrawable.setDrawPhoto(true);
        avatarImage.setImageDrawable(avatarDrawable);
        frameLayout.addView(avatarImage,
                LayoutHelper.createFrame(64, 64,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
        avatarImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                CharSequence[] items;

                if (avatar != null) {
                    items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                            LocaleController.getString("FromGalley", R.string.FromGalley),
                            LocaleController.getString("DeletePhoto", R.string.DeletePhoto) };
                } else {
                    items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                            LocaleController.getString("FromGalley", R.string.FromGalley) };
                }

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        if (i == 0) {
                            avatarUpdater.openCamera();
                        } else if (i == 1) {
                            avatarUpdater.openGallery();
                        } else if (i == 2) {
                            avatar = null;
                            uploadedAvatar = null;
                            avatarImage.setImage(avatar, "50_50", avatarDrawable);
                        }
                    }
                });
                showDialog(builder.create());
            }
        });

        nameTextView = new EditText(context);
        nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
        if (nameToSet != null) {
            nameTextView.setText(nameToSet);
            nameToSet = null;
        }
        nameTextView.setMaxLines(4);
        nameTextView
                .setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        //nameTextView.setHintTextColor(0xff979797);
        nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        InputFilter[] inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(100);
        nameTextView.setFilters(inputFilters);
        nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
        AndroidUtilities.clearCursorDrawable(nameTextView);
        nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        frameLayout.addView(nameTextView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
                        Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0,
                        LocaleController.isRTL ? 96 : 16, 0));
        nameTextView.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) {
                avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null,
                        null, false);
                avatarImage.invalidate();
            }
        });

        descriptionTextView = new EditText(context);
        descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        //descriptionTextView.setHintTextColor(0xff979797);
        descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
        descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
                | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(120);
        descriptionTextView.setFilters(inputFilters);
        descriptionTextView
                .setHint(LocaleController.getString("DescriptionPlaceholder", R.string.DescriptionPlaceholder));
        AndroidUtilities.clearCursorDrawable(descriptionTextView);
        linearLayout.addView(descriptionTextView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 18, 24, 0));
        descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                    doneButton.performClick();
                    return true;
                }
                return false;
            }
        });
        descriptionTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

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

            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        TextView helpTextView = new TextView(context);
        helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
        //helpTextView.setTextColor(0xff6d6d72);
        helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        helpTextView.setText(LocaleController.getString("DescriptionInfo", R.string.DescriptionInfo));
        linearLayout.addView(helpTextView,
                LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 20));
    } else if (currentStep == 1) {
        actionBar.setTitle(LocaleController.getString("ChannelSettings", R.string.ChannelSettings));
        fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

        LinearLayout linearLayout2 = new LinearLayout(context);
        linearLayout2.setOrientation(LinearLayout.VERTICAL);
        linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout2.setElevation(AndroidUtilities.dp(2));
        linearLayout.addView(linearLayout2,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        radioButtonCell1 = new RadioButtonCell(context);
        radioButtonCell1.setElevation(0);
        radioButtonCell1.setForeground(R.drawable.list_selector);
        radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic),
                LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false);
        linearLayout2.addView(radioButtonCell1,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        radioButtonCell1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isPrivate) {
                    return;
                }
                isPrivate = false;
                updatePrivatePublic();
            }
        });

        radioButtonCell2 = new RadioButtonCell(context);
        radioButtonCell2.setElevation(0);
        radioButtonCell2.setForeground(R.drawable.list_selector);
        radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate),
                LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate,
                false);
        linearLayout2.addView(radioButtonCell2,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        radioButtonCell2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isPrivate) {
                    return;
                }
                isPrivate = true;
                updatePrivatePublic();
            }
        });

        sectionCell = new ShadowSectionCell(context);
        linearLayout.addView(sectionCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        linkContainer = new LinearLayout(context);
        linkContainer.setOrientation(LinearLayout.VERTICAL);
        linkContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linkContainer.setElevation(AndroidUtilities.dp(2));
        linearLayout.addView(linkContainer,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        headerCell = new HeaderCell(context);
        linkContainer.addView(headerCell);

        publicContainer = new LinearLayout(context);
        publicContainer.setOrientation(LinearLayout.HORIZONTAL);
        linkContainer.addView(publicContainer,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0));

        EditText editText = new EditText(context);
        editText.setText("telegram.me/");
        editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        //editText.setHintTextColor(0xff979797);
        editText.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        editText.setMaxLines(1);
        editText.setLines(1);
        editText.setEnabled(false);
        editText.setBackgroundDrawable(null);
        editText.setPadding(0, 0, 0, 0);
        editText.setSingleLine(true);
        editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36));

        nameTextView = new EditText(context);
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        //nameTextView.setHintTextColor(0xff979797);
        nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        nameTextView.setMaxLines(1);
        nameTextView.setLines(1);
        nameTextView.setBackgroundDrawable(null);
        nameTextView.setPadding(0, 0, 0, 0);
        nameTextView.setSingleLine(true);
        nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
                | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        nameTextView.setHint(
                LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
        AndroidUtilities.clearCursorDrawable(nameTextView);
        publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
        nameTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                checkUserName(nameTextView.getText().toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        privateContainer = new TextBlockCell(context);
        privateContainer.setForeground(R.drawable.list_selector);
        privateContainer.setElevation(0);
        linkContainer.addView(privateContainer);
        privateContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (invite == null) {
                    return;
                }
                try {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link);
                    clipboard.setPrimaryClip(clip);
                    Toast.makeText(getParentActivity(),
                            LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT)
                            .show();
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        });

        checkTextView = new TextView(context);
        checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
        checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        checkTextView.setVisibility(View.GONE);
        linkContainer.addView(checkTextView,
                LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7));

        typeInfoCell = new TextInfoPrivacyCell(context);
        //typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
        linearLayout.addView(typeInfoCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        loadingAdminedCell = new LoadingCell(context);
        linearLayout.addView(loadingAdminedCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        adminedInfoCell = new TextInfoPrivacyCell(context);
        //adminedInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
        linearLayout.addView(adminedInfoCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        updatePrivatePublic();
    } else if (currentStep == 2) {
        actionBar.setTitle(LocaleController.getString("ChannelAddMembers", R.string.ChannelAddMembers));
        actionBar.setSubtitle(LocaleController.formatPluralString("Members", selectedContacts.size()));

        searchListViewAdapter = new SearchAdapter(context, null, false, false, false, false);
        searchListViewAdapter.setCheckedMap(selectedContacts);
        searchListViewAdapter.setUseUserCell(true);
        listViewAdapter = new ContactsAdapter(context, 1, false, null, false);
        listViewAdapter.setCheckedMap(selectedContacts);

        FrameLayout frameLayout = new FrameLayout(context);
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.chat_list_background));

        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        nameTextView = new EditText(context);
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        //nameTextView.setHintTextColor(0xff979797);
        nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
        nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
                | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        nameTextView.setMinimumHeight(AndroidUtilities.dp(54));
        nameTextView.setSingleLine(false);
        nameTextView.setLines(2);
        nameTextView.setMaxLines(2);
        nameTextView.setVerticalScrollBarEnabled(true);
        nameTextView.setHorizontalScrollBarEnabled(false);
        nameTextView.setPadding(0, 0, 0, 0);
        nameTextView.setHint(LocaleController.getString("AddMutual", R.string.AddMutual));
        nameTextView.setTextIsSelectable(false);
        nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        nameTextView
                .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
        AndroidUtilities.clearCursorDrawable(nameTextView);
        frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 10, 0, 10, 0));

        nameTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
                if (!ignoreChange) {
                    beforeChangeIndex = nameTextView.getSelectionStart();
                    changeString = new SpannableString(charSequence);
                }
            }

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

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!ignoreChange) {
                    boolean search = false;
                    int afterChangeIndex = nameTextView.getSelectionEnd();
                    if (editable.toString().length() < changeString.toString().length()) {
                        String deletedString = "";
                        try {
                            deletedString = changeString.toString().substring(afterChangeIndex,
                                    beforeChangeIndex);
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        if (deletedString.length() > 0) {
                            if (searching && searchWas) {
                                search = true;
                            }
                            Spannable span = nameTextView.getText();
                            for (int a = 0; a < allSpans.size(); a++) {
                                ChipSpan sp = allSpans.get(a);
                                if (span.getSpanStart(sp) == -1) {
                                    allSpans.remove(sp);
                                    selectedContacts.remove(sp.uid);
                                }
                            }
                            actionBar.setSubtitle(
                                    LocaleController.formatPluralString("Members", selectedContacts.size()));
                            listView.invalidateViews();
                        } else {
                            search = true;
                        }
                    } else {
                        search = true;
                    }
                    if (search) {
                        String text = nameTextView.getText().toString().replace("<", "");
                        if (text.length() != 0) {
                            searching = true;
                            searchWas = true;
                            if (listView != null) {
                                listView.setAdapter(searchListViewAdapter);
                                searchListViewAdapter.notifyDataSetChanged();
                                listView.setFastScrollAlwaysVisible(false);
                                listView.setFastScrollEnabled(false);
                                listView.setVerticalScrollBarEnabled(true);
                            }
                            if (emptyTextView != null) {
                                emptyTextView
                                        .setText(LocaleController.getString("NoResult", R.string.NoResult));
                            }
                            searchListViewAdapter.searchDialogs(text);
                        } else {
                            searchListViewAdapter.searchDialogs(null);
                            searching = false;
                            searchWas = false;
                            listView.setAdapter(listViewAdapter);
                            listViewAdapter.notifyDataSetChanged();
                            listView.setFastScrollAlwaysVisible(true);
                            listView.setFastScrollEnabled(true);
                            listView.setVerticalScrollBarEnabled(false);
                            emptyTextView
                                    .setText(LocaleController.getString("NoContacts", R.string.NoContacts));
                        }
                    }
                }
            }
        });

        LinearLayout emptyTextLayout = new LinearLayout(context);
        emptyTextLayout.setVisibility(View.INVISIBLE);
        emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.addView(emptyTextLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        emptyTextView = new TextView(context);
        emptyTextView.setTextColor(0xff808080);
        emptyTextView.setTextSize(20);
        emptyTextView.setGravity(Gravity.CENTER);
        emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
        emptyTextLayout.addView(emptyTextView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        FrameLayout frameLayout2 = new FrameLayout(context);
        emptyTextLayout.addView(frameLayout2,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        listView = new LetterSectionsListView(context);
        listView.setEmptyView(emptyTextLayout);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setFastScrollEnabled(true);
        listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
        listView.setAdapter(listViewAdapter);
        listView.setFastScrollAlwaysVisible(true);
        listView.setVerticalScrollbarPosition(
                LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
        linearLayout.addView(listView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TLRPC.User user;
                if (searching && searchWas) {
                    user = (TLRPC.User) searchListViewAdapter.getItem(i);
                } else {
                    int section = listViewAdapter.getSectionForPosition(i);
                    int row = listViewAdapter.getPositionInSectionForPosition(i);
                    if (row < 0 || section < 0) {
                        return;
                    }
                    user = (TLRPC.User) listViewAdapter.getItem(section, row);
                }
                if (user == null) {
                    return;
                }

                boolean check = true;
                if (selectedContacts.containsKey(user.id)) {
                    check = false;
                    try {
                        ChipSpan span = selectedContacts.get(user.id);
                        selectedContacts.remove(user.id);
                        SpannableStringBuilder text = new SpannableStringBuilder(nameTextView.getText());
                        text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                        allSpans.remove(span);
                        ignoreChange = true;
                        nameTextView.setText(text);
                        nameTextView.setSelection(text.length());
                        ignoreChange = false;
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else {
                    ignoreChange = true;
                    ChipSpan span = createAndPutChipForUser(user);
                    if (span != null) {
                        span.uid = user.id;
                    }
                    ignoreChange = false;
                    if (span == null) {
                        return;
                    }
                }
                actionBar.setSubtitle(LocaleController.formatPluralString("Members", selectedContacts.size()));
                if (searching || searchWas) {
                    ignoreChange = true;
                    SpannableStringBuilder ssb = new SpannableStringBuilder("");
                    for (ImageSpan sp : allSpans) {
                        ssb.append("<<");
                        ssb.setSpan(sp, ssb.length() - 2, ssb.length(),
                                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    nameTextView.setText(ssb);
                    nameTextView.setSelection(ssb.length());
                    ignoreChange = false;

                    searchListViewAdapter.searchDialogs(null);
                    searching = false;
                    searchWas = false;
                    listView.setAdapter(listViewAdapter);
                    listViewAdapter.notifyDataSetChanged();
                    listView.setFastScrollAlwaysVisible(true);
                    listView.setFastScrollEnabled(true);
                    listView.setVerticalScrollBarEnabled(false);
                    emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
                } else {
                    if (view instanceof UserCell) {
                        ((UserCell) view).setChecked(check, true);
                    }
                }
            }
        });
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
                if (i == SCROLL_STATE_TOUCH_SCROLL) {
                    AndroidUtilities.hideKeyboard(nameTextView);
                }
                if (listViewAdapter != null) {
                    listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (absListView.isFastScrollEnabled()) {
                    AndroidUtilities.clearDrawableAnimation(absListView);
                }
            }
        });
    }

    return fragmentView;
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Get pressed item information
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    // If Rename Tag pressed
    if (item.getTitle().equals(getResources().getString(R.string.rename_context_menu))) {
        // Create new EdiText and configure
        final EditText tagTitle = new EditText(this);
        tagTitle.setSingleLine(true);//from  w w w. ja v  a2 s .  c  o  m
        tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

        // Set tagTitle maxLength
        int maxLength = 50;
        InputFilter[] array = new InputFilter[1];
        array[0] = new InputFilter.LengthFilter(maxLength);
        tagTitle.setFilters(array);

        // Get tagName text into EditText
        try {
            assert info != null;
            tagTitle.setText(tags.getJSONObject(info.position).getString("tagName"));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        final LinearLayout l = new LinearLayout(this);

        l.setOrientation(LinearLayout.VERTICAL);
        l.addView(tagTitle);

        // Show rename dialog
        new AlertDialog.Builder(this).setTitle(R.string.rename_tag_dialog_title).setView(l)
                .setPositiveButton(R.string.rename_tag_dialog_button, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 'Rename' pressed, change tagName and store
                        try {
                            JSONObject newTagName = tags.getJSONObject(info.position);
                            newTagName.put("tagName", tagTitle.getText());

                            tags.put(info.position, newTagName);
                            adapter.notifyDataSetChanged();

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        writeToJSON();

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_renamed,
                                Toast.LENGTH_SHORT);
                        toast.show();

                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);
                    }
                }).show();
        tagTitle.requestFocus();
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

        return true;
    }

    // If Delete Tag pressed
    else if (item.getTitle().equals(getResources().getString(R.string.delete_context_menu))) {
        // Construct dialog message
        String dialogMessage = "";

        assert info != null;
        try {
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog1) + " '"
                    + tags.getJSONObject(info.position).getString("tagName") + "'?";

        } catch (JSONException e) {
            e.printStackTrace();
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog2);
        }

        // Show delete dialog
        new AlertDialog.Builder(this).setMessage(dialogMessage)
                .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JSONArray newArray = new JSONArray();

                        // Copy contents to new array, without the deleted item
                        for (int i = 0; i < tags.length(); i++) {
                            if (i != info.position) {
                                try {
                                    newArray.put(tags.get(i));

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                        // Equal original array to new array
                        tags = newArray;

                        // Write to file
                        try {
                            settings.put("tags", tags);
                            root.put("settings", settings);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        writeToJSON();

                        adapter.adapterData = tags;
                        adapter.notifyDataSetChanged();

                        updateListViewHeight(listView);

                        // If no tags, show 'Press + to add Tags' textView
                        if (tags.length() == 0)
                            noTags.setVisibility(View.VISIBLE);

                        else
                            noTags.setVisibility(View.INVISIBLE);

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_deleted,
                                Toast.LENGTH_SHORT);
                        toast.show();

                    }
                }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Do nothing, close dialog
                    }
                }).show();

        return true;
    }

    return super.onContextItemSelected(item);
}