Custom Plugin

Hessinger

Member
Hello,

I'm curious to find out if Pleco plugin API is available to the public to develop our own stuff?

A few quick queries on Google didn't reveal anything. Sorry if this has already been asked and answered elsewhere.

Hess
 

mikelove

皇帝
Staff member
What sort of plugin are you thinking of? We do have an API for looking up words in our search box if that's what you want - here's some sample code:

Code:
Intent plecoIntent = new Intent(Intent.ACTION_MAIN);
plecoIntent.setComponent(new ComponentName("com.pleco.chinesesystem","com.pleco.chinesesystem.PlecoDroidMainActivity"));
plecoIntent.addCategory(Intent.CATEGORY_LAUNCHER);
plecoIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
plecoIntent.putExtra(“launch_section", “dictSearch”);
plecoIntent.putExtra("replacesearchtext”, INSERT_YOUR_SEARCH_TEXT_HERE);
startActivity(plecoIntent);
 

Hessinger

Member
Hi Mike,

When I'm on the go and I come across a word I don't know, generally I'll use Pleco to look it up and while Pleco has a nice add to flashcard system, I prefer some other applications (not that Pleco's flashcard system is bad). Adding the words looked up in Pleco to my other applications requires several extra tedious steps and would nice just to integrate other applications with Pleco. An example of that is Skritter. Skritter has an open API for doing such integration, as do some of the other applications I use. The question then becomes how extensible the UI of Pleco is.

Thoughts?
 

mikelove

皇帝
Staff member
We'd have to implement support for those various other services on our end - doing that with Skritter at least is on our to-do list, but we've got so many other much-more-highly-anticipated new features we're working on (including a revamp of our own flashcard system) that it's hard to justify making it a priority.
 

阿尔曼

Member
We do have an API for looking up words in our search box if that's what you want - here's some sample code:

Code:
Intent plecoIntent = new Intent(Intent.ACTION_MAIN);
plecoIntent.setComponent(new ComponentName("com.pleco.chinesesystem","com.pleco.chinesesystem.PlecoDroidMainActivity"));
plecoIntent.addCategory(Intent.CATEGORY_LAUNCHER);
plecoIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
plecoIntent.putExtra(“launch_section", “dictSearch”);
plecoIntent.putExtra("replacesearchtext”, INSERT_YOUR_SEARCH_TEXT_HERE);
startActivity(plecoIntent);

What do I have to change here to open the Activity with the word I'm looking for :

Screenshot_2015-04-23-12-57-52.png

instead of the Activity with search results :

Screenshot_2015-04-23-12-57-44.png
 

mikelove

皇帝
Staff member
Not something we support yet - should be coming within the next few minor updates, though, probably through a URL rather than intent (we added URL support for searches in a recent update) since it's easier for people to integrate and works with mobile websites along with native apps.
 

阿尔曼

Member
Not something we support yet - should be coming within the next few minor updates, though, probably through a URL rather than intent (we added URL support for searches in a recent update) since it's easier for people to integrate and works with mobile websites along with native apps.

Do you mean iOS ?
Because in one of your posts you are saying that :

There's not currently a URI equivalent on Android - you can easily launch Pleco from an intent but not from a URI.
 

阿尔曼

Member
There wasn't back then, but we added one in 3.2.10:

http://android.pleco.com/manual/310/vershist.html

How to use it in Android?

I've tried the following code in Webview, which didn't work:

Code:
javascript:window.location='plecoapi://x-callback-url/s?q=放松'

This one didn't work either:

Code:
String url = "plecoapi://x-callback-url/s?q=放松";
 Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);

though, probably through a URL rather than intent (we added URL support for searches in a recent update) since it's easier for people to integrate and works with mobile websites along with native apps.

What's wrong with Intent ?
I'm using it now and it works fine.
 

mikelove

皇帝
Staff member
Hmm... are you sure you're using the latest version of Pleco? Does it come up correctly if you enter that URL in Chrome?

URLs are easier to embed in in-app HTML and to attach to TextViews (just create a URLSpan). Intents are trickier to add and harder to keep forward-compatible if we rearrange or rename our activities.
 

mikelove

皇帝
Staff member
Interesting, but not something we can rely upon since it won't work on old or forked versions of Android or in other contexts like URLSpans. (And it doesn't address the forward compatibility problem)
 

阿尔曼

Member
Is it possible to let pleco open in landscape mode by default, rather than portrait ?
And also hide keyboard at first start, otherwise keyboard takes half of the screen in landscape mode.
 
Last edited:

mikelove

皇帝
Staff member
I think it's theoretically possible but to be honest we haven't had much demand for it - is this because your app is always in landscape? And it's currently switching back to portrait when you open Pleco?

Hiding the keyboard was an option before but nobody seemed to use it - is this likewise an app interface thing? (less of a problem to work it into a URL scheme string than to add yet another checkbox to our already overwhelming preferences interface)
 

阿尔曼

Member
Is this because your app is always in landscape? And it's currently switching back to portrait when you open Pleco?

Precisely ))

Is this likewise an app interface thing?

Yes. This is the code that opens Pleco:
Code:
String url = "plecoapi://x-callback-url/s?q=" + word_to_look_for;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
 

mikelove

皇帝
Staff member
Got it, thanks - it would probably make sense to always keep the keyboard closed if you're opening with a query from a URI, actually. (unless the query is empty -> the URI is just a fast way of launching Pleco)
 

mikelove

皇帝
Staff member
@阿尔曼 - keyboard opening is dealt with for our next build, but we weren't able to reproduce your problem with landscape orientation; is the device oriented in landscape anyway when you do this, so that other apps that auto-rotate would naturally end up in landscape, or is your app forcing landscape orientation on a device that would otherwise be in portrait?
 

阿尔曼

Member
keyboard opening is dealt with for our next build

Tnank you ))

but we weren't able to reproduce your problem with landscape orientation; is your app forcing landscape orientation on a device that would otherwise be in portrait?

Yes, my app forcing landscape orientation on a device even if it is in portrait.
Could you modify the query, like:
Code:
plecoapi://x-callback-url/s?q=word_to_look_for&is_landscape=1
so it would force the application to open in landscape?
Currently pleco opens in landscape only when device is set to auto rotate. Otherwise it opens in portrait by default.
 
Last edited:

mikelove

皇帝
Staff member
Easy enough to do via an API (setRequestedOrientation()) - much easier than on iOS actually - but I'd have to investigate more to see if that might have some problematic consequences in other areas of Pleco (or require a lot of extra debugging to deal with edge cases where we aren't expecting to rotate at that particular time).
 
Top