Interactive portions of the screen are not highlighted when selected - android

my Submitted application for amazon fire TV failed for the following reason :
Issue 1: Interactive portions of the screen are not highlighted when selected : Rewind, Fast Forward, and Play buttons above progress bar can be navigated and selected but no highlighted cursor is visible.
I am using the default media controller class provided by android and it does not provide this functionality.
I was able to catch the controls but i was not able to add a highlight on key down and remove it on key up. can anyone help with this?

Try this may be it works..
Field ffwd = MediaController.class.getDeclaredField("mFfwdButton");
Field rwd = MediaController.class.getDeclaredField("mRewButton");
Field playPause = MediaController.class.getDeclaredField("mPauseButton");
//System.out.println(f.get(d));//not accessible now
ffwd.setAccessible(true);//Abracadabra
rwd.setAccessible(true);//Abracadabra
playPause.setAccessible(true);
//System.out.println("Fusioni"+ffwd.get(mediaController)+" "+f1.get(mediaController));//now its ok
ffwdBtn = (ImageButton) ffwd.get(mediaController);
rwdBtn = (ImageButton) rwd.get(mediaController);
playPauseBtn = (ImageButton) playPause.get(mediaController);
//Log.i("imbtn",""+imbtn);
ffwdBtn.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
v.setBackgroundResource(R.drawable.round_background_selected);
else
v.setBackgroundColor(Color.TRANSPARENT);
}
});
rwdBtn.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
v.setBackgroundResource(R.drawable.round_background_selected);
else
v.setBackgroundColor(Color.TRANSPARENT);
}
});
playPauseBtn.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
v.setBackgroundResource(R.drawable.round_background_selected);
else
v.setBackgroundColor(Color.TRANSPARENT);
}
});
playPauseBtn.setBackgroundResource(R.drawable.round_background_selected);
rwdBtn.setBackgroundColor(Color.TRANSPARENT);
ffwdBtn.setBackgroundColor(Color.TRANSPARENT);
playPauseBtn.setFocusable(true);
playPauseBtn.requestFocus();

Related

How to display view in foreground based on focus?

JAVA CODE:
mEdtTextPickup.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
mLayoutDrop.invalidate();
mEdtTextPickup.bringToFront();
}
}
});
mEdtTextDrop.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
mLayoutPickup.invalidate();
mEdtTextDrop.bringToFront();
}
}
});
`
I have two layouts in my application Source and Destination in which one overlaps the other inside a FrameLayout.(just like the attached image)
Now how do i bring destination layout on top of source layout animated when it is focused. I googled a lot but found no solutions.
You can use a focus change listener to identify when the field is focused and then bringToFront to bring the view above the others.
destinationEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
edittext.bringToFront();
}
}
});

Edittext Focus and click

I have Two EditTexts. I want On First EditTexts click clear the second and on second edittext click clear the first one. So I have tried OnClickListener and OnTouchListener. But it is not working properly.
et_email.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (!(et_email.getText().toString().equalsIgnoreCase("") && et_mobile.getText().toString().equalsIgnoreCase(""))) {
if (MotionEvent.ACTION_UP == event.getAction()) {
et_mobile.setText("");
et_mobile.setFocusableInTouchMode(true);
et_mobile.setFocusable(true);
et_mobile.requestFocus();
}
return true; // return is important...
} else
return false;
}
});
et_mobile.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (!(et_email.getText().toString().equalsIgnoreCase("") && et_mobile.getText().toString().equalsIgnoreCase(""))) {
if (MotionEvent.ACTION_UP == event.getAction()) {
et_email.setText("");
et_mobile.setFocusableInTouchMode(true);
et_mobile.setFocusable(true);
et_mobile.requestFocus();
}
return true; // return is important...
}
else
return false;
}
});
But the problem is Focus is not setting on first touch and while clicking and unable to clear EditText.
First add this to your Edittext layouts:
android:focusableInTouchMode="false"
Without this line, the EditText will react to touch-mode, and only listen to your onClick() the second time you click your EditText bar.
This will disable touch-mode for EditText, and fire onClick() in first time
focusableInTouchMode
Note: boolean that controls whether a view can take focus while in touch mode. If this is true for a view, that view can gain focus when clicked on, and can keep focus if another view is clicked on that doesn't have this attribute set to true.
than do as follows:
EditText1
EditText et_email = (EditText) findViewById(R.id.yourEditText1);
et_email.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//do this
et_mobile.setText("");
//or this
et_mobile.getText().clear();
}
});
EditText2
EditText et_mobile = (EditText) findViewById(R.id.yourEditText2);
et_mobile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//do this
et_email.setText("");
//or this
et_email.getText().clear();
}
});
This should help u out.
you are clearing the first one one touching the first one, change your variable names in first listener like this
if (!(et_email.getText().toString().equalsIgnoreCase("") && et_mobile.getText().toString().equalsIgnoreCase(""))) {
if (MotionEvent.ACTION_UP == event.getAction()) {
et_mobile.setText("");
et_email.setFocusableInTouchMode(true);
et_email.setFocusable(true);
et_email.requestFocus();
}
return true; // return is important...
} else
I hope this code helps you (it works for me)
edit1 = (EditText) findViewById(R.id.edit1);
edit2 = (EditText) findViewById(R.id.edit2);
edit1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
edit2.setText("");
}
});
edit2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
edit1.setText("");
}
});

How to highlight/focus two EditTexts in Android?

I have two EditTexts in an activity. I am trying to implement it so that when one EditText is focused, the second one looks like it is focused too (the underline must be bold as it is when EditText is focused).
I am trying to change underline like this when focus changes:
editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// here editText2 must have not state
} else {
// here editText2 must have not state
}
}
});
But how can I make the underline bold on another text without it actually receiving focus?
Try this
editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
editText2.setTypeface(Typeface.NORMAL);
} else {
editText2.setTypeface(Typeface.DEFAULT_BOLD);
}
}
});

Hide Numeric Keyboard ONLY WHEN clicked outside any of the Edit Text

I have three different Edit Text with restriction of entering only numeric values, thus tapping on any one of the Edit Text opens NUMERIC KEYBOARD.
I tried to implement setOnFocusChangeListener for all Edit Text which ensures that when user tap anywhere outside any of the Edit Text hide the keyboard.
editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
editText2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
editText3.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
And here is the implementation of 'hideKeyBoard'
public void hideKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
This works fine, however, when I change focus from one EditText to another EditText, keyboard hides. This behaviour might be frustrating for user.
How can I deal with it and avoid unnecessary hiding of keyboard.
P.S I need to ensure that keyboard is numeric not alphabetical in any case.
Thank you MarianoZorrila for correcting me on my approach to the problem.Here are the changes I performed to solve this problem.
Gave an Id to my Relative Layout
<RelativeLayout
...
...
android:id="#+id/parent">
Modifications to Java File
View parent = findViewById(R.id.parent);
parent.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
hideKeyboard(view);
}
}
});

EditText SetPosition

I'm trying to make when I click on my EditText cursor position go to the end of the text, my code is as follows:
tb_acrescimo.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
int position = tb_acrescimo.length();
Editable etext = tb_acrescimo.getText();
Selection.setSelection(etext, position);
}
});
But it works on Android API 2.3 but does not work on 4.1, does anyone know what should I do?
I find other solution for my problem but don't answer my question, flees the topic, so I will not post the solution, ok?
Try this:
tb_acrescimo.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus) return;
int position = tb_acrescimo.length();
Editable etext = tb_acrescimo.getText();
tb_acrescimo.setSelection(etext, position);
}
});

Categories

Resources