A simple issue on my IMDB movie application on Android - java

I am making an android application using IMDB open-source api (My movie api).
Features are:
when user search a particular movie they got the list in list view. If they click on a list it shows full details of the movie.
User also can add any movie to favourite list and also can delete it.
Everything works fine. BUT THE APPLICATION FORCE CLOSES IF ANY FIELD IS MISSING FOR A MOVIE ON IMDB DATABASE LIKE MOVIE LANGUAGE OR DURATION ETC.
I have tried if- else syntax but not worked. If have any suggestion please let me know. I will be thankful to you.
Here is my code:
ImageProvider Ip = new ImageProvider();
final String Title = getIntent().getStringExtra("title");
final String story = getIntent().getStringExtra("story");
final String actors = getIntent().getStringExtra("actors");
final String lang = getIntent().getStringExtra("lang");
final String Id = getIntent().getStringExtra("ID");
final String duration = getIntent().getStringExtra("time");
final String directBy = getIntent().getStringExtra("director");
final String year1 = getIntent().getStringExtra("year");
final String src = getIntent().getStringExtra("img");
Log.v("src", src);
title.setText(Title);
details.setText(story);
cast.setText(actors);
language.setText(lang);
mid.setText(Id);
time.setText(duration);
Director.setText(directBy);
year.setText(year1);
VImg.setImageBitmap(Ip.fetchImage(src));

Related

Replacing a string in Google Protocol Data Buffers

I've succesfully built the following .proto file:
package JervisStorage;
option java_package = "TextBase";
option java_outer_classname = "JervisStorage";
message Owner {
optional string name = 1;
optional string sex = 2;
optional string profession = 3;
optional string email = 4;
}
Now, I managed to build the Owner:
private static Owner owner;
private static FileOutputStream serialOutput;
Owner pusheen= Owner.newBuilder()
.setName("Siema")
.setSex(" ")
.setProfession(" ")
.setEmail(" ")
.build();
I wrote the object to the file and successfully read the object from the file:
serialOutput = new FileOutputStream("JervisStorage.ser");
pusheen.writeTo(serialOutput);
serialOutput.close();
owner = Owner.parseFrom(new FileInputStream("JervisStorage.ser"));
System.out.println(owner.getName());
The problem is that I am unable to replace a signle record, write it back to the file and read the whole updated object. I have been trying to do this:
owner.toBuilder().setName("newName").build();
System.out.println(owner.getName());
serialOutput = new FileOutputStream("JervisStorage.ser");
owner.writeTo(serialOutput);
serialOutput.close();
owner = Owner.parseFrom(new FileInputStream("JervisStorage.ser"));
System.out.println(owner.getName());
Unfortunately, this approach does not seem to work... Can anyone help?
why not do
editedOwner = Owner.newBuilder()
.mergeFrom(new FileInputStream("JervisStorage.ser"))
.setName("new name")
.build();
alternatively you could do
editedOwner = owner.toBuilder()
.setName("new name")
.build();
Ok, I managed to find a solution to this problem. I hate extending the computation time when unnecessary, but this is the best I can think of so far. I've got two Owner objects: owner and editedOwner:
Owner owner;//for reading the records from the file
Owner editedOwner;// for addidng to the file
owner = Owner.parseFrom(new FileInputStream("JervisStorage.ser"));
editedOwner = Owner.newBuilder()
.setName("new name")
.setSex(owner.getSex())
.setProfession(owner.getProfession())
.setEmail(owner.getEmail())
.build();
serialOutput = new FileOutputStream("JervisStorage.ser");
editedOwner.writeTo(serialOutput);
serialOutput.close();
Fortunately, this little messy approach solves my problem for now. Thank you.

Creating a poll system using PircBot

I'm new to Java and I'm trying to create a poll system using PircBot.
So far my code is this:
if (message.startsWith("!poll")) {
String polly = message.substring(6);
String[] vote = polly.split(" ");
String vote1 = vote[0];
String vote2 = vote[1];
}
Which splits the strings so that someone can type !poll "option1 option2" for example and it will be split into vote1 = option1 and vote2 = option2.
I'm kind of lost from here. Am I even heading in the right direction for creating a voting system?
I figure that I'd have a separate statement as follows.
if (message.equalsIgnoreCase("!vote " + option1))
But I'm not sure where to go with that either.

Create Liferay public pages on server start

I would like to create a Liferay hook that creates public pages on server start.
I already have the hook bound to server start. But I have some problems with creating the page. Maybe I am wrong about user, group, community, etc. (remember that this hook doesn't have access to themeDisplay).
Company company = CompanyLocalServiceUtil.getCompanyByMx(PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
long companyId = company.getCompanyId();
User defaultUser = UserLocalServiceUtil.getDefaultUser(companyId);
long userId = defaultUser.getUserId();
long groupId = GroupLocalServiceUtil.getCompanyGroup(PortalUtil.getDefaultCompanyId()).getGroupId();
boolean privateLayout = false;
long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
String name = page.getName();
String title = null;
String description = null;
String type = LayoutConstants.TYPE_PORTLET;
boolean hidden = false;
String friendlyUrl = "/test";
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);
LayoutLocalServiceUtil.addLayout(userId, groupId, privateLayout, parentLayoutId, name, title, description, type, hidden, friendlyUrl, serviceContext);
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
layoutTypePortlet.setLayoutTemplateId(userId, page.getLayoutId());
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
The page is never listed...
You might want to check the leftovers of that old sevencogs hook demo code - James Falkner has blogged about it and resurrected some of the code. It might not be for the current version, but if there are any API changes, they're minor.
Pay special attention to the "Adding a Layout (Page) to a Site" paragraph in that article and compare it with your code.
Also note that "on server start" means that you'll have to pay attention to not create the same page twice. It'd happen on every single server start - or actually on every deployment of the hook that you write.

Add domain to a relative link

I'm fetching some data containing HTML from my server to use in my app, and the html has some links like Go here.
I'm applying the html to a TextView like
text.setText(Html.fromHtml(htmlString));
text.setMovementMethod(LinkMovementMethod.getInstance());
The link works, but causes my app to crash with
No Activity found to handle Intent { act=android.intent.action.VIEW dat=/go/here...`
I'm guessing the crash is because it's a relative link and doesn't have the domain in. Is there any methods, maybe Regex, to search for all <a/> tags and add the domain before it?
I would be tempted to go the simplest way:
final String faultyHtml = "Link: click here etc etc";
final String domain = "http://www.google.fr";
final String fixedHtml = faultyHtml.replace("href=\"/", "href=\"" + domain + "/");
text.setText(Html.fromHtml(fixedHtml));
text.setMovementMethod(LinkMovementMethod.getInstance());
(all occurrences would be added the same domain though)
int index = htmlString.indexOf("<a>");
String part1 = htmlString.subString(0,index+2);
String part2 = htmlString.subString(index+3);
String newHtmlString = part1+"http://"+part2;
You can try like this codes.
TextView tv = (TextView) findViewById(R.id.textView1);
String text = "This is just a test. Click this link here Google to visit google.";
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(text));
reference How to make links in textview clickable in android?

Android / Blackberry10 call information not appearing

I have made an Android app that I am trying to port over to a blackberry 10 device. Currently, all of the functions of the app work except for one, where I try and get information about recent calls from the phone. This works fine on android, but does not seem to work on the blackberry 10 simulator I am using. Here is my code for the section:
final TextView time = (TextView) findViewById(R.id.AddNewEditTextTime);
final TextView date = (TextView) findViewById(R.id.AddNewEditTextDate);
final TextView number = (TextView) findViewById(R.id.AddNewEditTextNumber);
// fields to select.
String[] strFields = { android.provider.CallLog.Calls.NUMBER,
android.provider.CallLog.Calls.TYPE,
android.provider.CallLog.Calls.CACHED_NAME,
android.provider.CallLog.Calls.CACHED_NUMBER_TYPE,
android.provider.CallLog.Calls.DATE};
// only incoming.
String strSelection = android.provider.CallLog.Calls.TYPE + " = "
+ android.provider.CallLog.Calls.INCOMING_TYPE;
// most recent first
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
// get a cursor.
Cursor mCallCursor = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, // content provider
// URI
strFields, // project (fields to get)
strSelection, // selection
null, // selection args
strOrder // sortorder.
);
if (mCallCursor.moveToFirst()) {
String a = mCallCursor.getString(mCallCursor
.getColumnIndex("date"));
String b = mCallCursor.getString(mCallCursor
.getColumnIndex("number"));
mCallCursor.close();
SimpleDateFormat dateF = new SimpleDateFormat("dd-MMM-yyyy");
SimpleDateFormat timeF = new SimpleDateFormat("HH:mm");
String dateString = dateF.format(new Date(Long
.parseLong(a)));
String timeString = timeF.format(new Date(Long
.parseLong(a)));
time.setText(timeString);
date.setText(dateString);
number.setText(b);
}
The if(mCallCursor.moveToFirst()) statement is never entered on the blackberry 10 device, but works fine on Android. Is there something I'm missing / doing wrong, or is there no way to use the android.provider functions like this on a blackberry 10 device?
Apparently accessing call log is not yet supported
This is not supported, the Android API is not hooked up to retreive this data.
Edit: Usually when there's an equivalent native API, the corresponding API in Android will be supported. The Android API almost always uses the native equivalent for its implementation. AFAIK there isn't a native call logs API.
By bbenninger, at support forums.

Categories

Resources