Example usage for android.text InputType TYPE_CLASS_TEXT

List of usage examples for android.text InputType TYPE_CLASS_TEXT

Introduction

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

Prototype

int TYPE_CLASS_TEXT

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

Click Source Link

Document

Class for normal text.

Usage

From source file:net.gaast.giggity.ChooserActivity.java

private void showAddDialog() {
    AlertDialog.Builder d = new AlertDialog.Builder(this);
    d.setTitle(R.string.add_dialog);//from   w ww.j  a  v a  2 s .  co m

    final EditText urlBox = new EditText(this);
    urlBox.setHint(R.string.enter_url);
    urlBox.setSingleLine();
    urlBox.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    d.setView(urlBox);

    d.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            openSchedule(urlBox.getText().toString(), false, null);
        }
    });
    /* Apparently the "Go"/"Done" button still just simulates an ENTER keypress. Neat!...
       http://stackoverflow.com/questions/5677563/listener-for-done-button-on-edittext */
    urlBox.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                openSchedule(urlBox.getText().toString(), false, null);
                return true;
            } else {
                return false;
            }
        }
    });

    d.setNeutralButton(R.string.qr_scan, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            try {
                Intent intent = new Intent(BARCODE_SCANNER);
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                startActivityForResult(intent, 0);
            } catch (ActivityNotFoundException e) {
                new AlertDialog.Builder(ChooserActivity.this)
                        .setMessage("Please install the Barcode Scanner app").setTitle("Error").show();
            }
        }
    });
    d.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    d.show();
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog to get a name for the inbound device being paired and
 * starts a new {@link CallGooGlInbound} action if the chosen name is valid.
 * /* w w w.jav a 2  s .c  om*/
 * @param deviceType
 *            the model of the device being paired as suggested by the
 *            device itself
 * @param sharedSecret
 *            the keys used when encrypting the message between devices
 * @param activity
 *            the caller activity
 */
public static void promptForInboundName(final String deviceType, final int[] sharedSecret,
        final MainActivity activity) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        @Override
        public void run() {
            DialogFragment prompt = new PatchedDialogFragment() {
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                    AlertDialog.Builder builder = getBuilder(activity);
                    final EditText input = new EditText(getContext());
                    input.setInputType(InputType.TYPE_CLASS_TEXT);
                    input.setText(deviceType);
                    input.setSelection(deviceType.length());
                    // @formatter:off
                    builder.setTitle(R.string.device_name_chooser_title).setView(input)
                            .setPositiveButton(android.R.string.ok, null);
                    // @formatter:on
                    final AlertDialog alertDialog = builder.create();
                    alertDialog.setOnShowListener(
                            new DeviceNameChooserPrompt(alertDialog, input, activity, new Callback<String>() {

                                @Override
                                public void run() {
                                    // @formatter:off
                                    new CallGooGlInbound(activity, getParam(), deviceType)
                                            .execute(sharedSecret);

                                    ((InputMethodManager) activity
                                            .getSystemService(Context.INPUT_METHOD_SERVICE))
                                                    .hideSoftInputFromWindow(input.getWindowToken(), 0);
                                    // @formatter:on
                                }
                            }));
                    return alertDialog;
                }
            };
            prompt.show(activity.getSupportFragmentManager(), "chooseName");
        }
    });
}

From source file:com.iangclifton.android.floatlabel.FloatLabel.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    // Load custom attributes
    final int layout;
    final CharSequence text;
    final CharSequence hint;
    final ColorStateList hintColor;
    final int floatLabelColor;
    final int inputType;

    if (attrs == null) {
        layout = R.layout.float_label;
        text = null;//from  w w  w .j  a v  a2  s .  c om
        hint = null;
        hintColor = null;
        floatLabelColor = 0;
        inputType = 0;
    } else {
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabel, defStyle, 0);

        layout = a.getResourceId(R.styleable.FloatLabel_android_layout, R.layout.float_label);
        text = a.getText(R.styleable.FloatLabel_android_text);
        hint = a.getText(R.styleable.FloatLabel_android_hint);
        hintColor = a.getColorStateList(R.styleable.FloatLabel_android_textColorHint);
        floatLabelColor = a.getColor(R.styleable.FloatLabel_floatLabelColor, 0);
        inputType = a.getInt(R.styleable.FloatLabel_android_inputType, InputType.TYPE_CLASS_TEXT);
        a.recycle();
    }

    inflate(context, layout, this);
    mEditText = (EditText) findViewById(R.id.edit_text);
    if (mEditText == null) {
        throw new RuntimeException("Your layout must have an EditText whose ID is @id/edit_text");
    }
    mEditText.setHint(hint);
    mEditText.setText(text);
    if (hintColor != null) {
        mEditText.setHintTextColor(hintColor);
    }
    if (inputType != 0) {
        mEditText.setInputType(inputType);
    }

    mLabel = (TextView) findViewById(R.id.float_label);
    if (mLabel == null) {
        throw new RuntimeException("Your layout must have a TextView whose ID is @id/float_label");
    }
    mLabel.setText(mEditText.getHint());
    if (floatLabelColor != 0)
        mLabel.setTextColor(floatLabelColor);

    // Listen to EditText to know when it is empty or nonempty
    mEditText.addTextChangedListener(new EditTextWatcher());

    // Check current state of EditText
    if (mEditText.getText().length() == 0) {
        ViewHelper.setAlpha(mLabel, 0);
        mLabelShowing = false;
    } else {
        mLabel.setVisibility(View.VISIBLE);
        mLabelShowing = true;
    }

    // Mark init as complete to prevent accidentally breaking the view by
    // adding children
    mInitComplete = true;
}

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/*from   w w w.  j av a2s .  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.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;//w  w  w.  jav  a  2s  .co 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:com.anton.gavel.GavelMain.java

public void createDialog(int id) {
    if (progressDialog != null) {
        progressDialog.dismiss();/*from w w w  .jav a 2 s.  c  o m*/
    }
    // handles creation of any dialogs by other actions
    switch (id) {
    case DIALOG_PI:
        //call custom dialog for collecting Personal Info
        PersonalInfoDialogFragment personalInfoDialog = new PersonalInfoDialogFragment();
        personalInfoDialog.setPersonalInfo(mPersonalInfo);
        personalInfoDialog.show(getSupportFragmentManager(), "PersonalInfoDialogFragment");
        break;
    case DIALOG_ABOUT:
        //construct a simple dialog to show text

        //get about text
        TextView aboutView = new TextView(this);
        aboutView.setText(R.string.about_text);
        aboutView.setMovementMethod(LinkMovementMethod.getInstance());//enable links
        aboutView.setPadding(50, 30, 50, 30);

        //build dialog
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setTitle("About")//title
                .setView(aboutView)//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).create() //build
                .show(); //display
        break;

    case DIALOG_SUBMISSION_ERR:
        AlertDialog.Builder submissionErrorDialog = new AlertDialog.Builder(this);
        submissionErrorDialog.setTitle("Submission Error")//title
                .setMessage("There was a problem submitting your complaint on the City's website.")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;

    case DIALOG_OTHER_COMPLAINT:
        final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS | InputType.TYPE_CLASS_TEXT);
        // capitalize letters + seperate words
        AlertDialog.Builder getComplaintDialog = new AlertDialog.Builder(this);
        getComplaintDialog.setTitle("Other...").setView(input)
                .setMessage("Give a categorical title for your complaint:")
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String value = input.getText().toString();
                        // add the item to list and make it selected
                        complaintsAdapter.insert(value, 0);
                        complaintSpinner.setSelection(0);
                        complaintsAdapter.notifyDataSetChanged();
                        addToSubmitValues(value);

                        imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);//hide keyboard   
                        dialog.cancel();

                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);//hide keyboard              
                        dialog.cancel();
                    }
                }).create();

        input.requestFocus();
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);// show keyboard

        getComplaintDialog.show();//show dialog
        break;
    case DIALOG_NO_GEOCODING:
        AlertDialog.Builder noGeoCoding = new AlertDialog.Builder(this);
        noGeoCoding.setTitle("Not Available")//title
                .setMessage(
                        "Your version of Android does not support location-based address lookup. This feature is only supported on Gingerbread and above.")//insert textview from above
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;
    case DIALOG_INCOMPLETE_PERSONAL_INFORMATION:
        AlertDialog.Builder incompleteInfo = new AlertDialog.Builder(this);
        incompleteInfo.setTitle("Incomplete")//title
                .setMessage(
                        "Your personal information is incomplete. Select 'Edit Personal Information' from the menu and fill in all required fields")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display         
        break;
    case DIALOG_NO_COMPLAINT:
        AlertDialog.Builder noComplaint = new AlertDialog.Builder(this);
        noComplaint.setTitle("No Comlaint Specified")//title
                .setMessage("You must specify a complaint (e.g. barking dog).")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;
    case DIALOG_NO_LOCATION:
        AlertDialog.Builder incompleteComplaint = new AlertDialog.Builder(this);
        incompleteComplaint.setTitle("No Location Specified")//title
                .setMessage("You must specify a location (approximate street address) of the complaint.")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display         
    }

}

From source file:nya.miku.wishmaster.api.AbstractChanModule.java

/**
 *     ( ?/ )  ? ? ? ? ?//*from ww w .  j  a v  a 2s .c  o  m*/
 * @param group ,   ??? 
 */
protected void addPasswordPreference(PreferenceGroup group) {
    final Context context = group.getContext();
    EditTextPreference passwordPref = new EditTextPreference(context); //  ?
    passwordPref.setTitle(R.string.pref_password_title);
    passwordPref.setDialogTitle(R.string.pref_password_title);
    passwordPref.setSummary(R.string.pref_password_summary);
    passwordPref.setKey(getSharedKey(PREF_KEY_PASSWORD));
    passwordPref.getEditText()
            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    passwordPref.getEditText().setSingleLine();
    passwordPref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(255) });
    group.addPreference(passwordPref);
}

From source file:com.wearapp.PickFriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pick_friends_activity);
    newPermissionsRequest = new NewPermissionsRequest(this, Arrays.asList("xmpp_login"));
    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit();
    } else {/*w  ww  .  ja v a  2s  .  com*/
        // Subsequent times, our fragment is recreated by the framework and
        // already has saved and
        // restored its state, so we don't need to specify args again. (In
        // fact, this might be
        // incorrect if the fragment was modified programmatically since it
        // was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFriendsActivity.this.onError(error);
        }
    });

    friendPickerFragment.setOnSelectionChangedListener(new OnSelectionChangedListener() {
        @Override
        public void onSelectionChanged(PickerFragment<?> fragment) {
            // TODO Auto-generated method stub

            selectedUsers_temp1 = friendPickerFragment.getSelection();

            /*tempselectedUsers = friendPickerFragment.getSelection();
                    
            if (selectedUsers.size()==0)
            {
               selectedUsers = tempselectedUsers;
            }
                    
                    
            for (GraphUser u :tempselectedUsers)
            {                              
               if (!selectedUsers.contains(u))
               {
             selectedUsers.add(u);
             System.out.println("XX-add"+u.getName());
               }
                       
            }
                    
                    
            Iterator<GraphUser> it = selectedUsers.iterator();
               while(it.hasNext()) {
                     
             GraphUser u = it.next();
             if (!tempselectedUsers.contains(u))
             {                                        
                it.remove();
                selectedUsers.remove(u);
                System.out.println("XX-remove"+u.getName());
             }
               }
                    
                    
            System.out.println("XX===="+selectedUsers.size()+"====");
            for (GraphUser u :selectedUsers)
            {
               System.out.println("XX"+u.getName());
            }
            System.out.println("XX========");*/

        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {
            // We just store our selection in the Application for other
            // activities to look at.
            // FriendPickerApplication application =
            // (FriendPickerApplication) getApplication();

            // if No friends selected , show the dialog
            if ((selectedUsers.size() == 0) && (selectedUsers_temp1.size() == 0)) {
                Toast.makeText(getApplicationContext(), "No selected users, Message not sent",
                        Toast.LENGTH_LONG).show();

            } else if ((selectedUsers.size() == 0) && (selectedUsers_temp1.size() != 0)) // if the friend list not been filtered by keywords, initiate the selectedUsers list
            {
                selectedUsers = selectedUsers_temp1;
            }

            //remove duplicated friends in the selected friend list
            for (int i = 0; i < selectedUsers.size() - 1; i++) {
                for (int j = selectedUsers.size() - 1; j > i; j--) {
                    if (selectedUsers.get(j).getId().equals(selectedUsers.get(i).getId()))
                        selectedUsers.remove(j);
                }
            }

            Session session = Session.getActiveSession();

            editDialog = new EditText(PickFriendsActivity.this);
            editDialog.setRawInputType(Configuration.KEYBOARD_QWERTY);
            editDialog.setInputType(InputType.TYPE_CLASS_TEXT);

            if (session.isOpened()) {
                session.requestNewReadPermissions(newPermissionsRequest);

                for (GraphUser selectedUser : selectedUsers) {
                    if (selectedUsers.size() - 1 != selectedUsers.indexOf(selectedUser))
                        friendslist_selected.append(selectedUser.getName() + ",");
                    else
                        friendslist_selected.append(selectedUser.getName());
                }

                new AlertDialog.Builder(PickFriendsActivity.this)
                        .setMessage("Please edit the messages to send to " + friendslist_selected + " in "
                                + LocationUtil.selectedlocation.getName() + " ?")
                        .setView(editDialog).setPositiveButton("YES", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub                                       
                                sendMessage();
                                finishActivity();
                            }
                        }).setNegativeButton("NO", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub
                                Toast.makeText(getApplicationContext(), "Message not sent", Toast.LENGTH_LONG)
                                        .show();
                                finishActivity();
                            }
                        }).show();
            }
        }
    });
}

From source file:ca.mudar.mtlaucasou.BaseMapActivity.java

/**
 * Show dialog to type postal code for Geocode search.
 *///  w  w  w .  j a  va 2  s  .com
private void showPostalCodeDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(R.string.dialog_postal_code_title);
    alert.setMessage(R.string.dialog_postal_code_summary);

    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    input.setHint(R.string.input_hint_postal_code);
    alert.setView(input);

    alert.setPositiveButton(R.string.dialog_btn_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            /**
             * Store value and show processing dialog. Geocode search will
             * be done in a thread.
             */
            postalCode = input.getText().toString();
            showDialogProcessing();
        }
    });
    alert.setNegativeButton(R.string.dialog_btn_cancel, null);

    alert.show();
}

From source file:org.site_monitor.activity.MainActivity.java

public void floatingAddSite(final View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.add_monitor);
    final EditText input = new EditText(context);
    input.setHint(R.string.hint_site_url);
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
            | InputType.TYPE_TEXT_VARIATION_URI);
    builder.setView(input);/*from www  .  ja  v  a  2  s  .  co  m*/
    builder.setPositiveButton(R.string.action_add, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String host = input.getText().toString().trim();
            if (host.isEmpty()) {
                return;
            }
            try {
                DBSiteSettings dbSiteSettings = dbHelper.getDBSiteSettings();
                if (dbSiteSettings.findForHost(host) != null) {
                    Snackbar.make(v, host + getString(R.string.already_exists), Snackbar.LENGTH_SHORT).show();
                    return;
                }
                SiteSettings siteSettings = new SiteSettings(host);
                dbSiteSettings.create(siteSettings);
                alarmUtil.startAlarmIfNeeded(context);
                new CallSiteTask(context, taskFragment).execute(siteSettings);
                SiteSettingsActivity.start(context, siteSettings.getHost());
            } catch (SQLException e) {
                Log.e(TAG, "create", e);
            }
        }
    });
    builder.setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    builder.show();
}