mirror of https://github.com/FongMi/TV.git
parent
ac096a1e46
commit
956ba76d00
@ -1,48 +0,0 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import android.content.pm.ApplicationInfo; |
||||
import android.graphics.drawable.Drawable; |
||||
|
||||
import androidx.annotation.Nullable; |
||||
|
||||
import com.fongmi.android.tv.App; |
||||
|
||||
public class Info { |
||||
|
||||
private final Drawable icon; |
||||
private final String name; |
||||
private final String pack; |
||||
|
||||
public static Info get(ApplicationInfo info) { |
||||
Drawable icon = info.loadIcon(App.get().getPackageManager()); |
||||
String name = info.loadLabel(App.get().getPackageManager()).toString(); |
||||
String pack = info.packageName; |
||||
return new Info(name, pack, icon); |
||||
} |
||||
|
||||
public Info(String name, String pack, Drawable icon) { |
||||
this.name = name; |
||||
this.pack = pack; |
||||
this.icon = icon; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public String getPack() { |
||||
return pack; |
||||
} |
||||
|
||||
public Drawable getIcon() { |
||||
return icon; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(@Nullable Object obj) { |
||||
if (this == obj) return true; |
||||
if (!(obj instanceof Info)) return false; |
||||
Info it = (Info) obj; |
||||
return getPack().equals(it.getPack()); |
||||
} |
||||
} |
||||
@ -1,65 +0,0 @@ |
||||
package com.fongmi.android.tv.ui.activity; |
||||
|
||||
import android.content.Intent; |
||||
import android.content.pm.ApplicationInfo; |
||||
import android.net.Uri; |
||||
|
||||
import androidx.viewbinding.ViewBinding; |
||||
|
||||
import com.android.cast.dlna.dmr.DLNARendererService; |
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.bean.Info; |
||||
import com.fongmi.android.tv.databinding.ActivityLauncherBinding; |
||||
import com.fongmi.android.tv.ui.adapter.AppAdapter; |
||||
import com.fongmi.android.tv.ui.base.BaseActivity; |
||||
import com.fongmi.android.tv.ui.custom.SpaceItemDecoration; |
||||
|
||||
public class LauncherActivity extends BaseActivity implements AppAdapter.OnClickListener { |
||||
|
||||
private ActivityLauncherBinding mBinding; |
||||
private AppAdapter mAdapter; |
||||
|
||||
@Override |
||||
protected ViewBinding getBinding() { |
||||
return mBinding = ActivityLauncherBinding.inflate(getLayoutInflater()); |
||||
} |
||||
|
||||
@Override |
||||
protected void initView() { |
||||
DLNARendererService.Companion.start(this, R.drawable.ic_logo); |
||||
setRecyclerView(); |
||||
getApps(); |
||||
} |
||||
|
||||
private void setRecyclerView() { |
||||
mBinding.recycler.setHasFixedSize(true); |
||||
mBinding.recycler.setItemAnimator(null); |
||||
mBinding.recycler.setAdapter(mAdapter = new AppAdapter(this)); |
||||
mBinding.recycler.addItemDecoration(new SpaceItemDecoration(5, 16)); |
||||
} |
||||
|
||||
private void getApps() { |
||||
for (ApplicationInfo info : getPackageManager().getInstalledApplications(0)) { |
||||
if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) continue; |
||||
mAdapter.add(Info.get(info)); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onItemClick(Info item) { |
||||
try { |
||||
startActivity(getPackageManager().getLaunchIntentForPackage(item.getPack())); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean onLongClick(Info item) { |
||||
if (item.getPack().equals(getPackageName())) return false; |
||||
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE); |
||||
intent.setData(Uri.parse("package:" + item.getPack())); |
||||
startActivity(intent); |
||||
return true; |
||||
} |
||||
} |
||||
@ -1,88 +0,0 @@ |
||||
package com.fongmi.android.tv.ui.adapter; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.fongmi.android.tv.App; |
||||
import com.fongmi.android.tv.Product; |
||||
import com.fongmi.android.tv.bean.Info; |
||||
import com.fongmi.android.tv.bean.Style; |
||||
import com.fongmi.android.tv.databinding.AdapterAppBinding; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.ViewHolder> { |
||||
|
||||
private final OnClickListener mListener; |
||||
private final List<Info> mItems; |
||||
private int[] size; |
||||
|
||||
public AppAdapter(OnClickListener listener) { |
||||
this.mItems = new ArrayList<>(); |
||||
this.mListener = listener; |
||||
setSize(); |
||||
} |
||||
|
||||
public interface OnClickListener { |
||||
|
||||
void onItemClick(Info item); |
||||
|
||||
boolean onLongClick(Info item); |
||||
} |
||||
|
||||
private void setSize() { |
||||
int column = 5; |
||||
int space = ResUtil.dp2px(48) + ResUtil.dp2px(16 * (column - 1)); |
||||
this.size = Product.getSpec(space, column, Style.rect()); |
||||
} |
||||
|
||||
public void add(Info item) { |
||||
if (item.getPack().equals(App.get().getPackageName())) { |
||||
mItems.add(0, item); |
||||
notifyItemInserted(0); |
||||
} else { |
||||
mItems.add(item); |
||||
notifyItemInserted(mItems.size() - 1); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int getItemCount() { |
||||
return mItems.size(); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
return new ViewHolder(AdapterAppBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)).size(size); |
||||
} |
||||
|
||||
@Override |
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { |
||||
Info item = mItems.get(position); |
||||
holder.binding.name.setText(item.getName()); |
||||
holder.binding.icon.setImageDrawable(item.getIcon()); |
||||
holder.binding.getRoot().setOnClickListener(v -> mListener.onItemClick(item)); |
||||
holder.binding.getRoot().setOnLongClickListener(v -> mListener.onLongClick(item)); |
||||
} |
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder { |
||||
|
||||
private final AdapterAppBinding binding; |
||||
|
||||
public ViewHolder(@NonNull AdapterAppBinding binding) { |
||||
super(binding.getRoot()); |
||||
this.binding = binding; |
||||
} |
||||
|
||||
public ViewHolder size(int[] size) { |
||||
binding.getRoot().getLayoutParams().width = size[0]; |
||||
return this; |
||||
} |
||||
} |
||||
} |
||||
@ -1,17 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<FrameLayout 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"> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recycler" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:padding="24dp" |
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" |
||||
app:spanCount="5" /> |
||||
|
||||
</FrameLayout> |
||||
@ -1,38 +0,0 @@ |
||||
<?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_centerInParent="true" |
||||
android:background="@drawable/selector_item" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:orientation="vertical" |
||||
android:paddingStart="16dp" |
||||
android:paddingTop="16dp" |
||||
android:paddingEnd="16dp" |
||||
android:paddingBottom="8dp"> |
||||
|
||||
<ImageView |
||||
android:id="@+id/icon" |
||||
android:layout_width="64dp" |
||||
android:layout_height="64dp" |
||||
tools:src="@mipmap/ic_launcher" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/name" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="8dp" |
||||
android:shadowColor="@color/black" |
||||
android:shadowDx="2" |
||||
android:shadowDy="2" |
||||
android:shadowRadius="2" |
||||
android:singleLine="true" |
||||
android:ellipsize="marquee" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" |
||||
tools:text="@string/app_name" /> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue