Android Open Source - misound Faq Data Store






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.faq;
/*from  w w  w  .ja v a 2s .co m*/
import android.content.Context;
import com.xiaomi.mitv.content.FaqData;
import com.xiaomi.mitv.soundbarapp.provider.DataProvider;
import com.xiaomi.mitv.utils.IOUtil;

import java.io.*;

/**
 * Created by chenxuetong on 7/3/14.
 *
 * [
 *     {
 *         id:12111,
 *         title:q1.
 *         content:abcd
 *     },
 *     {
 *         id:22111,
 *         title:q2.
 *         content:abcd
 *     }
 * ]
 *
 */
public class FaqDataStore {
    private static final String ASSETS_DEFAULT_DATA_FILE = "faq/faq_list";
    private static final String QA_DATA_FILE_NAME = "faq_list";

    private final Context mContext;

    public FaqDataStore(Context context) {
        mContext = context;
    }


    public FaqData load() {
        InputStream input = null;
        try {
            input = getDataInputStream();
            return FaqData.loadString(new String(IOUtil.readInputAsBytes(input), "utf-8"));
        }catch (IOException e){
            return null;
        } finally {
            if(input!=null)try {input.close();}catch (IOException e){}
        }
    }

    public FaqData loadRemote() {
        DataProvider provider = new DataProvider();
        FaqData data = provider.queryFaqList();

        if(data != null) {
            File dataFile = new File(mContext.getFilesDir().getAbsolutePath() + "/" + QA_DATA_FILE_NAME);
            if (dataFile.exists()){
                dataFile.delete();
            }
            FileOutputStream fout = null;
            try {
                fout = new FileOutputStream(dataFile);
                fout.write(data.toString().getBytes("utf-8"));
                fout.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if(fout!=null) try{fout.close();}catch (Exception e){}
            }
        }
        return data;
    }

    public void refresh() {
        loadRemote();
    }


    private InputStream getDataInputStream() throws IOException {
        File dataFile = new File(mContext.getFilesDir().getAbsolutePath()+ "/"+QA_DATA_FILE_NAME);
        if(dataFile.exists()){
            return new FileInputStream(dataFile);
        }else{
            return mContext.getAssets().open(ASSETS_DEFAULT_DATA_FILE);
        }
    }
}




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