Android Open Source - JiangHomeStyle_Android_Phone Async Init Home Data






From Project

Back to project page JiangHomeStyle_Android_Phone.

License

The source code is released under:

Apache License

If you think the Android project JiangHomeStyle_Android_Phone 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.cidesign.jianghomestylephone.async;
/* w  w w.j av a  2s .com*/
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import com.cidesign.jianghomestylephone.R;
import com.cidesign.jianghomestylephone.db.DatabaseHelper;
import com.cidesign.jianghomestylephone.entity.ArticleEntity;
import com.cidesign.jianghomestylephone.tools.CategoryDataLoadingLogic;
import com.cidesign.jianghomestylephone.tools.LoadingDataFromDB;
import com.cidesign.jianghomestylephone.tools.LoadingImageTools;
import com.cidesign.jianghomestylephone.tools.StorageUtils;
import com.cidesign.jianghomestylephone.tools.TimeTools;
import com.cidesign.jianghomestylephone.tools.WidgetCache;

public class AsyncInitHomeData extends AsyncTask<Void, Void, List<ArticleEntity>>
{
  private Activity activity;
  private int screen_width;
  private LoadingDataFromDB loadingDataFromDB = null;
  private DatabaseHelper dbHelper;
  private LayoutInflater inflater = null;

  private HashMap<Integer, View> widgetCache;

  public AsyncInitHomeData(Activity activity, DatabaseHelper dbHelper, LayoutInflater inflater, int screen_width)
  {
    this.activity = activity;
    this.dbHelper = dbHelper;
    this.inflater = inflater;
    this.screen_width = screen_width;
  }
  
  @Override
  protected void onPreExecute()
  {
    loadingDataFromDB = new LoadingDataFromDB();
    widgetCache = WidgetCache.getInstance().getViewCache();
  }
  
  @Override
  protected List<ArticleEntity> doInBackground(Void... params)
  {
    return loadingDataFromDB.loadTopFourArticle(dbHelper.getArticleListDataDao());
  }
  
  @Override
  protected void onPostExecute(List<ArticleEntity> list)
  {
    if (list != null && list.size() >= 1)
    {
      ArticleEntity aEntity = list.get(0);

      LoadingImageTools loadingImg = new LoadingImageTools();

      ImageView homeBgImg = (ImageView) widgetCache.get(R.id.homeBigBg);
      final VideoView mVideoView = (VideoView) widgetCache.get(R.id.videoView);

      if (aEntity.getMax_bg_img() == null || aEntity.getMax_bg_img().equals(""))
      {
        homeBgImg.setVisibility(View.VISIBLE);
        mVideoView.setVisibility(View.GONE);
        loadingImg.loadingNativeImage(activity, homeBgImg, "bg1.jpg");
      }
      else if (aEntity.getMax_bg_img().endsWith(".mp4"))
      {
        homeBgImg.setVisibility(View.GONE);
        if (mVideoView != null)
        {
          final String videoPath = "file://" + StorageUtils.FILE_ROOT + aEntity.getServerID() + "/"
              + aEntity.getMax_bg_img();          
          mVideoView.setVisibility(View.VISIBLE);
          mVideoView.setVideoPath(videoPath);
          mVideoView.start();
          mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
          {

            @Override
            public void onPrepared(MediaPlayer mp)
            {
              mp.start();
              mp.setLooping(true);

            }
          });

          mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
          {

            @Override
            public void onCompletion(MediaPlayer mp)
            {
              mVideoView.setVideoPath(videoPath);
              mVideoView.start();

            }
          });

          mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener()
          {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra)
            {
              Toast.makeText(activity, "????????????????!", Toast.LENGTH_LONG).show();
              return true;
            }
          });
        }
      }
      else
      {
        mVideoView.setVisibility(View.GONE);
        homeBgImg.setVisibility(View.VISIBLE);
        loadingImg
            .loadingImage(homeBgImg, StorageUtils.FILE_ROOT + aEntity.getServerID() + "/" + aEntity.getMax_bg_img());
      }
      ((TextView) widgetCache.get(R.id.homeArticleTitle)).setText(aEntity.getTitle());
      ((TextView) widgetCache.get(R.id.homeArticleTime)).setText(TimeTools.getTimeByTimestap(Long.parseLong(aEntity.getPost_date())));
      ((LinearLayout) widgetCache.get(R.id.homeLinearLayout)).setTag(aEntity);
      if (list.size() >= 2)
      {
        CategoryDataLoadingLogic.loadHeadLineData(list, (LinearLayout) widgetCache.get(R.id.recommandLayout),
            screen_width, inflater); // ????????
      }
    }
  }
}




Java Source Code List

com.cidesign.jianghomestylephone.DetailActivity.java
com.cidesign.jianghomestylephone.JiangActivity.java
com.cidesign.jianghomestylephone.MainActivity.java
com.cidesign.jianghomestylephone.SplashActivity.java
com.cidesign.jianghomestylephone.adapter.CommunityViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.HumanityViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.LandscapeViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.LayoutCaculateAdapter.java
com.cidesign.jianghomestylephone.adapter.StoryViewpagerAdapter.java
com.cidesign.jianghomestylephone.async.AsyncDownTask.java
com.cidesign.jianghomestylephone.async.AsyncInitCommunityData.java
com.cidesign.jianghomestylephone.async.AsyncInitData.java
com.cidesign.jianghomestylephone.async.AsyncInitHomeData.java
com.cidesign.jianghomestylephone.async.AsyncInitHumanityData.java
com.cidesign.jianghomestylephone.async.AsyncInitLandscapeData.java
com.cidesign.jianghomestylephone.async.AsyncInitStoryData.java
com.cidesign.jianghomestylephone.db.DatabaseConfigUtil.java
com.cidesign.jianghomestylephone.db.DatabaseHelper.java
com.cidesign.jianghomestylephone.entity.ArticleEntity.java
com.cidesign.jianghomestylephone.entity.FileListEntity.java
com.cidesign.jianghomestylephone.entity.LayoutEntity.java
com.cidesign.jianghomestylephone.entity.RelativeLayoutRulesEntity.java
com.cidesign.jianghomestylephone.http.ArticalOperation.java
com.cidesign.jianghomestylephone.http.DownLoadThread.java
com.cidesign.jianghomestylephone.service.DownloadService.java
com.cidesign.jianghomestylephone.tools.CategoryDataLoadingLogic.java
com.cidesign.jianghomestylephone.tools.FileOperationTools.java
com.cidesign.jianghomestylephone.tools.JiangCategory.java
com.cidesign.jianghomestylephone.tools.LayoutMarginSetting.java
com.cidesign.jianghomestylephone.tools.LoadingDataFromDB.java
com.cidesign.jianghomestylephone.tools.LoadingImageTools.java
com.cidesign.jianghomestylephone.tools.MD5Tools.java
com.cidesign.jianghomestylephone.tools.StorageUtils.java
com.cidesign.jianghomestylephone.tools.TimeTools.java
com.cidesign.jianghomestylephone.tools.WidgetCache.java
com.cidesign.jianghomestylephone.tools.XmlParseTools.java
com.cidesign.jianghomestylephone.version.NetworkTool.java
com.cidesign.jianghomestylephone.version.VersionConfig.java
com.cidesign.jianghomestylephone.version.VersionUpdate.java
com.cidesign.jianghomestylephone.widget.CommunityRelativeLayout.java
com.cidesign.jianghomestylephone.widget.CustomScrollView.java
com.cidesign.jianghomestylephone.widget.HScrollViewTouchLogic.java
com.cidesign.jianghomestylephone.widget.HumanityRelativeLayout.java
com.cidesign.jianghomestylephone.widget.LandscapeRelativeLayout.java
com.cidesign.jianghomestylephone.widget.PopMenu.java
com.cidesign.jianghomestylephone.widget.StoryRelativeLayout.java
org.apache.tools.zip.AbstractUnicodeExtraField.java
org.apache.tools.zip.AsiExtraField.java
org.apache.tools.zip.CentralDirectoryParsingZipExtraField.java
org.apache.tools.zip.ExtraFieldUtils.java
org.apache.tools.zip.FallbackZipEncoding.java
org.apache.tools.zip.GeneralPurposeBit.java
org.apache.tools.zip.JarMarker.java
org.apache.tools.zip.NioZipEncoding.java
org.apache.tools.zip.Simple8BitZipEncoding.java
org.apache.tools.zip.UnicodeCommentExtraField.java
org.apache.tools.zip.UnicodePathExtraField.java
org.apache.tools.zip.UnixStat.java
org.apache.tools.zip.UnparseableExtraFieldData.java
org.apache.tools.zip.UnrecognizedExtraField.java
org.apache.tools.zip.UnsupportedZipFeatureException.java
org.apache.tools.zip.Zip64ExtendedInformationExtraField.java
org.apache.tools.zip.Zip64Mode.java
org.apache.tools.zip.Zip64RequiredException.java
org.apache.tools.zip.ZipConstants.java
org.apache.tools.zip.ZipEightByteInteger.java
org.apache.tools.zip.ZipEncodingHelper.java
org.apache.tools.zip.ZipEncoding.java
org.apache.tools.zip.ZipEntry.java
org.apache.tools.zip.ZipExtraField.java
org.apache.tools.zip.ZipFile.java
org.apache.tools.zip.ZipLong.java
org.apache.tools.zip.ZipOutputStream.java
org.apache.tools.zip.ZipShort.java
org.apache.tools.zip.ZipUtil.java