Android Open Source - misound Main Activity2






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;
// ww  w  .j a va2 s  .co m
import android.app.AlertDialog;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import com.xiaomi.market.sdk.XiaomiUpdateAgent;
import com.xiaomi.mitv.soundbar.DefaultMisoundDevice;
import com.xiaomi.mitv.soundbar.bluetooth.A2dpProfile;
import com.xiaomi.mitv.soundbar.protocol.TraceInfo0x816;
import com.xiaomi.mitv.soundbar.provider.SoundBarORM;
import com.xiaomi.mitv.soundbarapp.fragment.MainEntryFragment;
import com.xiaomi.mitv.soundbarapp.fragment.PanelFragment;
import com.xiaomi.mitv.soundbarapp.player.PlayerFragment;

/**
 * Created by chenxuetong on 8/20/14.
 */
public class MainActivity2 extends FragmentActivity implements PanelFragment.PanelListener, PlayerFragment.OnPlayerStateListener{
    private static final String PANEL_TAG = "panel";
    private static final String ENTRY_WITH_PLAYER_TAG = "entry_player";
    private static final String ENTRY_TAG = "entry";

    private PanelFragment mPanel;
    private MainEntryFragment mEntries;
    private boolean mNoSourceNotified = false;
    private boolean mPhoneConnected2Bar = false;
    public static void go(Context context){
        Intent i = new Intent(context, MainActivity2.class);
        context.startActivity(i);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_main);

        mNoSourceNotified = false;
        Fragment f = getSupportFragmentManager().findFragmentByTag(PANEL_TAG);
        if(f==null){
            mPanel = new PanelFragment();
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragment_panel, mPanel, PANEL_TAG)
                    .commit();
        }else{
            mPanel = (PanelFragment)f;
        }
        mPanel.setInitListener(this);

        mEntries = showDefaultEntries(false);

        XiaomiUpdateAgent.update(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        A2dpProfile.close();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        new DefaultMisoundDevice(this).release();
        A2dpProfile.close();
//        android.os.Process.killProcess(android.os.Process.myPid());
    }

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

    @Override
    public void onPanelRefreshed(TraceInfo0x816 info) {
        mEntries = setupEntryFragment(info);
        mEntries.setSourceReady(BarInfoUtils.haveSource(info));

//        if(!isPhoneConnected2Bar()){
//            Fragment player = getSupportFragmentManager().findFragmentByTag(ENTRY_WITH_PLAYER_TAG);
//            if(player != null) {
//                PlayerFragment playerFragment = (PlayerFragment) player;
//                playerFragment.stopMusic();
//            }
//        }
    }

    @Override
    public void onMusicPlayState(boolean playing) {
        refreshDeviceInfoDelay(5000);
    }

    @Override
    public void onMusicChanged() {}

    public boolean isPhoneConnected2Bar(){
        return mPhoneConnected2Bar;
    }

    private MainEntryFragment setupEntryFragment(TraceInfo0x816 info){
        A2dpProfile thisPhone = new A2dpProfile(this);
        BluetoothDevice bar = A2dpProfile.getBarDevice(this);
        mPhoneConnected2Bar = BarInfoUtils.isA2dpConnected(info) && thisPhone.isConnected(bar);

        if(mPanel!=null && !mNoSourceNotified){
            if(!mPanel.supportNewUi()) {
                mNoSourceNotified = true;
                mEntries.enableSettings(false);
                mEntries.enableEq(false);

                String msg = "???????????????4.0.4??????";
                showAlert("????", msg, false);
            }else {
                mEntries.enableSettings(true);
                mEntries.enableEq(true);
            }
        }
        return mEntries;
    }

    public MainEntryFragment showDefaultEntries(boolean stop){
        Fragment player = getSupportFragmentManager().findFragmentByTag(MainEntryFragment.PLAYER_TAG);
        if(player != null) {
            PlayerFragment playerFragment = (PlayerFragment) player;
            if (stop) playerFragment.stopMusic();
        }

        Fragment enties = getSupportFragmentManager().findFragmentByTag(ENTRY_TAG);
        if(enties==null){
            enties = new MainEntryFragment();
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.main_entry_container, enties, ENTRY_TAG)
                    .commit();
        }
        return (MainEntryFragment)enties;
    }

    public void onFirmwareUpgrading(boolean enabled) {
        mEntries.enableSettings(enabled);
        mEntries.enableEq(enabled);
        mPanel.enableVolControl(enabled);
    }

    public void showEq(){
        if(mEntries != null){
            mEntries.showEq();
        }
    }

    public void showSettings(){
        if(mEntries != null){
            mEntries.showSettings();
        }
    }

    public boolean supportNewUi(){
        String ver = SoundBarORM.getSettingValue(this, SoundBarORM.dfuCurrentVersion);
        return ver.compareTo("4.0.4")>=0;
    }

    public boolean supportSource(){
        String ver = SoundBarORM.getSettingValue(this, SoundBarORM.dfuCurrentVersion);
        return ver.compareTo("4.0.4")>=0;
    }

    public void refreshDeviceInfoDelay(long delay){
        mPanel.refreshBarPanel(delay);
    }
}




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