也還蠻簡單的,不過要利用Float object來判斷,程式碼如下:
Float dbear = new Float(this.myloc.bearingTo(oxlocate));
if (dbear.isNaN() == false) {
Android是Google為手機所打造的作業系統,良好的介面和易於學習的語言。這裡記錄著我的學習片段,就像一杯杯的咖啡,香韻留存。
Float dbear = new Float(this.myloc.bearingTo(oxlocate));
if (dbear.isNaN() == false) {
public boolean isInternetConnect() {
boolean isConnected = false;
ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
if (connec.getNetworkInfo(0).isConnectedOrConnecting() == true ||
connec.getNetworkInfo(1).isConnectedOrConnecting() == true ) {
isConnected = true;
}
return isConnected;
}
其中connec.getNetworkInfo(0)是指Mobile phone(GPRS,3G),connec.getNetworkInfo(1)是檢察WiFi有沒有通。
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="500" />
</set>
left_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="500" />
</set>
right_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="500" />
</set>
right_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="500" />
</set>
在main.xml我們定義了兩個Views,一個一開始是顯示的,另一個是隱藏起來的,另外定義了兩個按鈕來做視窗的切換。
.....
<LinearLayout
android:id="@+id/map_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dip"
android:layout_marginBottom="0dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:visibility="gone"
>
</LinearLayout>
<ListView android:id="@+id/oxcache_list"
android:persistentDrawingCache="animation|scrolling"
android:cacheColorHint="#00000000"
android:divider="@color/gray_light"
android:dividerHeight="1dip"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
.....
<Button
android:id="@+id/list_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dip"
android:text="@string/list"
android:textColor="@color/header_text"
android:background="@drawable/btn_left_unpress"
style="@style/List"
/>
<Button
android:id="@+id/map_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-8dip"
android:text="@string/map"
android:textColor="@color/header_text"
android:background="@drawable/btn_right_unpress"
style="@style/List"
/>
在程式中,透過監聽兩個按鈕的click event來切換不同的視窗,重點是什麼情況是右進左出,左進右出了。
listBtn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
mOxcacheList.setVisibility(View.VISIBLE);
mOxcacheList.setClickable(true);
mOxcacheList.setAnimation(AnimationUtils.loadAnimation(CacheMe.this, R.layout.push_left_in));
mMapLinear.setVisibility(View.GONE);
mMapLinear.setAnimation(AnimationUtils.loadAnimation(CacheMe.this, R.layout.push_right_out));
}
}
});
mapBtn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
mMapLinear.setVisibility(View.VISIBLE);
mMapLinear.setClickable(true);
mMapLinear.setAnimation(AnimationUtils.loadAnimation(CacheMe.this, R.layout.push_right_in));
mOxcacheList.setVisibility(View.GONE);
mOxcacheList.setAnimation(AnimationUtils.loadAnimation(CacheMe.this, R.layout.push_left_out));
}
}
});
......
public static boolean isDebugMode(Context ctx) {
PackageInfo packageInfo;
try {
packageInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
int flags = packageInfo.applicationInfo.flags;
if ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
return true;
}
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}