Cách kiếm tiền đơn giản, hiệu quả nhất

Thứ Năm, 10 tháng 9, 2015

Android - XML Parser Tutorial use of XMLPullParser parse xml on web api|android studio

|0 nhận xét
XML stands for Extensible Mark-up Language.XML is a very popular format and commonly used for sharing data on the internet. This chapter explains how to parse the XML file and extract necessary information from it.

XML-Parsing
we will create XMLPullParser object , but in order to create that we will first create XmlPullParserFactory object and then call its newPullParser() method to create XMLPullParser

Example:
Here is an example demonstrating the use of XMLPullParser class. It creates a basic Weather application that allows you to parse XML from google weather api and show the result.

Following is the content of the modified main activity file MainActivity.java.
package androiddemo.example.duyhoang.xmlparsedemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    private EditText txt1, txt2, txt3, txt4, txt5;
    private String url1 = "http://api.openweathermap.org/data/2.5/weather?q=";
    private String url2 = "&mode=xml";
    private HandleXml obj;
    Button btnWeather;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnWeather = (Button) findViewById(R.id.btn_weather);

        txt1 = (EditText) findViewById(R.id.txtLocation);
        txt2 = (EditText) findViewById(R.id.txt_curency);
        txt3 = (EditText) findViewById(R.id.txt_temp);
        txt4 = (EditText) findViewById(R.id.txt_humidity);
        txt5 = (EditText) findViewById(R.id.txt_pressure);
        btnWeather.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                String url = txt1.getText().toString();
                String finalUrl = url1 + url + url2;
                txt2.setText(finalUrl);
                obj = new HandleXml(finalUrl);
                obj.fetchXML();

                while (obj.parsingComplete) ;
                txt2.setText(obj.getCountry());
                txt3.setText(obj.getTemperature());
                txt4.setText(obj.getHumidity());
                txt5.setText(obj.getPressure());

            }
        });
    }

    @Override    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();

        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
Following is the content of src/com.example.xmlparser/HandleXML.java.
package androiddemo.example.duyhoang.xmlparsedemo;

import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/** * Created by DUYHOANG on 9/10/2015. */public class HandleXml {
    private String country = "country";
    private String temperature = "temperature";
    private String humidity = "humidity";
    private String pressure = "pressure";
    private String urlString = null;
    private XmlPullParserFactory xmlFactoryObject;
    public volatile boolean parsingComplete = true;

    public HandleXml(String url) {
        this.urlString = url;
    }

    public String getCountry() {
        return country;
    }

    public String getTemperature() {
        return temperature;
    }

    public String getHumidity() {
        return humidity;
    }

    public String getPressure() {
        return pressure;
    }

    public void parseXMLAndStorelt(XmlPullParser myParser) {
        int event;
        String text = null;
        try {
            event = myParser.getEventType();
            while (event != XmlPullParser.END_DOCUMENT) {
                String name = myParser.getName();
                switch (event) {
                    case XmlPullParser.START_TAG:
                        break;
                    case XmlPullParser.TEXT:
                        text = myParser.getText();
                        break;
                    case XmlPullParser.END_TAG:
                        if (name.equals("country")) {
                            country = text;
                        } else if (name.equals("humidity")) {
                            humidity = myParser.getAttributeValue(null, "value");
                        } else if (name.equals("pressure")) {
                            pressure = myParser.getAttributeValue(null, "value");
                        } else if (name.equals("temperature")) {
                            temperature = myParser.getAttributeValue(null, "value");
                        } else {
                        }
                        break;
                }
                event = myParser.next();
            }
            parsingComplete = false;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void fetchXML() {
        Thread thread = new Thread(new Runnable() {
            @Override            public void run() {
                try {
                    URL url = new URL(urlString);
                    HttpURLConnection connect = (HttpURLConnection) url.openConnection();
                    connect.setReadTimeout(10000);
                    connect.setConnectTimeout(15000);
                    connect.setRequestMethod("GET");
                    connect.setDoInput(true);
                    connect.connect();

                    InputStream stream = connect.getInputStream();
                    xmlFactoryObject = XmlPullParserFactory.newInstance();
                    XmlPullParser myparser = xmlFactoryObject.newPullParser();
                    myparser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
                    myparser.setInput(stream, null);
                    parseXMLAndStorelt(myparser);
                    stream.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
    }
}

Following is the modified content of the xml 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"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity">

    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentTop="true"        android:layout_centerHorizontal="true"        android:text="@string/fetch"        android:textSize="30dp" />

    <TextView        android:id="@+id/textView2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/textView1"        android:layout_centerHorizontal="true"        android:gravity="center"        android:text="@string/weather_report"        android:textColor="@color/text_color"        android:textSize="30dp"        android:textStyle="bold" />

    <EditText        android:id="@+id/txtLocation"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_below="@+id/textView2"        android:hint="@string/Location" />

    <Button        android:id="@+id/btn_weather"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/txtLocation"        android:layout_centerHorizontal="true"        android:text="@string/weather" />

    <LinearLayout        android:id="@+id/linearLayout1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_below="@id/btn_weather"        android:orientation="vertical">

        <EditText            android:id="@+id/txt_curency"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:text="@string/curency"            />

        <EditText            android:id="@+id/txt_temp"            android:text="@string/temp"            android:layout_width="match_parent"            android:layout_height="wrap_content" />

        <EditText            android:id="@+id/txt_humidity"            android:text="@string/humidity"            android:layout_width="match_parent"            android:layout_height="wrap_content" />

        <EditText            android:id="@+id/txt_pressure"            android:text="@string/pressure"            android:layout_width="match_parent"            android:layout_height="wrap_content" />
    </LinearLayout>

</RelativeLayout>

Following is the content of AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="androiddemo.example.duyhoang.xmlparsedemo" >
    <uses-permission android:name="android.permission.INTERNET"/>
    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >
        <activity            android:name=".MainActivity"            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Thank's for watching. good luck!!!

Chủ Nhật, 9 tháng 8, 2015

[Share] Ứng dụng học tiếng anh trên android đơn giản, dễ học

|0 nhận xét
Hiện nay, tiếng Anh được coi là ngôn ngữ quốc tế số một trên thế giới. Hàng triệu người từ các nền văn hóa khác nhau đều nỗ lực học tiếng Anh mỗi ngày. 

Ở Việt Nam, tiếng Anh cũng đã chiếm được vị trí quan trọng kể từ khi đất nước bắt đầu thực hiện chính sách mở cửa hội nhập ra khu vực và thế giới. Ở nhiều lĩnh vực khác nhau trong xã hội như kinh tế, chính trị, khoa học, du lịch, vv... đều rất cần những người có trình độ tiếng Anh giỏi. Người ta học và sử dụng tiếng Anh với nhiều mục đích khác nhau để đáp ứng nhu cầu giao tiếp ngày càng lớn trong xã hội, để kiếm được công việc tốt, để được thăng chức, hay để giành được cơ hội đi du học và làm việc ở nước ngoài. 
Trước những đặc điểm đó, mình xin giới thiệu với các bạn ứng dụng học tiếng anh trên điện thoại di động sử dụng hệ điều hành android.

Ứng dụng của mình có một số chức năng chính như sau:
-   Học từ vưng tiếng anh:
+ tổng hợp 3000 từ vựng thông dụng.
+ Từ vựng theo hình ảnh:Các loài động vât, thực vật, thức ăn đồ uống, phương tiện ,công việc, cơ thể người...
+ Từ vựng theo chủ đề:Tình yêu hôn nhân, các môn thể thao, thời tiết, các loại trái cây...
+ Từ vựng theo chuyên ngành:công nghệ thông tin, kinh tế,tài chính,kế toán...
- Học ngữ pháp tiếng anh
- Luyện nghe tiếng anh giao tiếp.
- Những cụm từ tiếng anh thông dụng trong giao tiếp.





Nội dung:
- Là một ứng dụng gọn nhẹ giúp người dùng có thể học ở mọi lúc mọi nơi một cách hiệu quả, học một mình hay học theo nhóm bạn bè.
- Người dùng có thể tra cứu những từ mới một cách dễ dàng.

- Xem các video hướng dẫn học tiếng anh khi có kết nối mạng.
Ứng dụng học tiếng anh cơ bản english study là một ứng dụng tuyệt vời giúp ích rất nhiều cho việc học tiếng anh của bạn.Ứng dụng được thiết kế để bạn dễ dàng học tập và củng cố kiến thức tiếng anh hạn hẹp.
Link cài đặt: English_study

Thứ Tư, 15 tháng 7, 2015

Khắc phục lỗi không nhận usb. Lỗi "Removable Disk" của USB

|1 nhận xét
Removable Disk xảy ra trong trường hợp usb của bạn sắp hỏng hoặc nhiễm virut. Hoặc trong trường hợp bạn copy dữ liệu vào trong usb có chứa file autorun.inf mà các phần mềm diệt virut nghi ngờ là các file virut nên chặn. 
Trong trường hợp đó khi kết nối usb vào với máy tính sẽ không thể mở được như hình sau: 
Như vậy Usb của bạn không thể đọc được, và việc cần làm là format lại usb nhưng lại nhận được thông báo dưới: 
Bạn download công cụ sửa lỗi HP USB Disk Storage Format Tool 2.2.3
Chạy file exe với Run as administrator
Ở bước này ta chọn kiểu định dạng tại File system: FAT 32, NTFS.
- Điền nhãn của USB tại Volume label.
- Chọn Quick Format sau đó chọn Start để bắt đầu Format USB.
Yes =>Ok

Sau khi Format xong chúng ta truy cập lại vào USB, nếu xảy ra lỗi trong quá trình Format, hoặc Format xong mà hiện thông báo bên dưới thì khả năng USb của bạn đã hỏng.
Chúc bạn thành công!!!


Thứ Bảy, 4 tháng 7, 2015

Displaying a dialog using an activity in android tutorial

|1 nhận xét
Displaying a dialog using an activity in android tutorial.

There are times where you need to display a dialog window to get a confirmation from the user. In 
this case, you can override the onCreateDialog()protected method defined in the base Activity
class to display a dialog window. The following Try It Out shows you how.
Now, create a new android project.
Edit interface in activity_main.xml file:

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.demoshowdialog.MainActivity" >

    <Button
        android:id="@+id/btnShow_Dialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Show Dialog" />

</RelativeLayout>
Next, the proccess code in MainActivity.java file:

package com.example.demoshowdialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
       private Button btnShow_Dialog;
       CharSequence[] items = { "Asus", "Acer", "Dell", "Vaio" };
       boolean[] bool = new boolean[items.length];

       @Override
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          btnShow_Dialog = (Button) findViewById(R.id.btnShow_Dialog);
          btnShow_Dialog.setOnClickListener(new OnClickListener() {

             @Override
             public void onClick(View v) {
                 showDialog(0);
             }
          });
       }

       @Override
       protected Dialog onCreateDialog(int id) {
          // TODO Auto-generated method stub
          switch (id) {
          case 0:
              return new AlertDialog.Builder(this)
              .setIcon(R.drawable.ic_launcher)
              .setTitle("Show Dialog Demo")
              .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                             @Override
                             public void onClick(DialogInterface dialog,int which) {
                             // TODO Auto-generated method stub
                             }
                   })
              .setNegativeButton("No",new DialogInterface.OnClickListener() {
                             @Override
                             public void onClick(DialogInterface dialogint which) {
                             // TODO Auto-generated method stub
                             }
                   })
              .setMultiChoiceItems(items, bool,new DialogInterface.OnMultiChoiceClickListener() {

              @Override
              public void onClick(DialogInterface dialog,int which, boolean isChecked) {
                                                              // TODO Auto-generated method stub
                    }
              }).create();
              }
              return null;
       }
}
Explain:
To display a dialog, you first override the onCreateDialog() method in the Activity class
@Override
       protected Dialog onCreateDialog(int id) {
...
}
This method is called when you call the showDialog() method
btnShow_Dialog = (Button) findViewById(R.id.btnShow_Dialog);
              btnShow_Dialog.setOnClickListener(new OnClickListener() {

                     @Override
                     public void onClick(View v) {
                           showDialog(0);
                     }
              });

The onCreateDialog() method is a callback for creating dialogs that are managed by the activity. When you call the showDialog() method, this callback will be invoked. The showDialog() method accepts an integer argument identifying a particular dialog to display.
Download source code: updating...

Thứ Hai, 29 tháng 6, 2015

Share bộ clip luyện phát âm chuẩn Anh-Mỹ

|1 nhận xét
Video clip được mình tổng hợp và chia sẻ cho các bạn gặp khó khăn cho việc học tiếng anh nói chung và khó khăn trong việc luyện phát âm nói riêng.

Bộ clip được tổng hợp gồm những từ vựng được sử dụng rất thông dụng trong tiếng anh giao tiếp hàng ngày. 

Share ebook học lập trình C từ cơ bản đến nâng cao cực hay

|0 nhận xét
Share ebook học lập trình C từ cơ bản đến nâng cao cực hay
Mô tả:
-Title The C Programming Language, 2nd Edition
-Author(s) Brian W. Kernighan, Dennis M. Ritchie
-Publisher: Prentice Hall PTR; 2 edition (April 1, 1988)
-Paperback 274 pages
-eBook PDF, 270 pages, 1.1 MB
-Language: English
Book Description
Just about every C programmer I respect learned C from this book. Unlike many of the 1,000 page doorstops stuffed with CD-ROMs that have become popular, this volume is concise and powerful (if somewhat dangerous) - like C itself. And it was written by Kernighan himself. Need we say more?
This book presents a complete guide to ANSI standard C language programming. Written by the developers of C, this new version helps readers keep up with the finalized ANSI standard for C while showing how to take advantage of C's rich set of operators, economy of expression, improved control flow, and data structures.
This 2nd edition has been completely rewritten with additional examples and problem sets to clarify the implementation of difficult language constructs.
About the Authors
  • Brian W. Kernighan works in the Computing Science Research Center at Bell Laboratories, Lucent Technologies. He is Consulting Editor for Addison-Wesley's Professional Computing Series and the author, with Dennis Ritchie, of The C Programming Language.
  • Dennis M. Ritchie was best known as the creator of the C programming language, a key developer of the Unix operating system. He was also notable for his influence on ALTRAN, B, BCPL, Multics, etc.
Hướng dẫn download tài liệu:
-Click vào đường dẫn download.
-Chờ khoảng 5s sau đỏ click vào SKIP THIS AD phía trên cùng bên phải .