mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Fine tuned themeing
The main activity's search view and various edittext views now show the server set theme colour for highlighted text, highlighted text selector handles and focus underline. Signed-off-by: Daniel Bailey <daniel.bailey@grappleIT.co.uk>
This commit is contained in:
parent
3e6d01965b
commit
7df8f8ba45
7 changed files with 119 additions and 8 deletions
|
@ -39,6 +39,7 @@ import android.widget.EditText;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
@ -99,16 +100,20 @@ public class PassCodeActivity extends AppCompatActivity {
|
|||
|
||||
mPassCodeEditTexts[0] = findViewById(R.id.txt0);
|
||||
ThemeUtils.colorEditText(mPassCodeEditTexts[0], elementColor);
|
||||
ThemeUtils.themeEditText(mPassCodeEditTexts[0], ThemeUtils.primaryColor(MainApp.getAppContext()));
|
||||
mPassCodeEditTexts[0].requestFocus();
|
||||
|
||||
mPassCodeEditTexts[1] = findViewById(R.id.txt1);
|
||||
ThemeUtils.colorEditText(mPassCodeEditTexts[1], elementColor);
|
||||
ThemeUtils.themeEditText(mPassCodeEditTexts[1], ThemeUtils.primaryColor(MainApp.getAppContext()));
|
||||
|
||||
mPassCodeEditTexts[2] = findViewById(R.id.txt2);
|
||||
ThemeUtils.colorEditText(mPassCodeEditTexts[2], elementColor);
|
||||
ThemeUtils.themeEditText(mPassCodeEditTexts[2], ThemeUtils.primaryColor(MainApp.getAppContext()));
|
||||
|
||||
mPassCodeEditTexts[3] = findViewById(R.id.txt3);
|
||||
ThemeUtils.colorEditText(mPassCodeEditTexts[3], elementColor);
|
||||
ThemeUtils.themeEditText(mPassCodeEditTexts[3], ThemeUtils.primaryColor(MainApp.getAppContext()));
|
||||
|
||||
Window window = getWindow();
|
||||
if (window != null) {
|
||||
|
|
|
@ -102,6 +102,7 @@ public class RenameFileDialogFragment
|
|||
String currentName = mTargetFile.getFileName();
|
||||
EditText inputText = v.findViewById(R.id.user_input);
|
||||
inputText.setText(currentName);
|
||||
ThemeUtils.themeEditText(inputText, ThemeUtils.primaryColor(getContext()));
|
||||
int selectionStart = 0;
|
||||
int extensionStart = mTargetFile.isFolder() ? -1 : currentName.lastIndexOf('.');
|
||||
int selectionEnd = extensionStart >= 0 ? extensionStart : currentName.length();
|
||||
|
|
|
@ -83,6 +83,8 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import static com.owncloud.android.utils.ThemeUtils.themeSearchView;
|
||||
|
||||
public class ExtendedListFragment extends Fragment
|
||||
implements OnItemClickListener, OnEnforceableRefreshListener, SearchView.OnQueryTextListener,
|
||||
SearchView.OnCloseListener {
|
||||
|
@ -181,6 +183,7 @@ public class ExtendedListFragment extends Fragment
|
|||
searchView = (SearchView) MenuItemCompat.getActionView(item);
|
||||
searchView.setOnQueryTextListener(this);
|
||||
searchView.setOnCloseListener(this);
|
||||
themeSearchView(searchView, ThemeUtils.primaryAccentColor(getContext()));
|
||||
|
||||
final Handler handler = new Handler();
|
||||
|
||||
|
|
|
@ -196,6 +196,8 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
|
|||
ThemeUtils.primaryAccentColor(getContext()),
|
||||
PorterDuff.Mode.SRC_ATOP
|
||||
);
|
||||
// ThemeUtils.colorEditText(commentInput, ThemeUtils.primaryAccentColor(getContext()));
|
||||
ThemeUtils.themeEditText(commentInput, ThemeUtils.primaryColor(getContext()));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -201,6 +201,7 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
|||
FileDetailSharingFragmentHelper.setupSearchView(
|
||||
(SearchManager) fileDisplayActivity.getSystemService(Context.SEARCH_SERVICE), searchView,
|
||||
fileDisplayActivity.getComponentName());
|
||||
ThemeUtils.themeSearchView(searchView, ThemeUtils.primaryColor(getContext()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,11 +32,13 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
@ -48,11 +50,14 @@ import com.owncloud.android.datamodel.FileDataStorageManager;
|
|||
import com.owncloud.android.lib.resources.status.OCCapability;
|
||||
import com.owncloud.android.ui.activity.ToolbarActivity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.widget.AppCompatCheckBox;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
@ -388,6 +393,20 @@ public final class ThemeUtils {
|
|||
));
|
||||
}
|
||||
|
||||
public static void themeEditText(EditText editText, int color) {
|
||||
editText.setHighlightColor(color);
|
||||
setTextViewCursorColor(editText, color);
|
||||
setTextViewHandlesColor(editText, color);
|
||||
}
|
||||
|
||||
public static void themeSearchView(SearchView searchView, int color) {
|
||||
SearchView.SearchAutoComplete editText = searchView.findViewById(R.id.search_src_text);
|
||||
|
||||
editText.setHighlightColor(color);
|
||||
ThemeUtils.setTextViewCursorColor(editText, color);
|
||||
ThemeUtils.setTextViewHandlesColor(editText, color);
|
||||
}
|
||||
|
||||
public static void tintCheckbox(AppCompatCheckBox checkBox, int color) {
|
||||
CompoundButtonCompat.setButtonTintList(checkBox, new ColorStateList(
|
||||
new int[][]{
|
||||
|
@ -472,4 +491,88 @@ public final class ThemeUtils {
|
|||
return new OCCapability();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lifted from SO.
|
||||
* @see https://stackoverflow.com/questions/25996032/how-to-change-programmatically-edittext-cursor-color-in-android#26543290
|
||||
* @param view TextView to be styled
|
||||
* @param color The desired cursor colour
|
||||
*/
|
||||
public static void setTextViewCursorColor(EditText view, @ColorInt int color) {
|
||||
try {
|
||||
// Get the cursor resource id
|
||||
Field field = TextView.class.getDeclaredField("mCursorDrawableRes");
|
||||
field.setAccessible(true);
|
||||
int drawableResId = field.getInt(view);
|
||||
|
||||
// Get the editor
|
||||
// TODO check this in API 15
|
||||
field = TextView.class.getDeclaredField("mEditor");
|
||||
field.setAccessible(true);
|
||||
Object editor = field.get(view);
|
||||
|
||||
// Get the drawable and set a color filter
|
||||
Drawable drawable = ContextCompat.getDrawable(view.getContext(), drawableResId);
|
||||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
Drawable[] drawables = {drawable, drawable};
|
||||
|
||||
// Set the drawables
|
||||
field = editor.getClass().getDeclaredField("mCursorDrawable");
|
||||
field.setAccessible(true);
|
||||
field.set(editor, drawables);
|
||||
} catch (Exception ignored) { }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the color of the handles when you select text in a
|
||||
* {@link android.widget.EditText} or other view that extends {@link TextView}.
|
||||
*
|
||||
* @param view
|
||||
* The {@link TextView} or a {@link View} that extends {@link TextView}.
|
||||
* @param color
|
||||
* The color to set for the text handles
|
||||
*
|
||||
* @see https://gist.github.com/jaredrummler/2317620559d10ac39b8218a1152ec9d4
|
||||
*/
|
||||
public static void setTextViewHandlesColor(TextView view, int color) {
|
||||
try {
|
||||
Field editorField = TextView.class.getDeclaredField("mEditor");
|
||||
if (!editorField.isAccessible()) {
|
||||
editorField.setAccessible(true);
|
||||
}
|
||||
|
||||
Object editor = editorField.get(view);
|
||||
Class<?> editorClass = editor.getClass();
|
||||
|
||||
String[] handleNames = {"mSelectHandleLeft", "mSelectHandleRight", "mSelectHandleCenter"};
|
||||
String[] resNames = {"mTextSelectHandleLeftRes", "mTextSelectHandleRightRes", "mTextSelectHandleRes"};
|
||||
|
||||
for (int i = 0; i < handleNames.length; i++) {
|
||||
Field handleField = editorClass.getDeclaredField(handleNames[i]);
|
||||
if (!handleField.isAccessible()) {
|
||||
handleField.setAccessible(true);
|
||||
}
|
||||
|
||||
Drawable handleDrawable = (Drawable) handleField.get(editor);
|
||||
|
||||
if (handleDrawable == null) {
|
||||
Field resField = TextView.class.getDeclaredField(resNames[i]);
|
||||
if (!resField.isAccessible()) {
|
||||
resField.setAccessible(true);
|
||||
}
|
||||
int resId = resField.getInt(view);
|
||||
handleDrawable = view.getResources().getDrawable(resId);
|
||||
}
|
||||
|
||||
if (handleDrawable != null) {
|
||||
Drawable drawable = handleDrawable.mutate();
|
||||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
handleField.set(editor, drawable);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,8 +58,7 @@
|
|||
android:cursorVisible="true"
|
||||
android:imeOptions="flagNoExtractUi"
|
||||
android:importantForAutofill="no"
|
||||
android:hint="@string/hidden_character"
|
||||
android:textCursorDrawable="@null">
|
||||
android:hint="@string/hidden_character">
|
||||
<requestFocus/>
|
||||
</com.google.android.material.textfield.TextInputEditText>
|
||||
|
||||
|
@ -69,8 +68,7 @@
|
|||
android:cursorVisible="true"
|
||||
android:imeOptions="flagNoExtractUi"
|
||||
android:importantForAutofill="no"
|
||||
android:hint="@string/hidden_character"
|
||||
android:textCursorDrawable="@null" />
|
||||
android:hint="@string/hidden_character" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/txt2"
|
||||
|
@ -78,8 +76,7 @@
|
|||
android:cursorVisible="true"
|
||||
android:imeOptions="flagNoExtractUi"
|
||||
android:importantForAutofill="no"
|
||||
android:hint="@string/hidden_character"
|
||||
android:textCursorDrawable="@null" />
|
||||
android:hint="@string/hidden_character" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/txt3"
|
||||
|
@ -87,8 +84,7 @@
|
|||
android:cursorVisible="true"
|
||||
android:imeOptions="flagNoExtractUi"
|
||||
android:importantForAutofill="no"
|
||||
android:hint="@string/hidden_character"
|
||||
android:textCursorDrawable="@null" />
|
||||
android:hint="@string/hidden_character" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
|
|
Loading…
Reference in a new issue