mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-06-05 21:59:19 +02:00
some refactoring, no functionality change
This commit is contained in:
@ -20,7 +20,7 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".activities.MainActivity"
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
@ -30,12 +30,12 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".AboutActivity"
|
android:name=".activities.AboutActivity"
|
||||||
android:label="@string/about"
|
android:label="@string/about"
|
||||||
android:screenOrientation="portrait"/>
|
android:screenOrientation="portrait"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".LicenseActivity"
|
android:name=".activities.LicenseActivity"
|
||||||
android:label="@string/third_party_licences"
|
android:label="@string/third_party_licences"
|
||||||
android:screenOrientation="portrait"/>
|
android:screenOrientation="portrait"/>
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
public class MarshmallowCamera {
|
public class MarshmallowCamera {
|
||||||
private static final String TAG = MyCameraImpl.class.getSimpleName();
|
private static final String TAG = MyCameraImpl.class.getSimpleName();
|
||||||
|
|
||||||
private MyCamera mCallback;
|
private MyCamera mCallback;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
|
@ -6,26 +6,27 @@ import android.util.Log;
|
|||||||
|
|
||||||
public class MyCameraImpl {
|
public class MyCameraImpl {
|
||||||
private static final String TAG = MyCameraImpl.class.getSimpleName();
|
private static final String TAG = MyCameraImpl.class.getSimpleName();
|
||||||
private Camera camera;
|
private static Camera mCamera;
|
||||||
private Camera.Parameters params;
|
private static Camera.Parameters mParams;
|
||||||
private boolean isFlashlightOn;
|
private static MyCamera mCallback;
|
||||||
private MyCamera callback;
|
private static Context mContext;
|
||||||
private Context context;
|
private static MarshmallowCamera mMarshmallowCamera;
|
||||||
private boolean isMarshmallow;
|
|
||||||
private MarshmallowCamera marshmallowCamera;
|
private static boolean mIsFlashlightOn;
|
||||||
|
private static boolean mIsMarshmallow;
|
||||||
|
|
||||||
public MyCameraImpl(MyCamera camera, Context cxt) {
|
public MyCameraImpl(MyCamera camera, Context cxt) {
|
||||||
callback = camera;
|
mCallback = camera;
|
||||||
context = cxt;
|
mContext = cxt;
|
||||||
isMarshmallow = isMarshmallow();
|
mIsMarshmallow = isMarshmallow();
|
||||||
handleCameraSetup();
|
handleCameraSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleFlashlight() {
|
public void toggleFlashlight() {
|
||||||
handleCameraSetup();
|
handleCameraSetup();
|
||||||
isFlashlightOn = !isFlashlightOn;
|
mIsFlashlightOn = !mIsFlashlightOn;
|
||||||
|
|
||||||
if (isFlashlightOn) {
|
if (mIsFlashlightOn) {
|
||||||
enableFlashlight();
|
enableFlashlight();
|
||||||
} else {
|
} else {
|
||||||
disableFlashlight();
|
disableFlashlight();
|
||||||
@ -33,7 +34,7 @@ public class MyCameraImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleCameraSetup() {
|
public void handleCameraSetup() {
|
||||||
if (isMarshmallow) {
|
if (mIsMarshmallow) {
|
||||||
setupMarshmallowCamera();
|
setupMarshmallowCamera();
|
||||||
} else {
|
} else {
|
||||||
setupCamera();
|
setupCamera();
|
||||||
@ -41,65 +42,67 @@ public class MyCameraImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupMarshmallowCamera() {
|
private void setupMarshmallowCamera() {
|
||||||
if (marshmallowCamera == null) {
|
if (mMarshmallowCamera == null) {
|
||||||
marshmallowCamera = new MarshmallowCamera(callback, context);
|
mMarshmallowCamera = new MarshmallowCamera(mCallback, mContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupCamera() {
|
private void setupCamera() {
|
||||||
if (isMarshmallow)
|
if (mIsMarshmallow)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (camera == null) {
|
if (mCamera == null) {
|
||||||
try {
|
try {
|
||||||
camera = Camera.open();
|
mCamera = Camera.open();
|
||||||
params = camera.getParameters();
|
mParams = mCamera.getParameters();
|
||||||
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
mParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
||||||
camera.setParameters(params);
|
mCamera.setParameters(mParams);
|
||||||
|
|
||||||
if (isFlashlightOn)
|
if (mIsFlashlightOn)
|
||||||
enableFlashlight();
|
enableFlashlight();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "setup camera " + e.getMessage());
|
Log.e(TAG, "setup mCamera " + e.getMessage());
|
||||||
callback.cameraUnavailable();
|
mCallback.cameraUnavailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableFlashlight() {
|
private void enableFlashlight() {
|
||||||
if (isMarshmallow) {
|
if (mIsMarshmallow) {
|
||||||
toggleMarshmallowFlashlight(true);
|
toggleMarshmallowFlashlight(true);
|
||||||
} else {
|
} else {
|
||||||
if (camera == null || params == null)
|
if (mCamera == null || mParams == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
|
mParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
|
||||||
camera.setParameters(params);
|
mCamera.setParameters(mParams);
|
||||||
}
|
}
|
||||||
callback.enableFlashlight();
|
mCallback.enableFlashlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableFlashlight() {
|
private void disableFlashlight() {
|
||||||
if (isMarshmallow()) {
|
if (isMarshmallow()) {
|
||||||
toggleMarshmallowFlashlight(false);
|
toggleMarshmallowFlashlight(false);
|
||||||
} else {
|
} else {
|
||||||
if (camera == null || params == null)
|
if (mCamera == null || mParams == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
mParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
||||||
camera.setParameters(params);
|
mCamera.setParameters(mParams);
|
||||||
}
|
}
|
||||||
callback.disableFlashlight();
|
mCallback.disableFlashlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleMarshmallowFlashlight(boolean enable) {
|
private void toggleMarshmallowFlashlight(boolean enable) {
|
||||||
marshmallowCamera.toggleMarshmallowFlashlight(enable);
|
mMarshmallowCamera.toggleMarshmallowFlashlight(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseCamera() {
|
public void releaseCamera() {
|
||||||
if (camera != null) {
|
if (mCamera != null) {
|
||||||
camera.release();
|
mCamera.release();
|
||||||
camera = null;
|
mCamera = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,67 +11,66 @@ import android.graphics.Bitmap;
|
|||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
public class MyWidgetProvider extends AppWidgetProvider implements MyCamera {
|
public class MyWidgetProvider extends AppWidgetProvider implements MyCamera {
|
||||||
private static MyCameraImpl cameraImpl;
|
|
||||||
private static RemoteViews remoteViews;
|
|
||||||
private static Context cxt;
|
|
||||||
private static int[] widgetIds;
|
|
||||||
private static AppWidgetManager widgetManager;
|
|
||||||
private static final String TOGGLE = "toggle";
|
private static final String TOGGLE = "toggle";
|
||||||
private static Bitmap coloredBmp;
|
private static MyCameraImpl mCameraImpl;
|
||||||
|
private static RemoteViews mRemoteViews;
|
||||||
|
private static AppWidgetManager mWidgetManager;
|
||||||
|
private static Bitmap mColoredBmp;
|
||||||
|
|
||||||
|
private static int[] mWidgetIds;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
initVariables(context);
|
initVariables(context);
|
||||||
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
|
appWidgetManager.updateAppWidget(appWidgetIds, mRemoteViews);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initVariables(Context context) {
|
private void initVariables(Context context) {
|
||||||
cxt = context;
|
final ComponentName component = new ComponentName(context, MyWidgetProvider.class);
|
||||||
final ComponentName component = new ComponentName(cxt, MyWidgetProvider.class);
|
mWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
widgetManager = AppWidgetManager.getInstance(context);
|
mWidgetIds = mWidgetManager.getAppWidgetIds(component);
|
||||||
widgetIds = widgetManager.getAppWidgetIds(component);
|
|
||||||
|
|
||||||
final Intent intent = new Intent(cxt, MyWidgetProvider.class);
|
final Intent intent = new Intent(context, MyWidgetProvider.class);
|
||||||
intent.setAction(TOGGLE);
|
intent.setAction(TOGGLE);
|
||||||
|
|
||||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(cxt, 0, intent, 0);
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||||
remoteViews = new RemoteViews(cxt.getPackageName(), R.layout.widget);
|
mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
|
||||||
remoteViews.setOnClickPendingIntent(R.id.toggle_btn, pendingIntent);
|
mRemoteViews.setOnClickPendingIntent(R.id.toggle_btn, pendingIntent);
|
||||||
cameraImpl = new MyCameraImpl(this, cxt);
|
mCameraImpl = new MyCameraImpl(this, context);
|
||||||
|
|
||||||
final Resources res = cxt.getResources();
|
final Resources res = context.getResources();
|
||||||
final int appColor = res.getColor(R.color.colorPrimary);
|
final int appColor = res.getColor(R.color.colorPrimary);
|
||||||
coloredBmp = Utils.getColoredIcon(cxt.getResources(), appColor, R.mipmap.flashlight_small);
|
mColoredBmp = Utils.getColoredIcon(context.getResources(), appColor, R.mipmap.flashlight_small);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
if (action.equals(TOGGLE)) {
|
if (action.equals(TOGGLE)) {
|
||||||
if (cameraImpl == null) {
|
if (mCameraImpl == null) {
|
||||||
initVariables(context);
|
initVariables(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
cameraImpl.toggleFlashlight();
|
mCameraImpl.toggleFlashlight();
|
||||||
} else
|
} else
|
||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableFlashlight() {
|
public void enableFlashlight() {
|
||||||
remoteViews.setImageViewBitmap(R.id.toggle_btn, coloredBmp);
|
mRemoteViews.setImageViewBitmap(R.id.toggle_btn, mColoredBmp);
|
||||||
for (int widgetId : widgetIds) {
|
for (int widgetId : mWidgetIds) {
|
||||||
widgetManager.updateAppWidget(widgetId, remoteViews);
|
mWidgetManager.updateAppWidget(widgetId, mRemoteViews);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableFlashlight() {
|
public void disableFlashlight() {
|
||||||
remoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_small);
|
mRemoteViews.setImageViewResource(R.id.toggle_btn, R.mipmap.flashlight_small);
|
||||||
for (int widgetId : widgetIds) {
|
for (int widgetId : mWidgetIds) {
|
||||||
widgetManager.updateAppWidget(widgetId, remoteViews);
|
mWidgetManager.updateAppWidget(widgetId, mRemoteViews);
|
||||||
}
|
}
|
||||||
cameraImpl.releaseCamera();
|
mCameraImpl.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -85,10 +84,10 @@ public class MyWidgetProvider extends AppWidgetProvider implements MyCamera {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void releaseCamera(Context context) {
|
private void releaseCamera(Context context) {
|
||||||
if (cameraImpl == null)
|
if (mCameraImpl == null)
|
||||||
initVariables(context);
|
initVariables(context);
|
||||||
|
|
||||||
disableFlashlight();
|
disableFlashlight();
|
||||||
cameraImpl.releaseCamera();
|
mCameraImpl.releaseCamera();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ public class Utils {
|
|||||||
final Paint paint = new Paint();
|
final Paint paint = new Paint();
|
||||||
final ColorFilter filter = new PorterDuffColorFilter(newTextColor, PorterDuff.Mode.SRC_IN);
|
final ColorFilter filter = new PorterDuffColorFilter(newTextColor, PorterDuff.Mode.SRC_IN);
|
||||||
paint.setColorFilter(filter);
|
paint.setColorFilter(filter);
|
||||||
|
|
||||||
final Canvas canvas = new Canvas(bmp);
|
final Canvas canvas = new Canvas(bmp);
|
||||||
canvas.drawBitmap(bmp, 0, 0, paint);
|
canvas.drawBitmap(bmp, 0, 0, paint);
|
||||||
return bmp;
|
return bmp;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.simplemobiletools.flashlight;
|
package com.simplemobiletools.flashlight.activities;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@ -8,6 +8,9 @@ import android.text.Html;
|
|||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.simplemobiletools.flashlight.BuildConfig;
|
||||||
|
import com.simplemobiletools.flashlight.R;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@ -15,17 +18,18 @@ import butterknife.ButterKnife;
|
|||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class AboutActivity extends AppCompatActivity {
|
public class AboutActivity extends AppCompatActivity {
|
||||||
@BindView(R.id.about_copyright) TextView copyright;
|
@BindView(R.id.about_copyright) TextView mCopyright;
|
||||||
@BindView(R.id.about_version) TextView version;
|
@BindView(R.id.about_version) TextView mVersion;
|
||||||
@BindView(R.id.about_email) TextView emailTV;
|
@BindView(R.id.about_email) TextView mEmailTV;
|
||||||
private Resources res;
|
|
||||||
|
private static Resources mRes;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_about);
|
setContentView(R.layout.activity_about);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
res = getResources();
|
mRes = getResources();
|
||||||
|
|
||||||
setupEmail();
|
setupEmail();
|
||||||
setupVersion();
|
setupVersion();
|
||||||
@ -33,23 +37,23 @@ public class AboutActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupEmail() {
|
private void setupEmail() {
|
||||||
final String email = res.getString(R.string.email);
|
final String email = mRes.getString(R.string.email);
|
||||||
final String appName = res.getString(R.string.app_name);
|
final String appName = mRes.getString(R.string.app_name);
|
||||||
final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>";
|
final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>";
|
||||||
emailTV.setText(Html.fromHtml(href));
|
mEmailTV.setText(Html.fromHtml(href));
|
||||||
emailTV.setMovementMethod(LinkMovementMethod.getInstance());
|
mEmailTV.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupVersion() {
|
private void setupVersion() {
|
||||||
final String versionName = BuildConfig.VERSION_NAME;
|
final String versionName = BuildConfig.VERSION_NAME;
|
||||||
final String versionText = String.format(res.getString(R.string.version), versionName);
|
final String versionText = String.format(mRes.getString(R.string.version), versionName);
|
||||||
version.setText(versionText);
|
mVersion.setText(versionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupCopyright() {
|
private void setupCopyright() {
|
||||||
final int year = Calendar.getInstance().get(Calendar.YEAR);
|
final int year = Calendar.getInstance().get(Calendar.YEAR);
|
||||||
final String copyrightText = String.format(res.getString(R.string.copyright), year);
|
final String copyrightText = String.format(mRes.getString(R.string.copyright), year);
|
||||||
copyright.setText(copyrightText);
|
mCopyright.setText(copyrightText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.about_license)
|
@OnClick(R.id.about_license)
|
@ -1,14 +1,17 @@
|
|||||||
package com.simplemobiletools.flashlight;
|
package com.simplemobiletools.flashlight.activities;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.simplemobiletools.flashlight.R;
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class LicenseActivity extends AppCompatActivity {
|
public class LicenseActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
@ -1,22 +1,27 @@
|
|||||||
package com.simplemobiletools.flashlight;
|
package com.simplemobiletools.flashlight.activities;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.simplemobiletools.flashlight.MyCamera;
|
||||||
|
import com.simplemobiletools.flashlight.MyCameraImpl;
|
||||||
|
import com.simplemobiletools.flashlight.R;
|
||||||
|
import com.simplemobiletools.flashlight.Utils;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements MyCamera {
|
public class MainActivity extends AppCompatActivity implements MyCamera {
|
||||||
@BindView(R.id.toggle_btn) ImageView toggleBtn;
|
@BindView(R.id.toggle_btn) ImageView mToggleBtn;
|
||||||
private MyCameraImpl cameraImpl;
|
|
||||||
|
private static MyCameraImpl mCameraImpl;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -29,8 +34,7 @@ public class MainActivity extends AppCompatActivity implements MyCamera {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
MenuInflater inflater = getMenuInflater();
|
getMenuInflater().inflate(R.menu.menu, menu);
|
||||||
inflater.inflate(R.menu.menu, menu);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,50 +51,50 @@ public class MainActivity extends AppCompatActivity implements MyCamera {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupCameraImpl() {
|
private void setupCameraImpl() {
|
||||||
cameraImpl = new MyCameraImpl(this, this);
|
mCameraImpl = new MyCameraImpl(this, this);
|
||||||
cameraImpl.toggleFlashlight();
|
mCameraImpl.toggleFlashlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.toggle_btn)
|
@OnClick(R.id.toggle_btn)
|
||||||
public void toggleFlashlight() {
|
public void toggleFlashlight() {
|
||||||
cameraImpl.toggleFlashlight();
|
mCameraImpl.toggleFlashlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
cameraImpl.handleCameraSetup();
|
mCameraImpl.handleCameraSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
cameraImpl.handleCameraSetup();
|
mCameraImpl.handleCameraSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
cameraImpl.releaseCamera();
|
mCameraImpl.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
cameraImpl.releaseCamera();
|
mCameraImpl.releaseCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableFlashlight() {
|
public void enableFlashlight() {
|
||||||
final int appColor = getResources().getColor(R.color.colorPrimary);
|
final int appColor = getResources().getColor(R.color.colorPrimary);
|
||||||
toggleBtn.setImageResource(R.mipmap.flashlight_big);
|
mToggleBtn.setImageResource(R.mipmap.flashlight_big);
|
||||||
toggleBtn.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
|
mToggleBtn.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableFlashlight() {
|
public void disableFlashlight() {
|
||||||
toggleBtn.setImageResource(R.mipmap.flashlight_big);
|
mToggleBtn.setImageResource(R.mipmap.flashlight_big);
|
||||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user