|
|
@@ -3,6 +3,7 @@ package com.sheep.gamegroup.util;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.Bitmap;
|
|
|
+import android.media.MediaPlayer;
|
|
|
import android.net.Uri;
|
|
|
import android.provider.MediaStore;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
@@ -17,9 +18,13 @@ import android.webkit.WebView;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.VideoView;
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
import com.bumptech.glide.request.RequestOptions;
|
|
|
+import com.sheep.gamegroup.model.entity.Advertising;
|
|
|
+import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
+import com.sheep.gamegroup.view.activity.SplashAct;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
@@ -50,11 +55,11 @@ public class ViewUtil {
|
|
|
.into(iv_qr);
|
|
|
Glide.with(activity)
|
|
|
.load(R.drawable.icon)
|
|
|
- .apply(new RequestOptions().override(G.WIDTH/5))
|
|
|
+ .apply(new RequestOptions().override(G.WIDTH / 5))
|
|
|
.into(iv_qr_small);
|
|
|
dialog.show();
|
|
|
Window window = dialog.getWindow();
|
|
|
- if(window != null) {
|
|
|
+ if (window != null) {
|
|
|
android.view.WindowManager.LayoutParams p = window.getAttributes();
|
|
|
p.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
p.width = WindowManager.LayoutParams.MATCH_PARENT;
|
|
|
@@ -70,8 +75,8 @@ public class ViewUtil {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
- File file = ViewUtil.saveImage((View) iv_qr.getParent(), ClassFileHelper.DIR, System.currentTimeMillis()+".jpg");
|
|
|
- if(file != null) {
|
|
|
+ File file = ViewUtil.saveImage((View) iv_qr.getParent(), ClassFileHelper.DIR, System.currentTimeMillis() + ".jpg");
|
|
|
+ if (file != null) {
|
|
|
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
|
|
Uri uri = Uri.fromFile(file);
|
|
|
intent.setData(uri);
|
|
|
@@ -84,8 +89,10 @@ public class ViewUtil {
|
|
|
});
|
|
|
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 分享对话框
|
|
|
+ *
|
|
|
* @param activity
|
|
|
* @param link
|
|
|
*/
|
|
|
@@ -105,7 +112,7 @@ public class ViewUtil {
|
|
|
TextView save_pic = view.findViewById(R.id.save_pic);
|
|
|
final ImageView iv_qr = view.findViewById(R.id.iv_qr);
|
|
|
|
|
|
- if(!TextUtils.isEmpty(link))
|
|
|
+ if (!TextUtils.isEmpty(link))
|
|
|
tv_link.setText(link);
|
|
|
|
|
|
Glide.with(activity)
|
|
|
@@ -131,8 +138,8 @@ public class ViewUtil {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
- File file = ViewUtil.saveImage((View) iv_qr.getParent(), ClassFileHelper.DIR, System.currentTimeMillis()+".jpg");
|
|
|
- if(file != null) {
|
|
|
+ File file = ViewUtil.saveImage((View) iv_qr.getParent(), ClassFileHelper.DIR, System.currentTimeMillis() + ".jpg");
|
|
|
+ if (file != null) {
|
|
|
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
|
|
Uri uri = Uri.fromFile(file);
|
|
|
intent.setData(uri);
|
|
|
@@ -167,12 +174,15 @@ public class ViewUtil {
|
|
|
}
|
|
|
return bitmap;
|
|
|
}
|
|
|
+
|
|
|
public static void sysSaveImage(View view, String title, String description) {
|
|
|
MediaStore.Images.Media.insertImage(view.getContext().getContentResolver(), getCacheBitmapFromView(view), title, description);
|
|
|
}
|
|
|
+
|
|
|
public static File saveImage(View view, String dir, String fileName) {
|
|
|
return saveImage(getCacheBitmapFromView(view), dir, fileName);
|
|
|
}
|
|
|
+
|
|
|
public static File saveImage(Bitmap bmp, String dir, String fileName) {
|
|
|
File appDir = new File(dir);
|
|
|
if (!appDir.exists()) {
|
|
|
@@ -192,11 +202,13 @@ public class ViewUtil {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
- public static void setH5Text(TextView textView, String content){
|
|
|
+
|
|
|
+ public static void setH5Text(TextView textView, String content) {
|
|
|
textView.setText(Html.fromHtml(content));
|
|
|
textView.setMovementMethod(new ScrollingMovementMethod());
|
|
|
}
|
|
|
- public static void loadDataWithBaseURL(WebView webView, String content){
|
|
|
+
|
|
|
+ public static void loadDataWithBaseURL(WebView webView, String content) {
|
|
|
webView.loadDataWithBaseURL(null,
|
|
|
new StringBuilder("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" /><style>img{max-width:100% !important;height:auto !important;}</style><style>body{max-width:100% !important;}</style></head><body>").append(content).append("</body></html>").toString()
|
|
|
, "text/html", "utf-8", null);
|
|
|
@@ -208,12 +220,20 @@ public class ViewUtil {
|
|
|
|
|
|
|
|
|
public static void showMsgDialog(final Activity activity, String msg) {
|
|
|
- showMsgDialog(activity, msg, null, null, null);
|
|
|
+ showMsgDialog(activity, new DialogConfig().setMsg(msg));
|
|
|
}
|
|
|
- public static void showMsgDialog(final Activity activity, String msg, String title, String sureText) {
|
|
|
- showMsgDialog(activity, msg, title, sureText, null);
|
|
|
+
|
|
|
+ public static void showMsgDialog(final Activity activity, String msg, String title) {
|
|
|
+ showMsgDialog(activity, new DialogConfig().setMsg(msg).setTitle(title));
|
|
|
}
|
|
|
- public static void showMsgDialog(final Activity activity, String msg, String title, String sureText, final View.OnClickListener onClickListener) {
|
|
|
+
|
|
|
+ public static void showMsgDialog(final Activity activity, DialogConfig dialogConfig) {
|
|
|
+ String title = dialogConfig.getTitle();
|
|
|
+ String msg = dialogConfig.getMsg();
|
|
|
+ String btnLeftText = dialogConfig.getBtnLeftText();
|
|
|
+ final View.OnClickListener btnLeftOnClickListener = dialogConfig.getBtnLeftOnClickListener();
|
|
|
+ String btnRightText = dialogConfig.getBtnRightText();
|
|
|
+ final View.OnClickListener btnRightOnClickListener = dialogConfig.getBtnRightOnClickListener();
|
|
|
View dialog_parent = View.inflate(activity, R.layout.dialog_parent, null);
|
|
|
final AlertDialog dialog = new AlertDialog.Builder(activity, R.style.MyDialogActivityTheme)
|
|
|
.setView(dialog_parent)
|
|
|
@@ -222,19 +242,35 @@ public class ViewUtil {
|
|
|
View dialog_close = dialog_parent.findViewById(R.id.dialog_close);
|
|
|
LinearLayout dialog_center_ll = dialog_parent.findViewById(R.id.dialog_center_ll);
|
|
|
View view = LayoutInflater.from(activity).inflate(R.layout.x_msg_dialog, dialog_center_ll, true);
|
|
|
- if(!TextUtils.isEmpty(title))
|
|
|
+ if (!TextUtils.isEmpty(title))
|
|
|
dialog_title.setText(title);
|
|
|
|
|
|
TextView dialog_msg = view.findViewById(R.id.dialog_msg);
|
|
|
- TextView dialog_sure = view.findViewById(R.id.dialog_sure);
|
|
|
dialog_msg.setText(msg);
|
|
|
- if(!TextUtils.isEmpty(sureText))
|
|
|
- dialog_sure.setText(sureText);
|
|
|
- dialog_sure.setOnClickListener(new View.OnClickListener() {
|
|
|
+
|
|
|
+ TextView dialog_btn_left = view.findViewById(R.id.dialog_btn_left);
|
|
|
+ dialog_btn_left.setVisibility(btnLeftText != null || btnLeftOnClickListener != null ? View.VISIBLE : View.GONE);
|
|
|
+ if (!TextUtils.isEmpty(btnLeftText))
|
|
|
+ dialog_btn_left.setText(btnLeftText);
|
|
|
+ dialog_btn_left.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- if(onClickListener != null){
|
|
|
- onClickListener.onClick(v);
|
|
|
+ if (btnLeftOnClickListener != null) {
|
|
|
+ btnLeftOnClickListener.onClick(v);
|
|
|
+ }
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ TextView dialog_btn_right = view.findViewById(R.id.dialog_btn_right);
|
|
|
+ dialog_btn_right.setVisibility(btnRightText != null || btnRightOnClickListener != null ? View.VISIBLE : View.GONE);
|
|
|
+ if (!TextUtils.isEmpty(btnRightText))
|
|
|
+ dialog_btn_right.setText(btnRightText);
|
|
|
+ dialog_btn_right.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (btnLeftOnClickListener != null) {
|
|
|
+ btnLeftOnClickListener.onClick(v);
|
|
|
}
|
|
|
dialog.dismiss();
|
|
|
}
|
|
|
@@ -249,4 +285,94 @@ public class ViewUtil {
|
|
|
}
|
|
|
|
|
|
public static final int REQUEST_CODE_TASK_LIST = 110;
|
|
|
-}
|
|
|
+
|
|
|
+ public static void showHalfScreenAd(final Advertising advertising) {
|
|
|
+ final Activity activity = ActivityManager.getInstance().currentActivity();
|
|
|
+ if (activity != null) {
|
|
|
+ View dialog_parent = View.inflate(activity, R.layout.dialog_parent, null);
|
|
|
+ final AlertDialog dialog = new AlertDialog.Builder(activity, R.style.MyDialogActivityTheme)
|
|
|
+ .setView(dialog_parent)
|
|
|
+ .create();
|
|
|
+ TextView dialog_title = dialog_parent.findViewById(R.id.dialog_title);
|
|
|
+ final View dialog_close = dialog_parent.findViewById(R.id.dialog_close);
|
|
|
+ LinearLayout dialog_center_ll = dialog_parent.findViewById(R.id.dialog_center_ll);
|
|
|
+ View view = LayoutInflater.from(activity).inflate(R.layout.dialog_half_screen_ad, dialog_center_ll, true);
|
|
|
+ dialog_title.setText("推荐给好友");
|
|
|
+
|
|
|
+ ImageView ad_iv = view.findViewById(R.id.ad_iv);
|
|
|
+ VideoView ad_video_view = view.findViewById(R.id.ad_video_view);
|
|
|
+ TextView ad_msg = view.findViewById(R.id.ad_msg);
|
|
|
+ final TextView ad_skip = view.findViewById(R.id.ad_skip);
|
|
|
+ TextView know_ad_tv = view.findViewById(R.id.know_ad_tv);
|
|
|
+
|
|
|
+
|
|
|
+ if (advertising.isImage()) {
|
|
|
+ Glide.with(activity).load(advertising.getDisplay_src()).into(ad_iv);
|
|
|
+ ad_video_view.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ Uri uri = Uri.parse(advertising.getDisplay_src());
|
|
|
+ ad_iv.setVisibility(View.GONE);
|
|
|
+ final VideoView videoView = ad_video_view;
|
|
|
+ videoView.setOnInfoListener(new MediaPlayer.OnInfoListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
|
|
|
+ if (!mediaPlayer.isLooping())
|
|
|
+ mediaPlayer.setLooping(true);
|
|
|
+ LogUtil.println("onInfo what = " + what + " extra = " + extra);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ videoView.setVideoURI(uri);
|
|
|
+ videoView.start();
|
|
|
+ videoView.requestFocus();
|
|
|
+ }
|
|
|
+ RxjavaCountDownTimer timer = null;
|
|
|
+ if (advertising.getShow_time() > 0)
|
|
|
+ timer = RxjavaCountDownTimer.getInstance(advertising.getShow_time())
|
|
|
+ .setOnTickListener(new RxjavaCountDownTimer.OnTickListener() {
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ dialog_close.setEnabled(true);
|
|
|
+ ad_skip.setEnabled(true);
|
|
|
+ ad_skip.setText("跳过");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTicker(long time) {
|
|
|
+ dialog_close.setEnabled(false);
|
|
|
+ ad_skip.setEnabled(false);
|
|
|
+ ad_skip.setText(activity.getString(R.string.tip_skip, time));
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+
|
|
|
+ final RxjavaCountDownTimer finalTimer = timer;
|
|
|
+
|
|
|
+ dialog_close.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (finalTimer != null) {
|
|
|
+ finalTimer.clear();
|
|
|
+ }
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ know_ad_tv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ SplashAct.goAdLink(ActivityManager.getInstance().currentActivity(), advertising);
|
|
|
+ if (finalTimer != null) {
|
|
|
+ finalTimer.clear();
|
|
|
+ }
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(TextUtils.isEmpty(advertising.getDesc())) {
|
|
|
+ ad_msg.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ ad_msg.setText(advertising.getDesc());
|
|
|
+ }
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|