package com.tv.ui.metro.utils; import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.util.Log;import android.view.View; import com.thunder.ktv.thunderjni.thunderapi.TDHotspot;import com.tv.ui.metro.MainActivity;import com.tv.ui.metro.model.GenericSubjectItem;import com.tv.ui.metro.model.KtvMainModuleDisplayItem;import com.tv.ui.metro.view.KtvLogoView; import java.lang.ref.WeakReference;import java.util.ArrayList; /** * Created by Administrator on 16-4-5. */public class ActivityHelper { public static class MainHandler extends Handler { private static MainHandler _this; public static final int MAIN_MODULE_JSON_READY = 1; public static final int LEFT_TOP_HST_READY = 2; public static String KEY_RAW_JSON = "raw_json"; public static String KEY_LEFT_TOP_LIST = "lt_list"; WeakReference<Activity> mActivityReference; MainHandler(Activity activity) { super(activity.getMainLooper()); mActivityReference = new WeakReference<Activity>(activity); } public static MainHandler getInstance(Activity activity) { if (_this == null) { _this = new MainHandler(activity); } return _this; } @Override public void handleMessage(Message msg) { final MainActivity activity = (MainActivity) mActivityReference.get(); Bundle b; if (activity != null) { switch (msg.what) { case MAIN_MODULE_JSON_READY: Log.d("MainActivity", "handleMessage MAIN_MODULE_JSON_READY"); //更新UI b = msg.getData(); GenericSubjectItem<KtvMainModuleDisplayItem> json = (GenericSubjectItem<KtvMainModuleDisplayItem>) b.getSerializable(KEY_RAW_JSON); activity.updateTabsAndMetroUI(json); activity.getTabHost().requestLayout(); final View tabView = activity.getTabs().getChildTabViewAt(activity.getViewPager().getCurrentItem()); tabView.post(new Runnable() { @Override public void run() { tabView.requestFocus(); } }); break; case LEFT_TOP_HST_READY: Log.d("MainActivity", "handleMessage LEFT_TOP_HST_READY"); b = msg.getData(); b.getSerializable(KEY_LEFT_TOP_LIST); KtvLogoView lv = activity.getLogoView(); lv = new KtvLogoView(activity); activity.setLogoView(lv); lv.setHsList((ArrayList<TDHotspot>) b.getSerializable("lt_list")); break; } } } }}
时间: 2024-10-23 08:58:24