Example usage for android.view.inputmethod InputMethodManager toggleSoftInput

List of usage examples for android.view.inputmethod InputMethodManager toggleSoftInput

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager toggleSoftInput.

Prototype

public void toggleSoftInput(int showFlags, int hideFlags) 

Source Link

Document

This method toggles the input method window display.

Usage

From source file:org.gluu.super_gluu.app.activities.MainNavDrawerActivity.java

@Override
public void onCancel(PinCodeFragment.EntryType entryType) {

    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
            Activity.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
    }// w  w w . j  a va2 s .  c  om

    if (entryType == PinCodeFragment.EntryType.SETTING_NEW) {
        Settings.setPinCodeEnabled(getBaseContext(), false);
        Settings.clearPinCode(getBaseContext());
    }

    onBackPressed();
}

From source file:com.itude.mobile.mobbl.core.controller.MBViewManager.java

public void showSoftKeyBoard(View triggeringView) {
    InputMethodManager imm = (InputMethodManager) triggeringView.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}

From source file:org.akvo.caddisfly.ui.activity.MainActivity.java

public void onSaveCalibration() {
    final Context context = this;
    final MainApp mainApp = (MainApp) this.getApplicationContext();

    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    final EditText input = new EditText(context);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(22) });

    alertDialogBuilder.setView(input);/*from  w w  w.ja v a  2s  .  c o m*/
    alertDialogBuilder.setCancelable(false);

    alertDialogBuilder.setTitle(R.string.saveCalibration);
    alertDialogBuilder.setMessage(R.string.giveNameForCalibration);

    alertDialogBuilder.setPositiveButton(R.string.ok, null);
    alertDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int i) {
            closeKeyboard(input);
            dialog.cancel();
        }
    });
    final AlertDialog alertDialog = alertDialogBuilder.create(); //create the box

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {

            Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            b.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {

                    if (!input.getText().toString().trim().isEmpty()) {
                        final ArrayList<String> exportList = new ArrayList<String>();

                        for (ColorInfo aColorList : mainApp.colorList) {
                            exportList.add(ColorUtils.getColorRgbString(aColorList.getColor()));
                        }

                        File external = Environment.getExternalStorageDirectory();
                        final String path = external.getPath() + Config.CALIBRATE_FOLDER_NAME;

                        File file = new File(path + input.getText());
                        if (file.exists()) {
                            AlertUtils.askQuestion(context, R.string.overwriteFile, R.string.nameAlreadyExists,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            FileUtils.saveToFile(path, input.getText().toString(),
                                                    exportList.toString());
                                        }
                                    });
                        } else {
                            FileUtils.saveToFile(path, input.getText().toString(), exportList.toString());
                        }

                        closeKeyboard(input);
                        alertDialog.dismiss();
                    } else {
                        input.setError(getString(R.string.invalidName));
                    }
                }
            });
        }
    });

    input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
                    || (actionId == EditorInfo.IME_ACTION_DONE)) {

            }
            return false;
        }
    });

    alertDialog.show();
    input.requestFocus();
    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

}

From source file:org.mozilla.gecko.tests.BaseTest.java

public void toggleVKB() {
    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}

From source file:com.songcode.materialnotes.ui.NotesListActivity.java

private void showSoftInput() {
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }//from   ww w . j  ava  2  s .  c o  m
}

From source file:com.juick.android.ThreadActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    JuickAdvancedApplication.maybeEnableAcceleration(this);
    JuickAdvancedApplication.setupTheme(this);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    //getSherlock().requestFeature(Window.FEATURE_NO_TITLE);
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    super.onCreate(savedInstanceState);
    handler = new Handler();

    Intent i = getIntent();/*from  w ww  .  java 2  s  . c  o m*/
    mid = (MessageID) i.getSerializableExtra("mid");
    if (mid == null) {
        finish();
    }

    messagesSource = (MessagesSource) i.getSerializableExtra("messagesSource");
    if (sp.getBoolean("fullScreenThread", false)) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }
    setContentView(R.layout.thread);
    /*
            findViewById(R.id.gotoMain).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        startActivity(new Intent(ThreadActivity.this, MainActivity.class));
    }
            });
    */
    final View buttons = findViewById(R.id.buttons);
    bSend = (ImageButton) findViewById(R.id.buttonSend);
    bSend.setOnClickListener(this);
    bAttach = (ImageButton) findViewById(R.id.buttonAttachment);
    bAttach.setOnClickListener(this);
    etMessage = (EditText) findViewById(R.id.editMessage);

    if (sp.getBoolean("helvNueFonts", false)) {
        etMessage.setTypeface(JuickAdvancedApplication.helvNue);
        /*
                    TextView oldTitle = (TextView)findViewById(R.id.old_title);
                    oldTitle.setTypeface(JuickAdvancedApplication.helvNue);
        */
    }

    Button cancel = (Button) findViewById(R.id.buttonCancel);
    cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            doCancel();
        }
    });

    tvReplyTo = (TextView) findViewById(R.id.textReplyTo);
    replyToContainer = (RelativeLayout) findViewById(R.id.replyToContainer);
    setHeight(replyToContainer, 0);
    showThread = (Button) findViewById(R.id.showThread);
    draftsButton = (Button) findViewById(R.id.drafts);
    etMessage.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                etMessage.setHint("");
                setHeight(buttons, ActionBar.LayoutParams.WRAP_CONTENT);
                InputMethodManager inputMgr = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                inputMgr.toggleSoftInput(0, 0);
            } else {
                etMessage.setHint(R.string.ClickToReply);
                setHeight(buttons, 0);
            }
            //To change body of implemented methods use File | Settings | File Templates.
        }
    });
    draftsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            class Item {
                String label;
                long ts;
                int index;

                Item(String label, long ts, int index) {
                    this.label = label;
                    this.ts = ts;
                    this.index = index;
                }
            }
            final ArrayList<Item> items = new ArrayList<Item>();
            final SharedPreferences drafts = getSharedPreferences("drafts", MODE_PRIVATE);
            for (int q = 0; q < 1000; q++) {
                String msg = drafts.getString("message" + q, null);
                if (msg != null) {
                    if (msg.length() > 50)
                        msg = msg.substring(0, 50);
                    items.add(new Item(msg, drafts.getLong("timestamp" + q, 0), q));
                }
            }
            Collections.sort(items, new Comparator<Item>() {
                @Override
                public int compare(Item item, Item item2) {
                    final long l = item2.ts - item.ts;
                    return l == 0 ? 0 : l > 0 ? 1 : -1;
                }
            });
            CharSequence[] arr = new CharSequence[items.size()];
            for (int i1 = 0; i1 < items.size(); i1++) {
                Item item = items.get(i1);
                arr[i1] = item.label;
            }
            new AlertDialog.Builder(ThreadActivity.this).setItems(arr, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, final int which) {
                    final Runnable doPull = new Runnable() {
                        @Override
                        public void run() {
                            pullDraft(null, drafts, items.get(which).index);
                            updateDraftsButton();
                        }
                    };
                    if (pulledDraft != null
                            && pulledDraft.trim().equals(etMessage.getText().toString().trim())) {
                        // no need to ask, user just looks at the drafts
                        saveDraft(pulledDraftRid, pulledDraftMid, pulledDraftTs, pulledDraft);
                        doPull.run();
                    } else {
                        if (etMessage.getText().toString().length() > 0) {
                            new AlertDialog.Builder(ThreadActivity.this)
                                    .setTitle(getString(R.string.ReplacingText))
                                    .setMessage(getString(R.string.YourTextWillBeReplaced))
                                    .setNegativeButton(android.R.string.ok,
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    doPull.run();
                                                }

                                            })
                                    .setNeutralButton(
                                            getString(pulledDraft != null ? R.string.SaveChangedDraft
                                                    : R.string.SaveDraft),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (pulledDraft != null) {
                                                        saveDraft(pulledDraftRid, pulledDraftMid,
                                                                System.currentTimeMillis(),
                                                                etMessage.getText().toString());
                                                    } else {
                                                        saveDraft(rid, mid.toString(),
                                                                System.currentTimeMillis(),
                                                                etMessage.getText().toString());
                                                    }
                                                    doPull.run();
                                                }
                                            })
                                    .setPositiveButton(android.R.string.cancel,
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                }
                                            })
                                    .show();
                        } else {
                            doPull.run();
                        }
                    }
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).show();
        }
    });
    enableDrafts = (sp.getBoolean("enableDrafts", false));
    if (sp.getBoolean("capitalizeReplies", false)) {
        etMessage.setInputType(etMessage.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
    }
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    tf = new ThreadFragment();
    tf.init(getLastCustomNonConfigurationInstance(), this);
    Bundle args = new Bundle();
    args.putSerializable("mid", mid);
    args.putSerializable("messagesSource", messagesSource);
    args.putSerializable("prefetched", i.getSerializableExtra("prefetched"));
    args.putSerializable("originalMessage", i.getSerializableExtra("originalMessage"));
    args.putBoolean("scrollToBottom", i.getBooleanExtra("scrollToBottom", false));
    tf.setArguments(args);
    ft.add(R.id.threadfragment, tf);
    ft.commit();
    MainActivity.restyleChildrenOrWidget(getWindow().getDecorView());
    detector = new GestureDetector(this, new GestureDetector.OnGestureListener() {
        @Override
        public boolean onDown(MotionEvent e) {
            return false;
        }

        @Override
        public void onShowPress(MotionEvent e) {

        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            return false;
        }

        @Override
        public void onLongPress(MotionEvent e) {

        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (velocityX > 0 && Math.abs(velocityX) > 4 * Math.abs(velocityY) && Math.abs(velocityX) > 400) {
                if (etMessage.getText().toString().trim().length() == 0) {
                    System.out.println("velocityX=" + velocityX + " velocityY" + velocityY);
                    if (sp.getBoolean("swipeToClose", true)) {
                        onBackPressed();
                    }
                }
            }
            return false;
        }
    });

    com.actionbarsherlock.app.ActionBar actionBar = getSherlock().getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setLogo(R.drawable.back_button);

}

From source file:com.undatech.opaque.RemoteCanvasActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // TODO: Implement left-icon
    //requestWindowFeature(Window.FEATURE_LEFT_ICON);
    //setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon); 

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    handler = new Handler();
    setContentView(R.layout.canvas);//from  www.  j a v a  2  s.c  o m
    canvas = (RemoteCanvas) findViewById(R.id.canvas);

    Intent i = getIntent();
    String vvFileName = startSessionFromVvFile(i);
    if (vvFileName == null) {
        android.util.Log.d(TAG, "Initializing session from connection settings.");
        connection = (ConnectionSettings) i.getSerializableExtra("com.undatech.opaque.ConnectionSettings");
        canvas.initialize(connection);
    } else {
        canvas.initialize(vvFileName, connection);
    }

    canvas.setOnKeyListener(this);
    canvas.setFocusableInTouchMode(true);
    canvas.setDrawingCacheEnabled(false);

    // If rotation is disabled, fix the orientation to the current one.
    if (!connection.isRotationEnabled()) {
        int orientation = getResources().getConfiguration().orientation;
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }

    // This code detects when the soft keyboard is up and sets an appropriate visibleHeight in the canvas.
    // When the keyboard is gone, it resets visibleHeight and pans zero distance to prevent us from being
    // below the desktop image (if we scrolled all the way down when the keyboard was up).
    // TODO: Move this into a separate thread, and post the visibility changes to the handler.
    //       to avoid occupying the UI thread with this.
    final View rootView = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();

            rootView.getWindowVisibleDisplayFrame(r);

            // To avoid setting the visible height to a wrong value after an screen unlock event
            // (when r.bottom holds the width of the screen rather than the height due to a rotation)
            // we make sure r.top is zero (i.e. there is no notification bar and we are in full-screen mode)
            // It's a bit of a hack.
            if (r.top == 0) {
                if (canvas.myDrawable != null) {
                    canvas.setVisibleDesktopHeight(r.bottom);
                    canvas.relativePan(0, 0);
                }
            }

            // Enable/show the zoomer if the keyboard is gone, and disable/hide otherwise.
            // We detect the keyboard if more than 19% of the screen is covered.
            int offset = 0;
            int rootViewHeight = rootView.getHeight();
            if (r.bottom > rootViewHeight * 0.81) {
                offset = rootViewHeight - r.bottom;
                // Soft Kbd gone, shift the meta keys and arrows down.
                if (layoutKeys != null) {
                    layoutKeys.offsetTopAndBottom(offset);
                    keyStow.offsetTopAndBottom(offset);
                    if (prevBottomOffset != offset) {
                        setExtraKeysVisibility(View.GONE, false);
                        canvas.invalidate();
                        kbdIcon.enable();
                    }
                }
            } else {
                offset = r.bottom - rootViewHeight;
                //  Soft Kbd up, shift the meta keys and arrows up.
                if (layoutKeys != null) {
                    layoutKeys.offsetTopAndBottom(offset);
                    keyStow.offsetTopAndBottom(offset);
                    if (prevBottomOffset != offset) {
                        setExtraKeysVisibility(View.VISIBLE, true);
                        canvas.invalidate();
                        kbdIcon.hide();
                        kbdIcon.disable();
                    }
                }
            }
            setKeyStowDrawableAndVisibility();
            prevBottomOffset = offset;
        }
    });

    kbdIcon = (ZoomControls) findViewById(R.id.zoomer);
    kbdIcon.hide();
    kbdIcon.setOnZoomKeyboardClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMgr.toggleSoftInput(0, 0);
        }
    });

    // Initialize and define actions for on-screen keys.
    initializeOnScreenKeys();

    myVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    // Initialize map from XML IDs to input handlers.
    inputHandlerIdMap = new HashMap<Integer, InputHandler>();
    inputHandlerIdMap.put(R.id.inputMethodDirectSwipePan,
            new InputHandlerDirectSwipePan(this, canvas, myVibrator));
    inputHandlerIdMap.put(R.id.inputMethodDirectDragPan,
            new InputHandlerDirectDragPan(this, canvas, myVibrator));
    inputHandlerIdMap.put(R.id.inputMethodTouchpad, new InputHandlerTouchpad(this, canvas, myVibrator));
    inputHandlerIdMap.put(R.id.inputMethodSingleHanded, new InputHandlerSingleHanded(this, canvas, myVibrator));

    android.util.Log.e(TAG, "connection.getInputMethod(): " + connection.getInputMethod());
    inputHandler = idToInputHandler(connection.getInputMethod());
}

From source file:org.linphone.ContactEditorFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.inflater = inflater;

    contact = null;// w w  w .jav  a 2 s. c om
    if (getArguments() != null) {
        if (getArguments().getSerializable("Contact") != null) {
            contact = (Contact) getArguments().getSerializable("Contact");
            isNewContact = false;
            contactID = Integer.parseInt(contact.getID());
            contact.refresh(getActivity().getContentResolver());
            if (getArguments().getString("NewSipAdress") != null) {
                newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
            }

        } else if (getArguments().getString("NewSipAdress") != null) {
            newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
            isNewContact = true;
        }
    }

    contactsManager = ContactsManager.getInstance();

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

    deleteContact = (ImageView) view.findViewById(R.id.delete_contact);

    cancel = (ImageView) view.findViewById(R.id.cancel);
    cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getFragmentManager().popBackStackImmediate();
        }
    });

    ok = (ImageView) view.findViewById(R.id.ok);
    ok.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isNewContact) {
                boolean areAllFielsEmpty = true;
                for (NewOrUpdatedNumberOrAddress nounoa : numbersAndAddresses) {
                    if (nounoa.newNumberOrAddress != null && !nounoa.newNumberOrAddress.equals("")) {
                        areAllFielsEmpty = false;
                        break;
                    }
                }
                if (areAllFielsEmpty) {
                    getFragmentManager().popBackStackImmediate();
                    return;
                }
                contactsManager.createNewContact(ops, firstName.getText().toString(),
                        lastName.getText().toString());
                setContactPhoto();
            } else {
                contactsManager.updateExistingContact(ops, contact, firstName.getText().toString(),
                        lastName.getText().toString());
                setContactPhoto();
            }

            for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
                numberOrAddress.save();
            }

            try {
                getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
                addLinphoneFriendIfNeeded();
                removeLinphoneTagIfNeeded();
                contactsManager.prepareContactsInBackground();
            } catch (Exception e) {
                e.printStackTrace();
            }

            getFragmentManager().popBackStackImmediate();

            if (LinphoneActivity.instance().getResources().getBoolean(R.bool.isTablet))
                ContactsListFragment.instance().invalidate();
        }
    });

    lastName = (EditText) view.findViewById(R.id.contactLastName);
    // Hack to display keyboard when touching focused edittext on Nexus One
    if (Version.sdkStrictlyBelow(Version.API11_HONEYCOMB_30)) {
        lastName.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                InputMethodManager imm = (InputMethodManager) LinphoneActivity.instance()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
            }
        });
    }
    lastName.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (lastName.getText().length() > 0 || firstName.getText().length() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }

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

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

    firstName = (EditText) view.findViewById(R.id.contactFirstName);
    firstName.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (firstName.getText().length() > 0 || lastName.getText().length() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }

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

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

    if (!isNewContact) {
        String fn = findContactFirstName(String.valueOf(contactID));
        String ln = findContactLastName(String.valueOf(contactID));
        if (fn != null || ln != null) {
            firstName.setText(fn);
            lastName.setText(ln);
        } else {
            lastName.setText(contact.getName());
            firstName.setText("");
        }
        deleteContact.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final Dialog dialog = LinphoneActivity.instance()
                        .displayDialog(getString(R.string.delete_text));
                Button delete = (Button) dialog.findViewById(R.id.delete_button);
                Button cancel = (Button) dialog.findViewById(R.id.cancel);

                delete.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        deleteExistingContact();
                        ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(),
                                contact);
                        LinphoneActivity.instance().displayContacts(false);
                        dialog.dismiss();
                    }
                });

                cancel.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();

                    }
                });
                dialog.show();
            }
        });
    } else {
        deleteContact.setVisibility(View.INVISIBLE);
    }

    contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
    if (contact != null && contact.getPhotoUri() != null) {
        InputStream input = Compatibility.getContactPictureInputStream(getActivity().getContentResolver(),
                contact.getID());
        contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
    } else {
        contactPicture.setImageResource(R.drawable.avatar);
    }

    contactPicture.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            pickImage();
        }
    });

    numbersAndAddresses = new ArrayList<NewOrUpdatedNumberOrAddress>();
    sipAddresses = initSipAddressFields(contact);
    numbers = initNumbersFields(contact);

    addSipAddress = (ImageView) view.findViewById(R.id.add_address_field);
    addSipAddress.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addEmptyRowToAllowNewNumberOrAddress(sipAddresses, true);
        }
    });

    addNumber = (ImageView) view.findViewById(R.id.add_number_field);
    addNumber.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addEmptyRowToAllowNewNumberOrAddress(numbers, false);
        }
    });

    ops = new ArrayList<ContentProviderOperation>();
    lastName.requestFocus();

    return view;
}

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

private void startEditTagsMode() {
    ImageButton editButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        editButton.setImageResource(R.drawable.ic_edit_anim);
        ((Animatable) editButton.getDrawable()).start();
    } else/*from  w  ww. j av a 2 s  .c  om*/
        editButton.setImageResource(R.drawable.ic_done);

    ((DrawerLayout) ((MainActivity) getActivity()).drawer)
            .setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    mRefreshLayout.setEnabled(false);
    getActivity().findViewById(R.id.refresh_fab).setEnabled(false);
    ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).hide();
    ((Toolbar) getActivity().findViewById(R.id.toolbar)).getMenu().clear();

    TextSwitcher textSwitcher = ((TextSwitcher) getActivity().findViewById(R.id.switcher));
    EditText songTV = (EditText) getActivity().findViewById(R.id.song);
    TextView artistTV = ((TextView) getActivity().findViewById(R.id.artist));

    EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics);
    newLyrics.setTypeface(LyricsTextFactory.FontCache.get("light", getActivity()));
    newLyrics.setText(((TextView) textSwitcher.getCurrentView()).getText(), TextView.BufferType.EDITABLE);

    textSwitcher.setVisibility(View.GONE);
    newLyrics.setVisibility(View.VISIBLE);

    songTV.setInputType(InputType.TYPE_CLASS_TEXT);
    artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
    songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
    artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);

    if (songTV.requestFocus()) {
        InputMethodManager imm = (InputMethodManager) getActivity().getApplicationContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT);
    }
}

From source file:net.smartpager.android.activity.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // exclude keyboard appearance on volume change
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_MENU:
        return super.onKeyUp(keyCode, event);
    default://from  w  w  w.  ja  v  a 2 s . c  o m
        break;
    }

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, 0);

    return super.onKeyUp(keyCode, event);
}