private boolean unpackPrimitive(final Field afield, InputObjectState os) {
    try {
      // TODO arrays

      if (afield.getType().equals(Boolean.TYPE)) afield.setBoolean(_theObject, os.unpackBoolean());
      else if (afield.getType().equals(Byte.TYPE)) afield.setByte(_theObject, os.unpackByte());
      else if (afield.getType().equals(Short.TYPE)) afield.setShort(_theObject, os.unpackShort());
      else if (afield.getType().equals(Integer.TYPE)) afield.setInt(_theObject, os.unpackInt());
      else if (afield.getType().equals(Long.TYPE)) afield.setLong(_theObject, os.unpackLong());
      else if (afield.getType().equals(Float.TYPE)) afield.setFloat(_theObject, os.unpackFloat());
      else if (afield.getType().equals(Double.TYPE))
        afield.setDouble(_theObject, os.unpackDouble());
      else if (afield.getType().equals(Character.TYPE)) afield.setChar(_theObject, os.unpackChar());
      else return false;
    } catch (final IOException ex) {
      ex.printStackTrace();

      return false;
    } catch (final Exception ex) {
      ex.printStackTrace();

      return false;
    }

    return true;
  }
 /**
  * Creates a new entity
  *
  * @param instantiationValues A Map containing the values to set for this new entity.
  */
 protected ActiveRecordBase(Map<String, Object> instantiationValues) {
   super();
   try {
     Map<String, Field> classFields = EntitiesHelper.getFieldsMap(getClass());
     for (String key : instantiationValues.keySet()) {
       if (classFields.containsKey(key)) {
         Field field = classFields.get(key);
         Class fieldClass = field.getClass();
         Object data = instantiationValues.get(key);
         if (fieldClass == Integer.class) {
           field.setInt(this, ((Integer) data).intValue());
         } else if (fieldClass == Byte.class) {
           field.setByte(this, ((Byte) data).byteValue());
         } else if (fieldClass == Short.class) {
           field.setShort(this, ((Short) data).shortValue());
         } else if (fieldClass == Long.class) {
           field.setLong(this, ((Long) data).longValue());
         } else if (fieldClass == Double.class) {
           field.setDouble(this, ((Double) data).doubleValue());
         } else if (fieldClass == Boolean.class) {
           field.setBoolean(this, ((Boolean) data).booleanValue());
         } else {
           field.set(this, data);
         }
       }
     }
   } catch (IllegalAccessException e) {
     // TODO: Fixme
   }
 }
Exemple #3
0
 /**
  * 把查询结果填充到vo中
  *
  * @param rs 查询结果,由调用负责游标
  * @param t vo
  * @throws IllegalArgumentException
  * @throws IllegalAccessException
  * @throws SQLException
  */
 private void fillVO(ResultSet rs, T t)
     throws IllegalArgumentException, IllegalAccessException, SQLException {
   for (Field f : listTableFields(t.getClass())) {
     String name = findFieldName(f);
     Object object = rs.getObject(name);
     if (object != null) {
       if (!f.isAccessible()) {
         f.setAccessible(true);
       }
       if (isBoolean(f)) {
         f.setBoolean(t, rs.getBoolean(name));
       } else if (isInt(f)) {
         f.setInt(t, rs.getInt(name));
       } else if (isLong(f)) {
         f.setLong(t, rs.getLong(name));
       } else if (isString(f)) {
         f.set(t, rs.getString(name));
       } else if (isDate(f)) {
         f.set(t, rs.getTimestamp(name));
       } else if (isByte(f)) {
         f.setByte(t, rs.getByte(name));
       } else if (isChar(f)) {
         f.setChar(t, rs.getString(name).charAt(0));
       } else if (isDouble(f)) {
         f.setDouble(t, rs.getDouble(name));
       } else if (isFloat(f)) {
         f.setFloat(t, rs.getFloat(name));
       } else {
         f.set(t, object);
       }
     }
   }
 }
 public static void toggleField(Field field, Object obj, boolean on)
     throws IllegalAccessException, InstantiationException {
   field.setAccessible(true);
   if (field.getType() == String.class) {
     field.set(obj, on ? TEST_STRING_VAL1 : TEST_STRING_VAL2);
   } else if (field.getType() == boolean.class) {
     field.setBoolean(obj, on ? true : false);
   } else if (field.getType() == short.class) {
     field.setShort(obj, on ? (short) 1 : (short) 0);
   } else if (field.getType() == long.class) {
     field.setLong(obj, on ? 1 : 0);
   } else if (field.getType() == float.class) {
     field.setFloat(obj, on ? 1 : 0);
   } else if (field.getType() == int.class) {
     field.setInt(obj, on ? 1 : 0);
   } else if (field.getType() == Integer.class) {
     field.set(obj, on ? 1 : 0);
   } else if (field.getType() == byte.class) {
     field.setByte(obj, on ? (byte) 1 : (byte) 0);
   } else if (field.getType() == char.class) {
     field.setChar(obj, on ? (char) 1 : (char) 0);
   } else if (field.getType() == double.class) {
     field.setDouble(obj, on ? 1 : 0);
   } else if (field.getType() == BigDecimal.class) {
     field.set(obj, on ? new BigDecimal(1) : new BigDecimal(0));
   } else if (field.getType() == Date.class) {
     field.set(obj, on ? new Date() : new Date(0));
   } else if (field.getType().isEnum()) {
     field.set(obj, field.getType().getEnumConstants()[on ? 1 : 0]);
   } else if (Object.class.isAssignableFrom(field.getType())) {
     field.set(obj, field.getType().newInstance());
   } else {
     fail("Don't know how to set a " + field.getType().getName());
   }
 }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    inflaterFactory = new InjectPoolFactory(getLayoutInflater().getFactory2());
    // use introspection to allow a new Factory to be set
    try {
      Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
      field.setAccessible(true);
      field.setBoolean(getLayoutInflater(), false);
      getLayoutInflater().setFactory2(inflaterFactory);
    } catch (NoSuchFieldException e) {
      // ...
    } catch (IllegalArgumentException e) {
      // ...
    } catch (IllegalAccessException e) {
      // ...
    }

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });
  }
    private final void map(Object value, Object result, java.lang.reflect.Field member)
        throws IllegalAccessException {
      Class<?> mType = member.getType();

      if (mType.isPrimitive()) {
        if (mType == byte.class) {
          member.setByte(result, (Byte) value);
        } else if (mType == short.class) {
          member.setShort(result, (Short) value);
        } else if (mType == int.class) {
          member.setInt(result, (Integer) value);
        } else if (mType == long.class) {
          member.setLong(result, (Long) value);
        } else if (mType == float.class) {
          member.setFloat(result, (Float) value);
        } else if (mType == double.class) {
          member.setDouble(result, (Double) value);
        } else if (mType == boolean.class) {
          member.setBoolean(result, (Boolean) value);
        } else if (mType == char.class) {
          member.setChar(result, (Character) value);
        }
      } else {
        member.set(result, value);
      }
    }
Exemple #7
0
  @Override
  public void onCreate() {
    try {
      final ViewConfiguration config = ViewConfiguration.get(this);
      final Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
      menuKeyField.setAccessible(true);
      menuKeyField.setBoolean(config, false);
    } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException ignored) {
    }

    // Set language to English if the user decided so.
    initApplicationLocale(Settings.useEnglish());

    // ensure initialization of lists
    DataStore.getLists();

    // Check if Google Play services is available
    if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this)
        == ConnectionResult.SUCCESS) {
      isGooglePlayServicesAvailable = true;
    }
    Log.i(
        "Google Play services are " + (isGooglePlayServicesAvailable ? "" : "not ") + "available");
    final Sensors sensors = Sensors.getInstance();
    sensors.setupGeoDataObservables(Settings.useGooglePlayServices(), Settings.useLowPowerMode());
    sensors.setupDirectionObservable(Settings.useLowPowerMode());

    // Attempt to acquire an initial location before any real activity happens.
    sensors
        .geoDataObservable(true)
        .subscribeOn(RxUtils.looperCallbacksScheduler)
        .first()
        .subscribe();
  }
 @Override
 public void onCreate() {
   super.onCreate();
   if (Config.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
     StrictMode.setThreadPolicy(
         new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
     StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
   }
   sInstance = this;
   initImageLoader(getApplicationContext());
   mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
   mPreferences.registerOnSharedPreferenceChangeListener(this);
   try {
     ViewConfiguration config = ViewConfiguration.get(this);
     Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
     if (menuKeyField != null) {
       menuKeyField.setAccessible(true);
       menuKeyField.setBoolean(config, false);
     }
   } catch (Exception ex) {
     // Ignore
   }
   // 全局异常捕获
   //		CustomException customException = CustomException.getInstance();
   //		customException.init(getApplicationContext());
   initJpush();
 }
 /**
  * @param node The node to be printed.
  * @param prettyPrint Whether to pretty print.
  * @param outputTypes Whether to output types as JSDocStrings.
  */
 public MagicCodePrinterBuilder(Node node, boolean prettyPrint, boolean outputTypes) {
   initialize();
   try {
     codePrinterBuilder = constructor.newInstance(node);
     field_prettyPrint.setBoolean(codePrinterBuilder, prettyPrint);
     field_outputTypes.setBoolean(codePrinterBuilder, outputTypes);
   } catch (IllegalArgumentException e) {
     throw new MagicException(e);
   } catch (InstantiationException e) {
     throw new MagicException(e);
   } catch (IllegalAccessException e) {
     throw new MagicException(e);
   } catch (InvocationTargetException e) {
     Magic.catchInvocationTargetException(e);
   }
 }
Exemple #10
0
  public static SootClass mockSootClass(String clsName) {
    SootClass sc = null;

    if (Scene.v().containsClass(clsName)) {
      sc = Scene.v().getSootClass(clsName);

      if (sc.isPhantom()) {
        // sc.setPhantom(false);
        sc.setApplicationClass();
        sc.setInScene(true);

        try {
          for (Field field : sc.getClass().getFields()) {
            if (field.getName().equals("isPhantom")) {
              field.setAccessible(true);
              field.setBoolean(sc, false);
            }
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    } else {
      sc = new SootClass(clsName);
      sc.setSuperclass(Scene.v().getSootClass("java.lang.Object"));

      sc.setPhantom(false);
      sc.setApplicationClass();
      sc.setInScene(true);
    }

    mockConstructor(sc);

    return sc;
  }
Exemple #11
0
 public void deserialize(JsonObject jo, Object t, Field field)
     throws IllegalAccessException {
   if (jo.has(field.getName())) {
     Boolean b = jo.getAsJsonPrimitive(field.getName()).getAsBoolean();
     field.setBoolean(t, b);
   }
 }
  /**
   * Tests various getter/setters.
   *
   * @throws IllegalArgumentException
   * @throws IllegalAccessException
   * @throws SecurityException
   * @throws NoSuchFieldException
   */
  @SuppressWarnings("deprecation")
  @Test
  public void testSettersGetters()
      throws IllegalArgumentException, IllegalAccessException, SecurityException,
          NoSuchFieldException {
    ConnectionPartition mockPartition = createNiceMock(ConnectionPartition.class);
    testClass.setOriginatingPartition(mockPartition);
    assertEquals(mockPartition, testClass.getOriginatingPartition());

    testClass.setConnectionLastReset(123);
    assertEquals(testClass.getConnectionLastReset(), 123);

    testClass.setConnectionLastUsed(456);
    assertEquals(testClass.getConnectionLastUsed(), 456);

    Field field = testClass.getClass().getDeclaredField("possiblyBroken");
    field.setAccessible(true);
    field.setBoolean(testClass, true);
    assertTrue(testClass.isPossiblyBroken());

    Object debugHandle = new Object();
    testClass.setDebugHandle(debugHandle);
    assertEquals(debugHandle, testClass.getDebugHandle());

    testClass.setInternalConnection(mockConnection);
    assertEquals(mockConnection, testClass.getInternalConnection());
    assertEquals(mockConnection, testClass.getRawConnection());

    field = testClass.getClass().getDeclaredField("logicallyClosed");
    field.setAccessible(true);
    field.setBoolean(testClass, true);
    assertTrue(testClass.isClosed());

    testClass.setLogStatementsEnabled(true);
    assertTrue(testClass.isLogStatementsEnabled());

    assertEquals(testClass.getPool(), mockPool);
    ArrayList<ReplayLog> testLog = new ArrayList<ReplayLog>();
    testClass.setReplayLog(testLog);
    assertEquals(testClass.getReplayLog(), testLog);
    testClass.setInReplayMode(true);
    assertTrue(testClass.isInReplayMode());
    testClass.setInReplayMode(false);

    testClass.threadUsingConnection = Thread.currentThread();
    assertEquals(Thread.currentThread(), testClass.getThreadUsingConnection());
  }
 void deserialize(AbstractHessianInput in, Object obj) throws IOException {
   boolean value = false;
   try {
     value = in.readBoolean();
     _field.setBoolean(obj, value);
   } catch (Exception e) {
     logDeserializeError(_field, obj, value, e);
   }
 }
Exemple #14
0
 /**
  * Set a boolean field by class name and field name.
  * 
  * @param classname  class name
  * @param fieldname  field name
  * @param value  value to set
  */
 public static void setBooleanField(String classname, String fieldname, boolean value) {
     try {
         Class c = Class.forName(classname);
         Field f = c.getField(fieldname);
         f.setBoolean(null, value);
     } catch (Exception e) {
         System.err.println("Cannot set the flag "+classname+"."+fieldname);
     }
 }
Exemple #15
0
 /** 统一OverFlow样式 */
 private void setOverflowShowAlways() {
   try {
     ViewConfiguration viewConfiguration = ViewConfiguration.get(this);
     Field field = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
     field.setAccessible(true);
     field.setBoolean(viewConfiguration, false);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public static void setAllowSleep(Player player) {
   try {
     Object nmsEntity = getNmsEntity(player);
     Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity);
     Field check = getNmsField(connection.getClass(), "checkMovement");
     check.setBoolean(connection, true);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Exemple #17
0
  private void loadDatabase() {
    // Declare a few local variables for later use
    ClassLoader currentClassLoader = null;
    Field cacheField = null;
    boolean cacheValue = true;

    try {
      // Store the current ClassLoader, so it can be reverted later
      currentClassLoader = Thread.currentThread().getContextClassLoader();

      // Set the ClassLoader to Plugin ClassLoader
      Thread.currentThread().setContextClassLoader(classLoader);

      // Get a reference to the private static "defaultUseCaches"-field in URLConnection
      cacheField = URLConnection.class.getDeclaredField("defaultUseCaches");

      // Make it accessible, store the default value and set it to false
      cacheField.setAccessible(true);
      cacheValue = cacheField.getBoolean(null);
      cacheField.setBoolean(null, false);

      // Setup Ebean based on the configuration
      ebeanServer = EbeanServerFactory.create(serverConfig);
    } catch (Exception ex) {
      throw new RuntimeException("Failed to create a new instance of the EbeanServer", ex);
    } finally {
      // Revert the ClassLoader back to its original value
      if (currentClassLoader != null) {
        Thread.currentThread().setContextClassLoader(currentClassLoader);
      }

      // Revert the "defaultUseCaches"-field in URLConnection back to its original value
      try {
        if (cacheField != null) {
          cacheField.setBoolean(null, cacheValue);
        }
      } catch (Exception e) {
        System.out.println(
            "Failed to revert the \"defaultUseCaches\"-field back to its original value, URLConnection-caching remains disabled.");
      }
    }
  }
Exemple #18
0
 private static boolean setFlag(Field f, boolean enabled) {
   boolean success = false;
   try {
     f.setBoolean(null, enabled);
     success = true;
     Log.info(f.getName() + " = " + enabled);
   } catch (IllegalAccessException e) {
     Log.warn("reflection problem", e);
   }
   return success;
 }
 /**
  * @param ai
  * @param instance
  * @param field
  * @param annotation
  */
 private void initClassFieldBooleanParameter(
     final Class<? extends AI> ai,
     final AI instance,
     final Field field,
     final AIBooleanParameter annotation)
     throws IllegalAccessException {
   AIJComponent uiComponent =
       new AIBooleanParameterJComponent(annotation.value(), ai, instance, field);
   field.setBoolean(instance, annotation.value());
   uiComponent.addComponents(instance.component());
 }
  @Override
  public void show(FragmentManager manager, String tag) {
    try {
      @SuppressWarnings("rawtypes")
      Class dialogFragmentClass = getDialogFragmentClass();
      Field mDismissed = dialogFragmentClass.getDeclaredField("mDismissed");
      mDismissed.setAccessible(true);
      mDismissed.setBoolean(this, false);

      Field mShownByMe = dialogFragmentClass.getDeclaredField("mShownByMe");
      mShownByMe.setAccessible(true);
      mShownByMe.setBoolean(this, true);
    } catch (Exception e) {
      LOG.e(e);
    }

    FragmentTransaction ft = manager.beginTransaction();
    ft.add(this, tag);
    ft.commitAllowingStateLoss();
  }
  /**
   * Forces the appearance of a menu in the given context.
   *
   * @param ctx
   */
  public static void showMenu(Context ctx) {
    try {
      ViewConfiguration config = ViewConfiguration.get(ctx);
      Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");

      if (menuKeyField != null) {
        menuKeyField.setAccessible(true);
        menuKeyField.setBoolean(config, false);
      }
    } catch (Exception e) {
    }
  }
Exemple #22
0
 // Activa el ítem de overflow en dispositivos con botón físico de menú.
 private void activarOverflow() {
   try {
     ViewConfiguration config = ViewConfiguration.get(this);
     Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
     if (menuKeyField != null) {
       menuKeyField.setAccessible(true);
       menuKeyField.setBoolean(config, false);
     }
   } catch (Exception ex) {
     // Ignorar
   }
 }
  protected void readFields0(
      final Object object, final Class classs, final ObjectInputStream objectInputStream)
      throws IllegalAccessException {
    final Set<Field> serializableFields = ReflectionHelper.buildSerializableFields(object, classs);

    // serialize fields in alphabetical order
    final Iterator<Field> iterator = serializableFields.iterator();
    while (iterator.hasNext()) {
      final Field field = iterator.next();
      field.setAccessible(true);

      final Class fieldType = field.getType();

      if (fieldType.equals(Boolean.TYPE)) {
        field.setBoolean(object, objectInputStream.readBoolean());
        continue;
      }
      if (fieldType.equals(Byte.TYPE)) {
        field.setByte(object, objectInputStream.readByte());
        continue;
      }
      if (fieldType.equals(Short.TYPE)) {
        field.setShort(object, objectInputStream.readShort());
        continue;
      }
      if (fieldType.equals(Integer.TYPE)) {
        field.setInt(object, objectInputStream.readInt());
        continue;
      }
      if (fieldType.equals(Long.TYPE)) {
        field.setLong(object, objectInputStream.readLong());
        continue;
      }
      if (fieldType.equals(Float.TYPE)) {
        field.setFloat(object, objectInputStream.readFloat());
        continue;
      }
      if (fieldType.equals(Double.TYPE)) {
        field.setDouble(object, objectInputStream.readDouble());
        continue;
      }
      if (fieldType.equals(Character.TYPE)) {
        field.setChar(object, objectInputStream.readChar());
        continue;
      }
      field.set(object, objectInputStream.readObject());
    }

    final Class superType = classs.getSuperclass();
    if (false == superType.equals(Object.class)) {
      this.readFields(object, superType, objectInputStream);
    }
  }
 // action overflow :.
 private void getOverflowMenu() {
   try {
     ViewConfiguration config = ViewConfiguration.get(this);
     Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
     if (menuKeyField != null) {
       menuKeyField.setAccessible(true);
       menuKeyField.setBoolean(config, false);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemple #25
0
  public static void assertMeetsHashCodeContract(Class<?> classUnderTest, String[] fieldNames) {
    try {
      Field[] fields = getFieldsByNameOrAll(classUnderTest, fieldNames);

      for (int i = 0; i < fields.length; i++) {
        Object o1 = classUnderTest.newInstance();
        int initialHashCode = o1.hashCode();

        Field field = fields[i];
        field.setAccessible(true);
        if (field.getType() == String.class) {
          field.set(o1, TEST_STRING_VAL1);
        } else if (field.getType() == boolean.class) {
          field.setBoolean(o1, true);
        } else if (field.getType() == short.class) {
          field.setShort(o1, (short) 1);
        } else if (field.getType() == long.class) {
          field.setLong(o1, (long) 1);
        } else if (field.getType() == float.class) {
          field.setFloat(o1, (float) 1);
        } else if (field.getType() == int.class) {
          field.setInt(o1, 1);
        } else if (field.getType() == byte.class) {
          field.setByte(o1, (byte) 1);
        } else if (field.getType() == char.class) {
          field.setChar(o1, (char) 1);
        } else if (field.getType() == double.class) {
          field.setDouble(o1, (double) 1);
        } else if (field.getType().isEnum()) {
          field.set(o1, field.getType().getEnumConstants()[0]);
        } else if (Object.class.isAssignableFrom(field.getType())) {
          field.set(o1, field.getType().newInstance());
        } else {
          fail("Don't know how to set a " + field.getType().getName());
        }
        int updatedHashCode = o1.hashCode();
        assertFalse(
            "The field "
                + field.getName()
                + " was not taken into account for the hashCode contract ",
            initialHashCode == updatedHashCode);
      }
    } catch (InstantiationException e) {
      e.printStackTrace();
      throw new AssertionError("Unable to construct an instance of the class under test");
    } catch (IllegalAccessException e) {
      e.printStackTrace();
      throw new AssertionError("Unable to construct an instance of the class under test");
    } catch (NoSuchFieldException e) {
      e.printStackTrace();
      throw new AssertionError("Unable to find field in the class under test");
    }
  }
 public static void keep_readBoolean(Parcel paramParcel, Field paramField, Object paramObject) {
   try {
     if (paramParcel.readInt() != 0) {}
     for (boolean bool = true; ; bool = false) {
       paramField.setBoolean(paramObject, bool);
       return;
     }
     return;
   } catch (Exception paramParcel) {
     v.e("MicroMsg.MCacheItem", "exception:%s", new Object[] {be.f(paramParcel)});
   }
 }
Exemple #27
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Initilization
    setContentView(R.layout.activity_charts);
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager(), this);
    viewPager.setAdapter(mAdapter);
    viewPager.setOffscreenPageLimit(2);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
    Bundle bundle;
    bundle = getIntent().getExtras();
    tabs = bundle.getStringArrayList("tabs");
    Intent intent = new Intent(this, TabsPagerAdapter.class);
    intent.putExtras(bundle);
    try {
      ViewConfiguration config = ViewConfiguration.get(this);
      Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
      if (menuKeyField != null) {
        menuKeyField.setAccessible(true);
        menuKeyField.setBoolean(config, false);
      }
    } catch (Exception ex) {
      // Ignore
    }

    viewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {

          @Override
          public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            // actionBar.setSelectedNavigationItem(position);
          }

          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {}

          @Override
          public void onPageScrollStateChanged(int arg0) {}
        });
    /*Intent recintent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "AndroidBite Voice Recognition...");
    startActivityForResult(recintent, 100);*/
  }
Exemple #28
0
  public static void init(Controller controller, Context context) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
      boolean mIsBound = false;
      java.lang.reflect.Field fIsBound = null;
      android.content.ServiceConnection mServiceConnection = null;
      java.lang.reflect.Field fServiceConnection = null;
      try {
        Class<?> cMogaController = controller.getClass();
        fIsBound = cMogaController.getDeclaredField("mIsBound");
        fIsBound.setAccessible(true);
        mIsBound = fIsBound.getBoolean(controller);
        fServiceConnection = cMogaController.getDeclaredField("mServiceConnection");
        fServiceConnection.setAccessible(true);
        mServiceConnection = (android.content.ServiceConnection) fServiceConnection.get(controller);
      } catch (NoSuchFieldException e) {
        Log.e("MogaHack", "MOGA Lollipop Hack NoSuchFieldException (get)", e);
      } catch (IllegalAccessException e) {
        Log.e("MogaHack", "MOGA Lollipop Hack IllegalAccessException (get)", e);
      } catch (IllegalArgumentException e) {
        Log.e("MogaHack", "MOGA Lollipop Hack IllegalArgumentException (get)", e);
      }
      if ((!mIsBound) && (mServiceConnection != null)) {
        // Convert implicit intent to explicit intent, see http://stackoverflow.com/a/26318757
        Intent intent = new Intent(IControllerService.class.getName());
        List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices(intent, 0);
        if (resolveInfos == null || resolveInfos.size() != 1) {
          // What? this doesn't do anything.
          // Log.e( "MogaHack", "Somebody is trying to intercept our intent. Disabling MOGA
          // controller for security." );
        }
        ServiceInfo serviceInfo = resolveInfos.get(0).serviceInfo;
        String packageName = serviceInfo.packageName;
        String className = serviceInfo.name;
        intent.setComponent(new ComponentName(packageName, className));

        // Start the service explicitly
        context.startService(intent);
        context.bindService(intent, mServiceConnection, 1);
        try {
          fIsBound.setBoolean(controller, true);
        } catch (IllegalAccessException e) {
          Log.e("MogaHack", "MOGA Lollipop Hack IllegalAccessException (set)", e);
        } catch (IllegalArgumentException e) {
          Log.e("MogaHack", "MOGA Lollipop Hack IllegalArgumentException (set)", e);
        }
      }
    } else {
      controller.init();
    }
  }
  private void configureField(Object check, Field field, String value) {
    try {
      field.setAccessible(true);

      if (field.getType().equals(String.class)) {
        field.set(check, value);

      } else if ("int".equals(field.getType().getSimpleName())) {
        field.setInt(check, Integer.parseInt(value));

      } else if ("short".equals(field.getType().getSimpleName())) {
        field.setShort(check, Short.parseShort(value));

      } else if ("long".equals(field.getType().getSimpleName())) {
        field.setLong(check, Long.parseLong(value));

      } else if ("double".equals(field.getType().getSimpleName())) {
        field.setDouble(check, Double.parseDouble(value));

      } else if ("boolean".equals(field.getType().getSimpleName())) {
        field.setBoolean(check, Boolean.parseBoolean(value));

      } else if ("byte".equals(field.getType().getSimpleName())) {
        field.setByte(check, Byte.parseByte(value));

      } else if (field.getType().equals(Integer.class)) {
        field.set(check, Integer.parseInt(value));

      } else if (field.getType().equals(Long.class)) {
        field.set(check, Long.parseLong(value));

      } else if (field.getType().equals(Double.class)) {
        field.set(check, Double.parseDouble(value));

      } else if (field.getType().equals(Boolean.class)) {
        field.set(check, Boolean.parseBoolean(value));

      } else {
        throw new SonarException(
            "The type of the field " + field + " is not supported: " + field.getType());
      }
    } catch (IllegalAccessException e) {
      throw new SonarException(
          "Can not set the value of the field "
              + field
              + " in the class: "
              + check.getClass().getName(),
          e);
    }
  }
Exemple #30
0
 public void a(SlidingPaneLayout slidingpanelayout, View view) {
   if (a != null && b != null) {
     try {
       b.setBoolean(view, true);
       a.invoke(view, (Object[]) null);
     } catch (Exception exception) {
       Log.e("SlidingPaneLayout", "Error refreshing display list state", exception);
     }
     super.a(slidingpanelayout, view);
     return;
   } else {
     view.invalidate();
     return;
   }
 }