diff --git a/app/src/main/java/com/finnmglas/launcher/FontAwesome.kt b/app/src/main/java/com/finnmglas/launcher/FontAwesome.kt index 762d29a..7a4627a 100644 --- a/app/src/main/java/com/finnmglas/launcher/FontAwesome.kt +++ b/app/src/main/java/com/finnmglas/launcher/FontAwesome.kt @@ -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") + } } } diff --git a/app/src/main/java/com/finnmglas/launcher/MainActivity.kt b/app/src/main/java/com/finnmglas/launcher/MainActivity.kt index f388c06..2af0b7c 100644 --- a/app/src/main/java/com/finnmglas/launcher/MainActivity.kt +++ b/app/src/main/java/com/finnmglas/launcher/MainActivity.kt @@ -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(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 } } diff --git a/app/src/main/java/com/finnmglas/launcher/SettingsActivity.kt b/app/src/main/java/com/finnmglas/launcher/SettingsActivity.kt index df8e967..54acf61 100644 --- a/app/src/main/java/com/finnmglas/launcher/SettingsActivity.kt +++ b/app/src/main/java/com/finnmglas/launcher/SettingsActivity.kt @@ -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() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 232fd1e..7d4be6e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,6 @@ - + app:layout_constraintVertical_bias="0.95" + custom:type="solid" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index fc6ff88..de26486 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,6 +1,7 @@ - + android:layout_height="match_parent"> + android:textSize="30sp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> - - + android:textSize="22sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + custom:type="solid" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/icons.xml b/app/src/main/res/values/icons.xml index 3243f56..44125b8 100644 --- a/app/src/main/res/values/icons.xml +++ b/app/src/main/res/values/icons.xml @@ -1,11 +1,21 @@ + - - - + + + + - + + + + + + + + +