Java Code Examples for android.view.ViewGroup#requestFocus()
The following examples show how to use
android.view.ViewGroup#requestFocus() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FullScreenDialogFragment.java From FullScreenDialog with Apache License 2.0 | 6 votes |
@Nullable @Override 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; }
Example 2
Source File: BorderEffect.java From AndroidTvDemo with Apache License 2.0 | 6 votes |
@Override public void onLayout(View target, View attachView) { try { ViewGroup viewGroup = (ViewGroup)attachView.getRootView(); if (target.getParent() != null && target.getParent() != viewGroup) { target.setVisibility(View.GONE); if (mFirstFocus) viewGroup.requestFocus(); } } catch (Exception ex) { ex.printStackTrace(); } }
Example 3
Source File: EditTextDefaultFocus.java From budget-envelopes with GNU General Public License v3.0 | 6 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mDefaultFocus) { if (getContext() instanceof Activity) { ((Activity)getContext()) .getWindow() .setSoftInputMode(WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_VISIBLE); } requestFocus(); } else { ViewGroup parent = (ViewGroup)getParent(); //while (parent.getParent() instanceof ViewGroup) { // parent = (ViewGroup)parent.getParent(); //} parent.setFocusableInTouchMode(true); parent.requestFocus(); clearFocus(); } }
Example 4
Source File: MetroViewBorderHandler.java From LivePlayback with Apache License 2.0 | 5 votes |
@Override public void onLayout(View target, View attachView) { try { ViewGroup viewGroup = (ViewGroup) attachView.getRootView(); if (target.getParent() != null && target.getParent() != viewGroup) { target.setVisibility(View.GONE); if (mFirstFocus) viewGroup.requestFocus();//如果是首次获取焦点,强制变成焦点态 } } catch (Exception ex) { ex.printStackTrace(); } }
Example 5
Source File: BorderEffect.java From TvWidget with Apache License 2.0 | 5 votes |
@Override public void onLayout(View target, View attachView) { try { // Log.d(TAG, "onLayout"); ViewGroup viewGroup = (ViewGroup) attachView.getRootView(); if (target.getParent() != null && target.getParent() != viewGroup) { target.setVisibility(View.GONE); if (mFirstFocus) viewGroup.requestFocus(); } } catch (Exception ex) { ex.printStackTrace(); } }
Example 6
Source File: MetroViewBorderHandler.java From TVSample with Apache License 2.0 | 5 votes |
@Override public void onLayout(View target, View attachView) { try { ViewGroup viewGroup = (ViewGroup) attachView.getRootView(); if (target.getParent() != null && target.getParent() != viewGroup) { target.setVisibility(View.GONE); if (mFirstFocus) viewGroup.requestFocus();//如果是首次获取焦点,强制变成焦点态 } } catch (Exception ex) { ex.printStackTrace(); } }
Example 7
Source File: MetroViewBorderHandler.java From TVSample with Apache License 2.0 | 5 votes |
@Override public void onLayout(View target, View attachView) { try { ViewGroup viewGroup = (ViewGroup) attachView.getRootView(); if (target.getParent() != null && target.getParent() != viewGroup) { target.setVisibility(View.GONE); if (mFirstFocus) viewGroup.requestFocus(); } } catch (Exception ex) { ex.printStackTrace(); } }
Example 8
Source File: CaptureActivity.java From ZXing-Standalone-library with Apache License 2.0 | 4 votes |
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { 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.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(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); } } }
Example 9
Source File: CaptureActivity.java From Study_Android_Demo with Apache License 2.0 | 4 votes |
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { 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.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(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); } } }
Example 10
Source File: CaptureActivity.java From barcodescanner-lib-aar with MIT License | 4 votes |
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { 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.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(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); } } }
Example 11
Source File: CaptureActivity.java From reacteu-app with MIT License | 4 votes |
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(fakeR.getId("id", "barcode_image_view")); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), fakeR.getId("drawable", "launcher_icon"))); } else { barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(fakeR.getId("id", "format_text_view")); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(fakeR.getId("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(fakeR.getId("id", "time_text_view")); timeTextView.setText(formattedTime); TextView metaTextView = (TextView) findViewById(fakeR.getId("id", "meta_text_view")); View metaTextViewLabel = findViewById(fakeR.getId("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(fakeR.getId("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(fakeR.getId("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(fakeR.getId("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); } } }
Example 12
Source File: CaptureActivity.java From android-apps with MIT License | 4 votes |
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.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); 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(), handler, 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); clipboard.setText(displayContents); } }