Android Open Source - misound Diagnosis Fragment






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.diagnosis;
//ww  w. j  ava  2s .  com
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.*;
import android.widget.Toast;
import com.xiaomi.mitv.idata.util.iDataCenterORM;
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.ByteUtil;
import com.xiaomi.mitv.soundbar.protocol.TraceInfo0x816;
import com.xiaomi.mitv.soundbarapp.R;
import com.xiaomi.mitv.soundbar.provider.SoundBarORM;
import com.xiaomi.mitv.soundbarapp.WrapperActivity;
import com.xiaomi.mitv.soundbarapp.fragment.BaseFragment;
import com.xiaomi.mitv.utils.Log;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by chenxuetong on 7/10/14.
 */
public class DiagnosisFragment extends BaseFragment implements View.OnClickListener {
    private ViewWrapper mUIContainer;
    private Engine mEngine;
    private OnListener mListener;
    private View mMainView;
    private SoundBarCheckTask mCheckTask;

    public interface OnListener{
        void goBack();
        void goFeedback();
        void goFaq();
    }

    public static DiagnosisFragment newInstance(OnListener listener){
        return new DiagnosisFragment(listener);
    }

    public DiagnosisFragment(){}
    private DiagnosisFragment(OnListener listener) {
        mListener = listener;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mUIContainer = new ViewWrapper();
        mMainView = mUIContainer.create(inflater, container);
        return mMainView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mEngine = new Engine(getActivity());
        mUIContainer.onActivityReady(getActivity(), this);
        mUIContainer.showLoading(true);
        mConfigLoader.execute();

        mMainView.findViewById(R.id.actionbar).setOnClickListener(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mConfigLoader.cancel(true);
        if(mCheckTask != null){
            mCheckTask.cancel(false);
            mCheckTask  = null;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.actionbar:
                if(mListener!=null) mListener.goBack();
                break;
            case R.id.category_bbs:
                goBBs();
                break;
            case R.id.category_faq:
                goFaq();
                break;
        }
    }

    private void goFaq(){
        WrapperActivity.go(getActivity(), WrapperActivity.FRAGMENT_FAQ);
    }

    private void goBBs(){
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("http://bbs.xiaomi.cn/forum.php?mod=forumdisplay&fid=681&filter=typeid&typeid=4654"));
        startActivity(i);
    }

    private void showLoading(boolean loading){
        mMainView.findViewById(R.id.examine_loading).setVisibility(loading?View.VISIBLE:View.GONE);
//        mMainView.findViewById(R.id.examine_content).setVisibility(loading?View.GONE:View.VISIBLE);
    }

    private void doExamine() {
        String ver = SoundBarORM.getSettingValue(getActivity(), SoundBarORM.dfuCurrentVersion);
        if(ver.compareTo("4.0.4")<0){
            showAlert("????", "???????????4.0.4?????????????????????");
            return;
        }
        showLoading(true);
        mCheckTask = new SoundBarCheckTask();
        mCheckTask.execute();
    }

    private void showAlert(String title, String msg) {
        new AlertDialog.Builder(getActivity())
                .setTitle(title)
                .setMessage(msg)
                .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create()
                .show();
    }

    @Override
    public boolean onBackPressed() {
        return mUIContainer.onActivityBackPressed();
    }

    public void go2Feedback(){
        if(mListener!=null) mListener.goFeedback();
    }

    public void goBack() {
        if(mListener!=null) mListener.goBack();
    }

    private AsyncTask<Void, Void, Boolean> mConfigLoader = new AsyncTask<Void, Void, Boolean>() {
        @Override
        protected Boolean doInBackground(Void... params) {
            return mEngine.init();
        }

        @Override
        protected void onPostExecute(Boolean loadded) {
            if(isCancelled()) return;
            if(loadded) {
                mUIContainer.showLoading(false);
                mEngine.bindView(mUIContainer);
            }else{
                Toast.makeText(getActivity(), "????????????????", Toast.LENGTH_LONG).show();
            }
        }
    };

    private class SoundBarCheckTask extends AsyncTask<Void, Void, String>{
        @Override
        protected String doInBackground(Void... params) {
            IMiSoundDevice mibar = new DefaultMisoundDevice(getActivity());
            try {
                String info = mibar.querySystemTraceInfo();
                reportTrace2Cloud(info);
                Log.logD("0x816: " + info);
                    JSONObject o = new JSONObject(info);
                    return o.getString("raw");
            } catch (GaiaException e ){
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            if(isCancelled()) return;
            showLoading(false);
            if(s==null){
                Toast.makeText(getActivity(), "?????????", Toast.LENGTH_LONG).show();
                return;
            }

            Log.logD("info: " + s);
            byte[] raw = ByteUtil.HexString2Bytes(s);
            TraceInfo0x816 info = new TraceInfo0x816();
            if(!info.parse(raw)){
                Toast.makeText(getActivity(), "??????????!", Toast.LENGTH_LONG).show();
                return;
            }

            StringBuffer buffer = new StringBuffer();
            String source = info.mAutoRouting.str_source();
            boolean wooferConnected = info.mAutoRouting.woofer_ready;
            buffer.append("????????").append(source.equals("none")?"??":source).append("\n");
            buffer.append("???????").append(info.mAutoRouting.woofer_ready ? "???" : "???").append("\n");
            int soundBarVol = info.mSoundBar.volumeOfSource(info.mAutoRouting.audio_source);
            if(soundBarVol>=0) {
                buffer.append("MiBar????").append(precent(soundBarVol, 31)).append("\n");
            }
            int wooferVol = info.mSubwoofer.volumeOfSource(info.mAutoRouting.audio_source);
            if(wooferVol>=0){
                buffer.append("???????").append(precent(wooferVol, 31)).append("\n");
            }
            buffer.append("?????????").append(info.mSoundBar.safety_mode?"??":"??").append("\n");

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
                    .setTitle("??????")
                    .setMessage(buffer.toString());
            if(!wooferConnected){
                builder.setNegativeButton("?????", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        connect2Woofer();
                    }
                });
            }
            builder.setPositiveButton("??", null)
                    .create()
                    .show();
        }

        private void reportTrace2Cloud(String info){
            iDataCenterORM.getInstance(getActivity()).sendDataBack("hw_state", info);
        }

        private String precent(int v, int max){
            return String.valueOf(v*100/max)+"%";
        }
        private void connect2Woofer(){
            new AsyncTask<Void,Void,Void>(){
                @Override
                protected Void doInBackground(Void... params) {
                    try{new DefaultMisoundDevice(getActivity()).connectWoofer();}catch (GaiaException e){e.printStackTrace();}
                    return null;
                }
            }.execute();
        }
    };
}




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