android开发常用公共
来源:互联网 发布:php 如何防止抓包截断 编辑:程序博客网 时间:2024/04/29 22:15
1、文件1 Tools.java
package com.mstar.tvsettings.util;import android.annotation.SuppressLint;import android.annotation.TargetApi;import android.content.ComponentName;import android.content.Context;import android.content.Intent;import android.os.Build;import android.view.View;import android.widget.RelativeLayout;import com.mstar.tvsettings.R;@TargetApi(Build.VERSION_CODES.HONEYCOMB)@SuppressLint("NewApi")public class Tools { private static final String MSTAR_PRODUCT_CHARACTERISTICS = "mstar.product.characteristics"; private static final String MSTAR_PRODUCT_STB = "stb"; private static String mProduct = null; public static void startForward(Context context, String className) { Intent intent = new Intent(); ComponentName name = new ComponentName(Constants.TVAPK_PACKAGE_NAME, className); intent.setComponent(name); context.startActivity(intent); } public static void intentForward(Context context, Class<?> forwardClass) { Intent intent = new Intent(); intent.setClass(context, forwardClass); context.startActivity(intent); } public static void changeButtonState(View button, boolean editable) { if (editable) { button.setActivated(true); } else { button.setActivated(false); } } public static void changeArrawState(View leftArrowhead, View rightArrowhead, boolean show) { if (show) { if (leftArrowhead != null) { leftArrowhead.setVisibility(View.VISIBLE);// display } if (rightArrowhead != null) { rightArrowhead.setVisibility(View.VISIBLE); } } else { if (leftArrowhead != null) { leftArrowhead.setVisibility(View.INVISIBLE); } if (rightArrowhead != null) { rightArrowhead.setVisibility(View.INVISIBLE); } } } public static void changeLayoutState(RelativeLayout oneLayout, RelativeLayout twoLayout, boolean show) { if (show) { oneLayout.setBackgroundResource(R.drawable.desktop_button);// focus twoLayout.setBackgroundResource(R.drawable.one_px); } else { oneLayout.setBackgroundResource(R.drawable.one_px); twoLayout.setBackgroundResource(R.drawable.desktop_button); } } /** * show toast * * @param mContext * @param txt */ public static void ShowToast(Context mContext, String txt) { Toast toast = Toast.makeText(mContext, txt, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); };}
=========================================================================
2、PreferancesTools.java
package com.mstar.tvsettings.util;import android.content.Context;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;public class PreferancesTools { public static final String PROGRAM_SORT = "program_sort"; public static final String PROGRAM_LCN = "program_lcn"; public static final String PICTURE_ASPECT_RATIO = "picture_aspect_ratio"; public static final String PICTURE_TV_FORMAT = "picture_tv_format"; public static final String OPTION_SUBTITLE_LANGUAGE = "option_subtitle_language"; public static final String OPTION_AUDIO_LANGUAGE = "option_audio_language"; public static final String SYSTEM_PARENTAL_GUIDANCE_AGE = "sytem_parental_guidance_age"; public static final String TIME_SLEEP_STATE_KEY = "time_sleep_state_key"; private Context context; public PreferancesTools(Context context) { this.context = context; } public int getIntPref(String name, int defalut) { String pkg = context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); return prefs.getInt(name, defalut); } public void setIntPref(String name, int value) { String pkg = context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); Editor ed = prefs.edit(); ed.putInt(name, value); ed.commit(); } public String getStringPref(String name, String defalut) { String pkg = context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); return prefs.getString(name, defalut); } public void setStringPref(String name, String value) { String pkg = context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); Editor ed = prefs.edit(); ed.putString(name, value); ed.commit(); } public long getLongPref(String name, Long defalut) { String pkg = context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); return prefs.getLong(name, defalut); } public void setLongPref(String name, Long value) { String pkg = context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); Editor ed = prefs.edit(); ed.putLong(name, value); ed.commit(); } public boolean getBooleanPref(String name, boolean defValue) { String pkg = context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); return prefs.getBoolean(name, defValue); } public void setBooleanPref(String name, boolean value) { String pkg = context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); Editor ed = prefs.edit(); ed.putBoolean(name, value); ed.commit(); }}
- android开发常用公共
- android开发的一些常用不常用的公共方法
- android 公共组件Dialog开发
- iOS 开发 一些常用的公共方法
- Android动画常用公共属性详解
- ASP.NET开发Web常用函数公共类
- iOS 开发 关于字符串 常用的公共方法
- Java和Android中一些常用的公共方法
- Android 常用开发术语
- Android 开发常用网站
- Android 常用开发术语
- Android开发常用代码
- Android常用开发网站
- android 开发常用网站
- android 开发 常用。
- android开发-常用色彩
- Android 开发常用代码
- Android开发常用颜色
- cocos2dx——CCProgressTimer
- 页面执行顺序
- Android4.2.2 Gallery2源码分析(1)——从布局入手
- VB.NET串口通信例子
- OpenCV 2.4.6.1编译安装
- android开发常用公共
- 如何在hadoop中控制map的个数
- VM不能安装64位操作系统
- 解决Source Insight自动缩进及TAB键扩展为4个空格问题
- [LeetCode] Container With Most Water
- Myeclipse2013下载,安装,破解,介绍(CSDN首发)
- 查看库文件编译时所使用的GCC版本号
- DG 单对单 liunx,windows 平台搭建
- C#关于数据库查询信息赋值到combobox 下拉框中