mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-06-05 21:59:31 +02:00
use custom views as tablayout items
This commit is contained in:
@@ -62,7 +62,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:4b8a3568df'
|
implementation 'com.github.SimpleMobileTools:Simple-Commons:0834a977e4'
|
||||||
implementation 'org.greenrobot:eventbus:3.3.1'
|
implementation 'org.greenrobot:eventbus:3.3.1'
|
||||||
implementation 'com.github.Armen101:AudioRecordView:1.0.4'
|
implementation 'com.github.Armen101:AudioRecordView:1.0.4'
|
||||||
implementation 'androidx.documentfile:documentfile:1.0.1'
|
implementation 'androidx.documentfile:documentfile:1.0.1'
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
package com.simplemobiletools.voicerecorder.activities
|
package com.simplemobiletools.voicerecorder.activities
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.drawable.ColorDrawable
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.models.FAQItem
|
import com.simplemobiletools.commons.models.FAQItem
|
||||||
@@ -52,10 +53,14 @@ class MainActivity : SimpleActivity() {
|
|||||||
setupTabColors()
|
setupTabColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
config.lastUsedViewPagerPage = view_pager.currentItem
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
getPagerAdapter()?.onDestroy()
|
getPagerAdapter()?.onDestroy()
|
||||||
config.lastUsedViewPagerPage = view_pager.currentItem
|
|
||||||
|
|
||||||
Intent(this@MainActivity, RecorderService::class.java).apply {
|
Intent(this@MainActivity, RecorderService::class.java).apply {
|
||||||
action = STOP_AMPLITUDE_UPDATE
|
action = STOP_AMPLITUDE_UPDATE
|
||||||
@@ -96,36 +101,51 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupViewPager() {
|
private fun setupViewPager() {
|
||||||
|
main_tabs_holder.removeAllTabs()
|
||||||
|
main_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
|
||||||
|
customView?.findViewById<ImageView>(R.id.tab_icon)?.setImageDrawable(getDrawable(R.drawable.ic_microphone_vector))
|
||||||
|
customView?.findViewById<TextView>(R.id.tab_label)?.setText(R.string.recorder)
|
||||||
|
main_tabs_holder.addTab(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
main_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
|
||||||
|
customView?.findViewById<ImageView>(R.id.tab_icon)?.setImageDrawable(getDrawable(R.drawable.ic_headset_vector))
|
||||||
|
customView?.findViewById<TextView>(R.id.tab_label)?.setText(R.string.player)
|
||||||
|
main_tabs_holder.addTab(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
main_tabs_holder.onTabSelectionChanged(
|
||||||
|
tabUnselectedAction = {
|
||||||
|
it.customView?.findViewById<ImageView>(R.id.tab_icon)?.applyColorFilter(getProperTextColor())
|
||||||
|
it.customView?.findViewById<TextView>(R.id.tab_label)?.setTextColor(getProperTextColor())
|
||||||
|
},
|
||||||
|
tabSelectedAction = {
|
||||||
|
view_pager.currentItem = it.position
|
||||||
|
it.customView?.findViewById<ImageView>(R.id.tab_icon)?.applyColorFilter(getProperPrimaryColor())
|
||||||
|
it.customView?.findViewById<TextView>(R.id.tab_label)?.setTextColor(getProperPrimaryColor())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
view_pager.adapter = ViewPagerAdapter(this)
|
view_pager.adapter = ViewPagerAdapter(this)
|
||||||
view_pager.onPageChangeListener {
|
view_pager.onPageChangeListener {
|
||||||
main_tabs_holder.getTabAt(it)?.select()
|
main_tabs_holder.getTabAt(it)?.select()
|
||||||
(view_pager.adapter as ViewPagerAdapter).finishActMode()
|
(view_pager.adapter as ViewPagerAdapter).finishActMode()
|
||||||
}
|
}
|
||||||
view_pager.currentItem = config.lastUsedViewPagerPage
|
view_pager.currentItem = config.lastUsedViewPagerPage
|
||||||
|
main_tabs_holder.getTabAt(config.lastUsedViewPagerPage)?.select()
|
||||||
main_tabs_holder.setTabTextColors(
|
|
||||||
getProperTextColor(),
|
|
||||||
getProperPrimaryColor()
|
|
||||||
)
|
|
||||||
|
|
||||||
main_tabs_holder.onTabSelectionChanged(
|
|
||||||
tabUnselectedAction = {
|
|
||||||
it.icon?.applyColorFilter(getProperTextColor())
|
|
||||||
},
|
|
||||||
tabSelectedAction = {
|
|
||||||
view_pager.currentItem = it.position
|
|
||||||
it.icon?.applyColorFilter(getProperPrimaryColor())
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPagerAdapter() = (view_pager.adapter as? ViewPagerAdapter)
|
private fun getPagerAdapter() = (view_pager.adapter as? ViewPagerAdapter)
|
||||||
|
|
||||||
private fun setupTabColors() {
|
private fun setupTabColors() {
|
||||||
main_tabs_holder.apply {
|
main_tabs_holder.getTabAt(getInactiveTabIndex())?.customView?.apply {
|
||||||
background = ColorDrawable(getProperBackgroundColor())
|
findViewById<ImageView>(R.id.tab_icon)?.applyColorFilter(getProperTextColor())
|
||||||
getTabAt(view_pager.currentItem)?.icon?.applyColorFilter(getProperPrimaryColor())
|
findViewById<TextView>(R.id.tab_label)?.setTextColor(getProperTextColor())
|
||||||
getTabAt(getInactiveTabIndex())?.icon?.applyColorFilter(getProperTextColor())
|
}
|
||||||
|
|
||||||
|
main_tabs_holder.getTabAt(view_pager.currentItem)?.customView?.apply {
|
||||||
|
findViewById<ImageView>(R.id.tab_icon)?.applyColorFilter(getProperPrimaryColor())
|
||||||
|
findViewById<TextView>(R.id.tab_label)?.setTextColor(getProperPrimaryColor())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,27 +16,9 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:elevation="8dp"
|
|
||||||
app:tabIndicator="@null"
|
app:tabIndicator="@null"
|
||||||
app:tabMinWidth="150dp"
|
app:tabMinWidth="150dp"
|
||||||
app:tabRippleColor="@null"
|
app:tabRippleColor="@null">
|
||||||
app:tabTextAppearance="@style/TabLayoutStyle">
|
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabItem
|
|
||||||
android:id="@+id/tab_recorder"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:contentDescription="@string/recorder"
|
|
||||||
android:icon="@drawable/ic_microphone_vector"
|
|
||||||
android:text="@string/recorder" />
|
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabItem
|
|
||||||
android:id="@+id/tab_player"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:contentDescription="@string/player"
|
|
||||||
android:icon="@drawable/ic_headset_vector"
|
|
||||||
android:text="@string/player" />
|
|
||||||
|
|
||||||
</com.google.android.material.tabs.TabLayout>
|
</com.google.android.material.tabs.TabLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
28
app/src/main/res/layout/bottom_tablayout_item.xml
Normal file
28
app/src/main/res/layout/bottom_tablayout_item.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/medium_margin"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/tab_icon"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
tools:src="@drawable/ic_headset_vector" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tab_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
android:paddingTop="@dimen/small_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:textSize="@dimen/smaller_text_size"
|
||||||
|
tools:text="@string/player" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@@ -135,7 +135,6 @@
|
|||||||
android:layout_marginBottom="@dimen/big_margin"
|
android:layout_marginBottom="@dimen/big_margin"
|
||||||
android:background="@drawable/circle_background"
|
android:background="@drawable/circle_background"
|
||||||
android:contentDescription="@string/playpause"
|
android:contentDescription="@string/playpause"
|
||||||
android:elevation="@dimen/medium_margin"
|
|
||||||
android:padding="@dimen/activity_margin"
|
android:padding="@dimen/activity_margin"
|
||||||
android:src="@drawable/ic_play_vector" />
|
android:src="@drawable/ic_play_vector" />
|
||||||
|
|
||||||
|
@@ -39,7 +39,6 @@
|
|||||||
android:layout_height="@dimen/toggle_recording_button_size"
|
android:layout_height="@dimen/toggle_recording_button_size"
|
||||||
android:layout_marginBottom="@dimen/big_margin"
|
android:layout_marginBottom="@dimen/big_margin"
|
||||||
android:background="@drawable/circle_background"
|
android:background="@drawable/circle_background"
|
||||||
android:elevation="@dimen/medium_margin"
|
|
||||||
android:padding="@dimen/normal_margin"
|
android:padding="@dimen/normal_margin"
|
||||||
android:src="@drawable/ic_microphone_vector"
|
android:src="@drawable/ic_microphone_vector"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
@@ -52,7 +51,6 @@
|
|||||||
android:layout_height="@dimen/fab_size"
|
android:layout_height="@dimen/fab_size"
|
||||||
android:layout_marginBottom="@dimen/big_margin"
|
android:layout_marginBottom="@dimen/big_margin"
|
||||||
android:background="@drawable/circle_background"
|
android:background="@drawable/circle_background"
|
||||||
android:elevation="@dimen/medium_margin"
|
|
||||||
android:padding="@dimen/activity_margin"
|
android:padding="@dimen/activity_margin"
|
||||||
android:src="@drawable/ic_pause_vector"
|
android:src="@drawable/ic_pause_vector"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
@@ -11,7 +11,4 @@
|
|||||||
<item name="android:windowNoDisplay">true</item>
|
<item name="android:windowNoDisplay">true</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="TabLayoutStyle" parent="Base.Widget.Design.TabLayout">
|
|
||||||
<item name="android:textSize">@dimen/smaller_text_size</item>
|
|
||||||
</style>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user