[PATCH]Various Swipe Gestures to Wake - Android Software/Hacking General [Developers Only]

Disclaimer
First off all, thanks to showp1984 for his original sweep2wake, based on which, this has been made.
I am a newbie in linux kernel programming, I did spend considerable amount of time, working with others to know about how touch input works. In many places, code will be useless, or there may be better way of implementation. Based on my understanding, I coded this.
This was originally made for a specific device, so I will try to explain wherever possible, so that it becomes easier for someone to implement in case they are interested.
This post does not show how to add hooks in touch panel driver and display driver.
Gestures Available
Swipe Left
Swipe Right
Swipe Up
Swipe Down
Swipe Forward Diagonally
Swipe Backward Diagonally
Draw 'L'
Draw 'V'
Commits
Initial Commit - https://github.com/corphish/android_kernel_sony_msm8930_lp/commit/dae03796da1f8ce97ed41c1b150b18741ac75f24 (Please read the extended description, as I have explained there what I have done)
Fixes - https://github.com/corphish/android_kernel_sony_msm8930_lp/commit/73562680a73956af105bffc0f2d1e7815a375677
Walkthrough
First off all I modified detect_sweep2wake function.
Code:
static bool detect_sweep2wake(int x, int y, int id)
{
key = KEY_POWER;
if (id == 255 && s2w_touch_count > 10) {
int x = s2w_coord_nature();
if(x) {
if(x == 1) {
if(s2w_right) {
s2w_coord_reset();
doubletap2wake_reset();
return true;
}
}
if(x == 2) {
if(s2w_left){
s2w_coord_reset();
doubletap2wake_reset();
return true;
}
}
if(x == 3) {
if(s2w_up){
s2w_coord_reset();
doubletap2wake_reset();
return true;
}
}
if(x == 4) {
if(s2w_down){
s2w_coord_reset();
doubletap2wake_reset();
return true;
}
}
if(x == 5) {
if(s2w_fwd_diag){
s2w_coord_reset();
doubletap2wake_reset();
return true;
}
}
if(x == 6) {
if(s2w_bck_diag){
s2w_coord_reset();
doubletap2wake_reset();
return true;
}
}
if(x == 7) {
if(s2w_l){
s2w_coord_reset();
doubletap2wake_reset();
return true;
}
}
if(x == 8) {
if(s2w_v){
s2w_coord_reset();
doubletap2wake_reset();
return true;
}
}
//pr_info("%s returned true\n",__func__);
}
} else {
//doubletap2wake_reset();
s2w_coord_dump(x, y);
direction_vector_calc();
new_touch(x, y);
}
if (ktime_to_ms(ktime_get())-tap_time_pre > D2W_TIME){
s2w_coord_reset();
doubletap2wake_reset();
}
//pr_info("%s returned false\n",__func__);
return false;
}
It now takes id as parameters as well.
id here is the touch id which is returned when we lift off contact from touch.
Do note that for this device, the id returned when we lift off contact from touch is 255, it will be different for different devices.
What this new detect_sweep2wake fn does is, it tests whether the id returned is that id (touch id which is returned when we lift off contact from touch) and the touch count is greater than a specific number or not.
The specific touch count is used to detect continuous touches (swipes).
If true, it calls for gesture detection function, if true, returns true, if false returns false.
If false, it dumps co-ordinates. Co-ordinates are dumped to 2 variables (x,y) and previous data is stored in (x_prev,y_prev). The first values of touch (the touch co-ordinates on first touch) is stored separately as well.
Then direction_vector_calc is called, which tests the nature of co-ordinates with respect to the previous one.
Code:
void direction_vector_calc(void) {
int tot = 0;
if(s2w_coord_count > 1) {
if(x > x_pre) {
dir[0]++; //right
tot++;
} else if (x < x_pre) {
dir[1]++; //left
tot++;
}
if(y < y_pre) {
dir[2]++; //up
tot++;
} else if (y > y_pre) {
dir[3]++; //down
tot++;
}
//To determine whether both x and y co-ordinates have changed from previous input or not and act accordingly.
if(tot > 1)
multiple_dir++;
//To determine max deviation in x coord.
if(x > max_x)
max_x = x;
//To determine min deviation in x coord.
if(x < min_x)
min_x = x;
//To determine max deviation in y coord.
if(y > max_y)
max_y = y;
//To determine min deviation in y coord.
if(y < min_y)
min_y = y;
} else {
min_y = y;
min_x = x;
max_x = x;
max_y = y;
}
}
At times, there maybe cases that a co-ordinate differs from its previous co-ordinate by 2 directions. This functions take care of that too.
The readings are stored in an array an then tested by gesture detection logic.
The working of gesture_detection is explained in the extended description of this commit.
Code:
int s2w_coord_nature(void)
{
int i = 0;
pr_info("%s:Recieved count - %d\n",__func__,s2w_touch_count);
pr_info("%s:max_x-%d\n",__func__,max_x);
pr_info("%s:max_y-%d\n",__func__,max_y);
pr_info("%s:min_x-%d\n",__func__,min_x);
pr_info("%s:min_y-%d\n",__func__,min_y);
/*This function detects the nature of sweep input, and on the basis of following, it returns -
1 - sweep right
2 - sweep left
3 - sweep up
4 - sweep down*/
pr_info("%s:multiple_dir - %d\n",__func__,multiple_dir);
for(i = 0; i < 4; i++ )
pr_info("%s:dir[%d] - %d\n",__func__,i,dir[i]);
if (abs(x - x_first) > 150 && abs(y - y_first) < 50 && abs(max_y - y) < 50) {
if(dir[0] > s2w_touch_count/2) {
pr_info("%s:Sweep right\n",__func__);
return 1;
}
else if(dir[1] > s2w_touch_count/2) {
pr_info("%s:Sweep left\n",__func__);
return 2;
}
}
if (abs(y - y_first) > 150 && abs(x - x_first) < 50 && abs(max_x - x) < 50) {
if(dir[2] > s2w_touch_count/2) {
pr_info("%s:Sweep up\n",__func__);
return 3;
}
else if(dir[3] > s2w_touch_count/2) {
pr_info("%s:Sweep down\n",__func__);
return 4;
}
}
if(abs(x - x_first) > 100 && abs(y - y_first) > 100 && (multiple_dir == s2w_touch_count - 1)) {
if(x > x_first) {
pr_info("%s:Forward diagonal swipe!!\n",__func__);
return 5;
}//forward diagonal swipe!!
else if(x < x_first) {
pr_info("%s:Backward diagonal swipe!!\n",__func__);
return 6;
}//backward diagonal swipe!!
}
if(abs(x - x_first) > 100 && abs(y - y_first) > 100 && (multiple_dir < s2w_touch_count - 1) && dir[0] > s2w_touch_count/3 && dir[3] > s2w_touch_count/3) {
pr_info("%s:Draw 'L'\n",__func__);
return 7;
}
if(abs(x - x_first) > 80 && abs(y - y_first) < 50 && dir[2] > s2w_touch_count/3 && dir[3] > s2w_touch_count/3 && (multiple_dir < s2w_touch_count - 1)) {
pr_info("%s:Draw 'V'\n",__func__);
return 8;
}
s2w_coord_reset();
return 0;
}
If swipe matches any gesture, it returns corresponding value, else returns 0.
About toggling, I created separate files for each gesture. Also, to simplify things, I had added a master switch for these gestures.
I also made an app for this to control these toggles - Gesture Control 1.4
Credits
showp1984 - Without his works, this is just nothing.
thewisenerd - It is for this guy, I know what I know about touch panels.

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.

[Q] Control cursor PC by WP7

I want to control the PC cursor by WP7, so I try to use the ManipulationDelta in WP7 that can help me to calculate the difference between he star tap and the end tap
Code:
public MainPage()
{
InitializeComponent();
this.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(MainPage_ManipulationDelta);
transformG = new TransformGroup();
translation = new TranslateTransform();
transformG.Children.Add(translation);
RenderTransform = transformG; // you see I don't use any transform here because I don't know where I put. If I use the image.RenderTransform of it will move also for the screen of WP if I put this.RenderTransform, So anyone have a solution
SenderSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
void MainPage_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
startX = e.ManipulationOrigin.X;
startY = e.ManipulationOrigin.Y;
DeltaX = e.DeltaManipulation.Translation.X;
DeltaY = e.DeltaManipulation.Translation.Y;
translation.X += e.DeltaManipulation.Translation.X;
translation.Y += e.DeltaManipulation.Translation.Y;
EndX = Convert.ToDouble(translation.X);
EndY = Convert.ToDouble(translation.Y);
}
I am juste want to send DeltaX and DeltaY to the server to calculate them to the mouse position in the screen, So I write this code
Code:
void StartSending()
{
while (!stop)
try
{
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
byte[] buffer = Encoding.UTF8.GetBytes(DeltaX.ToString() + "/" + DeltaY.ToString());
socketEventArg.SetBuffer(buffer, 0, buffer.Length);
SenderSocket.SendToAsync(socketEventArg);
}
catch (Exception) { }
}
I concatenate them in 1 buffer with separate by "/" and in server I use this code to separate
Code:
void Receive(byte[] buffer)
{
string chaine = "";
if (SenderSocket != null)
{
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
chaine = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred);
chaine.Trim('\0');
string[] pos = chaine.Split('/');
for (int i = 0; i < pos.Length; i++)
{
pX = Convert.ToInt32(pos[0]);
pY = Convert.ToInt32(pos[1]);
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X + pX, Cursor.Position.Y + pY);
}
}
else
{
}
});
SenderSocket.ReceiveFromAsync(socketEventArg);
}
Just I want to control the cursor, if you have any other methods so plz help me and I am really grateful
Didn't you already have a thread about this? Please re-use existing threads instead of starting new ones. Even if it wasn't you, *somebody* was working on this problem already, and very recently. Always use the Search button before starting a thread.
So... what are you looking for from us? Does your current code work? If not, in what way does it fail? Without knowing what your question is, we can't provide answers.
If you want some advice, though...
Sending as strings is very inefficient on both ends; it would be better to use arrays (which you could convert directly to byte arrays and back again).
You're sending as TCP, which is OK but probably not optimal. For this kind of data, UDP is quite possibly better. If nothing else, it provides clearly delineated packets indicating each update.

[Q] Alawyas report network not available when using NewtorkInfo program

0 down vote favorite
share [g+] share [fb] share [tw]
I have wrote a program to check if the network is available or not. Here is my simple code:
Code:
public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity=ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
boitealerte(this.getString(R.string.alert),"getSystemService rend null");
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
I run it on my Android phone, it always returns false but the network is available and I can make calls. Any suggestions>.

Samsung Galaxy S4 Secret Codes,New Galaxy S4 Hidden Code

How to access the internal function of Galaxy S4 for testing the various hardware parts of your phone if it is working properly or not with the help of this secret code you can test lcd, vibration, camera, sensor (accelerometer sensor, proximity sensor, magnetic sensor), touch screen, speaker, sub key, etc... if you have any hardware problem with your Galaxy S4 you can identify with this code if it is working or not to do this follow the steps below.
First of all open your keypad
Then dial the secret code *#0*#. Now you get a screen with title LCD TEST and below that you have lots of option to test various hardware parts of your phone such as speaker, sensor, lcd, etc
To go back use right physical button
while testing the touch, TSP Hovering you have to touch and mark all the squares back button does not work
Other use full secret codes for android phone tested on Galaxy S4
* #1234# to check software version of phone.
*#12580*369# to check software and hardware information.
*#0228# Battery status (ADC, RSSI reading)
*#0011# Service Menu
Do you have the code for turning on the other frequencies on international versions swe we can get them to more effectively work on ATT?
On the phone Dial Pad you run *#0011# , will get band info and Service Menu
Does anyone now the code to get into Diag mode?
Thanks for this (Y)
Sent from my GT-I9500 using xda premium
Thanks!!! Really helpful thread.
*#0*# Diagmode
Sent from my GT-I9500 using Tapatalk 2
Hey guys.
I had found on AndroidPit the following secret codes.
Insofar as I know they had work by my GT-I9505.
Just try it out
*#0011# service mode
*#0228# batteriestatus
*#0283# looback test
*#06# imei
*#03# nandflashheaderread
*#0808# usb service
*#9090# service mode
*#7284# FactoryKeystring
*#1234# Version
*#34971539#camera firmware standard
*#1111# servicemode
*#0*# Testmodus
On the Verizon version of the Galaxy S4, these codes do not work because the hidden menus are disabled by default. To enable the hidden menus on the Verizon version of the Samsung Galaxy S4 go here:
http://forum.xda-developers.com/showthread.php?t=2303905
recalibrated battery?
i just tried the code for battery status and my current batery status is 33% then was curious what function is "quick start" press it and the phone screen was turned of for 2-3 seconds and my battery went to 13% does that function calibrate battery status?
Very useful.
Thank you!
Hjogi
It amazes me the amount of carrier specific restrictions in this file! In fact, the contents of the file below is what was necessary to enable the S4 hidden menus on the VZW Galaxy S4 variant. It should work on other GS4 variants that have the hidden menus disabled.
I got the source below by using the dex2jar tool on HiddenMenu.apk, and then used jad & jd-gui to decompile the class files into Java source code. See here for steps to enable the hidden menus.
qualified class name is: com.android.hiddenmenu.HiddenmenuBroadcastReceiver
Code:
package com.android.hiddenmenu;
// <snip imports>
public class HiddenmenuBroadcastReceiver extends BroadcastReceiver
{
public static final boolean IS_DEBUG;
private static String checkMsl;
private static final String cpuCode;
private static final String cpuPreCode;
private static final String gsmsimcode;
private static final String mSalesCode = SystemProperties.get("ro.csc.sales_code", "NONE").trim().toUpperCase();
private static final String model;
private final String DIAG_FLAG = "0";
private String HIDDENMENU_ENABLE_PATH = "/efs/carrier/HiddenMenu";
private final String HIDDEN_MENU_OFF = "OFF";
private final String HIDDEN_MENU_ON = "ON";
private final int HIDDEN_MSL_CODE = 0;
private final int HIDDEN_OTHERS_CODE = 2;
private final int HIDDEN_OTKSL_CODE = 1;
static
{
if (SystemProperties.get("ro.product_ship", "FALSE").trim().toUpperCase().equalsIgnoreCase("TRUE"));
for (boolean bool = false; ; bool = true)
{
IS_DEBUG = bool;
cpuCode = SystemProperties.get("ro.baseband", "NONE").trim().toUpperCase();
cpuPreCode = SystemProperties.get("ro.product.board", "NONE").trim().toUpperCase();
model = SystemProperties.get("ro.product.model", "NONE").trim().toUpperCase();
gsmsimcode = SystemProperties.get("gsm.sim.operator.alpha", "NONE").trim().toUpperCase();
checkMsl = "";
return;
}
}
private boolean checkHiddenMenuEnable()
{
if (new File(this.HIDDENMENU_ENABLE_PATH).exists())
try
{
String str = read(this.HIDDENMENU_ENABLE_PATH);
if (str.equals("ON"))
return true;
boolean bool = str.equals("OFF");
if (bool)
return false;
}
catch (Exception localException)
{
Log.i("HiddenMenu", "Exception in reading file");
}
return false;
}
private static boolean isJigOn()
{
if (new File("/sys/class/sec/switch/adc").exists())
{
String str = readOneLine("/sys/class/sec/switch/adc");
if (IS_DEBUG)
Log.d("HiddenMenu", "JIG: 28");
if (IS_DEBUG)
Log.d("HiddenMenu", "JIG value: " + str);
try
{
if (Integer.parseInt(str, 16) == 28)
{
if (!IS_DEBUG)
break label160;
Log.d("HiddenMenu", "JIG ON");
break label160;
}
boolean bool4 = IS_DEBUG;
bool2 = false;
if (!bool4)
break label162;
Log.d("HiddenMenu", "Wrong value");
return false;
}
catch (Exception localException)
{
boolean bool3 = IS_DEBUG;
bool2 = false;
if (!bool3)
break label162;
}
Log.d("HiddenMenu", "value has unknown");
return false;
}
else
{
boolean bool1 = IS_DEBUG;
bool2 = false;
if (!bool1)
break label162;
Log.d("HiddenMenu", "File Does not Exist!");
return false;
}
label160: boolean bool2 = true;
label162: return bool2;
}
// ERROR //
public static String read(String paramString)
{
// <snip byte code>
// Exception table:
// from to target type
// 67 71 100 java/io/IOException
// 27 43 118 java/lang/Exception
// 140 144 150 java/io/IOException
// 27 43 171 finally
// 120 133 171 finally
// 177 181 184 java/io/IOException
// 50 59 202 finally
// 50 59 209 java/lang/Exception
}
// ERROR //
private static String readOneLine(String paramString)
{
// <snip byte code>
// Exception table:
// from to target type
// 51 56 73 java/io/IOException
// 61 66 73 java/io/IOException
// 7 17 91 java/io/FileNotFoundException
// 110 114 125 java/io/IOException
// 118 122 125 java/io/IOException
// 7 17 143 java/io/IOException
// 162 166 177 java/io/IOException
// 170 174 177 java/io/IOException
// 7 17 195 finally
// 93 106 195 finally
// 145 158 195 finally
// 201 205 216 java/io/IOException
// 209 213 216 java/io/IOException
// 17 31 239 finally
// 36 43 249 finally
// 17 31 260 java/io/IOException
// 36 43 270 java/io/IOException
// 17 31 281 java/io/FileNotFoundException
// 36 43 291 java/io/FileNotFoundException
}
public void onReceive(Context paramContext, Intent paramIntent)
{
Log.i("HiddenMenu", "intent " + paramIntent);
UsbManager localUsbManager = (UsbManager)paramContext.getSystemService("usb");
label162: if (paramIntent.getAction().equals("com.samsung.sec.android.application.csc.chameleon_diag"))
{
String str6 = paramIntent.getStringExtra("String");
Log.i("HiddenMenu", "value is " + str6);
SharedPreferences.Editor localEditor = paramContext.getSharedPreferences("hidden.diagMSLReq.preferences_name", 0).edit();
localEditor.putString("HIDDEN_DIAGMSLREQ", str6);
localEditor.commit();
SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("hidden.diagMSLReq.preferences_name", 0);
Log.i("HiddenMenu", " Hidden menu diagMSLReq - " + localSharedPreferences.getString("HIDDEN_DIAGMSLREQ", "none"));
break label162;
}
Intent localIntent1;
String str1;
String str2;
label309: int i;
while (true)
{
return;
if (paramIntent.getAction().equals("android.provider.Telephony.SECRET_CODE"))
{
localIntent1 = new Intent("android.intent.action.MAIN");
localIntent1.putExtra(CheckHiddenMenu.permissionKey, CheckHiddenMenu.permission);
str1 = paramIntent.getStringExtra("String");
str2 = paramIntent.getData().getHost();
Log.i("HiddenMenu", "intenton " + paramIntent);
Log.i("HiddenMenu", "host is " + str2);
boolean bool4;
label401: int k;
if ("VZW".equalsIgnoreCase(mSalesCode))
{
bool4 = checkHiddenMenuEnable();
if ("DMMODE".equals(str2))
localIntent1.setClass(paramContext, DmMode.class);
}
else
{
if (((mSalesCode.equals("VZW")) || (mSalesCode.equals("USC")) || (mSalesCode.equals("MTR")) || (mSalesCode.equals("XAR"))) && (SystemProperties.get("ro.build.type", "user").trim().equals("user")))
{
if (!"VZW".equals(mSalesCode))
break label725;
if (str2.equals("HIDDENMENUENABLE"))
break;
}
if (str2.equals("4433366335623"))
k = Settings.System.getInt(paramContext.getContentResolver(), "wifi_offload_monitoring", 0);
}
try
{
ContentResolver localContentResolver = paramContext.getContentResolver();
if (k == 0);
for (int m = 1; ; m = 0)
{
Settings.System.putInt(localContentResolver, "wifi_offload_monitoring", m);
if (!str2.equals("DATA"))
break label805;
localIntent1.setClass(paramContext, hdata_options.class);
i = 1;
label474: if (i == 1)
{
localIntent1.setFlags(268435456);
paramContext.startActivity(localIntent1);
}
if (!str2.equals("MSL_OTKSL"))
break;
if ((!str1.equals("433346")) || (!mSalesCode.equalsIgnoreCase("VZW")))
break label3043;
Log.i("HiddenMenu", "enter MSK_OTKSL iot" + str1);
localIntent1.setFlags(268435456);
localIntent1.setClass(paramContext, IOTHiddenMenu.class);
paramContext.startActivity(localIntent1);
return;
if ("setDMMODEMADB".equals(str2))
{
Log.i("HiddenMenu", "Change USB Setting to DM + MODEM + ADB");
localUsbManager.setCurrentFunction("diag,acm,adb", true);
return;
}
if ("setMASSSTORAGE".equals(str2))
{
Log.i("HiddenMenu", "Change USB Setting to setMASSSTORAGE");
localUsbManager.setCurrentFunction("mass_storage", true);
return;
}
if ((!SystemProperties.get("ro.build.type", "user").trim().equals("user")) || (bool4) || ((isJigOn()) && ((str2.equals("TESTMODE")) || (str2.equals("RTN")))))
break label309;
Log.i("HiddenMenu", "is Jig On " + isJigOn());
return;
label725: if (str2.equals("HIDDENMENUENABLE"))
{
localIntent1.setClass(paramContext, HiddenMenuEnable.class);
break label401;
}
if (SystemProperties.get("sys.hiddenmenu.enable", "0").equals("1"))
break label401;
return;
}
}
catch (Exception localException)
{
while (true)
{
Log.e("HiddenMenu", "Error setWifioffloadDebugMode " + localException);
continue;
label805: if (str2.equals("PROGRAM"))
{
localIntent1.setClass(paramContext, ProgramMenu.class);
i = 1;
}
else if (str2.equals("MEID"))
{
String str5 = paramContext.getSharedPreferences("hidden.diagMSLReq.preferences_name", 0).getString("HIDDEN_DIAGMSLREQ", "none");
Log.i("HiddenMenu", "MEID diag Falg" + str5);
i = 0;
if (str5 != null)
{
boolean bool3 = "none".equalsIgnoreCase(str5);
i = 0;
if (!bool3)
{
Intent localIntent2 = new Intent("android.intent.action.MAIN");
localIntent2.setFlags(268435456);
localIntent2.setClass(paramContext, MEIDInfo.class).putExtra(CheckHiddenMenu.permissionKey, CheckHiddenMenu.permission);
paramContext.startActivity(localIntent2);
i = 0;
}
}
}
else if (str2.equals("RTN"))
{
String str4 = paramContext.getSharedPreferences("hidden.diagMSLReq.preferences_name", 0).getString("HIDDEN_DIAGMSLREQ", "none");
localIntent1.setClass(paramContext, RTN.class).putExtra("DIAGFLAG", str4);
i = 1;
}
else if ((str2.equals("CTN")) && ("SCH-I925U".equalsIgnoreCase(model)))
{
localIntent1.setClass(paramContext, CTN.class).putExtra("keyString", str2);
i = 1;
}
else if (str2.equals("LOG"))
{
localIntent1.setClassName("com.sec.android.app.servicemodeapp", "com.sec.android.app.servicemodeapp.SysDump");
i = 1;
}
else if (str2.equals("DEBUG"))
{
if ("SCH-S960L".equalsIgnoreCase(model))
{
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", str2);
i = 1;
}
else if (!mSalesCode.equalsIgnoreCase("VZW"))
{
localIntent1.setClass(paramContext, DebugMenu_Check.class).putExtra("keyString", str2);
i = 1;
}
else
{
localIntent1.setClass(paramContext, DEBUGMENU.class);
i = 1;
}
}
else if (str2.equals("PROG"))
{
localIntent1.setClass(paramContext, TelesPree_Option.class);
i = 1;
}
else if (str2.equals("IOTHIDDENMENU"))
{
localIntent1.setClass(paramContext, IOTHiddenMenu.class);
i = 1;
}
else if (str2.equals("TESTMODE"))
{
Log.i("HiddenMenu", "gsm sim code is" + gsmsimcode + "#" + gsmsimcode.trim() + "#");
if (((mSalesCode.equals("SPR")) || (mSalesCode.equals("VMU"))) && ((gsmsimcode.replaceAll(" ", "").equalsIgnoreCase("BOOSTMOBILE")) || (gsmsimcode.equalsIgnoreCase("VIRGIN"))))
{
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", str2);
i = 1;
}
else if (cpuPreCode.equalsIgnoreCase("MSM7630_SURF"))
{
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", "TESTMODE");
i = 1;
}
else if ((cpuCode.equals("MSM")) || (cpuCode.equalsIgnoreCase("mdm")))
{
Log.i("HiddenMenu", str2);
localIntent1.setClass(paramContext, ServiceModeApp.class).putExtra("keyString", "TESTMODE");
i = 1;
}
else
{
localIntent1.setClass(paramContext, TerminalMode.class).putExtra("keyString", "TESTMODE");
i = 1;
}
}
else if (str2.equals("NAMBASIC"))
{
localIntent1.setClass(paramContext, MSL_option.class);
i = 1;
}
else if (str2.equals("GPSCLRX"))
{
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", str2);
i = 1;
}
else if (str2.equals("SCRTN"))
{
localIntent1.setClass(paramContext, SCRTN.class);
i = 1;
}
else
{
if (!str2.equals("TTY"))
break;
localIntent1.setClass(paramContext, TTY.class);
i = 1;
}
}
if (!str2.equals("PUTIL"))
break label2374;
}
}
}
if (!PhoneUtilSupport.canLaunchUsb());
for (int j = 0; ; j = 1)
{
String str3 = paramContext.getSharedPreferences("hidden.diagMSLReq.preferences_name", 0).getString("HIDDEN_DIAGMSLREQ", "none");
if ("SPH-L720".equalsIgnoreCase(model))
if ("0".equals(str3))
localIntent1.setClass(paramContext, PhoneUtil_Jspr.class);
while (true)
{
i = j;
break;
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", "PhoneUtil_JSPR");
continue;
if ((("BST".equalsIgnoreCase(mSalesCode)) || ("XAS".equalsIgnoreCase(mSalesCode)) || ("mdm".equalsIgnoreCase(cpuCode))) && (!"SPH-D710BST".equalsIgnoreCase(model)))
{
Log.i("HiddenMenu", "For prevail 2 code");
Log.i("HiddenMenu", "diagReq : " + str3);
if ("XAS".equalsIgnoreCase(mSalesCode))
{
if (("SPH-L900".equalsIgnoreCase(model)) || ("SPH-P600".equalsIgnoreCase(model)))
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", "PhoneUtil_Prevail2SPR");
else if ("SPH-L300".equalsIgnoreCase(model))
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", "PhoneUtil_VMU");
else if (("SPH-L500".equalsIgnoreCase(model)) || ("SPH-L720".equalsIgnoreCase(model)))
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", "PhoneUtil_VMU");
else if ((str3.equals("0")) || (str3.equals("none")))
localIntent1.setClass(paramContext, PhoneUtil_Prevail2SPR.class);
else
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", "PhoneUtil_Prevail2SPR");
}
else if ("mdm".equalsIgnoreCase(cpuCode))
{
if ((str3.equals("0")) || (str3.equals("none")))
localIntent1.setClass(paramContext, PhoneUtil.class);
else
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", "PhoneUtil");
}
else
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", "PhoneUtil_Prevail2SPR");
}
else if ("SCH-S960L".equalsIgnoreCase(model))
{
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", str2);
}
else if (("SPH-D710".equalsIgnoreCase(model)) || ("SPH-D710VMUB".equalsIgnoreCase(model)) || ("SPH-D710BST".equalsIgnoreCase(model)) || ("SCH-R760U".equalsIgnoreCase(model)))
{
if (("SPH-D710BST".equalsIgnoreCase(model)) || ("SPH-D710VMUB".equalsIgnoreCase(model)))
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", str2).putExtra("keyString", str2);
else
localIntent1.setClass(paramContext, PhoneUtil_Gaudi.class);
}
else if ("VMU".equalsIgnoreCase(mSalesCode))
{
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", str2).putExtra("keyString", "PhoneUtil_VMU");
}
else if ((cpuCode.equalsIgnoreCase("MSM")) || ("SPR".equalsIgnoreCase(mSalesCode)))
{
if ("SPH-L500".equalsIgnoreCase(model))
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", str2).putExtra("keyString", "PhoneUtil_VMU");
else
localIntent1.setClass(paramContext, PhoneUtil.class);
}
else
{
localIntent1.setClass(paramContext, PhoneUtil_C1vzw.class);
}
}
label2374: if (str2.equals("AKEY"))
{
if ((cpuCode.equals("MSM")) || (cpuCode.equalsIgnoreCase("mdm")))
{
localIntent1.setClass(paramContext, AKEY2.class);
i = 1;
break label474;
}
localIntent1.setClass(paramContext, AKEY2_via.class);
i = 1;
break label474;
}
if (str2.equals("DNSSET"))
{
localIntent1.setClass(paramContext, DNS_Set.class);
i = 1;
break label474;
}
if (str2.equals("DSA"))
{
localIntent1.setClass(paramContext, DSA_Edit.class);
i = 1;
break label474;
}
if (str2.equals("OTATEST"))
{
localIntent1.setClass(paramContext, OTATest.class);
i = 1;
break label474;
}
if (str2.equals("LTEMODE"))
{
localIntent1.setClass(paramContext, LTEMode.class);
i = 1;
break label474;
}
if (str2.equals("CLEAR"))
{
if (("SPR".equalsIgnoreCase(mSalesCode)) || ("SPH-L300".equalsIgnoreCase(model)))
break;
if (!mSalesCode.equalsIgnoreCase("VZW"))
{
localIntent1.setClass(paramContext, DebugMenu_Check.class).putExtra("keyString", str2);
i = 1;
break label474;
}
localIntent1.setClass(paramContext, CLEAR_Reset.class);
i = 1;
break label474;
}
if (str2.equals("setMTP"))
{
Log.i("HiddenMenu", "Change USB Setting to MTP");
localUsbManager.setCurrentFunction("mtp", true);
return;
}
if (str2.equals("setMTPADB"))
{
Log.i("HiddenMenu", "Change USB Setting to MTP + ADB");
localUsbManager.setCurrentFunction("mtp,adb", true);
return;
}
if (str2.equals("setPTP"))
{
Log.i("HiddenMenu", "Change USB Setting to PTP");
localUsbManager.setCurrentFunction("ptp", false);
return;
}
if (str2.equals("setPTPADB"))
{
Log.i("HiddenMenu", "Change USB Setting to RNDIS + ADB");
localUsbManager.setCurrentFunction("ptp,adb", false);
return;
}
if (str2.equals("setRNDISDMMODEM"))
{
Log.i("HiddenMenu", "Change USB Setting to RNDIS + DM + MODEM");
localUsbManager.setCurrentFunction("rndis,acm,diag", true);
return;
}
if (str2.equals("setMASSSTORAGEADB"))
{
Log.i("HiddenMenu", "Change USB Setting to setMASSSTORAGEADB");
localUsbManager.setCurrentFunction("mass_storage,adb", true);
return;
}
if (str2.equals("setMASSSTORAGE"))
{
Log.i("HiddenMenu", "Change USB Setting to setMASSSTORAGE");
localUsbManager.setCurrentFunction("mass_storage", true);
return;
}
if (str2.equals("setRMNETDMMODEM"))
{
Log.i("HiddenMenu", "Change USB Setting to RMNET + DM + MODEM");
localUsbManager.setCurrentFunction("rmnet,acm,diag", true);
return;
}
if (str2.equals("setDMMODEMADB"))
{
Log.i("HiddenMenu", "Change USB Setting to DM + MODEM + ADB");
localUsbManager.setCurrentFunction("diag,acm,adb", true);
return;
}
if ((str2.equals("HIDDENMENUENABLE")) && (SystemProperties.get("ro.build.type", "user").trim().equals("user")))
{
if ("SCH-S960L".equalsIgnoreCase(model))
{
localIntent1.setClass(paramContext, MSL_Checker.class).putExtra("keyString", str2);
i = 1;
break label474;
}
localIntent1.setClass(paramContext, HiddenMenuEnable.class);
i = 1;
break label474;
}
boolean bool1 = str2.equals("DMMODE");
i = 0;
if (!bool1)
break label474;
boolean bool2 = mSalesCode.equals("VZW");
i = 0;
if (!bool2)
break label474;
localIntent1.setClass(paramContext, DmMode.class);
i = 1;
break label474;
label3043: Log.i("HiddenMenu", "enter MSK_OTKSL " + str1);
localIntent1.setClass(paramContext, MSL_Service.class).putExtra("String", str1);
Log.i("HiddenMenu", "set intent : " + localIntent1);
paramContext.startService(localIntent1);
return;
}
}
}
Unfortunately there doesn't seem to be an entry for adjusting the sound. The 9505 still misses the function
Sent from my GT-I9505
Is there anyway of checking if your phone is simlocked? On the gs2 you could dial *#SIMLOCK# and if would display [Off] beside a list of text.
Sent from my GT-I9505 using xda app-developers app
@nanoy009 I had this problem too. The easiest you can make (and what I have also done) is pull the battery out and wait a few seconds. And then turn your device on and your battery is okay and shows you the current status.
Sent from my SGH-M919 (in reality an I9505 ) using xda app-developers app
any code to update camera firmware:thumbup:
Sent from my GT-I9505 using xda premium
Here's a list that I've compiled so far, I don't test ones that say clear on them though so I could of missed a few.
*#06# IMEI
*#0*# LCD Test?
*#1234# Version
*#12580*369# Main Version
*#0228# BatteryStatus
*#0011# ServiceMode
*#0283# Loobback Test
*#03# NandFlashHeaderRead
*#0808# USBSettings
*#9090# ServiceMode
*#7284# FactoryKeystring
*#34971539# CameraFirmware Standard
*#1111# ServiceMode
*#9900# SysDump
*#7353# Quick Test Menu?
I'm looking for Engineering Mode...
That's the one I want, it doesn't matter to me if there is no code for it or not, I'm rooted and have a terminal installed, whatever needs to be done...
NEOAethyr said:
Here's a list that I've compiled so far, I don't test ones that say clear on them though so I could of missed a few.
*#06# IMEI
*#0*# LCD Test?
*#1234# Version
*#12580*369# Main Version
*#0228# BatteryStatus
*#0011# ServiceMode
*#0283# Loobback Test
*#03# NandFlashHeaderRead
*#0808# USBSettings
*#9090# ServiceMode
*#7284# FactoryKeystring
*#34971539# CameraFirmware Standard
*#1111# ServiceMode
*#9900# SysDump
*#7353# Quick Test Menu?
I'm looking for Engineering Mode...
That's the one I want, it doesn't matter to me if there is no code for it or not, I'm rooted and have a terminal installed, whatever needs to be done...
Click to expand...
Click to collapse
:good:
Thanks guys
Sent from my GT-I9505 using xda premium
is there any secret code that I can enter to choose what LTE band I wanted to connect only? e.h 1800 or 2600

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);
}
}

Categories

Resources