Programming Help. Nicer button? - General Questions and Answers

hello, I'm trying develop an application for my HTC Touch Pro using C# in Visual Studio 2008. Though programming is not new to me, but programming for Window Mobile is brand new to me. I'm currently stuck on trying to make 3d button so it could look nicer but couldn't figure out how to do that. If someone could show me how to do it, it would be great, or if you have some source code I could take a look, it would also be great. I tried to search in google but w/ no luck.

Im not sure on how to do it, But you should upload it to the forums after your done.

It doesn't have to be a button. Use a picturebox object instead and load it with the image of your button. It still has Click and Double Click events that can be used to detect mouse clicks.
To make it look really good, create an image of your button in the 'button pressed' mode and trap the mouse down and mouse up events to switch the button image. Store the two images in an imagelist object and swap them in and out.
Code:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
pictureBox1.Image = imagelist.Images[1];
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
pictureBox1.Image = imagelist.Images[0];
}
private void pictureBox1_Click(object sender, MouseEventArgs e)
{
// Todo button click action code goes here.
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[0];
}
Form load code required to set it up. Just tried this all out. Works a treat. Buttons created with Steffan Gerlach's ZPaint, a great bit of freeware.
It doesn't quite behave exactly as a Button, if you click and hold the mouse down, then move it off the PictureBox, the image remains "down" until the mouse button is released.

stephj said:
It doesn't have to be a button. Use a picturebox object instead and load it with the image of your button. It still has Click and Double Click events that can be used to detect mouse clicks.
To make it look really good, create an image of your button in the 'button pressed' mode and trap the mouse down and mouse up events to switch the button image. Store the two images in an imagelist object and swap them in and out.
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
pictureBox1.Image = imagelist.Images[1];
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
pictureBox1.Image = imagelist.Images[0];
}
private void pictureBox1_Click(object sender, MouseEventArgs e)
{
// Todo button click action code goes here.
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[0];
}
Form load code required to set it up. Just tried this all out. Works a treat. Buttons created with Steffan Gerlach's ZPaint, a great bit of freeware.
It doesn't quite behave exactly as a Button, if you click and hold the mouse down, then move it off the PictureBox, the image remains "down" until the mouse button is released.
Click to expand...
Click to collapse
Thank you.

Related

Auto Link back to a form

Hi guys,
Anyone know how to do this:
I open Form2 when a button is clicked on Form1. To return back to Form1 I have a button to do so on Form2. However, is it possible to return back to Form1 automatically after Form2 has displayed for a set amount of time - lets say 2 seconds? This way I could do away with the button on Form2 - which is my goal.
Thanks much, magohn
Drop a timer from the tool box on to Form2 and set its interval to 2000 (2 sec). Then insert the following code into the Form.Activated() and Timer.Tick() events
private void Form2_Activated(object sender, EventArgs e)
{
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.Close();
}
Thank you SO much...
Thanks again stephj - I modified your code a little as I needed Form2 to be "re-useable" and repro the same action over and over. Thanks!
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Me.Hide()
Timer1.Enabled = True
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub
I did think afterwards that my example was a bit resource hungry as the Form.Close() method actually destroys the form rather than 'deactivate' it. I threw it together as a quick test, just to prove the point.
Glad it all works.
"I love it when a plan comes together." John "Hannibal" Smith

MapActivity, Buttons and OnClickListener

Hi all,
could you give me some help please? I have written a simple MapActivity that contains a mapview (defined in the xml file); it also contains a Button.
If the Button has no OnClickListener associated then the project runs fine (the mapview is of course empty).
If I add an OnclickListener the application simply Force closes.
Has anyone tried this? I was actually following the example in a book but I guess something has changed in the SDK since it was written?
I m using SDK 1.1 (for the moment).
If you have (recently) written something similar, could you give me some pointers please?
thanks
N
"could you give me some pointers please?"
Might be a nullpointer indeed. Check your LogCat (Eclipse: Window, show view, other, logcat), this will probably give you some nice hints.
LOL
ehhehe
havent checked the log yet, will do and then report back here.
if anyone else has other suggestions please dont hesitate!
thanks
N
LogCat
Vlemmix said:
"could you give me some pointers please?"
Might be a nullpointer indeed. Check your LogCat (Eclipse: Window, show view, other, logcat), this will probably give you some nice hints.
Click to expand...
Click to collapse
Vlemmix,
I checked the LogCat and seems too be a nullpointer indeed, but I cannot identify the mistake in the code.
This is the java source for the class. could you please have a look ?
If I un-comment the commented lines, I get a force close. Leave them uncommented and everything works (no click event on the button tho).
package com.chipset.testgps;
import com.google.android.maps.MapView;
import android.widget.Button;
import com.google.android.maps.MapActivity;
import android.os.Bundle;
public class main extends MapActivity {
@Override
public boolean isRouteDisplayed(){
return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Button but = (Button) findViewById(R.id.gpsButton);
// but.setOnClickListener(new View.OnClickListener() {
// public void onClick(View v){
//
// }
// });
final MapView map = (MapView) findViewById(R.id.myMap);
setContentView(R.layout.main);
}
}
Any help please??
thanks
N
1)
First do the setContentView, after that the Button is findable. The system could not find your Button now, so that's why it is a null. Your MapView map also would be a null in your code.
2)
If you define an object within {} it is only available within that {}
You probably going to need the Object "but" later, so make it a private variable of the class.
3)
Classname should start with a capital.
4) Visit anddev.org or some site like that for coding problems, xda seems to be more focused on system/firmware issues, not application code.
So, this should work:
public class MainActivity extends MapActivity {
final Button but;
final MapView map;
@Override
public boolean isRouteDisplayed() {
return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
but = (Button) findViewById(R.id.gpsButton);
but.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
}
});
map = (MapView) findViewById(R.id.myMap);
}
}
Right
Hi Vlemmix.
Thanks very much for your help. I can understand what you are telling me, but if its so:
1) with the listener's lines commented, my code does show both the button and the mapview.. shouldnt it force close anyways if the problem is the setcontentView?
2) yeah agree with you on this one, though since I couldnt get even this simplest code to work, I didnt really want to overcomplicate it for now.
3) this is not a requirement is it? I mean its a coding convention, a good one yes, but not mandatory..?
4) Will do thanks, I m trying to get my bearings with all the dev websites etc.
PS about the API Key.. is this strictly required for developing on localhost (testing on the emu)? I find the info a bit confusing to be honest..
I will give your mods a shot this evening and will post here later tonight.
For the moment a big thank you for showing me my (silly) mistakes (I kinda miss .NET at times.. I wouldnt have messed up that bad with it..).
thanks!
N
Quick reply:
1) You can only find a view when the content is set. No content: nothin' to find!
3) Just do it! ;-)
API key, localhost? I don't understand your question... I'm on SDK1.1, did some work on the emulator, now most on the G1, no big difference. Don't know about keys. You probably need a key for generation an apk for the market though.
ApiKey
Vlemmix said:
Quick reply:
1) You can only find a view when the content is set. No content: nothin' to find!
3) Just do it! ;-)
API key, localhost? I don't understand your question... I'm on SDK1.1, did some work on the emulator, now most on the G1, no big difference. Don't know about keys. You probably need a key for generation an apk for the market though.
Click to expand...
Click to collapse
Will try and let you know mate!
The API Key you need to put in the xml for the MapView. apparently google has made this a requirement instead of the bogus key. I just dont understand if this is true also for the apps you test on the emu or only the ones that go 'live'..
Vlemmix
HI there,
just wanted to let you know that moving the setcontentview worked a treat!
Im so very embarassed now
thanks again for your help mate, I owe you one.
N
You're welcome, no problem!

[5/03] WPA-Enterprise WORKING for UT, UNSW, Georgia Tech

At this time, my courseload is way too high for me to do this. I also formatted and lost my sourcecode so I would have to write it from scratch. Sorry!
http://www.4shared.com/file/103246844/247a67c/WPA_Enterprise.html
Look below for instructions to request your school
Root, of course, is required.
The only other things this program needs is for the user to input their username and password as well as copy the security certificate to their SDcard as well as copying the security file to the SDcard. The program takes care of the rest.
I can modify my program to allow other people to connect to WPA Enterprise places in their area. If there is interest in this, let me know and I would be happy to upload versions of my program that allows others to connect.
Donations are always enjoyed
For UT Students:
1. Copy cacerts.pem to your SDCard. Make sure its named cacerts.pem NOT cacerts.pem or anything else similar. The program is CASE SENSITIVE. Make sure to UNMOUNT your sdcard from the computer
2. Run the program and click always to the superuser prompt (if you have it installed)
3. Input your information.
4. Click Save
5. Click Install
6. Click Reboot
If you ever need to revert, just open the program and click undo!
For UNSW Students:
1. Run the program and click always to the superuser prompt (if you have it installed)
3. Input your password (leave username blank)
4. Click Save
5. Click Install
6. Click Reboot
If you ever need to revert, just open the program and click undo!
For Georgia Tech Students
1. Copy Equifax_Secure_CA.pem to your SDCard. Make sure its named Equifax_Secure_CA.pem. The program is CASE SENSITIVE. Make sure to UNMOUNT your sdcard from the computer
2. Run the program and click always to the superuser prompt (if you have it installed)
3. Input your information.
4. Click Save
5. Click Install
6. Click Reboot
If you ever need to revert, just open the program and click undo!
If anyone else wants it, link me to a page like this one and it will give me an example config.
Enjoy!
persiansown said:
I'm putting the finishing touches on my program that allows students that go to the University of Texas to connect to the WPA-Enterprise network here.
Root, of course, is required.
The only other things this program needs is for the user to input their username and password as well as copy the security certificate to their SDcard. The program takes care of the rest.
I can modify my program to allow other people to connect to WPA Enterprise places in their area. If there is interest in this, let me know and I would be happy to upload versions of my program that allows others to connect.
BTW, It definitely does work, I was able to connect to restricted.utexas.edu on my phone and browse the web through it.
Click to expand...
Click to collapse
Thats good news - I am interested - if this works, i'd be finally able to use it on my uni network.
btw - im on adb 1.5 official.
For those who are in a hurry:
http://forum.xda-developers.com/archive/index.php/t-450915.html
Cool Hook EM
Sorry I haven't uploaded the APK yet. I've been really busy with school and the like.
I need to put in a couple more lines so no one screws up their wifi. Expect it soon though
Fellow longhorn says "thanks in advance"
Sounds good, can finally connect to wifi @ my university
Program Released!
need a config pls
thanks alot for this.
here's a link for my uni : http://www.port.ac.uk/special/is/mobilemedia/broadband/wirelessoncampus/ -> its got the config details.
my uni operates on both wpa/wpa2 and the auth is peap, mschapv2
the cer certificate is on the windows xp part on the above link.
ive converted my .cer to .pem through openssl, so atleast one step is complete.
any help pls? thanks.
grippa said:
thanks alot for this.
here's a link for my uni : http://www.port.ac.uk/special/is/mobilemedia/broadband/wirelessoncampus/ -> its got the config details.
my uni operates on both wpa/wpa2 and the auth is peap, mschapv2
the cer certificate is on the windows xp part on the above link.
ive converted my .cer to .pem through openssl, so atleast one step is complete.
any help pls? thanks.
Click to expand...
Click to collapse
I can try that. Im not sure, but Ill try to wing it for you. Ill send you a PM when its uploaded.
If you could try to do the same for these settings that would be awesome =]
http://www.it.unsw.edu.au/services/uniwide/mobile_devices.html
smurphete said:
If you could try to do the same for these settings that would be awesome =]
http://www.it.unsw.edu.au/services/uniwide/mobile_devices.html
Click to expand...
Click to collapse
We've got the same settings here for WPA-Enterprise, only the SSID is "OpenWLAN". (WPA-TKIP / WPA2-AES (Enterprise) & EAP (PEAP and MS-CHAPv2))
Do you think there is a way to do this?
Please post the source. I suggest that other UT students refrain from using this application until then, due to the ridiculously high abuse potential of an app that elevates to root, and even worse, one that you enter EID + password in.
The normal restrictions on network access can be sidestepped. Your EID and password could easily be harvested. Don't run apps like this until the source is available and someone reputable looks at it.
I posted UT Austin specific instructions back in November. If you want access at UT but don't like to gamble, feel free to give them a try. They're a bit dated with respect to gaining root.
http://forum.xda-developers.com/showthread.php?t=450915
I'll add also that the instructions will probably work at any location using WPA Enterprise auth - anything that wpa_supplicant supports. There are several examples in my thread of people getting it to work at their school/workplace. You can either create the configuration file yourself by looking at the Windows/Mac/whatever instructions made available to you, or you may try contacting the local IT dept.
package com.test.login;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class Login extends Activity {
// Declare our Views, so we can access them later
private EditText etUsername;
private EditText etPassword;
private Button btnLogin;
private Button btnInstall;
private Button btnUndo;
private Button btnRestart;
private String username;
private String password;
private String securityfilename = "cacerts.pem";
private boolean copied = false;
/** Called when the activity is first created. */
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
command("cp /data/misc/wifi/wpa_supplicant.conf /sdcard/wpa_supplicant.conf");
command("cp /data/misc/wifi/wpa_supplicant.conf /sdcard/wpa_supplicant.conf.bac");
super.onCreate(savedInstanceState);
// Set Activity Layout
setContentView(R.layout.main);
// Get the EditText and Button References
etUsername = (EditText)findViewById(R.id.username);
etPassword = (EditText)findViewById(R.id.password);
btnLogin = (Button)findViewById(R.id.login_button);
btnInstall = (Button)findViewById(R.id.install_button);
btnRestart = (Button)findViewById(R.id.restart_button);
btnUndo = (Button)findViewById(R.id.undo_button);
// Spinner array
final Spinner s = (Spinner) findViewById(R.id.spinner);
ArrayAdapter adapter = ArrayAdapter.createFromResource(
this, R.array.locations, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
action("WARNING!","If you have superuser installed, you MUST click ALWAYS before continuing.\n \nOtherwise I'm not sure what may happen\n\nMake sure your Security Certificate is on your SDcard");
// Set Click Listener
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Check Login
username = etUsername.getText().toString();
password = etPassword.getText().toString();
action("Step 1 Complete","Input Successful\nIf phone is in landscape, change to portrait and click again ");
String place = (String) s.getSelectedItem();
inputvalues (username, password, place);
}
});
btnInstall.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
command ("cp /sdcard/" + securityfilename + " /data/misc/wifi/" + securityfilename);
command ("cp /sdcard/wpa_supplicant.conf" + " /data/misc/wifi/wpa_supplicant.conf");
command ("chmod 666 /data/misc/wifi/wpa_supplicant.conf");
command ("chmod 444 /data/misc/wifi/cacerts.pem");
copied = true;
try {
Thread.sleep(2500);
}
catch(InterruptedException e) {}
action("Step 2 Complete","Config Saved Successfly");
}
});
btnRestart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(copied)
command ("reboot");
}
});
btnUndo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
command ("cp /sdcard/wpa_supplicant.conf.bac" + " /data/misc/wifi/wpa_supplicant.conf");
}
});
}
public void command (String inputcommand)
{
Process process = null;
DataOutputStream os = null;
try
{
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(inputcommand);
os.flush();
os.close();
}
catch (Exception e)
{
return;
}
finally
{
try
{
if (os !=null)
{
os.close();
}
}
catch (Exception e) {}
}
}
public void inputvalues (String usrname, String pswrd, String location)
{
if (location=="University of Texas at Austin");
{
try
{
BufferedWriter writer = new BufferedWriter(new FileWriter("/sdcard/wpa_supplicant.conf", true));
writer.newLine();
writer.write("fast_reauth=0");
writer.newLine();
writer.write("network={");
writer.newLine();
writer.write("\t ssid=\"restricted.utexas.edu\"");
writer.newLine();
writer.write("\t key_mgmt=WPA-EAP");
writer.newLine();
writer.write("\t eap=TTLS");
writer.newLine();
writer.write("\t ca_cert=\"/data/misc/wifi/" + securityfilename + "\"");
writer.newLine();
writer.write("subject_match=\"CN=restricted.utexas.edu\"");
writer.newLine();
writer.write("\t anonymous_identity=\"anonymous\"");
writer.newLine();
writer.write("\t identity=\"" + usrname + "\"");
writer.newLine();
writer.write("\t password=\"" + pswrd + "\"");
writer.newLine();
writer.write("\t phase2=\"auth=MSCHAPV2\"");
writer.newLine();
writer.write("}");
writer.newLine();
writer.newLine();
writer.flush();
writer.close();
}
catch(FileNotFoundException ex){}
catch(IOException ioe){}
}
}
public void action (String step, String title)
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(step);
alert.setMessage(title);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
//cancel
}
});
alert.show();
}
}
Click to expand...
Click to collapse
Here is my source. There is an XML portion that takes care of the interface.
To be truthful, I'm kind of embarrassed of the code because I haven't touched Java since highschool. There is nothing wrong with this application, and nothing nefarious. To be honest, I wouldn't know how to do something like that if I wanted since I would have to delve into the commands.
If you have any suggestions for my code, I would be happy to hear them.
I took up this application as a side product just to see if my knowledge of linux was strong enough (I used linux on my netbook for a while before switching to windows 7) and once I got it working I wanted to share it with the community that has given me so much on both my current phone and previous ones.
Anyway, to all the people in this thread who are requesting stuff:
My birthday is today and my girlfriend came up to UT to celebrate with me. She won't be leaving until Sunday so.... I won't be working on it until Sunday. Bear with me though, I will get it up for you guys if I can (again, I pretty much suck. But now that the framework is down, I think I know what to do)
Smurfette, I took a look there and I'm pretty sure I can do it for you
Georgia Institute of Technology Pilot WPA Program
http://www.lawn.gatech.edu/help/gtwpa/
These are the instructions about signing on to WPA at my university. I will look at modifying the source myself, but I don't have time either at the moment. Just curious--how many other GT students are using XDA-developers to mod their Dream??
So far I am sure I can do it for ellingthepirate and smurphete. I found example configurations for those two. I'm not sure about N23 or the guy on the other page yet. Again, I won't be able to update the app until sunday night (central time) at the earliest.
Will this eventually work with the *.cer certificates?
Hi Persiansown,
I am working on something similar. Can you tell me how did you get permission to create/modify wpa_supplicant.conf programatically?
THANK YOU SO MUCH!!
zhang42 said:
Hi Persiansown,
I am working on something similar. Can you tell me how did you get permission to create/modify wpa_supplicant.conf programatically?
THANK YOU SO MUCH!!
Click to expand...
Click to collapse
Never mind! I've figured it out!
Updated for University of South Wales and Georgia Tech

[Q] How to insert a "run this always" loop

Hi Everyone,
Using the SkeletonApp default code, how would I insert a void or whatever (sorry not knowing the terminology yet) that would run each cycle of the program like a counter or something?
Just keep it simple, just a "run this always" loop while maintaining the button functions would be great.
thanks and hope you all had a happy thanksgiving
So I added this and it does not work, how in the world do I get a counter working ?
Please, Please someone point me in the right direction?
All I want it to do (in the default SkellyApp) is count to 30, then end the proggy. And yes, I did make the mytimer a variable at the top of my proggy.
public int mytimer;
-------- stuff ---------
@Override
public void onResume() {
mytimer = (mytimer + 1);
if (mytimer == 30) finish();
super.onResume();
}
thank you in advance for taking the time to look, and HOPEFULLY answer this for me.

[Q] How to code a "Really quit?" question when user press Back/Home buttons ?

[Q] How to code a "Really quit?" question when user press Back/Home buttons ?
Hello,
I am a noob ANDROID developer.
(I have a simple problem, I searched the forums and didn't found a solution.)
I am developing a strategy game/wargame on Android.
I am looking for a way to code a "really quit?" routine when the user press the back/home buttons.
(if that happens by mistake now, the whole app starts from scratch on restart)
I've seen tons of code examples, but not for this. I have only one (commercial) app that shows that exact behavior, but no access to that particular source code.
I've fiddle with the onPause(), onRestart(), onStop() , onDestroy() methods, trying to halt the process before exiting, but only got into error messages.
Basically when "back" is pressed I loose my "game screen" instantly. I've also looked into the onBackPressed() method, but then this seems to be an issue between Android 1.5/2.x. I'd like my app to run on both platforms.
Thanks for your help in this matter.
Mmm, as far as I know, you can also try to override the onKeyPressed (don't sure of the name, check the API) and check if the key pressed is back key. I think this is compatible with 1.X
http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
Android < 2.0
Code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back.
return true;
}
return super.onKeyDown(keyCode, event);
}
Android > 2.0
Code:
@Override
public void onBackPressed() {
// do something on back.
return;
}
If you don't add any code, a back button press will be ignored.
Call finish() method of your running Activity to stop your application.
Deleted post (question already answered)
Thanks!
Here the "quick and dirty" way I did it: User now have to press Back twice to get out!
===
int backPressed=0;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_BACK && event.getRepeatCount()==0){
backPressed++;
}
if(backPressed>1){
return super.onKeyDown(keyCode,event);
}
}
return false;
}
===
(Sorry for the indentation, tabs didn't copy..)

Categories

Resources