public boolean enableWIFI()
{
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()){
if(wifiManager.setWifiEnabled(false))
return true;
}else{
if(wifiManager.setWifiEnabled(true))
return true;
}
return false;
}
Archive for the ‘Android’ Category
Malware disguised as Instagram has been found online. It is getting distributed through Android downloads.
An IT firm, Sophos, has discovered fake versions of the popular photo sharing app and Angry Birds online. It has detected malware, which is being distributed on a Russian website pretending to be an official Instagram website, as Andr/Boxer-F.
Google Play, the Android market place is the official site for any such downloads. But, if the Android users download the app from an unapproved source, they may get their devices severely effected by the malware.
The Android way of delegating actions to other applications is to invoke an Intent that describes what you want done. This process involves three pieces: The Intent itself, a call to start the external Activity, and some code to handle the image data when focus returns to your activity.
Here’s a function that invokes an intent to capture a photo.
private void dispatchTakePictureIntent(int actionCode) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);
}
With this code, your application gains the ability to make another camera application take photos. Make sure that there is a compatible application ready to catch the Intent.
Function to check whether an app can handle your intent:
public static boolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
Many of today’s most popular smartphones can be erased from afar if they’re misplaced or fall into the wrong hands. Here’s how to do it.
Our phones are valuable, but they’re easily replaced. The data on them, however, is often much more important. Cell phones carry all kinds of personal and business information these days, so preventing them from getting in the wrong hands is key.
All of the major smartphone platforms have some kind of remote erase capability. There are several ways of doing it, such as installing apps on the handset, using a management console on the IT side, or signing up for a cloud-based service. Here’s a rundown of what’s out there for each platform. No matter which smartphone OS you or your employees use, you’re bound to find something that can help put your mind at ease.
The same features that enable the remote disable can also just be used to find the phone. Most of today’s smartphones have some form of GPS capability. That means you can use the same tools just to find or locate the lost phone in the first place—and potentially, depending on who has it, or where it’s found, get it back.
Though it varies by platform, the remote wipe solutions listed below—or any for that matter—aren’t fail-safe. If someone finds the phone before the remote wipe occurs—which could happen if the battery dies, or there’s no signal to receive the command—a thief or corporate spy could disable the network connections and then hack away. Your best insurance, therefore, is to disable the handset as quickly as possible, the same way you would call your credit card company the moment you noticed a credit card was missing.
Apple iPhone
You can now locate and remotely erase any iPhone. While you still have the device, head to Settings > iCloud and turn on Find My iPhone if it isn’t already enabled. If you lose your phone, you can find it either by installing the free ‘Find My iPhone’ app on another iOS device, or by visiting icloud.com, signing in, and using Apple’s Web-based ‘Find My iPhone’ app. With either tool, you can remotely lock the phone with a passcode if you haven’t already, send a message to it, play a sound, or remotely wipe the phone.
Google Android
‘Android Lost’ adds remote find and wipe capability, and also lets you set a password and lock the SIM card slot. You can even sound an alarm when the phone is on silent—perfect for finding it when it’s buried in the couch cushions. We’re particularly fond of Android Lost because you can push the app to the phone from Google Play (formerly the Android Market) remotely. In a corporate setting, IT managers deploying Android devices can enable native remote wipe capability by installing ‘Google Apps Device Policy’, though it can’t be added retroactively.
Microsoft Windows Phone
For any Windows Phone 7 or 7.5 device, head to www.windowsphone.com on a desktop or laptop PC and sign in. Then click My Phone. From here, you can locate the phone with GPS, erase all the data, lock the phone and display a message, or change your password. Microsoft also lets you set the phone itself to save its location every few hours; this helps if you lose the phone later and the battery dies, since it will have reported its last known location. To do so, head to Start > App List > Settings and tap Find My Phone.
RIM BlackBerry OS
Research In Motion offers ‘BlackBerry Protect’, a free app that lets you find, lock, or wipe your BlackBerry from a remote location. It also adds daily, weekly, and monthly backup capability for your data. Any BlackBerry Enterprise Server (BES) handset can be erased remotely via the ‘Erase Data and Disable Handheld’ IT administration command over the wireless network. IT admins can also specify if the handset should revert to factory default settings or retain the IT policy it had before.
Intents are just what they sound like, a way to declare to the Android Framework what you intend to do. This can be starting a specific activity, or it can be just asking Android to find some program that can perform an action (whether or not you know what programs are available). We can also go in the other direction, and determine what actions are available to us for a particular piece of content. We are going to cover each of these topics in this article.
Here is the basic ListActivity example.
package com.learnandroid.intents;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
public class UsingIntentsActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListAdapter adapter = createAdapter();
setListAdapter(adapter);
}
protected ListAdapter createAdapter()
{
String[ ] listValues = new String[ ] {
"The Activity You Know",
"The URI You Know",
"When You Just Don't Know"
};
// Create a simple array adapter (of type string) with the test values
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1
, listValues);
return adapter;
}
}
Adapters in Android
An adapter is how Android translates data from some data source onto a view. Typically adapters are used on ListViews and GridViews, and Android provides some very helpful adapters out of the box.
The adapter goes hand-in-hand with a corresponding view (which in our case is a ListView.) Together they bring cleaner code, optimized performance, and reusability to your project.
Cleaner separation of concerns
When you add an object to an adapter, the action also adds the representative view for that object to any lists bound to the adapter. Your code that is adding data into the list through the adapter doesn’t have to know how the list is built for each item. Likewise, the code that knows how to build views for each item in your list doesn’t have to know where the data is coming from.
This makes a somewhat clean separation of concerns that normally overlap in one spot. Those of you who have written many lines of code to populate UI elements with varied data can understand how tangled the project becomes when the code retrieving data is also the code rendering it.
Optimizations: View Recycling
Another great benefit of using a ListView/adapter is the immense performance gains it can bring. If you’ve ever built a ScrollView with a list of child views, you’ll notice that performance becomes slow quickly. The ListView/adapter pair solves this with a traditional technique: view recycling.
View recycling is a technique in which view objects are re-used once their current locations are no longer visible. This has a great performance advantage– as your list of items grows, the total number of views remains the same, which corresponds to the distinct number of views drawn in a single screenful. Even better yet, the process is handled behind the scenes, so your adapter should only be aware that views are reused, not necessarily how they are reused.
Code Reusability
Finally the code you write for an adapter, and the separation it forces in the data, view, and adaptation concerns, will result in your code being much more reusable. Where you may have previously written all of the code directly into some Activity for displaying a list of complex objects, now you have a separate class that you can reuse for other lists. In fact, you can even vary the layout the adapter uses without changing anything about the adapter itself.
This example requires three basic classes in order to implement a basic game. The game logic can be extended or changed and the resources can be replaces easily using the same patterns. The file DrawablePanel.java contains the code for DrawablePanel which extends SurfaceView and provides a full screen canvas. The DrawablePanel contains an AnimationThread. This class extends Thread (you could also provide a runnable, whatever pattern is more familiar). The AnimationThread class holds a reference to the DrawablePanel described above and updates the DrawablePanel for game logic and forces a redraw of the panel.
STS Validator
The eight STS validator options are project-wide validation rules.
These validators are disabled by default.
| STS Rule | Description |
| Driver Manager Data Source | Validates the project does not use this class |
| Bean Inheritance | Recommends bean inheritance for simplification |
| Import Elements at Top | Recommends imports before other bean definitions |
| Parent Beans not Abstract | Validates that parent beans are not abstract |
| Too Many Beans | Validates too many beans in file – approx. 80 beans |
| Unnecessary Ref | Check for ref elements and recommends ref attribute instead. <property … ref=””/> instead of <property …><ref bean=””/></property> |
| Dedicated Namespace Syntax | Checks for cases where dedicated namespaces can be used
|
BEAN NAVIGATION & ANALYSIS
Within STS, you can quickly open a bean or view bean cross references or bean outline from the Eclipse Search and Navigate menu options.
Finding Spring Beans
From Search > Beans, you can conduct a wildcard search for beans by name, class, property name, beans referencing, and child beans.
Navigate > Open Spring Bean displays a search box where you can search for class names using camel-case.
Beans Quick Cross References
Within the bean config editor, select Navigate > Beans Quick Cross References to show the beans cross references for the current bean file. From here, you can jump to the bean declaration.
Note:
- Beans Cross References view is for Spring
- Cross References view is for AspectJ
Beans Quick Outline
Within the bean config editor, select Navigate > Beans Quick Outline to display an outline list of all bean declarations and property settings. You can search for a specific bean by ID and click a bean to see its definition.
regards-http://refcardz.dzone.com/refcardz/eclipse-tools-spring
Basic Structure of an AndEngine game
As this is the first game tutorial, we will first off all go through the very basics of a game built using the AndEngine. First off all we will need to create an Activity obviously, which will be our start point. However, we do not extend the Activity class like we usually do with normal Android programs, we will use the class BaseGameActivity:
public class GameActivity extends BaseGameActivity {
Notice that I usually call my Game Activity “Game Activity” (makes kinda sense, doesn’t it?). However, you can just name your Activity whatever you want (except BaseGameActivity, unless you use your package to identify your Activity).
What you will surely notice when you write this code is that there are 4 abstract methods in the class BaseGameActivity, which basically means that you will need to overwrite them and place your game logics in those methods. Let’s go through them all systematically. I’ve also inserted some example code in each of the functions, so you get a feeling how they are actually going to be used later when we create our actual game.
public Engine onLoadEngine() {
Engine engine = new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT)));
return engine;
}
The only function of the onLoadEngine() is basically just to create an Engine object and return that (load the Engine, the name says it all). You might have noticed that I used the two constants CAMERA_WIDTH and CAMERA_HEIGHT above which are both simply float types which specify the screen resolution you will be using in your game. Usually I use 480 x 800, which is the standard resolution for Android devices. (There are other screen resolutions, but that’s not a problem your game will fill the whole screen thanks to the AndEngine without you having to do anything!).
Another important point is the second argument, which specifies which screen orientation your game is going to use, that’s either Landscape or Portrait, it all depends on your game though. Other than that there’s nothing really special about the code above, you can just copy it 1 : 1.
public void onLoadResources() {
Texture texture = new Texture(256, 256);
// Arguments: Texture, Context, String to the Image, posX, posY
TextureRegion playerTexture = TextureRegionFactory.createFromAsset(texture, this, "gfx/player", 0, 0);
this.mEngine.getTextureManager().loadTexture(texture);
}
This function is a lot more interesting for us, we do not return anything here, but we load all of our TextureRegions (Basically Images) in this function. It’s very important to understand the basic process when you load a TextureRegion (Image).
What you will need to do is to first create a Texture, which will actually hold the TextureRegion. A Texture is just a container of multiple (or a single) TextureRegions. We will need to provide the Texture with a Width and a Height and all the TextureRegions added to that Texture via the TextureRegionFactory will need to specify their position on the Texture. You will need to be careful that no TextureRegions overlap each other, also you will get an exception if a TextureRegion exceeds the bounds of your specified Texture. It’s also not a coincidence that our Texture width and height are a power of 2, it has to be this way, for whatever reason.
A crucial mistake which happens very often to beginners (or even novices) is that they forget to actually load the Texture into the Engine. You see this done on the line 7 in our little function, we simply need to tell the Engine that we have a collection of TextureRegions (a Texture) which we will use later on in our program. (Obviously you would need to save the local variable playerTexture as a field in your class, otherwise you will not be able to access the TextureRegion anymore.)
Actually you will not be able to draw TextureRegions directly on the Scene, you will need to wrap them into Sprites, but we will get to that later.
public Scene onLoadScene() {
Scene scene = new Scene(1);
// Creating a Sprite is pretty straight forward
scene.getTopLayer().addEntity(new Sprite(50, 50, playerTexture)); // posX, posY, TextureRegion
return scene;
}
Probably the most important function is the onLoadScene() because here we will actually do all our drawing, at least in our example. We will need to return a Scene, which contains all our Entities we draw on them. So a Scene is simply the Canvas (or an even simpler term would be “the area”) where we can draw all our stuff. As mentioned above we cannot add TextureRegions directly to the Scene, we will need to first create a Sprite, which is exactly what we are doing on line 4.
Also notice that we need to call the “getTopLayer()” method of our scene object, that’s the case because a Scene supports multiple Layers (That’s the argument 1 we supply for our Scene object; the number of Layers), for example you could call getBottomLayer() and add your background image there and on the top Layer you draw your other entities, such as a player. However, you could also just add your background before you add the other entities, which should be a tick faster than using multiple layers.
Another very important thing to keep in mind is that the onLoadScene() method is not a callback function, which means it won’t get called every time the engine draws the Scene, actually there’s no function like that in the AndEngine (unless you actually edit the Engine source code). You will have to work with adding and removing your sprites from the scene.
public void onLoadComplete() {
}
Last and least is the onLoadComplete() function which gets called once the Engine has fully loaded. You can clearly see that I left the function blank, that’s because I’ve never used this function and we aren’t going to need it in our tutorials either, that is because we will use the onLoadScene() method as our start point into the application.
regards-http://www.andgamedev.com/archives/basic-structure-of-an-andengine-game




