mirror of
https://github.com/rfc2822/GfxTablet
synced 2025-10-03 17:49:17 +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 {
|
defaultConfig {
|
||||||
applicationId "at.bitfire.gfxtablet"
|
applicationId "at.bitfire.gfxtablet"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 14
|
targetSdkVersion 22
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
@ -19,5 +19,5 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "com.android.support:appcompat-v7:21.0.0"
|
compile "com.android.support:appcompat-v7:21.0.+"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
android:targetSdkVersion="14" />
|
android:targetSdkVersion="22" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-configuration android:reqTouchScreen="stylus"/>
|
<uses-configuration android:reqTouchScreen="stylus"/>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package at.bitfire.gfxtablet;
|
package at.bitfire.gfxtablet;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -8,20 +9,35 @@ import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class CanvasActivity extends ActionBarActivity {
|
public class CanvasActivity extends ActionBarActivity implements View.OnSystemUiVisibilityChangeListener {
|
||||||
NetworkClient netClient;
|
NetworkClient netClient;
|
||||||
|
CanvasView canvas;
|
||||||
|
|
||||||
|
boolean fullScreen = false;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
netClient = new NetworkClient(PreferenceManager.getDefaultSharedPreferences(this));
|
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
|
@Override
|
||||||
|
@ -29,16 +45,16 @@ public class CanvasActivity extends ActionBarActivity {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
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);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
else
|
||||||
new ConfigureNetworkingTask().execute();
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onStop() {
|
||||||
super.onDestroy();
|
|
||||||
netClient.getQueue().add(new NetEvent(NetEvent.Type.TYPE_DISCONNECT));
|
netClient.getQueue().add(new NetEvent(NetEvent.Type.TYPE_DISCONNECT));
|
||||||
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,12 +64,14 @@ public class CanvasActivity extends ActionBarActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public void onBackPressed() {
|
||||||
menu.findItem(R.id.menu_fullscreen).setVisible(Build.VERSION.SDK_INT >= 19);
|
if (fullScreen)
|
||||||
return true;
|
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/"))));
|
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);
|
startActivityForResult(new Intent(this, SettingsActivity.class), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void switchFullScreen(MenuItem item) {
|
public void switchFullScreen(MenuItem item) {
|
||||||
final View decorView = getWindow().getDecorView();
|
final View decorView = getWindow().getDecorView();
|
||||||
decorView.setSystemUiVisibility(
|
int uiFlags = decorView.getSystemUiVisibility();
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
if (Build.VERSION.SDK_INT >= 14)
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
uiFlags ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | // hide nav bar
|
if (Build.VERSION.SDK_INT >= 16)
|
||||||
View.SYSTEM_UI_FLAG_FULLSCREEN | // hide status bar
|
uiFlags ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||||
View.SYSTEM_UI_FLAG_IMMERSIVE
|
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) {
|
protected void onPostExecute(Boolean success) {
|
||||||
if (success) {
|
if (success) {
|
||||||
setContentView(new CanvasView(CanvasActivity.this, netClient));
|
setContentView(canvas);
|
||||||
new Thread(netClient).start();
|
|
||||||
|
|
||||||
Toast.makeText(CanvasActivity.this, "Touch events will be sent to " + netClient.destAddress.getHostAddress() + ":" + NetworkClient.GFXTABLET_PORT, Toast.LENGTH_LONG).show();
|
Toast.makeText(CanvasActivity.this, "Touch events will be sent to " + netClient.destAddress.getHostAddress() + ":" + NetworkClient.GFXTABLET_PORT, Toast.LENGTH_LONG).show();
|
||||||
} else
|
} else
|
||||||
setContentView(R.layout.activity_no_host);
|
setContentView(R.layout.activity_no_host);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -22,17 +23,25 @@ public class CanvasView extends View {
|
||||||
|
|
||||||
public CanvasView(Context context, NetworkClient networkClient) {
|
public CanvasView(Context context, NetworkClient networkClient) {
|
||||||
super(context);
|
super(context);
|
||||||
|
this.netClient = networkClient;
|
||||||
netClient = networkClient;
|
|
||||||
|
|
||||||
// process preferences
|
// process preferences
|
||||||
settings = PreferenceManager.getDefaultSharedPreferences(context);
|
settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
acceptStylusOnly = settings.getBoolean(SettingsActivity.KEY_PREF_STYLUS_ONLY, false);
|
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) {
|
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;
|
maxX = w;
|
||||||
maxY = h;
|
maxY = h;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package at.bitfire.gfxtablet;
|
package at.bitfire.gfxtablet;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
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"
|
<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
|
<item
|
||||||
android:id="@+id/menu_fullscreen"
|
android:id="@+id/menu_fullscreen"
|
||||||
android:onClick="switchFullScreen"
|
|
||||||
android:title="Fullscreen"
|
|
||||||
android:icon="@drawable/ic_arrow_expand_white_48dp"
|
android:icon="@drawable/ic_arrow_expand_white_48dp"
|
||||||
app:showAsAction="always" />
|
android:onClick="switchFullScreen"
|
||||||
|
app:showAsAction="always"
|
||||||
|
android:title="Fullscreen"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:onClick="showSettings"
|
|
||||||
android:title="@string/menu_settings"
|
|
||||||
android:icon="@drawable/ic_settings_white_48dp"
|
android:icon="@drawable/ic_settings_white_48dp"
|
||||||
app:showAsAction="ifRoom" />
|
android:onClick="showSettings"
|
||||||
|
app:showAsAction="ifRoom"
|
||||||
|
android:title="@string/menu_settings"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:onClick="showAbout"
|
android:onClick="showAbout"
|
||||||
android:title="@string/menu_about"
|
app:showAsAction="never"
|
||||||
app:showAsAction="never" />
|
android:title="@string/menu_about"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
|
@ -1,10 +1,12 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<!-- Application theme. -->
|
<style name="BaseTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
|
||||||
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
|
|
||||||
<item name="colorPrimary">#4825d0</item>
|
<item name="colorPrimary">#4825d0</item>
|
||||||
<item name="colorPrimaryDark">#755a8e</item>
|
<item name="colorPrimaryDark">#755a8e</item>
|
||||||
<item name="colorAccent">#f32eac</item>
|
<item name="colorAccent">#f32eac</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme" parent="BaseTheme">
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<PreferenceCategory android:title="Drawing preferences">
|
<PreferenceCategory android:title="Drawing preferences">
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="true"
|
||||||
android:key="keep_display_active_preference"
|
android:key="keep_display_active_preference"
|
||||||
android:title="@string/preferences_keep_display_active"
|
android:title="@string/preferences_keep_display_active"
|
||||||
android:summaryOn="@string/preferences_keep_display_active_on"
|
android:summaryOn="@string/preferences_keep_display_active_on"
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
|
|
||||||
networktablet : networktablet.c protocol.h
|
networktablet : networktablet.c protocol.h
|
||||||
|
|
||||||
|
clean :
|
||||||
|
rm networktablet
|
||||||
|
|
|
@ -25,13 +25,17 @@ void init_device(int fd)
|
||||||
{
|
{
|
||||||
struct uinput_user_dev uidev;
|
struct uinput_user_dev uidev;
|
||||||
|
|
||||||
// 1 button
|
// enable synchronization
|
||||||
|
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) < 0)
|
||||||
|
die("error: ioctl UI_SET_EVBIT EV_SYN");
|
||||||
|
|
||||||
|
// enable 1 button
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_KEY) < 0)
|
if (ioctl(fd, UI_SET_EVBIT, EV_KEY) < 0)
|
||||||
die("error: ioctl UI_SET_EVBIT EV_KEY");
|
die("error: ioctl UI_SET_EVBIT EV_KEY");
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH) < 0)
|
if (ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH) < 0)
|
||||||
die("error: ioctl UI_SET_KEYBIT");
|
die("error: ioctl UI_SET_KEYBIT");
|
||||||
|
|
||||||
// 2 main axes + pressure (absolute positioning)
|
// enable 2 main axes + pressure (absolute positioning)
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_ABS) < 0)
|
if (ioctl(fd, UI_SET_EVBIT, EV_ABS) < 0)
|
||||||
die("error: ioctl UI_SET_EVBIT EV_ABS");
|
die("error: ioctl UI_SET_EVBIT EV_ABS");
|
||||||
if (ioctl(fd, UI_SET_ABSBIT, ABS_X) < 0)
|
if (ioctl(fd, UI_SET_ABSBIT, ABS_X) < 0)
|
||||||
|
@ -86,7 +90,7 @@ void send_event(int device, int type, int code, int value)
|
||||||
ev.code = code;
|
ev.code = code;
|
||||||
ev.value = value;
|
ev.value = value;
|
||||||
if (write(device, &ev, sizeof(ev)) < 0)
|
if (write(device, &ev, sizeof(ev)) < 0)
|
||||||
error("error: write()");
|
die("error: write()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit(int signal) {
|
void quit(int signal) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue