Report is not updated in blackberry analytic - blackberry

I have developed the demo application of blackberry analytic service but report is not updated in my account my program is..
public class MyApp extends WebtrendsUiApplication {
public static void main(String[] args) {
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp() {
WebtrendsConfigurator.LoadConfigFile(new AnalyticsConfig());
WebtrendsDataCollector wtDC = WebtrendsDataCollector.getInstance();
wtDC.Initialize();
pushScreen(new MyScreen());
}
private class AnalyticsConfig extends WebtrendsConfig {
public String wt_dc_app_name() {
return "sample";
}
public String wt_dc_app_version() {
return "1.0.1";
}
public String wt_dc_dcsid() {
return "dcswcrmlj9dv0hgctfq9y6lw8_3w4g"; // Analytics Demo
}
public String wt_dc_debug() {
return "true";
}
public String wt_dc_timezone() {
return "+5";
}
public String wt_dc_url() {
return "http://dc.webtrends.com/v1";
}
public String wt_dc_app_category() {
return "Utilities";
}
public String wt_dc_app_publisher() {
return "abc";
}
}
}
public final class MyScreen extends MainScreen implements FieldChangeListener{
ButtonField b;
public MyScreen() {
b=new ButtonField();
b.setChangeListener(this);
add(b);
}
public boolean onClose() {
try {
WebtrendsDataCollector.getInstance().onApplicationTerminate("Application Terminate", null);
} catch (IllegalWebtrendsParameterValueException err) {
WebtrendsDataCollector.getLog().e(err.getMessage());
}
System.exit(0);
return true;
}
public void fieldChanged(Field field, int context) {
if(field==b){
try {
WebtrendsDataCollector.getInstance().onAdClickEvent("/mainscreen", "Main Screen", "menu", null, "Demo Ad");
} catch (IllegalWebtrendsParameterValueException e1) {
System.out.println(e1.toString());
e1.printStackTrace();
}
}
}
}
please find where is the problem. I have changed only the dcsid in the application .

I know this question is quite old..but I wrote like a group of class u can use.. https://bitbucket.org/folorunsho1/googleanalyticsforblackberry

Related

How can I inject Optional<T> with hk2?

I have a Factory that looks at some property to determine if the value T should be provided. How can I use this with HK2 in an abstract binder?
public interface Printer {
void print(String str);
}
public ConsolePrinter implements Printer {
public void print(String str) {
System.out.println(str);
}
}
public PrinterFactory implements Factory<Optional<Printer>> {
boolean isPrinterAvailable;
public PrinterFactory(boolean isPrinterAvailable) {
this.isPrinterAvailable = isPrinterAvailable;
}
public Optional<Printer> provide() {
if (this.isPrinterAvailable) {
return new ConsolePrinter();
}
return Optional.empty();
}
}
public class Binder extends AbstractBinder {
protected void configure() {
// ?????
bindFactory(PrinterFactory.class).to(Printer.class);
}
}
Any help/documentation/examples is much appreciated!

Updating adapter of AutoCompleteTextView from LiveData

I have a AutoCompleteTextView that I give it 2 different adapters depending on the amount of text that is being present at the textview - if it has 0 characters I want it to display a list of "recently searched" strings adapter, while if it has more than 1 characters I want it to display auto completion list.
My getRecentlySearchedQueries method along with the RecentSearchedViewModel-
private List<String> recentlySearchedQueries = new ArrayList<>(); // pasted from the top of the class
#Override
public void getRecentlySearchedQueries() {
recentSearchViewModel.getAllQueries().observe(getActivity(), databaseRecentlySearchList -> {
if (databaseRecentlySearchList == null) {
return;
}
for (int i = 0; i < databaseRecentlySearchList.size(); i++) {
Log.d("localDBValue", "Added value - " + databaseRecentlySearchList.get(i).toString() + "\n");
String query = databaseRecentlySearchList.get(i).getQuery();
recentlySearchedQueries.add(query);
}
//Log.d("localDBValue", "recent search list value - " + recentlySearchedQueries);
});
}
public class RecentSearchViewModel extends AndroidViewModel {
private RecentSearchRepository recentSearchRepository;
private LiveData<List<RecentSearchModel>> allRecentlySearched;
public RecentSearchViewModel(#NonNull Application application) {
super(application);
recentSearchRepository = new RecentSearchRepository(application);
allRecentlySearched = recentSearchRepository.getAllRecentSearches();
}
public void insert(RecentSearchModel model) {
recentSearchRepository.insert(model);
}
public void update(RecentSearchModel model) {
// add implementation in the future if needed
}
public void delete(RecentSearchModel model) {
// add implementation in the future if needed
}
public LiveData<List<RecentSearchModel>> getAllQueries() {
return allRecentlySearched;
}
}
public class RecentSearchRepository {
private RecentSearchDao recentSearchDao;
private LiveData<List<RecentSearchModel>> allRecentSearches;
public RecentSearchRepository(Application application) {
MarketplaceDatabase database = MarketplaceDatabase.getRecentSearchInstance(application);
recentSearchDao = database.recentSearchDao();
allRecentSearches = recentSearchDao.getRecentSearchList();
}
public void insert(RecentSearchModel model) {
new RecentSearchRepository.InsertRecentSearchAsyncTask(recentSearchDao).execute(model);
}
public void update (RecentSearchModel model) {
//TODO - implement in future if needed
}
public void delete(RecentSearchModel model) {
//TODO - implement in future if needed
}
public LiveData<List<RecentSearchModel>> getAllRecentSearches() {
return allRecentSearches;
}
private static class InsertRecentSearchAsyncTask extends AsyncTask<RecentSearchModel, Void, Void> {
private RecentSearchDao recentSearchDao;
public InsertRecentSearchAsyncTask(RecentSearchDao recentSearchDao) {
this.recentSearchDao = recentSearchDao;
}
#Override
protected Void doInBackground(RecentSearchModel... recentSearchModels) {
recentSearchDao.insert(recentSearchModels[0]);
return null;
}
}
private static class UpdateRecentSearchAsyncTask extends AsyncTask<RecentSearchModel, Void, Void> {
private RecentSearchDao recentSearchDao;
public UpdateRecentSearchAsyncTask(RecentSearchDao recentSearchDao) {
this.recentSearchDao = recentSearchDao;
}
#Override
protected Void doInBackground(RecentSearchModel... recentSearchModels) {
recentSearchDao.update(recentSearchModels[0]);
return null;
}
}
}
#Dao
public interface RecentSearchDao {
#Insert()
void insert(RecentSearchModel model);
#Update
void update(RecentSearchModel model);
#Delete
void delete(RecentSearchModel model);
#Query("select * from recent_search_table")
LiveData<List<RecentSearchModel>> getRecentSearchList();
}
#Entity(tableName = "recent_search_table")
public class RecentSearchModel {
#PrimaryKey(autoGenerate = true)
private int ID;
private String query;
public RecentSearchModel(){
}
public RecentSearchModel(String query) {
this.query = query;
}
public void setID(int ID) {
this.ID = ID;
}
public int getID() {
return ID;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
#Override
public String toString() {
return "RecentSearchModel{" +
"query='" + query + '\'' +
'}';
}
#Override
public boolean equals(#Nullable Object obj) {
if (obj instanceof RecentSearchModel)
return this.query.equalsIgnoreCase(((RecentSearchModel) obj).query);
return false;
}
}
So, what I am doing here is for start getting all values inside my local DB and adding them to my String list that is part of the adapter. So far so good.
The issue I am facing is that the adapter won't show the amount of strings available in the list that populates it. In fact, it sometimes shows a view half-cut with wierd information, sometimes does not show anything and sometimes shows part of the corrent information. What am I missing?
Another thing I am facing is that the "recently searched" adapter won't work when clicking on the AutoCompleteTextView - it only works when typing and deleting values so the char length is 0. How can I make it work from start of focus?
Here is the way I am populating the information to the ViewModel -
/**
* Shows the searched products following
*/
#Override
public void getSearchedProducts(String searchedQuery) {
MarketplaceUtils.getSearchedProducts(searchedQuery, marketApiCalls, false, initialSearchTake, initialMarketplacePage, new MarketplaceUtils.OnProductsFetchCompleteListener() {
#Override
public void onSuccess(List<MiniProductModel> list) {
if (!searchedQuery.equals(currentSearchedText))
return;
if (list == null) {
//reaching here means we do not have a result to show to the UI so we empty the list.
currentProductList.clear();
productsAdapter.notifyDataSetChanged();
return;
}
if (searchedQuery.length() > 3 && searchAutoCompleteStrings.contains(searchedQuery)) {
Log.d("localDBValue", "searchedValue - " + searchedQuery);
recentSearchViewModel.insert(new RecentSearchModel(searchedQuery));
}
mPresenter.setDiscoverProductsLayoutVisibility(View.GONE);
currentProductList.clear();
currentProductList.addAll(list);
productsAdapter.notifyDataSetChanged();
}
#Override
public void onError(Throwable throwable) {
Log.d("searchedProducts", throwable.getMessage());
}
});
}
The default behaviour for #Insert method of Room is OnConflictStrategy.ABORT - so what I did is to implement equals() method to verify that the RecentSearchModels that are being compared are compared by their string value. Still does seems to effect anything.

Vaadin TreeTable with LazyQueryContainer

Could anyone explain me one thing? Is it possible to use Vaadin TreeTable with LazyQueryContainer? I've alredy tried but it doesn't work. Actually, there is no any lazy loading. The method loadItems of org.vaadin.addons.lazyquerycontainer.Query is called until all data are loaded. For instanse, if batch size for the container = 100 and I have 500 rows then this method will be called 5 times. Here is my code:
public class LazyHierarchicalQueryContainer extends LazyQueryContainer implements Container.Hierarchical {
private String parentProperty = "parent";
public LazyHierarchicalQueryContainer(QueryFactory queryFactory, Object idPropertyId, int batchSize,
boolean compositeItems) {
super(queryFactory, idPropertyId, batchSize, compositeItems);
}
public LazyHierarchicalQueryContainer(QueryDefinition queryDefinition, QueryFactory queryFactory) {
super(queryDefinition, queryFactory);
}
public LazyHierarchicalQueryContainer(QueryView queryView) {
super(queryView);
}
public String getParentProperty() {
return parentProperty;
}
public void setParentProperty(String parentProperty) {
this.parentProperty = parentProperty;
}
#Override
public Collection<?> getChildren(Object itemId) {
return Collections.emptyList();
}
#Override
public Object getParent(Object itemId) {
return null;
}
#Override
public Collection<?> rootItemIds() {
ArrayList arrayList = new ArrayList();
for (Object workItem : getItemIds()) {
if (isRoot(workItem)) {
arrayList.add(workItem);
}
}
return arrayList;
}
#Override
public boolean setParent(Object itemId, Object newParentId) throws UnsupportedOperationException {
if (getItem(newParentId) != null) {
getItem(itemId).getItemProperty(getParentProperty()).setValue(newParentId);
} else {
getItem(itemId).getItemProperty(getParentProperty()).setValue(null);
}
return true;
}
#Override
public boolean areChildrenAllowed(Object itemId) {
return true;
}
#Override
public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException {
return false;
}
#Override
public boolean isRoot(Object itemId) {
return getItem(itemId).getItemProperty(parentProperty).getValue() == null;
}
#Override
public boolean hasChildren(Object itemId) {
return false;
}
}
Thanks in advance.
It seems your implementation of rootItemIds() loads all items to filter out the root items. This may cause the whole container to be read in the first go.

Working example of JNA mouse hook

Can any one provide me with a working example of JNA mouse hook, which would be able to track mouse movements/click outside my Java Swing application ?
Thanks in Advance
Yep, here is the code...
public class CWMouseHook {
public final User32 USER32INST;
public final Kernel32 KERNEL32INST;
public CWMouseHook()
{
if(!Platform.isWindows())
{
throw new UnsupportedOperationException("Not supported on this platform.");
}
USER32INST = User32.INSTANCE;
KERNEL32INST = Kernel32.INSTANCE;
mouseHook=hookTheMouse();
Native.setProtected(true);
}
public static LowLevelMouseProc mouseHook;
public HHOOK hhk;
public Thread thrd;
public boolean threadFinish = true;
public boolean isHooked = false;
public static final int WM_MOUSEMOVE = 512;
public static final int WM_LBUTTONDOWN = 513;
public static final int WM_LBUTTONUP = 514;
public static final int WM_RBUTTONDOWN = 516;
public static final int WM_RBUTTONUP = 517;
public static final int WM_MBUTTONDOWN = 519;
public static final int WM_MBUTTONUP = 520;
public void unsetMouseHook()
{
threadFinish = true;
if (thrd.isAlive())
{
thrd.interrupt();
thrd = null;
}
isHooked = false;
}
public boolean isIsHooked()
{
return isHooked;
}
public void setMouseHook()
{
thrd = new Thread(new Runnable() {
#Override
public void run()
{
try
{
if(!isHooked)
{
hhk = USER32INST.SetWindowsHookEx(14, mouseHook,KERNEL32INST.GetModuleHandle(null),0);
isHooked = true;
MSG msg = new MSG();
while ((USER32INST.GetMessage(msg, null, 0, 0)) != 0)
{
USER32INST.TranslateMessage(msg);
USER32INST.DispatchMessage(msg);
System.out.print(isHooked);
if (!isHooked)
break;
}
}
else
System.out.println("The Hook is already installed.");
}
catch (Exception e)
{ System.err.println(e.getMessage());
System.err.println("Caught exception in MouseHook!");
}
}
},"Named thread");
threadFinish = false;
thrd.start();
}
private interface LowLevelMouseProc extends HOOKPROC
{
LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT lParam);
}
public LowLevelMouseProc hookTheMouse() {
return new LowLevelMouseProc()
{
#Override
public LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT info) {
if (nCode >= 0)
{
switch(wParam.intValue())
{
case CWMouseHook.WM_LBUTTONDOWN:
// do stuff
break;
case CWMouseHook.WM_RBUTTONDOWN:
//do stuff
break;
case CWMouseHook.WM_MBUTTONDOWN:
//do other stuff
break;
case CWMouseHook.WM_LBUTTONUP:
//do even more stuff
break;
case CWMouseHook.WM_MOUSEMOVE:
break;
default:
break;
}
/****************************DO NOT CHANGE, this code unhooks mouse *********************************/
if (threadFinish == true)
{
USER32INST.PostQuitMessage(0);
}
/***************************END OF UNCHANGABLE *******************************************************/
}
return USER32INST.CallNextHookEx(hhk, nCode, wParam, info.getPointer());
}
};
}
public class Point extends Structure
{
public class ByReference extends Point implements Structure.ByReference {};
public NativeLong x;
public NativeLong y;
}
public static class MOUSEHOOKSTRUCT extends Structure
{
public static class ByReference extends MOUSEHOOKSTRUCT implements Structure.ByReference {};
public POINT pt;
public HWND hwnd;
public int wHitTestCode;
public ULONG_PTR dwExtraInfo;
}
That's all about there is to it. Cheers.
It's a basically a ripoff of the code of a guy in Sun forums...but also tested by me, and it works so cheers again.
Edit: I edited the code so it includes the LowLevelMouseProc but you can use your extension of HOOK which you can define elsewhere. It doesn't matter that much. Be wary that for some reason you have TO have the variable mouseHook as static otherwise hook just unhooks after a while.
movements:
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.mouse.NativeMouseWheelEvent;
import org.jnativehook.mouse.NativeMouseWheelListener;
public class GlobalMouseWheelListenerExample implements NativeMouseWheelListener {
public void nativeMouseWheelMoved(NativeMouseWheelEvent e) {
System.out.println("Mosue Wheel Moved: " + e.getWheelRotation());
}
public static void main(String[] args) {
try {
GlobalScreen.registerNativeHook();
} catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
ex.printStackTrace();
System.exit(1);
}
// Construct the example object and initialze native hook.
GlobalScreen.getInstance().addNativeMouseWheelListener(new GlobalMouseWheelListenerExample());
}
}
click:
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.mouse.NativeMouseEvent;
import org.jnativehook.mouse.NativeMouseInputListener;
public class GlobalMouseListenerExample implements NativeMouseInputListener {
public void nativeMouseClicked(NativeMouseEvent e) {
System.out.println("Mosue Clicked: " + e.getClickCount());
}
public void nativeMousePressed(NativeMouseEvent e) {
System.out.println("Mosue Pressed: " + e.getButton());
}
public void nativeMouseReleased(NativeMouseEvent e) {
System.out.println("Mosue Released: " + e.getButton());
}
public void nativeMouseMoved(NativeMouseEvent e) {
System.out.println("Mosue Moved: " + e.getX() + ", " + e.getY());
}
public void nativeMouseDragged(NativeMouseEvent e) {
System.out.println("Mosue Dragged: " + e.getX() + ", " + e.getY());
}
public static void main(String[] args) {
try {
GlobalScreen.registerNativeHook();
}
catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
System.exit(1);
}
//Construct the example object.
GlobalMouseListenerExample example = new GlobalMouseListenerExample();
//Add the appropriate listeners for the example object.
GlobalScreen.getInstance().addNativeMouseListener(example);
GlobalScreen.getInstance().addNativeMouseMotionListener(example);
}
}

BlackBerry - Programmatically fetching data in calendar

i have invoked blackberry calender from my application
can anyone tell me how to fetch :
date
duration
notes
from the selected date
my code :
MenuItem importCalender = new MenuItem("Import from Calender",100,11)
{
public void run()
{
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
try
{
EventList list = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);
Enumeration events = list.items();
BlackBerryEvent e = (BlackBerryEvent) events.nextElement();
Invoke.invokeApplication(Invoke.APP_TYPE_CALENDAR, new CalendarArguments( CalendarArguments.ARG_VIEW_DEFAULT,e) );
}
catch (PIMException e)
{
//e.printStackTrace();
}
}
});
}
};
protected void makeMenu(Menu menu, int instance)
{
menu.add(importCalender);
}
You should register custom menu item for calendar application.
See How To - Add a custom menu item to an existing BlackBerry application
UPDATE
alt text http://img517.imageshack.us/img517/2789/caledar3.jpg
class Scr extends MainScreen {
VerticalFieldManager mManager;
UiApplication mApp;
public Scr() {
mApp = UiApplication.getUiApplication();
mManager = (VerticalFieldManager) this.getMainManager();
MyMenuItem myMenuitem = new MyMenuItem(0);
ApplicationMenuItemRepository.getInstance().addMenuItem(
ApplicationMenuItemRepository.MENUITEM_CALENDAR, myMenuitem);
}
class MyMenuItem extends ApplicationMenuItem {
MyMenuItem(int order) {
super(order);
}
public Object run(Object context) {
if (context instanceof Event) {
Event event = (Event) context;
final String text = "start: "
+ (new Date(event.getDate(Event.START, 0))).toString()
+ "\nend: "
+ (new Date(event.getDate(Event.END, 0))).toString()
+ "\nnote: " + event.getString(Event.NOTE, 0);
String message = "Import event\n" + text;
if (Dialog.YES == Dialog.ask(Dialog.D_YES_NO, message)) {
mApp.invokeLater(new Runnable() {
public void run() {
mApp.requestForeground();
mManager.add(new LabelField(text));
}
});
}
}
return context;
}
public String toString() {
return "Import Event";
}
}
MenuItem importCalender = new MenuItem("Import from Calender", 100, 11) {
public void run() {
UiApplication.getUiApplication().invokeAndWait(new Runnable() {
public void run() {
Invoke.invokeApplication(Invoke.APP_TYPE_CALENDAR,
new CalendarArguments(
CalendarArguments.ARG_VIEW_DEFAULT));
}
});
}
};
protected void makeMenu(Menu menu, int instance) {
menu.add(importCalender);
}
}

Resources