mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-02-21 14:20:51 +01:00
implement the actual brightness display
This commit is contained in:
parent
a62ebb98ca
commit
5761765387
@ -37,6 +37,10 @@
|
|||||||
android:label="@string/third_party_licences"
|
android:label="@string/third_party_licences"
|
||||||
android:parentActivityName=".activities.AboutActivity"/>
|
android:parentActivityName=".activities.AboutActivity"/>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activities.BrightDisplayActivity"
|
||||||
|
android:screenOrientation="portrait"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.SettingsActivity"
|
android:name=".activities.SettingsActivity"
|
||||||
android:label="@string/settings"
|
android:label="@string/settings"
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.simplemobiletools.flashlight.activities;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import com.simplemobiletools.flashlight.R;
|
||||||
|
|
||||||
|
public class BrightDisplayActivity extends SimpleActivity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_bright_display);
|
||||||
|
|
||||||
|
if (getSupportActionBar() != null)
|
||||||
|
getSupportActionBar().hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
toggleBrightness(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
toggleBrightness(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleBrightness(boolean increase) {
|
||||||
|
final WindowManager.LayoutParams layout = getWindow().getAttributes();
|
||||||
|
layout.screenBrightness = (increase ? 1 : 0);
|
||||||
|
getWindow().setAttributes(layout);
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import android.graphics.PorterDuff;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ import butterknife.OnClick;
|
|||||||
|
|
||||||
public class MainActivity extends SimpleActivity {
|
public class MainActivity extends SimpleActivity {
|
||||||
@BindView(R.id.toggle_btn) ImageView mToggleBtn;
|
@BindView(R.id.toggle_btn) ImageView mToggleBtn;
|
||||||
|
@BindView(R.id.bright_display_btn) ImageView mBrightDisplayBtn;
|
||||||
|
|
||||||
private static Bus mBus;
|
private static Bus mBus;
|
||||||
private static MyCameraImpl mCameraImpl;
|
private static MyCameraImpl mCameraImpl;
|
||||||
@ -34,6 +36,7 @@ public class MainActivity extends SimpleActivity {
|
|||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
mBus = BusProvider.getInstance();
|
mBus = BusProvider.getInstance();
|
||||||
|
changeIconColor(R.color.translucent_white, mBrightDisplayBtn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -66,6 +69,11 @@ public class MainActivity extends SimpleActivity {
|
|||||||
mCameraImpl.toggleFlashlight();
|
mCameraImpl.toggleFlashlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.bright_display_btn)
|
||||||
|
public void launchBrightDisplay() {
|
||||||
|
startActivity(new Intent(getApplicationContext(), BrightDisplayActivity.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
@ -81,6 +89,11 @@ public class MainActivity extends SimpleActivity {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
mCameraImpl.handleCameraSetup();
|
mCameraImpl.handleCameraSetup();
|
||||||
mCameraImpl.checkFlashlight();
|
mCameraImpl.checkFlashlight();
|
||||||
|
|
||||||
|
if (mConfig.getBrightDisplay())
|
||||||
|
mBrightDisplayBtn.setVisibility(View.VISIBLE);
|
||||||
|
else
|
||||||
|
mBrightDisplayBtn.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -109,18 +122,18 @@ public class MainActivity extends SimpleActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void enableFlashlight() {
|
public void enableFlashlight() {
|
||||||
changeIconColor(R.color.colorPrimary);
|
changeIconColor(R.color.colorPrimary, mToggleBtn);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableFlashlight() {
|
public void disableFlashlight() {
|
||||||
changeIconColor(R.color.translucent_white);
|
changeIconColor(R.color.translucent_white, mToggleBtn);
|
||||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeIconColor(int colorId) {
|
private void changeIconColor(int colorId, ImageView imageView) {
|
||||||
final int appColor = getResources().getColor(colorId);
|
final int appColor = getResources().getColor(colorId);
|
||||||
mToggleBtn.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
|
imageView.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
7
app/src/main/res/layout/activity_bright_display.xml
Normal file
7
app/src/main/res/layout/activity_bright_display.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/display_holder"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/white"/>
|
@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/main_holder"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@android:color/black"
|
android:background="@android:color/black"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
android:padding="@dimen/activity_margin">
|
android:padding="@dimen/activity_margin">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
@ -12,4 +14,15 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@mipmap/flashlight_big"/>
|
android:src="@mipmap/flashlight_big"/>
|
||||||
</RelativeLayout>
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/bright_display_btn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/bright_display_margin"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:padding="@dimen/activity_margin"
|
||||||
|
android:src="@mipmap/bright_display"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.7 KiB |
@ -1,5 +1,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="activity_margin">16dp</dimen>
|
<dimen name="activity_margin">16dp</dimen>
|
||||||
|
<dimen name="bright_display_margin">40dp</dimen>
|
||||||
<dimen name="social_padding">8dp</dimen>
|
<dimen name="social_padding">8dp</dimen>
|
||||||
<dimen name="social_logo">40dp</dimen>
|
<dimen name="social_logo">40dp</dimen>
|
||||||
<dimen name="settings_padding">8dp</dimen>
|
<dimen name="settings_padding">8dp</dimen>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user