mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-07 15:28:43 +01:00
display all app icons in a grid
This commit is contained in:
parent
1c8753c341
commit
a0a847632e
@ -28,6 +28,7 @@ dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:23.4.0'
|
||||
compile 'com.android.support:recyclerview-v7:23.4.0'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,38 @@
|
||||
package com.simplemobiletools.applauncher.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.adapters.LaunchersAdapter
|
||||
import com.simplemobiletools.applauncher.extensions.isFirstRun
|
||||
import com.simplemobiletools.applauncher.extensions.preferences
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
fillGrid()
|
||||
}
|
||||
|
||||
private fun fillGrid() {
|
||||
val apps = ArrayList<AppLauncher>()
|
||||
val pm = this.packageManager
|
||||
val intent = Intent(Intent.ACTION_MAIN, null)
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
val list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||
for (info in list) {
|
||||
val componentInfo = info.activityInfo.applicationInfo
|
||||
apps.add(AppLauncher(componentInfo.loadLabel(pm).toString(), componentInfo.loadIcon(pm)))
|
||||
}
|
||||
|
||||
launchers_holder.adapter = LaunchersAdapter(apps)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.simplemobiletools.applauncher.adapters
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.app_launcher_item.view.*
|
||||
import java.util.*
|
||||
|
||||
class LaunchersAdapter(val launchers: ArrayList<AppLauncher>) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>() {
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bindView(launchers[position])
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent?.context).inflate(R.layout.app_launcher_item, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return launchers.count()
|
||||
}
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(launcher: AppLauncher) {
|
||||
with(launcher) {
|
||||
itemView.launcher_label.text = launcher.name
|
||||
itemView.launcher_icon.setImageDrawable(launcher.icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.simplemobiletools.applauncher.models
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
data class AppLauncher(val name: String, val icon: Drawable) { }
|
@ -1,12 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
android:id="@+id/grid_holder"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/activity_margin">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/launchers_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||
app:spanCount="@integer/columns"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"/>
|
||||
</RelativeLayout>
|
||||
|
23
app/src/main/res/layout/app_launcher_item.xml
Normal file
23
app/src/main/res/layout/app_launcher_item.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
android:id="@+id/launcher_holder"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/launcher_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/launcher_icon"
|
||||
android:layout_width="@dimen/icon_size"
|
||||
android:layout_height="@dimen/icon_size"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/launcher_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal|top"
|
||||
android:textSize="@dimen/font_size"/>
|
||||
|
||||
</LinearLayout>
|
3
app/src/main/res/values-sw400dp/integers.xml
Normal file
3
app/src/main/res/values-sw400dp/integers.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<integer name="columns">5</integer>
|
||||
</resources>
|
@ -3,4 +3,8 @@
|
||||
<dimen name="social_padding">8dp</dimen>
|
||||
<dimen name="social_logo">40dp</dimen>
|
||||
<dimen name="settings_padding">8dp</dimen>
|
||||
<dimen name="launcher_padding">4dp</dimen>
|
||||
<dimen name="icon_size">60dp</dimen>
|
||||
|
||||
<dimen name="font_size">12sp</dimen>
|
||||
</resources>
|
||||
|
3
app/src/main/res/values/integers.xml
Normal file
3
app/src/main/res/values/integers.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<integer name="columns">4</integer>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user