Converted RetroUtil to Kotlin
This commit is contained in:
parent
6cc1ba746a
commit
e605b8c695
23 changed files with 175 additions and 175 deletions
|
@ -96,7 +96,6 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
navController.addOnDestinationChangedListener { _, destination, _ ->
|
navController.addOnDestinationChangedListener { _, destination, _ ->
|
||||||
val start = System.currentTimeMillis()
|
|
||||||
if (destination.id == navGraph.startDestinationId) {
|
if (destination.id == navGraph.startDestinationId) {
|
||||||
currentFragment(R.id.fragment_container)?.enterTransition = null
|
currentFragment(R.id.fragment_container)?.enterTransition = null
|
||||||
}
|
}
|
||||||
|
@ -117,7 +116,6 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
|
||||||
animate = true
|
animate = true
|
||||||
) // Hide Bottom Navigation Bar
|
) // Hide Bottom Navigation Bar
|
||||||
}
|
}
|
||||||
showToast("Time : ${System.currentTimeMillis() - start}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,8 +132,8 @@ class SongFileAdapter(
|
||||||
return dataSet[position]
|
return dataSet[position]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(`object`: File): String {
|
override fun getName(model: File): String {
|
||||||
return getFileTitle(`object`)
|
return getFileTitle(model)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMultipleItemAction(menuItem: MenuItem, selection: List<File>) {
|
override fun onMultipleItemAction(menuItem: MenuItem, selection: List<File>) {
|
||||||
|
|
|
@ -135,8 +135,8 @@ open class AlbumAdapter(
|
||||||
return dataSet[position]
|
return dataSet[position]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(album: Album): String {
|
override fun getName(model: Album): String {
|
||||||
return album.title
|
return model.title
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMultipleItemAction(
|
override fun onMultipleItemAction(
|
||||||
|
|
|
@ -132,8 +132,8 @@ class ArtistAdapter(
|
||||||
return dataSet[position]
|
return dataSet[position]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(artist: Artist): String {
|
override fun getName(model: Artist): String {
|
||||||
return artist.name
|
return model.name
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMultipleItemAction(
|
override fun onMultipleItemAction(
|
||||||
|
|
|
@ -64,9 +64,8 @@ abstract class AbsMultiSelectAdapter<V : RecyclerView.ViewHolder?, I>(
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun getIdentifier(position: Int): I?
|
protected abstract fun getIdentifier(position: Int): I?
|
||||||
protected open fun getName(i: I): String? {
|
|
||||||
return i.toString()
|
protected abstract fun getName(model: I): String?
|
||||||
}
|
|
||||||
|
|
||||||
protected fun isChecked(identifier: I): Boolean {
|
protected fun isChecked(identifier: I): Boolean {
|
||||||
return checked.contains(identifier)
|
return checked.contains(identifier)
|
||||||
|
|
|
@ -120,8 +120,8 @@ class PlaylistAdapter(
|
||||||
return dataSet[position]
|
return dataSet[position]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(playlist: PlaylistWithSongs): String {
|
override fun getName(model: PlaylistWithSongs): String {
|
||||||
return playlist.playlistEntity.playlistName
|
return model.playlistEntity.playlistName
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMultipleItemAction(menuItem: MenuItem, selection: List<PlaylistWithSongs>) {
|
override fun onMultipleItemAction(menuItem: MenuItem, selection: List<PlaylistWithSongs>) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ class ShuffleButtonSongAdapter(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.onBindViewHolder(holder, position - 1)
|
super.onBindViewHolder(holder, position - 1)
|
||||||
val landscape = RetroUtil.isLandscape()
|
val landscape = RetroUtil.isLandscape
|
||||||
if ((PreferenceUtil.songGridSize > 2 && !landscape) || (PreferenceUtil.songGridSizeLand > 5 && landscape)) {
|
if ((PreferenceUtil.songGridSize > 2 && !landscape) || (PreferenceUtil.songGridSizeLand > 5 && landscape)) {
|
||||||
holder.menu?.isVisible = false
|
holder.menu?.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ open class SongAdapter(
|
||||||
holder.text?.text = getSongText(song)
|
holder.text?.text = getSongText(song)
|
||||||
holder.text2?.text = getSongText(song)
|
holder.text2?.text = getSongText(song)
|
||||||
loadAlbumCover(song, holder)
|
loadAlbumCover(song, holder)
|
||||||
val landscape = RetroUtil.isLandscape()
|
val landscape = RetroUtil.isLandscape
|
||||||
if ((PreferenceUtil.songGridSize > 2 && !landscape) || (PreferenceUtil.songGridSizeLand > 5 && landscape)) {
|
if ((PreferenceUtil.songGridSize > 2 && !landscape) || (PreferenceUtil.songGridSizeLand > 5 && landscape)) {
|
||||||
holder.menu?.isVisible = false
|
holder.menu?.isVisible = false
|
||||||
}
|
}
|
||||||
|
@ -149,8 +149,8 @@ open class SongAdapter(
|
||||||
return dataSet[position]
|
return dataSet[position]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(song: Song): String {
|
override fun getName(model: Song): String {
|
||||||
return song.title
|
return model.title
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMultipleItemAction(menuItem: MenuItem, selection: List<Song>) {
|
override fun onMultipleItemAction(menuItem: MenuItem, selection: List<Song>) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package code.name.monkey.retromusic.extensions
|
package code.name.monkey.retromusic.extensions
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
|
||||||
|
@ -10,4 +11,8 @@ fun Context.showToast(@StringRes stringRes: Int, duration: Int = Toast.LENGTH_SH
|
||||||
|
|
||||||
fun Context.showToast(message: String, duration: Int = Toast.LENGTH_SHORT) {
|
fun Context.showToast(message: String, duration: Int = Toast.LENGTH_SHORT) {
|
||||||
Toast.makeText(this, message, duration).show()
|
Toast.makeText(this, message, duration).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val Context.isLandscape: Boolean get() = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||||
|
|
||||||
|
val Context.isTablet: Boolean get() = resources.configuration.smallestScreenWidthDp >= 600
|
|
@ -8,6 +8,6 @@ fun WindowInsetsCompat?.safeGetBottomInsets(): Int {
|
||||||
return if (PreferenceUtil.isFullScreenMode) {
|
return if (PreferenceUtil.isFullScreenMode) {
|
||||||
return 0
|
return 0
|
||||||
} else {
|
} else {
|
||||||
this?.getInsets(WindowInsetsCompat.Type.systemBars())?.bottom ?: RetroUtil.getNavigationBarHeight()
|
this?.getInsets(WindowInsetsCompat.Type.systemBars())?.bottom ?: RetroUtil.navigationBarHeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridL
|
||||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
super.onCreateMenu(menu, inflater)
|
super.onCreateMenu(menu, inflater)
|
||||||
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
||||||
if (RetroUtil.isLandscape()) {
|
if (RetroUtil.isLandscape) {
|
||||||
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
||||||
}
|
}
|
||||||
setUpGridSizeMenu(gridSizeItem.subMenu)
|
setUpGridSizeMenu(gridSizeItem.subMenu)
|
||||||
|
|
|
@ -171,7 +171,7 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment<ArtistAdapter, Gri
|
||||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
super.onCreateMenu(menu, inflater)
|
super.onCreateMenu(menu, inflater)
|
||||||
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
||||||
if (RetroUtil.isLandscape()) {
|
if (RetroUtil.isLandscape) {
|
||||||
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
||||||
}
|
}
|
||||||
setUpGridSizeMenu(gridSizeItem.subMenu)
|
setUpGridSizeMenu(gridSizeItem.subMenu)
|
||||||
|
|
|
@ -116,8 +116,8 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
override fun onBackupMenuClicked(file: File, item: MenuItem): Boolean {
|
override fun onBackupMenuClicked(file: File, menuItem: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.action_delete -> {
|
R.id.action_delete -> {
|
||||||
try {
|
try {
|
||||||
file.delete()
|
file.delete()
|
||||||
|
|
|
@ -28,7 +28,7 @@ abstract class AbsRecyclerViewCustomGridSizeFragment<A : RecyclerView.Adapter<*>
|
||||||
private var sortOrder: String? = null
|
private var sortOrder: String? = null
|
||||||
private var currentLayoutRes: Int = 0
|
private var currentLayoutRes: Int = 0
|
||||||
private val isLandscape: Boolean
|
private val isLandscape: Boolean
|
||||||
get() = RetroUtil.isLandscape()
|
get() = RetroUtil.isLandscape
|
||||||
|
|
||||||
val maxGridSize: Int
|
val maxGridSize: Int
|
||||||
get() = if (isLandscape) {
|
get() = if (isLandscape) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ GenresFragment : AbsRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(),
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createLayoutManager(): LinearLayoutManager {
|
override fun createLayoutManager(): LinearLayoutManager {
|
||||||
return if (RetroUtil.isLandscape()) {
|
return if (RetroUtil.isLandscape) {
|
||||||
GridLayoutManager(activity, 4)
|
GridLayoutManager(activity, 4)
|
||||||
} else {
|
} else {
|
||||||
GridLayoutManager(activity, 2)
|
GridLayoutManager(activity, 2)
|
||||||
|
|
|
@ -64,9 +64,8 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
private var showClearHistoryOption = false
|
private var showClearHistoryOption = false
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
_binding = FragmentPlaylistDetailBinding.bind(view)
|
|
||||||
when (args.type) {
|
when (args.type) {
|
||||||
TOP_ARTISTS,
|
TOP_ARTISTS,
|
||||||
RECENT_ARTISTS,
|
RECENT_ARTISTS,
|
||||||
|
@ -81,6 +80,13 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Y, false)
|
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Y, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
_binding = FragmentPlaylistDetailBinding.bind(view)
|
||||||
|
postponeEnterTransition()
|
||||||
|
view.doOnPreDraw { startPostponedEnterTransition() }
|
||||||
mainActivity.setSupportActionBar(binding.toolbar)
|
mainActivity.setSupportActionBar(binding.toolbar)
|
||||||
binding.progressIndicator.hide()
|
binding.progressIndicator.hide()
|
||||||
when (args.type) {
|
when (args.type) {
|
||||||
|
@ -106,8 +112,6 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
})
|
})
|
||||||
binding.appBarLayout.statusBarForeground =
|
binding.appBarLayout.statusBarForeground =
|
||||||
MaterialShapeDrawable.createWithElevationOverlay(requireContext())
|
MaterialShapeDrawable.createWithElevationOverlay(requireContext())
|
||||||
postponeEnterTransition()
|
|
||||||
view.doOnPreDraw { startPostponedEnterTransition() }
|
|
||||||
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
|
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
|
||||||
if (!handleBackPress()) {
|
if (!handleBackPress()) {
|
||||||
remove()
|
remove()
|
||||||
|
@ -232,10 +236,10 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
GridLayoutManager(requireContext(), gridCount(), GridLayoutManager.VERTICAL, false)
|
GridLayoutManager(requireContext(), gridCount(), GridLayoutManager.VERTICAL, false)
|
||||||
|
|
||||||
private fun gridCount(): Int {
|
private fun gridCount(): Int {
|
||||||
if (RetroUtil.isTablet()) {
|
if (RetroUtil.isTablet) {
|
||||||
return if (RetroUtil.isLandscape()) 6 else 4
|
return if (RetroUtil.isLandscape) 6 else 4
|
||||||
}
|
}
|
||||||
return if (RetroUtil.isLandscape()) 4 else 2
|
return if (RetroUtil.isLandscape) 4 else 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(R.layout.fragment_mini_p
|
||||||
view.setOnTouchListener(FlingPlayBackController(requireContext()))
|
view.setOnTouchListener(FlingPlayBackController(requireContext()))
|
||||||
setUpMiniPlayer()
|
setUpMiniPlayer()
|
||||||
|
|
||||||
if (RetroUtil.isTablet()) {
|
if (RetroUtil.isTablet) {
|
||||||
binding.actionNext.show()
|
binding.actionNext.show()
|
||||||
binding.actionPrevious.show()
|
binding.actionPrevious.show()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -205,7 +205,6 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
println("OK")
|
|
||||||
var wasExpanded = false
|
var wasExpanded = false
|
||||||
if (getQueuePanel().state == STATE_EXPANDED) {
|
if (getQueuePanel().state == STATE_EXPANDED) {
|
||||||
wasExpanded = getQueuePanel().state == STATE_EXPANDED
|
wasExpanded = getQueuePanel().state == STATE_EXPANDED
|
||||||
|
|
|
@ -74,7 +74,7 @@ class PlaylistsFragment :
|
||||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
super.onCreateMenu(menu, inflater)
|
super.onCreateMenu(menu, inflater)
|
||||||
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
||||||
if (RetroUtil.isLandscape()) {
|
if (RetroUtil.isLandscape) {
|
||||||
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
||||||
}
|
}
|
||||||
setupGridSizeMenu(gridSizeItem.subMenu)
|
setupGridSizeMenu(gridSizeItem.subMenu)
|
||||||
|
@ -109,7 +109,7 @@ class PlaylistsFragment :
|
||||||
7 -> gridSizeMenu.findItem(R.id.action_grid_size_7).isChecked = true
|
7 -> gridSizeMenu.findItem(R.id.action_grid_size_7).isChecked = true
|
||||||
8 -> gridSizeMenu.findItem(R.id.action_grid_size_8).isChecked = true
|
8 -> gridSizeMenu.findItem(R.id.action_grid_size_8).isChecked = true
|
||||||
}
|
}
|
||||||
val gridSize = if (RetroUtil.isLandscape()) 4 else 2
|
val gridSize = if (RetroUtil.isLandscape) 4 else 2
|
||||||
if (gridSize < 8) {
|
if (gridSize < 8) {
|
||||||
gridSizeMenu.findItem(R.id.action_grid_size_8).isVisible = false
|
gridSizeMenu.findItem(R.id.action_grid_size_8).isVisible = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ class SongsFragment : AbsRecyclerViewCustomGridSizeFragment<SongAdapter, GridLay
|
||||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
super.onCreateMenu(menu, inflater)
|
super.onCreateMenu(menu, inflater)
|
||||||
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
val gridSizeItem: MenuItem = menu.findItem(R.id.action_grid_size)
|
||||||
if (RetroUtil.isLandscape()) {
|
if (RetroUtil.isLandscape) {
|
||||||
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
gridSizeItem.setTitle(R.string.action_grid_size_land)
|
||||||
}
|
}
|
||||||
setUpGridSizeMenu(gridSizeItem.subMenu)
|
setUpGridSizeMenu(gridSizeItem.subMenu)
|
||||||
|
|
|
@ -11,149 +11,144 @@
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
package code.name.monkey.retromusic.util
|
||||||
|
|
||||||
package code.name.monkey.retromusic.util;
|
import android.content.Context
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.content.res.Resources
|
||||||
|
import code.name.monkey.retromusic.App.Companion.getContext
|
||||||
|
import android.view.WindowManager
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
|
import android.content.res.Resources.Theme
|
||||||
|
import android.graphics.Point
|
||||||
|
import android.view.Display
|
||||||
|
import androidx.core.content.res.ResourcesCompat
|
||||||
|
import androidx.core.view.DisplayCompat
|
||||||
|
import java.lang.Exception
|
||||||
|
import java.net.InetAddress
|
||||||
|
import java.net.NetworkInterface
|
||||||
|
import java.text.DecimalFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
import android.content.Context;
|
object RetroUtil {
|
||||||
import android.content.res.Configuration;
|
fun formatValue(value: Float): String {
|
||||||
import android.content.res.Resources;
|
var value = value
|
||||||
import android.graphics.Point;
|
val arr = arrayOf("", "K", "M", "B", "T", "P", "E")
|
||||||
import android.graphics.drawable.Drawable;
|
var index = 0
|
||||||
import android.view.Display;
|
while (value / 1000 >= 1) {
|
||||||
import android.view.WindowManager;
|
value /= 1000
|
||||||
|
index++
|
||||||
import androidx.annotation.ColorInt;
|
}
|
||||||
import androidx.annotation.DrawableRes;
|
val decimalFormat = DecimalFormat("#.##")
|
||||||
import androidx.annotation.NonNull;
|
return String.format("%s %s", decimalFormat.format(value.toDouble()), arr[index])
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import code.name.monkey.appthemehelper.util.TintHelper;
|
|
||||||
import code.name.monkey.retromusic.App;
|
|
||||||
|
|
||||||
public class RetroUtil {
|
|
||||||
|
|
||||||
public static String formatValue(float value) {
|
|
||||||
String[] arr = {"", "K", "M", "B", "T", "P", "E"};
|
|
||||||
int index = 0;
|
|
||||||
while ((value / 1000) >= 1) {
|
|
||||||
value = value / 1000;
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
||||||
return String.format("%s %s", decimalFormat.format(value), arr[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float frequencyCount(int frequency) {
|
fun frequencyCount(frequency: Int): Float {
|
||||||
return (float) (frequency / 1000.0);
|
return (frequency / 1000.0).toFloat()
|
||||||
}
|
|
||||||
|
|
||||||
public static Point getScreenSize(@NonNull Context c) {
|
|
||||||
Display display = null;
|
|
||||||
if (c.getSystemService(Context.WINDOW_SERVICE) != null) {
|
|
||||||
display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
|
||||||
}
|
}
|
||||||
Point size = new Point();
|
|
||||||
if (display != null) {
|
fun getScreenSize(c: Context): Point {
|
||||||
display.getSize(size);
|
var display: Display? = null
|
||||||
|
if (c.getSystemService(Context.WINDOW_SERVICE) != null) {
|
||||||
|
display = (c.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
|
||||||
|
}
|
||||||
|
val size = Point()
|
||||||
|
display?.getSize(size)
|
||||||
|
return size
|
||||||
}
|
}
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getStatusBarHeight() {
|
val statusBarHeight: Int
|
||||||
int result = 0;
|
get() {
|
||||||
int resourceId =
|
var result = 0
|
||||||
App.Companion.getContext()
|
val resourceId = getContext()
|
||||||
.getResources()
|
.resources
|
||||||
.getIdentifier("status_bar_height", "dimen", "android");
|
.getIdentifier("status_bar_height", "dimen", "android")
|
||||||
if (resourceId > 0) {
|
if (resourceId > 0) {
|
||||||
result = App.Companion.getContext().getResources().getDimensionPixelSize(resourceId);
|
result = getContext().resources.getDimensionPixelSize(resourceId)
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getNavigationBarHeight() {
|
|
||||||
int result = 0;
|
|
||||||
int resourceId =
|
|
||||||
App.Companion.getContext()
|
|
||||||
.getResources()
|
|
||||||
.getIdentifier("navigation_bar_height", "dimen", "android");
|
|
||||||
if (resourceId > 0) {
|
|
||||||
result = App.Companion.getContext().getResources().getDimensionPixelSize(resourceId);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static Drawable getTintedVectorDrawable(
|
|
||||||
@NonNull Context context, @DrawableRes int id, @ColorInt int color) {
|
|
||||||
return TintHelper.createTintedDrawable(
|
|
||||||
getVectorDrawable(context.getResources(), id, context.getTheme()), color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static Drawable getTintedVectorDrawable(
|
|
||||||
@NonNull Resources res,
|
|
||||||
@DrawableRes int resId,
|
|
||||||
@Nullable Resources.Theme theme,
|
|
||||||
@ColorInt int color) {
|
|
||||||
return TintHelper.createTintedDrawable(getVectorDrawable(res, resId, theme), color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static Drawable getVectorDrawable(
|
|
||||||
@NonNull Resources res, @DrawableRes int resId, @Nullable Resources.Theme theme) {
|
|
||||||
return ResourcesCompat.getDrawable(res, resId, theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isLandscape() {
|
|
||||||
return App.Companion.getContext().getResources().getConfiguration().orientation
|
|
||||||
== Configuration.ORIENTATION_LANDSCAPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isTablet() {
|
|
||||||
return App.Companion.getContext().getResources().getConfiguration().smallestScreenWidthDp
|
|
||||||
>= 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getIpAddress(boolean useIPv4) {
|
|
||||||
try {
|
|
||||||
List<NetworkInterface> interfaces =
|
|
||||||
Collections.list(NetworkInterface.getNetworkInterfaces());
|
|
||||||
for (NetworkInterface intf : interfaces) {
|
|
||||||
List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
|
|
||||||
for (InetAddress addr : addrs) {
|
|
||||||
if (!addr.isLoopbackAddress()) {
|
|
||||||
String sAddr = addr.getHostAddress();
|
|
||||||
//boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
|
|
||||||
boolean isIPv4 = sAddr.indexOf(':') < 0;
|
|
||||||
if (useIPv4) {
|
|
||||||
if (isIPv4) return sAddr;
|
|
||||||
} else {
|
|
||||||
if (!isIPv4) {
|
|
||||||
int delim = sAddr.indexOf('%'); // drop ip6 zone suffix
|
|
||||||
if (delim < 0) {
|
|
||||||
return sAddr.toUpperCase();
|
|
||||||
} else {
|
|
||||||
return sAddr.substring(
|
|
||||||
0,
|
|
||||||
delim
|
|
||||||
).toUpperCase();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
val navigationBarHeight: Int
|
||||||
} catch (Exception ignored) {
|
get() {
|
||||||
|
var result = 0
|
||||||
|
val resourceId = getContext()
|
||||||
|
.resources
|
||||||
|
.getIdentifier("navigation_bar_height", "dimen", "android")
|
||||||
|
if (resourceId > 0) {
|
||||||
|
result = getContext().resources.getDimensionPixelSize(resourceId)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTintedVectorDrawable(
|
||||||
|
context: Context, @DrawableRes id: Int, @ColorInt color: Int
|
||||||
|
): Drawable {
|
||||||
|
return TintHelper.createTintedDrawable(
|
||||||
|
getVectorDrawable(context.resources, id, context.theme), color)
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
}
|
fun getTintedVectorDrawable(
|
||||||
}
|
res: Resources,
|
||||||
|
@DrawableRes resId: Int,
|
||||||
|
theme: Theme?,
|
||||||
|
@ColorInt color: Int
|
||||||
|
): Drawable {
|
||||||
|
return TintHelper.createTintedDrawable(getVectorDrawable(res, resId, theme), color)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getVectorDrawable(
|
||||||
|
res: Resources, @DrawableRes resId: Int, theme: Theme?
|
||||||
|
): Drawable? {
|
||||||
|
return ResourcesCompat.getDrawable(res, resId, theme)
|
||||||
|
}
|
||||||
|
|
||||||
|
val isLandscape: Boolean
|
||||||
|
get() = (getContext().resources.configuration.orientation
|
||||||
|
== Configuration.ORIENTATION_LANDSCAPE)
|
||||||
|
val isTablet: Boolean
|
||||||
|
get() = (getContext().resources.configuration.smallestScreenWidthDp
|
||||||
|
>= 600)
|
||||||
|
|
||||||
|
fun getIpAddress(useIPv4: Boolean): String? {
|
||||||
|
try {
|
||||||
|
val interfaces: List<NetworkInterface> =
|
||||||
|
Collections.list(NetworkInterface.getNetworkInterfaces())
|
||||||
|
for (intf in interfaces) {
|
||||||
|
val addrs: List<InetAddress> = Collections.list(intf.inetAddresses)
|
||||||
|
for (addr in addrs) {
|
||||||
|
if (!addr.isLoopbackAddress) {
|
||||||
|
val sAddr = addr.hostAddress
|
||||||
|
|
||||||
|
if (sAddr != null) {
|
||||||
|
val isIPv4 = sAddr.indexOf(':') < 0
|
||||||
|
if (useIPv4) {
|
||||||
|
if (isIPv4) return sAddr
|
||||||
|
} else {
|
||||||
|
if (!isIPv4) {
|
||||||
|
val delim = sAddr.indexOf('%') // drop ip6 zone suffix
|
||||||
|
return if (delim < 0) {
|
||||||
|
sAddr.uppercase()
|
||||||
|
} else {
|
||||||
|
sAddr.substring(
|
||||||
|
0,
|
||||||
|
delim
|
||||||
|
).uppercase()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ class InsetsConstraintLayout @JvmOverloads constructor(
|
||||||
defStyleAttr: Int = 0
|
defStyleAttr: Int = 0
|
||||||
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||||
init {
|
init {
|
||||||
if (!RetroUtil.isLandscape())
|
if (!RetroUtil.isLandscape)
|
||||||
drawAboveSystemBarsWithPadding()
|
drawAboveSystemBarsWithPadding()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ class InsetsLinearLayout @JvmOverloads constructor(
|
||||||
defStyleAttr: Int = 0
|
defStyleAttr: Int = 0
|
||||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||||
init {
|
init {
|
||||||
if (!RetroUtil.isLandscape())
|
if (!RetroUtil.isLandscape)
|
||||||
drawAboveSystemBarsWithPadding()
|
drawAboveSystemBarsWithPadding()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue