Example usage for android.view KeyEvent getAction

List of usage examples for android.view KeyEvent getAction

Introduction

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

Prototype

public final int getAction() 

Source Link

Document

Retrieve the action of this key event.

Usage

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

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

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

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

    bAdd = (ImageButton) viewById(R.id.send_comment);
    bAdd.setEnabled(false);//from  ww  w  .  ja v a2  s  .  c o  m

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

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

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

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

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

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

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

    return getRootView();
}

From source file:com.coincollection.ReorderCollections.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // If the screen rotated and our view got destroyed/recreated,
    // grab the list of collections from the old view (that we stored
    // in the bundle.)
    if (savedInstanceState != null) {
        mItems = savedInstanceState.getParcelableArrayList("mItems");
        mUnsavedChanges = savedInstanceState.getBoolean("mUnsavedChanges");
    }/*from   ww  w . j  av  a  2s . co  m*/

    RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.reorder_collections_recycler_view);

    mRecyclerView.setBackgroundColor(Color.BLACK);

    // Indicate that the contents do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // Use a linear layout manager
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);

    // Set up the adapter that provides the collection entries
    ReorderAdapter mAdapter = new ReorderAdapter(mItems, this);
    mRecyclerView.setAdapter(mAdapter);

    // Register the ItemTouchHelper Callback so that we can allow reordering
    // collections when the user drags the coin images or long presses and then
    // drags.
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(mRecyclerView);

    // Register a callback so we can know when the list has been reordered
    mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
            super.onItemRangeMoved(fromPosition, toPosition, itemCount);

            Log.d("onItemRangeMoved", String.valueOf(fromPosition) + " " + String.valueOf(toPosition) + " "
                    + String.valueOf(itemCount));

            ReorderCollections fragment = (ReorderCollections) getFragmentManager()
                    .findFragmentByTag("ReorderFragment");

            fragment.setUnsavedChanges(true);
            fragment.showUnsavedTextView();
        }
    });

    if (mUnsavedChanges) {
        showUnsavedTextView();
    }

    //http://stackoverflow.com/questions/7992216/android-fragment-handle-back-button-press
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                if (mUnsavedChanges) {
                    showUnsavedChangesMessage();
                } else {
                    closeFragment();
                }
                return true;
            }
            return false;
        }
    });
}

From source file:com.vikingbrain.dmt.view.RemoteControlActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

    int keyaction = event.getAction();
    int keyCode = event.getKeyCode();

    //Manage key up keys
    if (keyaction == KeyEvent.ACTION_UP) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            //Back button, exit the activity
            onBackPressed();// ww w .  ja v  a  2s  .  c o  m
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_DEL) {
            //this is for backspace
            addCharacterToSendQueue(Keyboard2RemoteKey.BACKSPACE.getKeyboardSymbol());
            return true;
        } else {
            //Any other keyboard key up         
            DmtLogger.d("key pressed", String.valueOf(event.getKeyCode()));
            char unicodeChar = (char) event.getUnicodeChar();
            String keyboardSymbol = String.valueOf(unicodeChar);

            addCharacterToSendQueue(keyboardSymbol);
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:cl.ipp.katbag.fragment.Add.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) super.getActivity();
    v = inflater.inflate(R.layout.fragment_add, container, false);

    // rescues parameters
    Bundle bundle = getArguments();//w w w  .j  av a2 s . c  o  m
    if (bundle != null) {
        type_app = bundle.getString("type_app");
    }

    progress = (ProgressBar) v.findViewById(R.id.progress);

    setTitleAndImageForTypeApp();

    name_app = (EditText) v.findViewById(R.id.name_app);
    name_app.setFilters(new InputFilter[] { KatbagUtilities.katbagAlphaNumericFilter,
            new InputFilter.LengthFilter(MAX_LENGTH) });
    name_app.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                validateName();
            }

            return false;
        }
    });

    config_app_worlds = (RelativeLayout) v.findViewById(R.id.config_app_worlds);
    config_app_drawings = (RelativeLayout) v.findViewById(R.id.config_app_drawings);
    config_app_developments = (RelativeLayout) v.findViewById(R.id.config_app_developments);
    config_app_pages = (RelativeLayout) v.findViewById(R.id.config_app_pages);

    config_app_worlds.setOnClickListener(this);
    config_app_drawings.setOnClickListener(this);
    config_app_developments.setOnClickListener(this);
    config_app_pages.setOnClickListener(this);

    if (type_app.contentEquals(MainActivity.TYPE_APP_GAME)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.VISIBLE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.GONE);

    } else if (type_app.contentEquals(MainActivity.TYPE_APP_BOOK)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.GONE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.VISIBLE);

    } else if (type_app.contentEquals(MainActivity.TYPE_APP_COMICS)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.GONE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.VISIBLE);
    }

    return v;
}

From source file:com.haoxue.zixueplayer.MainActivity.java

/**
 * ?/*from   ww w  .  j a va 2s . c  om*/
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        new CustomDialog.Builder(MainActivity.this).setTitle(R.string.info).setMessage(R.string.dialog_messenge)
                .setPositiveButton(R.string.confrim, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        exit();

                    }
                }).setNeutralButton(R.string.cancel, null).show();
        return false;
    }
    return false;
}

From source file:org.alfresco.mobile.android.application.fragments.help.HelpDialogFragment.java

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

    webView = (WebView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty);
    emptyTextView = (TextView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final FragmentActivity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override/*from   w w w . j  a v a2s.  c o  m*/
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            displayProgress(true);
            if (refreshIcon != null) {
                refreshIcon.setVisible(false);
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (getActivity() == null) {
                return;
            }
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }
            displayProgress(false);
            if (refreshIcon != null) {
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:org.catrobat.catroid.ui.dialogs.OverwriteRenameMediaDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_overwrite_media, null);

    replaceButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_media_radio_replace);
    replaceButton.setOnClickListener(this);
    renameButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_media_radio_rename);
    renameButton.setOnClickListener(this);
    mediaText = (EditText) dialogView.findViewById(R.id.dialog_overwrite_media_edit);
    mediaText.setText(mediaName);//www .java 2s  .  c  o m
    mediaTextView = (TextView) dialogView.findViewById(R.id.dialog_overwrite_media_edit_text);
    mediaTextLine = dialogView.findViewById(R.id.dialog_overwrite_media_edit_line);

    final int header;
    final int replaceText;
    final int renameText;
    final int renameHeaderText;
    switch (mediaType) {
    case Constants.MEDIA_TYPE_LOOK:
        header = R.string.look_rename_overwrite;
        replaceText = R.string.overwrite_replace_look;
        renameText = R.string.overwrite_rename_look;
        renameHeaderText = R.string.new_look_name;
        break;
    case Constants.MEDIA_TYPE_SOUND:
        header = R.string.rename_sound_overwrite;
        replaceText = R.string.overwrite_replace_sound;
        renameText = R.string.overwrite_rename_sound;
        renameHeaderText = R.string.new_sound_name;
        break;
    default:
        header = R.string.rename_sprite_dialog;
        replaceText = R.string.overwrite_replace_default;
        renameText = R.string.overwrite_rename_default;
        renameHeaderText = R.string.new_sound_name;
    }

    replaceButton.setText(replaceText);
    renameButton.setText(renameText);
    mediaTextView.setText(renameHeaderText);

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(header)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).create();

    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleOkButton();
                }
            });
        }
    });

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                if (!okButtonResult) {
                    return false;
                } else {
                    dismiss();
                }
                return okButtonResult;
            } else if (keyCode == KeyEvent.KEYCODE_BACK) {
                dismiss();
                return true;
            }
            return false;
        }
    });

    return dialog;
}

From source file:org.protocoder.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {

        int keyCode = event.getKeyCode();
        switch (keyCode) {
        case KeyEvent.KEYCODE_R:
            MLog.d(TAG, "run app");
            break;

        default:/*  w w w.ja va  2  s.  c o m*/
            break;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.alivenet.dmvtaxi.fragment.Fragment_ride_list.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_ride_list, container, false);
    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);

    progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage("Please wait...");
    progressDialog.setCancelable(false);

    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);/*from   w w w .jav  a2 s  .  c  o  m*/
    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    llm.setOrientation(LinearLayoutManager.VERTICAL);

    recyclerView.addItemDecoration(new SpacesItemDecoration(VERTICAL_ITEM_SPACE));

    recyclerView.setLayoutManager(llm);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    mnorides = (TextView) view.findViewById(R.id.tv_norides);
    RequestParams params = new RequestParams();
    params.put("userId", mUserId);
    rideListWs(params);

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener

                if (keyCode == KeyEvent.KEYCODE_BACK) {

                    Fragment homeFragment = new FragmentMainScreen();
                    FragmentManager frgManager;
                    frgManager = getFragmentManager();
                    frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit();

                    return true;
                }

                return true;
            }
            return false;
        }
    });

    return view;
}

From source file:com.github.kanata3249.ffxieq.android.AugmentEditActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            EditText et;//  www .jav  a2 s.  c o  m
            Equipment eq;

            eq = getDAO().instantiateEquipment(mBaseID, mAugID);
            et = (EditText) findViewById(R.id.AugmentDescription);
            if (eq != null && et != null) {
                String augment;

                augment = et.getText().toString();
                if (!eq.getAugment().equals(augment)) {
                    showDialog(R.string.QueryDiscardChanges);
                    return true;
                }
            }
        }
    }

    return super.dispatchKeyEvent(event);
}