Skip to content

Commit

Permalink
Support immersive mode to hide the navigation buttons.
Browse files Browse the repository at this point in the history
Add Android TV support.
  • Loading branch information
Devesh Parekh committed Apr 19, 2015
1 parent 7d50e29 commit c32d47e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 18 deletions.
37 changes: 26 additions & 11 deletions build.gradle
@@ -1,38 +1,53 @@
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
classpath 'com.android.tools.build:gradle:1.1.3'
}
}
apply plugin: 'android'
apply plugin: 'com.android.application'

task wrapper(type: Wrapper) {
gradleVersion '1.6'
gradleVersion '2.3'
}

android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
compileSdkVersion 22
buildToolsVersion '22.0.1'

defaultConfig {
minSdkVersion 3
targetSdkVersion 17
targetSdkVersion 22
}

productFlavors {
cupcake {
versionCode 3000
}
immersive {
versionCode 11000
minSdkVersion 11
}
}

signingConfigs {
release {
storeFile file('devesh.keystore')
keyAlias 'deveshandroid'
storePassword System.getenv("KSTOREPWD")
keyPassword System.getenv("KEYPWD")
keyAlias 'flashlight'
}
}

buildTypes {
release {
runProguard true
proguardFile 'proguard.cfg'
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
debug {
debuggable true
}
}
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Fri May 17 02:12:17 PDT 2013
#Sat Apr 18 19:19:04 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
Expand Up @@ -14,10 +14,13 @@
* limitations under the License.
*/

package org.dyndns.devesh.flashlight;
package devesh.flashlight;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

Expand Down
56 changes: 56 additions & 0 deletions src/immersive/java/devesh/flashlight/Flashlight.java
@@ -0,0 +1,56 @@
/*
* Copyright 2012 Devesh Parekh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package devesh.flashlight;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class Flashlight extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow();
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
// Flashlights should be bright.
WindowManager.LayoutParams params = window.getAttributes();
params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL;
// params.buttonBrightness was added in API level 8. The additional brightness is not worth the added code size.
// The screen will go to max brightness even without the following line, but the API doesn't guarantee it.
window.setAttributes(params);
window.addFlags(
// Use the power button to turn flashlight off and on, even if you have a lock screen.
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
// We won't do anything with touch events. Don't bother sending them to us.
// Unfortunately, there is a platform bug that still exists in 4.2 (!) that causes ANRs if this
// flag is set.
// | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
// A flashlight that turns itself off isn't a good flashlight.
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
// Turn the screen on if it isn't already on when launching (e.g., from ADB).
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
}
14 changes: 10 additions & 4 deletions src/main/AndroidManifest.xml
Expand Up @@ -16,14 +16,16 @@
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.dyndns.devesh.flashlight"
android:versionCode="6"
android:versionName="3.0.1"
package="devesh.flashlight"
android:versionCode="7"
android:versionName="3.1"
android:installLocation="auto">
<!-- Window.LayoutParams.screenBrightness was added in Cupcake. -->
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="17"/>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="21"/>
<!-- Touch screen is assumed. Explicitly say we don't need it. -->
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<!-- Android TV. Why not? -->
<uses-feature android:name="android.software.leanback" android:required="false" />

<!-- I considered using @color/w for the icon to save even more space, but most launchers display that poorly,
and Android Market expects an icon file to extract from the APK. -->
Expand All @@ -38,6 +40,10 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

0 comments on commit c32d47e

Please sign in to comment.