コード例 #1
1
  //  @TargetApi(5)
  // TODO find out why the above is not working and I need to use SupressLint to get rid of the
  // error
  @SuppressLint("newApi")
  public void disableRotation() {
    switch (activity.getResources().getConfiguration().orientation) {
      case Configuration.ORIENTATION_PORTRAIT:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
          activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {
          int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
          if (rotation == android.view.Surface.ROTATION_90
              || rotation == android.view.Surface.ROTATION_180) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
          } else {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
          }
        }
        break;

      case Configuration.ORIENTATION_LANDSCAPE:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
          activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
          int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
          if (rotation == android.view.Surface.ROTATION_0
              || rotation == android.view.Surface.ROTATION_90) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
          } else {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
          }
        }
        break;
    } // switch
  }
コード例 #2
1
 /** 获取屏幕分辨率 */
 public static int getResolution(Activity act) {
   int Width = 0;
   int Height = 0;
   Width = act.getWindowManager().getDefaultDisplay().getWidth();
   Height = act.getWindowManager().getDefaultDisplay().getHeight();
   return Width * Height;
 }
コード例 #3
1
ファイル: BlurDialogUtil.java プロジェクト: clouse/gamedemo
  public static Bitmap takeScreenShot(Activity activity, View viewFragment) {
    // View是你需要截图的View
    View view = activity.getWindow().getDecorView();
    if (view == null) {
      System.out.println("view is null");
    } else {
      System.out.println("view:" + view.toString());
    }
    // View view = viewFragment;
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap b1 = view.getDrawingCache();

    // 获取状态栏高度
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;

    // 获取屏幕长和高
    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay().getHeight();
    Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return b;
  }
コード例 #4
0
 public static DisplayMetrics a(Activity activity) {
   if (activity.getWindowManager() == null) {
     return null;
   }
   DisplayMetrics displayMetrics = new DisplayMetrics();
   activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
   return displayMetrics;
 }
コード例 #5
0
 @SuppressLint("NewApi")
 private float getSmallestWidthDp(Activity activity) {
   DisplayMetrics metrics = new DisplayMetrics();
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
     activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
   } else {
     activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
   }
   float widthDp = metrics.widthPixels / metrics.density;
   float heightDp = metrics.heightPixels / metrics.density;
   return Math.min(widthDp, heightDp);
 }
コード例 #6
0
  public static void setCameraDisplayOrientation(
      Activity activity, int cameraId, android.hardware.Camera camera) {
    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
      case Surface.ROTATION_0:
        degrees = 0;
        break;
      case Surface.ROTATION_90:
        degrees = 90;
        break;
      case Surface.ROTATION_180:
        degrees = 180;
        break;
      case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
      result = (info.orientation + degrees) % 360;
      result = (360 - result) % 360; // compensate the mirror
    } else { // back-facing
      result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
  }
コード例 #7
0
ファイル: ToolBox.java プロジェクト: techlung/GlowAndroid
  public static int getScreenHeightPx(Activity activity) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int heightPx = metrics.heightPixels;
    return heightPx;
  }
コード例 #8
0
  public CacheListAdapter(
      final Activity activity, final List<cgCache> list, CacheListType cacheListType) {
    super(activity, 0, list);

    this.res = activity.getResources();
    this.list = list;
    this.cacheListType = cacheListType;
    if (cacheListType == CacheListType.HISTORY) {
      cacheComparator = new VisitComparator();
    }

    final DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    pixelDensity = metrics.density;

    for (final CacheType cacheType : CacheType.values()) {
      gcIconDrawables.put(
          cacheType, activity.getResources().getDrawable(cgBase.getCacheIcon(cacheType)));
    }

    if (Settings.isLightSkin()) {
      ratingBcgs[0] = R.drawable.favourite_background_red_light;
      ratingBcgs[1] = R.drawable.favourite_background_orange_light;
      ratingBcgs[2] = R.drawable.favourite_background_green_light;
    } else {
      ratingBcgs[0] = R.drawable.favourite_background_red_dark;
      ratingBcgs[1] = R.drawable.favourite_background_orange_dark;
      ratingBcgs[2] = R.drawable.favourite_background_green_dark;
    }
  }
コード例 #9
0
ファイル: WH.java プロジェクト: JekoShih/Test
 // Width & Height
 public static void getDisplayMetrics(Activity activity) {
   DisplayMetrics dm = new DisplayMetrics();
   activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
   Width = dm.widthPixels;
   Height = dm.heightPixels;
   Log.e("CTC", Width + "" + Height);
 }
コード例 #10
0
  public KamoflageLayout(
      Kamoflage.Widget _kContainer,
      String _title,
      Context context,
      boolean _horizontal,
      boolean _framed,
      boolean _scrollable) {
    super(context);

    kContainerParent = _kContainer;

    framed = _framed;
    scrollable = _scrollable;

    Activity act = (Activity) context;
    if (act != null) {
      WindowManager wm = act.getWindowManager();
      Display d = wm.getDefaultDisplay();
      screen_w = d.getWidth();
      screen_h = d.getHeight();
    }

    if (framed) {
      frame_view = new KamoflageLayoutFrame(context, _title);
      super.addView(frame_view);
      frame_view.setVisibility(View.VISIBLE);
    }

    title = _title;

    contained = new Vector<Contained>();
    expanded = new Vector<Contained>();

    horizontal = _horizontal;
  }
コード例 #11
0
  /*
   * The whole point of this class is to get a smaller image from a larger one
   */
  @SuppressWarnings("deprecation")
  public static BitmapDrawable getScaledDrawable(Activity a, String path) {
    Display display = a.getWindowManager().getDefaultDisplay();
    float destWidth = display.getWidth();
    float destHeight = display.getHeight();

    // read in the dimensions of the image on the disk
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);

    float srcWidth = options.outWidth;
    float srcHeight = options.outHeight;

    int inSampleSize = 1;
    if (srcHeight > destHeight || srcWidth > destWidth) {
      if (srcWidth > srcHeight) {
        inSampleSize = Math.round(srcHeight / destHeight);
      } else {
        inSampleSize = Math.round(srcWidth / destWidth);
      }
    }
    options = new BitmapFactory.Options();
    options.inSampleSize = inSampleSize;

    Bitmap bitmap = BitmapFactory.decodeFile(path, options);

    return new BitmapDrawable(a.getResources(), bitmap);
  }
コード例 #12
0
  @Override
  public Object instantiateItem(View pager, int pos) {

    DisplayMetrics displayMetrics = new DisplayMetrics();
    mActivty.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int screenWidth = displayMetrics.widthPixels;

    Bitmap bitmap = moviePosters.get(pos);
    View view = View.inflate(mActivty, R.layout.movieposter_viewpage_item, null);
    ImageView imageViewMoviePoster = (ImageView) view.findViewById(R.id.imageview_movieposter);

    imageViewMoviePoster.setScaleType(ImageView.ScaleType.FIT_CENTER);

    double height =
        (double) (screenWidth * ((double) bitmap.getHeight() / (double) bitmap.getWidth()));
    bitmap = Bitmap.createScaledBitmap(bitmap, screenWidth, (int) height, true);
    imageViewMoviePoster.getLayoutParams().height = (int) height;
    imageViewMoviePoster.getLayoutParams().width = screenWidth;
    imageViewMoviePoster.setImageBitmap(bitmap);

    /*imageLoader.DisplayImage(dramas.get(position).getPosterUrl(), imageViewMoviePoster);*/

    ((ViewPager) pager)
        .addView(
            view,
            ((ViewPager) pager).getChildCount() > pos ? pos : ((ViewPager) pager).getChildCount());

    return view;
  }
コード例 #13
0
ファイル: BitmapUtil.java プロジェクト: lszbd/BD
  /**
   * 处理大图片工具方法,避免 OOM
   *
   * @param imgPath : 图片路径
   * @return : 返回缩放后的图片
   */
  @SuppressWarnings("deprecation")
  public static Bitmap zoomBitmap(Activity activity, String imgPath) {
    //  1. 获取屏幕的宽高信息
    WindowManager windowManager = activity.getWindowManager();
    int width = windowManager.getDefaultDisplay().getWidth();
    int height = windowManager.getDefaultDisplay().getHeight();
    //      	System.out.println("屏幕的宽 = " + width + "   高 = " + height);

    //  2.获取图片的宽高
    Options options = new BitmapFactory.Options(); // 解析位图的附加条件
    options.inJustDecodeBounds = true; // 只解析位图的头文件信息(图片的附加信息)
    BitmapFactory.decodeFile(imgPath, options);
    int bitmapWidth = options.outWidth;
    int bitmapHeight = options.outHeight;
    //      	System.out.println("图片的宽 = " + bitmapWidth + "   高 = " + bitmapHeight);

    //  3.计算图片的缩放比例
    int dx = bitmapWidth / width;
    int dy = bitmapHeight / height;

    int scale = 1;
    if (dx > dy && dy > 1) {
      scale = dx;
      //          System.out.println("按照水平方向绽放,缩放比例 = " + dx);
    }
    if (dy > dx && dx > 1) {
      scale = dy;
      //          System.out.println("按照垂直方法缩放,缩放比例 = " + dy);
    }

    //  4.返回缩放后的位图给调用者
    options.inSampleSize = scale;
    options.inJustDecodeBounds = false; // 解析全部图片
    return BitmapFactory.decodeFile(imgPath, options);
  }
コード例 #14
0
 /**
  * Stores all data from DisplayMetrics and translates dimensions into density-independent pixels.
  * Must be called once before getting data.
  *
  * @param activity the current activity
  */
 public static void update(Activity activity) {
   orientation = activity.getResources().getConfiguration().orientation;
   DisplayMetrics displayMetrics = new DisplayMetrics();
   activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
   density = displayMetrics.density;
   densityDpi = displayMetrics.densityDpi;
   widthPx = displayMetrics.widthPixels;
   heightPx = displayMetrics.heightPixels;
   updateDp();
   Log.d(
       MetricsUtil.class.getSimpleName(),
       "Orientation: "
           + nameForOrientation(orientation)
           + "\nWidth (px): "
           + widthPx
           + ", Height (px): "
           + heightPx
           + "\nDPI: "
           + densityDpi
           + ", "
           + "Density Factor: "
           + density
           + "\nWidth (dp): "
           + widthDp
           + ", Height (dp): "
           + heightDp);
 }
コード例 #15
0
  public static Bitmap getScaledBitmap(String path, Activity activity) {
    Point size = new Point();

    activity.getWindowManager().getDefaultDisplay().getSize(size);

    return getScaledBitmap(path, size.x, size.y);
  }
コード例 #16
0
 public void printscreen_share(View v, Activity context) {
   View view1 = context.getWindow().getDecorView();
   Display display = context.getWindowManager().getDefaultDisplay();
   view1.layout(0, 0, display.getWidth(), display.getHeight());
   view1.setDrawingCacheEnabled(true);
   Bitmap bitmap = Bitmap.createBitmap(view1.getDrawingCache());
 }
コード例 #17
0
 public static float getDirectionNow(final float directionNowPre, final Activity activity) {
   if (isLevel8) {
     try {
       final int rotation = level8.getRotation(activity);
       if (rotation == Surface.ROTATION_90) {
         return directionNowPre + 90;
       } else if (rotation == Surface.ROTATION_180) {
         return directionNowPre + 180;
       } else if (rotation == Surface.ROTATION_270) {
         return directionNowPre + 270;
       }
     } catch (final Exception e) {
       // This should never happen: IllegalArgumentException, IllegalAccessException or
       // InvocationTargetException
       Log.e(Settings.tag, "Cannot call getRotation()", e);
     }
   } else {
     final Display display = activity.getWindowManager().getDefaultDisplay();
     final int rotation = display.getOrientation();
     if (rotation == Configuration.ORIENTATION_LANDSCAPE) {
       return directionNowPre + 90;
     }
   }
   return directionNowPre;
 }
コード例 #18
0
ファイル: Utils.java プロジェクト: cbedoy/MyBudget
  public static Bitmap takeScreenShot(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap drawingCache = view.getDrawingCache();
    Rect rect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
    int statusBarHeight = rect.top;
    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay().getHeight();

    Bitmap bitmap =
        Bitmap.createBitmap(drawingCache, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return bitmap;
  }
コード例 #19
0
ファイル: ToolBox.java プロジェクト: techlung/GlowAndroid
  public static int getScreenWidthPx(Activity activity) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int widthPx = metrics.widthPixels;
    return widthPx;
  }
コード例 #20
0
ファイル: Util.java プロジェクト: AOrobator/BernieAppAndroid
 public static int[] getScreenWidthHeight(Activity ctx) {
   DisplayMetrics metrics = new DisplayMetrics();
   ctx.getWindowManager().getDefaultDisplay().getMetrics(metrics);
   int width = Math.round(metrics.widthPixels / metrics.density) - 24;
   int height = Math.round(metrics.heightPixels / metrics.density) / 3;
   return new int[] {width, height};
 }
コード例 #21
0
 public static void screenInfo(Activity activity) {
   DisplayMetrics dm = new DisplayMetrics();
   activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
   screenW = dm.widthPixels;
   screenH = dm.heightPixels;
   Log.e("screenW:", screenW + ",screenH:" + screenH);
 }
コード例 #22
0
  public kehu_gengxinshijianPopWindow(final Activity context) {
    this.context = context;
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    conentView = inflater.inflate(R.layout.crm_kehu_gengxinshijian, null);
    int h = context.getWindowManager().getDefaultDisplay().getHeight();
    int w = context.getWindowManager().getDefaultDisplay().getWidth();
    // 设置SelectPicPopupWindow的View
    this.setContentView(conentView);
    // 设置SelectPicPopupWindow弹出窗体的宽
    // this.setWidth(w / 2 + 50);
    this.setWidth(w / 2);
    // 设置SelectPicPopupWindow弹出窗体的高
    this.setHeight(LayoutParams.WRAP_CONTENT);
    // 设置SelectPicPopupWindow弹出窗体可点击
    this.setFocusable(true);
    this.setOutsideTouchable(true);
    // 刷新状态
    this.update();
    // 实例化一个ColorDrawable颜色为半透明
    ColorDrawable dw = new ColorDrawable(0000000000);
    // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作
    this.setBackgroundDrawable(dw);
    // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
    // 设置SelectPicPopupWindow弹出窗体动画效果

    // this.setAnimationStyle(R.style.AnimationPreview);
    l1 = (LinearLayout) conentView.findViewById(R.id.l1);
    l2 = (LinearLayout) conentView.findViewById(R.id.l2);
    l3 = (LinearLayout) conentView.findViewById(R.id.l3);
    l1.setOnTouchListener(this);
    l2.setOnTouchListener(this);
    l3.setOnTouchListener(this);
  }
コード例 #23
0
  private static boolean isTablet(Context activityContext) {
    // http://stackoverflow.com/questions/5832368/tablet-or-phone-android

    // Verifies if the Generalized Size of the device is XLARGE to be
    // considered a Tablet
    boolean xlarge =
        ((activityContext.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
            == Configuration.SCREENLAYOUT_SIZE_XLARGE);

    // If XLarge, checks if the Generalized Density is at least MDPI
    // (160dpi)
    if (xlarge) {
      DisplayMetrics metrics = new DisplayMetrics();
      Activity activity = (Activity) activityContext;
      activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

      // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
      // DENSITY_TV=213, DENSITY_XHIGH=320
      if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
          || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
          || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
          || metrics.densityDpi == DisplayMetrics.DENSITY_TV
          || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {

        // Yes, this is a tablet!
        return true;
      }
    }

    // No, this is not a tablet!
    return false;
  }
コード例 #24
0
ファイル: Utils.java プロジェクト: Gracker/droidMock
  public static int getDensity(Activity activity) {

    Display display = activity.getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);
    return outMetrics.densityDpi;
  }
コード例 #25
0
 /**
  * Configures the necessary {@link Matrix} transformation to `mTextureView`. This method should be
  * called after the camera preview size is determined in setUpCameraOutputs and also the size of
  * `mTextureView` is fixed.
  *
  * @param viewWidth The width of `mTextureView`
  * @param viewHeight The height of `mTextureView`
  */
 private void configureTransform(int viewWidth, int viewHeight) {
   Activity activity = getActivity();
   if (null == mTextureView || null == mPreviewSize || null == activity) {
     return;
   }
   int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
   Matrix matrix = new Matrix();
   RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
   RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
   float centerX = viewRect.centerX();
   float centerY = viewRect.centerY();
   if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
     bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
     matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
     float scale =
         Math.max(
             (float) viewHeight / mPreviewSize.getHeight(),
             (float) viewWidth / mPreviewSize.getWidth());
     matrix.postScale(scale, scale, centerX, centerY);
     matrix.postRotate(90 * (rotation - 2), centerX, centerY);
   } else if (Surface.ROTATION_180 == rotation) {
     matrix.postRotate(180, centerX, centerY);
   }
   mTextureView.setTransform(matrix);
 }
コード例 #26
0
ファイル: CameraHelper.java プロジェクト: lucime/Promfy2
  public int getCameraDisplayOrientation(final Activity activity, final int cameraId) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
      case Surface.ROTATION_0:
        degrees = 0;
        break;
      case Surface.ROTATION_90:
        degrees = 90;
        break;
      case Surface.ROTATION_180:
        degrees = 180;
        break;
      case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    int result;
    CameraInfo2 info = new CameraInfo2();
    getCameraInfo(cameraId, info);
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
      result = (info.orientation + degrees) % 360;
    } else { // back-facing
      result = (info.orientation - degrees + 360) % 360;
    }
    return result;
  }
コード例 #27
0
  private void initData(Context context) {
    this.mContext = context;
    mActivity = (Activity) context;
    DisplayMetrics dm = new DisplayMetrics();
    mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    mDensity = dm.density;
    mWidth = dm.widthPixels;
    mInflater = LayoutInflater.from(mContext);
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_NORMAL);
    if (audioManager.isSpeakerphoneOn()) {
      audioManager.setSpeakerphoneOn(true);
    } else {
      audioManager.setSpeakerphoneOn(false);
    }
    mp.setAudioStreamType(AudioManager.STREAM_RING);
    mp.setOnErrorListener(
        new OnErrorListener() {

          @Override
          public boolean onError(MediaPlayer mp, int what, int extra) {
            return false;
          }
        });
  }
コード例 #28
0
  private String generateAdUrl() {
    StringBuilder sz = new StringBuilder("http://" + MoPubView.HOST + MoPubView.AD_HANDLER);
    sz.append("?v=4&id=" + mAdUnitId);

    String udid = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
    String udidDigest = (udid == null) ? "" : sha1(udid);
    sz.append("&udid=sha:" + udidDigest);

    if (mKeywords != null) sz.append("&q=" + Uri.encode(mKeywords));

    if (mLocation != null) {
      sz.append("&ll=" + mLocation.getLatitude() + "," + mLocation.getLongitude());
    }

    sz.append("&z=" + getTimeZoneOffsetString());

    int orientation = getResources().getConfiguration().orientation;
    String orString = DEVICE_ORIENTATION_UNKNOWN;
    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
      orString = DEVICE_ORIENTATION_PORTRAIT;
    } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
      orString = DEVICE_ORIENTATION_LANDSCAPE;
    } else if (orientation == Configuration.ORIENTATION_SQUARE) {
      orString = DEVICE_ORIENTATION_SQUARE;
    }
    sz.append("&o=" + orString);

    DisplayMetrics metrics = new DisplayMetrics();
    Activity activity = (Activity) getContext();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    sz.append("&sc_a=" + metrics.density);

    return sz.toString();
  }
コード例 #29
0
ファイル: CustomeCamera.java プロジェクト: rasenir/charsoo
  public CustomeCamera(
      Activity activity, FrameLayout cameraPreviewLayout, Integer size, Integer quality)
      throws Exception {
    this.activity = activity;
    this.size = size;
    this.quality = quality;

    // Create an instance of Camera
    try {
      mCamera = getCameraInstance();
    } catch (Exception e) {
      throw new Exception(e.getMessage());
    }
    try {
      mCamera.setDisplayOrientation(90);
    } catch (Exception e) {
      Log.d(TAG, e.getMessage());
    }

    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
      case Surface.ROTATION_0:
        degrees = 0;
        break; // Natural orientation
      case Surface.ROTATION_90:
        degrees = 90;
        break; // Landscape left
      case Surface.ROTATION_180:
        degrees = 180;
        break; // Upside down
      case Surface.ROTATION_270:
        degrees = 270;
        break; // Landscape right
    }
    int rotate = (info.orientation - degrees + 360) % 360;

    // STEP #2: Set the 'rotation' parameter
    Camera.Parameters params = mCamera.getParameters();
    params.setRotation(rotate);

    List<String> focusModes = params.getSupportedFocusModes();
    if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    }
    if (params.getFocusMode() == Camera.Parameters.FOCUS_MODE_AUTO) autoFocusEnabled = true;
    else autoFocusEnabled = false;

    // TODO for the test
    autoFocusEnabled = false;

    mCamera.setParameters(params);

    // Create our Preview view and set it as the content of our activity.
    mPreview = new CameraPreview(activity, mCamera);
    cameraPreviewLayout.addView(mPreview);
  }
コード例 #30
0
 private static void prepareResources(Context context) {
   if (mMetrics != null) return;
   mMetrics = new DisplayMetrics();
   Activity act = (Activity) context;
   act.getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
   AssetManager mgr = context.getAssets();
   mResources = new Resources(mgr, mMetrics, context.getResources().getConfiguration());
 }