Skip to content

Commit

Permalink
Add the webview activity. All urls shoule be opened inside the app by…
Browse files Browse the repository at this point in the history
… default.
  • Loading branch information
Zhongyi Tong committed Jan 30, 2016
1 parent a15d1c6 commit a6103c3
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 41 deletions.
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="xyz.monkeytong.hongbao">
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
Expand All @@ -22,6 +22,9 @@
<activity android:name=".activities.SettingsActivity"
android:theme="@style/Base.Theme.AppCompat.Light">
</activity>
<activity android:name=".activities.WebViewActivity"
android:theme="@style/Base.Theme.AppCompat.Light">
</activity>
<service
android:name=".services.HongbaoService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
Expand All @@ -15,14 +14,10 @@
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import xyz.monkeytong.hongbao.R;
import xyz.monkeytong.hongbao.utils.ConnectivityUtil;
import xyz.monkeytong.hongbao.utils.UpdateTask;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

public class MainActivity extends Activity {
Expand All @@ -37,7 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
switchPlugin = (Button) findViewById(R.id.button_accessible);

handleMIUIStatusBar();
handleMaterialStatusBar();
updateServiceStatus();

explicitlyLoadPreferences();
Expand All @@ -51,14 +46,18 @@ private void explicitlyLoadPreferences() {
* 适配MIUI沉浸状态栏
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void handleMIUIStatusBar() {
Window window = this.getWindow();
private void handleMaterialStatusBar() {
try {
Window window = this.getWindow();

window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

window.setStatusBarColor(0xffd84e43);
window.setStatusBarColor(0xffd84e43);
} catch (Exception e) {
// Guai wo lo
}
}

@Override
Expand Down Expand Up @@ -101,18 +100,29 @@ public void onButtonClicked(View view) {
}

public void openGithub(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/geeeeeeeeek/WeChatLuckyMoney"));
startActivity(browserIntent);
Intent webViewIntent = new Intent(this, WebViewActivity.class);
webViewIntent.putExtra("title", "Github项目主页");
webViewIntent.putExtra("url", "https://github.com/geeeeeeeeek/WeChatLuckyMoney");
startActivity(webViewIntent);
}

public void openGithubReleaseNotes(View view) {
Intent webViewIntent = new Intent(this, WebViewActivity.class);
webViewIntent.putExtra("title", "发布日志");
webViewIntent.putExtra("url", "https://github.com/geeeeeeeeek/WeChatLuckyMoney/issues?q=is%3Aissue+is%3Aopen+label%3A%22release+notes%22");
startActivity(webViewIntent);
}

public void openSettings(View view) {
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
}

public int getStatusBarHeight() {
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) return getResources().getDimensionPixelSize(resourceId);
return 0;
public void openNews(View view) {
Intent webViewIntent = new Intent(this, WebViewActivity.class);
webViewIntent.putExtra("title", "红包攻略");
webViewIntent.putExtra("url", "http://sec-cdn.static.xiaomi.net/secStatic/proj/luckyNewsInfo/0127/index.html?v=1&");
startActivity(webViewIntent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public boolean onPreferenceClick(Preference preference) {
Preference issuePref = findPreference("pref_etc_issue");
issuePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_github_issues)));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SettingsActivity.this.startActivity(browserIntent);
Intent webViewIntent = new Intent(SettingsActivity.this, WebViewActivity.class);
webViewIntent.putExtra("title", "Github Issues");
webViewIntent.putExtra("url", getString(R.string.url_github_issues));
webViewIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(webViewIntent);
return false;
}
});
Expand All @@ -69,13 +71,17 @@ private void loadUI() {
setContentView(R.layout.activity_preferences);
addPreferencesFromResource(R.xml.preferences);

Window window = this.getWindow();
try {
Window window = this.getWindow();

window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

window.setStatusBarColor(0xffd84e43);
window.setStatusBarColor(0xffd84e43);
} catch (Exception e) {
// Guai wo lo
}
}

@Override
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;
import xyz.monkeytong.hongbao.R;
import xyz.monkeytong.hongbao.activities.SettingsActivity;
import xyz.monkeytong.hongbao.activities.WebViewActivity;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@
<ImageView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="@+id/main_actiob_bar_placeholder" android:layout_alignParentTop="true"
android:id="@+id/main_action_bar_placeholder" android:layout_alignParentTop="true"
android:background="#d65645" android:layout_alignTop="@+id/textView"/>
<TextView
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView" android:background="@mipmap/bg_action_bar" android:text="微信红包" android:textColor="#fee1b4"
android:gravity="center_vertical|center_horizontal"
android:textSize="26dp" android:autoText="false"/>
<ImageView
android:layout_width="44dp"
android:layout_height="44dp"
android:id="@+id/imageView3"
android:src="@mipmap/ic_books"
android:padding="10dp"
android:onClick="openNews"
android:layout_below="@+id/main_action_bar_placeholder"
android:layout_alignLeft="@+id/textView" android:layout_marginLeft="6dp"/>

<ImageView
android:layout_width="44dp"
android:layout_height="44dp"
android:id="@+id/imageView2"
android:src="@mipmap/ic_settings"
android:padding="10dp"
android:onClick="openSettings"
android:layout_alignRight="@+id/textView" android:layout_below="@+id/main_actiob_bar_placeholder"
android:layout_alignRight="@+id/textView" android:layout_below="@+id/main_action_bar_placeholder"
android:layout_marginRight="6dp"/>
<ImageView
android:layout_width="wrap_content"
Expand All @@ -44,9 +54,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="前往Github关注项目进展"
android:text="查看最新版本功能介绍"
android:id="@+id/textView2" android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true" android:clickable="true" android:onClick="openGithub"
android:layout_centerHorizontal="true" android:clickable="true" android:onClick="openGithubReleaseNotes"
android:layout_marginTop="3dp" android:textColor="#999999"/>
<TextView
android:layout_width="fill_parent"
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/res/layout/activity_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@
android:background="#d84e43"
tools:context=".SettingsActivity"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/preference_action_bar_placeholder"/>
<TextView android:layout_width="wrap_content" android:layout_height="60dp"
android:id="@+id/settings_bar"
android:text="@string/preference" android:textColor="#fde1b5"
android:gravity="left|center_vertical|center_horizontal"
android:elegantTextHeight="false" android:textSize="20sp"
android:layout_toRightOf="@+id/preference_back"
android:layout_below="@+id/preference_action_bar_placeholder"
/>
<ImageView
android:layout_width="40dp"
Expand All @@ -31,14 +26,14 @@
android:layout_marginRight="8dp"
android:clickable="true" android:onClick="performBack"
android:layout_alignBottom="@+id/settings_bar"
android:layout_below="@+id/preference_action_bar_placeholder" android:src="@mipmap/ic_back"/>
<ImageView android:layout_width="40dp" android:layout_height="40dp" android:id="@+id/imageView3"
android:src="@mipmap/ic_back"/>
<ImageView android:layout_width="40dp" android:layout_height="match_parent" android:id="@+id/imageView3"
android:clickable="true"
android:onClick="enterAccessibilityPage"
android:layout_below="@+id/preference_action_bar_placeholder"
android:layout_alignBottom="@+id/settings_bar" android:layout_alignParentRight="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp" android:layout_marginLeft="8dp"
android:padding="6dp" android:src="@mipmap/ic_refresh"/>
android:padding="6dp" android:src="@mipmap/ic_refresh"
android:layout_alignBottom="@+id/settings_bar"/>
</RelativeLayout>
<ListView android:layout_height="wrap_content" android:layout_width="match_parent"
android:id="@android:id/list" android:background="#fffaf6f1" android:padding="0dp">
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/res/layout/activity_webview.xml
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>
Binary file added app/src/main/res/mipmap-xxhdpi/ic_books.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<CheckBoxPreference
android:key="pref_watch_on_lock"
android:title="息屏抢红包"
android:summary="30分钟内保持后台活跃,将极大增加电量消耗,谨慎使用"
android:summary="30分钟内后台将保持活跃,可能会极大增加电量消耗,请谨慎使用"
android:layout="@layout/preference_checkbox"
android:defaultValue="false"/>
</PreferenceCategory>
Expand Down

0 comments on commit a6103c3

Please sign in to comment.