mirror of
https://github.com/rfc2822/GfxTablet
synced 2025-10-03 09:39:16 +02:00
Add "sticky immersive" full-screen mode and background pattern
This commit is contained in:
parent
5af1ed116c
commit
e29a9b691f
12 changed files with 100 additions and 45 deletions
|
@ -7,7 +7,7 @@ android {
|
|||
defaultConfig {
|
||||
applicationId "at.bitfire.gfxtablet"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 14
|
||||
targetSdkVersion 22
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
@ -19,5 +19,5 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile "com.android.support:appcompat-v7:21.0.0"
|
||||
compile "com.android.support:appcompat-v7:21.0.+"
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
android:targetSdkVersion="14" />
|
||||
android:targetSdkVersion="22" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-configuration android:reqTouchScreen="stylus"/>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package at.bitfire.gfxtablet;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
|
@ -8,20 +9,35 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class CanvasActivity extends ActionBarActivity {
|
||||
public class CanvasActivity extends ActionBarActivity implements View.OnSystemUiVisibilityChangeListener {
|
||||
NetworkClient netClient;
|
||||
CanvasView canvas;
|
||||
|
||||
boolean fullScreen = false;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
netClient = new NetworkClient(PreferenceManager.getDefaultSharedPreferences(this));
|
||||
new Thread(netClient).start();
|
||||
|
||||
canvas = new CanvasView(CanvasActivity.this, netClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
new ConfigureNetworkingTask().execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,16 +45,16 @@ public class CanvasActivity extends ActionBarActivity {
|
|||
super.onResume();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (prefs.getBoolean(SettingsActivity.KEY_KEEP_DISPLAY_ACTIVE, false))
|
||||
if (prefs.getBoolean(SettingsActivity.KEY_KEEP_DISPLAY_ACTIVE, true))
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
new ConfigureNetworkingTask().execute();
|
||||
else
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
protected void onStop() {
|
||||
netClient.getQueue().add(new NetEvent(NetEvent.Type.TYPE_DISCONNECT));
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,12 +64,14 @@ public class CanvasActivity extends ActionBarActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
menu.findItem(R.id.menu_fullscreen).setVisible(Build.VERSION.SDK_INT >= 19);
|
||||
return true;
|
||||
public void onBackPressed() {
|
||||
if (fullScreen)
|
||||
switchFullScreen(null);
|
||||
else
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
public void showAbout(MenuItem item) {
|
||||
public void showAbout(MenuItem item) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(("https://rfc2822.github.io/GfxTablet/"))));
|
||||
}
|
||||
|
||||
|
@ -61,16 +79,31 @@ public class CanvasActivity extends ActionBarActivity {
|
|||
startActivityForResult(new Intent(this, SettingsActivity.class), 0);
|
||||
}
|
||||
|
||||
|
||||
public void switchFullScreen(MenuItem item) {
|
||||
final View decorView = getWindow().getDecorView();
|
||||
decorView.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 | // hide nav bar
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN | // hide status bar
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE
|
||||
);
|
||||
int uiFlags = decorView.getSystemUiVisibility();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 14)
|
||||
uiFlags ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
uiFlags ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||
if (Build.VERSION.SDK_INT >= 18)
|
||||
uiFlags ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
|
||||
decorView.setOnSystemUiVisibilityChangeListener(this);
|
||||
decorView.setSystemUiVisibility(uiFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int visibility) {
|
||||
// show/hide action bar according to full-screen mode
|
||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0) {
|
||||
CanvasActivity.this.getSupportActionBar().hide();
|
||||
fullScreen = true;
|
||||
Toast.makeText(CanvasActivity.this, "Press Back button to leave full-screen mode.", Toast.LENGTH_LONG).show();
|
||||
} else
|
||||
CanvasActivity.this.getSupportActionBar().show();
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,9 +115,7 @@ public class CanvasActivity extends ActionBarActivity {
|
|||
|
||||
protected void onPostExecute(Boolean success) {
|
||||
if (success) {
|
||||
setContentView(new CanvasView(CanvasActivity.this, netClient));
|
||||
new Thread(netClient).start();
|
||||
|
||||
setContentView(canvas);
|
||||
Toast.makeText(CanvasActivity.this, "Touch events will be sent to " + netClient.destAddress.getHostAddress() + ":" + NetworkClient.GFXTABLET_PORT, Toast.LENGTH_LONG).show();
|
||||
} else
|
||||
setContentView(R.layout.activity_no_host);
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
@ -22,21 +23,29 @@ public class CanvasView extends View {
|
|||
|
||||
public CanvasView(Context context, NetworkClient networkClient) {
|
||||
super(context);
|
||||
|
||||
netClient = networkClient;
|
||||
this.netClient = networkClient;
|
||||
|
||||
// process preferences
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
acceptStylusOnly = settings.getBoolean(SettingsActivity.KEY_PREF_STYLUS_ONLY, false);
|
||||
setBackgroundColor(settings.getBoolean(SettingsActivity.KEY_DARK_CANVAS, false) ? Color.BLACK : Color.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
if (settings.getBoolean(SettingsActivity.KEY_DARK_CANVAS, false))
|
||||
setBackgroundColor(Color.BLACK);
|
||||
else
|
||||
setBackgroundResource(R.drawable.bg_grid_pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
Log.i(TAG, "Canvas size changed: " + w + "x" + h + " (before: " + oldw + "x" + oldh + ")");
|
||||
maxX = w;
|
||||
maxY = h;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
if (isEnabled()) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package at.bitfire.gfxtablet;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
|
|
BIN
app-android/app/src/main/res/drawable/bg_grid.png
Normal file
BIN
app-android/app/src/main/res/drawable/bg_grid.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 251 B |
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<bitmap
|
||||
android:src="@drawable/bg_grid"
|
||||
android:tileMode="repeat"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"/>
|
|
@ -1,22 +1,22 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_fullscreen"
|
||||
android:onClick="switchFullScreen"
|
||||
android:title="Fullscreen"
|
||||
android:icon="@drawable/ic_arrow_expand_white_48dp"
|
||||
app:showAsAction="always" />
|
||||
android:onClick="switchFullScreen"
|
||||
app:showAsAction="always"
|
||||
android:title="Fullscreen"/>
|
||||
|
||||
<item
|
||||
android:onClick="showSettings"
|
||||
android:title="@string/menu_settings"
|
||||
android:icon="@drawable/ic_settings_white_48dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
android:onClick="showSettings"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/menu_settings"/>
|
||||
|
||||
<item
|
||||
android:onClick="showAbout"
|
||||
android:title="@string/menu_about"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="never"
|
||||
android:title="@string/menu_about"/>
|
||||
|
||||
</menu>
|
|
@ -1,10 +1,12 @@
|
|||
<resources>
|
||||
|
||||
<!-- Application theme. -->
|
||||
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
|
||||
<style name="BaseTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
|
||||
<item name="colorPrimary">#4825d0</item>
|
||||
<item name="colorPrimaryDark">#755a8e</item>
|
||||
<item name="colorAccent">#f32eac</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme" parent="BaseTheme">
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<PreferenceCategory android:title="Drawing preferences">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:defaultValue="true"
|
||||
android:key="keep_display_active_preference"
|
||||
android:title="@string/preferences_keep_display_active"
|
||||
android:summaryOn="@string/preferences_keep_display_active_on"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue