Skip to content

Commit

Permalink
增加更新渠道
Browse files Browse the repository at this point in the history
  • Loading branch information
youlookwhat committed Aug 30, 2018
1 parent c04e6ae commit 7d4ec41
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.example.jingbin.webviewstudy;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatEditText;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -42,6 +46,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
AppCompatButton btOpenUrl;
@BindView(R.id.bt_java_js)
TextView btJavaJs;
@BindView(R.id.tv_version)
TextView tvVersion;


@Override
Expand All @@ -51,13 +57,15 @@ protected void onCreate(Bundle savedInstanceState) {
ButterKnife.bind(this);

StatusBarUtil.setColor(this, ContextCompat.getColor(this, R.color.colorPrimary), 0);
tvVersion.setText(String.format("版本:v%s", BuildConfig.VERSION_NAME));
btBaidu.setOnClickListener(this);
btCall.setOnClickListener(this);
btUploadPhoto.setOnClickListener(this);
btMovie.setOnClickListener(this);
btJavaJs.setOnClickListener(this);
btDeepLink.setOnClickListener(this);
btOpenUrl.setOnClickListener(this);
tvVersion.setOnClickListener(this);
/** 处理键盘搜索键 */
etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
Expand Down Expand Up @@ -100,6 +108,25 @@ public void onClick(View v) {
String deepLinkUrl = "file:///android_asset/deeplink.html";
WebViewActivity.loadUrl(this, deepLinkUrl, "DeepLink测试");
break;
case R.id.tv_version:
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setTitle("感谢");
builder.setMessage("开源不易,给作者一个star好吗?😊");
builder.setCancelable(false);
builder.setNegativeButton("已给", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "感谢老铁~", Toast.LENGTH_LONG).show();
}
});
builder.setPositiveButton("去star", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
WebViewActivity.loadUrl(MainActivity.this, "https://github.com/youlookwhat/WebViewStudy", "WebViewStudy");
}
});
builder.show();
break;
default:
break;
}
Expand All @@ -124,4 +151,22 @@ private void openUrl() {
}
WebViewActivity.loadUrl(this, url);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionbar_update:
WebViewActivity.loadUrl(this, "https://fir.im/webviewstudy", "网页浏览器 - fir.im");
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void run() {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.webview_menu, menu);
getMenuInflater().inflate(R.menu.menu_webview, menu);
return true;
}

Expand Down
176 changes: 98 additions & 78 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,94 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.jingbin.webviewstudy.MainActivity">

<android.support.v7.widget.AppCompatEditText
android:id="@+id/et_search"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="github.com/youlookwhat/WebViewStudy"
android:imeOptions="actionSearch"
android:inputType="text"
android:textSize="15sp" />

<android.support.v7.widget.AppCompatButton
android:id="@+id/bt_openUrl"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:text="打开网页" />
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.jingbin.webviewstudy.MainActivity">

<TextView
android:id="@+id/bt_baidu"
style="@style/textStyle"
android:text="百度一下" />
<android.support.v7.widget.AppCompatEditText
android:id="@+id/et_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="github.com/youlookwhat/WebViewStudy"
android:imeOptions="actionSearch"
android:inputType="text"
android:textSize="15sp" />

<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/bt_openUrl"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:text="打开网页" />

<TextView
android:id="@+id/bt_movie"
style="@style/textStyle"
android:text="视频播放" />
<TextView
android:id="@+id/bt_baidu"
style="@style/textStyle"
android:text="百度一下" />

<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />
<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />

<TextView
android:id="@+id/bt_upload_photo"
style="@style/textStyle"
android:text="上传图片测试" />
<TextView
android:id="@+id/bt_movie"
style="@style/textStyle"
android:text="视频播放" />

<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />
<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />

<TextView
android:id="@+id/bt_call"
style="@style/textStyle"
android:text="电话、短信、邮件、注入js" />
<TextView
android:id="@+id/bt_upload_photo"
style="@style/textStyle"
android:text="上传图片测试" />

<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />
<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />

<TextView
android:id="@+id/bt_java_js"
style="@style/textStyle"
android:text="js与android原生代码互调"
android:textAllCaps="false" />
<TextView
android:id="@+id/bt_call"
style="@style/textStyle"
android:text="电话、短信、邮件、注入js" />

<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />
<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />

<TextView
android:id="@+id/bt_deeplink"
style="@style/textStyle"
android:text="DeepLink 测试" />
<TextView
android:id="@+id/bt_java_js"
style="@style/textStyle"
android:text="js与android原生代码互调"
android:textAllCaps="false" />

<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />
</LinearLayout>
<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />

<TextView
android:id="@+id/bt_deeplink"
style="@style/textStyle"
android:text="DeepLink 测试" />

<View
style="@style/lineStyle"
android:layout_width="match_parent"
android:layout_height="1px" />

</LinearLayout>

<TextView
android:id="@+id/tv_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="30dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="20dp"
android:textSize="11sp"
tools:ignore="SmallSp"
tools:text="版本:v2.0" />
</RelativeLayout>
11 changes: 11 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/actionbar_update"
android:orderInCategory="100"
android:title="@string/action_update"
app:showAsAction="always" />

</menu>
File renamed without changes.
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="app_name">浏览器</string>
<string name="app_name">网页浏览器</string>

<string name="action_update">更新</string>
<string name="action_share">分享</string>
<string name="actionbar_search">搜索</string>
<string name="actionbar_more">更多信息</string>
Expand Down

0 comments on commit 7d4ec41

Please sign in to comment.