forked from geeeeeeeeek/WeChatLuckyMoney
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the webview activity. All urls shoule be opened inside the app by…
… default.
- Loading branch information
Zhongyi Tong
committed
Jan 30, 2016
1 parent
a15d1c6
commit a6103c3
Showing
10 changed files
with
212 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
app/src/main/java/xyz/monkeytong/hongbao/activities/WebViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package xyz.monkeytong.hongbao.activities; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceActivity; | ||
import android.preference.PreferenceManager; | ||
import android.provider.Settings; | ||
import android.view.KeyEvent; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
import android.webkit.CookieSyncManager; | ||
import android.webkit.WebSettings; | ||
import android.webkit.WebView; | ||
import android.webkit.WebViewClient; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
import xyz.monkeytong.hongbao.R; | ||
import xyz.monkeytong.hongbao.utils.UpdateTask; | ||
|
||
/** | ||
* Created by Zhongyi on 1/19/16. | ||
* Settings page. | ||
*/ | ||
public class WebViewActivity extends Activity { | ||
private WebView webView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
loadUI(); | ||
|
||
Bundle bundle = getIntent().getExtras(); | ||
if (bundle != null && !bundle.isEmpty()) { | ||
String webViewTitle = bundle.getString("title"); | ||
String webViewUrl = bundle.getString("url"); | ||
|
||
TextView webViewBar = (TextView) findViewById(R.id.webview_bar); | ||
webViewBar.setText(webViewTitle); | ||
|
||
webView = (WebView) findViewById(R.id.webView); | ||
webView.getSettings().setBuiltInZoomControls(false); | ||
webView.getSettings().setJavaScriptEnabled(true); | ||
webView.getSettings().setDomStorageEnabled(true); | ||
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); | ||
webView.setWebViewClient(new WebViewClient() { | ||
@Override | ||
public boolean shouldOverrideUrlLoading(WebView view, String url) { | ||
view.loadUrl(url); | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onPageFinished(WebView view, String url) { | ||
CookieSyncManager.getInstance().sync(); | ||
} | ||
}); | ||
webView.loadUrl(webViewUrl); | ||
} | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | ||
private void loadUI() { | ||
setContentView(R.layout.activity_webview); | ||
try { | ||
Window window = this.getWindow(); | ||
|
||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
|
||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | ||
|
||
window.setStatusBarColor(0xffd84e43); | ||
} catch (Exception e) { | ||
// Guai wo lo | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
} | ||
|
||
public void performBack(View view) { | ||
super.onBackPressed(); | ||
} | ||
|
||
@Override | ||
public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
if (event.getAction() == KeyEvent.ACTION_DOWN) { | ||
switch (keyCode) { | ||
case KeyEvent.KEYCODE_BACK: | ||
if (webView.canGoBack()) { | ||
webView.goBack(); | ||
} else { | ||
finish(); | ||
} | ||
return true; | ||
} | ||
|
||
} | ||
return super.onKeyDown(keyCode, event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" tools:context=".activities.WebViewActivity"> | ||
|
||
<RelativeLayout android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="#d84e43" | ||
tools:context=".WebViewActivity" | ||
> | ||
<TextView android:layout_width="wrap_content" android:layout_height="60dp" | ||
android:id="@+id/webview_bar" | ||
android:text="@string/app_name" android:textColor="#fde1b5" | ||
android:gravity="left|center_vertical|center_horizontal" | ||
android:elegantTextHeight="false" android:textSize="20sp" | ||
android:layout_toRightOf="@+id/preference_back" | ||
/> | ||
<ImageView | ||
android:layout_width="40dp" | ||
android:layout_height="match_parent" | ||
android:id="@+id/preference_back" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginRight="8dp" | ||
android:clickable="true" android:onClick="performBack" | ||
android:layout_alignBottom="@+id/webview_bar" | ||
android:src="@mipmap/ic_back"/> | ||
</RelativeLayout> | ||
<WebView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/webView" android:layout_gravity="center_horizontal" android:foreground="#d84e43"/> | ||
|
||
</LinearLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters