Android Open Source - misound E Q Manager






From Project

Back to project page misound.

License

The source code is released under:

Apache License

If you think the Android project misound listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.xiaomi.mitv.soundbarapp.eq;
/*from   w w w  .j a v  a  2  s . c  o  m*/
import android.content.Context;
import android.util.SparseArray;
import com.xiaomi.mitv.soundbar.DefaultMisoundDevice;
import com.xiaomi.mitv.soundbar.IMiSoundDevice;
import com.xiaomi.mitv.soundbar.gaia.GaiaException;
import com.xiaomi.mitv.soundbar.protocol.UserEQ0x21A;
import com.xiaomi.mitv.soundbarapp.R;

import java.util.*;

/**
 * Created by chenxuetong on 8/28/14.
 */
public class EQManager {
    public static final int EQ_COSTUM = IMiSoundDevice.EQ_COSTUM;
    public static final int EQ_STANDARD = IMiSoundDevice.EQ_STANDARD;
    public static final int EQ_ROCK = IMiSoundDevice.EQ_ROCK;
    public static final int EQ_CLEAR = IMiSoundDevice.EQ_CLEAR;
    public static final int EQ_SOFT = IMiSoundDevice.EQ_LIGHT;

    public EQStyle findEqById(int id) {
        return mStyles.get(id);
    }

    public int idOfStyle(EQStyle style){
        if (style==null) return -1;
        for(int index=0; index<mStyles.size(); index++){
            if(mStyles.valueAt(index).equals(style)) return mStyles.keyAt(index);
        }
        return R.id.eq_style_custom;
    }

    public EQStyle readSoundBarStyle(Context context){
        IMiSoundDevice mibar = new DefaultMisoundDevice(context);
        try {
            int current_eq = mibar.getEQControl();
            if(current_eq == EQ_COSTUM) {
                EQStyle style = new EQStyle();
                for (int band : EQStyle.BANDS) {
                    UserEQ0x21A eq = new UserEQ0x21A(band, -1);
                    eq = mibar.getUserEQControl(eq);
                    if (eq != null) {
                        style.setGain(band, eq.mValue);
                    }
                }
                return style;
            }else{
                if(current_eq!=EQ_STANDARD) mibar.setEQControl(EQ_STANDARD);
                return mStyles.get(R.id.eq_style_standard);
            }
        }catch (GaiaException e){
            e.printStackTrace();
        }
        return null;
    }

    public boolean setUserEQ(Context context, int id){
        final EQStyle style = findEqById(id);
        if(style==null) return false;

        IMiSoundDevice mibar = new DefaultMisoundDevice(context);
        try {
            int current_Eq = mibar.getEQControl();

            boolean ok = true;
            if(id==R.id.eq_style_standard && current_Eq!=EQ_STANDARD){
                ok = mibar.setEQControl(EQ_STANDARD);
            }else {
                if(current_Eq!=EQ_COSTUM) ok=mibar.setEQControl(EQ_COSTUM);
                for (int band : EQStyle.BANDS) {
                    UserEQ0x21A eq = new UserEQ0x21A(band, style.getGain(band));
                    ok = ok && mibar.setUserEQControl(eq);
                }
            }
            return ok;
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    public EQStyleResource getResourceById(int id){
        return mResources.get(id);
    }

    private SparseArray<EQStyleResource> mResources = new SparseArray<EQStyleResource>();
    {
        mResources.put(R.id.eq_style_standard, new EQStyleResource(R.string.eq_standar,R.drawable.home_page_bg_xiaomisound_standard, R.drawable.home_page_button_xiaomisound_standard));
        mResources.put(R.id.eq_style_class, new EQStyleResource(R.string.eq_class,R.drawable.home_page_bg_xiaomisound_class, R.drawable.home_page_button_xiaomisound_class));
        mResources.put(R.id.eq_style_custom, new EQStyleResource(R.string.eq_custom,R.drawable.home_page_bg_xiaomisound_custom, R.drawable.home_page_button_xiaomisound_custom));
        mResources.put(R.id.eq_style_jazz, new EQStyleResource(R.string.eq_jazz,R.drawable.home_page_bg_xiaomisound_jazz, R.drawable.home_page_button_xiaomisound_jazz));
        mResources.put(R.id.eq_style_movie, new EQStyleResource(R.string.eq_movie,R.drawable.home_page_bg_xiaomisound_movie, R.drawable.home_page_button_xiaomisound_movie));
        mResources.put(R.id.eq_style_pop, new EQStyleResource(R.string.eq_pop,R.drawable.home_page_bg_xiaomisound_pop, R.drawable.home_page_button_xiaomisound_pop));
        mResources.put(R.id.eq_style_rock, new EQStyleResource(R.string.eq_rock,R.drawable.home_page_bg_xiaomisound_rock, R.drawable.home_page_button_xiaomisound_rock));
        mResources.put(R.id.eq_style_tv, new EQStyleResource(R.string.eq_tv,R.drawable.home_page_bg_xiaomisound_tv, R.drawable.home_page_button_xiaomisound_tv));
    }

    private SparseArray<EQStyle> mStyles = new SparseArray<EQStyle>();
    {
        mStyles.put(R.id.eq_style_standard, new EQStyle(0,0,0,0,0));
        mStyles.put(R.id.eq_style_movie, new EQStyle(8,0,5,4,2));
        mStyles.put(R.id.eq_style_tv, new EQStyle(0,-5,3,2,3));
        mStyles.put(R.id.eq_style_pop, new EQStyle(0,2,2,2,2));
        mStyles.put(R.id.eq_style_rock, new EQStyle(6,3,2,1,2));
        mStyles.put(R.id.eq_style_class, new EQStyle(-3,-2,0,-1,-4));
        mStyles.put(R.id.eq_style_jazz, new EQStyle(-2,3,3,4,-2));
    }

}




Java Source Code List

com.xiaomi.mitv.soundbar.DefaultMisoundDevice.java
com.xiaomi.mitv.soundbarapp.BarInfoUtils.java
com.xiaomi.mitv.soundbarapp.ConnectingActivity.java
com.xiaomi.mitv.soundbarapp.MainActivity2.java
com.xiaomi.mitv.soundbarapp.SoundBarApplication.java
com.xiaomi.mitv.soundbarapp.TestActivity.java
com.xiaomi.mitv.soundbarapp.TypefaceManager.java
com.xiaomi.mitv.soundbarapp.WrapperActivity.java
com.xiaomi.mitv.soundbarapp.diagnosis.DiagnosisFragment.java
com.xiaomi.mitv.soundbarapp.diagnosis.Engine.java
com.xiaomi.mitv.soundbarapp.diagnosis.ViewWrapper.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.Entry.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.Node.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.OrderedList.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.QAElement.java
com.xiaomi.mitv.soundbarapp.eq.EQManager.java
com.xiaomi.mitv.soundbarapp.eq.EQSettingsFragment.java
com.xiaomi.mitv.soundbarapp.eq.EQStyleResource.java
com.xiaomi.mitv.soundbarapp.eq.EQStyle.java
com.xiaomi.mitv.soundbarapp.eq.UserEQControlFragment.java
com.xiaomi.mitv.soundbarapp.faq.FaqDataStore.java
com.xiaomi.mitv.soundbarapp.faq.FaqFragment.java
com.xiaomi.mitv.soundbarapp.fragment.A2dpDlg.java
com.xiaomi.mitv.soundbarapp.fragment.BaseFragment.java
com.xiaomi.mitv.soundbarapp.fragment.FeedbackFragment.java
com.xiaomi.mitv.soundbarapp.fragment.MainEntryFragment.java
com.xiaomi.mitv.soundbarapp.fragment.PanelFragment.java
com.xiaomi.mitv.soundbarapp.fragment.SettingsFragment.java
com.xiaomi.mitv.soundbarapp.player.MediaButtonIntentReceiver.java
com.xiaomi.mitv.soundbarapp.player.MusicUtils.java
com.xiaomi.mitv.soundbarapp.player.PlayListFragment.java
com.xiaomi.mitv.soundbarapp.player.PlayerFragment.java
com.xiaomi.mitv.soundbarapp.player.PlayerService.java
com.xiaomi.mitv.soundbarapp.player.Player.java
com.xiaomi.mitv.soundbarapp.provider.DataProvider.java
com.xiaomi.mitv.soundbarapp.upgrade.FirmwareManager.java
com.xiaomi.mitv.soundbarapp.upgrade.FirmwareZipFile.java
com.xiaomi.mitv.soundbarapp.upgrade.UpdateActivity.java
com.xiaomi.mitv.soundbarapp.upgrade.UpgradeFragment.java
com.xiaomi.mitv.soundbarapp.upgrade.VersionSelectFragment.java
com.xiaomi.mitv.soundbarapp.util.ConfirmActivityDlg.java
com.xiaomi.mitv.soundbarapp.util.Worker.java
com.xiaomi.mitv.widget.GainView.java
com.xiaomi.mitv.widget.GifView.java
com.xiaomi.mitv.widget.LetterIndexSilderBar.java
com.xiaomi.mitv.widget.MiSwitch.java
com.xiaomi.mitv.widget.RoundAnimationView.java
com.xiaomi.mitv.widget.RoundProgressBar.java
com.xiaomi.mitv.widget.RoundSeekBar.java