improve the touchscreen smoothness - Motorola Photon Q 4G LTE

i'm korean photon q user, sorry for my bad english.
i bought Photon Q 2weeks ago on Ebay,
and i applied "SIM CARD MOD" it works perfect.
but touchscreen smoothness and sensitivity is dissatisfied for me..
i want to change touchscreen setting, and i found the solution.
modifying touchscreen driver in kernel source.
i refer to the "MXT224E Protocol Guide" (google it)
tested one by one all register on [TOUCH_ACQUIRESETTING_T8], [TOUCH_MULTITOUCHSCREEN_T9] Function.
For example, [TOUCH_MULTITOUCHSCREEN_T9] can set like this.
Code:
in "drivers/input/touchscreen/atmxt.c"
~~~~
if (entry[3] < 21) {
atmxt_dbg(dd, ATMXT_DBG3,
"%s: Only 10-bit resolution is available.\n", __func__);
} else {
if (reg[19] >= 0x04)
dd->data->res[0] = true;
if (reg[21] >= 0x04)
dd->data->res[1] = true;
}
// MOT
reg[0] = 139; //CTRL!
// reg[1] = ; //XORIGIN!
// reg[2] = ; //YORIGIN!
// reg[3] = ; //XSIZE! 19
// reg[4] = ; //YSIZE! 11
reg[5] = 0; //AKSFG
reg[6] = 70; //BLEN
reg[7] = 23; //TCHTHR
reg[8] = 2 ; //TCHDI
reg[9] = 1 ; //ORIENT
reg[10] = 0; //MRGTIMEOUT
reg[11] = 2; //MOVHYSTI
reg[12] = 1; //MOVHYSTN
reg[13] = 63; //MOVFILTER
reg[14] = 10; //NUM-TOUCH
reg[15] = 5; // HYSTERISIS MERGE
reg[16] = 40; // THRESHOLD MERGE
reg[17] = 7; // AMPLITUDE HYSTERESIS
reg[18] = 255; //XRANGE
reg[19] = 3; //XRANGE
reg[20] = 255; //YRANGE
reg[21] = 3; //YRANGE
// reg[22] =3; // XLOCLIP
// reg[23] =248; // XHICLIP
// reg[24] =28; // YLOCLIP
// reg[25] =17; // YHICLIP
reg[26] = 225; //XEDGECTRL
reg[27] = 50; //XEDGEDIST
reg[28] = 172; //YEDGECTRL
reg[29] = 80; //YEDGEDIST
reg[30] = 18; //JUMPLIMIT
reg[31] = 10; //TCHHYST
reg[32] = 40; //XPITCH
reg[33] = 40; //YPITCH
reg[34] = 0; //NEXTTCHDI
atmxt_save_data9_fail:
return err;
}
i attached "Touchscreen Tuned" Kernel flashable zip file.
(based on CM-Kernel source, "motorola_msm8960-common")
it works on CM11-SNAPSHOT-M12. "moto_msm8960_jbbl"
IT IS NOT a perfect solution.
if you want more smoothness and sensitivity, modify that values.

Related

[APP] Android Business Card program - Simple code for DIY use

Android Business Card Program - Open Code for DIY Use
Decided to make an Android .apk program Business Card instead of getting boring cardboard ones.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
All of the project names link back to the project post when tapped.
Took 6 hours from concept to finish while watching TV and catering to potential future in-laws.
DOWNLOAD: http://www.sendspace.com/file/k7wyst
EDIT 9/21/2011
I REWROTE THE PROGRAM USING PROCESSING FOR ANDROID (took NO-TIME whatsoever)
Now, you can use the basic code to make your own simple business card program by replacing my info with yours.
I made the sections really easy so all you have to do is add your own icon pictures and links. I made this template because of people I know wanting to be able to do it themselves and its an easy intro to programming as well as using the Processing core. When you get more advanced, you can bring the Processing core into Eclipse and have more fun. It simplifies intro Android programming for non-programmers to get in the game!
Code:
/*
Written by and for STACY DEVINO
doesitpew.blogspot.com
[email protected]
***Re-written in Processing for Android for ease of re-use by others in September 2011.***
http://wiki.processing.org/w/Android
^ All instructions are above!!!!
This program serves as a unique calling card for those looking for something beyond cardboard.
*/
//////////////////////////////////////////////////////////////////
//****************************************************************
// PAY ATTENTION HERE - ADD THE LINKS FOR YOUR PAGES!!!!!
//****************************************************************
//////////////////////////////////////////////////////////////////
String your_Blog = ; //make sure that this is a LINK
String your_Facebook = ; //make sure that this is a LINK
String your_Name = ; //make sure that this is a LINK
String your_Twitter = ; //make sure that this is a LINK
String your_LinkedIn = ; //make sure that this is a LINK
String your_CoverLetter = ; //make sure that this is a LINK
String your_Resume = ; //make sure that this is a LINK
//LOGIC FOR BUTTONS AND ACTIONS
//*dont touch unless you know how to code
boolean blog = false;
boolean linked = false;
boolean fb = false;
boolean twit = false;
boolean ok = false;
boolean res = false;
boolean qual = false;
boolean cl = false;
boolean rfid = false;
boolean hifi = false;
boolean ch = false;
boolean sensor = false;
boolean splash = false;
boolean ipod = false;
boolean evo = false;
boolean zoe = false;
boolean game = false;
boolean speak = false;
boolean eb = false;
boolean main = false;
// IMAGE NAMES!!!!!!
PImage b;
PFont font;
PImage blogger;
PImage in;
PImage facebook;
PImage twitter;
PImage projects;
PImage resume;
PImage cube;
PImage cover;
PImage q;
PFont ffont;
PImage menu;
/////////////////////////////////////////
// SET UP ALL PICTURES
////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//****************************************************************
// PAY ATTENTION HERE - ADD THE PICS FOR YOUR PAGES!!!!!
//****************************************************************
//////////////////////////////////////////////////////////////////
void setup(){
b = loadImage("mio.jpg"); //Picture of yourself or whatever
//Find your own 128x128 pictures (PNG is Better) for your icons and put the names here
blogger = loadImage("128x128.png");
in = loadImage("128x128.png");
//cube = loadImage("Cube.png"); // This would be a background picture
facebook = loadImage("128x128.png");
twitter = loadImage("128x128.png");
projects = loadImage("128x128.png");
resume = loadImage("128x128.png");
menu = loadImage("128x128.png");
cover = loadImage("128x128.png");
q = loadImage("128x128.png");
}
///////////////////////////////////////////
// HOME PAGE RETURN
//////////////////////////////////////////
void home(){
if(ok == true || res == true){
res = false;
cl = false;
qual = false;
rfid = false;
hifi = false;
ch = false;
sensor = false;
splash = false;
ipod = false;
evo = false;
zoe = false;
game = false;
speak = false;
eb = false;
ok = false;
}
}
//////////////////////////////////////////////
// MAIN LOOP
/////////////////////////////////////////////
void draw(){
if(res == false || ok == false){
background(0);
//image(cube, 0, 0);
font = loadFont("OldDreadfulNo7BT-Regular-48.vlw");
textFont(font, 48);
text(your_Name, 45, 75);
image(b, 110, 120);
image(blogger, 30, 470);
image(in, 170, 470);
image(facebook, 320, 470);
image(twitter, 30, 625);
image(projects, 170, 625);
image(resume, 320, 625);
// Left buttom
if (blog == true) {
link(your_Blog);
blog = false;
}
else if (linked == true) {
link(your_LinkedIn);
linked = false;
}
else if (fb == true) {
link(your_Facebook);
fb = false;
}
else if (twit == true) {
link(your_Twitter);
twit = false;
}
}
if (res == true) {
image(cube, 0, 0);
image(cover, 50, 100);
image(q, 170, 100);
ffont = loadFont("Vrinda-32.vlw");
textFont(ffont, 32);
///////////////////////////////////////////////////////
//ENTER YOUR COVER LETTER AND PERSONAL INFORMATION HERE!
///////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//****************************************************************
// PAY ATTENTION HERE
//****************************************************************
//////////////////////////////////////////////////////////////////
text("NAME HERE", 50, 275);
text("EMAIL HERE", 50, 325);
text("PHONE HERE", 50, 375);
text("CONTACT LINE", 50, 425);
text("BLOG HERE", 50, 475);
text("WEBPAGE HERE", 50, 525);
text("AKA HERE", 50, 575);
//Resume and Cover Letter links
if (qual == true){
link(your_Resume);
qual = false;
res = false;
}
else if (cl == true){
link(your_CoverLetter);
cl = false;
res = false;
}
image(menu, 170, 680);
}
if (ok == true){
image(cube, 0, 0);
font = loadFont("OldDreadfulNo7BT-Regular-48.vlw");
textFont(font, 48);
//ENTER THE PAGE NAME YOU WANT
text("PAGE_NAME", 20, 75);
ffont = loadFont("Vrinda-32.vlw");
textFont(ffont, 32);
//////////////////////////////////////////////////////////
// ENTER THE NAMES AND LINKS THAT YOU WANT YOUR PROJECT TO USE
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//****************************************************************
// PAY ATTENTION HERE - ADD THE LINKS and NAMES FOR YOUR PROJECTS!!!!!
//****************************************************************
//////////////////////////////////////////////////////////////////
text("PROJECT NAME", 50, 175);
if( rfid == true){
link("PROJECTLINK.html");
rfid = false;
ok = false;
}
text("PROJECT NAME", 50, 225);
if( hifi == true){
link("PROJECTLINK.html");
hifi = false;
ok = false;
}
text("PROJECT NAME", 50, 275);
if( ch == true){
link("PROJECTLINK.html");
ch = false;
ok = false;
}
text("PROJECT NAME", 50, 325);
if( sensor == true){
link("PROJECTLINK.html");
sensor = false;
ok = false;
}
text("PROJECT NAME", 50, 375);
if( splash == true){
link("PROJECTLINK.html");
splash = false;
ok = false;
}
text("PROJECT NAME", 50, 425);
if( ipod == true){
link("PROJECTLINK.html");
ipod = false;
ok = false;
}
text("PROJECT NAME", 50, 475);
if( evo == true){
link("PROJECTLINK.html");
evo = false;
ok = false;
}
text("PROJECT NAME", 50, 525);
if( zoe == true){
link("PROJECTLINK.html");
zoe = false;
ok = false;
}
text("PROJECT NAME", 50, 575);
if( game == true){
link("PROJECTLINK.html");
game = false;
ok = false;
}
text("PROJECT NAME", 50, 625);
if( speak == true){
link("PROJECTLINK.html");
speak = false;
ok = false;
}
text("I AM 8-BIT", 50, 675);
if( eb == true){
link("PROJECTLINK.html");
eb = false;
ok = false;
}
image(menu, 170, 680);
}
}
///////////////////////////////////////////////////////////////////
//*don't touch unless you need to change where it sees the clicks
//////////////////////////////////////////////////////////////////
void keyPressed(){
// doing other things here, and then:
if (key == CODED && keyCode == BACK && (res == true ||ok == true)) {
keyCode = 0;
println(res);
println(ok);
if(res == true) {
// you'll need to set keyCode to 0 if you want to prevent quitting (see above)
res = false;
cl = false;
qual = false;
}
else if (ok == true) {
// you'll need to set keyCode to 0 if you want to prevent quitting (see above)
rfid = false;
hifi = false;
ch = false;
sensor = false;
splash = false;
ipod = false;
evo = false;
zoe = false;
game = false;
speak = false;
eb = false;
ok = false;
}
}
}
void mousePressed(){
if (mouseX > 20 && mouseX < 150 && mouseY > 470 && mouseY < 600 && res == false && ok == false) {
blog = true;
}
else if (mouseX > 160 && mouseX < 300 && mouseY > 470 && mouseY < 600 && res == false && ok == false) {
linked = true;
}
else if (mouseX > 310 && mouseX < 450 && mouseY > 470 && mouseY < 600 && res == false && ok == false) {
fb = true;
}
else if (mouseX > 20 && mouseX < 150 && mouseY > 610 && mouseY < 760 && res == false && ok == false) {
twit = true;
}
else if (mouseX > 160 && mouseX < 300 && mouseY > 610 && mouseY < 760 && res == false) {
ok = true;
}
else if (mouseX > 310 && mouseX < 450 && mouseY > 610 && mouseY < 760 && ok == false) {
res = true;
}
else if (res == true && mouseX > 20 && mouseX < 150 && mouseY > 100 && mouseY < 220 ) {
cl = true;
}
else if (res == true && mouseX > 160 && mouseX < 350 && mouseY > 100 && mouseY < 220 ) {
qual = true;
}
else if (ok == true && mouseY > 135 && mouseY < 174 ) {
rfid = true;
}
else if (ok == true && mouseY > 175 && mouseY < 220 ) {
hifi = true;
}
else if (ok == true && mouseY > 225 && mouseY < 274 ) {
ch = true;
}
else if (ok == true && mouseY > 275 && mouseY < 324 ) {
sensor = true;
}
else if (ok == true && mouseY > 325 && mouseY < 374 ) {
splash = true;
}
else if (ok == true && mouseY > 375 && mouseY < 424 ) {
ipod = true;
}
else if (ok == true && mouseY > 425 && mouseY < 474 ) {
evo = true;
}
else if (ok == true && mouseY > 475 && mouseY < 524 ) {
zoe = true;
}
else if (ok == true && mouseY > 525 && mouseY < 574 ) {
game = true;
}
else if (ok == true && mouseY > 575 && mouseY < 624 ) {
speak = true;
}
else if (ok == true && mouseY > 625 && mouseY < 674 ) {
eb = true;
}
else if ( mouseY > 675 && (ok == true || res == true)) {
home();
}
else {
linked = fb = twit = false;
}
}
You are amazing!
I hope that's not your real number on there...
Where do I begin...
1) Why is this app (if you can call it that) front-page news? It's not an app that lets you or me make a "business card." It's an "app" that is hard-coded with this chick's own information and links. How is this useful to anyone else but her? Way to go XDA, you just gave her free publicity for something that is of no benefit to the rest of the community.
2) Congratulations Stacy. You wrote an app in 6 hours that is essentially a bunch of links and images. This is groundbreaking somehow? At least if this was an app that allows the user create their own version of a business card, it might have some use to the community, but as it stands it's basically self-publicizing drivel. Which leads me to...
3) Even if this app did allow the end-user to create their own business card, I can barely fathom the logistics of how useless that would be in a real world environment. Is someone really going to go around downloading "Business Card" APKs for every person they come into contact with? I know I sure as hell don't want 200 apps taking up my phone's memory. There's already a solution for this problem. It's called a contact list.
Give me a break XDA, does anyone actually screen these apps before they make front-page news, or does someone just go "omg blond chick" and post a story?
XsMagical said:
I hope that's not your real number on there...
Click to expand...
Click to collapse
I wonder how many hits her website has gotten this morning! Looks to be a useful app though.
BTW - welcome to Dallas!
EVOMG said:
Where do I begin...
1) Why is this app (if you can call it that) front-page news? It's not an app that lets you or me make a "business card." It's an "app" that is hard-coded with this chick's own information and links. How is this useful to anyone else but her? Way to go XDA, you just gave her free publicity for something that is of no benefit to the rest of the community.
2) Congratulations Stacy. You wrote an app in 6 hours that is essentially a bunch of links and images. This is groundbreaking somehow? At least if this was an app that allows the user create their own version of a business card, it might have some use to the community, but as it stands it's basically self-publicizing drivel. Which leads me to...
3) Even if this app did allow the end-user to create their own business card, I can barely fathom the logistics of how useless that would be in a real world environment. Is someone really going to go around downloading "Business Card" APKs for every person they come into contact with? I know I sure as hell don't want 200 apps taking up my phone's memory. There's already a solution for this problem. It's called a contact list.
Give me a break XDA, does anyone actually screen these apps before they make front-page news, or does some just go "omg blond chick" and post a story?
Click to expand...
Click to collapse
Priceless response!!!!, while the app seems to have merit, I agree who has the space to have these apks clogging up the memory, perhaps a step further integrate it with a database that can decode it and organize these , in digital form with little to no space requirements, with user access, kind of like a drop box for business associates, Or like a barcode for every android or yphone user , just like the blackberry devices have, your devices barcode and or PIN contains user and contact info, and stores it in your contacts
Thanks for that great tip.
Sent from my PC36100 using XDA App
EVOMG said:
Where do I begin...
1) Why is this app (if you can call it that) front-page news? It's not an app that lets you or me make a "business card." It's an "app" that is hard-coded with this chick's own information and links. How is this useful to anyone else but her? Way to go XDA, you just gave her free publicity for something that is of no benefit to the rest of the community.
2) Congratulations Stacy. You wrote an app in 6 hours that is essentially a bunch of links and images. This is groundbreaking somehow? At least if this was an app that allows the user create their own version of a business card, it might have some use to the community, but as it stands it's basically self-publicizing drivel. Which leads me to...
3) Even if this app did allow the end-user to create their own business card, I can barely fathom the logistics of how useless that would be in a real world environment. Is someone really going to go around downloading "Business Card" APKs for every person they come into contact with? I know I sure as hell don't want 200 apps taking up my phone's memory. There's already a solution for this problem. It's called a contact list.
Give me a break XDA, does anyone actually screen these apps before they make front-page news, or does someone just go "omg blond chick" and post a story?
Click to expand...
Click to collapse
lolz, I hope it was a mindless machine that posted that on the front page. I hear ya harsh cruel truth man, and you threw out some excellent points. I must say that when I clicked that link I expected something else, dare I say I thought I saw something EPIC but it was fueled by my imagination. Though I must say I must say this could be something potentially very useful if it could get past the "all about me" aspect.
I can see how little this was thought out without you saying so and I recommend not showing this to any potential employer as it paints a negative picture. If you want to create some more start by decentralizing it from being a standalone app and integrating contacts(thats what its for)
hope I don't sound quite as harsh as the honest guy above, but anything less would be deceiving you. I'm sure you can find plenty of help around here.
~UGP
I should make an apk full of links and my number..... Maybe that'll get me to the front page :shrug:
Sent from my PC36100 using XDA Premium App
You just ruined her...
Android Business card App
You guys are really ****ed up and cruel.. However it is the truth. I to was expecting something else.. In the end, if Stacy (you) ever come to Miami, we can work on my project and have good sex.. My black on your white... YuP!
StarlahRain said:
You just ruined her...
Click to expand...
Click to collapse
She was already ruined before she even posted that crap! LMAO!!! Ya'lllllllllllll is ****ed up!!! LMAO!!!
Hey guys, I rewrote the code into a simple template for you to use with the Proccessing IDE for Android.
http://wiki.processing.org/w/Android
Friends of mine requested that I make them one too, so I came up with this so that they could simply fill in the blanks and compile it themselves. It is a good intro to basic programming as well as getting started in doing things for Android.
When you get more advanced, you can use the Processing core in Eclipse and eventually to the proper XML stuff.
For right now, enjoy making your own Simple Business card APKs to hand to friends and potential new employers!
*If there is enough interest, I can try and turn this into a program that integrates with your Google contacts and lets people have their own pages like this one has. Make it fill in the blanks and easy to share.

[APP][3.0+] LectureNotes - custom pattern JavaScript codes

As I receive numerous questions concerning the custom pattern JavaScript interface of LectureNotes and how to implement specific patterns, I thought that it might be helpful to post my replies here, which should allow to easily copy them. Please feel invited to post additional ones!
First, a so-called isometric pattern that is quoted at the app's help page (where the code lines are commented)
Code:
width = LN.getWidth();
height = LN.getHeight();
scale = LN.getScale();
step = width / 150 + scale * width / 25;
LN.setStrokeWidth(width / 1000);
for (x = 0; x < width; x += step)
LN.drawLine(x, 0, x, height);
stepX = 2 * step;
stepY = 1.1547 * step;
x1 = 0; y1 = step;
x2 = stepX; y2 = 0;
while ((x1 < width) && (y2 < height)) {
LN.drawLine(x1, y1, x2, y2);
if (y1 < height)
y1 += stepY;
else
x1 += stepX;
if (x2 < width)
x2 += stepX;
else
y2 += stepY;
}
x1 = x2 - stepX; y1 = 0;
y2 = step;
while ((x2 > 0) && (y1 < height)) {
LN.drawLine(x1, y1, x2, y2);
if (x1 > 0)
x1 -= stepX;
else
y1 += stepY;
if (y2 < height)
y2 += stepY;
else
x2 -= stepX;
}
and a simple additional one that places a page number centered at the page bottom
Code:
width = LN.getWidth();
height = LN.getHeight();
page = LN.getPage();
LN.setTextSize(0.02 * width);
LN.setTextAlign(0);
LN.drawText("Page " + page, 0.5 * width, 0.95 * height);
Some more, an eternal calender, one month per page, starting January 2012
Code:
year = 2012;
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
monthdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
month = LN.getPage() - 1;
year += Math.floor(month / 12);
month2 = month % 12;
month = month + 1;
days = monthdays[month2];
if ((month == 2) && (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
days++;
if (month <= 2)
year2 = year - 1;
else
year2 = year;
c = Math.floor(year2 / 100);
y = year2 % 100;
m = ((month + 9) % 12) + 1;
w = (1 + Math.floor(2.6 * m - 0.2) + y +
Math.floor(y / 4) + Math.floor(c / 4) - 2 * c + 7 * 100) % 7;
width = LN.getWidth();
height = LN.getHeight();
size = Math.min(width, height);
stepx = width / 8;
stepy = height / 8;
LN.setTextSize(0.025 * size);
for (d = 0; d < 7; d++)
LN.drawText(weekdays[d], (d + 0.6) * stepx, 1.4 * stepy);
LN.setTextSize(0.05 * size);
LN.setTextAlign(-1);
LN.drawText(months[month2] + " " + year, 7.5 * stepx, 0.25 * stepy + 0.05 * size);
LN.setTextAlign(1);
l = 0;
for (d = 1; d <= days; d++) {
LN.drawText(d, stepx * (w + 0.6), stepy * (l + 2.4));
if ((++w == 7) && (d != days)) {
w = 0;
l++;
}
}
for (x = 0.5 * stepx; x < width; x += stepx)
LN.drawLine(x, 1.5 * stepy, x, (l + 2.5) * stepy);
for (y = 1.5 * stepy; y < (l + 3) * stepy; y += stepy)
LN.drawLine(0.5 * stepx, y, 7.5 * stepx, y);
and another simple one, a checkered pattern in which every fifth line is thicker
Code:
width = LN.getWidth();
height = LN.getHeight();
scale = LN.getScale();
LN.drawCheckeredPattern(scale, false);
LN.setStrokeWidth(0.002 * width);
step = width / 150 + scale * width / 25;
for(y = step / 2; y < height; y += 5 * step) {
LN.drawLine(0, y, width, y);
}
for(x = step / 2; x < width; x += 5 * step) {
LN.drawLine(x, 0, x, height);
}
Today two examples for writing music, a simple one
Code:
width = LN.getWidth();
height = LN.getHeight();
LN.setStrokeWidth(0.001 * width);
left = 0.05 * width;
right = 0.95 * width;
step = 0.005 * height;
for(y = 0.05 * height; y < 0.95 * height; y += 0.05 * height) {
LN.drawLine(left, y, right, y);
LN.drawLine(left, y + step, right, y + step);
LN.drawLine(left, y + 2 * step, right, y + 2 * step);
LN.drawLine(left, y + 3 * step, right, y + 3 * step);
LN.drawLine(left, y + 4 * step, right, y + 4 * step);
LN.drawLine(left, y, left, y + 4 * step);
LN.drawLine(right, y, right, y + 4 * step);
}
and a double one
Code:
width = LN.getWidth();
height = LN.getHeight();
LN.setStrokeWidth(0.001 * width);
left = 0.05 * width;
right = 0.95 * width;
step = 0.005 * height;
for(y = 0.05 * height; y < 0.9 * height; y += 0.1 * height) {
LN.drawLine(left, y, right, y);
LN.drawLine(left, y + step, right, y + step);
LN.drawLine(left, y + 2 * step, right, y + 2 * step);
LN.drawLine(left, y + 3 * step, right, y + 3 * step);
LN.drawLine(left, y + 4 * step, right, y + 4 * step);
LN.drawLine(left, y + 9 * step, right, y + 9 * step);
LN.drawLine(left, y + 10 * step, right, y + 10 * step);
LN.drawLine(left, y + 11 * step, right, y + 11 * step);
LN.drawLine(left, y + 12 * step, right, y + 12 * step);
LN.drawLine(left, y + 13 * step, right, y + 13 * step);
LN.drawLine(left, y, left, y + 13 * step);
LN.drawLine(right, y, right, y + 4 * step);
LN.drawLine(right, y + 9 * step, right, y + 13 * step);
}
(step size etc. can easily be adjusted).
Since v1.16.13, there is an additional JavaScript command LN.setColor(r, g, b) that allows to use colors other then the one chosen in the dialog. This allows now, for instance, a ruled pattern with a red line on the left side
Code:
width = LN.getWidth();
height = LN.getHeight();
LN.drawRuledPattern(LN.getScale(), false);
LN.setStrokeWidth(0.002 * width);
LN.setColor(1, 0, 0);
LN.drawLine(0.05 * width, 0, 0.05 * width, height);
isometric problems
acadoid said:
As I receive numerous questions concerning the custom pattern JavaScript interface of LectureNotes and how to implement specific patterns, I thought that it might be helpful to post my replies here, which should allow to easily copy them. Please fell invited to post additional on;
Click to expand...
Click to collapse
I love this app. I am using it on a Galaxy Note 10.1. The isometric script give an error message that it takes too long and aborts. Thought you would want to know.
By the way, I tested it three times using cut ans paste. Once from the help page, and twice from here.
Keep up the good work.
@RETIEF: To double-check, I copied and paste the content shown in this thread, and it works. Note, however, that on my Samsung Galaxy Note 10.1 (for instance in difference to my Lenovo ThinkPad Tablet), the copy/paste converts a `new line´ into nothing (instead of a space), this causes problems, for instance `else y1´ becomes `elsey1´, which is wrong. Please check whether this is causing the problem in your case.
Attempt to fix calendar
acadoid said:
@RETIEF: To double-check, I copied and paste the content shown in this thread, and it works. Note, however, that on my Samsung Galaxy Note 10.1 (for instance in difference to my Lenovo ThinkPad Tablet), the copy/paste converts a `new line´ into nothing (instead of a space), this causes problems, for instance `else y1´ becomes `elsey1´, which is wrong. Please check whether this is causing the problem in your case.
Click to expand...
Click to collapse
I didn't have that exact problem, but the if else structures left out lines in the paste so that that all read if (xxxxx); else ;next line.
I manually edited the script to match exactly what was posted here and I still get the same error message. This is for the isometric code.
On the calendar code, if I use a task killer (I use the factory Samsung one), I can get the code to load and execute if I stopped on January. But if I left the document later in the year, I get the same error message.
I'm no coder (at least not since the Fortran G and Turbo Pascal days), but I wounder if extending the process time a second would solve the problem.
Like I said. I'm no coder.
In any case, I appreciate your help. I'm sure you have better things to do.
@RETIEF: All the posted codes work fine on my Samsung Galaxy Note 10.1. I can increase the maximal time, but I do not think that this is the problem. Have you tried to share such page or export it to PDF? In these cases, the maximal waiting time is ten times longer (these operations are not time critical), so if you get an abort message there, then something is wrong in your code.
If you drop me an email, I can send the code as email attachment to you, this will exclude all possible sources of error.
PMed you with address. Didn't now your address.
acadoid said:
@RETIEF: All the posted codes work fine on my Samsung Galaxy Note 10.1. I can increase the maximal time, but I do not think that this is the problem. Have you tried to share such page or export it to PDF? In these cases, the maximal waiting time is ten times longer (these operations are not time critical), so if you get an abort message there, then something is wrong in your code.
If you drop me an email, I can send the code as email attachment to you, this will exclude all possible sources of error.
Click to expand...
Click to collapse
see the PM
Edit. I get a partial rendering in landscape mode before abort. I get horizontal lines, and one diagonal in the upper left.
Isometric paper
Thanks for the e-mail. It works like a champ. I've talked with a lot of developers in my time, but you are the most responsive and responsible I have ever had the pleasure to know. Thanks.
@RETIEF: Curious, the text in the post above is copied and pasted from the same file. In any case, glad that it works.
Heye acadoid. Really dig the app, but im looking for something with type capabilities as well. Are you thinking about implementng this at all?
I am familiar with other apps, but some offer too much and have strange and annoying options (freenote) or great simple user and user friendly text environments with no drawing capabilities(jotterpad hd).
@jewnersey: LectureNotes has a text drawing tool for typed text, but this is intended for a keyword or a small phrase, not for longer text. To improve in this respect is on my agenda.
Note that this is not quite the right thread, there are several general threads on LectureNotes, this one is specific for custom paper pattern.
Week-by-week calendar
Below is a calendar which shows one week at a time. The width of the paper should be twice the height for this calendar to look right.
Editable parameters:
line 1 through 3: Starting date of the calendar
line 9 through 19: text sizes, margins, size of free space on weekdays, start and end hour of weekdays, a few colors
I made this for myself, and thought I might as well share it in case someone else can make use of it. I also uploaded a couple of screenshots.
Thanks for giving us the opportunity of making custom backgrounds!
Code:
year = 2012;
month = 11;
day = 20;
relativeWeek = LN.getPage()-1;
width = LN.getWidth();
height = LN.getHeight();
headertext = height * 0.05;
headerheight = height * 0.10;
toplineheight = headerheight + headertext;
leftmargin = height * 0.1;
rightmargin = leftmargin;
noteSpace = height * 0.2;
startHour = 7;
endHour = 17;
defaultColor = [150,150,150];
headlineColor = [0,0,0];
weekColors = [[208,0,250],[0,200,240],[92,255,1],[255,255,0],[255,146,1],[255,9,32],[255,25,145]];
monthdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
monthdays[1] = 29;
/* calculate what date the first monday is */
year2 = year;
if (month <= 2)
--year2;
c = Math.floor(year2 / 100);
y = year2 % 100;
m = ((month + 9) % 12) + 1;
firstweekday = (Math.floor(2.6 * m - 0.2) + y + Math.floor(y / 4) + Math.floor(c / 4) - 2 * c + 7 * 100) % 7;
/* 0 is monday */
firstmonday = (7 - firstweekday) % 7 + 1;
/* convert day and month so that they represent the monday of the user inputted week */
if (day < firstmonday) {
--month;
if (month == 0) {
month = 12;
--year;
monthdays[1] = 28;
if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
monthdays[1] = 29;
}
day = monthdays[month-1] + firstmonday - 7;
} else {
day = firstmonday + 7*Math.floor((day-firstmonday)/7);
}
/* work out the year, month, day and week of the current sheet */
day += 7*relativeWeek;
while (day > monthdays[month-1]) {
day -= monthdays[month-1];
++month;
if (month == 13) {
month = 1;
++year;
monthdays[1] = 28;
if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
monthdays[1] = 29;
}
}
/* calculate the week number of user input */
totalDays = day;
for (i = 0; i < month-1; ++i)
totalDays += monthdays[i];
week = Math.ceil(totalDays/7);
/* Make colors for each day */
stepx = (width-leftmargin-rightmargin)/6;
i = 0;
for (x = leftmargin; x-leftmargin <= 5.5*stepx; x += stepx) {
/* create lines for each half hour */
if (x-leftmargin < 4.5*stepx) {
y = toplineheight+headertext*1.1;
LN.setColor( weekColors[i][0]/255, weekColors[i][1]/255, weekColors[i][2]/255 );
LN.drawFilledRect( x, toplineheight, x+stepx, y );
} else {
y1 = toplineheight+headertext*1.1;
y2 = (toplineheight+height)/2+headertext*1.1;
LN.setColor( weekColors[i][0]/255, weekColors[i][1]/255, weekColors[i][2]/255 );
LN.drawFilledRect( x, toplineheight, x+stepx, y1 );
++i;
LN.setColor( weekColors[i][0]/255, weekColors[i][1]/255, weekColors[i][2]/255 );
LN.drawFilledRect( x, (toplineheight+height)/2, x+stepx, y2 );
}
LN.setStrokeWidth(4);
++i;
}
/* Reset color */
LN.setColor( defaultColor[0]/255, defaultColor[1]/255, defaultColor[2]/255 );
/* Drawing the main lines */
stepx = (width-leftmargin-rightmargin)/6;
stepy = (height-toplineheight-headertext*1.01-noteSpace)/(2+endHour-startHour);
LN.setTextAlign(1);
LN.setTextSize(stepy*0.9);
for (x = leftmargin; x-leftmargin < 6.5*stepx; x += stepx) {
LN.drawLine(x, toplineheight, x, height);
if (x-leftmargin < 5.5*stepx) {
/* create lines for each half hour */
LN.setStrokeWidth(1);
if (x-leftmargin < 4.5*stepx) {
i = -2;
for (y = toplineheight+headertext*1.1; y < height-noteSpace; y += stepy) {
LN.drawLine(x, y, x+stepx, y);
if (++i > 0) {
LN.drawText(startHour+i-1, x, y-stepy*0.05);
LN.drawLine(x+LN.getTextWidth(startHour+i-1), y-stepy/2, x+stepx, y-stepy/2);
}
}
} else {
LN.drawLine(x, toplineheight+headertext*1.1, x+stepx, toplineheight+headertext*1.1);
LN.drawLine(x, (toplineheight+height)/2+headertext*1.1, x+stepx, (toplineheight+height)/2+headertext*1.1);
}
LN.setStrokeWidth(4);
}
}
LN.drawLine(leftmargin, toplineheight, width-rightmargin, toplineheight);
LN.drawLine(leftmargin+5*stepx, (toplineheight+height)/2, width-rightmargin, (toplineheight+height)/2);
/* Write which week it is */
LN.setTextSize(headertext);
LN.setColor( headlineColor[0]/255, headlineColor[1]/255, headlineColor[2]/255 );
LN.setTextAlign(-1);
LN.drawText("Week " + week, width-rightmargin, headerheight);
oldMonth = month;
oldYear = year;
LN.setTextAlign(0);
for (i = 0; i < 7; ++i){
if (day > monthdays[month-1]) {
day -= monthdays[month-1];
++month;
if (month == 13) {
month = 1;
++year;
monthdays[1] = 28;
if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
monthdays[1] = 29;
}
}
if (i < 6) {
LN.drawText(day + " " + weekdays[i], leftmargin + stepx * (i + 0.5), toplineheight+headertext );
} else {
LN.drawText(day + " " + weekdays[i], leftmargin + stepx * (i - 0.5), (toplineheight+height)/2+headertext );
}
++day;
}
LN.setTextAlign(1);
if (oldMonth == month)
LN.drawText(months[month-1], leftmargin, headerheight );
else {
LN.drawText(months[oldMonth-1] + " / " + months[month-1], leftmargin, headerheight );
}
LN.setTextAlign(0);
if (oldYear == year)
LN.drawText(year, leftmargin+(width-leftmargin-rightmargin)/2, headerheight );
else {
LN.drawText(oldYear + " / " + year, leftmargin+(width-leftmargin-rightmargin)/2, headerheight );
}
Thanks for the Weekly Calendar
Thanks for this post. It took a couple of edits to get it perfect on my note 10.1, but I like it. Thanks for your work and sharing.:good:
Egenskaper said:
Below is a calendar which shows one week at a time. The width of the paper should be twice the height for this calendar to look right.
Editable parameters:
Click to expand...
Click to collapse
RETIEF said:
Thanks for this post. It took a couple of edits to get it perfect on my note 10.1, but I like it. Thanks for your work and sharing.:good:
Click to expand...
Click to collapse
Just turned on to LectureNotes and this Forum will make me appreciate it all the more.
page x of y
The programmer added the funtion LNgetNumberOfPages();
My custom pattern is checkered and shoes the number of pages (page x of y) at the bottom:
width = LN.getWidth();
height = LN.getHeight();
page = LN.getPage ();
pages = LN.getNumberOfPages();
scale = LN.getScale ();
LN.drawCheckeredPattern (scale, false);
LN.setColor (1, 1, 1);
LN.drawFilledRect(width/2-0.07*width, height-0.025*height, width/2+0.07*width, height);
LN.setColor (0.4, 0.4,0.4);
LN.setTextSize (0.02 * width);
LN.setTextAlign (0);
LN.drawText("Seite " + page + " von " + pages , 0.5*width, 0.99*height);
Hope you like it as well.
Thanks
Thanks. This works well. Anyone skilled enough to make one that is checkered with every fifth line bold or red?
tech.towan said:
The programmer added the funtion LNgetNumberOfPages();
My custom pattern is checkered and shoes the number of pages (page x of y) at the bottom:
width = LN.getWidth();
height = LN.getHeight();
page = LN.getPage ();
pages = LN.getNumberOfPages();
scale = LN.getScale ();
LN.drawCheckeredPattern (scale, false);
LN.setColor (1, 1, 1);
LN.drawFilledRect(width/2-0.07*width, height-0.025*height, width/2+0.07*width, height);
LN.setColor (0.4, 0.4,0.4);
LN.setTextSize (0.02 * width);
LN.setTextAlign (0);
LN.drawText("Seite " + page + " von " + pages , 0.5*width, 0.99*height);
Hope you like it as well.
Click to expand...
Click to collapse
@RETIEF: Try
Code:
width = LN.getWidth();
height = LN.getHeight();
scale = LN.getScale();
LN.drawCheckeredPattern(scale, false);
LN.setStrokeWidth(0.002 * width);
step = width / 150 + scale * width / 25;
for(y = step / 2; y < height; y += 5 * step) {
LN.drawLine(0, y, width, y);
}
for(x = step / 2; x < width; x += 5 * step) {
LN.drawLine(x, 0, x, height);
}
This draws a thicker line every fifth line, the scale of the pattern is controlled by the slider in the notebook settings dialog. To get red lines, add a
Code:
LN.setColor(1, 0, 0);
after the LN.setStrokeWidth.
thanks
this is perfect. Thanks.
acadoid said:
@RETIEF: Try
Code:
width = LN.getWidth();
height = LN.getHeight();
scale = LN.getScale();
LN.drawCheckeredPattern(scale, false);
LN.setStrokeWidth(0.002 * width);
step = width / 150 + scale * width / 25;
for(y = step / 2; y < height; y += 5 * step) {
LN.drawLine(0, y, width, y);
}
for(x = step / 2; x < width; x += 5 * step) {
LN.drawLine(x, 0, x, height);
}
This draws a thicker line every fifth line, the scale of the pattern is controlled by the slider in the notebook settings dialog. To get red lines, add a
Code:
LN.setColor(1, 0, 0);
after the LN.setStrokeWidth.
Click to expand...
Click to collapse

Image not saving new dimensions after resize using xamarin c#

I am only posting here because it wont allow me to post in the other forums.
i am taking a photo with my app then rotating if needed then resizing. after that i am saving the new rotated and scaled down pic to the sd card. the photo does rotate and the byte size changes but when i view the new photo it still has the same dimensions as the orginal photo.
my resizing and saving calls are
Code:
//resize for preview
using (var bitmap = _file.Path.LoadAndResizeBitmap(300, 225))
{
//resize for saving
Bitmap resized = _file.Path.LoadAndResizeBitmap(800, 600);
BitmapHelpers.saveBitmap(resized,_user_id,_dateStr);
//shows preview resize
photo.SetImageBitmap(ConvertToBitmap(bitmap));
}
public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height)
{
//First we get the diamensions of the file on disk
BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
BitmapFactory.DecodeFile(fileName, options);
//Next we calculate the ratio that we need to resize the image by
//in order to fit the requested dimensions.
int outHeight = options.OutHeight;
int outWidth = options.OutWidth;
int inSampleSize = 1;
if (outHeight > height || outWidth > width)
{
inSampleSize = outWidth > outHeight
? outHeight / height : outWidth / width;
}
//Now we will load the image
options.InSampleSize = inSampleSize;
options.InJustDecodeBounds = false;
Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);
// Images are being saved in landscape, so rotate them back to portrait if they were taken in portrait
Matrix mtx = new Matrix();
Android.Media.ExifInterface exif = new Android.Media.ExifInterface(fileName);
string orientation = exif.GetAttribute(Android.Media.ExifInterface.TagOrientation);
switch (orientation)
{
case "6": // portrait
mtx.PreRotate(90);
resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
mtx.Dispose();
mtx = null;
break;
case "1": // landscape
//mtx.PreRotate(-90);
//resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
//mtx.Dispose();
//mtx = null;
break;
default:
mtx.PreRotate(90);
resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
mtx.Dispose();
mtx = null;
break;
}
return resizedBitmap;
}
public static void saveBitmap(Bitmap bitmap, int userId, String dateStr)
{
var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
String fileName = "bb_" + userId + "_" + dateStr + "_new.jpg";
var filePath = System.IO.Path.Combine(sdCardPath, fileName);
var stream = new FileStream(filePath, FileMode.Create);
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
stream.Close();
}
when it does the first _file.Path.LoadAndResizeBitmap(300, 225) the inSampleSize is 3 and returns new height,width of 640,360
when it does _file.Path.LoadAndResizeBitmap(800, 600) the inSampleSize is 1 and returns original values of 1280,720

How to crop bitmaps according to size of a custom view

Trying to make a motion detection app. The intention is to make the app take pictures when motion is detected by comparing two images. Up to this part, the app is working fine.
Requirement:
To specify area of detection by a custom view. So that, the pictures will be captured only if a motion is detected inside the defined area by calculating the detection area.
What I have tried:
Created a movable custom view, like a crop view of which the dimensions (`Rect`) are saved in the preference each time when the view is moved.
In the detection thread I tried setting the width and height from the preference like
Code:
private int width = Prefe.DetectionArea.width();
private int height = Prefe.DetectionArea.height();
But it didn't work.
What is not working:
The motion detection from inside the custom view is not working. I believe that the bitmaps must be cropped according to the size of the custom view.
Please help me by explaining how this could be achieved so that the motion detection will happen according to the size of the custom view. I'm new to android and trying to self learn, any help is appreciated.
MotionDetectionActivity.java
Code:
public class MotionDetectionActivity extends SensorsActivity {
private static final String TAG = "MotionDetectionActivity";
private static long mReferenceTime = 0;
private static IMotionDetection detector = null;
public static MediaPlayer song;
public static Vibrator mVibrator;
private static SurfaceView preview = null;
private static SurfaceHolder previewHolder = null;
private static Camera camera = null;
private static boolean inPreview = false;
private static AreaDetectorView mDetector;
private static FrameLayout layoutDetectorArea;
static FrameLayout layoutMain;
static View mView;
private static volatile AtomicBoolean processing = new AtomicBoolean(false);
/**
* {@inheritDoc}
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.main);
mVibrator = (Vibrator)this.getSystemService(VIBRATOR_SERVICE);
layoutMain=(FrameLayout)findViewById(R.id.layoutMain);
preview = (SurfaceView) findViewById(R.id.preview);
previewHolder = preview.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mView=layoutMain;
mDetector= (AreaDetectorView) findViewById(R.id.viewDetector);
layoutDetectorArea=(FrameLayout) findViewById(R.id.layoutDetectArea);
ToggleButton toggle = (ToggleButton) findViewById(R.id.simpleToggleButton);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// The toggle is enabled
} else {
// The toggle is disabled
}
}
});
if (Preferences.USE_RGB) {
detector = new RgbMotionDetection();
} else if (Preferences.USE_LUMA) {
detector = new LumaMotionDetection();
} else {
// Using State based (aggregate map)
detector = new AggregateLumaMotionDetection();
}
}
/**
* {@inheritDoc}
*/
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
/**dd:
* Song play # 1
* Camera callback
*
* {@inheritDoc}
*/
@Override
public void onPause() {
super.onPause();
if(song!=null && song.isPlaying())
{
song.stop();}
camera.setPreviewCallback(null);
if (inPreview) camera.stopPreview();
inPreview = false;
camera.release();
camera = null;
}
/**
* {@inheritDoc}
*/
@Override
public void onResume() {
super.onResume();
camera = Camera.open();
}
private PreviewCallback previewCallback = new PreviewCallback() {
/**
* {@inheritDoc}
*/
@Override
public void onPreviewFrame(byte[] data, Camera cam) {
if (data == null) return;
Camera.Size size = cam.getParameters().getPreviewSize();
if (size == null) return;
if (!GlobalData.isPhoneInMotion()) {
DetectionThread thread = new DetectionThread(data, size.width, size.height);
thread.start();
}
}
};
private SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {
/**
* {@inheritDoc}
*/
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
camera.setPreviewDisplay(previewHolder);
camera.setPreviewCallback(previewCallback);
} catch (Throwable t) {
Log.e("Prek", "Exception in setPreviewDisplay()", t);
}
}
/**
* {@inheritDoc}
*/
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if(camera != null) {
Camera.Parameters parameters = camera.getParameters();
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
Camera.Size size = getBestPreviewSize(width, height, parameters);
if (size != null) {
parameters.setPreviewSize(size.width, size.height);
Log.d(TAG, "Using width=" + size.width + " height=" + size.height);
}
camera.setParameters(parameters);
camera.startPreview();
inPreview = true;
}
//AreaDetectorView.InitDetectionArea();
}
/**
* {@inheritDoc}
*/
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// Ignore
}
};
private static Camera.Size getBestPreviewSize(int width, int height, Camera.Parameters parameters) {
Camera.Size result = null;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width <= width && size.height <= height) {
if (result == null) {
result = size;
} else {
int resultArea = result.width * result.height;
int newArea = size.width * size.height;
if (newArea > resultArea) result = size;
}
}
}
return result;
}
//***************Detection Class******************//
private final class DetectionThread extends Thread {
private byte[] data;
private int width;
private int height;
public DetectionThread(byte[] data, int width, int height) {
this.data = data;
this.width = width;
this.height = height;
}
/**
* {@inheritDoc}
*/
@Override
public void run() {
if (!processing.compareAndSet(false, true)) return;
// Log.d(TAG, "BEGIN PROCESSING...");
try {
// Previous frame
int[] pre = null;
if (Preferences.SAVE_PREVIOUS) pre = detector.getPrevious();
// Current frame (with changes)
// long bConversion = System.currentTimeMillis();
int[] img = null;
if (Preferences.USE_RGB) {
img = ImageProcessing.decodeYUV420SPtoRGB(data, width, height);
} else {
img = ImageProcessing.decodeYUV420SPtoLuma(data, width, height);
}
// Current frame (without changes)
int[] org = null;
if (Preferences.SAVE_ORIGINAL && img != null) org = img.clone();
if (img != null && detector.detect(img, width, height)) {
// The delay is necessary to avoid taking a picture while in
// the
// middle of taking another. This problem can causes some
// phones
// to reboot.
long now = System.currentTimeMillis();
if (now > (mReferenceTime + Preferences.PICTURE_DELAY)) {
mReferenceTime = now;
//mVibrator.vibrate(10);
Bitmap previous = null;
if (Preferences.SAVE_PREVIOUS && pre != null) {
if (Preferences.USE_RGB) previous = ImageProcessing.rgbToBitmap(pre, width, height);
else previous = ImageProcessing.lumaToGreyscale(pre, width, height);
}
Bitmap original = null;
if (Preferences.SAVE_ORIGINAL && org != null) {
if (Preferences.USE_RGB) original = ImageProcessing.rgbToBitmap(org, width, height);
else original = ImageProcessing.lumaToGreyscale(org, width, height);
}
Bitmap bitmap = null;
if (Preferences.SAVE_CHANGES) {
if (Preferences.USE_RGB) bitmap = ImageProcessing.rgbToBitmap(img, width, height);
else bitmap = ImageProcessing.lumaToGreyscale(img, width, height);
}
Log.i(TAG, "Saving.. previous=" + previous + " original=" + original + " bitmap=" + bitmap);
Looper.prepare();
new SavePhotoTask().execute(previous, original, bitmap);
} else {
Log.i(TAG, "Not taking picture because not enough time has passed since the creation of the Surface");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
processing.set(false);
}
// Log.d(TAG, "END PROCESSING...");
processing.set(false);
}
};
private static final class SavePhotoTask extends AsyncTask<Bitmap, Integer, Integer> {
/**
* {@inheritDoc}
*/
@Override
protected Integer doInBackground(Bitmap... data) {
for (int i = 0; i < data.length; i++) {
Bitmap bitmap = data[i];
String name = String.valueOf(System.currentTimeMillis());
if (bitmap != null) save(name, bitmap);
}
return 1;
}
private void save(String name, Bitmap bitmap) {
File photo = new File(Environment.getExternalStorageDirectory(), name + ".jpg");
if (photo.exists()) photo.delete();
try {
FileOutputStream fos = new FileOutputStream(photo.getPath());
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
} catch (java.io.IOException e) {
Log.e("PictureDemo", "Exception in photoCallback", e);
}
}
}
}
AreaDetectorView.java
Code:
public class AreaDetectorView extends LinearLayout {
public static int Width;
public static int Height;
private static Paint BoxPaint = null;
private static Paint TextPaint = null;
private static Paint ArrowPaint = null;
private static Path mPath = null;
private static Rect mRect = null;
private static int lastX, lastY = 0;
private static boolean mBoxTouched = false;
private static boolean mArrowTouched = false;
private static Context mContext;
private static int ArrowWidth = 0;
private static Paint BoxPaint2 = null;
public AreaDetectorView(Context context) {
super(context);
mContext = context;
}
//attrs was not there
public AreaDetectorView(Context context, AttributeSet attrs) {
super(context,attrs);
mContext = context;
// TODO Auto-generated constructor stub
if (!this.getRootView().isInEditMode()) {
ArrowWidth =GetDisplayPixel(context, 30);
}
//InitDetectionArea();
InitMemberVariables();
setWillNotDraw(false);
}
public static int GetDisplayPixel(Context paramContext, int paramInt)
{
return (int)(paramInt * paramContext.getResources().getDisplayMetrics().density + 0.5F);
}
public static void InitMemberVariables() {
if (BoxPaint == null) {
BoxPaint = new Paint();
BoxPaint.setAntiAlias(true);
BoxPaint.setStrokeWidth(2.0f);
//BoxPaint.setStyle(Style.STROKE);
BoxPaint.setStyle(Style.FILL_AND_STROKE);
BoxPaint.setColor(ContextCompat.getColor(mContext, R.color.bwff_60));
}
if (ArrowPaint == null) {
ArrowPaint = new Paint();
ArrowPaint.setAntiAlias(true);
ArrowPaint.setColor(ContextCompat.getColor(mContext,R.color.redDD));
ArrowPaint.setStyle(Style.FILL_AND_STROKE);
}
if (TextPaint == null) {
TextPaint = new Paint();
TextPaint.setColor(ContextCompat.getColor(mContext,R.color.yellowL));
TextPaint.setTextSize(16);
//txtPaint.setTypeface(lcd);
TextPaint.setStyle(Style.FILL_AND_STROKE);
}
if (mPath == null) {
mPath = new Path();
} else {
mPath.reset();
}
if (mRect == null) {
mRect = new Rect();
}
if (BoxPaint2 == null) {
BoxPaint2 = new Paint();
BoxPaint2.setAntiAlias(true);
BoxPaint2.setStrokeWidth(2.0f);
//BoxPaint.setStyle(Style.STROKE);
BoxPaint2.setStyle(Style.STROKE);
BoxPaint2.setColor(ContextCompat.getColor(mContext,R.color.bwff_9e));
}
}
public static void InitDetectionArea() {
try {
int w = Prefe.DetectionArea.width();
int h = Prefe.DetectionArea.height();
int x = Prefe.DetectionArea.left;
int y = Prefe.DetectionArea.top;
// ver 2.6.0
if (Prefe.DetectionArea.left == 1
&& Prefe.DetectionArea.top == 1
&& Prefe.DetectionArea.right == 1
&& Prefe.DetectionArea.bottom == 1) {
w = Prefe.DisplayWidth / 4;
h = Prefe.DisplayHeight / 3;
// ver 2.5.9
w = Width / 4;
h = Height / 3;
Prefe.DetectorWidth = w; //UtilGeneralHelper.GetDisplayPixel(this, 100);
Prefe.DetectorHeight = h; //UtilGeneralHelper.GetDisplayPixel(this, 100);
x = (Prefe.DisplayWidth / 2) - (w / 2);
y = (Prefe.DisplayHeight / 2) - (h / 2);
// ver 2.5.9
x = (Width / 2) - (w / 2);
y = (Height / 2) - (h / 2);
}
//Prefe.DetectionArea = new Rect(x, x, x + Prefe.DetectorWidth, x + Prefe.DetectorHeight);
Prefe.DetectionArea = new Rect(x, y, x + w, y + h);
Prefe.gDetectionBitmapInt = new int[Prefe.DetectionArea.width() * Prefe.DetectionArea.height()];
Prefe.gDetectionBitmapIntPrev = new int[Prefe.DetectionArea.width() * Prefe.DetectionArea.height()];
} catch (Exception e) {
e.printStackTrace();
}
}
public static void SetDetectionArea(int x, int y, int w, int h) {
try {
Prefe.DetectionArea = new Rect(x, y, w, h);
} catch (Exception e) {
e.printStackTrace();
}
}
private void DrawAreaBox(Canvas canvas) {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
try {
if (this.getRootView().isInEditMode()) {
super.dispatchDraw(canvas);
return;
}
//canvas.save(Canvas.MATRIX_SAVE_FLAG);
//Prefe.DetectionAreaOrient = UtilGeneralHelper.GetDetectRectByOrientation();
canvas.drawColor(0);
mPath.reset();
canvas.drawRect(Prefe.DetectionArea, BoxPaint);
mPath.moveTo(Prefe.DetectionArea.right - ArrowWidth, Prefe.DetectionArea.bottom);
mPath.lineTo(Prefe.DetectionArea.right, Prefe.DetectionArea.bottom - ArrowWidth);
mPath.lineTo(Prefe.DetectionArea.right, Prefe.DetectionArea.bottom);
mPath.lineTo(Prefe.DetectionArea.right - ArrowWidth, Prefe.DetectionArea.bottom);
mPath.close();
canvas.drawPath(mPath, ArrowPaint);
mPath.reset();
//canvas.drawRect(Prefe.DetectionAreaOrient, BoxPaint2);
//canvas.drawRect(Prefe.DetectionAreaOrientPort, BoxPaint2);
TextPaint.setTextSize(16);
//TextPaint.setLetterSpacing(2);
TextPaint.setColor(ContextCompat.getColor(mContext,R.color.bwff));
TextPaint.getTextBounds(getResources().getString(R.string.str_detectarea), 0, 1, mRect);
canvas.drawText(getResources().getString(R.string.str_detectarea),
Prefe.DetectionArea.left + 4,
Prefe.DetectionArea.top + 4 + mRect.height(),
TextPaint);
int recH = mRect.height();
TextPaint.setStrokeWidth(1.2f);
TextPaint.setTextSize(18);
TextPaint.setColor(ContextCompat.getColor(mContext,R.color.redD_9e));
TextPaint.getTextBounds(getResources().getString(R.string.str_dragandmove), 0, 1, mRect);
canvas.drawText(getResources().getString(R.string.str_dragandmove),
Prefe.DetectionArea.left + 4,
Prefe.DetectionArea.top + 20 + mRect.height()*2,
TextPaint);
TextPaint.getTextBounds(getResources().getString(R.string.str_scalearea), 0, 1, mRect);
canvas.drawText(getResources().getString(R.string.str_scalearea),
Prefe.DetectionArea.left + 4,
Prefe.DetectionArea.top + 36 + mRect.height()*3,
TextPaint);
super.dispatchDraw(canvas);
//canvas.restore();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onDraw(Canvas canvas) {
try {
super.onDraw(canvas);
invalidate();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean retValue = true;
int X = (int)event.getX();
int Y = (int)event.getY();
//AppMain.txtLoc.setText(String.valueOf(X) + ", " + String.valueOf(Y));
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mBoxTouched = TouchedInBoxArea(X, Y);
//AppMain.txtLoc.setText("BoxTouched: " + String.valueOf(mBoxTouched));
if (!mBoxTouched) break;
lastX = X;
lastY = Y;
BoxPaint.setStyle(Style.FILL_AND_STROKE);
BoxPaint.setColor(ContextCompat.getColor(mContext,R.color.redD_9e));
mArrowTouched = TouchedInArrow(X, Y);
//AppMain.txtLoc.setText("ArrowTouched: " + String.valueOf(mBoxTouched));
if (mArrowTouched) {
ArrowPaint.setColor(ContextCompat.getColor(mContext,R.color.bwff_9e));
}
break;
case MotionEvent.ACTION_MOVE:
if (!mBoxTouched) break;
int moveX = X - lastX;
int moveY = Y - lastY;
//AppMain.txtLoc.setText("Move X, Y: " + String.valueOf(moveX) + "," + String.valueOf(moveY));
if (!mArrowTouched) {
if (Prefe.DetectionArea.left + moveX < 0) {
break;
}
// if (Prefe.DetectionArea.right + moveX > Prefe.gDisplay.getWidth()) {
// break;
// }
// ver 2.5.9
if (Prefe.DetectionArea.right + moveX > Width) {
break;
}
if (Prefe.DetectionArea.top + moveY < 0) {
break;
}
// if (Prefe.DetectionArea.bottom + moveY > Prefe.gDisplay.getHeight()) {
// break;
// }
// ver 2.5.9
if (Prefe.DetectionArea.bottom + moveY > Height) {
break;
}
}
if (mArrowTouched) {
if ((Prefe.DetectionArea.width() + moveX) < ArrowWidth * 2){
break;
}
if ((Prefe.DetectionArea.height() + moveY) < ArrowWidth * 2) {
break;
}
Prefe.DetectionArea.right += moveX;
Prefe.DetectionArea.bottom += moveY;
//Log.i("DBG", "W,H: " + String.valueOf(Prefe.DetectionArea.width()) + "," + String.valueOf(Prefe.DetectionArea.height()));
} else {
Prefe.DetectionArea.left += moveX;
Prefe.DetectionArea.right += moveX;
Prefe.DetectionArea.top += moveY;
Prefe.DetectionArea.bottom += moveY;
}
lastX = X;
lastY = Y;
//AppMain.txtLoc.setText(String.valueOf(Prefe.DetectionArea.left) + ", " + String.valueOf(Prefe.DetectionArea.top));
break;
case MotionEvent.ACTION_UP:
mBoxTouched = false;
mArrowTouched = false;
//BoxPaint.setStyle(Style.STROKE);
BoxPaint.setStyle(Style.FILL_AND_STROKE);
BoxPaint.setColor(ContextCompat.getColor(mContext,R.color.bwff_60));
ArrowPaint.setColor(ContextCompat.getColor(mContext,R.color.redDD));
//AppMain.txtLoc.setText(String.valueOf(Prefe.DetectionArea.left) + ", " + String.valueOf(Prefe.DetectionArea.top));
if (Prefe.DetectionArea.left < 0) {
Prefe.DetectionArea.left = 0;
}
// if (Prefe.DetectionArea.right > Prefe.gDisplay.getWidth()) {
// Prefe.DetectionArea.right = Prefe.gDisplay.getWidth();
// }
// ver 2.5.9
if (Prefe.DetectionArea.right > Width) {
Prefe.DetectionArea.right = Width;
}
if (Prefe.DetectionArea.top < 0) {
Prefe.DetectionArea.top = 0;
}
// if (Prefe.DetectionArea.bottom > Prefe.gDisplay.getHeight()) {
// Prefe.DetectionArea.bottom = Prefe.gDisplay.getHeight();
// }
if (Prefe.DetectionArea.bottom > Height) {
Prefe.DetectionArea.bottom = Height;
}
Prefe.gDetectionBitmapInt = new int[Prefe.DetectionArea.width() * Prefe.DetectionArea.height()];
Prefe.gDetectionBitmapIntPrev = new int[Prefe.DetectionArea.width() * Prefe.DetectionArea.height()];
//Prefe.gDetectionBitmapInt = null;
//Prefe.gDetectionBitmapIntPrev = null;
String area = String.valueOf(Prefe.DetectionArea.left)
+ "," + String.valueOf(Prefe.DetectionArea.top)
+ "," + String.valueOf(Prefe.DetectionArea.right)
+ "," + String.valueOf(Prefe.DetectionArea.bottom);
// UtilGeneralHelper.SavePreferenceSetting(Prefe.gContext, Prefe.PREF_DETECTION_AREA_KEY, area);
//Saving the value
SharedPrefsUtils.setStringPreference(mContext.getApplicationContext(), Prefe.PREF_DETECTION_AREA_KEY, area);
Log.v("TAG", SharedPrefsUtils.getStringPreference(mContext.getApplicationContext(),Prefe.PREF_DETECTION_AREA_KEY));
break;
}
invalidate();
return retValue;
}
private boolean TouchedInBoxArea(int x, int y) {
boolean retValue = false;
try {
if (x > Prefe.DetectionArea.left && x < Prefe.DetectionArea.right) {
if (y > Prefe.DetectionArea.top && y < Prefe.DetectionArea.bottom) {
retValue = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return retValue;
}
private boolean TouchedInArrow(int x, int y) {
boolean retValue = false;
try {
if (x > Prefe.DetectionArea.right - ArrowWidth && x < Prefe.DetectionArea.right) {
if (y > Prefe.DetectionArea.bottom - ArrowWidth && y < Prefe.DetectionArea.bottom) {
retValue = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return retValue;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
Width = width;
Height = height;
InitDetectionArea();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
for (int i = 0; i < this.getChildCount()-1; i++){
(this.getChildAt(i)).layout(l, t, r, b);
}
if (changed) {
// check width height
if (r != Width || b != Height) {
// size does not match
}
}
}
}
Prefe.java
Code:
public class Prefe extends Application{
...
public static final String PREF_DETECTION_AREA_KEY = "pref_detection_area_key";
}
static{
...
DetectionArea = new Rect(1, 1, 1, 1);
}
}

Memory Game inspired in Wordle

Hello everyone,
I just published a simple game but I think it has been very good. At least my kids love it.https://play.google.com/store/apps/details?id=com.ham.game.memo
I have mixed two concepts: the memory game of matching classic images with the wordle, that is, a daily game board and the possibility of sharing the result on Social Networks,
Download and comments are appreciated.
For anyone that could be interested this is the source code how i convert the drawable tiles to a image like wordle style:
public static Bitmap getImageMemo(Context context) {
// base
Drawable blank = null;
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){
if(MemoColors.dark)
blank = App.context().getResources().getDrawable( R.drawable.keyback, App.context().getTheme());
else
blank = App.context().getResources().getDrawable( R.drawable.keyback_light, App.context().getTheme());
} else {
blank = ContextCompat.getDrawable(App.context(), R.drawable.keyback_light);
}
// create image
int margin = 2;
int piece = 48;
Bitmap image = Bitmap.createBitmap((int) piece * 5 + margin * 4, piece * 6 + margin * 5, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
int pTop = 0, pLeft = 0;
for(int row=1; row < 7; row++)
{
for(int col=1; col < 6; col++)
{
Drawable drawable = blank;
if(getActualWord(row, col) < 0)
drawable = MemoIcons.getIconByIndex(MemoIcons.getFamily("robots"), getIconToday(row, col));
drawable.setBounds(pLeft, pTop, pLeft+piece, pTop+piece);
drawable.draw(canvas);
pLeft += piece+margin;
}
pLeft = 0;
pTop += piece+margin;
}
return image;
}
seems very nicely designed.. will give it a try.. thx!

Categories

Resources