Monday, April 15, 2013

[Code Snippets] Lấy thông tin về Battery

main.xml
[JAVA]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:eek:rientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>

[Code Snippets] Một cách kiểm tra phiên bản mới của ứng dụng

Có nhiều cách để cho người dùng kiểm tra phiên bản mới ứng dụng. Phương pháp sau đây không cần phải có server riêng để kiểm tra phiên bản mà dùng chính Android Market server (đòi hỏi ứng dụng phải có trên Market). Nguyên lý là bạn truy cập trang thông tin ứng dụng của mình để trích xuất thông tin phiên bản, sau đó so sánh với phiên bản hiện tại trong PackageInfo của ứng dụng.

Đoạn code sau đây mình lấy từ chương trình OptiNews (định danh là vn.zerox.optinews, các bạn sẽ thay bằng cái khác):

Wednesday, April 10, 2013

Android Google Map View Example Tutorial

Step 1 : Obtaining Google API Key
To make use of Google Map or any other Google API you need to have a Google API key.
It is extremely easy to get a Google API Key. You see below I have made a Video which is made up of step-by-step procedure for obtaining the Google API key.

Detailed Steps
  • Proceed to the location exactly where JDK installed.
  • Certainly, there you will see KeyTool.
  • Then simply Copy the path.
  • Start a command prompt then change the directory to the keytool path.
  • copy and paste the below code snippet to command prompt
keytool -list -alias androiddebugkey -keystore
  • At this point we need to copy the path of the debug.keystore
  • Head over to windows/users/[your computer user name]/.android/
  • It’s simple to find the debug.keystore, so copy the path.
  • Next paste the keystore path surrounded with “” combined with the step 5 code snippet.
keytool -list -alias androiddebugkey -keystore "C:.android.keystore" -storepass android -keypass android
  • Last but not least press Enter. You will notice the Certificate Finger Print.

  • At this moment visit this link to sign up to Google API.
  • Enter the Finger print using only number and digits. Stay away from including “:” .
  • After that Tick the Agreement.
  • Simply click Generate API key. You should see the API key now. Copy the actual URL intended for future reference.
Step 2 : Hands-on Google Map in Emulator
Before start to code our Google Map Alert App, we are now going to test it, to ensure we are ready to go.
  • Start a Sample Project named GoogleMapDemo.

  • Choose the Choose bulid SDK to Google API. I choosed Google API Level 16.
  • Then Click Next for the rest, Finally press Finish.

  • Copy the below code to your Layout.
res/layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <com.google.android.maps.MapView
  android:id="@+id/map"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:clickable="true"
   android:apiKey="06Q7KxHWP0w3-i0IpzRr8sSRnDLyHWAfJ_lk8mQ" />
</RelativeLayout>

Here you should enter your apikey otherwise it won’t work.
  • Ok in case you are so curious, then simply run it. You will find the below stopped message.

Just what exactly is the mistake we certainly have done. We have setup every little thing as well as enter the MapView component within our layout.
But It is not sufficient to really make it do the job. We have seen lots of android tutorial for beginners. Therefore by now you should capable of finding out, exactly what do we have to do in order to succeed.
Absolutely yes, you are right, we should tell to the Manifest file that we are going to make use of Google Map for this application, and also Internet access.
Android Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemapdemo"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="15" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/google_map_demo" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <uses-library android:name="com.google.android.maps"/>
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Do you believe that this time, it’s going to run the app and show the map.
I am not going to say anything at the moment, just proceed as well as run the project.


So above is the answer. So for we have extends only Activity, but in order to make use of Google Map, Our Java Code should extends MapActivity. :)
  • Then finally include the unimplemented methods.
src/com.example.androidmapviewdemo/AndroidMapViewDemo.java
package com.example.googlemapdemo;
import com.google.android.maps.MapActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MainActivity extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}

 
 
 
 
Download Code

Thursday, February 21, 2013

Ứng dụng Ajax, Json để Upload file trong CodeIgniter


Chào các bạn, hôm nay mình sẽ hướng dẫn các bạn sử dụng ajax khi chúng ta upload file trong CodeIgniter! 
Để nắm rõ dc TUT này, các bạn phải có kiến thức cơ bản về Json nha ! Tham thảo jsontại :http://www.qhonline.info/forum/showt...highlight=json. 
+++Ở đây, chúng ta sẽ nạp vào thư viện AjaxFileUpload. Các bạn có thể tải tại đây:http://www.phpletter.com/DOWNLOAD/. 

->Các bước cb đã xong !giờ chúng ta bắt tay vào viết ứng dụng nào . 

Caching website với CodeIgniter

Nội dung :
  • Tại sao cần phải caching website
  • Sự khác biệt giữa caching và không caching
  • Làm thế nào để caching trong CodeIgniter

1.Tại sao cần phải caching website: 
- Trước hết , bạn hiểu như thế nào là caching : Web caching là việc lưu trữ bản sao của những tài liệu web sao cho gần với người dùng, cả về mặt chức năng trong web client hoặc những web caching servers riêng biệt 
- Ưu điểm : 
  • Load nội dung nhanh hơn
  • Hạn chế việc truy vấn trực tiếp vào Databse

Monday, January 28, 2013

Combo box / Drop down list box in Android


As usual doing something simple in Android is frustrating - this time: a simple Combo (or DropDownList). The little and important tweak - calling "setDropDownViewResource" to set the style of the items in the dialog box.

XML:
<spinner id="@+id/spinner" layout_width="wrap_content" android:layout_height="wrap_content" />

Code to add the data:
  1. Spinner spinner = (Spinner)this.findViewById(R.id.spinner);  
  2. ArrayAdapter<String> adapter = new ArrayAdapter<String>(  
  3.         this,  
  4.         android.R.layout.simple_spinner_item,  
  5.         new String[] { "1", "2", "3" });  
  6. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
  7. spinner.setAdapter(adapter);  

Tuesday, January 22, 2013

Using Google Maps in Android

Google Maps is one of the many applications bundled with the Android platform. In addition to simply using the Maps application, you can also embed it into your own applications and make it do some very cool things. In this article, I will show you how to use Google Maps in your Android applications and how to programmatically perform the following:
  1. Change the views of Google Maps
  2. Obtain the latitude and longitude of locations in Google Maps
  3. Perform geocoding and reverse geocoding
  4. Add markers to Google Maps

Saturday, January 19, 2013

How to set environment variables in Windows 7 for Java

Environmental variables are used by the operating system to save settings (default values, locations of resources) to be used by Windows or by processes launched by users.
There are two types of environmental variables:
  • user variables that are specific to a particular Windows user account;
  • system variables are always visible, regardless of the used user account.

Even if these variables are usually defined and initialized automatically when you install the system or other applications, there are situations in which the user must manually define them to put at the disposal of applications.
The considered scenario is to set environment variables to enable the compilation and execution of Java applications from the command line (command prompt) or by using an IDE like Eclipse. By installing the Java SDK, system variables about the location of executables (compiler, java virtual machine) are not defined or initialized automatically.
Testing is done by opening command prompt (Start -> cmd) and trying to launch the compiler with the command

Thursday, January 3, 2013

Hàm lấy ảnh thumbnails từ hình ảnh trong bài viết,featured image và youtube

Chèn vào file functions.php trong thư mục theme

Code:
// Note that your theme must support post thumbnails for this function to work.
// If you are getting an error try adding add_theme_support('post-thumbnails'); to your functions. php file
function vp_get_thumb_url($text, $size){
    global $post;
    $imageurl="";

    // Check to see which image is set as "Featured Image"
    $featuredimg = get_post_thumbnail_id($post->ID);
    // Get source for featured image
    $img_src = wp_get_attachment_image_src($featuredimg, $size);
    // Set $imageurl to Featured Image
    $imageurl=$img_src[0];

    // If there is no "Featured Image" set, move on and get the first image attached to the post
    if (!$imageurl) {
        // Extract the thumbnail from the first attached imaged
        $allimages =&get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );

        foreach ($allimages as $img){
            $img_src = wp_get_attachment_image_src($img->ID, $size);
            break;
        }
        // Set $imageurl to first attached image
        $imageurl=$img_src[0];
    }

    // If there's no image attached or inserted in the post, look for a YouTube video
if (!$imageurl){
   // look for traditional youtube.com url from address bar
preg_match("/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $text, $matches2);
$youtubeurl = $matches2[0];
    if ($youtubeurl)
$imageurl = "http://i.ytimg.com/vi/{$matches2[3]}/1.jpg"; 
// look for YouTube embed
   else preg_match("/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/(v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $text, $matches2);
$youtubeurl = $matches2[0];
   if ($youtubeurl)
        // Get the thumbnail YouTube automatically generates
        // '0' is the biggest version, use 1 2 or 3 for smaller versions
$imageurl = "http://i.ytimg.com/vi/{$matches2[3]}/1.jpg"; 
}
    // If there is no image attached to the post, look for anything that looks like an image and get that
    if (!$imageurl) {
        preg_match('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i' ,  $text, $matches);
        $imageurl=$matches[1];
    }
// If there is no youtube thumbnail, show a default image
    if (!$imageurl) {
        $imageurl= "http://killthebeat.com/wp-content/themes/buzznews/images/thumbz.jpg";
    }

    // Spit out the image path
    return $imageurl;
}

Wednesday, January 2, 2013

Tạo File DEB và Source Cydia

Chúng ta hãy khái niệm sơ qua về cách thức hoạt động của Cydia và cách vận hành của nó!

Cydia được viết bởi Jay Freeman (saurik) cũng là 1 trong những thành viên trong iphone dev team dựa trên nền tảng unix có tính tương thích cao với HĐH MAC OS của iPhone giúp dễ dàng quản lý cũng như cài đặt các chương trình của hãng thứ 3 (liên quan tới System, nên ko được cấp phép bới Apple) nói cách khác Cydia được cài cho những máy đã Jailbreak.
Kiếm tiền từ wap 
Thay thế Installer: như chúng ta đã biết Installer 1 chương trình quá quen thuộc với những người dùng iPhone FW 1.x. Nay khi FW 2.x 3.x ra đời Cydia đã thay thế cho Installer 1 cách toàn diện.

Những gói cài đặt trên Installer là dạng .zip khi được down về thì Installer sẽ giải nén nó ra vào đường dẫn tương ứng. Cydia cũng giống vậy nhưng gói cài đặt của nó là dạng deb (DEBIAN) 1 dạng của Linux.

Cydia hoạt động bằng cách Down 1 file Packages.gz hoặc Packages.bz2 của 1 host bất kỳ và phân tích giải nén nó ra được 1 file Packages bao gồm những thông tin của toàn bộ những Packages trên Source.

Ta có 1 host làm Source cho Cydia Cydia Repo khi ta add Source này vào Cydia thì Cydia sẽ Down file Packages.bz2 của host này về giải nén được file Packages và phân tích thông tin của từng gói cài đặt bao gồm:

Popular Posts