mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +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 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 {
|
||||
constructor(
|
||||
context: Context?,
|
||||
attrs: AttributeSet?,
|
||||
defStyle: Int
|
||||
) : super(context, attrs, defStyle) {
|
||||
init()
|
||||
class FontAwesome : AppCompatTextView {
|
||||
|
||||
var type = "" // "solid", "regular" or "brand"
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int)
|
||||
: super(context, attrs, defStyle) { init(attrs) }
|
||||
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(
|
||||
context,
|
||||
attrs
|
||||
) {
|
||||
init()
|
||||
}
|
||||
// Useful if you want to change between a regular and solid icon (example: star)
|
||||
fun setIconType(iconType : String){
|
||||
type = iconType
|
||||
|
||||
constructor(context: Context?) : super(context) {
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
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"
|
||||
)
|
||||
typeface = when (type) {
|
||||
"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")
|
||||
else -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-solid-900.ttf")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,13 @@ class MainActivity : AppCompatActivity(),
|
|||
|
||||
// Start by showing the settings icon
|
||||
showSettingsIcon()
|
||||
|
||||
// As older APIs somehow do not recognize the xml defined onClick
|
||||
findViewById<View>(R.id.settingstooltip).setOnClickListener() {
|
||||
openSettings()
|
||||
true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onStart(){
|
||||
|
@ -75,6 +82,8 @@ class MainActivity : AppCompatActivity(),
|
|||
|
||||
mDetector = GestureDetectorCompat(this, this)
|
||||
mDetector.setOnDoubleTapListener(this)
|
||||
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -116,7 +125,6 @@ class MainActivity : AppCompatActivity(),
|
|||
|
||||
override fun onFling(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean {
|
||||
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
val width = displayMetrics.widthPixels
|
||||
val height = displayMetrics.heightPixels
|
||||
|
||||
|
@ -139,10 +147,12 @@ class MainActivity : AppCompatActivity(),
|
|||
// Tooltip
|
||||
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
|
||||
when(settingsIconShown) {
|
||||
true -> hideSettingsIcon()
|
||||
true -> {
|
||||
hideSettingsIcon()
|
||||
}
|
||||
false -> showSettingsIcon()
|
||||
}
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
private fun showSettingsIcon(){
|
||||
|
@ -165,15 +175,15 @@ class MainActivity : AppCompatActivity(),
|
|||
fun settingsIconOnTouch(view: View){ openSettings() }
|
||||
|
||||
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
|
||||
* because this inherits from GestureDetector.OnGestureListener */
|
||||
override fun onDoubleTap(event: MotionEvent): Boolean { return true }
|
||||
override fun onDoubleTapEvent(event: MotionEvent): Boolean { return true }
|
||||
override fun onDown(event: MotionEvent): Boolean { return true }
|
||||
override fun onScroll(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { return true }
|
||||
override fun onDoubleTap(event: MotionEvent): Boolean { return false }
|
||||
override fun onDoubleTapEvent(event: MotionEvent): Boolean { return false }
|
||||
override fun onDown(event: MotionEvent): Boolean { return false }
|
||||
override fun onScroll(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { return false }
|
||||
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 com.finnmglas.launcher.ui.main.SectionsPagerAdapter
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -36,20 +37,20 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.finnmglas.launcher.FontAwesomeSolid
|
||||
<com.finnmglas.launcher.FontAwesome
|
||||
android:id="@+id/settingstooltip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="settingsIconOnTouch"
|
||||
android:text="@string/fas_settings"
|
||||
android:textColor="#ccc"
|
||||
android:textColor="#999"
|
||||
android:textSize="36sp"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.95"
|
||||
app:layout_constraintStart_toStartOf="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>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -13,10 +14,9 @@
|
|||
android:background="@color/colorPrimaryDark"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<LinearLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
|
@ -27,26 +27,36 @@
|
|||
android:padding="@dimen/appbar_padding"
|
||||
android:text="@string/settings_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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center|right"
|
||||
<com.finnmglas.launcher.FontAwesome
|
||||
android:id="@+id/close_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:gravity="center"
|
||||
android:includeFontPadding="true"
|
||||
android:onClick="backHome"
|
||||
android:paddingLeft="16sp"
|
||||
android:paddingRight="16sp"
|
||||
android:text="@string/fas_close_window"
|
||||
android:text="@string/fa_close_window"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="22sp" />
|
||||
</LinearLayout>
|
||||
android:textSize="22sp"
|
||||
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
|
||||
android:id="@+id/tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimaryDark" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<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"?>
|
||||
<resources>
|
||||
<!-- icons that can be used with type="solid" -->
|
||||
<string name="fas_bars" 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_close_window" translatable="false"></string>
|
||||
<string name="fas_star" translatable="false"></string>
|
||||
<string name="fas_globe" 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>
|
||||
|
|
Loading…
Add table
Reference in a new issue