Application1 to control App2 (VisualStudio2008) - Windows Mobile Development and Hacking General

Hello!
I'm developing one application in VS2008 for my pocket pc, and I need some help to continue with it.
I need to make the buttons of the application1 run even when the application2 is running and try to control it with application1 buttons, but I donĀ“t know if it's possible!?
For example, is it possible to move between items on "windows mob. file explorer" using the up and down keys/buttons of application1?
The application1 only fills 1/3 of the screen, and I still seen windows explorer
When I try to do it, the application1 came to the "top" and windows file explorer control seems to be disable.
Is it possible? Any tips for it?
Regards

Have a look into the SendMessage API call. It should be able to do what you want.

Northernmost said:
Have a look into the SendMessage API call. It should be able to do what you want.
Click to expand...
Click to collapse
I agree. You basically need to catch WM_KEYDOWN messages (and any other you want to pass) and send them to file explorer... I think the tricky part is knowing what application is running directly underneath yours. Post here how you did it if you manage to achieve all that

Arlanthir said:
I agree. You basically need to catch WM_KEYDOWN messages (and any other you want to pass) and send them to file explorer... I think the tricky part is knowing what application is running directly underneath yours. Post here how you did it if you manage to achieve all that
Click to expand...
Click to collapse
Hi!
Ok, I will post here the code of application. Take a look at it and say something about.
Here goes the code:
Code:
Imports System
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("coredll.dll", CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", SetLastError:=True)> _
Public Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
'Bye!
Application.Exit()
End Sub
Private Sub UpButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpButton.Click
Const VK_UP As Byte = &H26
keybd_event(VK_UP, 0, 0, 0)
'Up
End Sub
Private Sub LeftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftButton.Click
Const VK_LEFT As Byte = &H25
keybd_event(VK_LEFT, 0, 0, 0)
'Left
End Sub
Private Sub DownButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownButton.Click
Const VK_DOWN As Byte = &H28
keybd_event(VK_DOWN, 0, 0, 0)
'Down
End Sub
Private Sub RightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RightButton.Click
Const VK_RIGHT As Byte = &H27
keybd_event(VK_RIGHT, 0, 0, 0)
'Right
End Sub
End Class
Do you think it is possible to control any other application with this?
I don't want only control windows explorer, I want to control other applications, including games.
Tanks for help.
Regards

I'm not getting what you want to do with it.
You're designing something like a userbar that's always staying on top but letting you interact with the application directly underneath it;
OR
You're making a "remote control" application to send various commands to different programs, which you specify hardcoding.
Now the control is an easy one (at least in C++) but actually getting what application is underneath yours may be tricky. Can't help much more there, specially with another language. Have you searched msdn?

Hello.
So, I mean to do a virtual d-pad cause I have one of my pocket pc dont have any!
See this post
This is what I want to do.
I think this will be, like you said, a little bit "tricky".
But, if some one could help, I think it will work.
I don't have many skills programming mobile applications.. so every tips and examples are welcome.
Regards

What? That changes everything! xD
On the first post you said you wanted to make the "up and down buttons" sent to app1 change app2... Well, I thought you were talking hardware keys here
(thus the WM_KEYDOWN event)
What language are you using and in what way do you interact with the touchscreen? Did you understand when I said you had to catch the events?
Basically, you want to catch touchscreen (mouse) events, compare the mouse coordinates to those of your buttons (let's say it was a MOUSEDOWN in the LEFT button area), get the window directly below you and post a WM_KEYDOWN message with the LEFT code to it.
The only problems in doing this in C++ for me right now (I'm also a beginner ) would be creating a window that doesn't cover the screen and getting the window below. The rest is really easy

Arlanthir said:
What? That changes everything! xD
On the first post you said you wanted to make the "up and down buttons" sent to app1 change app2... Well, I thought you were talking hardware keys here
(thus the WM_KEYDOWN event)
What language are you using and in what way do you interact with the touchscreen? Did you understand when I said you had to catch the events?
Basically, you want to catch touchscreen (mouse) events, compare the mouse coordinates to those of your buttons (let's say it was a MOUSEDOWN in the LEFT button area), get the window directly below you and post a WM_KEYDOWN message with the LEFT code to it.
The only problems in doing this in C++ for me right now (I'm also a beginner ) would be creating a window that doesn't cover the screen and getting the window below. The rest is really easy
Click to expand...
Click to collapse
Hi!
I'm using Visual Studio 2008 to code it.
Creating a window that cover only 1/3 of the screen, in VisualStudio is not difficult. If you have VS2008, I can send you the project for your email and so you can take a look at it.
If I understand, you can make this work coding it in C++, so we can share both parts... the 1/3 screen window and the way to make app1 control any other app2, cause I have no idea how to make app1 control app2!!!!!
Tanks.

all bull ****
Guys This Is Crap>>>>>>believe Me

jawad786 said:
Guys This Is Crap>>>>>>believe Me
Click to expand...
Click to collapse
?? Why this "is crap" ??
It's a mobile application development try like any other one!

ImpactMan said:
Hi!
I'm using Visual Studio 2008 to code it.
Creating a window that cover only 1/3 of the screen, in VisualStudio is not difficult. If you have VS2008, I can send you the project for your email and so you can take a look at it.
If I understand, you can make this work coding it in C++, so we can share both parts... the 1/3 screen window and the way to make app1 control any other app2, cause I have no idea how to make app1 control app2!!!!!
Tanks.
Click to expand...
Click to collapse
You are aware that Visual Studio actually lets you code in different languages, I hope.

Arlanthir said:
You are aware that Visual Studio actually lets you code in different languages, I hope.
Click to expand...
Click to collapse
Yes. I know that!
So, you think in C++ is possible to make it work?
Have any idea how to? Any tips?
Tanks for help.
Regards

I've already told you what I do know, now for the rest someone has to dig up the information from msdn... I don't have the time right now, as I'm working on something else on the little spare time I have But if you do find a way to do the rest I'll gladly help you with what I can do now.

Arlanthir said:
I've already told you what I do know, now for the rest someone has to dig up the information from msdn... I don't have the time right now, as I'm working on something else on the little spare time I have But if you do find a way to do the rest I'll gladly help you with what I can do now.
Click to expand...
Click to collapse
OK. Tanks for your availability.
I will try to make some progresses... Let you know than.
Regards.

Google is your friend - http://www.google.co.uk/search?q=compact+framework+sendmessage+send+keystroke
Top of the list (http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=40803) looks promising. Note the use of PostMessage rather than SendMessage. It appears SendMessage requires the target app to have focus to work reliably... where as PostMessage doesn't. You learn something new every day

dont know if ur coding something to control only one specific program, but if its for all programs maybe a sip input panel do the same in an easier way

Northernmost said:
Google is your friend - http://www.google.co.uk/search?q=compact+framework+sendmessage+send+keystroke
Top of the list (http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=40803) looks promising. Note the use of PostMessage rather than SendMessage. It appears SendMessage requires the target app to have focus to work reliably... where as PostMessage doesn't. You learn something new every day
Click to expand...
Click to collapse
Tanks for the links.
I've already take a look at it, and now I'm going to try understand it and try to adapt something like to my application.
I will see the to ways... PostMessage and SendMessage.
Regards.

Keep the development goin! Looks like a very interesting project I'll keep track, since I have an Omnia anyway.
Unfortunately I cannot help since I'm a begginer still stuck on Turbo C++ 3.0 (LOL, seriously-awesome right?)

Related

Simple Programming Question embedded VC++

I'm currently doing some programs myself with the free MS embedded VC++.. and I'm finding it comfortable to do a simple dialog-based programs for PPC. I think I can have most of the background code going, and I've just got the GUI .. alright.
Now the question, how do I do a copy/paste to/from clipboard? I had most of the stuff done using the included MFC Wizard. I can get and send data to/from an EditBox (TextBox, whatever you call it). However, the click-hold thing on PPC doesn't seems to work on my EditBox, and hence I'm thinking what's needed to enable a simple Copy/Paste on an EditBox.
Currently, I'm using the simple
Code:
m_editBox = _T("the message I want to show");
UpdateData(FALSE); //send it to the EditBox
Any guide from here would be appreciated. However, I'm thinking there may not be an easy way to do that, hence I've also tried adding a 'Copy' and 'Paste' button to do the job, but I've tried things like
Code:
SetClipboardData(x, x)
GetClipboardData(x)
None works.
I have also tried
Code:
COleDataObject DataObject;
and with the handle etc etc .. but I can't seems to find this COleDataObject , is that in some other environment (e.g. not PPC env)?
Help
Fast solution:
http://www.pocketpcdn.com/articles/sip.html
(this shows/hides sip on get/lost focus in edit controls and add the context menu too)
and this is a simple example how to copy datas into clipboard
if(OpenClipboard(NULL))
{
EmptyClipboard();
HLOCAL clipbuffer = LocalAlloc(0, 100);
wcscpy((WCHAR*) clipbuffer, (WCHAR*) (vtNumber.bstrVal));
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
free(szMsg);
LocalFree(clipbuffer);
}
I hope this help u
bye
Thanks for your respond.. things work.. a bit
Code:
//put a test char
char *test;
test = (char*) malloc(100);
strcpy(test, "blah blah blah");
//codes you've given
if(OpenClipboard()) //OpenClipboard(NULL) gives me error
{
EmptyClipboard();
HLOCAL clipbuffer = LocalAlloc(0, 100);
wcscpy((WCHAR*) clipbuffer, (WCHAR*) test);
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
//free(szMsg); //not sure what 'szMsg' is
LocalFree(clipbuffer);
}
Things somewhat works. I'm not really sure which part I've got wrong. I'm suspecting some memory allocation is giving me problems. The thing is, if I were to use 'CF_UNICODETEXT' on the 'SetClipboardData(x,x)' line, I get something to paste on other programs (PPC Notes). BUT, the thing pasted is some funny stuff (e.g. letters that cannot be rendered, hence I get the little squares). If I were to use 'CF_TEXT', I don't seems to able to send my stuff to the clipboard or it made it invalid for (PPC Notes) pasting (e.g. I'm not able to paste it in PPC Notes).
Thanks.
BTW, if you are in the mood, can you give me a Paste function as well. Thanks a bunch.
Hi hanmin.
Odd I didn't notice this thread sooner.
Any way if you still having problems with this code here is the solution:
You are working with char and strcpy so your text is in ASCII (each letter one byte).
But you are calling SetClipboardData with CF_UNICODETEXT so it expects WCHAR (UNICODE) where each letter is two bytes.
The strange letters are the result of two consecutive bytes being interpreted as a single letter (probably lends you in Chinese or Japanese region of the Unicode table)
Windows mobile doesn't usually work with ASCII so the text you get from the edit box will already be in Unicode and won't give you any trouble.
The code should look like this:
Code:
//put a test char
CString test; //since you are working with MFC save your self the trouble of memory allocation
test = L"The text I want on clipboard"; //The L makes the string Unicode
//codes you've given
if(OpenClipboard()) //OpenClipboard(NULL) gives me error
{
EmptyClipboard();
//not sure why you need to copy it again, but here goes:
HLOCAL clipbuffer = LocalAlloc(0, test.GetLength() * 2); //remember: every letter 2 bytes long!
wcscpy((WCHAR*) clipbuffer, (WCHAR*)(LPCTSTR)test); //LPCTSTR is an overloaded operator for CString
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
//szMsg probably belongs to some larger application and is irrelevant
LocalFree(clipbuffer);
}
I never used the clipboard APIs my self so I can't guide you farther but this code should work.
Hope this helps.
Wooo hooo.. Thanks levenum. I'm back on business!
You code works wonderfully.. just the final code "LocalFree(clipbuffer);" seems to cause problems. Without that, it works. I'm not sure if it will cause a memory leak.. but that's not much of my concern now
Now my Paste also works, and it seems that the magic code is the "LPCTSTR", which I have NO idea what it is (I'm more of a pure C person and.. a Java person ) Thanks again.
Glad I could help.
I am working from Ubuntu right know (Linux distro in case you didn't know) so I do not have access to my off-line MSDN files, but I recommend you check out the documentation for SetClipboardData.
It is possible it releases the memory it self so when you call LocalFree the handle is no longer valid.
That could also be the reason why you need to allocate memory instead of passing it the string directly.
As for LPCTSTR it is simple and not C++ related:
#define const* WCHAR LPCTSTR
Its M$ way of saying Long Pointer to Constant STRing
T changes meaning based on what you are working with:
If you work with ASCII TCHAR is char
If you work with Unicode TCHAR is WCHAR
Basically these are just all redefinitions of variable types so you can distinguish what they are used for.
In C++ you can overload operators. For example you can have a function which changes the way ++ works with certain types of variables.
In our case CString class has a function which determines what happens when you try to cast (convert) it to a pointer to string.
Thats all the "magi" code.
Good luck with your app.
Small update:
Since I had to go in to XP anyway (to change PDAMobiz ROM which kept hanging at random and didn't let me use BT to latest PDAViet which for now seem very good) I took a quick peek at the help files.
Here is why you should not release the memory:
After SetClipboardData is called, the system owns the object identified by the hMem parameter. The application can read the data, but must not free the handle or leave it locked. If the hMem parameter identifies a memory object, the object must have been allocated using the LocalAlloc function
Click to expand...
Click to collapse
levenum, thanks. You've got me almost there. There are several stuff I need to polish up though. Attach is a pre-mature version of what I wanted to do. There are several issues (including the fact that, only the 4 characters of the password are effectively used, which can be easily fix, I think. Just need to find the bug and squash it) that I like to polish up. They are sorted in order of importance (to me):
[1] Keyboard (SIP) pop up.
For this, I digged around and got to know that the function
"SHSipPreference( HWND, SIP_UP)" is the one to used. However, it never did what it suppose to do. I have had it put inside the "OnSetfocusConfirmPasswordEdit()" of the edit box, which should be called when it is set focus. I suspect that is I haven't set the HWND correctly. I have tried "NULL" and also tried using the "CWnd* pParent" from my dialog constructor (generated code my MFC Wizard). None of them worked.
[2] Editbox focusing.
For some reason, the focus on my main-dialog is correct on the editbox of the 'message'. However, on the dialog which is to confirm the password (which I called using
Code:
CConfirmPasswordDlg confirmPasswordDlg;
int nResponse = confirmPasswordDlg.DoModal();
is focusing on the 'Ok' button. What I like it to do is to focus on the 'confirmPasswordEdit' box, and it ought to automatically pop up the keyboard (SIP).
[3]Reduced size pop up dialog
I was trying to make the 2nd confirm password dialog smaller, something like a pop up in the PPC rather than something that take up the whole screen without much contents in it. How would you go about doing that? Is it not possible in PPC? E.g, if you were to use Total Commander, and start copying files around, they do have a pop up that does take up the entire screen. I'm suspecting I shouldn't do a "confirmPasswordDlg.DoModal()", and should some what do something myself. I have tried, SetVisible(1) thing, but that doesn't work. Or it shouldn't meant to work because my 1st screen is a dialog screen?
[4]Timer?
I would like to have a function of which after a certain period of idle time, it will clear off the clipboard and close itself. How would I go about doing this? Some sort of background thread thing?
Anyone can shine a light on my issues above? On MS-embedded Visual C++ (free), with Pocket PC 2003 SDK (free)
Attached the Blender-XXTea edition
Works on PPC2005 and WM5 (should work on WM6)
Does not require .NET framework
VERY small (54K)
hanmin said:
[2] Editbox focusing.
For some reason, the focus on my main-dialog is correct on the editbox of the 'message'. However, on the dialog which is to confirm the password (which I called using
Code:
CConfirmPasswordDlg confirmPasswordDlg;
int nResponse = confirmPasswordDlg.DoModal();
is focusing on the 'Ok' button. What I like it to do is to focus on the 'confirmPasswordEdit' box, and it ought to automatically pop up the keyboard (SIP).
Click to expand...
Click to collapse
In your CConfirmPasswordDlg::OnInitDialog handler, call GetDlgItem(confirmPasswordEdit).SetFocus() and return FALSE. That should handle the focus and possibly the SIP popup.
3waygeek said:
In your CConfirmPasswordDlg::OnInitDialog handler, call GetDlgItem(confirmPasswordEdit).SetFocus() and return FALSE. That should handle the focus and possibly the SIP popup.
Click to expand...
Click to collapse
HEY! The focus works! The working code is
Code:
((CWnd*) CConfirmPasswordDlg::GetDlgItem(IDC_CONFIRM_PASSWORD_EDIT))->SetFocus();
BTW, I'm wondering, whats the effect of a return TRUE/FALSE on a 'OnInitDialog()'?
Anyway, the keyboard pop up is still not working. I'm using the command
Code:
void CConfirmPasswordDlg::OnSetfocusConfirmPasswordEdit() {
SHSipPreference( (HWND)g_pParent, SIP_UP);//
}
which I suspect the 'g_pParent' is NULL. If it is NULL, would it work?
Ok, I haven't used MFC for a while and almost not at all on PPC but I will give this a shot:
1) MFC forces dialogs to be full-screen. Here is a detailed explanation on how to change that. Note that for some reason this will work only once if you use the same variable (object) to create the dialog several times.
If you use a local variable in say a button handler thats not a problem because the object is destroyed when you exit the function.
2) There is a simple SetTimer API. You can give it a window handle and then add an OnTimer message handler to that window. Or you could give it a separate function which will be called (say TimerProc). In that case you can give it NULL as window handle.
Note that CWnd objects have a member function with the same name (SetTimer) which sets the timer with that window handle (so that window will receive WM_TIMER message). If you want the raw API call ::SetTimer.
Also note that the timer will continue to send messages / call your special function every x milliseconds until you call KillTimer.
3) I am not sure what the problem with the SIP is. CWnd and derived classes like CDialog have a function called GetSafeHwnd (or GetSafeHandle, I don't remember exact name). Try passing that to SHSipPreference.
If that does not work here is an article with an alternate solution.
WOHO!! Everything works NOW!!.. MUAHAHHAHA.. wait til you see my release version
Non maximized windows works using the code suggested at the page. Although I still do not understand where the heck this '.m_bFullScreen' property came from. It is not anywhere obvious to be seen.
Code:
CNfsDlg dlg;
dlg.m_bFullScreen = FALSE;
dlg.DoModal();
Timer works using the
Code:
xx{
//your code...
CBlenderDlg::SetTimer(1, 5000, 0); //event 1, 5 seconds, something
//your code...
}
void CBlenderDlg::OnTimer(UINT nIDEvent){
//do something here for the timer
}
although somehow, the OnTimer() only works if I went to the MFC class wizard to add the WM_TIMER function. Doesn't work when I add in the OnTimer() myself. Must be something else that I've missed. Anyway.
Keyboard issue solved using
Code:
SHSipPreference( CBlenderDlg::GetSafeHwnd(), SIP_UP);
Glad its working out for you.
Couple of comments:
1) Somewhere at the top of the cpp file, if I am not mistaking there is something called a message map. It's a bunch of macros that lets MFC know what window messages it handles. An entry there is what was missing when you added the function manually.
2) m_bFullScreen is just another among many undocumented features. M$ likes to keep developers in the dark. For instance WM 2003 and up have an API called SHLoadImage which can load bmp, gif, jpg and some other formats and return HBITMAP which all the usual GDI functions use.
This API was undocumented until WM 5 came out and even then they said it only works for gif...
hanmin said:
BTW, I'm wondering, whats the effect of a return TRUE/FALSE on a 'OnInitDialog()'?
Click to expand...
Click to collapse
The return value indicates whether or not the standard dialog handler (which calls your OnInitDialog) should handle setting the focus. As a rule, OnInitDialog should return TRUE, unless you change the focus within the handler (or you're doing an OCX property page on big Windows).
I haven't done much WinMob/CE development -- I've been doing big Windows for 15+ years, so window message handling is pretty much second nature. I started doing Windows development back in the days when you didn't have C++ or MFC boilerplate; you had to implement your own DialogProc, crack the messages yourself, etc. It's a lot easier now.
CommandBar / MenuBar
I'm back.. with more questions
Not much of a major issue, but rather an annoying thing I've found. Probably that's what evc/mfc/m$ intended to do that.
Anyway, I'm starting my way of getting around CommandBar. I created a MFC skeleton, studied the code, and that's what I've found, after I've created a CommandBar/MenuBar on evc and putting it in
Code:
if(!m_mainMenuBar.Create(this) ||
!m_mainMenuBar.InsertMenuBar(IDR_MAINMENUBAR) ||
!m_mainMenuBar.AddAdornments() ||
!m_mainMenuBar.LoadToolBar(IDR_MAINMENUBAR))
{
TRACE0("Failed to create IDR_MAINMENUBAR\n");
return -1; // fail to create
}
where I have the variable 'CCeCommandBar m_mainMenuBar' and I have created a MenuBar on evc with the Id 'IDR_MAINMENUBAR'. The menu bar works flawlessly on my dialog based application, when I have the 1st level as a pop up. Example
MenuBar --> 'File' --> 'New', 'Save'
Where 'File' is a folder-like thing that pop-ups and show the contents (i.e. in this example, 'New', and 'Save'). However, given the SAME code to load the CommandBar/MenuBar, it will not work, if I were to put the actual command at 1st level. Example, this will not work
MenuBar -> 'New', 'Save'
where there isn't any folder-like pop-up to store the commands 'New', and 'Save'.
I know that I can have buttons for these commands, and probably works. But, what I'm trying to do is to utilize the bottom-left-right softkey in WM5/6. If I were to have the 'File'->'New','Save' structure, it works fine with WM5, showing it as a softkey. But, if I were to do just 'New','Save' it will not show up in both WM2003 emulator and WM5.
As a matter of fact, even if I have (say) File->New,Load, and I added a new command (i.e. not folder-like-pop-up), example 'Help' on the CommandBar/MenuBar, the File->New,Load will not show up too. It seems like the 1st level command (ie. without a folder-pop-up), causes some problems and stop it from loading further.
Guys, ring any bell?
two bytes more
levenum said:
Hi hanmin.
Odd I didn't notice this thread sooner.
Any way if you still having problems with this code here is the solution:
You are working with char and strcpy so your text is in ASCII (each letter one byte).
But you are calling SetClipboardData with CF_UNICODETEXT so it expects WCHAR (UNICODE) where each letter is two bytes.
The strange letters are the result of two consecutive bytes being interpreted as a single letter (probably lends you in Chinese or Japanese region of the Unicode table)
Windows mobile doesn't usually work with ASCII so the text you get from the edit box will already be in Unicode and won't give you any trouble.
The code should look like this:
Code:
//put a test char
CString test; //since you are working with MFC save your self the trouble of memory allocation
test = L"The text I want on clipboard"; //The L makes the string Unicode
//codes you've given
if(OpenClipboard()) //OpenClipboard(NULL) gives me error
{
EmptyClipboard();
//not sure why you need to copy it again, but here goes:
HLOCAL clipbuffer = LocalAlloc(0, test.GetLength() * 2); //remember: every letter 2 bytes long!
wcscpy((WCHAR*) clipbuffer, (WCHAR*)(LPCTSTR)test); //LPCTSTR is an overloaded operator for CString
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
//szMsg probably belongs to some larger application and is irrelevant
LocalFree(clipbuffer);
}
I never used the clipboard APIs my self so I can't guide you farther but this code should work.
Hope this helps.
Click to expand...
Click to collapse
I know it is a bit late! But there is a mistake the code snippet:
HLOCAL clipbuffer = LocalAlloc(0, test.GetLength() * 2); //remember: every letter 2 bytes long!
needs to be
HLOCAL clipbuffer = LocalAlloc(0, test.GetLength() * 2+2);
the terminating 0 is als 2 bytes long!
Those errors are sometimes fatal, with very less chance to find them!
ms64o

Interest in a task automater / macro recorder and playback utility?

I wrote a program for Windows 2000/XP called Do It Again ( http://www.spacetornado.com/DoItAgain/ ) that does simple task automation (also called macro recording and playback).
You click "Create a New Task" and it then records all of your keystrokes and mouse clicks in any program until you hit a certain hot key (Scroll Lock by default). You can then run the task back in a number of different ways and it will recreate your keystrokes and mouse clicks... either with the same pauses in between, or it can speed them up. And there are some other options available as well (repeating tasks, manually extending pauses between actions, etc).
I thought something like this might be useful for Windows Mobile devices. I wrote Do It Again in C# using .NET Framework 2.0, so I'm guessing it should be fairly easy to port to .NET Compact Framework 2.0.
But I only want to start porting this to Windows Mobile if there is any interest in it, and if people think they might get some use out of it. I know for me personally there are several things I do on my WinMo device that get repetitive and monotonous... starting and minimizing GPS Test to activate the GPS adapter, dismissing old Notifications, marking all email as Read, etc.
This sounds like a perfect application which can be used for pretty much anything.
Personally, i'm very interested in this, and would be glad to have it ported.
There are a lot of people who're looking to do things the easy way around here, for instance, settings up accounts, changing settings.. and so forth, without having to go 8 clicks...
nir36 said:
This sounds like a perfect application which can be used for pretty much anything.
Personally, i'm very interested in this, and would be glad to have it ported.
There are a lot of people who're looking to do things the easy way around here, for instance, settings up accounts, changing settings.. and so forth, without having to go 8 clicks...
Click to expand...
Click to collapse
I would find this very useful for using both Google Maps and Tom Tom Nav.. Say you want to go somewhere new.. Use google maps to find the address and then activate the script, prime the GPS, load Tom Tom, then copy paste the address info into Tom Tom. One cycle activated by a hot key would be nice.
norkoastal said:
I would find this very useful for using both Google Maps and Tom Tom Nav.. Say you want to go somewhere new.. Use google maps to find the address and then activate the script, prime the GPS, load Tom Tom, then copy paste the address info into Tom Tom. One cycle activated by a hot key would be nice.
Click to expand...
Click to collapse
Yeah that would be a perfect example of how you could use it. And that would be a lot safer to have a task automation app perform those steps for you instead of having to do it yourself while driving.
I'll start working on this in a week or so (as soon as I can get Scrobble finished up and to a point where people stop requesting more features! ) and see if can be ported over.
It should be easy; there are just a couple Win32 library calls it makes that I'm not sure are available in WinMo 6.1:
Code:
// imports mouse_event function from user32.dll
[SRI.DllImport("user32.dll", CharSet = SRI.CharSet.Auto, CallingConvention = SRI.CallingConvention.StdCall)]
public static extern void mouse_event(int dwFlags, int dx, int dy, uint cButtons, uint dwExtraInfo);
// imports keybd_event function from user32.dll
[SRI.DllImport("user32.dll", CharSet = SRI.CharSet.Auto, CallingConvention = SRI.CallingConvention.StdCall)]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
These two functions mouse_event() and keybd_event() poll for all mouse and keyboard events (clicks, movement, keypresses, etc.) globally... in any window, program, and so on.
Does anyone know off the top of their head if user32.dll is also available in Windows Mobile 6.1 Professional?
I am *VERY* interested in this application. How is the porting coming? I can't wait!!!
Man. That would be a revolution for us ppccusumizenerds! Holy ****! ..that would actually be Holy ****!
There is a version of AutoHotKey for Pocket PCs / WinCE, still in development, but a lot of it working, see here http://www.autohotkey.com/forum/topic27146.html&highlight=wince.
I'm very interested. In fact, I was looking for such an application but gave up finding.
Looking forward.
Thanks.
Hi,
if it's getting as good as Scrobble, then I vote for it . This would be a very handy feature, moreover very clever.
I would test it with pleasure.
Greets.
It will be a very useful app!
Looking forward to it, in the meanwhile I'll play with XP version!!

dynamically setting image resources

greetings
was referred to this forum from someone at androidcommunity.com regarding this...
i searched the forum but couldnt find any relevant posts - can anyone point me in the right direction for doing this properly?
specifically how could one set an image resource based on a string variable being used for part of the image's file name
i tried this based on a post i saw elsewhere:
myContext.getResources().getIdentifier(myStringVariable + "_thumbnail", "drawable", myContext.getPackageName()));
but it returnes a string(or an integer?) of numbers (the resource id?) that setImageResource couldnt use unless i just wasnt doing it properly.
is there perhaps a way to get the resource name based on that id number or whatever it is that im getting?
apreesh
33 views
dang
getIdentifier() returns int and yes, it could be used in setImageResource() method.
But why you want to set resources from strings?
because the image being set is based on user selection and is not just one image its several associated images so there is a number sequence to the image file names as well that i did not show in the snippet i posted.
but i went back and plugged some of those returned values (resources ids?) from getIdentifier() into setImageResource() and it does indeed work so thanks for that - i have an idea what i was doing wrong before but for the sake of moving on im using a different solution now - in short i am now defining each group of images as a separate class member int[] and i will probably use a switch case to plug the correct one into the gridview. its ugly, but i currently only have 11 different groups and no more than 16 images per group so it will work for now until i can study the resource object more and figure out a way to get counts of associated image resources based on a part of the resource name, like with a regular expression or something, because thats the next problem i will have to deal with if i am not pre-defining all of these arrays.
if you know of a way to do that that would be awesome but ill will probably look into it more myself once i get this app closed up and can go back and fix stuff. im pressed for time right now.
thanks
It's really bad thing to use getIdentifier() method, we should always use R class. I think your problem resides somewhere before, you try to do something, that you shouldn't
How do you get these strings? You mentioned they are from user, but he doesn't write them by hand, right? If this is some selectable list, etc., they should be ints, enums, or some objects from the beginning. Not strings. Parsing strings is always ugly.
Ahh and if you have group of many small images, it is usually better to concatenate them into one big image - it's more efficient and you don't have to use 200 R constants in your code.
the string comes from the tag associated with a clickable imageView selected from the previous screen - a menu item if you will. the string will serve several purposes, retrieving related data, etc, but the first thing i needed to work out was retrieving the correct images and displaying them. i dont know how i could concatenate the images into one big image because each one needs to be clickable itself and handle certain events associated with itself.
i will go ahead and admit this is my first app so im basically figuring stuff out as i go. and learning most of my oop from flash has probably handicapped me
i appreciate your help dude
Brut.all said:
it's more efficient and you don't have to use 200 R constants in your code.
Click to expand...
Click to collapse
the only other thing i could think of trying was creating an xml doc to group the associated resource names together and figure out how to read from that to know which images to set
i dont see any methods in the R class i could use for sorting, grouping and then retrieving certain resources based on user interaction
switch cant eval string types...!?
kadmos said:
switch cant eval string types...!?
Click to expand...
Click to collapse
Nope
As I said, strings aren't good for identifying things - regardless of the language used. This is why people created int constants and/or enums.
And no, I doubt there are some mechanisms of grouping resources, etc. It must be simple, you are trying to complicate everything
I have a strong feeling that you should change your app architecture and get rid of strings. But here quick general fix (not a good solution! but just works).
Map your strings to R ints:
Code:
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("button_normal", R.drawable.button_normal);
map.put("button_pressed", R.drawable.button_pressed);
// etc
Accessing will be done:
Code:
map.get("button_" + state); // Return int id, use as you need.
This is a bad practice, but it will work. Consider re-archirecturing your app.
@Brut.all: do you have any plans on updating apktool with 2.2 support?
@kadmos
Full example:
Code:
public static enum Planet {
MERCURY(R.string.planet_mercury, R.drawable.planet_mercury),
VENUS(R.string.planet_venus, R.drawable.planet_venus),
EARTH(R.string.planet_earth, R.drawable.planet_earth),
MARS(R.string.planet_mars, R.drawable.planet_mars);
public final int nameResId;
public final int imageResId;
public static Planet findByNameResId(int nameResId) {
for (Planet p : values()) {
if (p.nameResId == nameResId) {
return p;
}
}
return null;
}
private Planet(int nameResId, int imageResId) {
this.nameResId = nameResId;
this.imageResId = imageResId;
}
}
You have enum of planets, each of them has its name and image. Then you could do something like:
Code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
for (Planet planet : Planet.values()) {
menu.add(0, planet.nameResId, 0, planet.nameResId);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Planet planet = Planet.findByNameResId(item.getItemId());
doSomethingWithPlanetImage(planet.imageResId);
return true;
}
You identifies planets by ints (nameResId in this example - of course it must be unique), not by strings. Operations on ints are several times faster, than on strings, this is why Google decided to identify all things: resources, menu items, etc. just by ints.
Ahh and no, writing switch-cases to do something depending on given object isn't true OOP. OOP is above: enums know, which drawable is connected to them, there is no need for switches.
AuxLV said:
@Brut.all: do you have any plans on updating apktool with 2.2 support?
Click to expand...
Click to collapse
Yeah, of course, I want to work on apktool this weekend. Unfortunately baksmali doesn't support Froyo yet, so I can't support it fully neither.
@Brut.all:
Ha, I recognise that example It's from the Java Trail/tutorial on enums isn't it? Except they used gravity rather than drawable references.
@kadmos:
Are all the images known from the beginning? In other words, is the user creating them at runtime or are you including them with your app? If they are included with your APK then normally, as Brut said, you should be able to use the identifiers directly.
Concatenating the images all into one isn't hard to do, as you can still draw the specific bitmaps out using the Bitmap.create(bitmapToGetAPartOutOf, ....) method. You can then make those individual bitmaps into ImageViews and only have to remember the 'grid reference' for where they came out of the big image. That said, you'd have to balance the added complexity of creating the big images against the ease of not having loads of R constants. I can't really say anymore because I'm not fully following what you're trying to achieve.
Steven__ said:
@Brut.all:
Ha, I recognise that example It's from the Java Trail/tutorial on enums isn't it? Except they used gravity rather than drawable references.
Click to expand...
Click to collapse
I took planets example, because it's good, but everything was written from scratch
Steven__ said:
Concatenating the images (...)
Click to expand...
Click to collapse
I'm pretty sure I saw this concatenating approach somewhere in official Android's guidelines for performance, but now I can't find it :-/ Also I don't have much experience in Android development, so if no one else suggest this approach, then I think kadmos could forget about it.
Brut.all said:
You identifies planets by ints (nameResId in this example - of course it must be unique), not by strings. Operations on ints are several times faster, than on strings, this is why Google decided to identify all things: resources, menu items, etc. just by ints.
Ahh and no, writing switch-cases to do something depending on given object isn't true OOP. OOP is above: enums know, which drawable is connected to them, there is no need for switches.
Click to expand...
Click to collapse
i know its not true oop i didnt want to have to do that but i have not yet seen a way to pass any value from a selected item into a method that could use that value to retrieve x amount of associated resources (images in this case).
Steven__ said:
Are all the images known from the beginning? In other words, is the user creating them at runtime or are you including them with your app? If they are included with your APK then normally, as Brut said, you should be able to use the identifiers directly.
...I can't really say anymore because I'm not fully following what you're trying to achieve.
Click to expand...
Click to collapse
using the planets example, say i had x (varying) amount of pics of each planet's surface in my drawables and wanted only those planet's pics to display in a grid view when a user selects whichever planet. thats really all this is. being new to this i just dont know the most efficient way to do it. if this was Flash i could just group all the images file names/paths in an external xml doc and use that to load them from whatever folder at runtime - i wouldnt need any of those 200 or so images declared as anything or even as assets in my library (and i would only need the xml because flash cant access a file system on its own to see and filter files that it would or wouldnt need based on, say, a string comparison - though there is third party software like Zinc that gives Flash that capability.)
so i did get this to work by passing a number as a tag (string) in a bundle though an imageView click event and then casting the string as an int to use in the switch - which as of now leads to one of 11 different int arrays of resources names (images) ive got declared in my ImageAdapter class to populate my gridView.
the way i wished i could made this work would have been to use a string (like a planet name) ,passed from whatever planet image/menu item/whatever was clicked, and use that string to compare and determine which and how many images in drawables were associated with that planet and then use that to create my gridView at runtime.
kadmos said:
so i did get this to work by passing a number as a tag (string) in a bundle though an imageView click event and then casting the string as an int to use in the switch - which as of now leads to one of 11 different int arrays of resources names (images) ive got declared in my ImageAdapter class to populate my gridView.
Click to expand...
Click to collapse
I see what you're saying, that makes sense. Just as a quick note though, if you're declaring your ImageViews programmatically, you don't have to use a string object for the tag. You can directly give the integer and then cast it back when you get the tag. Just remember to use (Integer) as the tag is actually just an unspecified object.
kadmos said:
the way i wished i could made this work would have been to use a string (like a planet name) ,passed from whatever planet image/menu item/whatever was clicked, and use that string to compare and determine which and how many images in drawables were associated with that planet and then use that to create my gridView at runtime.
Click to expand...
Click to collapse
Yes, I can see why you'd want to do it this way. Your current problem is that if you add more images, you have to manually update your arrays. Unfortunately I can't think of a better, 'clean' way of doing it.
@kadmos
Now I have problems understanding you ;-) But if you don't want to declare all images in sources, but in XMLs, then you could use XML arrays.
Code:
<resources>
<string-array name="planet_names">
<item>mercury</item>
<item>venus</item>
<item>earth</item>
<item>mars</item>
</string-array>
<integer-array name="planet_images">
<item>@array/mercury_images</item>
<item>@array/venus_images</item>
<item>@array/earth_images</item>
<item>@array/mars_images</item>
</integer-array>
<integer-array name="mercury_images">
<item>@drawable/mercury_0</item>
<item>@drawable/mercury_1</item>
<item>@drawable/mercury_2</item>
</integer-array>
<integer-array name="venus_images">
<item>@drawable/venus_0</item>
<item>@drawable/venus_1</item>
<item>@drawable/venus_2</item>
</integer-array>
<integer-array name="earth_images">
<item>@drawable/earth_0</item>
<item>@drawable/earth_1</item>
<item>@drawable/earth_2</item>
</integer-array>
<integer-array name="mars_images">
<item>@drawable/mars_0</item>
<item>@drawable/mars_1</item>
<item>@drawable/mars_2</item>
</integer-array>
</resources>
When user will open planet selector, you will iterate through contents of R.array.planet_names array, each item (planet) in this selector will have itemId set to array index. When user will click on something, you will get itemId of clicked item, then you will find array of its images as R.array.planet_images[itemId] (not exactly - it's conceptual example).
You will be able to add new images or even planets through XML editing.
Steven__ said:
Yes, I can see why you'd want to do it this way. Your current problem is that if you add more images, you have to manually update your arrays. Unfortunately I can't think of a better, 'clean' way of doing it.
Click to expand...
Click to collapse
Brut.all said:
But if you don't want to declare all images in sources, but in XMLs, then you could use XML arrays...
...You will be able to add new images or even planets through XML editing.
Click to expand...
Click to collapse
as i posted earlier this was the idea that i had - i havent tried it yet because i wanted to get some feedback from you guys just to see if i was completely off base. so right now its coming down to what would make for the more memory efficient final product - declaring all these images as class array constants (which i already have working) or using xml and coding the operations for parsing, counting, filtering, assigning, etc?
again thank you guys for your time and help
kadmos said:
or using xml and coding the operations for parsing, counting, filtering, assigning, etc?
Click to expand...
Click to collapse
Do you mean parsing XMLs? My example above uses standard Android resources. You don't have to parse these XMLs, you will get them as arrays And yes, it's super efficient, because they are compiled to easy-to-read form
ok then im going to go ahead and try it
be back soon
i hope

help with my time organizer app

I'm developing an organizer app as my bc. thesis and I don't have any real Android developer to consult, so I made this thread and hope somebody will help me and point me in the right direction.
I just started to work on it and I have roughly 1 month to make something useable out of it.
So... the first thing that comes to my mind right now is synchronization.
1. I don't know if I should implement it or not.
I have a hosting with 1.5 GB space, a relatively fast connection. Would syncing data (text (probably xml) only) with this server slow it down significantly ? How many users could an average server take ?
And another one regarding sync:
2. I'd like my application to exchange data with my server under the google account on which the device is logged in, so no registration will be neccessary (I suppose the majority of devices are loggen in with google). I'll probably need to get the user's google account name on every sync session. Is that possible ?
The app will already have a server-side app to edit your events and stuff, so I'll need the user's login information again to retrieve his data from my database, but I won't have his password, so I can't make a usual login form. I guess Google has some API to figure out if a user is logged in, doesn't it ?
Any advice will be appreciated.
Can I open a menu with a simple button click ? Like a context menu but for short clicks.
// I solved the **** outta this one.
Still waiting for answers on the first post.
"Organizer App" really doesn't tell us what you're trying to do. It's hard to answer questions if one doesn't know that basic plan of the project you're trying to create.
Check this -> Basic info about my bc thesis
Nice web page...ambitious project for a 4 week time frame.
As a programmer, you know to start small and add functionality as your program grows.
I would start by making a simple"To Do" list: Add item, Delete item, Edit item, Mark item done, Save this list, Recall a list, Delete a list.
Post back when that's done
Rootstonian said:
Nice web page...ambitious project for a 4 week time frame.
As a programmer, you know to start small and add functionality as your program grows.
I would start by making a simple"To Do" list: Add item, Delete item, Edit item, Mark item done, Save this list, Recall a list, Delete a list.
Post back when that's done
Click to expand...
Click to collapse
Agreed 100%.
@ OP:
I don't know much about syncing, but it won't have a large cost of the server's resources - syncing an CSV or XML file is pretty trivial. Even if you have a low bandwidth cap, text files are quite small. So you should be fine in terms of that.
Nobody can give you a "set number" - ie. the server can take "X people." It greatly depends on the server type, how much bandwidth is allocated to you, your traffic priority, etc. I mean if it's one server with like a xeon processor then it can probably handled a pretty heavy load (say 50 probably? (and yes, I'm kind of pulling that number out of my ass)). Though most web hosts don't just dedicate one server to each customer. Typically, now-a-days, everything is virtualized. Everything is unified using server farms (ie. multiple servers or computers) virtually, then virtual chunks of resources are distributed to clients. So even if somebody could give you exact numbers (which is impossible), they'd most likely be wrong. That is unless you paid extra to have a particular server or particular number of servers dedicated to you...but even then, there's a high chance that it's just a chunk of a virtual server farm.
He's right, this is pretty ambitious in a 4 week period, especially if you have other activities going on as well. It's even more ambitious if this is your first app. You may want to reconsider your objectives given your time frame.
As for the google login, you'd need to look at the google API, and see if there's a way to verify peoples' usernames and passwords. If you can, then it's just a matter of encrypting them and storing them in a properties file or something.
Hope that helps ya out some.
Rootstonian said:
Nice web page
Click to expand...
Click to collapse
Thank you
I know, I know. I could have started 4 months ago. But I didn't, the lazy bastard I am.
This is the practical part of my bc thesis. The ultimate deadline is 3rd of june, but I have to have my theoretical part (30-50 pages of text, if IIRC) done by then, all printed out and ****. So I plan to work as hard as I can on this till the end of this month and then start to work on both at the same time. I really don't have any other duties in school, since I have a nice reserve of credits so this is my priority #1.
The main objective is geo-tasks, since that's what the name of my thesis says. Everything else is just an addition (i.e. the widget, that was just an idea, I doubt I will have time for that). So I'd rather start with that (I know, It's the hardest part). Or do you still think I should start with the to-do's ?
You can check out my last night's post to see what I've been up to the last 2 days and what I'll be up to next.
What is your level of Android programming experience (None, Basic, Intermediate, Advanced)?
And I'm a little fuzzy on the whole "Geo" thing. Is it like I have a list "Get milk, bread eggs", "Pick-up dry cleaning", "Get oil change" and then your app is going to "sense" when I'm by the grocery, dry cleaner's and oil change place? Which grocery? I use 4 different stores. Same dry cleaner and oil change though usually.
If so, you are going to need to code in lat/long coordinates for these places and then compute your location vs one of the merchants, compare that merchant to an "active" TO DO list item and pop-up an alert of some sort if you're within a mile. Wow
Your project, you know your skill level. Start where you want I guess LOL.
I think it's more of an agenda type thing - that syncs.
@Rootstonian
I'd say basic, but quickly crawling up to intermediate.
It's almost like you said, but there's only one location for every task. Maybe in a later version...
Well, good luck. Keep us posted
Will do. Hope you guys will keep on helping me
I need to use my database object in more than one activity. How do I pass it from one activity to another ?
Should I create a new instance in each activity ? Or should I create a content provider ? (I'd rather not - they're quite complicated for me and I only need to access the DB in this app).
I'm going to assume you are using a database helper type class.
No need to pass data from Activity to Activity; just open, use and close the database in each Activity as required.
I have a problem.
I created a LinearLayout for all the tasks in the database. Now I want to register all of them for a context menu. I can do that, but I can't figure out which one's menu was triggered.
LinearLayout has a setId method, but it only takes integer values, which is no good for me, because I have 3 types of tasks and if I assign them their id from the database, then the same ID will probably be assigned to 3 different views.
I could use some sort of multiplication, like for timed tasks I would multiply the ID by 10 000, but that's not elegant at all, and it would crash after a few months of using the app.
So what do I do now ?
I'll paste some code.
Code:
public void drawTasks() {
TextView emptyText = (TextView) findViewById(R.id.empty_todo);
if (tasks.isEmpty()) {
emptyText.setVisibility(View.VISIBLE);
} else {
emptyText.setVisibility(View.GONE);
Iterator<Task> it = tasks.iterator();
//create views
while (it.hasNext()) {
//create a temporary object
Task tmpTask = it.next();
//get it's properties
long id = tmpTask.getId();
String title = tmpTask.getTitle();
String description = tmpTask.getDescription();
int important = tmpTask.getImportant();
int finished = tmpTask.getFinished();
//create new LinearLayout for this task
LinearLayout newTaskLayout = new LinearLayout(this);
newTaskLayout.setId((int)id);
newTaskLayout.setOrientation(LinearLayout.VERTICAL);
newTaskLayout.setPadding(5, 0, 0, 10);
taskLayouts.add(newTaskLayout);
//create new views for these properties :
//title
TextView newTaskTitle = new TextView(this);
newTaskTitle.setText(title);
newTaskTitle.setTypeface(null, Typeface.BOLD);
//important tasks are highlighted
if (important == 1)
newTaskTitle.setTextColor(Color.RED);
//finished tasks are italic
if (finished == 1)
newTaskTitle.setTypeface(null, Typeface.ITALIC);
//description
TextView newTaskDescription = new TextView(this);
newTaskDescription.setText(description);
if (finished == 1)
newTaskDescription.setTypeface(null, Typeface.ITALIC);
//add views to this tasks' LinearLayout
newTaskLayout.addView(newTaskTitle);
newTaskLayout.addView(newTaskDescription);
//add new linearLayout to tasksRootLayout
tasksRootLayout.addView(newTaskLayout);
}
}
}
This is self-explanatory. taskLayouts is an ArrayList of LinearLayouts where I keep the pointers to all layouts that need to have a context menu.
There are 2 other similar methods: drawTimedTasks() and drawGeoTasks() which do basically the same (I couldn't figure out a way to do it with one universal function).
Here's how I register them for context menu:
Code:
private void registerViewsForContextMenu() {
//register control bar buttons
registerForContextMenu(newGeoTaskButton);
registerForContextMenu(newTaskButton);
Iterator<LinearLayout> it = taskLayouts.iterator();
while (it.hasNext()) {
registerForContextMenu(it.next());
}
}
And here's how I'm checking for context menu trigger:
Code:
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case ...
return true;
}
...
}
return false;
}
What am I doing wrong ?
Anyone ?
----
I haven't really been following this thread so I don't know all the details of your app, but I'll try to help.
So each task has 3 views for it? Each task is in the db once? I'm a little foggy on how you're storing them and what the correlations are between views, events, and types of event, more specifically the latter.
If you explain that a little more clear, I can try to help a little better.
There are 3 types of tasks : simple, timed, and geo tasks. Each type has its own table in the db, hence it's own IDs. That means, the first geo task, first simple task, and the first timed task ever added have all the same ID = 1. That means if I want to give their views unique IDs, I can't use their IDs from the database.
So I'm trying to figure out a way how to give the view ID's so I can find out which database record they represent.
In an ideal world, I would be able to define a string ID (i.e. geo_1, simple_1, timed_1), but this is not the case. I dunno why... in XML you give your views string IDs, but programatically you can't.
grandioso said:
There are 3 types of tasks : simple, timed, and geo tasks. Each type has its own table in the db, hence it's own IDs. That means, the first geo task, first simple task, and the first timed task ever added have all the same ID = 1. That means if I want to give their views unique IDs, I can't use their IDs from the database.
So I'm trying to figure out a way how to give the view ID's so I can find out which database record they represent.
In an ideal world, I would be able to define a string ID (i.e. geo_1, simple_1, timed_1), but this is not the case. I dunno why... in XML you give your views string IDs, but programatically you can't.
Click to expand...
Click to collapse
If all of the tasks have common elements (even if they don't really), you can merge them into one table. Then define an enum or something for the task type, as a simple field in the table. This removes the issue with duplicate ID's, while still being able to differentiate what type they are. You can typically leave fields blank in a database, so you wouldn't have to worry about what's filled in for tasks that don't have particular fields associated with them, just verify all fields prior to mutating the database.
If you're hellbent on keeping three separate tables you can hold a global ID, which can be an intersection between all three tables. So this wouldn't be the primary key, just a global ID, and you can key them up by that. Not entirely sure where you'd keep it to persist over power cycles unless you just make a 4th table with one row and store it in there. Or just throw it in the program's data somewhere.
The reason you can define things in the XML is he XML is compiled into the R class at compile time...though everything in there *should* have a corresponding methodology to get it done programatically. Though if you're talking about the primary key, as far as I know that is always numerical. So the ideal world may not apply - BUT, that doesn't mean you can't create a field that stores a string id (which I wouldn't, because string comparisons take a lot of time, but whatevs).
Hope that helps you out some, I don't really touch databases and am very new to Android programming, just know what I know from absorbing info from others - but I know a pretty decent amount about programming in general and know Java pretty well so I can probably help you out the best I can in some respects.

[ help needed ]

Hello to everyone.
I am new comer in the world of Android App Development.
I am completely new in android app development.
I want someone to teach me some basics so that I can learn that and them implement my own imagination to build a desire app.
Firstly, I have installed the adt_bundel which include SDK and eclipse.
When I first started using android, I learned that it is open source that means we can easily free the source code of it.
when I started using apps and games I always thought to make an android app for me.
So for that reason I m posting this.
I want to create a very simple app in which there are 3 buttons and when click on that button the background should change.
Eg: There are 3 button red,blue,green. so if I press the red button the background should change to red color and vise versa.
So can anyone please help me in building my very 1st own Android App.
What about video tutorials on youtube? For me the tutorials from 'thenewboston' helped a lot
tschmid said:
What about video tutorials on youtube? For me the tutorials from 'thenewboston' helped a lot
Click to expand...
Click to collapse
I tried mate and I got many tutorials on google with code but I didnt got clear idea. Mostly the example they all use in the tutorial is making calculator in which there are 2 text input field and 1 button. by pressing that both number will add.
I don't want that.
I have created many app in VB.Net in my college. Infact created a mini notepad and mini calculator.
Actually I have created the app in vb.net in which if we press the desire button it will change color. So I thought why can't I make for the Android too.
It's easy
Set OnClickListener for ur buttons to listen for click events.
e.g For changing color to red
red.setOnClickListener(new View.OnClickListener({
// use the reference to ur background layout and set the color
urBackgroundLayout.setBackgroundColor(Color.Red);
}));
Do the same for the other two buttons.
I hope this was helpful!
P.S : braces in the code snippet might b incorrect.
red.setOnClickListener(new View.OnClickListener{
public void onClick(View v) {
urBackgroundLayout.setBackgroundColor(Color.Red);
}
});
Yeah the braces are indeed not quite correct. Also i think you must put the onClick method inside the listener.
OkieKokie said:
Set OnClickListener for ur buttons to listen for click events.
e.g For changing color to red
red.setOnClickListener(new View.OnClickListener({
// use the reference to ur background layout and set the color
urBackgroundLayout.setBackgroundColor(Color.Red);
}));
Do the same for the other two buttons.
I hope this was helpful!
P.S : braces in the code snippet might b incorrect.
Click to expand...
Click to collapse
Thanks bro for replying.
Actually I a complete noob here.
I have created a graphical layout of my app with 3 bottons red blue and green.
Now the noob question is where I have to do the coding.
I have seen in many tutorial that the coding is done under src->package->.java file.
please correct me if I am wrong....
Masrepus said:
red.setOnClickListener(new View.OnClickListener{
public void onClick(View v) {
urBackgroundLayout.setBackgroundColor(Color.Red);
}
});
Yeah the braces are indeed not quite correct. Also i think you must put the onClick method inside the listener.
Click to expand...
Click to collapse
The same question goes to you bro.
Can you please explain in detail
what are the things I need to do.
Thanks
Mustakim_456 said:
The same question goes to you bro.
Can you please explain in detail
what are the things I need to do.
Thanks
Click to expand...
Click to collapse
Start a new Android app project in eclipse and it will generate a MainActivity.java file for you, do the coding there.
Also u will need to add views to ur graphical layout. After creating a new project go to the 'res' folder, then go to 'layouts' and open ur activity_main.xml. Add views to this file by dragging from the left pane onto the view.
Inside the MainActivity.java you will find a method called onCreate()
Inside it you put the code we gave you. This method is called when the app is started up, so all the initialising etc like setting button onClickListeners you have to do, is normally being put inside this onCreate()
You will also have to create a layout.xml for your app in which you put your buttons and one background layout, for example a linear layout, which will later change its colour.
All about how to make such a layout can be found in every video tutorial series you will find. I could recommend the mybringback youtube channel.
Now inside the code you got for the button, the button is being referred to as 'red' (see red.setOnClickListener(...) )
So now to be able to do that, before that you will have to declare that specific button:
Button red = (Button) findViewById(R.id.yourButtonId);
Click to expand...
Click to collapse
Same thing goes for the background layout, i will give you the example for a LinearLayout:
LinearLayout urBackgroundLayout = (LinearLayout) findViewById(R.id.yourLayoutId);
Click to expand...
Click to collapse
I called it urBackgroundLayout because in the code posted above it is being referred to as this. You can change it to whatever name you desire.
Now android knows which button the button 'red' actually is, when you replace the 'yourButtonId' with the id of that specific button. (Read about view ids in android on google or inside a tutorial video)
Same thing for the linear layout
Now after declaring all of your buttons that way, maybe Button green and Button blue,... You just copy/paste the code above for each button you have, e.g. 'blue.setOnClickListener' and 'green.setOnClickListener' and change the 'Color.Red' to each desired color, voila you are done!
Masrepus said:
Inside the MainActivity.java you will find a method called onCreate()
Inside it you put the code we gave you. This method is called when the app is started up, so all the initialising etc like setting button onClickListeners you have to do, is normally being put inside this onCreate()
You will also have to create a layout.xml for your app in which you put your buttons and one background layout, for example a linear layout, which will later change its colour.
All about how to make such a layout can be found in every video tutorial series you will find. I could recommend the mybringback youtube channel.
Now inside the code you got for the button, the button is being referred to as 'red' (see red.setOnClickListener(...) )
So now to be able to do that, before that you will have to declare that specific button:
Same thing goes for the background layout, i will give you the example for a LinearLayout:
I called it urBackgroundLayout because in the code posted above it is being referred to as this. You can change it to whatever name you desire.
Now android knows which button the button 'red' actually is, when you replace the 'yourButtonId' with the id of that specific button. (Read about view ids in android on google or inside a tutorial video)
Same thing for the linear layout
Now after declaring all of your buttons that way, maybe Button green and Button blue,... You just copy/paste the code above for each button you have, e.g. 'blue.setOnClickListener' and 'green.setOnClickListener' and change the 'Color.Red' to each desired color, voila you are done!
Click to expand...
Click to collapse
Thank you soo much... Learned a lot..
Mate I will tell you what I have done in detail ok. you correct me if I a doing something wrong.
1. Opened eclipse and selected new -> android project -> and created my app.
2. By default there is hello world text. so I deleted the text.
3. By default there is a layout i.e relative layout
4. So I dragged linear layout from the layout section. but got an warning message of something like there there is no id, no style etc. So I selected style from property windows and the warning message got dissappear
5. Then I inserted a large text. pressed F2 to change text of it. created a new string -> inserted name as My First App
6. After that I dragged 3 buttons. Again pressed F2 to change text and id off all the button by creating new string -> name as Red, Blue and Green and ID as button1, button2 and button3.
7. After that my app graphical layout is finished.
8. After that as you said I have to write code in MainActivity.java file. So in src folder and my package I opened up MainActivity.java file. By default there were 2 onCreate() Functions. When I try to write any code inside the onCreate() it gives me an error.
Please correct me.
If you provide me with a zip of the whole project folder, i would have a look at it if you would like
Mustakim_456 said:
Hello to everyone.
I am new comer in the world of Android App Development.
I am completely new in android app development.
I want someone to teach me some basics so that I can learn that and them implement my own imagination to build a desire app.
Firstly, I have installed the adt_bundel which include SDK and eclipse.
When I first started using android, I learned that it is open source that means we can easily free the source code of it.
when I started using apps and games I always thought to make an android app for me.
So for that reason I m posting this.
I want to create a very simple app in which there are 3 buttons and when click on that button the background should change.
Eg: There are 3 button red,blue,green. so if I press the red button the background should change to red color and vise versa.
So can anyone please help me in building my very 1st own Android App.
Click to expand...
Click to collapse
1)The first question is whether you know how to use the Java programming language fluently. That's a prerequisite.
2)If that's a yes then do you understand how the Android activity and fragment life cycle works and looks like? Probably not. Android is a lot about java APIs.
3)Goto https://developer.android.com and start learning Android APIs!
Maybe I'll write a startup guide to Android app programming. Give this a plus one if you'd like that! :thumbup:
Sent from my Nexus 4 using XDA Premium 4 mobile app
Masrepus said:
If you provide me with a zip of the whole project folder, i would have a look at it if you would like
Click to expand...
Click to collapse
sure I will provide you when I go back home. now I am in college.
boggartfly said:
1)The first question is whether you know how to use the Java programming language fluently. That's a prerequisite.
2)If that's a yes then do you understand how the Android activity and fragment life cycle works and looks like? Probably not. Android is a lot about java APIs.
3)Goto https://developer.android.com and start learning Android APIs!
Maybe I'll write a startup guide to Android app programming. Give this a plus one if you'd like that! :thumbup:
Sent from my Nexus 4 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
+1
bro I don't know any thing much in programming.
I have just learned very basic java programming in my college as tere was a subject. what I learned in my college and what I see in tutorials of android is completely different. so in short I am completely new to android and its java programming.
if you don't mind could you make a step by step guide of android app development as my app as an example. it would be very useful too.
Yeah the thing with android and java that you learn in school is this: if you learn java, you got i would call it the ability to use the basic operations you later definitely need for programming android, as android is obviously a java api. But in many cases android has different ways of approachal, one of the biggest being the activity system.
So learning java is important, but you have to know that some of the stuff you learn there you wont ever use with android.
Masrepus said:
Yeah the thing with android and java that you learn in school is this: if you learn java, you got i would call it the ability to use the basic operations you later definitely need for programming android, as android is obviously a java api. But in many cases android has different ways of approachal, one of the biggest being the activity system.
So learning java is important, but you have to know that some of the stuff you learn there you wont ever use with android.
Click to expand...
Click to collapse
I think thats the thing. Because there is no such thing which I learned in college goes for android programming. I learned different types of constructor and inheritance etc .
but in android its totally different.
Mustakim_456 said:
I think thats the thing. Because there is no such thing which I learned in college goes for android programming. I learned different types of constructor and inheritance etc .
but in android its totally different.
Click to expand...
Click to collapse
Yes constructor is such an example, because with android you only use it if you got a more complex project with more classes that are no activities. In any other case you put initialising things in onCreate() that you would normally put in the constructor
Same thing with inheritance, it is only needed if you use more complex projects. But you should anyways at least know what it is and how it works
Masrepus said:
Yes constructor is such an example, because with android you only use it if you got a more complex project with more classes that are no activities. In any other case you put initialising things in onCreate() that you would normally put in the constructor
Same thing with inheritance, it is only needed if you use more complex projects. But you should anyways at least know what it is and how it works
Click to expand...
Click to collapse
yeah bro I know how to do inheritance and initialize construtor but here its of no use na...
Here is the zip of my project.
No coding is done. its only graphical layout of my app.

Resources