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:com.he5ed.lib.cloudprovider.picker.CloudPickerActivity.java

/**
 * @hide/*from ww  w.  jav  a2s  .  co  m*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cp_activity_picker);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    // lock right drawer from been swiped open
    drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setItemIconTintList(null); // remove the auto grey tint to keep icon color
    Menu menu = navigationView.getMenu();
    CloudProvider cloudProvider = CloudProvider.getInstance(this);
    // check whether individual account is assigned
    String accountId = getIntent().getStringExtra(EXTRA_PICK_ACCOUNT_ID);
    if (!TextUtils.isEmpty(accountId)) {
        mAccounts = new CloudAccount[1];
        mAccounts[0] = cloudProvider.getAccountById(accountId);
    } else {
        mAccounts = cloudProvider.getCloudAccounts();
    }
    // populate navigation menu
    for (int i = 0; i < mAccounts.length; i++) {
        CloudAccount account = mAccounts[i];
        MenuItem item = menu.add(0, i, 0, account.getUser().email);
        // use cloud API class reflection
        try {
            Class clazz = Class.forName(account.api);
            Field iconResource = clazz.getField("ICON_RESOURCE");
            item.setIcon(iconResource.getInt(null));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
            item.setIcon(R.drawable.ic_cloud_black_24dp);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        item.setCheckable(true);
    }

    mFragmentManager = getSupportFragmentManager();
    mItemFragment = (ItemFragment) mFragmentManager.findFragmentById(R.id.right_drawer_view);
    if (mItemFragment == null) {
        mItemFragment = new ItemFragment();
        mFragmentManager.beginTransaction().add(R.id.right_drawer_view, mItemFragment).commit();
    }

    mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
    mErrorView = (LinearLayout) findViewById(R.id.error_view);
    if (savedInstanceState != null) {
        switch (savedInstanceState.getInt("empty_view_visibility")) {
        case View.VISIBLE:
            mErrorView.setVisibility(View.VISIBLE);
            ImageView icon = (ImageView) mErrorView.findViewById(R.id.empty_icon_image_view);
            TextView title = (TextView) mErrorView.findViewById(R.id.empty_title_text_view);
            TextView detail = (TextView) mErrorView.findViewById(R.id.empty_detail_text_view);
            Bitmap bitmap = savedInstanceState.getParcelable("icon_drawable");
            icon.setImageBitmap(bitmap);
            title.setText(savedInstanceState.getCharSequence("title_text"));
            detail.setText(savedInstanceState.getCharSequence("detail_text"));
            break;
        case View.INVISIBLE:
            mErrorView.setVisibility(View.INVISIBLE);
            break;
        case View.GONE:
            mErrorView.setVisibility(View.GONE);
            break;
        }
    } else {
        // open drawer on first load
        drawer.openDrawer(GravityCompat.START);
    }
}

From source file:com.allmycode.flags.other.MyActivityOther.java

public void go(View view) {
    Intent intent = new Intent();
    String targetActivityName = "com.allmycode.flags";
    String fromEditText = targetActivity.getText().toString().trim();
    String other = (fromEditText.contains("Other")) ? ".other" : "";
    targetActivityName += other;//  w w  w  . jav  a 2  s . c  om
    targetActivityName += ".FlagsDemoActivity";
    targetActivityName += fromEditText;
    Log.i(CLASSNAME, "Target activity: >>" + targetActivityName + "<<");
    intent.setClassName("com.allmycode.flags" + other, targetActivityName);
    String allFlags = flags.getText().toString();
    int flagsValue = 0;
    if (allFlags != "" && allFlags != null) {

        TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter('|');
        splitter.setString(allFlags);
        boolean existErrors = false;
        for (String flagName : splitter) {

            Log.i(CLASSNAME, ">>" + flagName + "<<");

            flagName = flagName.trim();
            if (!flagName.equals("") && flagName != null) { // BARRY
                                                            // need
                                                            // both?
                if (isHex(flagName)) {
                    Log.i(CLASSNAME, flagName + " is hex");
                    flagsValue |= Integer.parseInt(flagName.substring(2), 16);
                } else if (isDec(flagName)) {
                    Log.i(CLASSNAME, flagName + " is decimal");
                    flagsValue |= Integer.parseInt(flagName);
                } else {
                    Field flagsField = null;
                    try {
                        Log.i(CLASSNAME, "About to do reflection>>" + flagName + "<<");
                        flagsField = Intent.class.getField(flagName);
                        Log.i(CLASSNAME, Integer.toString(flagsField.getInt(this)));
                        flagsValue |= flagsField.getInt(this);
                    } catch (SecurityException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    } catch (NoSuchFieldException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    } catch (IllegalAccessException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    }
                    try {
                        Log.i(CLASSNAME, Integer.toHexString(flagsValue));
                        if (flagsValue != 0) {
                            intent.addFlags(flagsValue);
                        }
                    } catch (IllegalArgumentException e) {
                        existErrors = true;
                        e.printStackTrace();
                    }
                }
            }
        }
        if (flagsValue != 0) {
            intent.addFlags(flagsValue);
        }
        intent.putExtra("existErrors", existErrors);

        Log.i(CLASSNAME, "About to start " + intent.toString());
        startActivity(intent);
    }
}

From source file:com.baifendian.swordfish.execserver.job.ProcessJob.java

/**
 *  id/*from w w  w  . j  a v a2 s . c om*/
 *
 * @param process ?
 * @return  id
 */
private int getProcessId(Process process) {
    int processId = 0;

    try {
        Field f = process.getClass().getDeclaredField("pid");
        f.setAccessible(true);

        processId = f.getInt(process);
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
    }

    return processId;
}

From source file:com.allmycode.flags.MyActivity.java

public void go(View view) {
    Intent intent = null;//from   w  ww .jav  a 2s . c o m
    String targetActivityName = "com.allmycode.flags";
    intent = new Intent();
    String fromEditText = targetActivity.getText().toString().trim();
    String other = (fromEditText.contains("Other")) ? ".other" : "";
    targetActivityName += other;
    targetActivityName += ".FlagsDemoActivity";
    targetActivityName += fromEditText;
    Log.i(CLASSNAME, "Target activity: >>" + targetActivityName + "<<");
    intent.setClassName("com.allmycode.flags" + other, targetActivityName);
    String allFlags = flags.getText().toString();
    int flagsValue = 0;
    if (allFlags != "" && allFlags != null) {

        TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter('|');
        splitter.setString(allFlags);
        boolean existErrors = false;
        for (String flagName : splitter) {

            Log.i(CLASSNAME, ">>" + flagName + "<<");

            flagName = flagName.trim();
            if (!flagName.equals("") && flagName != null) { // BARRY
                                                            // need
                                                            // both?
                if (isHex(flagName)) {
                    Log.i(CLASSNAME, flagName + " is hex");
                    flagsValue |= Integer.parseInt(flagName.substring(2), 16);
                } else if (isDec(flagName)) {
                    Log.i(CLASSNAME, flagName + " is decimal");
                    flagsValue |= Integer.parseInt(flagName);
                } else {
                    Field flagsField = null;
                    try {
                        Log.i(CLASSNAME, "About to do reflection>>" + flagName + "<<");
                        flagsField = Intent.class.getField(flagName);
                        Log.i(CLASSNAME, Integer.toString(flagsField.getInt(this)));
                        flagsValue |= flagsField.getInt(this);
                    } catch (SecurityException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    } catch (NoSuchFieldException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    } catch (IllegalAccessException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    }
                    try {
                        Log.i(CLASSNAME, Integer.toHexString(flagsValue));
                        if (flagsValue != 0) {
                            intent.addFlags(flagsValue);
                        }
                    } catch (IllegalArgumentException e) {
                        existErrors = true;
                        e.printStackTrace();
                    }
                }
            }
        }
        if (flagsValue != 0) {
            intent.addFlags(flagsValue);
        }
        intent.putExtra("existErrors", existErrors);

        Log.i(CLASSNAME, "About to start " + intent.toString());
        startActivity(intent);
    }
}

From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java

public void integerTest(String fieldName, Field testField) {
    try {/* ww  w . j a v  a 2  s . c  o  m*/
        Assert.assertTrue(getPropertiesFile().getInt(fieldName) == testField.getInt(getConfigBase()));
    } catch (IllegalAccessException e) {
        assertFailFieldError(fieldName);
    }
}

From source file:com.redhat.rcm.version.CliTest.java

private void assertExitValue() {
    try {/*from w  w  w.j av a  2 s. c om*/
        final Field f = Cli.class.getDeclaredField("exitValue");
        f.setAccessible(true);
        assertThat(f.getInt(null), equalTo(0));
    } catch (final SecurityException e) {
        fail("Exception retrieving field information " + e);
    } catch (final NoSuchFieldException e) {
        fail("Exception retrieving field information " + e);
    } catch (final IllegalArgumentException e) {
        fail("Exception retrieving field information " + e);
    } catch (final IllegalAccessException e) {
        fail("Exception retrieving field information " + e);
    }
}

From source file:tv.acfun.video.HomeActivity.java

private void initDrawer() {
    try {// w w  w .  j  a va 2s  .  co  m
        Field mDragger = mDrawer.getClass().getDeclaredField("mLeftDragger");
        mDragger.setAccessible(true);
        ViewDragHelper draggerObj = (ViewDragHelper) mDragger.get(mDrawer);
        Field mEdgeSize = draggerObj.getClass().getDeclaredField("mEdgeSize");
        mEdgeSize.setAccessible(true);
        int edge = mEdgeSize.getInt(draggerObj);
        mEdgeSize.setInt(draggerObj, edge * 2);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.alex73.skarynka.scan.Book2.java

private void get(Object obj, String prefix, List<String> lines) throws Exception {
    for (Field f : obj.getClass().getFields()) {
        if (Modifier.isPublic(f.getModifiers()) && !Modifier.isStatic(f.getModifiers())
                && !Modifier.isTransient(f.getModifiers())) {
            if (f.getType() == int.class) {
                int v = f.getInt(obj);
                if (v != -1) {
                    lines.add(prefix + f.getName() + "=" + v);
                }/*from  w  w w . j  a va 2s.c  om*/
            } else if (f.getType() == boolean.class) {
                lines.add(prefix + f.getName() + "=" + f.getBoolean(obj));
            } else if (f.getType() == String.class) {
                String s = (String) f.get(obj);
                if (s != null) {
                    lines.add(prefix + f.getName() + "=" + s);
                }
            } else if (Set.class.isAssignableFrom(f.getType())) {
                Set<?> set = (Set<?>) f.get(obj);
                StringBuilder t = new StringBuilder();
                for (Object o : set) {
                    t.append(o.toString()).append(';');
                }
                if (t.length() > 0) {
                    t.setLength(t.length() - 1);
                }
                lines.add(prefix + f.getName() + "=" + t);
            } else {
                throw new RuntimeException("Unknown field class for get '" + f.getName() + "'");
            }
        }
    }
}

From source file:com.netflix.genie.server.jobmanager.impl.JobManagerImpl.java

/**
 * Get process id for the given process.
 *
 * @param proc java process object representing the job launcher
 * @return pid for this process//from w w  w .java2s  .c  om
 * @throws GenieException if there is an error getting the process id
 */
private int getProcessId(final Process proc) throws GenieException {
    LOG.debug("called");

    try {
        final Field f = proc.getClass().getDeclaredField(PID);
        f.setAccessible(true);
        return f.getInt(proc);
    } catch (final IllegalAccessException | IllegalArgumentException | NoSuchFieldException
            | SecurityException e) {
        final String msg = "Can't get process id for job";
        LOG.error(msg, e);
        throw new GenieServerException(msg, e);
    }
}

From source file:com.mattprecious.notisync.service.NotificationService.java

@SuppressLint("NewApi")
private CustomMessage getCustomMessage(PrimaryProfile profile, Notification notification, String packageName) {
    RemoteViews views = null;//w  w w. ja va  2  s  .  c o m
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        views = notification.bigContentView;
    }
    MyLog.d(TAG, "views: " + views);
    if (views == null) {
        views = notification.contentView;
    }
    if (views == null) {
        return null;
    }
    Class secretClass = views.getClass();
    ArrayList<String> listLong = new ArrayList<String>();
    ArrayList<String> listMessages = new ArrayList<String>();
    try {
        Map<Integer, String> text = new HashMap<Integer, String>();
        Field outerFields[] = secretClass.getDeclaredFields();

        for (int i = 0; i < outerFields.length; i++) {
            if (!outerFields[i].getName().equals("mActions"))
                continue;

            outerFields[i].setAccessible(true);

            ArrayList<Object> actions = (ArrayList<Object>) outerFields[i].get(views);
            for (Object action : actions) {
                Field innerFields[] = action.getClass().getDeclaredFields();

                Object value = null;
                Integer type = null;
                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) {
                        if (type == 5) {
                            listLong.add(value.toString());
                        } else if (type == 9 || type == 10) {
                            listMessages.add(value.toString());
                        }
                    }
                }
            }
        }

        String testStrNumbers = "";
        for (int i = 0; i < listLong.size(); i++) {
            testStrNumbers += ", " + listLong.get(i);
        }
        String testStrMessages = "";
        for (int i = 0; i < listMessages.size(); i++) {
            testStrMessages += ", " + listMessages.get(i);
        }

        MyLog.d(TAG, "testStrNumbers: " + testStrNumbers);
        MyLog.d(TAG, "testStrMessages: " + testStrMessages);

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

    /*String bitmapString = bitmapToString(notification.largeIcon);
    Log.d("NotificationService", "BitmapString: " + bitmapString);
            
    Drawable icon = null;
    try {
       icon = getPackageManager().getApplicationIcon(profile.getPackageName());
    } catch (NameNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }
    String iconString = drawableToString(icon);*/
    if (PACKAGE_WHATSAPP.equals(packageName)) {
        return new CustomMessage.Builder().tag(profile.getTag()).appName(profile.getName())
                .messageTitle(listMessages.get(0)).time(listLong.get(0)).message(listMessages.get(2))
                .packageName(profile.getPackageName())
                .tickerText((notification.tickerText != null) ? notification.tickerText.toString() : "")
                .unread("").account("").build();
    } else if (listMessages.size() >= 5) {
        return new CustomMessage.Builder().tag(profile.getTag()).appName(profile.getName())
                .messageTitle(listMessages.get(0)).time(listLong.get(0))
                .message(listMessages.get(3) + "\n" + listMessages.get(4)).packageName(profile.getPackageName())
                .tickerText((notification.tickerText != null) ? notification.tickerText.toString() : "")
                .unread(listMessages.get(1)).account(listMessages.get(2)).build();
    } else if (listMessages.size() == 4) {
        return new CustomMessage.Builder().tag(profile.getTag()).appName(profile.getName())
                .messageTitle(listMessages.get(0)).time(listLong.get(0)).message(listMessages.get(3))
                .packageName(profile.getPackageName())
                .tickerText((notification.tickerText != null) ? notification.tickerText.toString() : "")
                .unread(listMessages.get(1)).account(listMessages.get(2)).build();
    } else {
        return new CustomMessage.Builder().tag(profile.getTag()).appName(profile.getName())
                .messageTitle(listMessages.get(0)).time(listLong.get(0)).message(listMessages.get(1))
                .packageName(profile.getPackageName())
                .tickerText((notification.tickerText != null) ? notification.tickerText.toString() : "")
                .unread("").account("").build();
    }
}