pda/zhuike/.svn/pristine/43/43d5f65e252ca9645cef0ed87a8...

110 lines
3.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.novelbook.android.AD;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;
import com.novelbook.android.R;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import butterknife.BindView;
import butterknife.ButterKnife;
public class AdvertisementViewActivity extends AppCompatActivity {
@BindView(R.id.adSplashView)
AdvertisementView advertisementView;
@BindView(R.id.textTile)
TextView tvTitle;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
);
// advertisementView = new AdvertisementView(this);
// setContentView(advertisementView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
setContentView(R.layout.activity_splash_ad);
ButterKnife.bind(this);
//获取ImageView, 设置显示图片
//这样设计是为了方便调用者使用不同的图片加载框架。比如Picsso、Fresco、ImageLoader...
// advertisementView.getImageView().setImageResource(R.drawable.header);
/* String picPathName = "";
if (new File(picPathName).exists()) {
loadPicture(new File(picPathName));
}
else
advertisementView.getImageView().setImageResource(R.drawable.header);*/
loadPicture();
advertisementView.init(5000, 1000, new AdvertisementView.OnComponentActionListener() {
@Override
public void onComponentAction(int actionCode, View view) {
switch (actionCode) {//点击广告图片
case AdvertisementView.ACTION_CODE_PREVIEW:
String url = "http://www.baidu.com";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
break;
case AdvertisementView.ACTION_CODE_JUMP://点击跳过
break;
case AdvertisementView.ACTION_CODE_FINISH://倒计时结束
break;
}
//因为广告图片可能比较大所以我们主动移除所有子view加快GC回收
advertisementView.removeAllViews();
System.gc();
finish();
}
});
tvTitle.setText(R.string.app_name);
}
private void loadPicture(/*File file*/) {
InputStream is = null;
try {
// is = new FileInputStream(file);
is =getAssets().open("ad.jpg");
Drawable drawable = Drawable.createFromStream(is, null);
advertisementView.getImageView().setImageDrawable(drawable);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
protected void onResume() {
super.onResume();
advertisementView.startCountDown();
}
@Override
public void onBackPressed() {
}
@Override
protected void onPause() {
advertisementView.cancelCountDown();
super.onPause();
}
}