Skip to content

Commit

Permalink
Added image support
Browse files Browse the repository at this point in the history
  • Loading branch information
scorzy committed Nov 10, 2016
1 parent 8f074c8 commit 90ae4ee
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 73 deletions.
19 changes: 11 additions & 8 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
Expand All @@ -82,8 +74,17 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.2.1/jars" />
Expand All @@ -105,6 +106,8 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 14
targetSdkVersion 24
versionCode 3
versionName '1.0.7'
versionName '1.0.8'
}
buildTypes {
release {
Expand Down
95 changes: 47 additions & 48 deletions app/src/main/java/it/lorenzo/clw/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import java.util.ArrayList;

import it.lorenzo.clw.core.modules.Agenda;
import it.lorenzo.clw.core.modules.Image;
import it.lorenzo.clw.core.modules.Module;
import it.lorenzo.clw.core.modules.OsInfo;
import it.lorenzo.clw.core.modules.SystemInfo;
import it.lorenzo.clw.core.modules.TextManager;
import it.lorenzo.clw.core.modules.TopCpu;
import it.lorenzo.clw.core.modules.TopMem;
import it.lorenzo.clw.core.modules.Utility.BitmapWithPosition;

public class Core {

Expand All @@ -45,8 +47,8 @@ public class Core {
private Canvas c;
private ArrayList<Module> modules;
private TextManager txtMan;
private ArrayList<Pair<Bitmap, Integer>> drawCenter;
private ArrayList<Pair<Bitmap, Integer>> drawRight;
private ArrayList<Pair<BitmapWithPosition, Integer>> drawCenter;
private ArrayList<Pair<BitmapWithPosition, Integer>> drawRight;
private int centerLenght;
private int rightLenght;
private int bgColor = 0;
Expand All @@ -72,6 +74,7 @@ private Core() {
modules.add(new TopCpu());
modules.add(new TopMem());
modules.add(new Agenda());
modules.add(new Image());
drawCenter = new ArrayList<>();
drawRight = new ArrayList<>();
}
Expand Down Expand Up @@ -131,10 +134,10 @@ private void printText() {
Canvas c2 = new Canvas(bmp2);
txtMan.drawText(toPrint, c2, txtMan.getBoundsMarginX() / 2, bounds.height());
if (allign == 1) {
drawCenter.add(new Pair<>(bmp2, 0));
drawCenter.add(new Pair<>(new BitmapWithPosition(bmp2), 0));
centerLenght += bmp2.getWidth();
} else {
drawRight.add(new Pair<>(bmp2, 0));
drawRight.add(new Pair<>(new BitmapWithPosition(bmp2), 0));
rightLenght += bmp2.getWidth();
}
} else
Expand Down Expand Up @@ -214,40 +217,38 @@ private int drawLine(String line, float y, Context context) {
// module draw
} else if (module.check(key) == Module.Result.draw) {
printText();
if (allign == 0) {
Bitmap bitmap = module.GetBmp(key, params,
maxWidth - currentX, context);
if (bitmap != null) {
int newHeight = Math.max(
bitmap.getHeight(), height);
bounds = new Rect(0, 0, bitmap.getWidth(),
newHeight);
BitmapWithPosition bitmap = module.GetBmp(key, params, maxWidth - currentX, context);
if (!bitmap.getRelative()) {
c.drawBitmap(
bitmap.getBitmap(),
bitmap.getPoint().x,
bitmap.getPoint().y, null);
bounds = null;
} else {
if (allign == 0) {
bounds = new Rect(0, 0,
Math.max(bitmap.getBitmap().getWidth() + bitmap.getPoint().x, 0),
Math.max(bitmap.getBitmap().getHeight() + bitmap.getPoint().y, height));
float descent = txtMan.getStrokePaint().getFontMetrics().descent;
c.drawBitmap(
bitmap,
currentX,
y + bounds.height() + descent
- bitmap.getHeight(), null);
}
} else if (allign == 1) {
Bitmap bitmap = module.GetBmp(key, params, maxWidth - currentX, context);
if (bitmap != null) {
bitmap.getBitmap(),
currentX + bitmap.getPoint().x,
y + bounds.height() + bitmap.getPoint().y + descent
- bitmap.getBitmap().getHeight(), null);
} else if (allign == 1) {
int newHeight = Math.max(
bitmap.getHeight(), height);
bitmap.getBitmap().getHeight(), height);
drawCenter.add(new Pair<>(
bitmap, newHeight
- bitmap.getHeight()));
centerLenght += bitmap.getWidth();
}
} else {
Bitmap bitmap = module.GetBmp(key, params, maxWidth - currentX, context);
if (bitmap != null) {
bitmap, newHeight + bitmap.getPoint().y +
-bitmap.getBitmap().getHeight()));
centerLenght += bitmap.getBitmap().getWidth();
} else {
int newHeight = Math.max(
bitmap.getHeight(), height);
bitmap.getBitmap().getHeight(), height);
drawRight.add(new Pair<>(
bitmap, newHeight
- bitmap.getHeight()));
rightLenght += bitmap.getWidth();
bitmap, newHeight + bitmap.getPoint().y +
-bitmap.getBitmap().getHeight()));
rightLenght += bitmap.getBitmap().getWidth();
}
}
break;
Expand All @@ -266,33 +267,33 @@ private int drawLine(String line, float y, Context context) {
}
if (!toPrint.equals("") && current >= lenght)
printText();
}
if (bounds != null) {
currentX += bounds.width();
height = Math.max(height, bounds.height());
if (bounds != null) {
currentX += bounds.width();
height = Math.max(height, bounds.height());
}
}

// draw center stuff
if (!drawCenter.isEmpty()) {
int sum = 0;
for (Pair<Bitmap, Integer> pair : drawCenter) {
Bitmap toDraw = pair.first;
//Log.i("asd", "" + maxWidth + " " + centerLenght + " " + sum);
for (Pair<BitmapWithPosition, Integer> pair : drawCenter) {
BitmapWithPosition toDraw = pair.first;
int pos = ((maxWidth - centerLenght) / 2) + sum;
c.drawBitmap(toDraw, pos, y + pair.second, null);
sum += toDraw.getWidth();
c.drawBitmap(toDraw.getBitmap(), pos + toDraw.getPoint().x, y
+ pair.second + toDraw.getPoint().y, null);
sum += toDraw.getBitmap().getWidth() + toDraw.getPoint().x;
}
}
drawCenter.clear();

//draw right stuff
if (!drawRight.isEmpty()) {
int sum = 0;
for (Pair<Bitmap, Integer> pair : drawRight) {
Bitmap toDraw = pair.first;
c.drawBitmap(toDraw, maxWidth - xOffsetRight - rightLenght + sum, y
+ pair.second, null);
sum += toDraw.getWidth();
for (Pair<BitmapWithPosition, Integer> pair : drawRight) {
BitmapWithPosition toDraw = pair.first;
c.drawBitmap(toDraw.getBitmap(), maxWidth - xOffsetRight - rightLenght + sum + toDraw.getPoint().x, y
+ pair.second + toDraw.getPoint().y, null);
sum += toDraw.getBitmap().getWidth() + toDraw.getPoint().x;
}
}
drawRight.clear();
Expand Down Expand Up @@ -322,8 +323,6 @@ private void readConfigFile(String path) throws IOException {
}
}
//if (!done)


}
}
// text
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package it.lorenzo.clw.core.modules;

import android.content.Context;

import java.util.HashMap;

import it.lorenzo.clw.core.modules.Utility.BitmapWithPosition;

/**
* Created by lorenzo on 21/02/15.
*/
Expand All @@ -24,4 +28,9 @@ public Result check(String key) {
return Result.no;
return res;
}

@Override
public BitmapWithPosition GetBmp(String key, String[] params, int maxWidth, Context context) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import it.lorenzo.clw.core.modules.Utility.BitmapWithPosition;
import it.lorenzo.clw.core.modules.Utility.CommonUtility;

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ public void initialize(Context context) {
}

@Override
public Bitmap GetBmp(String key, String[] params, int maxWidth, Context context) {
public BitmapWithPosition GetBmp(String key, String[] params, int maxWidth, Context context) {
return null;
}

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/it/lorenzo/clw/core/modules/Agenda.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.provider.CalendarContract;
Expand All @@ -15,6 +14,8 @@
import java.util.GregorianCalendar;
import java.util.Locale;

import it.lorenzo.clw.core.modules.Utility.BitmapWithPosition;

/**
* Created by lorenzo on 24/03/15.
*/
Expand Down Expand Up @@ -146,7 +147,7 @@ public void changeSetting(String key, String[] params, Context context) {
}

@Override
public Bitmap GetBmp(String key, String[] params, int maxWidth, Context context) {
public BitmapWithPosition GetBmp(String key, String[] params, int maxWidth, Context context) {
return null;
}

Expand Down
74 changes: 74 additions & 0 deletions app/src/main/java/it/lorenzo/clw/core/modules/Image.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package it.lorenzo.clw.core.modules;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Point;

import java.util.StringTokenizer;

import it.lorenzo.clw.core.modules.Utility.BitmapWithPosition;


/**
* Created by lorenzo on 09/11/16.
*/

public class Image extends AbstractModule {

public static final String IMAGE = "image";

public Image() {
keys.put(IMAGE, Result.draw);
}

@Override
public BitmapWithPosition GetBmp(String key, String[] params, int maxWidth, Context context) {
BitmapWithPosition bmp = new BitmapWithPosition();
bmp.setPoint(new Point(0, 0));
if (key.equals(IMAGE)) {
bmp.setBitmap(BitmapFactory.decodeFile(params[0]));
for (int i = 1; i < params.length; i++) {

StringTokenizer str;
switch (params[i]) {
case "p":
str = new StringTokenizer(params[i + 1], ",");
if (str.countTokens() > 1)
bmp.setPoint(new Point(Integer.parseInt(str.nextToken()), Integer.parseInt(str.nextToken())));
break;
case "s":
str = new StringTokenizer(params[i + 1], "x");
if (str.countTokens() > 1) {
bmp.setBitmap(android.graphics.Bitmap.createScaledBitmap(bmp.getBitmap(),
Integer.parseInt(str.nextToken()),
Integer.parseInt(str.nextToken()),
false));
}
break;
case "relative":
bmp.setRelative(true);
break;
case "fixed":
bmp.setRelative(false);
break;
}
}
}
return bmp;
}

@Override
public void initialize(Context context) {

}

@Override
public void changeSetting(String key, String[] params, Context context) {

}

@Override
public String getString(String key, String[] params, Context context) {
return null;
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/it/lorenzo/clw/core/modules/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

import android.content.Context;
import android.graphics.Bitmap;

import it.lorenzo.clw.core.modules.Utility.BitmapWithPosition;

public interface Module {

Expand All @@ -15,7 +16,7 @@ public interface Module {

void changeSetting(String key, String[] params, Context context);

Bitmap GetBmp(String key, String[] params, int maxWidth, Context context);
BitmapWithPosition GetBmp(String key, String[] params, int maxWidth, Context context);

void initialize(Context context);

Expand Down
Loading

0 comments on commit 90ae4ee

Please sign in to comment.