コード例 #1
0
  private void toggleCamera(boolean isNeedEnableCam) {

    // TODO temporary insertion will be removed when GLVideoView will be fixed
    DisplayMetrics displaymetrics = new DisplayMetrics();
    displaymetrics.setToDefaults();

    ViewGroup.LayoutParams layoutParams = imgMyCameraOff.getLayoutParams();

    layoutParams.height = localVideoView.getHeight();
    layoutParams.width = localVideoView.getWidth();

    imgMyCameraOff.setLayoutParams(layoutParams);

    Log.d(
        TAG,
        "Width is: "
            + imgMyCameraOff.getLayoutParams().width
            + " height is:"
            + imgMyCameraOff.getLayoutParams().height);

    if (SessionManager.getCurrentSession() != null) {
      SessionManager.getCurrentSession().setVideoEnabled(isNeedEnableCam);
      cameraToggle.setChecked(isNeedEnableCam);

      if (isNeedEnableCam) {
        Log.d(TAG, "Camera is on");
        switchCameraToggle.setVisibility(View.VISIBLE);
        imgMyCameraOff.setVisibility(View.INVISIBLE);
      } else {
        Log.d(TAG, "Camera is off");
        switchCameraToggle.setVisibility(View.INVISIBLE);
        imgMyCameraOff.setVisibility(View.VISIBLE);
      }
    }
  }
コード例 #2
0
  /**
   * 获取一个apk文件的签名,思路是更具PackageParser对象反射而来
   *
   * @param path apk文件的路径
   * @return
   */
  public static String getApkSign(String path) {
    String packageParserStr = "android.content.pm.PackageParser";
    // 方法的参数类型
    Class<?>[] typeArgs = new Class[1];

    // 方法需要传入的参数值
    Object[] valueArgs = new Object[1];

    try {
      // 实例化PackageParser对象
      Class<?> pkgParserCls = Class.forName(packageParserStr);
      typeArgs[0] = String.class;
      Constructor<?> pkgParserCt = pkgParserCls.getConstructor(typeArgs);
      valueArgs[0] = path;
      Object pkgParser = pkgParserCt.newInstance(valueArgs);

      // 执行parsePackage方法
      typeArgs = new Class[4];
      typeArgs[0] = File.class;
      typeArgs[1] = String.class;
      typeArgs[2] = DisplayMetrics.class;
      typeArgs[3] = int.class;
      Method parsePackageMtd = pkgParserCls.getDeclaredMethod("parsePackage", typeArgs);

      valueArgs = new Object[4];
      valueArgs[0] = new File(path);
      valueArgs[1] = path;
      DisplayMetrics metrics = new DisplayMetrics();
      metrics.setToDefaults();
      valueArgs[2] = metrics;
      valueArgs[3] = PackageManager.GET_SIGNATURES;

      // 得到PackageParser.Package对象
      Object pkgParserPkg = parsePackageMtd.invoke(pkgParser, valueArgs);

      // 执行collectCertificates方法
      typeArgs = new Class[2];
      typeArgs[0] = pkgParserPkg.getClass();
      typeArgs[1] = int.class;
      Method collectCertificatedsMtd = pkgParserCls.getMethod("collectCertificates", typeArgs);

      valueArgs = new Object[2];
      valueArgs[0] = pkgParserPkg;
      valueArgs[1] = PackageManager.GET_SIGNATURES;
      collectCertificatedsMtd.invoke(pkgParser, valueArgs);

      // 获取mSignature的属性值
      Field mSignatures = pkgParserPkg.getClass().getDeclaredField("mSignatures");
      Signature[] signatures = (Signature[]) mSignatures.get(pkgParserPkg);

      return signatures[0].toCharsString();

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
コード例 #3
0
ファイル: ApkUtils.java プロジェクト: Kcwind/root-tools
  public static PackageParser.Package getPackageInfoFromPackage(
      String filePath, boolean collectSignature) {
    PackageParser packageParser = new PackageParser(filePath);
    File sourceFile = new File(filePath);
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.setToDefaults();
    PackageParser.Package pkg = packageParser.parsePackage(sourceFile, filePath, metrics, 0);
    if (pkg != null && collectSignature) {
      packageParser.collectCertificates(pkg, 0);
    }

    return pkg;
  }
コード例 #4
0
 public static Drawable geTApkIcon(Context context, String Path) {
   // 未安装的程序通过apk文件获取icon
   String apkPath = Path; // apk 文件所在的路径
   String PATH_PackageParser = "android.content.pm.PackageParser";
   String PATH_AssetManager = "android.content.res.AssetManager";
   try {
     Class<?> pkgParserCls = Class.forName(PATH_PackageParser);
     Class<?>[] typeArgs = {String.class};
     Constructor<?> pkgParserCt = pkgParserCls.getConstructor(typeArgs);
     Object[] valueArgs = {apkPath};
     Object pkgParser = pkgParserCt.newInstance(valueArgs);
     DisplayMetrics metrics = new DisplayMetrics();
     metrics.setToDefaults();
     typeArgs = new Class<?>[] {File.class, String.class, DisplayMetrics.class, int.class};
     Method pkgParser_parsePackageMtd = pkgParserCls.getDeclaredMethod("parsePackage", typeArgs);
     valueArgs = new Object[] {new File(apkPath), apkPath, metrics, 0};
     Object pkgParserPkg = pkgParser_parsePackageMtd.invoke(pkgParser, valueArgs);
     Field appInfoFld = pkgParserPkg.getClass().getDeclaredField("applicationInfo");
     ApplicationInfo info = (ApplicationInfo) appInfoFld.get(pkgParserPkg);
     Class<?> assetMagCls = Class.forName(PATH_AssetManager);
     Object assetMag = assetMagCls.newInstance();
     typeArgs = new Class[1];
     typeArgs[0] = String.class;
     Method assetMag_addAssetPathMtd = assetMagCls.getDeclaredMethod("addAssetPath", typeArgs);
     valueArgs = new Object[1];
     valueArgs[0] = apkPath;
     assetMag_addAssetPathMtd.invoke(assetMag, valueArgs);
     Resources res = context.getResources();
     typeArgs = new Class[3];
     typeArgs[0] = assetMag.getClass();
     typeArgs[1] = res.getDisplayMetrics().getClass();
     typeArgs[2] = res.getConfiguration().getClass();
     Constructor<Resources> resCt = Resources.class.getConstructor(typeArgs);
     valueArgs = new Object[3];
     valueArgs[0] = assetMag;
     valueArgs[1] = res.getDisplayMetrics();
     valueArgs[2] = res.getConfiguration();
     res = (Resources) resCt.newInstance(valueArgs);
     if (info != null) {
       if (info.icon != 0) {
         Drawable icon = res.getDrawable(info.icon);
         return icon;
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
コード例 #5
0
  @Test
  @org.robolectric.annotation.Config(
      sdk = {
        Build.VERSION_CODES.JELLY_BEAN_MR1,
        Build.VERSION_CODES.JELLY_BEAN_MR2,
        Build.VERSION_CODES.KITKAT,
        Build.VERSION_CODES.LOLLIPOP
      })
  public void shouldCreateMutableBitmapWithDisplayMetrics() throws Exception {
    final DisplayMetrics metrics = new DisplayMetrics();
    metrics.densityDpi = 1000;

    final Bitmap bitmap = Bitmap.createBitmap(metrics, 100, 100, Config.ARGB_8888);
    assertThat(bitmap.isMutable()).isTrue();
    assertThat(bitmap.getDensity()).isEqualTo(1000);
  }
コード例 #6
0
  public void updateLayoutParams(boolean inDialog) {
    LayoutParams layoutParams = getLayoutParams();
    DisplayMetrics metrics = getDisplayMetrics(getContext());
    log.debug("Maximum display resolution: {} X {}\n", metrics.widthPixels, metrics.heightPixels);
    if (inDialog) {
      metrics.widthPixels -= 40;
      metrics.heightPixels -= 40;
    }
    int[] params = getDisplayParameters(metrics.widthPixels, metrics.heightPixels);
    layoutParams.width = params[0];
    layoutParams.height = params[1];
    setLayoutParams(layoutParams);

    if (showing)
      nativeResize(metrics.widthPixels, metrics.heightPixels, params[0], params[1], 0, 0);
    else initDrawer(metrics.widthPixels, metrics.heightPixels, params[0], params[1], 0, 0);
  }
コード例 #7
0
ファイル: LoginActivity.java プロジェクト: kyeah/Revibe
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidProperties.init(this);

    // Set pixel density based on Android device
    DisplayMetrics metrics = new DisplayMetrics();
    try {
      WindowManager winMgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
      winMgr.getDefaultDisplay().getMetrics(metrics);
    } catch (Exception e) {
      metrics.density = 1;
    }

    AndroidProperties.set("pixel_density", String.valueOf(metrics.density), this);

    loginWithFacebook();
  }
コード例 #8
0
 protected void updateBackground(URI uri) {
   Log.d(TAG, "uri" + uri);
   Log.d(TAG, "metrics" + mMetrics.toString());
   Picasso.with(getActivity())
       .load(uri.toString())
       .resize(mMetrics.widthPixels, mMetrics.heightPixels)
       .error(mDefaultBackground)
       .into(mBackgroundTarget);
 }
コード例 #9
0
  @Implementation
  public DisplayMetrics getDisplayMetrics() {
    if (displayMetrics == null) {
      if (display == null) {
        display = Robolectric.newInstanceOf(Display.class);
      }

      displayMetrics = new DisplayMetrics();
      display.getMetrics(displayMetrics);
    }
    displayMetrics.density = this.density;
    return displayMetrics;
  }
コード例 #10
0
ファイル: ApkUtils.java プロジェクト: Kcwind/root-tools
  public static Drawable getIconFromPackage(Context context, String archiveFilePath) {
    PackageParser packageParser = new PackageParser(archiveFilePath);
    File sourceFile = new File(archiveFilePath);
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.setToDefaults();
    PackageParser.Package pkg = packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);
    if (pkg == null) {
      return context.getResources().getDrawable(R.drawable.android);
    }
    ApplicationInfo info = pkg.applicationInfo;

    Resources pRes = context.getResources();
    AssetManager assmgr = new AssetManager();
    assmgr.addAssetPath(archiveFilePath);
    Resources res = new Resources(assmgr, pRes.getDisplayMetrics(), pRes.getConfiguration());

    if (info.icon != 0) {
      Drawable icon = res.getDrawable(info.icon);
      return icon;
    } else {
      return context.getResources().getDrawable(R.drawable.android);
    }
  }
コード例 #11
0
ファイル: ApkUtils.java プロジェクト: cwj10/toolbox
  /**
   * 判断一个文件存在且apk完整有效
   *
   * @return true 完整有效
   */
  public static boolean isEffectiveApk(String archiveFilePath, Context activity) {
    try {
      String PATH_PackageParser = "android.content.pm.PackageParser";
      Class pkgParserCls = Class.forName(PATH_PackageParser);
      Class[] typeArgs = new Class[1];
      typeArgs[0] = String.class;
      Constructor pkgParserCt = pkgParserCls.getConstructor(typeArgs);
      Object[] valueArgs = new Object[1];
      valueArgs[0] = archiveFilePath;
      Object pkgParser = pkgParserCt.newInstance(valueArgs);
      DisplayMetrics metrics = new DisplayMetrics();
      metrics.setToDefaults();

      final File sourceFile = new File(archiveFilePath);
      typeArgs = new Class[4];
      typeArgs[0] = File.class;
      typeArgs[1] = String.class;
      typeArgs[2] = DisplayMetrics.class;
      typeArgs[3] = Integer.TYPE;
      // PackageParser.parsePackage();
      Method pkgParser_parsePackageMtd = pkgParserCls.getDeclaredMethod("parsePackage", typeArgs);
      valueArgs = new Object[4];
      valueArgs[0] = sourceFile;
      valueArgs[1] = archiveFilePath;
      valueArgs[2] = metrics;
      valueArgs[3] = 0;
      // PackageParser.Package
      Object pkgParserPkg = pkgParser_parsePackageMtd.invoke(pkgParser, valueArgs);
      if (pkgParserPkg == null) {
        return false;
      } else {
        return true;
      }
    } catch (Exception e) {
      return false;
    }
  }
コード例 #12
0
  private static void setDisplayMetrics(Context context) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics);

    DisplayMetrics screenDisplayMetrics = new DisplayMetrics();
    screenDisplayMetrics.setTo(displayMetrics);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    // Get the real display metrics if we are using API level 17 or higher.
    // The real metrics include system decor elements (e.g. soft menu bar).
    //
    // See:
    // http://developer.android.com/reference/android/view/Display.html#getRealMetrics(android.util.DisplayMetrics)
    if (Build.VERSION.SDK_INT >= 17) {
      display.getRealMetrics(screenDisplayMetrics);
    } else {
      // For 14 <= API level <= 16, we need to invoke getRawHeight and getRawWidth to get the real
      // dimensions.
      // Since react-native only supports API level 16+ we don't have to worry about other cases.
      //
      // Reflection exceptions are rethrown at runtime.
      //
      // See:
      // http://stackoverflow.com/questions/14341041/how-to-get-real-screen-height-and-width/23861333#23861333
      try {
        Method mGetRawH = Display.class.getMethod("getRawHeight");
        Method mGetRawW = Display.class.getMethod("getRawWidth");
        screenDisplayMetrics.widthPixels = (Integer) mGetRawW.invoke(display);
        screenDisplayMetrics.heightPixels = (Integer) mGetRawH.invoke(display);
      } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
        throw new RuntimeException("Error getting real dimensions for API level < 17", e);
      }
    }
    DisplayMetricsHolder.setScreenDisplayMetrics(screenDisplayMetrics);
  }
コード例 #13
0
    private void createWindow() {
      LayoutInflater inflater = LayoutInflater.from(mContext);

      mWindowContent = inflater.inflate(R.layout.overlay_display_window, null);
      mWindowContent.setOnTouchListener(mOnTouchListener);

      mTextureView = (TextureView) mWindowContent.findViewById(R.id.overlay_display_window_texture);
      mTextureView.setPivotX(0);
      mTextureView.setPivotY(0);
      mTextureView.getLayoutParams().width = mWidth;
      mTextureView.getLayoutParams().height = mHeight;
      mTextureView.setOpaque(false);
      mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);

      mNameTextView = (TextView) mWindowContent.findViewById(R.id.overlay_display_window_title);
      mNameTextView.setText(mName);

      mWindowParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
      mWindowParams.flags |=
          WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
              | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
              | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
              | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
              | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
      if (DISABLE_MOVE_AND_RESIZE) {
        mWindowParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
      }
      mWindowParams.alpha = WINDOW_ALPHA;
      mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
      mWindowParams.setTitle(mName);

      mGestureDetector = new GestureDetector(mContext, mOnGestureListener);
      mScaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);

      // Set the initial position and scale.
      // The position and scale will be clamped when the display is first shown.
      mWindowX = (mGravity & Gravity.LEFT) == Gravity.LEFT ? 0 : mDefaultDisplayMetrics.widthPixels;
      mWindowY = (mGravity & Gravity.TOP) == Gravity.TOP ? 0 : mDefaultDisplayMetrics.heightPixels;
      Log.d(TAG, mDefaultDisplayMetrics.toString());
      mWindowScale = INITIAL_SCALE;

      // calculate and save initial settings
      updateWindowParams();
      saveWindowParams();
    }
コード例 #14
0
  @Test
  public void testPropertiesResetToDefault() {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    displayMetrics.density = 1.0f;
    DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics);

    LayoutShadowNode reactShadowNode = spy(new LayoutShadowNode());
    ReactStylesDiffMap map =
        buildStyles(
            "width", 10.0,
            "height", 10.0,
            "left", 10.0,
            "top", 10.0,
            "flex", 1.0,
            "padding", 10.0,
            "marginLeft", 10.0,
            "borderTopWidth", 10.0,
            "flexDirection", "row",
            "alignSelf", "stretch",
            "alignItems", "center",
            "justifyContent", "space_between",
            "position", "absolute");

    reactShadowNode.updateProperties(map);
    verify(reactShadowNode).setStyleWidth(10.f);
    verify(reactShadowNode).setStyleHeight(10.f);
    verify(reactShadowNode).setPositionLeft(10.f);
    verify(reactShadowNode).setPositionTop(10.f);
    verify(reactShadowNode).setFlex(1.0f);
    verify(reactShadowNode).setPadding(Spacing.ALL, 10.f);
    verify(reactShadowNode).setMargin(Spacing.LEFT, 10.f);
    verify(reactShadowNode).setBorder(Spacing.TOP, 10.f);
    verify(reactShadowNode).setFlexDirection(CSSFlexDirection.ROW);
    verify(reactShadowNode).setAlignSelf(CSSAlign.STRETCH);
    verify(reactShadowNode).setAlignItems(CSSAlign.CENTER);
    verify(reactShadowNode).setJustifyContent(CSSJustify.SPACE_BETWEEN);
    verify(reactShadowNode).setPositionType(CSSPositionType.ABSOLUTE);

    map =
        buildStyles(
            "width", null,
            "height", null,
            "left", null,
            "top", null,
            "flex", null,
            "padding", null,
            "marginLeft", null,
            "borderTopWidth", null,
            "flexDirection", null,
            "alignSelf", null,
            "alignItems", null,
            "justifyContent", null,
            "position", null);

    reset(reactShadowNode);
    reactShadowNode.updateProperties(map);
    verify(reactShadowNode).setStyleWidth(CSSConstants.UNDEFINED);
    verify(reactShadowNode).setStyleHeight(CSSConstants.UNDEFINED);
    verify(reactShadowNode).setPositionLeft(CSSConstants.UNDEFINED);
    verify(reactShadowNode).setPositionTop(CSSConstants.UNDEFINED);
    verify(reactShadowNode).setFlex(0.f);
    verify(reactShadowNode).setPadding(Spacing.ALL, CSSConstants.UNDEFINED);
    verify(reactShadowNode).setMargin(Spacing.LEFT, CSSConstants.UNDEFINED);
    verify(reactShadowNode).setBorder(Spacing.TOP, CSSConstants.UNDEFINED);
    verify(reactShadowNode).setFlexDirection(CSSFlexDirection.COLUMN);
    verify(reactShadowNode).setAlignSelf(CSSAlign.AUTO);
    verify(reactShadowNode).setAlignItems(CSSAlign.STRETCH);
    verify(reactShadowNode).setJustifyContent(CSSJustify.FLEX_START);
    verify(reactShadowNode).setPositionType(CSSPositionType.RELATIVE);
  }
  /**
   * Initializes and acquires the scene, creating various Android objects such as context, inflater,
   * and parser.
   *
   * @param timeout the time to wait if another rendering is happening.
   * @return whether the scene was prepared
   * @see #acquire(long)
   * @see #release()
   */
  public Result init(long timeout) {
    // acquire the lock. if the result is null, lock was just acquired, otherwise, return
    // the result.
    Result result = acquireLock(timeout);
    if (result != null) {
      return result;
    }

    // setup the ParserFactory
    ParserFactory.setParserFactory(mParams.getLayoutlibCallback().getParserFactory());

    HardwareConfig hardwareConfig = mParams.getHardwareConfig();

    // setup the display Metrics.
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.densityDpi = metrics.noncompatDensityDpi = hardwareConfig.getDensity().getDpiValue();

    metrics.density =
        metrics.noncompatDensity = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;

    metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density;

    metrics.widthPixels = metrics.noncompatWidthPixels = hardwareConfig.getScreenWidth();
    metrics.heightPixels = metrics.noncompatHeightPixels = hardwareConfig.getScreenHeight();
    metrics.xdpi = metrics.noncompatXdpi = hardwareConfig.getXdpi();
    metrics.ydpi = metrics.noncompatYdpi = hardwareConfig.getYdpi();

    RenderResources resources = mParams.getResources();

    // build the context
    mContext =
        new BridgeContext(
            mParams.getProjectKey(),
            metrics,
            resources,
            mParams.getAssets(),
            mParams.getLayoutlibCallback(),
            getConfiguration(),
            mParams.getTargetSdkVersion(),
            mParams.isRtlSupported());

    setUp();

    return SUCCESS.createResult();
  }
コード例 #16
0
 @DSModeled(DSC.SAFE)
 public void setTo(DisplayMetrics o) {
   addTaint(o.getTaint());
 }
コード例 #17
0
 public void setDensity(float density) {
   this.density = density;
   if (displayMetrics != null) {
     displayMetrics.density = density;
   }
 }
  private void getMetricsWithSize(
      DisplayMetrics outMetrics,
      CompatibilityInfo compatInfo,
      Configuration configuration,
      int width,
      int height) {
    outMetrics.densityDpi = outMetrics.noncompatDensityDpi = logicalDensityDpi;
    outMetrics.density =
        outMetrics.noncompatDensity = logicalDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
    outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density;
    outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi;
    outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi;

    width =
        (configuration != null
                && configuration.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED)
            ? (int) ((configuration.screenWidthDp * outMetrics.density) + 0.5f)
            : width;
    height =
        (configuration != null
                && configuration.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED)
            ? (int) ((configuration.screenHeightDp * outMetrics.density) + 0.5f)
            : height;

    outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width;
    outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height;

    if (!compatInfo.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) {
      compatInfo.applyToDisplayMetrics(outMetrics);
    }
  }
コード例 #19
0
 private boolean isConfigurationStillValid() {
   DisplayMetrics dm = new DisplayMetrics();
   mDisplay.getMetrics(dm);
   return dm.equalsPhysical(getResources().getDisplayMetrics());
 }