2011年9月28日 星期三

About DIII Game Guide App Skill Calculator


AndroidManifest.xml

<activity android:name=".XXX">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="*" android:pathPattern=".*\\calculator/.*" android:scheme="http" />
</intent-filter>
</activity>

JAVA:


String XXXX = "http://xxxxxxxxxx";



Intent intent = new Intent();
intent = new Intent(Intent.ACTION_VIEW,Uri.parse(XXXX));
startActivity(intent);


About DIII Game Guide App Youtube


private PackageManager packageManager = null;

Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", "diablo 3");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

packageManager = this.getPackageManager();

if (packageManager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY) != null && packageManager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
    startActivity(intent);
}else{
    openWebView();
}

//如果手機端有com.google.android.youtube則呼叫

//否則使用網頁開啟youtube網站

About DIII Game Guide App Skill List Layout



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:id="@+id/view_paper_icon_tag_left"
android:src="@drawable/indicator_left" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="left|center_vertical"
android:clickable="true" android:focusable="true" />
<TextView android:id="@+id/view_paper_title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/list_text_light_color"
android:layout_gravity="center" android:textStyle="bold" />
<ImageView android:id="@+id/view_paper_icon_tag_right"
android:src="@drawable/indicator_right" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="right|center_vertical"
android:clickable="true" android:focusable="true" />
</FrameLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager_main" android:layout_width="match_parent"
android:layout_height="0px" android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>

About DIII Game Guide App Classes Layout



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:background="@drawable/bg2" android:layout_height="fill_parent">
<LinearLayout android:layout_weight="0.3" android:gravity="center"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Gallery android:id="@+id/classes_gallery"
android:layout_gravity="center" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center" />
</LinearLayout>
<ScrollView android:layout_width="fill_parent"
android:layout_gravity="center_horizontal" android:layout_weight="0.3"
android:layout_height="wrap_content" android:scrollbars="none">
<LinearLayout android:orientation="vertical"
android:gravity="center" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/classes_name"
android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content" android:textColor="@color/list_text_dark_color" />
<TextView android:id="@+id/classes_description"
android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content" android:textColor="@color/list_text_light_color" />
<TextView android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content" android:textColor="@color/list_text_color"
android:text="@string/select_classes_info" android:textStyle="italic" />
</LinearLayout>
</ScrollView>
</LinearLayout>

About DIII Game Guide App WebView

Xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ProgressBar android:id="@+id/progress_web_load"
style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent"
android:layout_height="10dip" android:max="100" android:progress="0" />
<WebView android:id="@+id/webview"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>

ProgressBar 用來顯示網頁讀取進度

Java:

public class Web extends Activity {
private WebView wv;
private ProgressBar pgWebLoad;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
wv = (WebView) findViewById(R.id.webview);
pb = (ProgressBar) findViewById(R.id.progress_web_load);

wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setSavePassword(true);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setPluginsEnabled(true); //true才能顯示flash


if (this.getIntent().getBooleanExtra("isDesktop", false)) {
wv.getSettings().setUserAgentString(
"Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/11.04 Chromium/12.0.742.91 Chrome/12.0.742.91 Safari/534.30");
}
//是否強制以桌面瀏覽器呈現方式

wv.setFocusable(true);
wv.setFocusableInTouchMode(true);
wv.setWebChromeClient(new WebChromeClient() {

@Override
public void onProgressChanged(WebView view, int newProgress) {
// TODO Auto-generated method stub
pb.setProgress(newProgress);
if (newProgress == 100) {
pb.setVisibility(View.GONE);
} else {
pb.setVisibility(View.VISIBLE);
}
super.onProgressChanged(view, newProgress);
}
});

wv.setWebViewClient(new WebViewClient() {

public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Toast.makeText(WebSite.this, description, Toast.LENGTH_SHORT).show();
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
});
wv.loadUrl(getIntent().getStringExtra("url"));
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if ((keyCode == KeyEvent.KEYCODE_BACK) && wv.canGoBack()) {
wv.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}

About DIII Game Guide App Change Locale

主畫面按menu 可以選擇語系


private void changeLang(int whichcountry) {
String[] items = new String[] { "Deutsch", "English(United States)",
"Español(España)", "Français", "Русский", "한국어", "中文(繁體)",
"中文(简体)" };

Resources res = getResources();
Locale.setDefault(getLocale(whichcountry));
Configuration config = new Configuration();
config.locale = Locale.getDefault();
res.updateConfiguration(config, res.getDisplayMetrics());
updateView();
}


private Locale getLocale(int whichcountry) {
switch (whichcountry) {
case 0:
return Locale.GERMANY;
case 1:
return Locale.US;
case 2:
return new Locale("es");
case 3:
return Locale.FRANCE;
case 4:
return new Locale("ru");
case 5:
return Locale.KOREA;
case 6:
return Locale.TRADITIONAL_CHINESE;
case 7:
return Locale.SIMPLIFIED_CHINESE;
default:
return Locale.ENGLISH;
}
}

About DIII Game Guide App Share

使用Intent.createChooser的方式




Sample:





String[] recipients = new String[] { "XXX@XXX.XXX" };

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

emailIntent.setType("text/html");

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,recipients);

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Email subject");

emailIntent.putExtra(Intent.EXTRA_TEXT,"Email text");

startActivity(Intent.createChooser(emailIntent, "Email:"));

About DIII Game Guide App Library


android-support-v4.jar
GoogleAdMobAdsSdk-4.1.1.jar
libGoogleAnalytics.jar


android-support-v4.jar
增加Fragment
參考 http://code.google.com/p/iosched/

proguard.cfg 增加

-dontwarn **CompatHoneycomb
-dontwarn **CompatHoneycombMR2
-dontwarn **CompatCreatorHoneycombMR2
-keep class android.support.v4.** { *; }

-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment



GoogleAdMobAdsSdk-4.1.1.jar
提供AdMob廣告
參考http://code.google.com/mobile/ads/docs/android/fundamentals.html

Layout xml檔設定

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_gravity="center" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
ads:adUnitId="XXXXXXXXX" ads:adSize="BANNER" ads:loadAdOnCreate="true" />
</LinearLayout>



AndroidManifest.xml

<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation" />


  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


libGoogleAnalytics.jar
用於 Google Analytics
參考http://code.google.com/mobile/analytics/docs/android/

AndroidManifest.xml

<receiver android:name="com.google.android.apps.analytics.AnalyticsReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>

  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Java:

GoogleAnalyticsTracker tracker;

tracker = GoogleAnalyticsTracker.getInstance();
tracker.start(this.getString(R.string.ga_api_key), 20, this
.getApplicationContext());

protected void onDestroy() {
super.onDestroy();
tracker.stop();
}

protected void onResume() {
super.onResume();
tracker.trackPageView("/" + this.getLocalClassName());
}