Example usage for java.lang.reflect Field getInt

List of usage examples for java.lang.reflect Field getInt

Introduction

In this page you can find the example usage for java.lang.reflect Field getInt.

Prototype

@CallerSensitive
@ForceInline 
public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException 

Source Link

Document

Gets the value of a static or instance field of type int or of another primitive type convertible to type int via a widening conversion.

Usage

From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarColorizer.java

public static void setCursorTint(@NonNull EditText editText, @ColorInt int color) {
    try {/*  w  ww. j  a v  a2  s. c  om*/
        Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
        fCursorDrawableRes.setAccessible(true);
        int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
        Field fEditor = TextView.class.getDeclaredField("mEditor");
        fEditor.setAccessible(true);
        Object editor = fEditor.get(editText);
        Class<?> clazz = editor.getClass();
        Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
        fCursorDrawable.setAccessible(true);
        Drawable[] drawables = new Drawable[2];
        drawables[0] = ColorUtils.getTintedIcon(editText.getContext(), mCursorDrawableRes, color);
        drawables[1] = ColorUtils.getTintedIcon(editText.getContext(), mCursorDrawableRes, color);
        fCursorDrawable.set(editor, drawables);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:xyz.klinker.android.article.Utils.java

/**
 * Changes the text selection handle colors.
 *//*w  w  w  . j a v  a2s .  c  o  m*/
static void changeTextSelectionHandleColors(TextView textView, int color) {
    textView.setHighlightColor(Color.argb(40, Color.red(color), Color.green(color), Color.blue(color)));

    try {
        Field editorField = TextView.class.getDeclaredField("mEditor");
        if (!editorField.isAccessible()) {
            editorField.setAccessible(true);
        }

        Object editor = editorField.get(textView);
        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(textView);
                handleDrawable = ContextCompat.getDrawable(textView.getContext(), resId);
            }

            if (handleDrawable != null) {
                Drawable drawable = handleDrawable.mutate();
                drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                handleField.set(editor, drawable);
            }
        }
    } catch (Exception ignored) {
    }
}

From source file:Main.java

public static boolean setStatusBarDarkIcon(Window window, boolean dark) {
    boolean result = false;
    if (window != null) {
        try {/* w w w.  j av  a 2 s .co  m*/
            WindowManager.LayoutParams lp = window.getAttributes();
            Field darkFlag = WindowManager.LayoutParams.class
                    .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
            Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
            darkFlag.setAccessible(true);
            meizuFlags.setAccessible(true);
            int bit = darkFlag.getInt(null);
            int value = meizuFlags.getInt(lp);
            if (dark) {
                value |= bit;
            } else {
                value &= ~bit;
            }
            meizuFlags.setInt(lp, value);
            window.setAttributes(lp);
            result = true;
        } catch (Exception ignored) {
        }
    }
    return result;
}

From source file:arun.com.chromer.browsing.article.util.ArticleUtil.java

/**
 * Changes the text selection handle colors.
 *///from   ww w.  java  2s .  c om
public static void changeTextSelectionHandleColors(TextView textView, int color) {
    textView.setHighlightColor(Color.argb(40, Color.red(color), Color.green(color), Color.blue(color)));

    try {
        Field editorField = TextView.class.getDeclaredField("mEditor");
        if (!editorField.isAccessible()) {
            editorField.setAccessible(true);
        }

        Object editor = editorField.get(textView);
        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(textView);
                handleDrawable = ContextCompat.getDrawable(textView.getContext(), resId);
            }

            if (handleDrawable != null) {
                Drawable drawable = handleDrawable.mutate();
                drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                handleField.set(editor, drawable);
            }
        }
    } catch (Exception ignored) {
    }
}

From source file:Main.java

/**
 * meizu Flyme set status bar light mode
 *//*ww  w  .j a  v  a2  s .c  o  m*/
public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) {
    boolean result = false;
    if (window != null) {
        try {
            WindowManager.LayoutParams lp = window.getAttributes();
            Field darkFlag = WindowManager.LayoutParams.class
                    .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
            Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
            darkFlag.setAccessible(true);
            meizuFlags.setAccessible(true);
            int bit = darkFlag.getInt(null);
            int value = meizuFlags.getInt(lp);
            if (dark) {
                value |= bit;
            } else {
                value &= ~bit;
            }
            meizuFlags.setInt(lp, value);
            window.setAttributes(lp);
            result = true;
        } catch (Exception e) {

        }
    }
    return result;
}

From source file:Main.java

@SuppressLint("UseSparseArrays")
public static ArrayList<String> extractor(Notification notification) {
    ArrayList<String> notifText = new ArrayList<String>();
    RemoteViews views = notification.contentView;
    @SuppressWarnings("rawtypes")
    Class secretClass = views.getClass();

    try {//from w w w.j ava 2 s  . c  o m

        Field outerFields[] = secretClass.getDeclaredFields();
        for (int i = 0; i < outerFields.length; i++) {

            if (!outerFields[i].getName().equals("mActions"))
                continue;

            outerFields[i].setAccessible(true);

            @SuppressWarnings("unchecked")
            ArrayList<Object> actions = (ArrayList<Object>) outerFields[i].get(views);
            for (Object action : actions) {

                Field innerFields[] = action.getClass().getDeclaredFields();

                Object value = null;
                Integer type = null;
                @SuppressWarnings("unused")
                Integer viewId = null;
                for (Field field : innerFields) {

                    field.setAccessible(true);
                    if (field.getName().equals("value")) {
                        value = field.get(action);
                    } else if (field.getName().equals("type")) {
                        type = field.getInt(action);
                    } else if (field.getName().equals("viewId")) {
                        viewId = field.getInt(action);
                    }
                }

                if (type != null && (type == 9 || type == 10) && value != null) {
                    // System.out.println("Type: " + Integer.toString(type)
                    // + " Value: " + value.toString());
                    if (!notifText.contains(value.toString()))
                        notifText.add(value.toString());
                }

            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return notifText;
}

From source file:net.pms.util.ProcessUtil.java

public static Integer getProcessID(Process p) {
    Integer pid = null;//from  w  ww  . j  a  v a 2s.  c  o  m

    if (p != null && p.getClass().getName().equals("java.lang.UNIXProcess")) {
        try {
            Field f = p.getClass().getDeclaredField("pid");
            f.setAccessible(true);
            pid = f.getInt(p);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException
                | IllegalAccessException e) {
            LOGGER.debug("Can't determine the Unix process ID: " + e.getMessage());
        }
    }

    return pid;
}

From source file:com.ikanow.aleph2.data_model.utils.ProcessUtils.java

/**
 * Returns the pid for the given process
 * //w  w w  . j  av  a  2  s . c o  m
 * @param px
 * @return
 */
private static String getPid(Process px) {
    try {
        final Class<?> ProcessImpl = px.getClass();
        final Field field = ProcessImpl.getDeclaredField("pid");
        field.setAccessible(true);
        return Integer.toString(field.getInt(px));
    } catch (Throwable t) {
        return "unknown";
    }
}

From source file:szjy.advtech.BuildInfo.java

/**
 * Get int of field from Class//from ww w  .  jav a 2s . c om
 * @param c
 * @param fieldName
 * @param defaultReturn
  * @return
  */
private static int getClassFieldInt(Class c, String fieldName, int defaultReturn) {
    int ret = defaultReturn;
    Field field = getClassField(c, fieldName);

    if (null != field) {
        try {
            ret = field.getInt(c);
        } catch (IllegalAccessException iae) {
            iae.printStackTrace();
        }
    }

    return ret;
}

From source file:org.apache.cassandra.utils.CLibrary.java

/**
 * Get system file descriptor from FileDescriptor object.
 * @param descriptor - FileDescriptor objec to get fd from
 * @return file descriptor, -1 or error//www  . j  a  v  a2 s. c  om
 */
public static int getfd(FileDescriptor descriptor) {
    Field field = FBUtilities.getProtectedField(descriptor.getClass(), "fd");

    if (field == null)
        return -1;

    try {
        return field.getInt(descriptor);
    } catch (Exception e) {
        logger.warn("unable to read fd field from FileDescriptor");
    }

    return -1;
}