mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
commit
61fd660195
7 changed files with 104 additions and 106 deletions
|
@ -7,87 +7,45 @@ import android.graphics.Typeface
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.appcompat.widget.AppCompatTextView
|
import androidx.appcompat.widget.AppCompatTextView
|
||||||
|
|
||||||
|
/** [FontAwesome] is just a type of TextView with special functions:
|
||||||
|
*
|
||||||
|
* `setText(str)` can be used to change the icon
|
||||||
|
* `setIconType(Int)` changes the FontAwesome style ("solid", "regular" or "brand")
|
||||||
|
* `setTextColor(Int)` changes the color
|
||||||
|
* `setTextSize(Int, Float)` changes the icon size
|
||||||
|
*/
|
||||||
|
|
||||||
class FontAwesomeSolid : AppCompatTextView {
|
class FontAwesome : AppCompatTextView {
|
||||||
constructor(
|
|
||||||
context: Context?,
|
var type = "" // "solid", "regular" or "brand"
|
||||||
attrs: AttributeSet?,
|
|
||||||
defStyle: Int
|
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int)
|
||||||
) : super(context, attrs, defStyle) {
|
: super(context, attrs, defStyle) { init(attrs) }
|
||||||
init()
|
constructor(context: Context?, attrs: AttributeSet?)
|
||||||
|
: super(context, attrs) { init(attrs) }
|
||||||
|
constructor(context: Context?)
|
||||||
|
: super(context) { init(null) }
|
||||||
|
|
||||||
|
private fun init(attrs: AttributeSet?) {
|
||||||
|
if (attrs != null) {
|
||||||
|
val a = context!!.obtainStyledAttributes(attrs, R.styleable.FontAwesome)
|
||||||
|
if (a.hasValue(R.styleable.FontAwesome_type))
|
||||||
|
type = a.getString(R.styleable.FontAwesome_type)!!
|
||||||
|
a.recycle()
|
||||||
|
if (type == "") type = "solid"
|
||||||
|
}
|
||||||
|
setIconType(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
// Useful if you want to change between a regular and solid icon (example: star)
|
||||||
context,
|
fun setIconType(iconType : String){
|
||||||
attrs
|
type = iconType
|
||||||
) {
|
|
||||||
init()
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(context: Context?) : super(context) {
|
typeface = when (type) {
|
||||||
init()
|
"regular" -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-regular-400.ttf")
|
||||||
}
|
"solid" -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-solid-900.ttf")
|
||||||
|
"brands" -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-brands-400.ttf")
|
||||||
private fun init() {
|
else -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-solid-900.ttf")
|
||||||
typeface = Typeface.createFromAsset(
|
|
||||||
context.assets,
|
|
||||||
"fontawesome/fa-solid-900.ttf"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FontAwesomeRegular : AppCompatTextView {
|
|
||||||
constructor(
|
|
||||||
context: Context?,
|
|
||||||
attrs: AttributeSet?,
|
|
||||||
defStyle: Int
|
|
||||||
) : super(context, attrs, defStyle) {
|
|
||||||
init()
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
|
||||||
context,
|
|
||||||
attrs
|
|
||||||
) {
|
|
||||||
init()
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(context: Context?) : super(context) {
|
|
||||||
init()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun init() {
|
|
||||||
typeface = Typeface.createFromAsset(
|
|
||||||
context.assets,
|
|
||||||
"fontawesome/fa-regular-400.ttf"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FontAwesomeBrand : AppCompatTextView {
|
|
||||||
constructor(
|
|
||||||
context: Context?,
|
|
||||||
attrs: AttributeSet?,
|
|
||||||
defStyle: Int
|
|
||||||
) : super(context, attrs, defStyle) {
|
|
||||||
init()
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
|
||||||
context,
|
|
||||||
attrs
|
|
||||||
) {
|
|
||||||
init()
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(context: Context?) : super(context) {
|
|
||||||
init()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun init() {
|
|
||||||
typeface = Typeface.createFromAsset(
|
|
||||||
context.assets,
|
|
||||||
"fontawesome/fa-brands-400.ttf"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,13 @@ class MainActivity : AppCompatActivity(),
|
||||||
|
|
||||||
// Start by showing the settings icon
|
// Start by showing the settings icon
|
||||||
showSettingsIcon()
|
showSettingsIcon()
|
||||||
|
|
||||||
|
// As older APIs somehow do not recognize the xml defined onClick
|
||||||
|
findViewById<View>(R.id.settingstooltip).setOnClickListener() {
|
||||||
|
openSettings()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart(){
|
override fun onStart(){
|
||||||
|
@ -75,6 +82,8 @@ class MainActivity : AppCompatActivity(),
|
||||||
|
|
||||||
mDetector = GestureDetectorCompat(this, this)
|
mDetector = GestureDetectorCompat(this, this)
|
||||||
mDetector.setOnDoubleTapListener(this)
|
mDetector.setOnDoubleTapListener(this)
|
||||||
|
|
||||||
|
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -116,7 +125,6 @@ class MainActivity : AppCompatActivity(),
|
||||||
|
|
||||||
override fun onFling(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean {
|
override fun onFling(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean {
|
||||||
|
|
||||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
|
||||||
val width = displayMetrics.widthPixels
|
val width = displayMetrics.widthPixels
|
||||||
val height = displayMetrics.heightPixels
|
val height = displayMetrics.heightPixels
|
||||||
|
|
||||||
|
@ -139,10 +147,12 @@ class MainActivity : AppCompatActivity(),
|
||||||
// Tooltip
|
// Tooltip
|
||||||
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
|
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
|
||||||
when(settingsIconShown) {
|
when(settingsIconShown) {
|
||||||
true -> hideSettingsIcon()
|
true -> {
|
||||||
|
hideSettingsIcon()
|
||||||
|
}
|
||||||
false -> showSettingsIcon()
|
false -> showSettingsIcon()
|
||||||
}
|
}
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSettingsIcon(){
|
private fun showSettingsIcon(){
|
||||||
|
@ -165,15 +175,15 @@ class MainActivity : AppCompatActivity(),
|
||||||
fun settingsIconOnTouch(view: View){ openSettings() }
|
fun settingsIconOnTouch(view: View){ openSettings() }
|
||||||
|
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
return if (mDetector.onTouchEvent(event)) { true } else { super.onTouchEvent(event) }
|
return if (mDetector.onTouchEvent(event)) { false } else { super.onTouchEvent(event) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Remove those. For now they are necessary
|
/* TODO: Remove those. For now they are necessary
|
||||||
* because this inherits from GestureDetector.OnGestureListener */
|
* because this inherits from GestureDetector.OnGestureListener */
|
||||||
override fun onDoubleTap(event: MotionEvent): Boolean { return true }
|
override fun onDoubleTap(event: MotionEvent): Boolean { return false }
|
||||||
override fun onDoubleTapEvent(event: MotionEvent): Boolean { return true }
|
override fun onDoubleTapEvent(event: MotionEvent): Boolean { return false }
|
||||||
override fun onDown(event: MotionEvent): Boolean { return true }
|
override fun onDown(event: MotionEvent): Boolean { return false }
|
||||||
override fun onScroll(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { return true }
|
override fun onScroll(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { return false }
|
||||||
override fun onShowPress(event: MotionEvent) {}
|
override fun onShowPress(event: MotionEvent) {}
|
||||||
override fun onSingleTapUp(event: MotionEvent): Boolean { return true }
|
override fun onSingleTapUp(event: MotionEvent): Boolean { return false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
import com.finnmglas.launcher.ui.main.SectionsPagerAdapter
|
import com.finnmglas.launcher.ui.main.SectionsPagerAdapter
|
||||||
import com.google.android.material.tabs.TabLayout
|
import com.google.android.material.tabs.TabLayout
|
||||||
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
|
|
||||||
|
|
||||||
class SettingsActivity : AppCompatActivity() {
|
class SettingsActivity : AppCompatActivity() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:custom="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/container"
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -36,20 +37,20 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<com.finnmglas.launcher.FontAwesomeSolid
|
<com.finnmglas.launcher.FontAwesome
|
||||||
android:id="@+id/settingstooltip"
|
android:id="@+id/settingstooltip"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:onClick="settingsIconOnTouch"
|
android:onClick="settingsIconOnTouch"
|
||||||
android:text="@string/fas_settings"
|
android:text="@string/fas_settings"
|
||||||
android:textColor="#ccc"
|
android:textColor="#999"
|
||||||
android:textSize="36sp"
|
android:textSize="36sp"
|
||||||
android:visibility="invisible"
|
android:visibility="invisible"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.95"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintVertical_bias="0.95" />
|
app:layout_constraintVertical_bias="0.95"
|
||||||
|
custom:type="solid" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:custom="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/container"
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -13,10 +14,9 @@
|
||||||
android:background="@color/colorPrimaryDark"
|
android:background="@color/colorPrimaryDark"
|
||||||
android:theme="@style/AppTheme.AppBarOverlay">
|
android:theme="@style/AppTheme.AppBarOverlay">
|
||||||
|
|
||||||
<LinearLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
|
@ -27,26 +27,36 @@
|
||||||
android:padding="@dimen/appbar_padding"
|
android:padding="@dimen/appbar_padding"
|
||||||
android:text="@string/settings_title"
|
android:text="@string/settings_title"
|
||||||
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
|
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
|
||||||
android:textSize="30sp" />
|
android:textSize="30sp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
<com.finnmglas.launcher.FontAwesomeSolid
|
<com.finnmglas.launcher.FontAwesome
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/close_settings"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:gravity="center|right"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:gravity="center"
|
||||||
android:includeFontPadding="true"
|
android:includeFontPadding="true"
|
||||||
android:onClick="backHome"
|
android:onClick="backHome"
|
||||||
android:paddingLeft="16sp"
|
android:paddingLeft="16sp"
|
||||||
android:paddingRight="16sp"
|
android:paddingRight="16sp"
|
||||||
android:text="@string/fas_close_window"
|
android:text="@string/fa_close_window"
|
||||||
android:textColor="#ffffff"
|
android:textColor="#ffffff"
|
||||||
android:textSize="22sp" />
|
android:textSize="22sp"
|
||||||
</LinearLayout>
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
custom:type="solid" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<com.google.android.material.tabs.TabLayout
|
||||||
android:id="@+id/tabs"
|
android:id="@+id/tabs"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/colorPrimaryDark" />
|
android:background="?attr/colorPrimaryDark" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<androidx.viewpager.widget.ViewPager
|
<androidx.viewpager.widget.ViewPager
|
||||||
|
|
8
app/src/main/res/values/attrs.xml
Normal file
8
app/src/main/res/values/attrs.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!-- This declares attributes for the FontAwesome TextView -->
|
||||||
|
<resources>
|
||||||
|
<declare-styleable name="FontAwesome">
|
||||||
|
<attr name="type" format="string" />
|
||||||
|
</declare-styleable>
|
||||||
|
</resources>
|
|
@ -1,11 +1,21 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<!-- icons that can be used with type="solid" -->
|
||||||
<string name="fas_bars" translatable="false"></string>
|
<string name="fas_bars" translatable="false"></string>
|
||||||
<string name="fas_home" translatable="false"></string>
|
<string name="fas_home" translatable="false"></string>
|
||||||
<string name="fas_globe" translatable="false"></string>
|
|
||||||
<string name="fas_settings" translatable="false"></string>
|
<string name="fas_settings" translatable="false"></string>
|
||||||
<string name="fas_close_window" translatable="false"></string>
|
<string name="fas_globe" translatable="false"></string>
|
||||||
<string name="fas_star" translatable="false"></string>
|
<string name="fas_ad" translatable="false"></string>
|
||||||
|
<string name="fas_backspace" translatable="false"></string>
|
||||||
|
<string name="fas_calendar" translatable="false"></string>
|
||||||
|
|
||||||
<string name="far_star" translatable="false"></string>
|
<!-- icons that can be used with type="brands" -->
|
||||||
|
<string name="fab_apple" translatable="false"></string>
|
||||||
|
<string name="fab_instagram" translatable="false"></string>
|
||||||
|
|
||||||
|
<!-- icons that can be used with type="solid" and type="regular" -->
|
||||||
|
<string name="fa_close_window" translatable="false"></string>
|
||||||
|
<string name="fa_square" translatable="false"></string>
|
||||||
|
<string name="fa_star" translatable="false"></string>
|
||||||
|
<string name="fa_clipboard" translatable="false"></string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Reference in a new issue