Skip to content

Commit 5761765

Browse files
committed
implement the actual brightness display
1 parent a62ebb9 commit 5761765

File tree

7 files changed

+82
-6
lines changed

7 files changed

+82
-6
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
android:label="@string/third_party_licences"
3838
android:parentActivityName=".activities.AboutActivity"/>
3939

40+
<activity
41+
android:name=".activities.BrightDisplayActivity"
42+
android:screenOrientation="portrait"/>
43+
4044
<activity
4145
android:name=".activities.SettingsActivity"
4246
android:label="@string/settings"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.simplemobiletools.flashlight.activities;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.view.WindowManager;
6+
7+
import com.simplemobiletools.flashlight.R;
8+
9+
public class BrightDisplayActivity extends SimpleActivity {
10+
@Override
11+
protected void onCreate(@Nullable Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
setContentView(R.layout.activity_bright_display);
14+
15+
if (getSupportActionBar() != null)
16+
getSupportActionBar().hide();
17+
}
18+
19+
@Override
20+
protected void onResume() {
21+
super.onResume();
22+
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
23+
toggleBrightness(true);
24+
}
25+
26+
@Override
27+
protected void onPause() {
28+
super.onPause();
29+
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
30+
toggleBrightness(false);
31+
}
32+
33+
private void toggleBrightness(boolean increase) {
34+
final WindowManager.LayoutParams layout = getWindow().getAttributes();
35+
layout.screenBrightness = (increase ? 1 : 0);
36+
getWindow().setAttributes(layout);
37+
}
38+
}

app/src/main/java/com/simplemobiletools/flashlight/activities/MainActivity.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.os.Bundle;
66
import android.view.Menu;
77
import android.view.MenuItem;
8+
import android.view.View;
89
import android.view.WindowManager;
910
import android.widget.ImageView;
1011

@@ -23,6 +24,7 @@
2324

2425
public class MainActivity extends SimpleActivity {
2526
@BindView(R.id.toggle_btn) ImageView mToggleBtn;
27+
@BindView(R.id.bright_display_btn) ImageView mBrightDisplayBtn;
2628

2729
private static Bus mBus;
2830
private static MyCameraImpl mCameraImpl;
@@ -34,6 +36,7 @@ protected void onCreate(Bundle savedInstanceState) {
3436
ButterKnife.bind(this);
3537

3638
mBus = BusProvider.getInstance();
39+
changeIconColor(R.color.translucent_white, mBrightDisplayBtn);
3740
}
3841

3942
@Override
@@ -66,6 +69,11 @@ public void toggleFlashlight() {
6669
mCameraImpl.toggleFlashlight();
6770
}
6871

72+
@OnClick(R.id.bright_display_btn)
73+
public void launchBrightDisplay() {
74+
startActivity(new Intent(getApplicationContext(), BrightDisplayActivity.class));
75+
}
76+
6977
@Override
7078
protected void onStart() {
7179
super.onStart();
@@ -81,6 +89,11 @@ protected void onResume() {
8189
super.onResume();
8290
mCameraImpl.handleCameraSetup();
8391
mCameraImpl.checkFlashlight();
92+
93+
if (mConfig.getBrightDisplay())
94+
mBrightDisplayBtn.setVisibility(View.VISIBLE);
95+
else
96+
mBrightDisplayBtn.setVisibility(View.GONE);
8497
}
8598

8699
@Override
@@ -109,18 +122,18 @@ public void stateChangedEvent(Events.StateChanged event) {
109122
}
110123

111124
public void enableFlashlight() {
112-
changeIconColor(R.color.colorPrimary);
125+
changeIconColor(R.color.colorPrimary, mToggleBtn);
113126
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
114127
}
115128

116129
public void disableFlashlight() {
117-
changeIconColor(R.color.translucent_white);
130+
changeIconColor(R.color.translucent_white, mToggleBtn);
118131
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
119132
}
120133

121-
private void changeIconColor(int colorId) {
134+
private void changeIconColor(int colorId, ImageView imageView) {
122135
final int appColor = getResources().getColor(colorId);
123-
mToggleBtn.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
136+
imageView.getDrawable().mutate().setColorFilter(appColor, PorterDuff.Mode.SRC_IN);
124137
}
125138

126139
@Subscribe
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout
3+
android:id="@+id/display_holder"
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="@android:color/white"/>
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout
2+
<LinearLayout
3+
android:id="@+id/main_holder"
34
xmlns:android="http://schemas.android.com/apk/res/android"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
android:background="@android:color/black"
78
android:gravity="center"
9+
android:orientation="vertical"
810
android:padding="@dimen/activity_margin">
911

1012
<ImageView
1113
android:id="@+id/toggle_btn"
1214
android:layout_width="wrap_content"
1315
android:layout_height="wrap_content"
1416
android:src="@mipmap/flashlight_big"/>
15-
</RelativeLayout>
17+
18+
<ImageButton
19+
android:id="@+id/bright_display_btn"
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:layout_marginTop="@dimen/bright_display_margin"
23+
android:background="@android:color/transparent"
24+
android:padding="@dimen/activity_margin"
25+
android:src="@mipmap/bright_display"
26+
android:visibility="gone"/>
27+
28+
</LinearLayout>
727 Bytes
Loading

app/src/main/res/values/dimens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<resources>
22
<dimen name="activity_margin">16dp</dimen>
3+
<dimen name="bright_display_margin">40dp</dimen>
34
<dimen name="social_padding">8dp</dimen>
45
<dimen name="social_logo">40dp</dimen>
56
<dimen name="settings_padding">8dp</dimen>

0 commit comments

Comments
 (0)