how to use photoview 2.0.0 in android studio 3 - casting

I have a problem with photoview lib from gihub... How can I cast my image to the photoview? I have a error in .java file and no more ...!!!
and it is a image of my XML file

You should put it inside in onCreate and not outside.
protected void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.activity_main);
PhotoView view = (PhotoView) findViewById(R.id.photo_view);
view.setImageResource( your-image-here );
}

Related

How can I interact with html elements use QT

For example, I have a simple HTML page with button and label (or something else). How can I change the text in label (or something else) and catch the button click use QT.
I try to use QWebEngineView to show html, but I don`t know how to interact with elements from QT modul, just change the url, but I dont think its a better way
To be able to interact with HTML rendered with QWebEngine you need to use QWebChannel. You can find the basic guidelines at Qt WebChannel JavaScript API page.
To implement intercommunication with JavaScript in your HTML page you need:
Add Qt += webchannel in your project file
Implement a QObject derived class that should be a proxy between C++ and JavaScript. The simpliest way to make it usable in JavaScript is to create getters, setters and signals for the values you intend to use in JavaScript, and expose them as Q_PROPERTY.
Example:
class ProxyClass: public QObject
{
Q_OBJECT
Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)
public:
explicit ProxyClass(QObject *parent = nullptr);
QString value() const;
void setValue(const QString &aValue);
signals:
void valueChanged(const QString &aValue);
};
Set HTML to QWebEngineView with QWebEngineView::setHtml, instantiate your "proxy" class and create QWebChannel for the page (note that you can register multiple objects in QWebChannel). Example:
//create QWebEngineView and set HTML from resources
auto webView = new QWebEngineView;
QFile htmlFile(":/page.html");
htmlFile.open(QIODevice::ReadOnly);
QString html = htmlFile.readAll();
webView->setHtml(html);
//create and set up the instance of your "proxy" class
auto proxy = new ProxyClass;
//create QWebChannel and set it for the page
QWebChannel *webChannel = new QWebChannel(webView->page());
webChannel->registerObject(QStringLiteral("proxy"), proxy);
webView->page()->setWebChannel(webChannel);
Embed qwebchannel.js file in HTML. File is located at <Qt installation directory>/Examples/Qt-<version>/webchannel/shared directory. You can include it in application resources and embed in HTML with <script type="text/javascript" src="qrc:/qwebchannel.js"></script>
Create onload event handler in HTML and initialize QWebChannel in it. Example:
function loaded() {
new QWebChannel(qt.webChannelTransport, function (channel) {
<!--get and assign "proxy"-->
window.proxy = channel.objects.proxy;
<!--now you can-->
<!--get values-->
let proxyValue = proxy.value;
<!--connect signals-->
proxy.valueChanged.connect(() => {
...
});
});
}
function someFunction(newValue) {
<!--set values-->
proxy.value = newValue;
}
...
<body onload="loaded()">...</body>
Once you initialized a web channel and assigned "proxy" object to the window object, you are free to use it everywhere in JavaScript.

Google Glass GDK Hello World Immersion Activity

Steps, I have used to create my first Google Glass GDK App
New Project > Application name, company domain > Next > Glass (Glass Development Kit Preview (Google Inc.) (API 19)) > Next > Immersion Activity
ImmersionActivity.java:
public class ImmersionActivity extends Activity {
/**
* {#link CardScrollView} to use as the main content view.
*/
private CardScrollView mCardScroller;
private View mView;
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
mView = buildView();
mCardScroller = new CardScrollView(this);
mCardScroller.setAdapter(new CardScrollAdapter() {
#Override
public int getCount() {
return 1;
}
#Override
public Object getItem(int position) {
return mView;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return mView;
}
#Override
public int getPosition(Object item) {
if (mView.equals(item)) {
return 0;
}
return AdapterView.INVALID_POSITION;
}
});
// Handle the TAP event.
mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Plays disallowed sound to indicate that TAP actions are not supported.
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.playSoundEffect(Sounds.DISALLOWED);
}
});
setContentView(mCardScroller);
}
#Override
protected void onResume() {
super.onResume();
mCardScroller.activate();
}
#Override
protected void onPause() {
mCardScroller.deactivate();
super.onPause();
}
/**
* Builds a Glass styled "Hello World!" view using the {#link CardBuilder} class.
*/
private View buildView() {
CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
card.setText(R.string.hello_world);
return card.getView();
}
}
Manifest.xml:
<activity
android:name=".ImmersionActivity"
android:icon="#drawable/ic_glass_logo"
android:label="#string/title_activity_immersion" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger" />
</activity>
voice_trigger.xml:
<trigger command="SHOW_ME_A_DEMO" />
Now, what i have understood, we can run this app by trigger voice command "SHOW ME A DEMO", Is that right or wrong ?
And is there any way to run Glass GDK app on Android Emulator using Android Studio ?
Now, what i have understood, we can run this app by trigger voice command "SHOW ME A DEMO", Is that right or wrong ?
It's correct. YOu can even configure this trigger and use other commands.
And is there any way to run Glass GDK app on Android Emulator using Android Studio ?
No you can't. Only Tablet, Phone, Wear (watches) and TV devices are available on the Android Virtual Device Manager.
Now, what i have understood, we can run this app by trigger voice command "SHOW ME A DEMO", Is that right or wrong ?
yes you could run a app with the trigger set as command = "Show_me_a_demo"
But with this you are only able to run it from the speak menu.
I would turn it into
<trigger keyword="#string/app_name"/>
you could use any keyword you want but with this it would show up in the application menu as well as on the speak menu. The name that would show would be whatever you named your app.
It would also be a good idea to add <uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
to your manifest. To make sure the custom commands work
there are no emulators for the glass available as of now.

Automatically saving a file with QFileDialog

I have to automate a test using QTest, Qt, C++:
I write text in a tab (part of tabwidget) and then try to close it, afterwards a QFileDialog appears ( because I made changes to the plaintext in the tab), I try to "catch" the QFileDialog like this:
QWidgetList topWidgets = QApplication::topLevelWidgets();
foreach (QWidget *w, topWidgets) {
if (QFileDialog *fd = qobject_cast<QFileDialog *>(w)) {
fd->setFileMode(QFileDialog::ExistingFiles);
fd->selectFile("/tmp/test.txt");
}
}
After getting the QFileDialog object I want my changes from the tab to be saved in the file "test.txt" which I created before in the tmp directory. When I execute this nothing happens, the QFileDialog pops up, but test.txt is not selected and not saved, how can I achieve this?
The selectFile method does not work if the filedialog is visible and if the focus is set to the line edit widget. From the qfiledialog.cpp (QT 5.2):
if (!isVisible() || !d->lineEdit()->hasFocus())
d->lineEdit()->setText(file);
For our automated tests, we just hide the filedialog for a moment, call selectFile() and show it again
Try this:
QWidgetList topWidgets = QApplication::topLevelWidgets();
foreach (QWidget *w, topWidgets) {
if (QFileDialog *fd = qobject_cast<QFileDialog *>(w)) {
fd->hide();
fd->selectFile("/tmp/test.txt");
fd->show();
fd->exec();
}
}

How do you update a Glass CardScrollView programatically in XE16 (KitKat)?

How do you update a Glass CardScrollView programatically in XE16 (KitKat)?
I have a CardScrollView of cards that display photos from url's. I download the photos from the url's in a background thread and then I want to "refresh" or update the CardScrolView to make the cards display the new images.
I was calling:
cardScrollView.updateViews(true);
In XE12, but in XE16/KitKat that operation is deprecated. So how do you download an image in the background and then update a displayed "Card" with that image? Just calling card.addImage() seems to add a blank image and doesn't display the image.
I've updated my call from the background thread to be:
cardScrollView.getAdapter().notifyDataSetChanged();
Here is the code for the card scroll adapter with
private class SpecialCardsScrollAdapter extends CardScrollAdapter {
#Override
public int getPosition(Object item) {
return specialCardsList.indexOf(item);
}
#Override
public int getCount() {
return specialCardsList.size();
}
#Override
public Object getItem(int position) {
return specialCardsList.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return specialCardsList.get(position).getView();
}
}
Should I expect that calling cardScrollView.getAdapter().notifyDataSetChanged(); would cause Cards already put into the scrollview to update the image they have stored?
As mentioned in the release notes, use BaseAdapter#notifyDataSetChanged() from your CardScrollAdapter instead.

Add line below tabs in ActionBar

After a lot of looking here and there I am posting this problem that I am facing on SO. Basically I have an Action bar with a tabbed layout. Below is a snapshot of how it looks now :
And here is the code chunk that sets the tabs :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_example);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
setContentView(R.layout.landing_page);
ViewPager viewPager = (ViewPager) findViewById(R.LandingPage.pager);
final ActionBar bar = getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mTabsAdapter = new LandingPageTabsAdapter(this, viewPager);
mTabsAdapter.addTab(bar.newTab().setText("Search"), Search.class, null);
mTabsAdapter.addTab(bar.newTab().setText("Categories"),Categories.class, null);
mTabsAdapter.addTab(bar.newTab().setText("Bookmarks"), Bookmarks.class,null);
}
I want to add a straight line just below the tab highlighter, which is of the same color as the tab highlighter. Something like the line in Google Playstore (green line circled in red):
Currently I am styling the Actionbar using the Android Asset Studio's ActionBar Style Generator. My only reason to put the line there is to get a clean look.
Can someone suggest / advice on how I can solve this ? Thanks for stopping by and lending in your thoughts.
Instead of adding a line below your actionbar try adding a line above your viewpager in your layout. Also the play store isn't using tabs they are using the PageTitleStrip