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:org.eclipse.jubula.rc.swt.utils.SwtUtils.java

/**
 * GTK-specific workaround for getting the bounds of a TreeColumn.
 * //  w w  w  .ja v  a2 s . com
 * @param treeColumn   The TreeColumn to find the bounds for.
 * @return  the bounding rectangle
 */
static Rectangle gtkgetBounds(TreeColumn treeColumn) {
    Rectangle bounds = new Rectangle(0, 0, 0, 0);
    try {
        Class clazz = treeColumn.getClass();
        Field f = clazz.getDeclaredField("buttonHandle"); //$NON-NLS-1$
        f.setAccessible(true);
        int handle = f.getInt(treeColumn);
        gtkgetBounds(handle, bounds);
        bounds.y -= treeColumn.getParent().getHeaderHeight();
        return treeColumn.getDisplay().map(treeColumn.getParent(), null, bounds);
    } catch (Exception e) {
        return handleBoundsError(e);
    }
}

From source file:org.eclipse.jubula.rc.swt.utils.SwtUtils.java

/**
 * Win32-specific workaround for getting the bounds of a TreeColumn.
 * /*from   w  ww  .  j a  va 2 s. c om*/
 * @param treeColumn   The TreeColumn to find the bounds for.
 * @return  the bounding rectangle
 */
static Rectangle win32getBounds(TreeColumn treeColumn) {
    Tree parent = treeColumn.getParent();
    int index = parent.indexOf(treeColumn);
    if (index == -1) {
        return new Rectangle(0, 0, 0, 0);
    }
    int hwndHeader = 0;
    try {
        Class clazz = parent.getClass();
        Field f = clazz.getDeclaredField("hwndHeader"); //$NON-NLS-1$
        f.setAccessible(true);
        hwndHeader = f.getInt(parent);
        int[] rect = new int[4];

        sendMessage(hwndHeader, /*HDM_GETITEMRECT*/ 0x1200 + 7, index, rect);
        int width = rect[2] - rect[0];
        int height = rect[3] - rect[1];
        Rectangle bounds = new Rectangle(rect[0], rect[1], width, height);
        bounds.y -= treeColumn.getParent().getHeaderHeight();
        return treeColumn.getDisplay().map(parent, null, bounds);
    } catch (Exception e) {
        return handleBoundsError(e);
    }
}

From source file:org.gluu.oxpush2.u2f.v2.SoftwareDevice.java

private String getVersionName() {
    Field[] fields = Build.VERSION_CODES.class.getFields();
    for (Field field : fields) {
        String fieldName = field.getName();
        int fieldValue = -1;

        try {/*ww  w . jav a2s . com*/
            fieldValue = field.getInt(new Object());
        } catch (Exception ex) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Error: " + ex.getMessage());
        }

        if (fieldValue == Build.VERSION.SDK_INT) {
            return fieldName.toLowerCase();
        }
    }

    return "unknown";
}

From source file:org.gluu.com.ox_push2.u2f.v2.SoftwareDevice.java

private String getVersionName() {
    Field[] fields = Build.VERSION_CODES.class.getFields();
    for (Field field : fields) {
        String fieldName = field.getName();
        int fieldValue = -1;

        try {//ww w .  j ava2  s. c o m
            fieldValue = field.getInt(new Object());
        } catch (Exception ex) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Error: " + ex.getMessage());
        }

        if (fieldValue == Build.VERSION.SDK_INT) {
            return fieldName.toLowerCase(Locale.getDefault());
        }
    }

    return "unknown";
}

From source file:edu.pdx.its.portal.routelandia.DatePickUp.java

/**
 * change the minute interval to quarter*
 * @param timePicker : timepicker obk in the view
 *//*  w  w  w .ja  v  a 2s .co m*/
@SuppressLint("NewApi")
private void setTimePickerInterval(TimePicker timePicker) {
    try {
        Class<?> classForid = Class.forName("com.android.internal.R$id");

        Field field = classForid.getField("minute");
        NumberPicker minutePicker = (NumberPicker) timePicker.findViewById(field.getInt(null));

        minutePicker.setMinValue(0);
        minutePicker.setMaxValue(7);
        ArrayList<String> displayedValues = new ArrayList<>();
        for (int i = 0; i < 60; i += TIME_PICKER_INTERVAL) {
            displayedValues.add(String.format("%02d", i));
        }
        for (int i = 0; i < 60; i += TIME_PICKER_INTERVAL) {
            displayedValues.add(String.format("%02d", i));
        }
        minutePicker.setDisplayedValues(displayedValues.toArray(new String[0]));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ggikko.me.steppertest.stepper.RoundedView.java

private int getBackgroundColor(View view) {
    ColorDrawable drawable = (ColorDrawable) view.getBackground();
    if (drawable != null) {
        if (Build.VERSION.SDK_INT >= 11) {
            return drawable.getColor();
        }/*from   ww w.ja  v a 2 s.co m*/
        try {
            Field field = drawable.getClass().getDeclaredField("mState");
            field.setAccessible(true);
            Object object = field.get(drawable);
            field = object.getClass().getDeclaredField("mUseColor");
            field.setAccessible(true);
            return field.getInt(object);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
    return 0;
}

From source file:eu.vital.vitalcep.cep.CepProcess.java

private int getPid(Process process) {
    try {/*from w w w  .  j a  v  a  2s . c  o m*/

        Class<?> cProcessImpl = process.getClass();
        java.lang.reflect.Field fPid = cProcessImpl.getDeclaredField("pid");

        if (!fPid.isAccessible()) {
            fPid.setAccessible(true);
        } else {
            return -1;
        }

        return fPid.getInt(process);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        return -2;
    }
}

From source file:com.yek.keyboard.ChewbaccaUncaughtExceptionHandler.java

private void addResourceNameWithId(StringBuilder resources, int resourceId, Class clazz) {
    for (Field field : clazz.getFields()) {
        if (field.getType().equals(int.class)) {
            if ((field.getModifiers() & (Modifier.STATIC | Modifier.PUBLIC)) != 0) {
                try {
                    if (resourceId == field.getInt(null)) {
                        resources.append(clazz.getName()).append(".").append(field.getName());
                        resources.append('\n');
                    }/*from w ww.j  a v  a 2  s .c  o m*/
                } catch (IllegalAccessException e) {
                    Logger.d("EEEE", "Failed to access " + field.getName(), e);
                }
            }
        }
    }
}

From source file:org.jajuk.services.players.AbstractMPlayerImpl.java

@Override
public void stop() throws Exception {
    bFading = false;/*from w  w  w.j  a va 2s. c  o m*/
    this.bStop = true;
    Log.debug("Stop");
    if (proc != null) {
        if (UtilSystem.isUnderLinux()) {
            /*
             * Under linux (not sure if it may happen on others Unix and never
             * reproduced under Windows), mplayer process can "zombified" after
             * destroy() method call for unknown reason (linked with the mplayer
             * slave mode ?). Even worse, these processes block the dsp audio line
             * and then all new mplayer processes fail. To avoid this, we force a
             * kill on every process call under Linux.
             *
             * Note also that mplayer slave mode opens two processes with different
             * pids. When we try to kill them with -9 (abruptly) only the parent
             * process dies and the second process is left hanging in the
             * background. The solution is to just use kill (without -9) to let both
             * mplayer processes die gracefully. I guess the destroy() method
             * internally also tries to use -9 and so both pids are never killed.
             */
            Field field = proc.getClass().getDeclaredField("pid");
            field.setAccessible(true);
            int pid = field.getInt(proc);
            try {
                ProcessBuilder pb = new ProcessBuilder("kill", Integer.toString(pid));
                pb.start();
            } catch (Error error) {
                Log.error(error);
            }
        } else {
            proc.destroy();
        }
    }
}

From source file:org.opensilk.video.tv.ui.playback.PlaybackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Field[] fields = KeyEvent.class.getDeclaredFields();
    for (Field f : fields) {
        if (f.getName().startsWith("KEYCODE")) {
            try {
                int val = f.getInt(null);
                if (val == keyCode) {
                    Timber.d("onKeyDown(%s)", f.getName());
                }/*from w  ww.  j  a  va  2s.c o m*/
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
    //        switch (keyCode) {
    //            case KeyEvent.KEYCODE_DPAD_RIGHT:
    //            case KeyEvent.KEYCODE_DPAD_LEFT: {
    //                boolean pos = keyCode == KeyEvent.KEYCODE_DPAD_RIGHT;
    //                getMediaController().getTransportControls().sendCustomAction(
    //                        PlaybackService.ACTION.SEEK_DELTA,
    //                        BundleHelper.b().putInt(pos ? 10000 : -10000).get());
    //                return true;
    //            }
    //        }
    //        if (keyCode == KeyEvent.KEYCODE_BUTTON_R1) {
    //            getMediaController().getTransportControls().skipToNext();
    //            return true;
    //        } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L1) {
    //            getMediaController().getTransportControls().skipToPrevious();
    //            return true;
    //        }
    return super.onKeyDown(keyCode, event);
}