List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:org.egov.android.controller.ServiceController.java
/** * On error we have checked the file size with device available spac. If the space is * insufficient then show the message else increment the tried count. */// w w w.j a v a 2 s .c o m @Override public void onError(byte[] data) { StorageManager sm = new StorageManager(); Object[] obj = sm.getStorageInfo(ctx); long totalSize = (Long) obj[2]; if (jobType.equals("download") && totalSize < AndroidLibrary.getInstance().getConfig().getInt("upload.file.size") * 1024 * 1024) { SQLiteHelper.getInstance().execSQL("UPDATE tbl_jobs SET status='error' WHERE id = " + id); Toast toast = Toast.makeText(ctx, "There is no sufficient space in your sdcard", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 120); toast.show(); stopJobs(); return; } JSONArray ja = SQLiteHelper.getInstance().query("SELECT * FROM tbl_jobs WHERE id = " + id); if (ja == null || (ja != null && ja.length() == 0)) { startJob(); return; } int triedCount = 0; try { JSONObject jo = ja.getJSONObject(0); triedCount = jo.getInt("triedCount") + 1; } catch (JSONException e) { e.printStackTrace(); } SQLiteHelper.getInstance() .execSQL("UPDATE tbl_jobs SET status='error', triedCount=" + triedCount + " WHERE id = " + id); isJobRunning = false; startJob(); }
From source file:com.kinvey.sample.kitchensink.account.LoginFragment.java
@Override public void onClick(View v) { if (v == login) { if (implicit.isChecked()) { ((KitchenSinkApplication) getSherlockActivity().getApplicationContext()).getClient().user() .login(new KinveyUserCallback() { @Override public void onSuccess(User result) { if (getSherlockActivity() == null) { return; }/*from w w w. j a va 2s . c o m*/ CharSequence text = "Logged in " + result.get("username") + "."; Toast.makeText(getSherlockActivity().getApplicationContext(), text, Toast.LENGTH_LONG).show(); loggedIn(); } @Override public void onFailure(Throwable error) { if (getSherlockActivity() == null) { return; } CharSequence text = "Something went wrong -> " + error; Toast toast = Toast.makeText(getSherlockActivity().getApplicationContext(), text, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.show(); } }); } else { ((KitchenSinkApplication) getSherlockActivity().getApplicationContext()).getClient().user().login( username.getText().toString(), password.getText().toString(), new KinveyUserCallback() { @Override public void onSuccess(User result) { if (getSherlockActivity() == null) { return; } CharSequence text = "Logged in " + result.get("username") + "."; Toast.makeText(getSherlockActivity().getApplicationContext(), text, Toast.LENGTH_LONG).show(); loggedIn(); } public void onFailure(Throwable t) { if (getSherlockActivity() == null) { return; } CharSequence text = "Something went wrong -> " + t; Toast toast = Toast.makeText(getSherlockActivity().getApplicationContext(), text, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.show(); } }); } } }
From source file:org.egov.android.view.activity.AllComplaintActivity.java
/** * Function used to show toast/*from w ww . j av a 2 s . c o m*/ * * @param message * => Message to be shown */ private void _showMsg(String message) { if (message != null && !message.equals("")) { Toast toast = Toast.makeText(getActivity(), message, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 120); toast.show(); } }
From source file:es.curso.android.streamingVLC.VideoActivity.java
/************* * Player/*from w ww . j a va 2s . co m*/ *************/ private void createPlayer(String media) { releasePlayer(); if (media.length() > 0) { Toast toast = Toast.makeText(this, media, Toast.LENGTH_LONG); toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } // Create a new media player try { libvlc = LibVLC.getInstance(); } catch (LibVlcException e) { Toast.makeText(this, "Can't create player", Toast.LENGTH_LONG).show(); return; } libvlc.setIomx(false); libvlc.setSubtitlesEncoding(""); libvlc.setAout(LibVLC.AOUT_OPENSLES); libvlc.setTimeStretching(true); libvlc.setChroma("RV32"); libvlc.setVerboseMode(true); LibVLC.restart(this); EventHandler.getInstance().addHandler(mHandler); if (holder == null) Log.d(TAG, "holder==null"); holder.setFormat(PixelFormat.RGBX_8888); holder.setKeepScreenOn(true); MediaList list = libvlc.getMediaList(); list.clear(); list.add(new Media(libvlc, LibVLC.PathToURI(media)), false); libvlc.playIndex(0); }
From source file:gr.rambou.secheader.MainActivity.java
private void getHeader(String url) { //Create a Listener for our requests Response.Listener listener = new Response.Listener<JSONObject>() { @Override// ww w .ja va 2 s.c o m public void onResponse(JSONObject newjson) { //Check if we need to save into database CheckBox cb = (CheckBox) findViewById(R.id.checkbox_save); if (cb.isChecked()) { //We open/create our sqlite database DatabaseHandler mydb = new DatabaseHandler(getApplicationContext()); //Loop over all results for (int i = 0; i < newjson.names().length(); i++) { try { //Check if the value is URL and don't insert it into db String value = newjson.names().getString(i).toString(); if (!value.equals("URL")) //Add result into database mydb.addResult(newjson.getString("URL"), value, (newjson.get(newjson.names().getString(i)).equals("Secure")) ? 1 : 0); } catch (JSONException e) { e.printStackTrace(); } } } /* for (int i = 0; i < newjson.names().length(); i++) { try { Log.wtf("LOL", "key = " + newjson.names().getString(i) + " value = " + newjson.get(newjson.names().getString(i))); } catch (JSONException e) { e.printStackTrace(); } }*/ //decrease requests value; requests--; //Update progressBar int max = ((ProgressBar) findViewById(R.id.progressBar)).getMax(); ((ProgressBar) findViewById(R.id.progressBar)).setProgress(max - requests); //Check if we finished if (requests == 1) { //Sending a toast to the user that we got all headers Context context = getApplicationContext(); CharSequence text = "We Got all Headers!!!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0); toast.show(); //Re-Enable Buttons functionality (findViewById(R.id.button_scan)).setEnabled(true); (findViewById(R.id.checkbox_save)).setEnabled(true); } } }; //Create an Error Listener for our requests Response.ErrorListener errorListener = new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { if (error.networkResponse != null) { Log.v("Error Response code", String.valueOf(error.networkResponse.statusCode)); } } }; // Request a string response from the provided URL. JsonObjectRequest stringRequest = new JsonObjectRequest(Request.Method.HEAD, //We only want the headers, although it's similar with GET. url, //our url listener, //our listener, handling our findings errorListener) { //Error Listener to handle errors in requests @Override protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { try { //We create a JSONObject and add the url address to it. org.json.JSONObject f = new JSONObject(response.headers).put("URL", this.getUrl()); /*We return the headers as a JSONObject which, we filter the headers and return the security ones*/ return Response.success(FilterHeaders(f), HttpHeaderParser.parseCacheHeaders(response)); } catch (JSONException e) { return Response.error(new ParseError(e)); } } }; // Add the request to the RequestQueue. queue.add(stringRequest); }
From source file:jackpal.androidterm.RemoteInterface.java
void alert(final String message) { Toast toast = Toast.makeText(this, message, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();//from ww w .j a v a2 s . c o m }
From source file:alaindc.memenguage.View.MainActivity.java
private void updateWordsList() { wordsListview = (ListView) findViewById(R.id.wordslistview); adapter = new WordsAdapter(this, crs, 0); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return dbmanager.getMatchingWords(String.valueOf(constraint)); }// ww w . j a v a 2s .c o m }); wordsListview.setAdapter(adapter); wordsListview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) { Intent createWordIntentActivity = new Intent(MainActivity.this, CreateEditActivity.class); createWordIntentActivity.setAction(Constants.ACTION_EDIT_WORD); Cursor crs = (Cursor) arg0.getItemAtPosition(pos); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ITA, crs.getString(crs.getColumnIndex(Constants.FIELD_ITA))); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ENG, crs.getString(crs.getColumnIndex(Constants.FIELD_ENG))); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ID, id); MainActivity.this.startActivity(createWordIntentActivity); return true; } }); wordsListview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long id) { crs = (Cursor) arg0.getItemAtPosition(pos); String text = "Memory level: " + crs.getInt(crs.getColumnIndex(Constants.FIELD_RATING)) + "/5"; text = text + "\nLast edit: " + Utils.getDate(crs.getLong(crs.getColumnIndex(Constants.FIELD_TIMESTAMP))); crs = dbmanager.getContextById(id); if (crs != null && crs.getCount() > 0) { crs.moveToFirst(); String cont = crs.getString(crs.getColumnIndex(Constants.FIELD_CONTEXT)); text = text + "\n\n" + ((cont.equals("")) ? "Add a context sentence" : "Context:\n" + cont); } Toast t = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG); t.setGravity(Gravity.TOP, 0, 250); t.show(); } }); //Toast.makeText(getApplicationContext(), adapter.getCount()+" words in Memenguage", Toast.LENGTH_SHORT).show(); }
From source file:fm.smart.r1.activity.CreateExampleActivity.java
public void onClick(View v) { EditText exampleInput = (EditText) findViewById(R.id.create_example_sentence); EditText translationInput = (EditText) findViewById(R.id.create_example_translation); EditText exampleTransliterationInput = (EditText) findViewById(R.id.sentence_transliteration); EditText translationTransliterationInput = (EditText) findViewById(R.id.translation_transliteration); final String example = exampleInput.getText().toString(); final String translation = translationInput.getText().toString(); if (TextUtils.isEmpty(example) || TextUtils.isEmpty(translation)) { Toast t = Toast.makeText(this, "Example and translation are required fields", 150); t.setGravity(Gravity.CENTER, 0, 0); t.show();/*from w w w.j a v a 2 s . co m*/ } else { final String example_language_code = Utils.LANGUAGE_MAP.get(example_language); final String translation_language_code = Utils.LANGUAGE_MAP.get(translation_language); final String example_transliteration = exampleTransliterationInput.getText().toString(); final String translation_transliteration = translationTransliterationInput.getText().toString(); if (Main.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid // navigation // back to this? LoginActivity.return_to = CreateExampleActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("list_id", list_id); LoginActivity.params.put("item_id", item_id); LoginActivity.params.put("example", example); LoginActivity.params.put("translation", translation); LoginActivity.params.put("example_language", example_language); LoginActivity.params.put("translation_language", translation_language); LoginActivity.params.put("example_transliteration", example_transliteration); LoginActivity.params.put("translation_transliteration", translation_transliteration); startActivity(intent); } else { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Creating Example ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread create_example = new Thread() { public void run() { // TODO make this interruptable .../*if // (!this.isInterrupted())*/ try { // TODO failures here could derail all ... CreateExampleActivity.add_item_list_result = ItemActivity.addItemToList(list_id, item_id, CreateExampleActivity.this); CreateExampleActivity.create_example_result = createExample(example, example_language_code, example_transliteration, translation, translation_language_code, translation_transliteration, item_id, list_id); CreateExampleActivity.add_sentence_list_result = ItemActivity.addSentenceToList( CreateExampleActivity.create_example_result.http_response, item_id, list_id, CreateExampleActivity.this); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } myOtherProgressDialog.dismiss(); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { create_example.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { create_example.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); myOtherProgressDialog.show(); create_example.start(); } } }
From source file:cz.babi.android.remoteme.service.ConnectionService.java
/** * If server is unreachable we need to stop service and notice that to user. *///from ww w . j a va2s . com private void closeConnection() { if (Common.DEBUG) Log.d(TAG_CLASS_NAME, "[closeConnection]"); if (clientSocket != null) try { clientSocket.close(); } catch (IOException e) { if (Common.ERROR) Log.e(TAG_CLASS_NAME, "[stopService][Can not close client " + "socket.]"); } ConnectionService.server = null; ConnectionService.clientSocket = null; ConnectionService.in = null; ConnectionService.out = null; ConnectionService.needEncryptedCommunication = false; LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View toastLayout = mInflater.inflate(R.layout.toast_warning, null); TextView text = (TextView) toastLayout.findViewById(R.id.warning_text); text.setText(R.string.connection_service_connection_lost_text); Toast toast = new Toast(this); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(toastLayout); toast.show(); disconnectWithError = true; }
From source file:com.actionbarsherlock.internal.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }/*from ww w .ja va 2 s .c o m*/ final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }