volume raise indication dialog in blackberry - blackberry

In my app I want to display an dialog(a screen indicating volume level) when user press VOLUME_UP and VolUme_down keys in the Blackberry Phone,Now I increase or decrase volume when user clicks those keys:
public boolean keyDown(int keycode, int time) {
if(volume != null){
int key = Keypad.key(keycode);
if(key == Keypad.KEY_VOLUME_DOWN){
volume.setLevel(volume.getLevel()-10);
}
else if(key == Keypad.KEY_VOLUME_UP){
volume.setLevel(volume.getLevel()+10);
}
}
return false;
}
I need dialog which like in Blackberry phone when users take songs(and press volume keys) in blackberry Media folder. If any one have idea please help,Thanks.

Related

How to show the 1st fragment when back button is pressed?

I'm new to Mobile Development
I am currently developing a Telephone Directory app from Xamarin Android, in this app, I have 4 Fragment(HomeFragment, AboutFragment, DirectoryFragment, and SyncFragment).
HomeFragment is the first fragment that shows from the app. When I click the item About in the side bar then pressed the back button, it works well because i used AddToBackStack(null) before commit() in the main activity.
But the problem is, let's say I open the app then it shows the HomeFragment fist by default, when i navigate to the AboutFragment, it shows the AboutPage, then if I navigate to the DirectoryFragment next and click the back button, i keep on going back to the AboutPage/AboutFragment, which is what i want to achieve is, it should go back to the HomePage/HomeFragment
In short, what i want to achieve is like the Navigation behavior of the Gmail App.
Anyway this is my code in Main Activity
switch (e.MenuItem.ItemId)
{
case (Resource.Id.nav_home):
FragmentTransaction ft = FragmentManager.BeginTransaction();
HomeFragment home = new HomeFragment();
ft.Replace(Resource.Id.HomeFrameLayout, home);
HideSoftKeyboard();
mDrawerLayout.AddDrawerListener(mDrawerToggle);
ft.AddToBackStack(null);
ft.Commit();
break;
case (Resource.Id.nav_about):
FragmentTransaction ft1 = FragmentManager.BeginTransaction();
AboutFragment about = new AboutFragment();
ft1.Replace(Resource.Id.HomeFrameLayout, about);
HideSoftKeyboard();
ft1.AddToBackStack(null);
ft1.Commit();
break;
case (Resource.Id.nav_etel):
FragmentTransaction ft2 = FragmentManager.BeginTransaction();
GHQFragment ghq = new DirectoryFragment();
ft2.Replace(Resource.Id.HomeFrameLayout, ghq);
HideSoftKeyboard();
ft2.AddToBackStack(null);
ft2.Commit();
break;
case (Resource.Id.nav_refresh):
if (CrossConnectivity.Current.IsConnected)
{
FragmentTransaction ft3 = FragmentManager.BeginTransaction();
SyncFragment sync = new SyncFragment();
ft3.Replace(Resource.Id.HomeFrameLayout, sync);
HideSoftKeyboard();
ft3.AddToBackStack(null);
ft3.Commit();
}
else
{
Toast.MakeText(this, "Please connect to the internet to sync records.", ToastLength.Long).Show();
}
break;
You can override the OnKeyDown method like following code.
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Back)
{
FragmentManager fragmentManager = this.FragmentManager;
int count = fragmentManager.BackStackEntryCount;
for (int i = 0; i < count; ++i)
{
fragmentManager.PopBackStack();
}
// your code
return false;
}
return base.OnKeyDown(keyCode, e);
}
I switch three fragment, when I click the back button. it switch to the first fragment.
Update
Do you want to achieve the result that you click back button then back to the desktop when you in the HomePage?
Here is code.
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Back)
{
FragmentManager fragmentManager = this.FragmentManager;
int count = fragmentManager.BackStackEntryCount;
if(count>0){
for (int i = 0; i < count; ++i)
{
fragmentManager.PopBackStack();
}
return false;
}
}
return base.OnKeyDown(keyCode, e);
}

Is it possible to remotely control an EA on a PC from another PC?

I have an EA (i.e Robot) i want people to have it on their PC. is it possible to activate or deactivate it from my PC based on their subscription condition? Explanation: if Mr. A has subscribed for this month, i will be the one to activate it from my PC. Meaning, even though the EA is on their system, they won't be able to activate or deactivate it.
You can use your PC (need to make sure that you have a static IP address and then launch a web application). Simpler is to rent a VPS. Then, create a simple web application, probably using Django (Python) or PHP, with REST webservice and admin panel.
EA side: every robot is compiled, EX4 file is provided to a client. Your client adds http://yourwebsite.org/ into list of allowed urls in MT4 then uses the EA. When EA is attached to the chart, OnInit() function is called, use WebRequest() function inside that block to let your EA contact your website and ask whether it can work (probably client may pass login and password, or account number and broker name (with client name if you wish). The webserver receives that data and makes validation.
Another question is how to let your EA to work till some time. Easiest way is to call the webserver once a day (at random time seems better) with the same validation request. If validation fails - EA stops working.
Finally, think of how you are going to deactivate your EA... It might happen that EA opened plenty of deals and pending orders, and if it kills itself with ExpertRemove(), those deals will remain in MT4. So probably it would be better to notify the client that EA is no longer active, and follow the existing orders, close all at breakeven if possible, or other solutions that depends on your EA logic. The following piece of code worked for some clients without any complaints, you are welcome to use it (with your super admin, password if needed, and domain name).
class CLicenseOnline : public CObject
{
private:
string m_login;
string m_password;
datetime m_nextCheck;
int m_prevResult;
string m_url;
int m_strategyId;
public:
CLicenseOnline(const string login,const string password,const int id):
m_login(login),m_password(password),m_nextCheck(0),m_strategyId(id),m_prevResult(-1)
{
bool isCheckingRequired=false;
if(CLicenseOnline::isSuperAdmin(login,password))
{
printf("%i %s - Hello, SUPER ADMIN!",__LINE__,__FILE__);
isCheckingRequired=true;
}
isCheckingRequired= isCheckingRequired || IsTesting();
if(isCheckingRequired)
{
m_nextCheck=INT_MAX;
m_prevResult=1;
}
else
{
m_url=CLicenseOnline::genUrl(login,password);
}
}
~CLicenseOnline(){}
int check()
{
if(TimeCurrent()>m_nextCheck)
{
int result=this.checkMain();
switch(result)
{
case 1: m_nextCheck=this.generateNextDate(); m_prevResult=1;break;
default:
case 0: m_nextCheck=TimeCurrent()+PeriodSeconds(PERIOD_M1); m_prevResult=0;break;
case-1: m_nextCheck=TimeCurrent()+PeriodSeconds(PERIOD_H1); m_prevResult=-1;break;
}
}
return(m_prevResult);
}
static string genUrl(const string login,const string password)
{
const string http="localhost";
return(StringFormat("http://%s/verify/?Login=%s&&Password=%s&&Check=%d",http,login,password,2147483647));
}
static string getHttpResponce(const string url)
{
char data[],res[];
string cookies=NULL, headers=NULL,result;
ResetLastError();
int answer = WebRequest("GET",url,cookies,NULL,5000,data,0,res,headers);
if(answer==200)
{
result = CharArrayToString(res);
return(result);
}
//printf("%i - result=%d|%s|size=%d; %d",__LINE__,answer,result,ArraySize(res),GetLastError());
return(NULL);
}
private:
static bool isSuperAdmin(const string login,const string password)
{
static string
superAdminLogin="Admin",
superAdminPassword="password";
//ATTENTION! Edit the login and password here!
return login==superAdminLogin && password==superAdminPassword;
}
datetime generateNextDate()const
{
return(iTime(_Symbol,PERIOD_D1,0)+PeriodSeconds(PERIOD_D1)+MathRand()%PeriodSeconds(PERIOD_D1));
}
int checkMain()const
{
string respond=CLicenseOnline::getHttpResponce(m_url);
if(respond==NULL)
return(0);//try later
CJAVal js(NULL,jtUNDEF);
if(!js.Deserialize(respond))
{
printf("%i %s - failed to deserialize %s",__LINE__,__FUNCTION__,respond);
return(-1);
}
int retCode=(int)js["key"].ToInt();
switch(retCode)
{
case -1: Alert("incorrect password");return(0);
case -2: Alert("incorrect key!");return(0);
case -3: Alert("incorrect request method!");return(0);
case -4:
case -5: Alert("no such login");return(0);
default:
Alert(StringFormat("%i %s - incorrect login/password/no such user!",__LINE__,__FUNCTION__));
return(0);
case 200:
{
CJAVal *valueJs=js["value"];
if(!this.checkStatus(valueJs["Status"].ToStr()))
return(-1);
if(!this.checkAccount(
(int)valueJs["Allow_account_1"].ToInt(),(int)valueJs["Allow_account_2"].ToInt(),(int)valueJs["Allow_account_3"].ToInt()))
return -1;
bool strategyX=(bool)valueJs["Allow_strategy_"+(string)m_strategyId].ToBool();
if(!stategyX)
{
return(-1);
}
return(1);
}
}
return(-1);
}
bool checkStatus(const string status)const
{ //printf("%i %s - status = |%s|%d",__LINE__,__FUNCTION__,status,IsDemo());
if(status=="demo")
{
if(!IsDemo())
{
string message=StringFormat("your login %s is allowed to trade on Demo accounts only!",m_login);
Alert(message);
printf("%i %s - %s",__LINE__,__FILE__,message);
return(false);
}
return(true);
}
if(status!="active")
{
string message=StringFormat("status of your login [%s] is [%s] so not allowed to trade!",m_login,status);
Alert(message);
printf("%i %s - %s",__LINE__,__FILE__,message);
return(false);
}
return(true);
}
bool checkAccount(const int acc1,const int acc2,const int acc3)const
{
if(acc1==0 && acc2==0 && acc3==0)
return(true);
int currentAccount=AccountNumber();
if(acc1==currentAccount || acc2==currentAccount || acc3==currentAccount)
return(true);
string message=StringFormat("allowed accounts are only %d, %d and %d, your account %d is not allowed!",acc1,acc2,acc3,currentAccount);
Alert(message);
printf("%i %s - %s",__LINE__,__FUNCTION__,message);
return(false);
}
};

Disabling and enabling internet in blackberry

I want to know what is the way to enable and disable internet connection in blackberry through coding.
EDIT
protected void disableConnection() {
activeConn = RadioInfo.getActiveWAFs();
if(activeConn == 0){
activeConn = RadioInfo.getEnabledWAFs();
}
mystore.setContents(new Integer(activeConn));
mystore.commit();
Radio.deactivateWAFs(activeConn);
Dialog.alert("Off internet");
}
protected void enableConnection() {
if(RadioInfo.getState() == RadioInfo.STATE_ON){
Dialog.alert("Internet on already");
}else if(mystore.getContents() != null){
if(Radio.activateWAFs(Integer.parseInt(mystore.getContents().toString())) == true){
Dialog.alert("On Internet");
}else{
Dialog.alert("Unable to on internet");
}
}else{
Dialog.alert("Unable to on internet");
}
}
These are two methods which I call on turn on and turn off button click.
You asked about internet connectivity, so I assume you are interested in more than just the Wi-Fi connection. Calling Radio.deactivateWAFs(RadioInfo.WAF_WLAN); will only disable Wi-Fi.
A better implementation would probably first check which radios are on, and then turn those radios off. When you want to turn service on again, reactivate the radios which you turned off. Something like this:
/** we record which radios are active */
private int _activeWAFs = 0;
private void getActiveWAFs() {
_activeWAFs = RadioInfo.getActiveWAFs();
if (_activeWAFs == 0) {
_activeWAFs = RadioInfo.getEnabledWAFs();
}
}
/** turn radios off if they're currently on */
private void disableAll() {
getActiveWAFs();
Radio.deactivateWAFs(_activeWAFs);
}
/** turn radios on, if we turned them off with disableAll() */
private void enableAll() {
boolean success = Radio.activateWAFs(_activeWAFs) && (RadioInfo.getState() == RadioInfo.STATE_ON);
if (!success) {
// do something?
}
}
Also, if you want notifications about the results of these operations, or external changes to the radio, you can implement RadioStatusListener:
public void networkStarted(int networkId, int service) {
if (RadioInfo.getState() == RadioInfo.STATE_ON) {
// network ready to use!
}
}
And, yes, this call will affect the entire device, not just internet connectivity for your app.
Radio.deactivateWAFS() will it deactivate all the wireless connection or just internet connectivity or Bluetooth connectivity.
Example: deactive WiFi connectivity.
Radio.deactivateWAFs(RadioInfo.WAF_WLAN);
try this -
this will turn on wifi-
Radio.activateWAFs(RadioInfo.WAF_WLAN);
this will turn off the wifi-
Radio.deactivateWAFs(RadioInfo.WAF_WLAN);

Showing the location in Windows Phone 7 works in the emulator but not on the real phone

I have code that is used to show a device's location. It works just fine on the emulator and it takes me to the fake location at Microsoft. But it didn't work when I build it into the phone, it showed me the world map. Is this a known bug or I have done something wrong? Here is my code:
private GeoCoordinateWatcher loc = null;
private void button1_Click(object sender, RoutedEventArgs e)
{
if (loc == null)
{
loc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
loc.StatusChanged += loc_StatusChanged;
}
if (loc.Status == GeoPositionStatus.Disabled)
{
loc.StatusChanged -= loc_StatusChanged;
MessageBox.Show("Location services must be enabled on your phone.");
return;
}
loc.Start();
}
void loc_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Ready)
{
Pushpin p = new Pushpin();
p.Template = this.Resources["pinMyLoc"] as ControlTemplate;
p.Location = loc.Position.Location;
mapControl.Items.Add(p);
map1.SetView(loc.Position.Location, 17.0);
loc.Stop();
}
}
}
Instead of using the StatusChanged event, you should use the GeoCoordinateWatcher.PositionChanged event, in from which you should use the GeoPositionChangedEventArgs.Position property, to reflect the changed location.
This is due to my location doesn't support by Bing Map. I couldn't use the Bing Map app installed in my phone neither. Hmm...

How can I invoke the Blackberry camera and save the picture that is taken in my code?

I'd like my user to take a picture as an attachment by using the built in camera.
Is there someway to invoke the camera on a button press and save the resulting taken picture?
The other option is to use the BlackBerry Invoke API to start the native camera application and listen for a file system event:
Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
then, later:
class FileExplorerDemoJournalListener implements FileSystemJournalListener {
public void fileJournalChanged() {
long nextUSN = FileSystemJournal.getNextUSN();
for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) {
FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN);
if (entry == null) {
break;
}
String path = entry.getPath();
if (path != null) {
if (path.endsWith("png") || path.endsWith("jpg") || path.endsWith("bmp") || path.endsWith("gif") ){
switch (entry.getEvent()) {
case FileSystemJournalEntry.FILE_ADDED:
//either a picture was taken or a picture was added to the BlackBerry device
break;
case FileSystemJournalEntry.FILE_DELETED:
//a picture was removed from the BlackBerry device;
break;
}
}
}
}
}
}
Finally...
Application.addFileSystemJournalListener(new FileExplorerDemoJournalListener());
This will get you most of the way there... taken from: http://docs.blackberry.com/en/developers/deliverables/11942/Detect_when_img_is_added_or_removed_file_system_740288_11.jsp
http://docs.blackberry.com/en/developers/deliverables/17968/Take_a_picture_in_a_BB_device_app_1228201_11.jsp

Resources