mirror of https://github.com/FongMi/TV.git
parent
83da9ff510
commit
4aefa87f67
@ -0,0 +1,80 @@ |
||||
package com.fongmi.android.tv.ui.dialog; |
||||
|
||||
import android.app.Activity; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.WindowManager; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.databinding.DialogMenuBinding; |
||||
import com.fongmi.android.tv.ui.activity.HistoryActivity; |
||||
import com.fongmi.android.tv.ui.activity.HomeActivity; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
public class MenuDialog { |
||||
private final DialogMenuBinding binding; |
||||
private final AlertDialog dialog; |
||||
|
||||
private final Activity activity; |
||||
private String[] homeMenuKey; |
||||
|
||||
public static MenuDialog create(Activity activity) { |
||||
return new MenuDialog(activity); |
||||
} |
||||
|
||||
public MenuDialog(Activity activity) { |
||||
this.activity = activity; |
||||
this.binding = DialogMenuBinding.inflate(LayoutInflater.from(activity)); |
||||
this.dialog = new MaterialAlertDialogBuilder(activity).setView(binding.getRoot()).create(); |
||||
} |
||||
|
||||
public void show() { |
||||
initView(); |
||||
initEvent(); |
||||
} |
||||
|
||||
private void initView() { |
||||
setTextView(); |
||||
setDialog(); |
||||
binding.site.requestFocus(); |
||||
} |
||||
|
||||
private void initEvent() { |
||||
binding.site.setOnClickListener(this::showSiteDialog); |
||||
binding.settingVodHistory.setOnClickListener(this::showSettingVodHistory); |
||||
binding.history.setOnClickListener(this::startHistory); |
||||
} |
||||
|
||||
private void setTextView() { |
||||
homeMenuKey = ResUtil.getStringArray(R.array.select_home_menu_key); |
||||
binding.siteText.setText(homeMenuKey[1]); |
||||
binding.settingVodHistoryText.setText(homeMenuKey[2]); |
||||
binding.historyText.setText(homeMenuKey[3]); |
||||
} |
||||
|
||||
private void setDialog() { |
||||
WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); |
||||
params.width = (int) (ResUtil.getScreenWidth() * 0.4f); |
||||
dialog.getWindow().setAttributes(params); |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void showSiteDialog(View view) { |
||||
dialog.dismiss(); |
||||
if (activity instanceof HomeActivity) ((HomeActivity) activity).showDialog(); |
||||
} |
||||
|
||||
private void showSettingVodHistory(View view) { |
||||
dialog.dismiss(); |
||||
if (activity instanceof HomeActivity) ((HomeActivity) activity).showSettingVodHistory(); |
||||
} |
||||
|
||||
private void startHistory(View view) { |
||||
dialog.dismiss(); |
||||
HistoryActivity.start(activity); |
||||
} |
||||
} |
||||
@ -0,0 +1,81 @@ |
||||
<?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="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
android:padding="16dp"> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/site" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="40dp" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center_vertical" |
||||
android:layout_marginBottom="12dp" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/siteText" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:ellipsize="marquee" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:textColor="@color/text" |
||||
android:textSize="18sp" |
||||
tools:text="泥巴" /> |
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/settingVodHistory" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="40dp" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center_vertical" |
||||
android:layout_marginBottom="12dp" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/settingVodHistoryText" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:ellipsize="marquee" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:textColor="@color/text" |
||||
android:textSize="18sp" |
||||
tools:text="泥巴" /> |
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/history" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="40dp" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center_vertical" |
||||
android:layout_marginBottom="12dp" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/historyText" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:ellipsize="marquee" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:textColor="@color/text" |
||||
android:textSize="18sp" |
||||
tools:text="泥巴" /> |
||||
</LinearLayout> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue