Thứ Năm, 25 tháng 10, 2012
20 địa chỉ ăn buffet được ưa thích ở Sài Gòn
Thứ Hai, 22 tháng 10, 2012
Mẹo giữ cho đầu óc luôn tỉnh táo
Convert Html and Set text to Textview in Android
Spanned marked_up = Html.fromHtml(myString); textview.setText(marked_up.toString(),BufferType.SPANNABLE);
String styledText = "This is <font color='red'>simple</font>."; textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
WebView webview = new WebView(this); String summary = "<html><body>Sorry, <span style=\"background: red;\">Madonna</span>
gave no results</body></html>"; webview.loadData(summary, "text/html", "utf-8");
textView.setText(Html.fromHtml("this is <u>underlined</u> text"));
SpannableString content = new SpannableString(<your text>); content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
textView.setText(content);
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Thứ Bảy, 20 tháng 10, 2012
Android tutorial – display embedded HTML file in WebView
So let’s get started…
- first, embed an html file in the app resources. For this, create the
“raw” subfolder in “res” folder and add your HTML formatted file:
- use a WebView view in your layout file:
1
<
WebView
xmlns:android
=
"http://schemas.android.com/apk/res/android"
2
android:id
=
"@+id/webviewHelp android:layout_width="
fill_parent"
3
android:layout_height
=
"fill_parent"
/>
- use this code in your activity onCreate() method:
1
WebView webview = (WebView) findViewById(R.id.webviewHelp);
2
webview.loadData(readTextFromResource(R.raw.help),
"text/html"
,
"utf-8"
);
01
private
String readTextFromResource(
int
resourceID)
02
{
03
InputStream raw = getResources().openRawResource(resourceID);
04
ByteArrayOutputStream stream =
new
ByteArrayOutputStream();
05
int
i;
06
try
07
{
08
i = raw.read();
09
while
(i != -
1
)
10
{
11
stream.write(i);
12
i = raw.read();
13
}
14
raw.close();
15
}
16
catch
(IOException e)
17
{
18
e.printStackTrace();
19
}
20
return
stream.toString();
21
}
Thứ Tư, 17 tháng 10, 2012
Spiner Android Demo
2. http://androidviawikigauswami.blogspot.com/2012/06/simple-spinner-demo.html
3. http://www.technotalkative.com/android-spinner-example/
4.http://theandroid.in/simple-spinner-widget-demo-in-android/
5. http://app-solut.com/blog/2011/03/using-custom-layouts-for-spinner-or-listview-entries-in-android/
6.http://www.java-samples.com/showtutorial.php?tutorialid=1517
7.http://mylifewithandroid.blogspot.com/2009/10/spinner-and-its-data-behind.html
8. http://www.java2s.com/Code/Android/UI/SpinnerItemSelectedListener.htm
9http://androidgeisha.blogspot.com/2011/01/custom-spinner-row-layout-custom.html
10. http://stackoverflow.com/questions/8713283/custom-arrayadapter-and-spinner-no-item-selection
11.http://stackoverflow.com/questions/1625249/android-how-to-bind-spinner-to-custom-object-list
12. http://android-er.blogspot.com/2010/12/custom-spinner-with-icon.html
13. http://stackoverflow.com/questions/5744065/spinner-with-text-and-icons
14. http://stackoverflow.com/questions/10403923/how-to-set-spinner-to-a-specific-value-when-using-custom-adapter
15. http://stackoverflow.com/questions/12504702/displaying-objects-in-a-spinner-rather-than-just-strings
16.
Thứ Hai, 15 tháng 10, 2012
1. Android and JSON
1. Android and JSON
1.1. Included standard library
The Android platform includes the json.org
library which allows processing and creating JSON files.
Prefer using open source libraries like Gson or https://github.com/square/moshi[Moshi for JSON processing. These libraries are easier to use, faster and provide more flexibility |
1.2. Example: Reading JSON
Converting a JSON string into a JSON object is also simple. Create the following coding for the activity.
import org.json.JSONArray;
import org.json.JSONObject;
String jsonString = readJsonObjectFromSomeWhere(); (1)
try {
JSONObject json = new JSONObject(jsonString);
} catch (Exception e) {
e.printStackTrace();
}
1 | method which provides a JSON string, left out for brevity |
The code example cannot run in the main thread in Android. Ensure to run this snippet outside the main thread. |
1.3. Write JSON
Writing JSON is very simple. Just create the JSONObject or JSONArray and use the toString() method.
public void writeJSON() {
JSONObject object = new JSONObject();
try {
object.put("name", "Jack Hack");
object.put("score", new Integer(200));
object.put("current", new Double(152.32));
object.put("nickname", "Hacker");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println(object);
}
Android Detect Internet Connection Status
Detecting internet connection status in your app is very easy and won’t take more than 5mins. In this article you will learn how to detect internet connection status manually and automatically. Using broadcast receiver, your app will be automatically notified when there is a change in network connection.
This provides easy way do any changes in the app like hiding few button (like WhatsApp hides send, upload icon when there is not internet), navigation user to another screen, or just show a Snackbar message.
Creating New Project
1. Create a new project in Android Studio from File ⇒ New Project. When it prompts you to select the default activity, select Blank Activity and proceed.
2. Create a class named ConnectivityReceiver.java and extend it from BroadcastReceiver. This is a receiver class which will be notified whenever there is change in network / internet connection.
package info.androidhive.checkinternet; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class ConnectivityReceiver extends BroadcastReceiver { public static ConnectivityReceiverListener connectivityReceiverListener; public ConnectivityReceiver() { super(); } @Override public void onReceive(Context context, Intent arg1) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (connectivityReceiverListener != null) { connectivityReceiverListener.onNetworkConnectionChanged(isConnected); } } public static boolean isConnected() { ConnectivityManager cm = (ConnectivityManager) MyApplication.getInstance().getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); } public interface ConnectivityReceiverListener { void onNetworkConnectionChanged(boolean isConnected); } }
3. Create another class named MyApplication.java and extend it from Application. This class will be called whenever app is launched. Here setConnectivityListener() method is used to initiate the connectivity listener.
package info.androidhive.checkinternet; import android.app.Application; public class MyApplication extends Application { private static MyApplication mInstance; @Override public void onCreate() { super.onCreate(); mInstance = this; } public static synchronized MyApplication getInstance() { return mInstance; } public void setConnectivityListener(ConnectivityReceiver.ConnectivityReceiverListener listener) { ConnectivityReceiver.connectivityReceiverListener = listener; } }
4. Open AndroidManifest.xml and do the below changes.
> Add MyApplication to <application> tag.
> Add ConnectivityReceiver as <receiver>.
> Declare INTERNET and ACCESS_NETWORK_STATE permissions.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="info.androidhive.checkinternet"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".ConnectivityReceiver" android:enabled="true"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> </application> </manifest>
Broadcasting Internet Status to All Activities
Now we have all the setup ready. Let’s see how to notify an activity when the device is connected or disconnected from internet.
5. Open layout file main activity activity_main.xml add the below layout.
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="info.androidhive.checkinternet.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Turn on/off wifi to notify the app about connection status." /> <Button android:id="@+id/btn_check" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="Check Connection" /> </LinearLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@drawable/ic_add_white_24dp" /> </android.support.design.widget.CoordinatorLayout>
6. Open your MainActivity.java and do the below changes to receive the internet status.
> Register the connection change listener in onResume() method by calling MyApplication.getInstance().setConnectivityListener(this).
> Implement the activity from ConnectivityReceiver.ConnectivityReceiverListener which will override onNetworkConnectionChanged() method.
> onNetworkConnectionChanged() method will be triggered whenever device is connected / disconnected from internet. You need to take appropriate action here.
Follow the above same three steps in all other activities in which in you want to notify the internet status.
package info.androidhive.checkinternet; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity implements ConnectivityReceiver.ConnectivityReceiverListener { private Button btnCheck; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); btnCheck = (Button) findViewById(R.id.btn_check); // Manually checking internet connection checkConnection(); btnCheck.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Manually checking internet connection checkConnection(); } }); } // Method to manually check connection status private void checkConnection() { boolean isConnected = ConnectivityReceiver.isConnected(); showSnack(isConnected); } // Showing the status in Snackbar private void showSnack(boolean isConnected) { String message; int color; if (isConnected) { message = "Good! Connected to Internet"; color = Color.WHITE; } else { message = "Sorry! Not connected to internet"; color = Color.RED; } Snackbar snackbar = Snackbar .make(findViewById(R.id.fab), message, Snackbar.LENGTH_LONG); View sbView = snackbar.getView(); TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(color); snackbar.show(); } @Override protected void onResume() { super.onResume(); // register connection status listener MyApplication.getInstance().setConnectivityListener(this); } /** * Callback will be triggered when there is change in * network connection */ @Override public void onNetworkConnectionChanged(boolean isConnected) { showSnack(isConnected); } }
Run the project and try turning off / on wifi or mobile data. You can notice a Snackbar is shown with network connection status.
Installation SVN For ECLIPSE
This method is recommended if you wish to install a stable Subversive version that is an integral part of the yearly Eclipse Simultaneous Release. It allows you to install the Subversive plug-in using an Eclipse update site for an Eclipse Simultaneous Release.
Run Eclipse and select Help > Install New Software... from the main menu.
On the dialog that appears, select a pre-configured simultaneous release update site in the Work with combo-box. For example, for the Juno release, select the "http://download.eclipse.org/releases/juno" update site.
Wait a few seconds until the content of the selected update site is displayed under the combo-box.
Expand the Collaboration group and select the Subversive features that you would like to install. Certain Subversive features are required if you want to work with SVN, others are optional and offer some additional functionality. You can skip the optional features, if you wish.
Follow the next steps to install the selected Subversive features using the standard plug-in installation procedure. Reboot Eclipse after installation is complete.
Follow the instructions below to install Subversive connectors.
Option 2 - Use a Subversive Update Site
You can install Subversive using its online or archived update site. Use this method to install the Early Access Build that isn't available in the Eclipse Simultaneous Releases.
Run Eclipse and select Help > Install New Software... from the main menu.
In the Install dialog that appears, press the Add... button and specify the path to an online or archived Subversive update site. You can find information about the available Subversive update sites on the Downloads page.
Select the required Subversive features to install and follow the standard plug-in installation procedure. Reboot Eclipse after installation is complete.
Follow the instructions below to install Subversive connectors.
Chủ Nhật, 14 tháng 10, 2012
Android: Make a button not visible
View b = findViewById(R.id.button);
b.setVisibility(View.GONE);
or in xml:<Button ... android:visibility="gone"/>
Or
Button resetButton=(Button)findViewById(R.id.my_button_del);
resetButton.setVisibility(0); //To set visible
Xml:<Button
android:text="Delete"
android:id="@+id/my_button_del"
android:layout_width="72dp" android:layout_height="40dp"
android:visibility="invisible"/>
Thứ Năm, 11 tháng 10, 2012
Sai lầm các mẹ hay mắc khi dạy con
Quên giúp đỡ trẻ
Cha mẹ thường ít khi tìm hiểu lý do vì sao trẻ có hành động bất thường, mà nặng về trừng phạt. Ảnh: mom.me
|
Không động viên
Quá cứng nhắc
Nói dài dòng
Bạn thổi phồng sự việc
Quên mất câu hỏi "Tại sao"
Quên dạy trẻ
Nói quá nhiều
Trừng phạt quá mức cần thiết
Quan tâm đến người xung quanh nghĩ gì
Thuận An (theo mom.me)
Thứ Ba, 9 tháng 10, 2012
Adding menus to action bar in pre Honeycomb versions using Sherlock library
The application in this article is developed in Eclipse ( 3.7.2 ) with ADT plugin ( 20.0.2 ), Android SDK ( R20.0.1 ) and Action bar Sherlock library ( 4.1.0 )
1. Setup Action bar Sherlock library in Eclipse IDE
To setup Action bar Sherlock library in Eclipse IDE, refer the article “Setting up Sherlock library for action bar in pre Honeycomb Android Applications“.
2. Create new Android Application project namely “ActionBarSherlockMenu”
3. Design application launcher
Figure 2 : Design Application Launcher
4. Create a Blank Activity
Figure 3 : Create a blank Activity
5. Enter MainActivity Details
Figure 4 : Enter Main Activity Details
6. Delete default Support library
By default, ADT plugin adds a support library ( lib/android-support-v4.jar ) to the project. This is not needed for our application since this is being added by Sherlock library. So in order to avoid the conflict, delete the default support library via Eclipse’s project explorer.
7. Add Sherlock library to this project
Open the properties window of this project ( by right clicking the application at project explorer ) , and select Android tab to add the Sherlock library to this project.
Add Sherlock actionbar library
Figure 5 : Add Sherlock actionbar library
8. Add menu icons to this project
From the given below links, download the files drawable-mdpi.zip, drawable-hdpi.zip and drawable-xhdpi.zip and extract to the folders drawable-mdpi, drawable-hdpi and drawable-xhdpi respectively
Download drawable-mdpi.zip
Download drawable-hdpi.zip
Download drawable-xhdpi.zip
9. Update res/values/strings.xml
<resources>
<string name="app_name">ActionBarSherlockMenu</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="phone">Phone</string>
<string name="computer">Computer</string>
<string name="gamepad">Gamepad</string>
<string name="camera">Camera</string>
<string name="video">Video</string>
<string name="email">EMail</string>
</resources>
10. Update the menu file res/menu/activity_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Theme.Sherlock"
>
<item
android:id="@+id/phone"
android:title="@string/phone"
android:icon="@drawable/phone"
android:showAsAction="ifRoom|withText"
style="@style/Theme.Sherlock"
/>
<item
android:id="@+id/computer"
android:title="@string/computer"
android:icon="@drawable/computer"
android:showAsAction="ifRoom|withText"
style="@style/Theme.Sherlock"
/>
<item
android:id="@+id/gamepad"
android:title="@string/gamepad"
android:icon="@drawable/gamepad"
android:showAsAction="ifRoom|withText"
style="@style/Theme.Sherlock"
/>
<item
android:id="@+id/camera"
android:title="@string/camera"
android:icon="@drawable/camera"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/video"
android:title="@string/video"
android:icon="@drawable/video"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/email"
android:title="@string/email"
android:icon="@drawable/email"
android:showAsAction="ifRoom|withText"
/>
</menu>
11. Update the file src/in/wptrafficanalyzer/actionbarsherlockmenu/MainActivity.java
package in.wptrafficanalyzer.actionbarsherlockmenu;
import android.os.Bundle;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
public class MainActivity extends SherlockActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.phone:
Toast.makeText(getBaseContext(), "You selected Phone", Toast.LENGTH_SHORT).show();
break;
case R.id.computer:
Toast.makeText(getBaseContext(), "You selected Computer", Toast.LENGTH_SHORT).show();
break;
case R.id.gamepad:
Toast.makeText(getBaseContext(), "You selected Gamepad", Toast.LENGTH_SHORT).show();
break;
case R.id.camera:
Toast.makeText(getBaseContext(), "You selected Camera", Toast.LENGTH_SHORT).show();
break;
case R.id.video:
Toast.makeText(getBaseContext(), "You selected Video", Toast.LENGTH_SHORT).show();
break;
case R.id.email:
Toast.makeText(getBaseContext(), "You selected EMail", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
}
12. Update AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.wptrafficanalyzer.actionbarsherlockmenu"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
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/title_activity_main"
android:theme="@style/Theme.Sherlock.ForceOverflow"
android:uiOptions="splitActionBarWhenNarrow"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Download Source Code
Download Full Source Code
Reference
http://developer.android.com/guide/index.html
Học lập trình web căn bản với PHP
Bài 1: Các kiến thức căn bản Part 1: https://jimmyvan88.blogspot.com/2012/05/can-ban-lap-trinh-web-voi-php-bai-1-cac.html Part 2: https://...
-
IMindMap 8.0.4 iMindMap là công cụ tuyệt vời để vẽ bản đồ tư duy đem mọi chi tiết trong đầu bạn ra thành các ý tươgnr, để nắm bắt ý tư...
-
1. Download Bamboo in : http://www.atlassian.com/software/bamboo/download?os=linux cd ~ mkdir BAMBOO cd BAMBOO wget http://www.atlassia...
-
1.Giới thiệu về Vim Vim – Vi iMprove là bản cải thiện của Vim – một trình soạn thảo phổ biến trên Unix. Vim có tính cấu hình rất cao ...