Android Tutorial

1.30.2012

The Eclipse Color Theme Plugin

The Eclipse Color Theme Plugin

 

 

The Eclipse Color Theme plugin makes it possible to switch color themes conveniently and without side effects. It includes the most popular themes from eclipsecolorthemes.org, but you can add any theme created on the site by exporting it as XML.

Installation

If you are on Eclipse 3.6 (Helios), the easiest way to install the plugin is from the Eclipse Marketplace. Go to Help→Eclipse Marketplace..., then search for Eclipse Color Theme and install it.
If you are on Eclipse 3.5 (Galileo), go to Help→Install New Software..., press Add Site and enter Eclipse Color Theme as the name and http://eclipse-color-theme.github.com/update as the URL. Then select the new entry from the select box labeled Work with, mark Eclipse Color Theme for installation and proceed.
Please note: If you are using a version of the plugin lower than 0.6, please uninstall and reinstall it following the instructions above. Update site and plugin ID have changed.

Usage

After the installation, go to Window→Preferences→General→Appereance→Color Theme to change the color theme.
If you have a feature request, create an issue or a pull request on GitHub.

 

12.27.2011

Copy and delete file in android



private void copyFile(String pathIn, String pathOut) {
Log.d(TAG, "copyFile start");
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(pathIn);
out = new FileOutputStream(pathOut);
copy(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
delFile(pathIn);
} catch (Exception e) {
Log.e("copy clipart ERROR", e.toString());
e.printStackTrace();
}
Log.d(TAG, "copyFile end");
}

private boolean delFile(String filePath) {
File file = new File(filePath);
boolean deleted = file.delete();
return deleted;
}

/* ------------- File Processes -------------> */
/**
* Copy data from $from to $to
*
* @param $from
*            source
* @param $to
*            destination
* @throws IOException
*/
public static void copy(InputStream $from, OutputStream $to)
throws IOException {
byte[] buffer = new byte[1024];
int length;
while ((length = $from.read(buffer)) > 0) {
$to.write(buffer, 0, length);
}
$to.flush();
$to.close();
$from.close();
}

Copy file from assets to app in android



/**********************************
*
* Copy List file from folder if fileName != null : copy file of folderName
* if folderName == null: copy file of folder root assets else if folderName
* == null : copy all file of folder root assets
*
*
* *********************************/
private void copyFileFromAssetsToApp(String folderName, String fileName,
String folderNameInApp, String fileNameInApp, Context Ctx) {
Log.d(TAG, "copyClipart start");
AssetManager assetManager = getResources().getAssets();
final String root_dir = "/data/data/" + Ctx.getPackageName();
String basepath = root_dir + "/" + folderNameInApp;
if (Utils.checkNullOrEmpty(folderNameInApp)) {
basepath = root_dir;
}
File clipartdir = new File(basepath);
if (!clipartdir.exists()) {
clipartdir.mkdirs();
}

Unzip file not password in Android



/****************************************************************************
* Unzip file not password
*
* Example:
* String path = "/sdcard/files.zip";
* String folderOut = "/data/data" + mCtx.getPackageName() + "/folder";
* File fi = new File(path);
* InputStream zipIn = new FileInputStream(fi);
* // if asset : AssetManager assetManager = getResources().getAssets();
* // InputStream zipIn = assetManager.open("files.zip");
* unZipFileNotPass(zipIn, folderOut);
*
******************************************************************************/

8.26.2011

Get version code and version name in android

      main:
         PackageInfo manager = ggetPackageManager().getPackageInfo(getPackageName(), 0);
        Log.d(TAG, "Version Code = " + getVersionCode(manager));
        Log.d(TAG, "Version Name = " + getVersionName(manager));


      /*
* get Version code
*
*  @para PackageInfo manager = ggetPackageManager().getPackageInfo(getPackageName(), 0);
*/
public static int getVersionCode(PackageInfo manager){
int verCode= 0;
verCode = manager.versionCode;  
   return verCode;
}

/*
* get Version name
*
*  @para PackageInfo manager = ggetPackageManager().getPackageInfo(getPackageName(), 0);
*/
public static String getVersionName(PackageInfo manager){
String verName = "";
verName = manager.versionName;  
   return verName;
}

8.25.2011

resizeImage trong Android.


 public static Drawable resizeImage(Context ctx, int resId, int w, int h) {

     // load the origial Bitmap
     Bitmap BitmapOrg = BitmapFactory.decodeResource(ctx.getResources(),
                                                     resId);

     int width = BitmapOrg.getWidth();
     int height = BitmapOrg.getHeight();
     int newWidth = w;
     int newHeight = h;

     // calculate the scale
     float scaleWidth = ((float) newWidth) / width;
     float scaleHeight = ((float) newHeight) / height;

     // create a matrix for the manipulation
     Matrix matrix = new Matrix();
     // resize the Bitmap
     matrix.postScale(scaleWidth, scaleHeight);
     // if you want to rotate the Bitmap
     // matrix.postRotate(45);

     // recreate the new Bitmap
     Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0,
                                                width, height, matrix, true);

     // make a Drawable from Bitmap to allow to set the Bitmap
     // to the ImageView, ImageButton or what ever
     return new BitmapDrawable(resizedBitmap);

    }

7.24.2011

Developing Native Android Apps with Titanium

In today’s Titanium Week webinar, we took a look at features new and old for developing native Android applications using Titanium. Hacker Extraordinaire Marshall Culpepper surveys major Android native application concepts, like Activities, Intents, and Services, and shows how to apply these concepts in your Titanium application to create a deeply integrated native application experience on Android. Other cross-platform development techniques and code structure options are explored, and we tease our next great super demo app, Tweetanium!
Please find both the slides and recorded webinar below. In addition to Tweetanium, Marshall’s example project (used in this presentation) will be posted to GitHub early next week: