This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fixes #350 Personalized homepage * Select homepage text field when it's the default value
- Loading branch information
Showing
22 changed files
with
528 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SettingsEditText.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package org.mozilla.vrbrowser.ui.views.settings; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.text.Editable; | ||
import android.text.TextWatcher; | ||
import android.text.style.ForegroundColorSpan; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
@SuppressLint("AppCompatCustomView") | ||
public class SettingsEditText extends EditText { | ||
|
||
private int mNormalTextColor = 0; | ||
private int mHighlightedTextColor = 0; | ||
|
||
public SettingsEditText(Context context) { | ||
super(context); | ||
initialize(); | ||
} | ||
|
||
public SettingsEditText(Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
initialize(); | ||
} | ||
|
||
public SettingsEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
initialize(); | ||
} | ||
|
||
private void initialize() { | ||
mNormalTextColor = getTextColors().getColorForState(View.EMPTY_STATE_SET, 0); | ||
addTextChangedListener(watcher); | ||
|
||
setOnFocusChangeListener((view, b) -> { | ||
if (hasSelection()) { | ||
if (b) { | ||
int start = getSelectionStart(); | ||
int end = getSelectionEnd(); | ||
if (end < start) { | ||
int tmp = end; | ||
end = start; | ||
start = tmp; | ||
} | ||
|
||
ForegroundColorSpan highlightedColor = new ForegroundColorSpan(mHighlightedTextColor); | ||
getText().setSpan(highlightedColor, start, end, 0); | ||
|
||
} else { | ||
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); | ||
getText().setSpan(normalColor, 0, length(), 0); | ||
} | ||
|
||
} else { | ||
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); | ||
getText().setSpan(normalColor, 0, length(), 0); | ||
} | ||
}); | ||
} | ||
|
||
TextWatcher watcher = new TextWatcher() { | ||
@Override | ||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { | ||
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); | ||
getText().setSpan(normalColor, 0, length(), 0); | ||
} | ||
|
||
@Override | ||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { | ||
|
||
} | ||
|
||
@Override | ||
public void afterTextChanged(Editable editable) { | ||
|
||
} | ||
}; | ||
|
||
@Override | ||
protected void onSelectionChanged(int selStart, int selEnd) { | ||
super.onSelectionChanged(selStart, selEnd); | ||
|
||
if (getTextColors() != null) { | ||
handleTextColor(); | ||
} | ||
} | ||
|
||
private void handleTextColor() { | ||
if (mHighlightedTextColor == 0) { | ||
mHighlightedTextColor = mNormalTextColor; | ||
} | ||
|
||
if (isPressed()) { | ||
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); | ||
getText().setSpan(normalColor, 0, length(), 0); | ||
} | ||
|
||
if (hasSelection()) { | ||
int start = getSelectionStart(); | ||
int end = getSelectionEnd(); | ||
if (end < start) { | ||
int tmp = end; | ||
end = start; | ||
start = tmp; | ||
} | ||
|
||
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); | ||
getText().setSpan(normalColor, 0, length(), 0); | ||
ForegroundColorSpan highlightedColor = new ForegroundColorSpan(mHighlightedTextColor); | ||
getText().setSpan(highlightedColor, start, end, 0); | ||
} | ||
} | ||
|
||
public void setHighlightedTextColor(int color) { | ||
mHighlightedTextColor = color; | ||
} | ||
|
||
} |
Oops, something went wrong.