Skip to content

Commit

Permalink
フラッシュ点灯を Android 6.0 API にしたけど,Redmi Note 3Pro ではフラッシュが高速点灯できないようで意味な…
Browse files Browse the repository at this point in the history
…かった(;´д⊂)
  • Loading branch information
yoshinrt committed Jun 29, 2018
1 parent 863714a commit e2888f9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
Empty file modified vsdroid/.idea/.name
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion vsdroid/.idea/gradle.xml
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file modified vsdroid/.idea/runConfigurations.xml
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions vsdroid/vsdroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.dds.vsdroid"
android:versionCode="984"
android:versionName="r984" >
android:versionCode="956"
android:versionName="r956" >

<uses-sdk
android:minSdkVersion="10"
Expand Down
47 changes: 32 additions & 15 deletions vsdroid/vsdroid/src/main/java/jp/dds/vsdroid/Vsdroid.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import android.graphics.PorterDuff.Mode;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.hardware.camera2.CameraManager;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
Expand Down Expand Up @@ -66,20 +68,17 @@ public class Vsdroid extends Activity {
SharedPreferences Pref;

// カメラ
Camera Cam = null;
Camera.Parameters CamParam;
private Camera Cam = null;
private Camera.Parameters CamParam;
private CameraManager CamMgr = null;
private String CamID = null;

boolean bRevWarn = false;
boolean bEcoMode = false;
boolean bDebugInfo = false;

int iBattery = 100;

enum FLASH_STATE {
OFF,
ON,
BLINK,
};

//*** utils **************************************************************

void Sleep( int ms ){
Expand All @@ -88,15 +87,20 @@ void Sleep( int ms ){

//*** カメラフラッシュ設定 ***********************************************

public void SetFlash( FLASH_STATE Switch ){
if( Cam != null ){
public void SetFlash( boolean sw ){

if( Build.VERSION.SDK_INT >= 23 ){
if( CamID != null ){
try{ CamMgr.setTorchMode( CamID, sw ); }catch( android.hardware.camera2.CameraAccessException e ){}
}
}else if( Cam != null ){
// フラッシュモードを設定
CamParam.setFlashMode(
bRevWarn && Switch == FLASH_STATE.ON ?
sw ?
Camera.Parameters.FLASH_MODE_TORCH :
Camera.Parameters.FLASH_MODE_OFF
);

// パラメータを設定
Cam.setParameters( CamParam );
}
Expand Down Expand Up @@ -520,7 +524,7 @@ private void Draw(){
}

// フラッシュライト
SetFlash( iTachoBar > 0 ? FLASH_STATE.ON : FLASH_STATE.OFF );
SetFlash( bRevWarn && iTachoBar > 0 );

// メーターパネル
paint.setTypeface( Typeface.DEFAULT_BOLD );
Expand Down Expand Up @@ -841,7 +845,20 @@ protected void onResume() {
super.onResume();

// カメラ (フラッシュ) オープン
if( Cam == null && ( Cam = Camera.open()) != null ){
if( Build.VERSION.SDK_INT >= 23 ){
if( CamMgr == null ){
CamMgr = ( CameraManager )getSystemService( Context.CAMERA_SERVICE );
CamMgr.registerTorchCallback( new CameraManager.TorchCallback(){
//トーチモードが変更された時の処理
@Override
public void onTorchModeChanged( String cameraId, boolean enabled ){
super.onTorchModeChanged( cameraId, enabled );
//カメラIDをセット
CamID = cameraId;
}
}, new Handler());
}
}else if( Cam == null && ( Cam = Camera.open()) != null ){
CamParam = Cam.getParameters(); //カメラのパラメータを取得
Cam.startPreview(); //プレビューをしないと光らない
}
Expand All @@ -857,7 +874,7 @@ protected void onStop() {
if( bDebug ) Log.d( "VSDroid", "onStop" );
super.onStop();

SetFlash( FLASH_STATE.OFF );
SetFlash( false );
if( Cam != null ) Cam.release();
Cam = null;
}
Expand Down

0 comments on commit e2888f9

Please sign in to comment.