软件的一个工具类,banner,单位转换等

package com.yiplayer.toolbox.shareit.utils;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
/**
 * 保存所有设置的值
 * */
public class SettingSave {
		
	private static final String FIRSTSET = "Firstset";
	public static final String SETTING = "com.yiplayer.toolbox.shareit_preferences";	
		
	/**
	 * 第二版新增字段,用于判断是否是更新版本后第一次打开
	 */
	public final static String VERSIONCODE = "versionCode"; 
	public static final String GOOGLE_URL = "http://google.com.hk/search?q=";
	public static final String BAIDU_URL = "http://wap.baidu.com/s?from=819b_w1&vit=uni&word=";
	public static final String ROOTTUTORIAL_URL = "http://yiplayer.com/help/root";
	//软件版本更新的地址
	public static final String updateUrl = "http://yiplayer.com/update/101/";
	/**
	 *保存FilterValue的值
	 *@param  context
	 *@param  key 
	 *@param  value 要保存的值
	 */
	public static void saveFilterValue(Context context,String key,String value){
		SharedPreferences pref = context.getSharedPreferences(SETTING, 0);
		SharedPreferences.Editor editor = pref.edit();
		editor.putString(key, value);		
		editor.commit();
	}
	
	/**
	 *获取FilterValue的值
	 *@param  context
	 *@param  key 
	 */
	public static String getFilterValue(Context context,String key){
		SharedPreferences pref = context.getSharedPreferences(SETTING, 0);
		return pref.getString(key, "filter_NO");
	}
	
	/**
	 *保存BooleanValue的值
	 *@param  context
	 *@param  key 
	 *@param  value 要保存的值
	 */
	public static void saveBooleanValue(Context context,String key,boolean value){
		SharedPreferences pref = context.getSharedPreferences(SETTING, 0);
		SharedPreferences.Editor editor = pref.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}
	/**
	 *获取BooleanValue的值
	 *@param  context
	 *@param  key
	 */
	public static boolean getBooleanValue(Context context,String key){
		SharedPreferences pref = context.getSharedPreferences(SETTING, 0);
		return pref.getBoolean(key, true);
	}
	
	

	/**
	 *保存Firstset的值
	 */
	public static void saveFirstset(Context context,boolean Firstset){
		SharedPreferences pref = context.getSharedPreferences(SETTING, 0);
		SharedPreferences.Editor editor = pref.edit();
		editor.putBoolean(FIRSTSET, Firstset);
		editor.commit();
	}
	public static boolean getFirstset(Context context){//获取Firstset的值
		SharedPreferences pref = context.getSharedPreferences(SETTING, 0);
		return pref.getBoolean(FIRSTSET, true);
	}
	
	
	/**
	 * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
	 */
	public static int dipToPixels(Context context, int dip) {
		Resources r = context.getResources();
		float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
		return (int) px;
	}
	
	/**
	 * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
	 */
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}
	
	/**
	 * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
	 */
	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}
	
	/**
	 * 获取渠道号CID
	 * @param context
	 */
	public static int getWap3Cid(Context context){
		PackageManager pm = context.getPackageManager();
		Bundle bundle = null;
		ApplicationInfo appInfo;
		int cid = 0;
		try {
			appInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
			if (appInfo != null && appInfo.metaData != null) {
				bundle = appInfo.metaData;
				if (bundle != null) {
					cid = bundle.getInt("UMENG_CHANNEL");
					return cid;
				}
			}
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return cid;
	}
}



你可能感兴趣的:(String,null,手机,工具,float,resources)