android开发常用公共

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

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值