Hi,
I have been trying to get to grips with Android.
First off I guess, any good books you can recommend? I have Hello, Android which has some good examples, but some of the things leave me a little cold in that it seems overly simplistic and then seems to fail to pick up on some latter crucial points, not least about creating custom adapters.
Anyhow, back to the questions.
Firstly, various devices, like the Samsung Galaxy S uses a "blue" summary line in its settings menus. Looks good. But if you want to mimic that style outside of a summary menu, is it possible to get details of system colours?
Secondly, in terms of icon design, tab icons in as defined in the Android SDK seem to suggest using a Grey icon for off and a white icon for on. This seems to bit a bit foolish when the tabs are white.... and most of the other programs I've seen that use tabs have Grey icons for on and white icons for off! Thoughts?
Third, back to this book, one of the examples it gives, is a way to load data from a SQL database using Cursors and SimpleAdapters. Im guessing if I want anything more than a relatively simple list and data pulled from the database, that Im going to need to use a CustomAdapter.
In terms of these cursors though, some of the code does this in the onCreate:
Code:
Cursor cursor
CustomDatabaseHelper test = new CustomDatabaseHelper(this);
try {
cursor = getData();
showData(cursor);
} finally {
test.close();
}
I think I found a couple of problems with that... The CustomDatabaseHelper and Cursor are both local to the onClick method and therefore if I need to access these via a Buttons onClick Im stuffed unless I make them private/public to the class. I don't know the best way around this TBH, what would you suggest? I guess I could define another CustomDatabaseHelper in the onClick method, but Im not sure whether it is a good idea to keep opening all these references.
Plus as well in onClick, you can't give a context of "this" because it's it's not a context there its an OnClickListener?
Code:
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
}
And there must be a better way of refreshing the data set? I've tried cursor.notify, test.notify and globalising the adapter and doing adapter.notifyDataSetChanged(); things still don't refresh.
Im going to guess this is a pretty basic and common issue for newcomers trying to understand this that super context intent.
I think Im getting there, Im just trying to get a bit of background to a few of the basic issues Im having a bit of trouble with and find out what the best way to handle the issues are.
Oh, the showData function (which I call after any data change at the moment), does this:
Code:
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.test_item, cursor, Columns, TO);
I think that'll do for now, as my next issues are about SQL, Dates and Formatting.
Thanks
Simon
I think my problem stems around this book of mine... I can do a "notifyDataSetChanged()" on the adapter provided I don't do the "test.close" as above.
This suggests to me the DB Helper should be open across the activity lifetime.
Is that right?
Related
Hi all,
I am using eVC++ 4.0, and i've dynamically created a CListView like this:
Code:
lv.Create(0,_T(""),WS_CHILD|WS_VISIBLE,r,this,5);
but I dont know how to handle the events of this control... any ideas??
Mohammad
To get events from a listview (win32) I normally subclass it. I use the subclassing routine to post a message back to the parent when the user is doing something like tapping on it, then the windows routine can check whats selected etc and act on it. Is subclassing possible in mfc ?( I don't use it).
Thank u
but can anybody post some code??
thnx
Ok, I am a bit lazy to look up code at the moment, but here's something:
Yes, subclassing is possible in MFC. You just derive your class from the basic class provided like this:
Code:
class MyListView : pubic CListView
Then you add message handlers in the normal matter.
EDIT: The following passage is incorrect:
But I think subclassing may not be necessary in you case. List box controls send WM_COMMAND messages with notifications of major events like selection change to the parent window. All you have to do is to create a WM_COMMAND handler in your parent class.
Sorry I was thinking of ListBox not list view when I wrote it.
To manually add message handlers you need to put macros like ON_MESAGE or ON_COMMAND in the DECLARE_MESSAGE_MAP section of the class cpp file. All the detaisl are available on MSDN.
Are you saying that a listview will send the same WM_COMMAND as a list box in mfc? Dose this also happen in win32 made listviews. I have always thought it was a bit too tedious to find out when the user taps an item in the listview.
After reading your post levenum I had a quick look and it says that a WM_NOTIFY gets sent to the parent with a LVN_ITEMCHANGED for example. I had not used the LVN_**** because when I looked at them there was none that seem to deal with selections. I would guess that LVN_ITEMACTIVATE or LVN_ODSTATECHANGED would be usefull for this but then a second tap would not be picked up still leaving me wanting subclassing in many situations to get the users tap.
Ok, I have read what u wrote guys and my problem is almost solved, I used the OnNotify() method to handle messages sent from child controls like this:
Code:
BOOL CTest2Dlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
// TODO: Add your specialized code here and/or call the base class
if(wParam ==5 ) //5 is control ID
{
NMHDR *ph =(NMHDR*)lParam;
if(ph->code==NM_CLICK)
MessageBox("Click");
else if(ph->code==HDN_ITEMCLICK)
MessageBox("Item Click");
else
{
CString str;
str.Format("%d",ph->code);
MessageBox(str);
}
}
return CDialog::OnNotify(wParam, lParam, pResult);
}
Now there still a very small prolem: what messages should I handle for 'Selected Item Changed' event ?? I know its easy but I couldnt find it
Regards
mohgdeisat: I am sorry, I made a mistake about WM_COMMAND.
OdeeanRDeathshead is right, I was thinking of a list box not list view.
To make up for this, here is some sample code from a win32 dialog app that uses list view control. I hope it will be of some help:
Code:
//this is from the dialog window function:
case WM_NOTIFY: //handle events:
nmhdr = (LPNMHDR)lParam;
switch (nmhdr->idFrom)
{
case IDC_LEDLIST: //list control ID.
return OnLEDListEvent(hwndDlg, (LPNMLISTVIEW)lParam);
break;
}
break;
BOOL OnLEDListEvent(HWND hwndDlg, LPNMLISTVIEW nmlv)
{
/////
// Handles list view control notification messages
switch (nmlv->hdr.code)
{
case LVN_ITEMCHANGED:
return OnLEDListItemChanged(hwndDlg, nmlv);
break;
}
return 0;
}
BOOL OnLEDListItemChanged(HWND hwndDlg, LPNMLISTVIEW nmlv)
{
if (ListView_GetSelectionMark(nmlv->hdr.hwndFrom) != nmlv->iItem) return 0;
/* do what you need here */
return 0;
}
Don't mind the fact that I used 3 different functions. This is part of a bigger program and I am trying to keep things well organized without resorting to classes.
As I understand it, LVN_ITEMCHANGE is received for different reasons so I try to handle only the one coming from selected item. LVN_ITEMACTIVATE is only sent when you double click the item so if you just want to catch selection change you need to use LVN_ITEMCHANGE.
Once again, sorry for confusing you before.
thanx pals, good job!!!
I think my problem is now solved with ur help :wink:
Mohammad
Ok guys, I said that my problem was solved, yet, another problem arises...
When the list view is in the report mode, how can I determine when a header button is clicked, and determine which one was clicked???????
thanx in advance
To identify a header column click, you need to handle the WM_NOTIFY/HDN_ITEMCLICK message. Normally this message will be received by the header's parent control (i.e. the listview) -- some frameworks may redirect the message to the header control itself. I haven't worked with MFC in 10 years so I can't really if it reflects notification messages back to the control.
If you're trying to implement column sort, do yourself a favor and check out the Windows Template Library (WTL) at sourceforge.net. It's a set of C++ template classes that provide a thin yet useful wrapper around the standard Windows UI components. One of the classes is a sortable listview control. I've been using WTL with big Windows for more than 5 years -- you couldn't pay me to go back to MFC.
hi,
I have seen the WTL library and it seems very useful and time-saver, but I have a couple of questions about it:
1. can WTL 8.0 be installed with VC++ 6.0, specifically the appwizard stuff??how?? I see only javascript files of vc7.0 and 7.1 and 8.0!!
2. is there a good documentation about those classes??
Mohammad
I don't know about WTL 8; I'm still using WTL 7.5 with VS .Net 2003 for all my Win32 development. My guess is that it wouldn't work too well, as WTL is based on ATL, which has substantially changed between VC 6 and 7.
Good references for WTL include www.codeproject.com/wtl, and the WTL group over at Yahoo groups (reflected at www.gmane.org).
My limited programming experience does not reach into the realm of android, as evidenced by the title of this thread. So I figured I'd ask for help.
Here is what I'm trying to do: Tie and activity to the Simi Clock launcher.
Unfortunately, it only lists apps in the launcher options, so I was wondering if there is an easy way to make an app out of an activity.
Any help is greatly appreciated.
Do you mean how do you make an app with an activity at all, or how to use it with the clock you mentioned?
A new app can be easily created using the ADT Plugin for Eclipse, a great thing to have. From there all you have to do is make a new class that extends Activity class.
You can use intents to run portions of other apps, but I am not sure if I quite understand what you mean.
roflha said:
Do you mean how do you make an app with an activity at all, or how to use it with the clock you mentioned?
A new app can be easily created using the ADT Plugin for Eclipse, a great thing to have. From there all you have to do is make a new class that extends Activity class.
You can use intents to run portions of other apps, but I am not sure if I quite understand what you mean.
Click to expand...
Click to collapse
Hehe, and I'm not sure I understand what you mean, but that's because I know diddly-squat about this stuff.
Let me be more descriptive:
- Let's say I have a widget, for example Beautiful clock, which allows me to to launch an app upon clicking on the clock numbers.
- I also have a launcher which allows me to make shortcuts directly to activities, for example wifi toggle. That acts like an app or widget if placed on a home screen.
- Now, I would like to be able to invoke that "wifi toggle" or other activity by clicking on the clock widget numbers. However, my clock widget only lists apps in "launch-able" options. Hence the dilemma.
Did that make any sense?
Yeah, I think I see what you're saying.
Well one thing worth noting is that the clock widget is most likely not pulling its list of possible applications based off of the ones you have links to or the ones in your drawer. What I am guessing is it using something called an Intent that allows it to filter for all of the apps that have a launch-able intent Your shortcut most likely doesn't have that.
What you could try doing is, since you were asking about Activities, is create a simple app that, when run, redirects you to the WiFi settings. All the code would be for such an Activity is
Code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent("android.settings.WIFI_SETTINGS");
startActivity(intent);
}
Like the attached apk... lol. Install it and try to map weather to it.
roflha said:
Yeah, I think I see what you're saying.
Well one thing worth noting is that the clock widget is most likely not pulling its list of possible applications based off of the ones you have links to or the ones in your drawer. What I am guessing is it using something called an Intent that allows it to filter for all of the apps that have a launch-able intent Your shortcut most likely doesn't have that.
What you could try doing is, since you were asking about Activities, is create a simple app that, when run, redirects you to the WiFi settings. All the code would be for such an Activity is
Code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent("android.settings.WIFI_SETTINGS");
startActivity(intent);
}
Like the attached apk... lol. Install it and try to map weather to it.
Click to expand...
Click to collapse
Thanks for the help. I love this place!
I´v published my first app on the Android Market. However I have little people in my direct suroundings who have Android Phones so hopefully there are a few people here who can help me by telling my what my application misses.
e.g. I think my app uses little battery power. So maybe anyone can confirm this to me?
becouse i am new to the forum (or .. well not new, but little posts) I can not put the link to my app here. Search on Triton Bubble Breaker on Appbrain or Market to download.
It is a bubble breaker game. Why I developed it when there are other alternatives on the market already? Because I missed the feeling I got when playing it on a old phone for the first time. Wanted to make it faster, simpler, free and maybe add some extra features (that should not be disturbing the simplicity of the game)
(when you are a coder.. I have (maybe a simple) question. When the game is finished I like to save the Score. However I can not do this from a DrawView? only from the main activity, so that i have to use menu buttons to call saving the score... is there a way to save data from view/drawview? )
Thanks in advance, and i wander what you think of my first attempt building a android app.
Good work! Very impressive for a first app!
for saving stuff, use these commands:
(put this at the begining of your class)
public static final String PREFERENCE_FILENAME = "AppGamePrefs";
(put this where you need it, usually located where you are doing the saving)
SharedPreferences gameSettings = getSharedPreferences("MyGamePreferences", MODE_PRIVATE);
SharedPreferences.Editor prefEditor = gameSettings.edit();
(get saved data like this)
score=gameSettings.getInt("score", 0); //"score" is the saved variables name, 0 is the default value incase the variable "score" has not been saved yet
(save like this)
prefEditor.putInt("score", points); // saves to variable "score" with value of variable points (you can change the putInt to putString, putBoolean, etc.)
(this finalizes the save VERY IMPORTANT)
prefEditor.commit();
Hope that helps, keep up the good work!
thanx for the reply. Starting writing in Java (?) was getting used to. I did had some experience with coding in Matlab (if that can be labled programming )
I have tried your advice, I have come across the same code on other fora and samples from google. Only problem is that it doesn't work in the class I am programming in, the drawview class.
In essence my program is setup like this:
public class activity extends Activity
...
public void onCreate(Bundle savedInstanceState) {
...
setContentView(drawView);
...
}
.. some other functions for the menu (from which i can do the code for storing data!)
then it goes into the drawView.
Here my program just draws and draws, until there is a touch on the screen, then it will calculate the new situation. But at a given moment, the game is finished. Then i will draw the finish screen (in the same drawview). I can not get out of this drawview. So i can not do setContentView(results_layout) or something like that. And i can not call the code for saving data because that can not be defined in that class (according to Eclipse).
public class DrawView extends View implements OnTouchListener {
...
@Override protected void onDraw(Canvas canvas) {
Draw everything
...
if game_end = true then {
drawResults
save-code here gives error
}
...
}
public boolean onTouch(View view, MotionEvent event) {
calculate everyting
...
game_end = check_game_end(); //return true or false
}
this is my code in essence. Ofcourse it not all, but this i hope you get my idea/problem.
Thanx for the response again
Hi Devs,
I was recently working on a radial menu widget for android. Since I didn't find many references (other than one), I thought of building my own. I am posting the link to download the library file and the tutorial. Please feel free to post back your comments for improvements.
You can also use it for any commercial project as it is free...just post a link of the app you will be using for..
Link
Link simply goes to link.com which cannot be found. First! :-D
Sent from my SPH-D710 using xda premium
The Real Sitek said:
Link simply goes to link.com which cannot be found. First! :-D
Sent from my SPH-D710 using xda premium
Click to expand...
Click to collapse
My bad...UPDATED :cyclops:
IMO, you should base the look off of the quick controls menu in the stock ICS Browser. It would be pretty damn awesome the look was inspired by that and PLUS it would match the android ICS UI perfectly.
Chew DZ said:
IMO, you should base the look off of the quick controls menu in the stock ICS Browser. It would be pretty damn awesome the look was inspired by that and PLUS it would match the android ICS UI perfectly.
Click to expand...
Click to collapse
Will update... :highfive:
I encourage you to keep this up, this surpasses mine with icons.
for text only menues, an idea would be to
Path arc = new Path();
arc.addArc();
canvas.drawTextOnPath();
This can be used with the right math to make a curved text appearance.
Heres my implementation:
http://dakunesu.dev.animuson.net/apps/radialExample.java
I discontinued mine as i had little to no use at the moment.
strider2023 said:
Hi Devs,
I was recently working on a radial menu widget for android. Since I didn't find many references (other than one), I thought of building my own. I am posting the link to download the library file and the tutorial. Please feel free to post back your comments for improvements.
You can also use it for any commercial project as it is free...just post a link of the app you will be using for..
Link
Click to expand...
Click to collapse
hi strider2023,
1st things first, great library, truly, saved me a lot of effort, looks pretty cool.
I'm currently implementing here in a project at work and I'm working directly on the source code (as I needed to customised a couple of stuff for specific needs), but I found some improvement on, and that's the reason for the post.
inside class RadialmenuWidget.java:
inside onTouchEvent(MotionEven e)
yuou're only detecting touches on the wedge itself, in my case here. the wedge will be a very soft 1 pixel width line and the icons is what the user will see and click, so I added the icon rectangle on the check, the first part is your current wedge point check, and after the OR checks for the point into the icon.
Code:
inWedge = helper.pntInWedge(eventX, eventY, xPosition, yPosition, MinSize, MaxSize, (i * slice) + start, slice)
|| iconRect[i].contains(eventX, eventY);
inside class RadialmenuWidget.java:
inside onDraw(Canvas c)
I've included code to set the proper drawable state for the icon, just after you get the Drawable from the resources so now when you click on the icon it change state appropriately.
Code:
if (f.equals(selected)) {
drawable.setState(new int[] { android.R.attr.state_pressed });
} else {
drawable.setState(new int[] { -android.R.attr.state_enabled });
}
inside the class RadialMenuItem:
the interface RadialMenuItemClickListener
I've changed it completely for two reasons, 1) method name better mimic android naming, 2) it receives the item back to make possible implement only one listener.
Code:
public interface RadialMenuItemClickListener {
public void onItemClick(RadialMenuItem item);
}
so then on the implementation I can do something like this and only have one listener object.
Code:
private RadialMenuItemClickListener menuClick = new RadialMenuItemClickListener() {
@Override
public void onItemClick(RadialMenuItem item) {
String name = item.getName();
Log.d(TAG, "Menu click: " + name);
if (name.equals("item1")) {
} else if (name.equals("item2")) {
}
}
};
hope it helps improving the library.
I am using one edit text view and one OK button to input a large amount of user data during a setup function but can't figure out how to pause the thread execution unit the OK button is pressed. I don't want to have to register and use a ton of different buttons and listeners to call individual functions for each user input and so far I've found out the hard way that a while look will lock the UI thread and running the loop in a separate thread will not make the program wait. Any Ideas?
public class SetupMenuActivity extends Activity
{
private TextView setupPrompt;
boolean okButtonPressed = false;
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_menu);
setup();
}
private OnClickListener okButtonListener = new OnClickListener()
{
@override
public void onClick(View v)
{
okButtonPressed = true;
}
};
private void setup()
{
Button okButton = (Button) findViewById(R.id.okButton);
okButton.setOnClickListener(okButtonListener);
setupPrompt = (TextView) findViewById(R.id.setupPrompt);
setupPrompt.setText("Please Enter Your Name");
// Make program wait for ok button clicked
setupPrompt.setText("Please Enter a Name for your Account");
}
}
What else could the user click/etc that you want to prevent from happening? If you want to block another button, then you can either do button.setClickable(false) or even button.setVisibility(View.GONE) until the ok button is clicked. Instead blocking the whole thread doesn't make much sense
The only two things the user can interact with is the button and the edit text box. I want to prevent the changing of the setupPrompt text view until the Ok button is pressed. The easy way to do it would be to put it into the onClickListener but there is a whole series of the prompts and waiting for user input so I'm trying to avoid creating a ton of different button listeners for each piece of user input.
TShipman1981 said:
The only two things the user can interact with is the button and the edit text box. I want to prevent the changing of the setupPrompt text view until the Ok button is pressed. The easy way to do it would be to put it into the onClickListener but there is a whole series of the prompts and waiting for user input so I'm trying to avoid creating a ton of different button listeners for each piece of user input.
Click to expand...
Click to collapse
The way you think this would work is not right, you have to think through it again, sorry . In Android, you can almost never wait for user events (because they might not happen). Instead, you have to do what you can during setup and everything that can only happen after a certain event has to be in the onEvent method (for instance onClick). What you can do to make it less complex is one method which is called only from the onClickListener. The method keeps track of how many times it has been called with an int step instance variable. That method has to execute what should happen at each step.
SimplicityApks said:
The way you think this would work is not right, you have to think through it again, sorry . In Android, you can almost never wait for user events (because they might not happen). Instead, you have to do what you can during setup and everything that can only happen after a certain event has to be in the onEvent method (for instance onClick). What you can do to make it less complex is one method which is called only from the onClickListener. The method keeps track of how many times it has been called with an int step instance variable. That method has to execute what should happen at each step.
Click to expand...
Click to collapse
Yeah Agreed with Simp. I would honestly make one method with all the info you need then get all the info and call it only when the button is clicked. If I knew a bit more of what your trying to accomplish I might be able to help you code it more efficiently.