List of usage examples for android.view ViewGroup requestFocus
public final boolean requestFocus()
From source file:ti.modules.titanium.ui.widget.TiUIEditText.java
/** * Called when key input has been received, but before it has been processed by the IME. * @param keyCode Unique integer ID of the key that was pressed/released. * @param event Provides additional key event details. * @return/*from w ww . j a va 2 s . c om*/ * Returns true if this method has handled the key and it should not be passed to the IME. * <p> * Returns false to allow the IME to handle the key. */ @Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { // Work-around Android bug where center-alisgned and right-aligned EditText won't // always pan above the virtual keyboard when given the focus. (See TIMOB-23757) boolean isLeftAligned = (getGravity() & Gravity.LEFT) != 0; if ((Build.VERSION.SDK_INT < 24) && !isLeftAligned && (keyCode == KeyEvent.KEYCODE_BACK)) { ViewGroup view = (ViewGroup) getParent(); view.setFocusableInTouchMode(true); view.requestFocus(); } return super.onKeyPreIme(keyCode, event); }
From source file:com.franmontiel.fullscreendialog.FullScreenDialogFragment.java
@Nullable @Override/*w ww .j a v a 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { initBuilderArguments(); if (fullScreen) hideActivityActionBar(savedInstanceState == null); ViewGroup view = (ViewGroup) inflater.inflate(R.layout.full_screen_dialog, container, false); initToolbar(view); if (fullScreen) setThemeBackground(view); view.setFocusableInTouchMode(true); view.requestFocus(); return view; }
From source file:android.support.v7.app.ToolbarActionBar.java
@Override public boolean requestFocus() { final ViewGroup viewGroup = mDecorToolbar.getViewGroup(); if (viewGroup != null && !viewGroup.hasFocus()) { viewGroup.requestFocus(); return true; }/*w w w . j av a 2 s. c o m*/ return false; }
From source file:com.coact.kochzap.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { maybeSetClipboard(resultHandler);/*w w w . j a v a2 s. c o m*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) { resultHandler.handleButtonPress(resultHandler.getDefaultButtonID()); return; } statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon)); } else { barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formatter.format(rawResult.getTimestamp())); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } CharSequence displayContents = resultHandler.getDisplayContents(); TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); contentsTextView.setText(displayContents); int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) { SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, resultHandler.getResult(), historyManager, this); } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } }
From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { final CharSequence displayContents = resultHandler.getDisplayContents(); // if (copyToClipboard && !resultHandler.areContentsSecure()) { // ClipboardInterface.setText(displayContents, this); // }//from w ww . j av a2 s . co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) { // resultHandler.handleButtonPress(resultHandler.getDefaultButtonID()); // return; // } statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); } else { barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp()))); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } final TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); final String baseUrl = "http://qrk.kuaipai.cn/loganal/base/scan/show-json-advert.action?code="; new Thread(new Runnable() { @Override public void run() { HttpGet get = new HttpGet(baseUrl + displayContents); Log.e(TAG, "full url = " + baseUrl + displayContents); HttpClient client = new DefaultHttpClient(); try { HttpResponse response = client.execute(get); String json = EntityUtils.toString(response.getEntity(), "UTF-8"); JSONObject jsonObject = new JSONObject(json); NetScanResult result = new NetScanResult(); result.name = jsonObject.getString("name"); result.url = jsonObject.getString("img"); Message message = new Message(); message.obj = result; message.what = 1; mNetHandler.sendMessage(message); } catch (Exception e) { mNetHandler.sendEmptyMessage(-1); e.printStackTrace(); } } }).start(); // contentsTextView.setText(displayContents); int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); // if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean( // PreferencesActivity.KEY_SUPPLEMENTAL, true)) { // SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, // resultHandler.getResult(), // historyManager, // this); // } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } }
From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { //- ------------------------------------------------------- // String text = rawResult.getText(); if (text != null && StringUtils.isUrl(text)) { if (text.contains("scan_login")) { statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); showConfirmLogin(text);// www . j av a 2s . c om return; } if (text.contains("oschina.net")) { UIHelper.showUrlRedirect(CaptureActivity.this, text); finish(); return; } } try { BarCode2 bc = BarCode2.parse(text); int type = bc.getType(); switch (type) { case BarCode2.SIGN_IN:// handleSignIn(bc); return; default: break; } } catch (JSONException e) { e.printStackTrace(); } //- ------------------------------------------------------- // CharSequence displayContents = resultHandler.getDisplayContents(); if (copyToClipboard && !resultHandler.areContentsSecure()) { ClipboardInterface.setText(displayContents, this); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) { resultHandler.handleButtonPress(resultHandler.getDefaultButtonID()); return; } statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.app_icon)); } else { barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp()))); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); contentsTextView.setText(displayContents); int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) { //SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, // resultHandler.getResult(), // historyManager, // this); } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } }
From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.qr_scan)); } else {/*from w w w. j av a2 s.c o m*/ barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); String formattedTime = formatter.format(new Date(rawResult.getTimestamp())); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formattedTime); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); CharSequence displayContents = resultHandler.getDisplayContents(); contentsTextView.setText(displayContents); // Crudely scale betweeen 22 and 32 -- bigger font for shorter text int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) { SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, resultHandler.getResult(), historyManager, this); } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } if (copyToClipboard && !resultHandler.areContentsSecure()) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (displayContents != null) { clipboard.setText(displayContents); } } }
From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java
@Nullable @Override/*from w ww . j a v a2s.c om*/ public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { resolveTheme(); LayoutInflater localInflater = getThemeInflater(inflater); final ViewGroup view = (ViewGroup) localInflater.inflate(R.layout.lb_onboarding_fragment, container, false); mIsLtr = getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR; mPageIndicator = (PagingIndicator) view.findViewById(R.id.page_indicator); mPageIndicator.setOnClickListener(mOnClickListener); mPageIndicator.setOnKeyListener(mOnKeyListener); mStartButton = view.findViewById(R.id.button_start); mStartButton.setOnClickListener(mOnClickListener); mStartButton.setOnKeyListener(mOnKeyListener); mLogoView = (ImageView) view.findViewById(R.id.logo); mTitleView = (TextView) view.findViewById(R.id.title); mDescriptionView = (TextView) view.findViewById(R.id.description); if (sSlideDistance == 0) { sSlideDistance = (int) (SLIDE_DISTANCE * getActivity().getResources().getDisplayMetrics().scaledDensity); } if (savedInstanceState == null) { mCurrentPageIndex = 0; mEnterTransitionFinished = false; mPageIndicator.onPageSelected(0, false); view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); if (!startLogoAnimation()) { startEnterAnimation(); } return true; } }); } else { mEnterTransitionFinished = true; mCurrentPageIndex = savedInstanceState.getInt(KEY_CURRENT_PAGE_INDEX); initializeViews(view); } view.requestFocus(); return view; }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testBug27258366() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear_with_button_onleft); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.horizontal_item); intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, 10); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_UPDATE_SIZE, false); initActivity(intent);//from ww w. j a v a 2 s .co m mOrientation = BaseGridView.VERTICAL; mNumRows = 1; // move item1 500 pixels right, when focus is on item1, default focus finder will pick // item0 and item2 for the best match of focusSearch(FOCUS_LEFT). The grid widget // must override default addFocusables(), not to add item0 or item2. mActivity.mAdapterListener = new GridActivity.AdapterListener() { public void onBind(RecyclerView.ViewHolder vh, int position) { if (position == 1) { vh.itemView.setPaddingRelative(500, 0, 0, 0); } else { vh.itemView.setPaddingRelative(0, 0, 0, 0); } } }; runTestOnUiThread(new Runnable() { @Override public void run() { mGridView.getAdapter().notifyDataSetChanged(); } }); Thread.sleep(100); final ViewGroup secondChild = (ViewGroup) mGridView.getChildAt(1); runTestOnUiThread(new Runnable() { @Override public void run() { secondChild.requestFocus(); } }); sendKeys(KeyEvent.KEYCODE_DPAD_LEFT); Thread.sleep(100); final View button = mActivity.findViewById(R.id.button); assertTrue(button.isFocused()); }