mirror of https://github.com/FongMi/TV.git
parent
1dc9307806
commit
2f7c0e5782
@ -0,0 +1,73 @@ |
||||
package com.fongmi.android.tv.ui.activity; |
||||
|
||||
import android.app.Activity; |
||||
import android.content.Intent; |
||||
import android.view.View; |
||||
|
||||
import androidx.viewbinding.ViewBinding; |
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.databinding.ActivitySettingPlayerBinding; |
||||
import com.fongmi.android.tv.impl.UaCallback; |
||||
import com.fongmi.android.tv.player.ExoUtil; |
||||
import com.fongmi.android.tv.ui.base.BaseActivity; |
||||
import com.fongmi.android.tv.ui.custom.dialog.UaDialog; |
||||
import com.fongmi.android.tv.utils.Prefers; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
public class SettingPlayerActivity extends BaseActivity implements UaCallback { |
||||
|
||||
private ActivitySettingPlayerBinding mBinding; |
||||
private String[] http; |
||||
|
||||
public static void start(Activity activity) { |
||||
activity.startActivity(new Intent(activity, SettingPlayerActivity.class)); |
||||
} |
||||
|
||||
private String getSwitch(boolean value) { |
||||
return getString(value ? R.string.setting_on : R.string.setting_off); |
||||
} |
||||
|
||||
@Override |
||||
protected ViewBinding getBinding() { |
||||
return mBinding = ActivitySettingPlayerBinding.inflate(getLayoutInflater()); |
||||
} |
||||
|
||||
@Override |
||||
protected void initView() { |
||||
mBinding.uaText.setText(Prefers.getUa()); |
||||
mBinding.tunnelText.setText(getSwitch(Prefers.isTunnel())); |
||||
mBinding.httpText.setText((http = ResUtil.getStringArray(R.array.select_player_http))[Prefers.getHttp()]); |
||||
mBinding.tunnel.setVisibility(Prefers.getPlayer() == 0 ? View.VISIBLE : View.GONE); |
||||
mBinding.http.setVisibility(Prefers.getPlayer() == 0 ? View.VISIBLE : View.GONE); |
||||
} |
||||
|
||||
@Override |
||||
protected void initEvent() { |
||||
mBinding.ua.setOnClickListener(this::onUa); |
||||
mBinding.http.setOnClickListener(this::setHttp); |
||||
mBinding.tunnel.setOnClickListener(this::setTunnel); |
||||
} |
||||
|
||||
private void onUa(View view) { |
||||
UaDialog.create(this).show(); |
||||
} |
||||
|
||||
private void setHttp(View view) { |
||||
int index = Prefers.getHttp(); |
||||
Prefers.putHttp(index = index == http.length - 1 ? 0 : ++index); |
||||
mBinding.httpText.setText(http[index]); |
||||
ExoUtil.reset(); |
||||
} |
||||
|
||||
private void setTunnel(View view) { |
||||
Prefers.putTunnel(!Prefers.isTunnel()); |
||||
mBinding.tunnelText.setText(getSwitch(Prefers.isTunnel())); |
||||
} |
||||
|
||||
@Override |
||||
public void setUa(String ua) { |
||||
mBinding.uaText.setText(ua); |
||||
Prefers.putUa(ua); |
||||
} |
||||
} |
||||
@ -0,0 +1,97 @@ |
||||
package com.fongmi.android.tv.ui.custom.dialog; |
||||
|
||||
import android.content.DialogInterface; |
||||
import android.text.TextUtils; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.WindowManager; |
||||
import android.view.inputmethod.EditorInfo; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
import androidx.fragment.app.FragmentActivity; |
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.databinding.DialogUaBinding; |
||||
import com.fongmi.android.tv.event.ServerEvent; |
||||
import com.fongmi.android.tv.impl.UaCallback; |
||||
import com.fongmi.android.tv.server.Server; |
||||
import com.fongmi.android.tv.utils.Prefers; |
||||
import com.fongmi.android.tv.utils.QRCode; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
import org.greenrobot.eventbus.EventBus; |
||||
import org.greenrobot.eventbus.Subscribe; |
||||
import org.greenrobot.eventbus.ThreadMode; |
||||
|
||||
public class UaDialog implements DialogInterface.OnDismissListener { |
||||
|
||||
private final DialogUaBinding binding; |
||||
private final UaCallback callback; |
||||
private final AlertDialog dialog; |
||||
|
||||
public static UaDialog create(FragmentActivity activity) { |
||||
return new UaDialog(activity); |
||||
} |
||||
|
||||
public UaDialog(FragmentActivity activity) { |
||||
this.callback = (UaCallback) activity; |
||||
this.binding = DialogUaBinding.inflate(LayoutInflater.from(activity)); |
||||
this.dialog = new MaterialAlertDialogBuilder(activity).setView(binding.getRoot()).create(); |
||||
} |
||||
|
||||
public void show() { |
||||
initDialog(); |
||||
initView(); |
||||
initEvent(); |
||||
} |
||||
|
||||
private void initDialog() { |
||||
WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); |
||||
params.width = (int) (ResUtil.getScreenWidth() * 0.55f); |
||||
dialog.getWindow().setAttributes(params); |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.setOnDismissListener(this); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void initView() { |
||||
String ua = Prefers.getUa(); |
||||
String address = Server.get().getAddress(); |
||||
binding.text.setText(ua); |
||||
binding.code.setImageBitmap(QRCode.getBitmap(address, 200, 0)); |
||||
binding.text.setSelection(TextUtils.isEmpty(ua) ? 0 : ua.length()); |
||||
binding.info.setText(ResUtil.getString(R.string.push_info, address).replace(",", "\n")); |
||||
} |
||||
|
||||
private void initEvent() { |
||||
EventBus.getDefault().register(this); |
||||
binding.positive.setOnClickListener(this::onPositive); |
||||
binding.negative.setOnClickListener(this::onNegative); |
||||
binding.text.setOnEditorActionListener((textView, actionId, event) -> { |
||||
if (actionId == EditorInfo.IME_ACTION_DONE) binding.positive.performClick(); |
||||
return true; |
||||
}); |
||||
} |
||||
|
||||
private void onPositive(View view) { |
||||
callback.setUa(binding.text.getText().toString().trim()); |
||||
dialog.dismiss(); |
||||
} |
||||
|
||||
private void onNegative(View view) { |
||||
dialog.dismiss(); |
||||
} |
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN) |
||||
public void onServerEvent(ServerEvent event) { |
||||
if (event.getType() != ServerEvent.Type.API) return; |
||||
binding.text.setText(event.getText()); |
||||
binding.positive.performClick(); |
||||
} |
||||
|
||||
@Override |
||||
public void onDismiss(DialogInterface dialogInterface) { |
||||
EventBus.getDefault().unregister(this); |
||||
} |
||||
} |
||||
@ -0,0 +1,104 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:fillViewport="true" |
||||
android:keepScreenOn="true" |
||||
tools:ignore="NestedWeights"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical" |
||||
android:padding="24dp"> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/ua" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/selector_item" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_weight="0.3" |
||||
android:text="@string/setting_player_ua" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/uaText" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="0.7" |
||||
android:ellipsize="middle" |
||||
android:gravity="end" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" |
||||
tools:text="okhttp/4.11.0" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/http" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:background="@drawable/selector_item" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:text="@string/setting_player_http" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/httpText" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" |
||||
tools:text="OkHttp" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/tunnel" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:background="@drawable/selector_item" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:text="@string/setting_player_tunnel" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/tunnelText" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" |
||||
tools:text="關" /> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
</androidx.core.widget.NestedScrollView> |
||||
@ -0,0 +1,81 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<RelativeLayout 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:padding="16dp"> |
||||
|
||||
<ImageView |
||||
android:id="@+id/code" |
||||
android:layout_width="180dp" |
||||
android:layout_height="180dp" |
||||
android:scaleType="centerCrop" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/info" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="12dp" |
||||
android:layout_toEndOf="@+id/code" |
||||
android:focusable="true" |
||||
android:lineSpacingExtra="4dp" |
||||
android:paddingStart="4dp" |
||||
android:paddingEnd="4dp" |
||||
android:textColor="@color/grey_700" |
||||
android:textSize="18sp" |
||||
tools:text="@string/push_info" /> |
||||
|
||||
<EditText |
||||
android:id="@+id/text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_above="@+id/bottom" |
||||
android:layout_alignStart="@+id/info" |
||||
android:layout_marginBottom="10dp" |
||||
android:hint="@string/setting_player_ua" |
||||
android:imeOptions="actionDone" |
||||
android:importantForAutofill="no" |
||||
android:inputType="text" |
||||
android:nextFocusDown="@id/positive" |
||||
android:singleLine="true" |
||||
android:textSize="18sp" /> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/bottom" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignStart="@+id/info" |
||||
android:layout_alignBottom="@+id/code" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/positive" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:text="@string/dialog_positive" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/negative" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:singleLine="true" |
||||
android:text="@string/dialog_negative" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" /> |
||||
|
||||
</LinearLayout> |
||||
</RelativeLayout> |
||||
@ -0,0 +1,6 @@ |
||||
package com.fongmi.android.tv.impl; |
||||
|
||||
public interface UaCallback { |
||||
|
||||
void setUa(String ua); |
||||
} |
||||
@ -1,29 +1,13 @@ |
||||
package tv.danmaku.ijk.media.player.ui; |
||||
|
||||
import android.content.Context; |
||||
import android.content.pm.PackageInfo; |
||||
import android.content.pm.PackageManager; |
||||
import android.os.Build; |
||||
import android.util.DisplayMetrics; |
||||
|
||||
public class Utils { |
||||
|
||||
public static final String USER_AGENT = "User-Agent"; |
||||
public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"; |
||||
|
||||
public static float dp2px(Context context, float dpValue) { |
||||
return Math.round((dpValue * context.getResources().getDisplayMetrics().densityDpi) / DisplayMetrics.DENSITY_DEFAULT); |
||||
} |
||||
|
||||
public static String getUserAgent(Context context) { |
||||
String versionName; |
||||
try { |
||||
String packageName = context.getPackageName(); |
||||
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); |
||||
versionName = info.versionName; |
||||
} catch (PackageManager.NameNotFoundException e) { |
||||
versionName = "?"; |
||||
} |
||||
return context.getPackageName() + "/" + versionName + " (Linux;Android " + Build.VERSION.RELEASE + ") " + "IjkPlayerLib/0.8.9"; |
||||
} |
||||
} |
||||
|
||||
Loading…
Reference in new issue