Skip to content

Instantly share code, notes, and snippets.

@xxnjdlys
Created December 29, 2014 12:44
Show Gist options
  • Save xxnjdlys/5c00f4879de8a809273c to your computer and use it in GitHub Desktop.
Save xxnjdlys/5c00f4879de8a809273c to your computer and use it in GitHub Desktop.
package com.wukongtv.wkremote.client.tv;
import android.text.TextUtils;
import android.view.KeyEvent;
import com.wukongtv.wkremote.client.ControlImpl.ControlMiddleware;
import com.wukongtv.wkremote.client.R;
import java.util.HashMap;
/**
* TV & DogTag
* Created by zhangge on 14-11-5.
*/
public class TVDogTagManager {
private static final int FLAG_UP_NEXT = 1; //1
private static final int FLAG_DOWN_NEXT = 1 << 1; //2
private static final int FLAG_LEFT_VOLUME_UP = 1 << 2; //4
private static final int FLAG_RIGHT_VOLUME_UP = 1 << 3; // 8
private static final int FLAG_LEFT_CHANGE_SOURCE = 1 << 4; //16
private static final int FLAG_RIGHT_CHANGE_SOURCE = 1 << 5; //32
private static HashMap<String, Integer> sPackageTypeMap;
static {
sPackageTypeMap = new HashMap<String, Integer>();
sPackageTypeMap.put("com.elinkway.tvlive2", 9);
sPackageTypeMap.put("hdpfans.com", 49);
sPackageTypeMap.put("xlcao.sohutv4", 50);
sPackageTypeMap.put("com.eagletv.live", 10);
sPackageTypeMap.put("com.ott.qingsi.live", 9);
sPackageTypeMap.put("com.kaiboertvlive.activity", 49);
sPackageTypeMap.put("com.iflyor.binfuntv", 50);
sPackageTypeMap.put("com.sunchip.livetv", 49);
sPackageTypeMap.put("com.androidx.live", 49);
sPackageTypeMap.put("com.mylove.bslive", 49);
sPackageTypeMap.put("com.giec.live", 49);
sPackageTypeMap.put("com.sunchip.livetv2", 49);
sPackageTypeMap.put("com.tvlive.vodapp4tvlive", 49);
}
private TVDogTagManager() {
mCurrentName = "";
mCurrentPackage = "";
}
private static TVDogTagManager sInstance;
public static TVDogTagManager getInstance() {
if (sInstance == null) {
synchronized (TVDogTagManager.class) {
if (sInstance == null) {
sInstance = new TVDogTagManager();
}
}
}
return sInstance;
}
/**
* current app info
* whether it is a live tv app
*/
private String mCurrentPackage;
private String mCurrentName;
/**
* sync current running package
*
* @param pkg package name
* @return true if it is a live tv app
*/
public boolean syncCurrentRunningPackage(String pkg, String name) {
if (TextUtils.isEmpty(name)) {
mCurrentName = "";
} else {
mCurrentName = name;
}
mCurrentPackage = pkg;
return isCurrentAppLiveTV();
}
public String getCurrentPackage() {
return mCurrentPackage;
}
public String getCurrentAppName() {
return mCurrentName;
}
public boolean isCurrentAppLiveTV() {
return sPackageTypeMap.containsKey(mCurrentPackage);
}
public void nextChannel() {
if (sPackageTypeMap.containsKey(mCurrentPackage)) {
int flag = sPackageTypeMap.get(mCurrentPackage);
if ((flag & FLAG_UP_NEXT) > 0) {
ControlMiddleware.getInstance().sendKey(KeyEvent.KEYCODE_DPAD_UP);
} else if ((flag & FLAG_DOWN_NEXT) > 0) {
ControlMiddleware.getInstance().sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
}
}
}
/**
* get up text
*
* @return the resource of the string, 0 for nothing
*/
public int getUpTextId() {
if (sPackageTypeMap.containsKey(mCurrentPackage)) {
int flag = sPackageTypeMap.get(mCurrentPackage);
if ((flag & FLAG_UP_NEXT) > 0) {
return R.string.live_hint_next_channel;
} else if ((flag & FLAG_DOWN_NEXT) > 0) {
return R.string.live_hint_previous_channel;
}
}
return 0;
}
public int getDownTextId() {
if (sPackageTypeMap.containsKey(mCurrentPackage)) {
int flag = sPackageTypeMap.get(mCurrentPackage);
if ((flag & FLAG_UP_NEXT) > 0) {
return R.string.live_hint_previous_channel;
} else if ((flag & FLAG_DOWN_NEXT) > 0) {
return R.string.live_hint_next_channel;
}
}
return 0;
}
public int getRightTextId() {
if (sPackageTypeMap.containsKey(mCurrentPackage)) {
int flag = sPackageTypeMap.get(mCurrentPackage);
if ((flag & FLAG_LEFT_VOLUME_UP) > 0) {
return R.string.live_hint_volume_down;
} else if ((flag & FLAG_RIGHT_VOLUME_UP) > 0) {
return R.string.live_hint_volume_up;
} else {
if ((flag & FLAG_RIGHT_CHANGE_SOURCE) > 0) {
return R.string.live_hint_change_source;
}
}
}
return 0;
}
public int getLeftTextId() {
if (sPackageTypeMap.containsKey(mCurrentPackage)) {
int flag = sPackageTypeMap.get(mCurrentPackage);
if ((flag & FLAG_LEFT_VOLUME_UP) > 0) {
return R.string.live_hint_volume_up;
} else if ((flag & FLAG_RIGHT_VOLUME_UP) > 0) {
return R.string.live_hint_volume_down;
} else {
if ((flag & FLAG_LEFT_CHANGE_SOURCE) > 0) {
return R.string.live_hint_change_source;
}
}
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment