工具类 得到屏幕的宽度,高度,打开浏览器,判断控件是否在屏幕中,查看图片是否已经缓存

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);
		
	}
	
	
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值