Android Open Source - misound Version Select 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.upgrade;
/*from  w ww.  j  a v  a 2s.  co  m*/
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.xiaomi.mitv.content.FirmwareVersion;
import com.xiaomi.mitv.soundbar.provider.SoundBarORM;
import com.xiaomi.mitv.soundbarapp.R;
import com.xiaomi.mitv.soundbarapp.provider.DataProvider;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by chenxuetong on 7/31/14.
 */
public class VersionSelectFragment extends DialogFragment implements View.OnClickListener {
    private ViewGroup mMainView;
    private Spinner mVersionSpinner;
    private VersionLoader mLoader;
    private UpgradeFragment mUpgrade;

    private List<FirmwareVersion> mVersions = Collections.emptyList();
    private VersionAdapter mAdapter;

    public void setUpgradeHandler(UpgradeFragment handler){
        mUpgrade = handler;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mMainView = (ViewGroup)inflater.inflate(R.layout.upgrade_version_selection, container, false);
        return mMainView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        getDialog().setTitle(R.string.upgrade_version_selection_title);
        mVersionSpinner = (Spinner)mMainView.findViewById(R.id.upgrade_version_list);

        mAdapter = new VersionAdapter();
        mVersionSpinner.setAdapter(mAdapter);
        mVersionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                onItemChecked(view);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        mMainView.findViewById(R.id.upgrade_execute).setOnClickListener(this);

        mLoader = new VersionLoader();
        mLoader.execute();
    }

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

    private void onItemChecked(View item){
        ViewHolder holder = (ViewHolder)item.getTag();
        FirmwareVersion version = holder.mVersion;
        holder.mVersionDesc.setText(version.description);
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.upgrade_execute){
            ViewHolder holder = (ViewHolder)mVersionSpinner.getSelectedView().getTag();
            mVersions = Collections.emptyList();
            getFragmentManager().popBackStack();
            mUpgrade.forceUpgrade(holder.mVersion);
        }
    }

    private class ViewHolder{
        TextView mVersionName;
        TextView mVersionRelease;
        TextView mVersionDesc;
        FirmwareVersion mVersion;
    }

    private class VersionAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return mVersions.size();
        }

        @Override
        public Object getItem(int position) {
            if(position<0 || position>mVersions.size()) return null;
            return mVersions.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            if(convertView==null){
                LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                final ViewGroup item = (ViewGroup)inflater.inflate(R.layout.upgrade_version_item, parent, false);
                ViewHolder holder = new ViewHolder();
                holder.mVersionName = (TextView)item.findViewById(R.id.version_name);
                holder.mVersionRelease = (TextView)item.findViewById(R.id.release_flag);
                holder.mVersionDesc = (TextView)mMainView.findViewById(R.id.version_desc);
                item.setTag(holder);
                convertView = item;
            }

            ViewHolder holder = (ViewHolder)convertView.getTag();
            FirmwareVersion version = mVersions.get(position);
            holder.mVersionName.setText("??:"+version.codeName + "(" + version.code + ")");
            holder.mVersionRelease.setText(version.strFlag());
            holder.mVersion = version;
            return convertView;
        }
    }

    private class VersionLoader extends AsyncTask<Void,Void,List<FirmwareVersion>>{
        @Override
        protected void onPreExecute() {
            mMainView.findViewById(R.id.progress).setVisibility(View.VISIBLE);
            mMainView.findViewById(R.id.upgrade_execute).setVisibility(View.GONE);
            mMainView.findViewById(R.id.upgrade_version_list).setVisibility(View.GONE);
            mMainView.findViewById(R.id.version_desc).setVisibility(View.GONE);
        }

        @Override
        protected List<FirmwareVersion> doInBackground(Void... params) {
            List<FirmwareVersion> targets = new ArrayList<FirmwareVersion>();
            List<FirmwareVersion> versions = new DataProvider().listVersion();
            String currentVersion = SoundBarORM.getSettingValue(getActivity(), SoundBarORM.dfuCurrentVersion);
            for(FirmwareVersion v : versions){
                if(v.codeName.equals(currentVersion)){
                    continue;
                }
                boolean have = false;
                for(FirmwareVersion t : targets){
                    if(t.flag == v.flag){
                        have = true;
                        break;
                    }
                }
                if(!have){
                    targets.add(v);
                }
            }
            return targets;
        }

        @Override
        protected void onPostExecute(List<FirmwareVersion> versions) {
            if(isCancelled() || versions==null ) return;
            mVersions = versions;
            mAdapter.notifyDataSetChanged();
            mVersionSpinner.setSelection(0);
            mMainView.findViewById(R.id.progress).setVisibility(View.GONE);
            mMainView.findViewById(R.id.upgrade_execute).setVisibility(View.VISIBLE);
            mMainView.findViewById(R.id.upgrade_version_list).setVisibility(View.VISIBLE);
            mMainView.findViewById(R.id.version_desc).setVisibility(View.VISIBLE);
        }
    }
}




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