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

View File

@ -29,6 +29,8 @@ import butterknife.OnClick;
public class MainActivity extends SimpleActivity {
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.bright_display_btn) ImageView mBrightDisplayBtn;
@ -47,6 +49,27 @@ public class MainActivity extends SimpleActivity {
mBus = BusProvider.getInstance();
changeIconColor(R.color.translucent_white, mBrightDisplayBtn);
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
@ -180,7 +203,7 @@ public class MainActivity extends SimpleActivity {
private void changeIconColor(int colorId, ImageView imageView) {
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

View File

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

View File

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