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

原创粉丝点击