I am getting these errors while compiling - android

package com.prgguru.example;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;
public class MainActivity extends ActionBarActivity{
//DB Class to perform DB related operations
DBController controller = new DBController(this);
//Progress Dialog Object
ProgressDialog prgDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get User records from SQLite DB
ArrayList<HashMap<String, String>> userList = controller.getAllUsers();
//
if(userList.size()!=0){
//Set the User Array list in ListView
ListAdapter adapter = new SimpleAdapter( MainActivity.this,userList, R.layout.view_user_entry, new String[] { "userId","userName"}, new int[] {R.id.userId, R.id.userName});
ListView myList=(ListView)findViewById(android.R.id.list);
myList.setAdapter(adapter);
//Display Sync status of SQLite DB
Toast.makeText(getApplicationContext(), controller.getSyncStatus(), Toast.LENGTH_LONG).show();
}
//Initialize Progress Dialog properties
prgDialog = new ProgressDialog(this);
prgDialog.setMessage("Synching SQLite Data with Remote MySQL DB. Please wait...");
prgDialog.setCancelable(false);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//When Sync action button is clicked
if (id == R.id.refresh) {
//Sync SQLite DB data to remote MySQL DB
syncSQLiteMySQLDB();
return true;
}
return super.onOptionsItemSelected(item);
}
//Add User method getting called on clicking (+) button
public void addUser(View view) {
Intent objIntent = new Intent(getApplicationContext(), NewUser.class);
startActivity(objIntent);
}
public void syncSQLiteMySQLDB(){
//Create AsycHttpClient object
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
ArrayList<HashMap<String, String>> userList = controller.getAllUsers();
if(userList.size()!=0){
if(controller.dbSyncCount() != 0){
prgDialog.show();
params.put("usersJSON", controller.composeJSONfromSQLite());
client.post("http://192.168.65.1/sqlitemysqlsync/insertuser.php",params ,new AsyncHttpResponseHandler() {
#Override
public void onSuccess(String response) {
System.out.println(response);
prgDialog.hide();
try {
JSONArray arr = new JSONArray(response);
System.out.println(arr.length());
for(int i=0; i<arr.length();i++){
JSONObject obj = (JSONObject)arr.get(i);
System.out.println(obj.get("id"));
System.out.println(obj.get("status"));
controller.updateSyncStatus(obj.get("id").toString(),obj.get("status").toString());
}
Toast.makeText(getApplicationContext(), "DB Sync completed!", Toast.LENGTH_LONG).show();
} catch (JSONException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
#Override
public String getCharset() {
// TODO Auto-generated method stub
return super.getCharset();
}
#Override
public Header[] getRequestHeaders() {
// TODO Auto-generated method stub
return super.getRequestHeaders();
}
#Override
public URI getRequestURI() {
// TODO Auto-generated method stub
return super.getRequestURI();
}
#Override
public boolean getUseSynchronousMode() {
// TODO Auto-generated method stub
return super.getUseSynchronousMode();
}
#Override
protected void handleMessage(Message arg0) {
// TODO Auto-generated method stub
super.handleMessage(arg0);
}
#Override
protected Message obtainMessage(int responseMessageId,
Object responseMessageData) {
// TODO Auto-generated method stub
return super.obtainMessage(responseMessageId, responseMessageData);
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
super.onCancel();
}
#Override
public void onFinish() {
// TODO Auto-generated method stub
super.onFinish();
}
#Override
public void onPostProcessResponse(
ResponseHandlerInterface instance,
HttpResponse response) {
// TODO Auto-generated method stub
super.onPostProcessResponse(instance, response);
}
#Override
public void onPreProcessResponse(
ResponseHandlerInterface instance,
HttpResponse response) {
// TODO Auto-generated method stub
super.onPreProcessResponse(instance, response);
}
#Override
public void onProgress(int bytesWritten, int totalSize) {
// TODO Auto-generated method stub
super.onProgress(bytesWritten, totalSize);
}
//#Override
public void onRetry(int retryNo) {
// TODO Auto-generated method stub
super.onRetry(retryNo);
}
#Override
public void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
#Override
protected void postRunnable(Runnable runnable) {
// TODO Auto-generated method stub
super.postRunnable(runnable);
}
#Override
protected void sendMessage(Message msg) {
// TODO Auto-generated method stub
super.sendMessage(msg);
}
#Override
public void sendResponseMessage(HttpResponse arg0)
throws IOException {
// TODO Auto-generated method stub
super.sendResponseMessage(arg0);
}
#Override
public void setCharset(String charset) {
// TODO Auto-generated method stub
super.setCharset(charset);
}
#Override
public void setRequestHeaders(Header[] requestHeaders) {
// TODO Auto-generated method stub
super.setRequestHeaders(requestHeaders);
}
#Override
public void setRequestURI(URI requestURI) {
// TODO Auto-generated method stub
super.setRequestURI(requestURI);
}
#Override
public void setUseSynchronousMode(boolean sync) {
// TODO Auto-generated method stub
super.setUseSynchronousMode(sync);
}
#Override
protected Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return super.clone();
}
#Override
public boolean equals(Object o) {
// TODO Auto-generated method stub
return super.equals(o);
}
#Override
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
super.finalize();
}
#Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
}
#Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
#Override
public void onFailure(int statusCode, Throwable error,
String content){
// TODO Auto-generated method stub
prgDialog.hide();
if(statusCode == 404){
Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
}else if(statusCode == 500){
Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]", Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(int arg0, Header[] arg1, byte[] arg2,
Throwable arg3) {
// TODO Auto-generated method stub
}
#Override
public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
// TODO Auto-generated method stub
}
});
}else{
Toast.makeText(getApplicationContext(), "SQLite and Remote MySQL DBs are in Sync!", Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(getApplicationContext(), "No data in SQLite DB, please do enter User name to perform Sync action", Toast.LENGTH_LONG).show();
}
}
}
The errors during compiling are:
Description Resource Path Location Type The method onSuccess(String)
of type new AsyncHttpResponseHandler(){} must override or implement a
supertype method
The method onFailure(int, Throwable, String) of type new
AsyncHttpResponseHandler(){} must override or implement a supertype
method
Please help!!!

IMHO, you need to define the methods onSuccess and onFailure using different signature. Check which version of the library you are using but shoudn't it be something like this?
#Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
// Successfully got a response
}
#Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
// Response failed :(
}

You don't respect the original class method prototypes
onSuccess:
onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody)
onFailure:
onFailure(int statusCode, org.apache.http.Header[] headers, byte[] responseBody, java.lang.Throwable error)

Related

Unable to create Session in Quickblox in Android

I am new to Quickblox. I am trying to work on webrtc. I followed the tutorial here. I have also referred to QuickBlox Error with Custom Object (Android). I am getting the following errors when I try to create a session:
Authentication error: Unable to respond to any of these challenges: {}
D/QBASDK(31816): STATUS : 401
D/QBASDK(31816): '{"errors":["Unauthorized"]}'
My full code is pasted below:
public class MainActivity extends ActionBarActivity implements OnClickListener,
QBRTCClientSessionCallbacks, QBRTCClientConnectionCallbacks,
QBRTCClientVideoTracksCallbacks {
QBChatService chatService;
QBUser user1, user2;
QBGLVideoView localVideoVidew;
Button btn_session;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_session = (Button) findViewById(R.id.btn_session);
btn_session.setOnClickListener(MainActivity.this);
/*
* user1 = new User(1, "User1", "user1", "1234", 1); user2 = new User(2,
* "User2", "user2", "1234", 2);
*/
if (!QBChatService.isInitialized()) {
QBChatService.init(MainActivity.this);
chatService.getInstance();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_session:
create_session();
// create_SignallingManager();
break;
default:
break;
}
}
public void create_SignallingManager() {
// TODO Auto-generated method stub
QBChatService
.getInstance()
.getVideoChatWebRTCSignalingManager()
.addSignalingManagerListener(
new QBVideoChatSignalingManagerListener() {
#Override
public void signalingCreated(
QBSignaling qbSignaling, boolean arg1) {
// TODO Auto-generated method stub
if (!arg1) {
QBRTCClient.getInstance().addSignaling(
(QBWebRTCSignaling) qbSignaling);
}
}
});
QBRTCClient.getInstance().setCameraErrorHendler(
new VideoCapturerAndroid.CameraErrorHandler() {
#Override
public void onCameraError(final String s) {
MainActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(MainActivity.this, s,
Toast.LENGTH_LONG).show();
}
});
}
});
QBRTCClient.getInstance()
.addSessionCallbacksListener(MainActivity.this);
QBRTCClient.getInstance().addConnectionCallbacksListener(
MainActivity.this);
QBRTCClient.getInstance().addVideoTrackCallbacksListener(
MainActivity.this);
QBRTCClient.getInstance().prepareToProcessCalls(MainActivity.this);
}
private void create_session() {
QBSettings.getInstance().fastConfigInit("XXXX", "XXXXXXX", "XXXXX");//Have put ids properly in code
final QBUser user = new QBUser("user1", "1234");
QBAuth.createSession(user, new QBCallback() {
#Override
public void onComplete(Result arg0, Object arg1) {
// TODO Auto-generated method stub
QBUsers.signIn(user,new QBCallback() {
#Override
public void onComplete(Result arg0, Object arg1) {
// TODO Auto-generated method stub
}
#Override
public void onComplete(Result arg0) {
// TODO Auto-generated method stub
if(arg0.isSuccess())
{
Log.i("working","fine");
}
}
});
}
#Override
public void onComplete(Result arg0) {
// TODO Auto-generated method stub
}
});
}
#Override
public void onLocalVideoTrackReceive(QBRTCSession arg0,
QBRTCVideoTrack videoTrack) {
// TODO Auto-generated method stub
localVideoVidew = (QBGLVideoView) findViewById(R.id.localVideoView);
Log.d("TAG", "localVideoVidew is " + localVideoVidew);
if (localVideoVidew != null) {
videoTrack.addRenderer(new VideoRenderer(new VideoCallBacks(
localVideoVidew, QBGLVideoView.Endpoint.LOCAL)));
localVideoVidew.setVideoTrack(videoTrack,
QBGLVideoView.Endpoint.LOCAL);
Log.d("TAG", "onLocalVideoTrackReceive() is raned");
}
}
#Override
public void onRemoteVideoTrackReceive(QBRTCSession arg0,
QBRTCVideoTrack arg1, Integer arg2) {
// TODO Auto-generated method stub
}
#Override
public void onConnectedToUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
#Override
public void onConnectionClosedForUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
#Override
public void onConnectionFailedWithUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
#Override
public void onDisconnectedFromUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
#Override
public void onDisconnectedTimeoutFromUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
#Override
public void onError(QBRTCSession arg0, QBRTCException arg1) {
// TODO Auto-generated method stub
}
#Override
public void onStartConnectToUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
#Override
public void onCallRejectByUser(QBRTCSession arg0, Integer arg1,
Map<String, String> arg2) {
// TODO Auto-generated method stub
}
#Override
public void onReceiveHangUpFromUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
#Override
public void onReceiveNewSession(QBRTCSession arg0) {
// TODO Auto-generated method stub
}
#Override
public void onSessionClosed(QBRTCSession arg0) {
// TODO Auto-generated method stub
}
#Override
public void onSessionStartClose(QBRTCSession arg0) {
// TODO Auto-generated method stub
}
#Override
public void onUserNotAnswer(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
}
401 Unauthorized
The request requires user authentication. Basic and Digest Access Authentication"
You are missing onSuccessMethod().
QBSettings.getInstance().fastConfigInit("XXXX", "XXXXXXX", "XXXXX");//Have put ids properly in code
final QBUser user = new QBUser("user1", "1234");
// then the user will be logged in automatically
QBAuth.createSession(login, password, new QBEntityCallbackImpl<QBSession>() {
#Override
public void onSuccess(QBSession session, Bundle bundle) {
user.setId(session.getUserId());
// INIT CHAT SERVICE
if (!QBChatService.isInitialized()) {
QBChatService.init(this);
chatService = QBChatService.getInstance();
}
// LOG IN CHAT SERVICE
chatService.login(user, new QBEntityCallbackImpl<QBUser>() {
#Override
public void onSuccess() {
// success
}
#Override
public void onError(List errors) {
//error
}
});
}
#Override
public void onError(List<String> errors) {
//error
}
});
Unauthorized means that user's login or password are wrong, you should check this first
Use this method as per notes here
http://quickblox.com/developers/Android#How_to:_add_SDK_to_IDE_and_connect_to_the_cloud
Note there is no "User" field for this create session method
QBAuth.createSession(new QBEntityCallbackImpl() {}

How to tag a page in facebook while posting an image on facebook in android

09-05 13:14:42.500: E/response=0(7474): ==={"error":{"message":"Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api","type":"GraphMethodException","code":100}}
final String inputParm = post_id + "/tags?to=" + "pageId" ;
runOnUiThread(new Runnable() {
public void run() {
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, faceboo.getAccessToken());
Log.e("params TOKEN",""+faceboo.getAccessToken());
mAsyncRunner.request(inputParm, params, "POST", new RequestListener()
{
#Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
Log.e("response=0","==="+response);
}
#Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
Log.e("onIOException","==="+e);
}
#Override
public void onFileNotFoundException(
FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
Log.e("FileNotFoundException","==="+e);
}
#Override
public void onMalformedURLException(
MalformedURLException e, Object state) {
// TODO Auto-generated method stub
Log.e("MalformedURLException","==="+e);
}
#Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
Log.e("FacebookError","==="+e);
}
}, null);
}
});

Using a Speech Recognizer and TTS manager class

I'm trying to have this central manager class that handles the speech recognition and output voice data. So far, I have failed. This is what the class looks like but my app crashes when I try implementing it in other classes. Can someone please help me out?
Cheers!
import java.util.Locale;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.speech.tts.TextToSpeech;
public class speechEngineR extends Activity {
SpeechRecognizer ears;
TextToSpeech tts;
Intent i;
Context mCon = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ears = SpeechRecognizer.createSpeechRecognizer(mCon);
i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, mCon.getPackageName());
tts = new TextToSpeech(mCon, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
// TODO Auto-generated method stub
if(status != TextToSpeech.ERROR){
tts.setLanguage(Locale.US);
}
}
});
ears.setRecognitionListener(new RecognitionListener() {
#Override
public void onRmsChanged(float rmsdB) {
// TODO Auto-generated method stub
}
#Override
public void onResults(Bundle results) {
// TODO Auto-generated method stub
}
#Override
public void onReadyForSpeech(Bundle params) {
// TODO Auto-generated method stub
}
#Override
public void onPartialResults(Bundle partialResults) {
// TODO Auto-generated method stub
}
#Override
public void onEvent(int eventType, Bundle params) {
// TODO Auto-generated method stub
}
#Override
public void onError(int error) {
// TODO Auto-generated method stub
}
#Override
public void onEndOfSpeech() {
// TODO Auto-generated method stub
}
#Override
public void onBufferReceived(byte[] buffer) {
// TODO Auto-generated method stub
}
#Override
public void onBeginningOfSpeech() {
// TODO Auto-generated method stub
}
});
}
public speechEngineR(Context c){
mCon = c;
}
public void outSpeech(String out){
tts.speak(out, TextToSpeech.QUEUE_FLUSH, null);
}
}
And yes, I have I added the following permission in the Manifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Your question and code does not help.
In your code it seems you are trying to use Speech to Text(Audio recorder), and you are calling it using TTS (Text to Speech) which does exactly the opposite of what you are trying to accomplish i.e. speech to text.
Can you make it a bit more clear what you are trying to do??

Does twitter4j provide event listener for incoming direct messages?

I am developing an application which interacts with Twitter using twitter4j API. Does this API provide an event listener for incomning direct messages?
Please find the implementation in the following code.
Please add the twitter4j-core-2.2.6.jar & twitter4j-stream-2.2.6.jar to your build path.
package com.apt.java.test.twitterdemo;
import java.util.List;
import twitter4j.DirectMessage;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.User;
import twitter4j.UserList;
import twitter4j.UserStreamListener;
import twitter4j.auth.AccessToken;
import twitter4j.conf.ConfigurationBuilder;
public class TwitterDemo {
private TwitterStream twitterStream;
private void initConfiguration(){
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("YOUR CONSUMER KEY")
.setOAuthConsumerSecret("YOUR CONSUMER SECRET");
TwitterStreamFactory twitterStreamFactory = new TwitterStreamFactory(cb.build());
twitterStream = twitterStreamFactory.getInstance(new AccessToken("YOUR ACCESS TOKEN", "YOUR ACCESS TOKEN SECRET"));
twitterStream.addListener(userStreamListener);
twitterStream.user();
}
UserStreamListener userStreamListener = new UserStreamListener() {
#Override
public void onException(Exception arg0) {
// TODO Auto-generated method stub
}
#Override
public void onTrackLimitationNotice(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStatus(Status status) {
// TODO Auto-generated method stub
System.out.println(status.getText());
}
#Override
public void onScrubGeo(long arg0, long arg1) {
// TODO Auto-generated method stub
}
#Override
public void onDeletionNotice(StatusDeletionNotice arg0) {
// TODO Auto-generated method stub
}
#Override
public void onUserProfileUpdate(User arg0) {
// TODO Auto-generated method stub
}
#Override
public void onUserListUpdate(User arg0, UserList arg1) {
// TODO Auto-generated method stub
}
#Override
public void onUserListUnsubscription(User arg0, User arg1, UserList arg2) {
// TODO Auto-generated method stub
}
#Override
public void onUserListSubscription(User arg0, User arg1, UserList arg2) {
// TODO Auto-generated method stub
}
#Override
public void onUserListMemberDeletion(User arg0, User arg1, UserList arg2) {
// TODO Auto-generated method stub
}
#Override
public void onUserListMemberAddition(User arg0, User arg1, UserList arg2) {
// TODO Auto-generated method stub
}
#Override
public void onUserListDeletion(User arg0, UserList arg1) {
// TODO Auto-generated method stub
}
#Override
public void onUserListCreation(User arg0, UserList arg1) {
// TODO Auto-generated method stub
}
#Override
public void onUnfavorite(User arg0, User arg1, Status arg2) {
// TODO Auto-generated method stub
}
#Override
public void onUnblock(User arg0, User arg1) {
// TODO Auto-generated method stub
}
#Override
public void onRetweet(User arg0, User arg1, Status arg2) {
// TODO Auto-generated method stub
}
#Override
public void onFriendList(long[] arg0) {
// TODO Auto-generated method stub
}
#Override
public void onFollow(User arg0, User arg1) {
// TODO Auto-generated method stub
}
#Override
public void onFavorite(User arg0, User arg1, Status arg2) {
// TODO Auto-generated method stub
}
#Override
public void onDirectMessage(DirectMessage message) {
// TODO Auto-generated method stub
System.out.println(message.getText());
}
#Override
public void onDeletionNotice(long arg0, long arg1) {
// TODO Auto-generated method stub
}
#Override
public void onBlock(User arg0, User arg1) {
// TODO Auto-generated method stub
}
};
public static void main(String[] args){
TwitterDemo demo = new TwitterDemo();
demo.initConfiguration();
}
}

Android: adding text color,background and font size to optionsmenu

I tried a lot to add the font size,text color and background for my options menu but couldn't able to solve, how to do this for the following code?Help is always appreciated.....!, Thanks.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add("Share In Heart Club!");
menu.add("Play");
menu.add("Check Your Heart Type?");
menu.add("Cancel");
// Return true so that the menu gets displayed.
return true;
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Close the menu after a period of time.
// Note that this STARTS the timer when the options menu is being
// prepared, NOT when the menu is made visible.
Timer timing = new Timer();
timing.schedule(new TimerTask() {
#Override
public void run() {
closeOptionsMenu();
}
}, 10000);
return super.onPrepareOptionsMenu(menu);
}
Try the following code
#Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// MenuInflater inflater = getMenuInflater();
// inflater.inflate(R.menu.menu, menu);
// setContentView(R.layout.menu);
menu.clear();
setMenuBackground();
menu.add(0, MobilePagesConstant.MenuConstant.MENU_ABOUT, 0,
R.string.menu_about).setIcon(R.drawable.ico_about);
menu.add(0, MobilePagesConstant.MenuConstant.MENU_INDEX, 1,
R.string.menu_index).setIcon(R.drawable.ico_help);
// if (HNHConstant.IS_LAST_LIST_ON == 1) {
menu.add(0, MobilePagesConstant.MenuConstant.MENU_CUSTOMER_SUPPORT, 2,
R.string.menu_customer_support).setIcon(
R.drawable.ico_customer_support);
menu.add(0, MobilePagesConstant.MenuConstant.MENU_LEGAL, 3,
R.string.menu_legal).setIcon(R.drawable.ico_moderate);
menu.add(0, MobilePagesConstant.MenuConstant.MENU_GETTING_STARTED, 0,
R.string.menu_getting_started).setIcon(
R.drawable.ico_gettingstarted);
return true;
}
private void setMenuBackground() {
// TODO Auto-generated method stub
getLayoutInflater().setFactory(new Factory() {
#Override
public View onCreateView(final String name, final Context context,
final AttributeSet attrs) {
if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
try { // Ask our inflater to create the view
final LayoutInflater f = getLayoutInflater();
final View[] view = new View[1];
try {
view[0] = f.createView(name, null, attrs);
} catch (InflateException e) {
chaneDeafultMenu(name, attrs, f, view);
}
// Kind of apply our own background
new Handler().post(new Runnable() {
#Override
public void run() {
view[0].setBackgroundResource(R.drawable.background);
((TextView) view[0]).setTextColor(Color.BLACK);
((TextView) view[0])
.setTypeface(Typeface.SANS_SERIF);
}
});
return view[0];
} catch (InflateException e) {
} catch (ClassNotFoundException e) {
}
}
return null;
}
});
}
static void chaneDeafultMenu(final String name,
final android.util.AttributeSet attrs, final LayoutInflater f,
final View[] view) {
// mConstructorArgs[0] is only non-null during a running call to
// inflate()
// so we make a call to inflate() and inside that call our dully
// XmlPullParser get's called
// and inside that it will work to call
// "f.createView( name, null, attrs );"!
try {
f.inflate(new XmlPullParser() {
#Override
public int next() throws XmlPullParserException, IOException {
try {
view[0] = f.createView(name, null, attrs);
} catch (InflateException e) {
} catch (ClassNotFoundException e) {
}
throw new XmlPullParserException("exit");
}
#Override
public void defineEntityReplacementText(String arg0, String arg1)
throws XmlPullParserException {
// TODO Auto-generated method stub
}
#Override
public int getAttributeCount() {
// TODO Auto-generated method stub
return 0;
}
#Override
public String getAttributeName(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getAttributeNamespace(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getAttributePrefix(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getAttributeType(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getAttributeValue(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getAttributeValue(String arg0, String arg1) {
// TODO Auto-generated method stub
return null;
}
#Override
public int getColumnNumber() {
// TODO Auto-generated method stub
return 0;
}
#Override
public int getDepth() {
// TODO Auto-generated method stub
return 0;
}
#Override
public int getEventType() throws XmlPullParserException {
// TODO Auto-generated method stub
return 0;
}
#Override
public boolean getFeature(String arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public String getInputEncoding() {
// TODO Auto-generated method stub
return null;
}
#Override
public int getLineNumber() {
// TODO Auto-generated method stub
return 0;
}
#Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNamespace() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNamespace(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public int getNamespaceCount(int arg0)
throws XmlPullParserException {
// TODO Auto-generated method stub
return 0;
}
#Override
public String getNamespacePrefix(int arg0)
throws XmlPullParserException {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNamespaceUri(int arg0)
throws XmlPullParserException {
// TODO Auto-generated method stub
return null;
}
#Override
public String getPositionDescription() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getPrefix() {
// TODO Auto-generated method stub
return null;
}
#Override
public Object getProperty(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getText() {
// TODO Auto-generated method stub
return null;
}
#Override
public char[] getTextCharacters(int[] arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public boolean isAttributeDefault(int arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isEmptyElementTag()
throws XmlPullParserException {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isWhitespace() throws XmlPullParserException {
// TODO Auto-generated method stub
return false;
}
#Override
public int nextTag() throws XmlPullParserException, IOException {
// TODO Auto-generated method stub
return 0;
}
#Override
public String nextText() throws XmlPullParserException,
IOException {
// TODO Auto-generated method stub
return null;
}
#Override
public int nextToken() throws XmlPullParserException,
IOException {
// TODO Auto-generated method stub
return 0;
}
#Override
public void require(int arg0, String arg1, String arg2)
throws XmlPullParserException, IOException {
// TODO Auto-generated method stub
}
#Override
public void setFeature(String arg0, boolean arg1)
throws XmlPullParserException {
// TODO Auto-generated method stub
}
#Override
public void setInput(Reader arg0) throws XmlPullParserException {
// TODO Auto-generated method stub
}
#Override
public void setInput(InputStream arg0, String arg1)
throws XmlPullParserException {
// TODO Auto-generated method stub
}
#Override
public void setProperty(String arg0, Object arg1)
throws XmlPullParserException {
// TODO Auto-generated method stub
}
}, null, false);
} catch (InflateException e1) {
// "exit" ignored
}
}
http://www.droidnova.com/how-to-create-an-option-menu,427.html
Please check the link and vote up if u find it useful
Applying styles / themes to the options menu is not easy in Android. However, there is a great article which shows you how to implement your own.
Setting the background colour is possible, but it's quite buggy on 2.3. See How to change the background color of the options menu? for more information.
Create a custom xml view with your fav icons and colors. Use menuinflator to inflate them to options menu.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.splash_screen, menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.payby_menu, menu);
getLayoutInflater().setFactory(new Factory() {
#Override
public View onCreateView(String name, Context context,
AttributeSet attrs) {
if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater f = getLayoutInflater();
final View view = f.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
// set the background drawable
// view.setBackgroundResource(R.drawable.my_ac_menu_background);
// set the text color
((TextView) view).setTextColor(Color.WHITE);
}
});
return view;
} catch (InflateException e) {
} catch (ClassNotFoundException e) {
}
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}
1: you can simply add color to text by just writing
android:textColor="#ff00ff"
in your layout xml in textview tag
or second method is
you can add color by using
values->string.xml and adding a color resource to your string

Categories

Resources