From cceb4ad9d79dcf464df8f337fdc529ea1b150c77 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 24 Dec 2016 22:47:40 +0800 Subject: [PATCH] Move about to fragment --- src/main/res/layout/layout_about.xml | 11 ++++++++ .../github/shadowsocks/AboutFragment.scala | 28 +++++++++++++++++++ .../com/github/shadowsocks/MainActivity.scala | 24 +++------------- 3 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 src/main/res/layout/layout_about.xml create mode 100644 src/main/scala/com/github/shadowsocks/AboutFragment.scala diff --git a/src/main/res/layout/layout_about.xml b/src/main/res/layout/layout_about.xml new file mode 100644 index 00000000..a1c74fa0 --- /dev/null +++ b/src/main/res/layout/layout_about.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/src/main/scala/com/github/shadowsocks/AboutFragment.scala b/src/main/scala/com/github/shadowsocks/AboutFragment.scala new file mode 100644 index 00000000..6ef35cdf --- /dev/null +++ b/src/main/scala/com/github/shadowsocks/AboutFragment.scala @@ -0,0 +1,28 @@ +package com.github.shadowsocks +import java.util.Locale + +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.view.{LayoutInflater, View, ViewGroup} +import android.webkit.{WebView, WebViewClient} + +class AboutFragment extends ToolbarFragment { + override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View = + inflater.inflate(R.layout.layout_about, container, false) + + override def onViewCreated(view: View, savedInstanceState: Bundle) { + super.onViewCreated(view, savedInstanceState) + toolbar.setTitle(getString(R.string.about_title).formatLocal(Locale.ENGLISH, BuildConfig.VERSION_NAME)) + val web = view.findViewById(R.id.web_view).asInstanceOf[WebView] + web.loadUrl("file:///android_asset/pages/about.html") + web.setWebViewClient(new WebViewClient() { + override def shouldOverrideUrlLoading(view: WebView, url: String): Boolean = { + try startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))) catch { + case _: android.content.ActivityNotFoundException => // Ignore + } + true + } + }) + } +} diff --git a/src/main/scala/com/github/shadowsocks/MainActivity.scala b/src/main/scala/com/github/shadowsocks/MainActivity.scala index eed2a65d..c58f73c3 100644 --- a/src/main/scala/com/github/shadowsocks/MainActivity.scala +++ b/src/main/scala/com/github/shadowsocks/MainActivity.scala @@ -24,11 +24,11 @@ import java.lang.System.currentTimeMillis import java.net.{HttpURLConnection, URL} import java.util.Locale -import android.app.{Activity, ProgressDialog} import android.app.backup.BackupManager +import android.app.{Activity, ProgressDialog} import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.content._ -import android.net.{Uri, VpnService} +import android.net.VpnService import android.nfc.{NdefMessage, NfcAdapter} import android.os.{Build, Bundle, Handler, Message} import android.support.design.widget.{FloatingActionButton, Snackbar} @@ -38,7 +38,6 @@ import android.support.v7.widget.RecyclerView.ViewHolder import android.text.TextUtils import android.util.Log import android.view.View -import android.webkit.{WebView, WebViewClient} import android.widget.{TextView, Toast} import com.github.jorgecastilloprz.FABProgressCircle import com.github.shadowsocks.ShadowsocksApplication.app @@ -78,6 +77,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe private var currentFragment: ToolbarFragment = _ private lazy val profilesFragment = new ProfilesFragment() private lazy val globalSettingsFragment = new GlobalSettingsFragment() + private lazy val aboutFragment = new AboutFragment() // Services private val callback = new IShadowsocksServiceCallback.Stub { @@ -237,7 +237,6 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe .withName(R.string.about) .withIcon(ContextCompat.getDrawable(this, R.drawable.ic_action_copyright)) .withIconTintingEnabled(true) - .withSelectable(false) ) .withOnDrawerItemClickListener(this) .withActionBarDrawerToggle(true) @@ -374,22 +373,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe case DRAWER_GLOBAL_SETTINGS => displayFragment(globalSettingsFragment) case DRAWER_ABOUT => app.track(TAG, "about") - val web = new WebView(this) - web.loadUrl("file:///android_asset/pages/about.html") - web.setWebViewClient(new WebViewClient() { - override def shouldOverrideUrlLoading(view: WebView, url: String): Boolean = { - try startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))) catch { - case _: android.content.ActivityNotFoundException => // Ignore - } - true - } - }) - new AlertDialog.Builder(this) - .setTitle(getString(R.string.about_title).formatLocal(Locale.ENGLISH, BuildConfig.VERSION_NAME)) - .setNegativeButton(getString(android.R.string.ok), null) - .setView(web) - .create() - .show() + displayFragment(aboutFragment) } true // unexpected cases will throw exception }