Skip to content

Commit

Permalink
[Toolbar] 🎨 More icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercandj committed Dec 30, 2017
1 parent 29e8419 commit 63cf514
Show file tree
Hide file tree
Showing 13 changed files with 336 additions and 269 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ android {
// Split resources.
// https://medium.com/google-developer-experts/android-project-structure-alternative-way-29ce766682f0#.sjnhetuhb
res.srcDirs = [
'src/main/res/browser',
'src/main/res/common',
'src/main/res/home'
]
Expand Down
40 changes: 0 additions & 40 deletions app/src/main/assets/browser.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import android.os.Bundle
import android.support.design.widget.AppBarLayout
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.PopupMenu
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.EditText
import android.widget.ProgressBar
import android.widget.TextView
import android.widget.Toast
import com.mercandalli.android.browser.R
import com.mercandalli.android.browser.keyboard.KeyboardUtils
import com.mercandalli.android.browser.main.Constants
Expand Down Expand Up @@ -58,8 +61,8 @@ class BrowserActivity : AppCompatActivity() {
webView = findViewById(R.id.activity_main_web_view)
webView!!.browserWebViewListener = browserWebViewListener
progress = findViewById(R.id.activity_main_progress)
home = findViewById(R.id.activity_main_home)
home!!.setOnClickListener { loadHomePage() }
home = findViewById(R.id.activity_main_more)
home!!.setOnClickListener { showOverflowPopupMenu(home!!) }
input = findViewById(R.id.activity_main_search)
input!!.setOnEditorActionListener(createOnEditorActionListener())

Expand Down Expand Up @@ -107,6 +110,7 @@ class BrowserActivity : AppCompatActivity() {
}

private fun loadHomePage() {
setProgressBarProgress(0)
webView!!.load(Constants.HOME_PAGE)
}

Expand All @@ -123,19 +127,25 @@ class BrowserActivity : AppCompatActivity() {
return
}
progress!!.visibility = VISIBLE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
progress!!.setProgress(progressPercent, true)
} else {
progress!!.progress = progressPercent
}
setProgressBarProgress(progressPercent)
}
}
}

private fun setProgressBarProgress(progressPercent: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
progress!!.setProgress(progressPercent, true)
} else {
progress!!.progress = progressPercent
}
}

private fun createOnEditorActionListener(): TextView.OnEditorActionListener {
return TextView.OnEditorActionListener { v, _, _ ->
webView!!.load("https://www.google.fr/search?q=" + v!!.text.toString().replace(" ", "+"))
webView!!.load("https://www.google.fr/search?q=" + v!!.text.toString()
.replace(" ", "+"))
appBarLayout!!.setExpanded(false)
input!!.setText("")
KeyboardUtils.hideSoftInput(input!!)
true
}
Expand All @@ -153,6 +163,30 @@ class BrowserActivity : AppCompatActivity() {
}
}

/**
* Show a popup menu which allows the user to perform action related to the video and the queue.
*
* @param view : The [View] on which the popup menu should be anchored.
*/
private fun showOverflowPopupMenu(view: View) {
val popupMenu = PopupMenu(this, view, Gravity.END)
popupMenu.menuInflater.inflate(R.menu.menu_browser, popupMenu.menu)
popupMenu.setOnMenuItemClickListener(createOnMenuItemClickListener())
popupMenu.show()
}

private fun createOnMenuItemClickListener(): PopupMenu.OnMenuItemClickListener? {
return PopupMenu.OnMenuItemClickListener { item ->
when (item!!.itemId) {
R.id.menu_browser_home -> loadHomePage()
R.id.menu_browser_clear_data -> webView!!.clearData()
R.id.menu_browser_settings -> Toast.makeText(this@BrowserActivity,
"Not yet", Toast.LENGTH_SHORT).show()
}
false
}
}

private fun updateTheme() {
updateTheme(themeManager.theme)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.webkit.*
import com.mercandalli.android.browser.main.Constants

class BrowserWebView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
Expand Down Expand Up @@ -35,7 +34,7 @@ class BrowserWebView @JvmOverloads constructor(
settings.setSupportZoom(true)
settings.builtInZoomControls = true
settings.displayZoomControls = false
settings.userAgentString = Constants.USER_AGENT
//settings.userAgentString = Constants.USER_AGENT

webChromeClient = object : WebChromeClient() {
override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
Expand Down Expand Up @@ -67,18 +66,12 @@ class BrowserWebView @JvmOverloads constructor(
}
}

fun clearData() {
clearHistory()
clearCache(true)
}

fun load(url: String) {
/*
if(url.contains("youtube")) {
loadDataWithBaseURL(
"http://www.google.com/",
BrowserUtils.getHtml(context),
WEB_VIEW_MIME_TYPE,
WEB_VIEW_ENCODING,
"")
loadUrl(String.format("javascript:loadUrl(%s);", url))
}
*/
loadUrl(url)
}

Expand Down

This file was deleted.

Loading

0 comments on commit 63cf514

Please sign in to comment.