mirror of
https://github.com/rfc2822/GfxTablet
synced 2025-10-05 10:29:25 +02:00
new darwing method / added refresh button / removed unsued functions
This commit is contained in:
parent
5d07e66470
commit
27ede5ca15
8 changed files with 38 additions and 80 deletions
|
@ -3,6 +3,8 @@ 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;
|
||||
|
@ -98,14 +100,6 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
super.onBackPressed();
|
||||
}
|
||||
|
||||
public void showAbout(MenuItem item) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, homepageUri));
|
||||
}
|
||||
|
||||
public void showDonate(MenuItem item) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, homepageUri.buildUpon().appendPath("donate").build()));
|
||||
}
|
||||
|
||||
public void showSettings(MenuItem item) {
|
||||
startActivityForResult(new Intent(this, SettingsActivity.class), 0);
|
||||
}
|
||||
|
@ -123,9 +117,13 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
}
|
||||
}
|
||||
|
||||
// refresh methods
|
||||
public void refreshBackground(MenuItem item) {
|
||||
netClient.getQueue().add(new NetEvent(Type.TYPE_MOTION, (short) 0, (short) 0, (short) 0, -1, false));
|
||||
}
|
||||
|
||||
|
||||
// full-screen methods
|
||||
|
||||
public void switchFullScreen(MenuItem item) {
|
||||
final View decorView = getWindow().getDecorView();
|
||||
int uiFlags = decorView.getSystemUiVisibility();
|
||||
|
@ -156,61 +154,23 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
}
|
||||
|
||||
|
||||
// template image logic
|
||||
|
||||
private String getTemplateImagePath() {
|
||||
return preferences.getString(SettingsActivity.KEY_TEMPLATE_IMAGE, null);
|
||||
}
|
||||
|
||||
public void selectTemplateImage(MenuItem item) {
|
||||
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(i, RESULT_LOAD_IMAGE);
|
||||
}
|
||||
|
||||
public void clearTemplateImage(MenuItem item) {
|
||||
preferences.edit().remove(SettingsActivity.KEY_TEMPLATE_IMAGE).apply();
|
||||
showTemplateImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null) {
|
||||
Uri selectedImage = data.getData();
|
||||
String[] filePathColumn = { MediaStore.Images.Media.DATA };
|
||||
|
||||
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
||||
try {
|
||||
cursor.moveToFirst();
|
||||
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String picturePath = cursor.getString(columnIndex);
|
||||
|
||||
preferences.edit().putString(SettingsActivity.KEY_TEMPLATE_IMAGE, picturePath).apply();
|
||||
showTemplateImage();
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fits chosen image to screen size.
|
||||
*/
|
||||
public void showTemplateImage() {
|
||||
ImageView template = (ImageView)findViewById(R.id.canvas_template);
|
||||
template.setImageDrawable(null);
|
||||
|
||||
if (template.getVisibility() == View.VISIBLE) {
|
||||
String picturePath = preferences.getString(SettingsActivity.KEY_TEMPLATE_IMAGE, null);
|
||||
if (picturePath != null)
|
||||
try {
|
||||
final Drawable drawable = new BitmapDrawable(getResources(), picturePath);
|
||||
template.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||
template.setImageDrawable(drawable);
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,7 +187,6 @@ public class CanvasActivity extends AppCompatActivity implements View.OnSystemUi
|
|||
|
||||
findViewById(R.id.canvas_template).setVisibility(success ? View.VISIBLE : View.GONE);
|
||||
findViewById(R.id.canvas).setVisibility(success ? View.VISIBLE : View.GONE);
|
||||
findViewById(R.id.canvas_message).setVisibility(success ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class NetworkServer implements Runnable {
|
|||
|
||||
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 nee the ip of the client.
|
||||
// but we need the ip of the client.
|
||||
CanvasActivity.get().sendMotionStopSignal();
|
||||
CanvasActivity.get().sendMotionStopSignal();
|
||||
while (true) {
|
||||
|
@ -34,18 +34,17 @@ public class NetworkServer implements Runnable {
|
|||
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().getFilesDir().getPath() + "/desktop.png";
|
||||
path = "/storage/emulated/0/test.png"; //TODO set via options
|
||||
String path = CanvasActivity.get().getCacheDir() + "/dsektop.png";
|
||||
Log.i("buffer:", String.valueOf(buf[0]));
|
||||
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)));
|
||||
//Log.i("keyAt " + i, String.valueOf(buffer.keyAt(i)));
|
||||
parts = buffer.keyAt(i) == i+1;
|
||||
}
|
||||
}
|
||||
|
@ -65,10 +64,11 @@ public class NetworkServer implements Runnable {
|
|||
fos.close();
|
||||
File file = new File(path);
|
||||
long size = file.length();
|
||||
Log.i("file-path", path);
|
||||
Log.i("file-size", String.valueOf(size));
|
||||
Log.i("file-path-current", preferences.getString(SettingsActivity.KEY_TEMPLATE_IMAGE, null));
|
||||
//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() {
|
||||
|
|
BIN
app-android/app/src/main/res/drawable-hdpi/ic_renew.png
Normal file
BIN
app-android/app/src/main/res/drawable-hdpi/ic_renew.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 638 B |
BIN
app-android/app/src/main/res/drawable-mdpi/ic_renew.png
Normal file
BIN
app-android/app/src/main/res/drawable-mdpi/ic_renew.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 409 B |
BIN
app-android/app/src/main/res/drawable-xhdpi/ic_renew.png
Normal file
BIN
app-android/app/src/main/res/drawable-xhdpi/ic_renew.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 781 B |
BIN
app-android/app/src/main/res/drawable-xxhdpi/ic_renew.png
Normal file
BIN
app-android/app/src/main/res/drawable-xxhdpi/ic_renew.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -6,24 +6,16 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/canvas_template"
|
||||
android:src="@drawable/ic_action_picture"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitCenter"/>
|
||||
android:scaleType="fitXY"/>
|
||||
|
||||
<view
|
||||
android:id="@+id/canvas"
|
||||
class="at.bitfire.gfxtablet.CanvasView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/canvas_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/no_host_defined"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
android:visibility="visible" />
|
||||
|
||||
</FrameLayout>
|
|
@ -2,6 +2,13 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_refresh"
|
||||
android:icon="@drawable/ic_renew"
|
||||
android:onClick="refreshBackground"
|
||||
app:showAsAction="always"
|
||||
android:title="@string/fullscreen"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_fullscreen"
|
||||
android:icon="@drawable/ic_arrow_expand_white_48dp"
|
||||
|
@ -12,7 +19,7 @@
|
|||
<item
|
||||
android:icon="@drawable/ic_settings_white_48dp"
|
||||
android:onClick="showSettings"
|
||||
app:showAsAction="never"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/menu_settings"/>
|
||||
|
||||
</menu>
|
Loading…
Add table
Add a link
Reference in a new issue