mirror of
https://github.com/rfc2822/GfxTablet
synced 2025-10-03 17:49:17 +02:00
added auto refresh and removed unused stuff
This commit is contained in:
parent
bd49aea3d0
commit
9a74c8d1e4
15 changed files with 58 additions and 94 deletions
|
@ -2,20 +2,14 @@ package at.bitfire.gfxtablet;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -23,16 +17,17 @@ import android.view.View;
|
|||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import at.bitfire.gfxtablet.NetEvent.Type;
|
||||
|
||||
public class CanvasActivity extends AppCompatActivity implements View.OnSystemUiVisibilityChangeListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final int RESULT_LOAD_IMAGE = 1;
|
||||
private static final String TAG = "GfxTablet.Canvas";
|
||||
public static String SCREEN_PATH;
|
||||
private static CanvasActivity instance;
|
||||
private Handler autoRefreshHandler;
|
||||
private Runnable autoRefreshBackground;
|
||||
public static CanvasActivity get() { return instance; }
|
||||
|
||||
final Uri homepageUri = Uri.parse(("https://gfxtablet.bitfire.at"));
|
||||
|
||||
NetworkClient netClient;
|
||||
NetworkServer netServer;
|
||||
|
||||
|
@ -44,6 +39,8 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
instance = this;
|
||||
autoRefreshHandler = new Handler();
|
||||
SCREEN_PATH = CanvasActivity.get().getCacheDir() + "/screen.png";
|
||||
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
|
@ -64,6 +61,20 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
canvas.setNetworkClient(netClient);
|
||||
}
|
||||
|
||||
private void startAutoRefresh() {
|
||||
autoRefreshHandler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
refreshBackground();
|
||||
autoRefreshBackground=this;
|
||||
autoRefreshHandler.postDelayed(autoRefreshBackground, 5000);
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
private void stopAutoRefresh() {
|
||||
autoRefreshHandler.removeCallbacks(autoRefreshBackground);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -73,12 +84,24 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
else
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
if (preferences.getBoolean(SettingsActivity.KEY_AUTO_REFRESH, true))
|
||||
startAutoRefresh();
|
||||
else
|
||||
stopAutoRefresh();
|
||||
|
||||
showTemplateImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
stopAutoRefresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
stopAutoRefresh();
|
||||
netClient.getQueue().add(new NetEvent(NetEvent.Type.TYPE_DISCONNECT));
|
||||
}
|
||||
|
||||
|
@ -118,10 +141,14 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
}
|
||||
|
||||
// refresh methods
|
||||
public void refreshBackground(MenuItem item) {
|
||||
public void refreshBackground() {
|
||||
netClient.getQueue().add(new NetEvent(Type.TYPE_MOTION, (short) 0, (short) 0, (short) 0, -1, false));
|
||||
}
|
||||
|
||||
public void refreshBackground(MenuItem item) {
|
||||
refreshBackground();
|
||||
}
|
||||
|
||||
|
||||
// full-screen methods
|
||||
public void switchFullScreen(MenuItem item) {
|
||||
|
@ -160,17 +187,11 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
public void showTemplateImage() {
|
||||
ImageView template = (ImageView)findViewById(R.id.canvas_template);
|
||||
template.setVisibility(View.VISIBLE);
|
||||
String picturePath = preferences.getString(SettingsActivity.KEY_TEMPLATE_IMAGE, null);
|
||||
if (picturePath != null) {
|
||||
try {
|
||||
Drawable d = Drawable.createFromPath(picturePath);
|
||||
template.setImageDrawable(d);
|
||||
//Bitmap bm = BitmapFactory.decodeFile(picturePath);
|
||||
//template.setImageBitmap(bm);
|
||||
Log.i("drawn", picturePath);
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
try {
|
||||
Drawable d = Drawable.createFromPath(SCREEN_PATH);
|
||||
template.setImageDrawable(d);
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ public class CanvasView extends View implements SharedPreferences.OnSharedPrefer
|
|||
|
||||
|
||||
// setup
|
||||
|
||||
public CanvasView(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
|
||||
|
@ -40,7 +39,6 @@ public class CanvasView extends View implements SharedPreferences.OnSharedPrefer
|
|||
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
settings.registerOnSharedPreferenceChangeListener(this);
|
||||
setBackground();
|
||||
setInputMethods();
|
||||
inRangeStatus = InRangeStatus.OutOfRange;
|
||||
}
|
||||
|
@ -52,27 +50,14 @@ public class CanvasView extends View implements SharedPreferences.OnSharedPrefer
|
|||
|
||||
|
||||
// settings
|
||||
|
||||
protected void setBackground() {
|
||||
if (settings.getBoolean(SettingsActivity.KEY_DARK_CANVAS, false))
|
||||
setBackgroundColor(Color.BLACK);
|
||||
//else
|
||||
//setBackgroundResource(R.drawable.bg_grid_pattern); //<-- Add this as option?
|
||||
}
|
||||
|
||||
protected void setInputMethods() {
|
||||
acceptStylusOnly = settings.getBoolean(SettingsActivity.KEY_PREF_STYLUS_ONLY, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case SettingsActivity.KEY_PREF_STYLUS_ONLY:
|
||||
setInputMethods();
|
||||
break;
|
||||
case SettingsActivity.KEY_DARK_CANVAS:
|
||||
setBackground();
|
||||
break;
|
||||
if (key.equals(SettingsActivity.KEY_PREF_STYLUS_ONLY)) {
|
||||
setInputMethods();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,34 +23,34 @@ public class NetworkServer implements Runnable {
|
|||
public void run() {
|
||||
try {
|
||||
DatagramSocket socket = new DatagramSocket(GFXTABLET_PORT);
|
||||
int packets = 0;
|
||||
|
||||
SparseArray<byte[]> buffer = new SparseArray<>();
|
||||
// Init has to be done twice because the first call will be set on the server with 0.0.0.0
|
||||
// but we need the ip of the client.
|
||||
CanvasActivity.get().sendMotionStopSignal();
|
||||
CanvasActivity.get().sendMotionStopSignal();
|
||||
CanvasActivity.get().refreshBackground();
|
||||
while (true) {
|
||||
byte[] buf = new byte[60030];
|
||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||
socket.receive(packet);
|
||||
int n = buf[60029];
|
||||
//Log.i("receive:", String.valueOf(n));
|
||||
Log.i("receive:", String.valueOf(n));
|
||||
if (n != 0){
|
||||
buffer.put(n, buf);
|
||||
} else if (buffer.size() > 0 ) {
|
||||
try {
|
||||
String path = CanvasActivity.get().getCacheDir() + "/dsektop.png";
|
||||
Log.i("buffer:", String.valueOf(buf[0]));
|
||||
String path = CanvasActivity.SCREEN_PATH;
|
||||
boolean parts = buffer.size() == (int) buf[0];
|
||||
for (int i=0; i < buf[0]; i++) {
|
||||
if (parts) {
|
||||
//Log.i("keyAt " + i, String.valueOf(buffer.keyAt(i)));
|
||||
parts = buffer.keyAt(i) == i+1;
|
||||
}
|
||||
}
|
||||
if (!parts) {
|
||||
buffer.clear();
|
||||
CanvasActivity.get().sendMotionStopSignal();
|
||||
CanvasActivity.get().refreshBackground();
|
||||
Log.i("Image Problem", "tying to refetch the screenshot");
|
||||
continue;
|
||||
}
|
||||
|
@ -62,13 +62,6 @@ public class NetworkServer implements Runnable {
|
|||
}
|
||||
fos.flush();
|
||||
fos.close();
|
||||
File file = new File(path);
|
||||
long size = file.length();
|
||||
//Log.i("file-path", path);
|
||||
//Log.i("file-size", String.valueOf(size));
|
||||
preferences.edit().remove(SettingsActivity.KEY_TEMPLATE_IMAGE).apply();
|
||||
preferences.edit().putString(SettingsActivity.KEY_TEMPLATE_IMAGE, path).apply();
|
||||
//Log.i("file-path-current", preferences.getString(SettingsActivity.KEY_TEMPLATE_IMAGE, null));
|
||||
CanvasActivity.get().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -8,10 +8,9 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
public static final String
|
||||
KEY_PREF_HOST = "host_preference",
|
||||
KEY_PREF_STYLUS_ONLY = "stylus_only_preference",
|
||||
KEY_DARK_CANVAS = "dark_canvas_preference",
|
||||
KEY_KEEP_DISPLAY_ACTIVE = "keep_display_active_preference",
|
||||
KEY_TEMPLATE_IMAGE = "key_template_image";
|
||||
|
||||
KEY_AUTO_REFRESH = "auto_refresh_preference";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 771 B |
Binary file not shown.
Before Width: | Height: | Size: 558 B |
Binary file not shown.
Before Width: | Height: | Size: 947 B |
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 251 B |
|
@ -1,5 +0,0 @@
|
|||
<?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"/>
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/canvas_template"
|
||||
android:src="@drawable/ic_action_picture"
|
||||
android:src="@drawable/ic_renew"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitXY"/>
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_clear_template_image"
|
||||
android:onClick="clearTemplateImage"
|
||||
android:title="@string/menu_clear_template_image"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_select_template_image"
|
||||
android:onClick="selectTemplateImage"
|
||||
android:title="@string/menu_select_another_template_image"/>
|
||||
|
||||
</menu>
|
|
@ -1,15 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">GfxTablet</string>
|
||||
<string name="menu_settings">Settings</string>
|
||||
<string name="menu_about">About / Help</string>
|
||||
<string name="menu_donate">Donate</string>
|
||||
|
||||
<string name="fullscreen">Full-screen mode</string>
|
||||
<string name="menu_set_template_image">Set template image</string>
|
||||
<string name="menu_clear_template_image">Clear template image</string>
|
||||
<string name="menu_select_another_template_image">Select another image</string>
|
||||
|
||||
<string name="no_host_defined">No valid recipient host defined. Please configure in \"Settings / Recipient host\".</string>
|
||||
|
||||
|
@ -18,11 +12,9 @@
|
|||
<string name="preferences_stylus_only">Sense stylus only</string>
|
||||
<string name="preferences_stylus_only_on">Only stylus input will be processed</string>
|
||||
<string name="preferences_stylus_only_off">Finger and stylus input will be processed</string>
|
||||
<string name="preferences_dark_canvas">Use dark canvas</string>
|
||||
<string name="preferences_dark_canvas_on">Black canvas will be used (covers template image)</string>
|
||||
<string name="preferences_dark_canvas_off">White/transparent gridded canvas will be used</string>
|
||||
<string name="preferences_keep_display_active">Keep display active</string>
|
||||
<string name="preferences_keep_display_active_on">Display won\'t turn off while GfxTablet is active</string>
|
||||
<string name="preferences_keep_display_active_off">Display will turn off according to system settings</string>
|
||||
|
||||
<string name="auto_reload_summary">It will refresh every 5 seconds.</string>
|
||||
<string name="auto_reload_title">Auto refresh</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
<resources>
|
||||
|
||||
<style name="BaseTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
|
||||
</style>
|
||||
|
||||
<style name="AppTheme" parent="BaseTheme">
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -16,20 +16,16 @@
|
|||
android:title="@string/preferences_keep_display_active"
|
||||
android:summaryOn="@string/preferences_keep_display_active_on"
|
||||
android:summaryOff="@string/preferences_keep_display_active_off" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="stylus_only_preference"
|
||||
android:title="@string/preferences_stylus_only"
|
||||
android:summaryOn="@string/preferences_stylus_only_on"
|
||||
android:summaryOff="@string/preferences_stylus_only_off" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="dark_canvas_preference"
|
||||
android:title="@string/preferences_dark_canvas"
|
||||
android:summaryOn="@string/preferences_dark_canvas_on"
|
||||
android:summaryOff="@string/preferences_dark_canvas_off" />
|
||||
|
||||
android:key="auto_refresh_preference"
|
||||
android:summary="@string/auto_reload_summary"
|
||||
android:title="@string/auto_reload_title" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue