Issue # 2344 OpenCV Manager doesn't tell which pack is used fixed.

This commit is contained in:
Alexander Smorkalov 2012-09-11 16:10:15 +04:00
parent 84087a8566
commit a699594854
3 changed files with 115 additions and 44 deletions
android/service/engine
res/layout
src/org/opencv/engine/manager

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="fill_parent"
android:focusable="false" android:focusable="false"
android:orientation="vertical" > android:orientation="vertical" >

@ -47,11 +47,11 @@ public class ManagerActivity extends Activity
mMarket = new MarketConnector(this); mMarket = new MarketConnector(this);
mInstalledPacksAdapter = new SimpleAdapter( mInstalledPacksAdapter = new PackageListAdapter(
this, this,
mListViewItems, mListViewItems,
R.layout.info, R.layout.info,
new String[] {"Name", "Version", "Hardware"}, new String[] {"Name", "Version", "Hardware", "Activity"},
new int[] {R.id.InfoName,R.id.InfoVersion, R.id.InfoHardware} new int[] {R.id.InfoName,R.id.InfoVersion, R.id.InfoHardware}
); );
@ -158,7 +158,7 @@ public class ManagerActivity extends Activity
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long id) { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long id) {
mInstalledPackageView.setTag(new Integer((int)id)); mInstalledPackageView.setTag(Integer.valueOf((int)id));
mActionDialog.show(); mActionDialog.show();
} }
}); });
@ -188,6 +188,7 @@ public class ManagerActivity extends Activity
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Log.d(TAG, "Filling package list on resume");
FillPackageList(); FillPackageList();
} }
@ -195,15 +196,18 @@ public class ManagerActivity extends Activity
protected ListView mInstalledPackageView; protected ListView mInstalledPackageView;
protected Button mUpdateEngineButton; protected Button mUpdateEngineButton;
protected PackageInfo[] mInstalledPackageInfo; protected PackageInfo[] mInstalledPackageInfo;
protected static final ArrayList<HashMap<String,String>> mListViewItems = new ArrayList<HashMap<String,String>>(); protected final ArrayList<HashMap<String,String>> mListViewItems = new ArrayList<HashMap<String,String>>();
protected static final String TAG = "OpenCV_Manager/Activity";
protected MarketConnector mMarket; protected MarketConnector mMarket;
AlertDialog mActionDialog; protected AlertDialog mActionDialog;
protected HashMap<String,String> mActivePackageMap = new HashMap<String, String>();
protected BroadcastReceiver mPackageChangeReciever = new BroadcastReceiver() { protected BroadcastReceiver mPackageChangeReciever = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.d("OpenCV Manager/Reciever", "Bradcast message " + intent.getAction() + " reciever"); Log.d("OpenCV Manager/Reciever", "Bradcast message " + intent.getAction() + " reciever");
Log.d("OpenCV Manager/Reciever", "Filling package list on broadcast message");
FillPackageList(); FillPackageList();
} }
}; };
@ -224,50 +228,83 @@ public class ManagerActivity extends Activity
EngineVersionView.setText("not avaliable"); EngineVersionView.setText("not avaliable");
e.printStackTrace(); e.printStackTrace();
} }
try {
String path = EngineService.getLibPathByVersion("2.4");
Log.d(TAG, "2.4 -> " + path);
mActivePackageMap.put("24", path);
path = EngineService.getLibPathByVersion("2.5");
Log.d(TAG, "2.5 -> " + path);
mActivePackageMap.put("25", path);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d(TAG, "Filling package list on service connection");
FillPackageList();
unbindService(mServiceConnection); unbindService(mServiceConnection);
} }
}; };
protected void FillPackageList() protected void FillPackageList()
{ {
mInstalledPackageInfo = mMarket.GetInstalledOpenCVPackages(); synchronized (mListViewItems) {
mListViewItems.clear(); mInstalledPackageInfo = mMarket.GetInstalledOpenCVPackages();
mListViewItems.clear();
for (int i = 0; i < mInstalledPackageInfo.length; i++) for (int i = 0; i < mInstalledPackageInfo.length; i++)
{ {
// Convert to Items for package list view // Convert to Items for package list view
HashMap<String,String> temp = new HashMap<String,String>(); HashMap<String,String> temp = new HashMap<String,String>();
temp.put("Name", mMarket.GetApplicationName(mInstalledPackageInfo[i].applicationInfo)); String PublicName = mMarket.GetApplicationName(mInstalledPackageInfo[i].applicationInfo);
int idx = 0; int idx = 0;
String OpenCVersion = "unknown"; String OpenCVersion = "unknown";
String HardwareName = ""; String HardwareName = "";
StringTokenizer tokenizer = new StringTokenizer(mInstalledPackageInfo[i].packageName, "_"); StringTokenizer tokenizer = new StringTokenizer(mInstalledPackageInfo[i].packageName, "_");
while (tokenizer.hasMoreTokens()) while (tokenizer.hasMoreTokens())
{ {
if (idx == 1) if (idx == 1)
{ {
// version of OpenCV // version of OpenCV
OpenCVersion = tokenizer.nextToken().substring(1); OpenCVersion = tokenizer.nextToken().substring(1);
} }
else if (idx >= 2) else if (idx >= 2)
{ {
// hardware options // hardware options
HardwareName += tokenizer.nextToken() + " "; HardwareName += tokenizer.nextToken() + " ";
} }
else else
{ {
tokenizer.nextToken(); tokenizer.nextToken();
} }
idx++; idx++;
} }
temp.put("Version", NormalizeVersion(OpenCVersion, mInstalledPackageInfo[i].versionName)); String ActivePackagePath;
temp.put("Hardware", HardwareName); ActivePackagePath = mActivePackageMap.get(OpenCVersion);
mListViewItems.add(temp); Log.d(TAG, OpenCVersion + " -> " + ActivePackagePath);
}
mInstalledPacksAdapter.notifyDataSetChanged(); if (null != ActivePackagePath && ActivePackagePath.indexOf(mInstalledPackageInfo[i].packageName) >= 0)
{
temp.put("Activity", "y");
PublicName += " (Active)";
}
else
{
temp.put("Activity", "n");
}
temp.put("Name", PublicName);
temp.put("Version", NormalizeVersion(OpenCVersion, mInstalledPackageInfo[i].versionName));
temp.put("Hardware", HardwareName);
mListViewItems.add(temp);
}
mInstalledPacksAdapter.notifyDataSetChanged();
}
} }
protected String NormalizeVersion(String OpenCVersion, String PackageVersion) protected String NormalizeVersion(String OpenCVersion, String PackageVersion)

@ -0,0 +1,34 @@
package org.opencv.engine.manager;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
public class PackageListAdapter extends SimpleAdapter {
public PackageListAdapter(Context context,
List<? extends Map<String, ?>> data, int resource, String[] from,
int[] to) {
super(context, data, resource, from, to);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
@SuppressWarnings("unchecked")
Map<String, String> item = (Map<String, String>)getItem(position);
Log.d("PackageListAdapter", item.get("Activity"));
if (item.get("Activity") != "n")
{
view.setBackgroundColor(0x50ffffff);
}
return view;
}
}