Example usage for android.view View getWindowToken

List of usage examples for android.view View getWindowToken

Introduction

In this page you can find the example usage for android.view View getWindowToken.

Prototype

public IBinder getWindowToken() 

Source Link

Document

Retrieve a unique token identifying the window this view is attached to.

Usage

From source file:com.google.reviewit.ServerSettingsFragment.java

private void init() {
    final AutoCompleteTextView urlInput = (AutoCompleteTextView) v(R.id.urlInput);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1,
            getResources().getStringArray(R.array.urls));
    urlInput.setAdapter(adapter);//from   w  w w .  ja v  a  2 s .  c o  m

    v(R.id.pasteCredentialsButton).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            if (clipboard.hasPrimaryClip()
                    && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
                String pasteData = item.getText().toString();
                if (!pasteData.contains("/.gitcookies")) {
                    return;
                }

                pasteData = pasteData.substring(pasteData.indexOf("/.gitcookies"));
                pasteData = pasteData.substring(pasteData.lastIndexOf(",") + 1);
                int pos = pasteData.indexOf("=");
                String user = pasteData.substring(0, pos);
                pasteData = pasteData.substring(pos + 1);
                String password = pasteData.substring(0, pasteData.indexOf("\n"));
                WidgetUtil.setText(v(R.id.userInput), user);
                WidgetUtil.setText(v(R.id.passwordInput), password);

                // hide keyboard if it is open
                View view = getActivity().getCurrentFocus();
                if (view != null) {
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            }
        }
    });

    ((EditText) v(R.id.urlInput)).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) {
            if (Strings.isNullOrEmpty(textOf(R.id.nameInput))) {
                try {
                    String host = new URL(s.toString()).getHost();
                    int pos = host.indexOf(".");
                    WidgetUtil.setText(v(R.id.nameInput), pos > 0 ? host.substring(0, pos) : host);
                } catch (MalformedURLException e) {
                    // ignore
                }
            }
            displayCredentialsInfo(s.toString());
        }
    });

    v(R.id.saveServerSettings).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            enabledForm(false);

            if (!isServerInputComplete()) {
                widgetUtil.showError(R.string.incompleteInput);
                enabledForm(true);
                return;
            }

            if (!isUrlValid()) {
                widgetUtil.showError(R.string.invalidUrl);
                enabledForm(true);
                return;
            }

            if (!hasUniqueName()) {
                widgetUtil.showError(getString(R.string.duplicate_server_name, textOf(R.id.nameInput)));
                enabledForm(true);
                return;
            }

            setVisible(v(R.id.statusTestConnection, R.id.statusTestConnectionProgress));
            WidgetUtil.setText(v(R.id.statusTestConnectionText), null);
            new AsyncTask<Void, Void, String>() {
                private TextView status;
                private View statusTestConnectionProgress;
                private View statusTestConnection;

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    status = tv(R.id.statusTestConnectionText);
                    statusTestConnectionProgress = v(R.id.statusTestConnectionProgress);
                    statusTestConnection = v(R.id.statusTestConnection);
                }

                @Override
                protected String doInBackground(Void... v) {
                    return testConnection();
                }

                protected void onPostExecute(String errorMsg) {
                    if (errorMsg != null) {
                        enabledForm(true);
                        status.setTextColor(widgetUtil.color(R.color.statusFailed));
                        status.setText(getString(R.string.test_server_connection_failed));
                        setInvisible(statusTestConnectionProgress);
                        new AlertDialog.Builder(getContext()).setTitle(getString(R.string.error_title))
                                .setMessage(getString(R.string.connection_failed, errorMsg))
                                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        // do nothing
                                    }
                                }).setNegativeButton(getString(R.string.save_anyway),
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                                setGone(statusTestConnection);
                                                onServerSave(saveServerSettings());
                                            }
                                        })
                                .setIcon(android.R.drawable.ic_dialog_alert).show();
                    } else {
                        status.setTextColor(widgetUtil.color(R.color.statusOk));
                        status.setText(getString(R.string.test_server_connection_ok));
                        setGone(statusTestConnection);
                        onServerSave(saveServerSettings());
                    }
                }
            }.execute();
        }
    });

    enabledForm(true);
    setGone(v(R.id.statusTestConnection));
}

From source file:il.ac.shenkar.todos.view.MainActivity.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    // hide keyboard
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    return false;
}

From source file:org.mklab.mikity.android.editor.AbstractObjectEditor.java

/**
 * {@inheritDoc}/* www.j  a v a2 s  .  co m*/
 */
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
        final InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
        saveParameters();
        return true;
    }

    return false;
}

From source file:file_manager.Activity_files.java

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    }//  www .j  a  v a2s  .  c  om

    PackageManager pm = getPackageManager();
    boolean isInstalled = isPackageInstalled("de.baumann.pdfcreator", pm);

    if (isInstalled) {
        PackageManager p = getPackageManager();
        p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("de.baumann.pdfcreator");
        LaunchIntent.setAction("pdf_openFolder");
        startActivity(LaunchIntent);
        finish();
    }

    setContentView(R.layout.activity_file_manager);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit()
            .putString("files_startFolder",
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath())
            .apply();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    listView = (ListView) findViewById(R.id.listNotes);
    filter_layout = (RelativeLayout) findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    filter = (EditText) findViewById(R.id.myFilter);

    ImageButton ib_hideKeyboard = (ImageButton) findViewById(R.id.ib_hideKeyboard);
    ib_hideKeyboard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            filter_layout.setVisibility(View.GONE);
            setFilesList();
        }
    });

    //calling Notes_DbAdapter
    db = new DbAdapter_Files(this);
    db.open();

    setTitle();
    setFilesList();
}

From source file:de.stadtrallye.rallyesoft.fragments.AssistantServerFragment.java

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

    scrollView = (ScrollView) v.findViewById(R.id.scrollView);

    protocol = (Spinner) v.findViewById(R.id.protocol);
    edit_server = (EditText) v.findViewById(R.id.server);
    port = (EditText) v.findViewById(R.id.port);
    //      path = (EditText) v.findViewById(R.id.path);

    port.setHint(Std.DEFAULT_PORT);//from   w w  w .  ja va 2s .  com
    //      path.setHint(Std.DEFAULT_PATH);

    //      path.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    //         @Override
    //         public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    //            if (actionId == EditorInfo.IME_ACTION_SEND) {
    //               infoManager.startTest();
    //            }
    //            return false;
    //         }
    //      });

    btn_test = (Button) v.findViewById(R.id.test);
    btn_test.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            View focus = getActivity().getCurrentFocus();
            if (focus != null) {
                InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(focus.getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }
            infoManager.startTest();
        }
    });

    grp_server_info_manager = (ViewGroup) v.findViewById(R.id.info_manager);
    grp_server_info = (ViewGroup) v.findViewById(R.id.server_info);
    grp_server_loading = (ViewGroup) v.findViewById(R.id.loading);
    srv_image = (ImageView) v.findViewById(R.id.server_image);
    srv_name = (TextView) v.findViewById(R.id.server_name);
    srv_desc = (TextView) v.findViewById(R.id.server_desc);

    btn_next = (Button) v.findViewById(R.id.next);
    btn_next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            assistant.next();
        }
    });

    loader = ImageLoader.getInstance();

    if (android.os.Build.VERSION.SDK_INT >= 11)
        setLayoutTransition((ViewGroup) v);

    return v;
}

From source file:org.mklab.mikity.android.SettingsFragment.java

/**
 * {@inheritDoc}//from   w  w  w.java2 s.co m
 */
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
        final InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
        saveEnvironment();
        return true;
    }

    return false;
}

From source file:com.limewoodmedia.nsdroid.activities.World.java

private void doSearch(final String string) {
    searchResults.removeAllViews();/*from www. ja v  a2s  .co m*/
    final LoadingView loadingView = (LoadingView) search.findViewById(R.id.loading);
    LoadingHelper.startLoading(loadingView, R.string.searching, this);
    // Don't update automatically if we're reading back in history
    errorMessage = getResources().getString(R.string.general_error);
    new ParallelTask<Void, Void, Boolean>() {
        protected Boolean doInBackground(Void... params) {
            try {
                try {
                    nData = API.getInstance(World.this).getNationInfo(string, NationData.Shards.NAME,
                            NationData.Shards.CATEGORY, NationData.Shards.REGION);
                } catch (UnknownNationException e) {
                    nData = null;
                }

                try {
                    rData = API.getInstance(World.this).getRegionInfo(string, NAME, NUM_NATIONS, DELEGATE);
                } catch (UnknownRegionException e) {
                    rData = null;
                }

                return true;
            } catch (RateLimitReachedException e) {
                e.printStackTrace();
                errorMessage = getResources().getString(R.string.rate_limit_reached);
            } catch (RuntimeException e) {
                e.printStackTrace();
                errorMessage = e.getMessage();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
                errorMessage = getResources().getString(R.string.xml_parser_exception);
            } catch (IOException e) {
                e.printStackTrace();
                errorMessage = getResources().getString(R.string.api_io_exception);
            }

            return false;
        }

        protected void onPostExecute(Boolean result) {
            LoadingHelper.stopLoading(loadingView);
            if (result) {
                // Show search results
                RelativeLayout nation = (RelativeLayout) getLayoutInflater().inflate(R.layout.search_nation,
                        searchResults, false);
                if (nData != null) {
                    ((TextView) nation.findViewById(R.id.nation_name)).setText(nData.name);
                    ((TextView) nation.findViewById(R.id.nation_category)).setText(nData.category);
                    ((TextView) nation.findViewById(R.id.nation_region)).setText(nData.region);
                    nation.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(World.this, Nation.class);
                            intent.setData(Uri.parse(
                                    "com.limewoodMedia.nsdroid.nation://" + TagParser.nameToId(nData.name)));
                            startActivity(intent);
                        }
                    });
                } else {
                    ((TextView) nation.findViewById(R.id.nation_name)).setText(R.string.no_nation_found);
                    ((TextView) nation.findViewById(R.id.nation_category)).setVisibility(View.GONE);
                    ((TextView) nation.findViewById(R.id.nation_region)).setVisibility(View.GONE);
                }
                searchResults.addView(nation);
                RelativeLayout region = (RelativeLayout) getLayoutInflater().inflate(R.layout.search_region,
                        searchResults, false);
                if (rData != null) {
                    ((TextView) region.findViewById(R.id.region_name)).setText(rData.name);
                    ((TextView) region.findViewById(R.id.region_nations))
                            .setText(Integer.toString(rData.numNations));
                    ((TextView) region.findViewById(R.id.region_wad)).setText(rData.delegate);
                    region.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(World.this, Region.class);
                            intent.setData(Uri.parse(
                                    "com.limewoodMedia.nsdroid.region://" + TagParser.nameToId(rData.name)));
                            startActivity(intent);
                        }
                    });
                } else {
                    ((TextView) region.findViewById(R.id.region_name)).setText(R.string.no_region_found);
                    ((TextView) region.findViewById(R.id.region_nations_label)).setVisibility(View.GONE);
                    ((TextView) region.findViewById(R.id.region_nations)).setVisibility(View.GONE);
                    ((TextView) region.findViewById(R.id.region_wad_label)).setVisibility(View.GONE);
                    ((TextView) region.findViewById(R.id.region_wad)).setVisibility(View.GONE);
                }
                searchResults.addView(region);
            } else {
                Toast.makeText(World.this, errorMessage, Toast.LENGTH_SHORT).show();
            }
            View view = World.this.getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
        }
    }.execute();
}

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

private void hideKeyboard(View v) {
    try {/*from  w  w w  .  ja v a2 s.co m*/
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
}

From source file:com.codeim.coxin.LoginActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        View v = getCurrentFocus();
        if (isShouldHideInput(v, ev)) {
            hideSoftInput(v.getWindowToken());
        }//from  w w  w . java2 s. c  om
    }
    return super.dispatchTouchEvent(ev);
}

From source file:co.carlosjimenez.android.currencyalerts.app.MainActivityFragment.java

/**
 * This method forces the soft keyboard to hide
 *//*from  ww w  . j  ava2  s . c o m*/
private void hideIme() {
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
    //Find the currently focused view, so we can grab the correct window token from it.
    View view = mContext.getCurrentFocus();
    //If no view currently has focus, create a new one, just so we can grab a window token from it
    if (view == null) {
        view = new View(mContext);
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}