change imageview visuals from src to background

This commit is contained in:
tibbi 2016-09-25 15:42:27 +02:00
parent 439023e119
commit 37ec102452
4 changed files with 45 additions and 15 deletions

View File

@ -9,6 +9,7 @@ import com.squareup.otto.Bus;
public class MyCameraImpl { public class MyCameraImpl {
private static final String TAG = MyCameraImpl.class.getSimpleName(); private static final String TAG = MyCameraImpl.class.getSimpleName();
private static Camera mCamera; private static Camera mCamera;
private static Camera.Parameters mParams; private static Camera.Parameters mParams;
private static Bus mBus; private static Bus mBus;
@ -20,10 +21,12 @@ public class MyCameraImpl {
private static boolean mIsFlashlightOn; private static boolean mIsFlashlightOn;
private static boolean mIsMarshmallow; private static boolean mIsMarshmallow;
private static boolean mShouldEnableFlashlight; private static boolean mShouldEnableFlashlight;
private static int mStroboFrequency;
public MyCameraImpl(Context cxt) { public MyCameraImpl(Context cxt) {
mContext = cxt; mContext = cxt;
mIsMarshmallow = isMarshmallow(); mIsMarshmallow = isMarshmallow();
mStroboFrequency = 1000;
if (mBus == null) { if (mBus == null) {
mBus = BusProvider.getInstance(); mBus = BusProvider.getInstance();
@ -39,6 +42,10 @@ public class MyCameraImpl {
handleCameraSetup(); handleCameraSetup();
} }
public void setStroboFrequency(int frequency) {
mStroboFrequency = frequency;
}
public boolean toggleStroboscope() { public boolean toggleStroboscope() {
if (!mIsStroboscopeRunning) if (!mIsStroboscopeRunning)
disableFlashlight(); disableFlashlight();
@ -202,9 +209,9 @@ public class MyCameraImpl {
while (!mShouldStroboscopeStop) { while (!mShouldStroboscopeStop) {
try { try {
mCamera.setParameters(torchOn); mCamera.setParameters(torchOn);
Thread.sleep(500); Thread.sleep(mStroboFrequency);
mCamera.setParameters(torchOff); mCamera.setParameters(torchOff);
Thread.sleep(500); Thread.sleep(mStroboFrequency);
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
mShouldStroboscopeStop = true; mShouldStroboscopeStop = true;
} catch (RuntimeException ignored) { } catch (RuntimeException ignored) {

View File

@ -29,6 +29,8 @@ import butterknife.OnClick;
public class MainActivity extends SimpleActivity { public class MainActivity extends SimpleActivity {
private static final int CAMERA_PERMISSION = 1; private static final int CAMERA_PERMISSION = 1;
private static final int MAX_STROBO_DELAY = 2000;
private static final int MIN_STROBO_DELAY = 30;
@BindView(R.id.toggle_btn) ImageView mToggleBtn; @BindView(R.id.toggle_btn) ImageView mToggleBtn;
@BindView(R.id.bright_display_btn) ImageView mBrightDisplayBtn; @BindView(R.id.bright_display_btn) ImageView mBrightDisplayBtn;
@ -47,6 +49,27 @@ public class MainActivity extends SimpleActivity {
mBus = BusProvider.getInstance(); mBus = BusProvider.getInstance();
changeIconColor(R.color.translucent_white, mBrightDisplayBtn); changeIconColor(R.color.translucent_white, mBrightDisplayBtn);
changeIconColor(R.color.translucent_white, mStroboscopeBtn); changeIconColor(R.color.translucent_white, mStroboscopeBtn);
mStroboscopeBar.setMax(MAX_STROBO_DELAY - MIN_STROBO_DELAY);
mStroboscopeBar.setProgress(mStroboscopeBar.getMax() / 2);
mStroboscopeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
final int frequency = mStroboscopeBar.getMax() - progress + MIN_STROBO_DELAY;
if (mCameraImpl != null)
mCameraImpl.setStroboFrequency(frequency);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
} }
@Override @Override
@ -180,7 +203,7 @@ public class MainActivity extends SimpleActivity {
private void changeIconColor(int colorId, ImageView imageView) { private void changeIconColor(int colorId, ImageView imageView) {
final int appColor = getResources().getColor(colorId); final int appColor = getResources().getColor(colorId);
imageView.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN); imageView.getBackground().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
} }
@Subscribe @Subscribe

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item <item
android:width="60dp" android:bottom="60dp"
android:height="60dp"
android:left="60dp" android:left="60dp"
android:right="60dp"
android:top="60dp"> android:top="60dp">
<shape <shape
android:shape="oval"> android:shape="oval">
@ -15,9 +15,9 @@
</item> </item>
<item <item
android:width="120dp" android:bottom="30dp"
android:height="120dp"
android:left="30dp" android:left="30dp"
android:right="30dp"
android:top="30dp"> android:top="30dp">
<shape <shape
android:shape="oval"> android:shape="oval">
@ -28,9 +28,7 @@
</shape> </shape>
</item> </item>
<item <item>
android:width="180dp"
android:height="180dp">
<shape <shape
android:shape="oval"> android:shape="oval">
<stroke <stroke

View File

@ -13,23 +13,25 @@
android:id="@+id/toggle_btn" android:id="@+id/toggle_btn"
android:layout_width="@dimen/main_button_size" android:layout_width="@dimen/main_button_size"
android:layout_height="@dimen/main_button_size" android:layout_height="@dimen/main_button_size"
android:src="@drawable/circles_big"/> android:layout_marginBottom="@dimen/activity_margin"
android:background="@drawable/circles_big"/>
<ImageView <ImageView
android:id="@+id/bright_display_btn" android:id="@+id/bright_display_btn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginTop="@dimen/buttons_margin" android:layout_marginTop="@dimen/buttons_margin"
android:padding="@dimen/activity_margin" android:background="@mipmap/bright_display"
android:src="@mipmap/bright_display"/> android:padding="@dimen/activity_margin"/>
<ImageView <ImageView
android:id="@+id/stroboscope_btn" android:id="@+id/stroboscope_btn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/buttons_margin" android:layout_marginTop="@dimen/buttons_margin"
android:padding="@dimen/activity_margin" android:background="@mipmap/bright_display"
android:src="@mipmap/bright_display"/> android:padding="@dimen/activity_margin"/>
<SeekBar <SeekBar
android:id="@+id/stroboscope_bar" android:id="@+id/stroboscope_bar"