forked from mozilla-mobile/focus-android
-
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.
- Loading branch information
1 parent
b189185
commit 26f68eb
Showing
6 changed files
with
297 additions
and
312 deletions.
There are no files selected for viewing
69 changes: 0 additions & 69 deletions
69
app/src/main/java/org/mozilla/focus/widget/DefaultBrowserPreference.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
app/src/main/java/org/mozilla/focus/widget/DefaultBrowserPreference.kt
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,65 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.widget | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import android.support.v7.preference.Preference | ||
import android.support.v7.preference.PreferenceViewHolder | ||
import android.util.AttributeSet | ||
import android.widget.Switch | ||
import org.mozilla.focus.R | ||
import org.mozilla.focus.telemetry.TelemetryWrapper | ||
import org.mozilla.focus.utils.Browsers | ||
import org.mozilla.focus.utils.SupportUtils | ||
|
||
class DefaultBrowserPreference : Preference { | ||
private var switchView: Switch? = null | ||
|
||
// Instantiated from XML | ||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { | ||
init() | ||
} | ||
|
||
// Instantiated from XML | ||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | ||
init() | ||
} | ||
|
||
private fun init() { | ||
widgetLayoutResource = R.layout.preference_default_browser | ||
|
||
val appName = context.resources.getString(R.string.app_name) | ||
val title = context.resources.getString(R.string.preference_default_browser2, appName) | ||
|
||
setTitle(title) | ||
} | ||
|
||
override fun onBindViewHolder(holder: PreferenceViewHolder) { | ||
super.onBindViewHolder(holder) | ||
|
||
switchView = holder.findViewById(R.id.switch_widget) as Switch | ||
|
||
update() | ||
} | ||
|
||
fun update() { | ||
if (switchView != null) { | ||
val browsers = Browsers(context, Browsers.TRADITIONAL_BROWSER_URL) | ||
switchView?.isChecked = browsers.isDefaultBrowser(context) | ||
} | ||
} | ||
|
||
public override fun onClick() { | ||
val context = context | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
SupportUtils.openDefaultAppsSettings(context) | ||
TelemetryWrapper.makeDefaultBrowserSettings() | ||
} else { | ||
SupportUtils.openDefaultBrowserSumoPage(context) | ||
} | ||
} | ||
} |
93 changes: 0 additions & 93 deletions
93
app/src/main/java/org/mozilla/focus/widget/FloatingSessionsButton.java
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
app/src/main/java/org/mozilla/focus/widget/FloatingSessionsButton.kt
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,89 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.widget | ||
|
||
import android.content.Context | ||
import android.graphics.Canvas | ||
import android.graphics.Color | ||
import android.graphics.Paint | ||
import android.graphics.Typeface | ||
import android.support.design.widget.CoordinatorLayout | ||
import android.support.design.widget.FloatingActionButton | ||
import android.text.TextPaint | ||
import android.util.AttributeSet | ||
|
||
import org.mozilla.focus.R | ||
|
||
class FloatingSessionsButton : FloatingActionButton { | ||
|
||
private var textPaint: TextPaint? = null | ||
private var tabCount: Int = 0 | ||
|
||
constructor(context: Context) : super(context) { | ||
init() | ||
} | ||
|
||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | ||
init() | ||
} | ||
|
||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { | ||
init() | ||
} | ||
|
||
private fun init() { | ||
val paint = Paint() | ||
paint.color = Color.WHITE | ||
paint.typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD) | ||
|
||
val textSize = resources.getDimensionPixelSize(R.dimen.tabs_button_text_size) | ||
|
||
textPaint = TextPaint(paint) | ||
textPaint?.textAlign = Paint.Align.CENTER | ||
textPaint?.textSize = textSize.toFloat() | ||
|
||
setImageResource(R.drawable.tab_number_border) | ||
} | ||
|
||
fun updateSessionsCount(tabCount: Int) { | ||
this.tabCount = tabCount | ||
|
||
contentDescription = resources.getString(R.string.content_description_tab_counter, tabCount.toString()) | ||
|
||
val params = layoutParams as CoordinatorLayout.LayoutParams | ||
val behavior = params.behavior as FloatingActionButtonBehavior? | ||
|
||
val shouldBeVisible = tabCount >= 2 | ||
|
||
behavior?.setEnabled(shouldBeVisible) | ||
|
||
if (shouldBeVisible) { | ||
show() | ||
invalidate() | ||
} else { | ||
hide() | ||
} | ||
} | ||
|
||
override fun onDraw(canvas: Canvas) { | ||
super.onDraw(canvas) | ||
|
||
val x = canvas.width / 2f | ||
val y = canvas.height / 2f - (textPaint!!.descent() + textPaint!!.ascent()) / 2f | ||
|
||
val text = if (tabCount < TOO_MANY_TABS) tabCount.toString() else TOO_MANY_TABS_SYMBOL | ||
|
||
canvas.drawText(text, x, y, textPaint!!) | ||
} | ||
|
||
companion object { | ||
/** | ||
* The Answer to the Ultimate Question of Life, the Universe, and Everything. And the number of | ||
* tabs that is just too many. | ||
*/ | ||
private val TOO_MANY_TABS = 42 | ||
private val TOO_MANY_TABS_SYMBOL = ":(" | ||
} | ||
} |
Oops, something went wrong.