package com.jh.advertisement.util;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.jh.common.cache.FileCache;
import com.jh.common.cache.FileCache.FileEnum;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
/**
* 广告工具类
* @author 099
* @since 2013-12-25
*/
public class AdvertisementUtils {
/**
* 通过浏览器,跳转到广告详情界面
* @param context
* @param advertiseUrl
*/
public static void gotoBrowser(Context context, String advertiseUrl) {
if (advertiseUrl != null) {
// 开启新窗口
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse(advertiseUrl);
intent.setData(content_url);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
/**
* 获取屏幕的宽度
* @param context
* @return
*/
public static int getScreenWidth(Context context){
return context.getResources().getDisplayMetrics().widthPixels;
}
/**
* 获取屏幕的长度
* @param context
* @return
*/
public static int getScreenHeight(Context context){
return context.getResources().getDisplayMetrics().heightPixels;
}
/**
* 判断控件是否在屏幕中。
* @param view
* @return
*/
public static boolean isViewInScreen(View view){
int[] location = new int[2];
view.getLocationOnScreen(location);
int x=location[0];
int y=location[1];
int screenWidth=getScreenWidth(view.getContext());
int screenHeight=getScreenHeight(view.getContext());
if(x>=0&&x<=screenWidth&&y<=screenHeight){
return true;
}
return false;
}
/**
* 查看图片是否已经缓存
* @param saveLocation
* @return
*/
public static boolean hasImageCache(String saveLocation){
File imagefile = new File(saveLocation);
// //测试log
if (imagefile != null && imagefile.exists()
&& imagefile.length() > 0) {
return true;
}
return false;
}
/**
* date to String
* @param date
* @return
*/
public static String dateToString(Date date){
SimpleDateFormat format=new SimpleDateFormat("yyyyMMdd");
return format.format(date);
}
}