List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:com.xargsgrep.portknocker.activity.EditHostActivity.java
private boolean validateAndDisplayErrors(Host host) { // boolean validHostname = HOSTNAME_PATTERN.matcher(host.getHostname()).matches(); // boolean validIP = InetAddressUtils.isIPv4Address(host.getHostname()); String errorText = ""; if (StringUtils.isBlank(host.getLabel())) { errorText = getString(R.string.toast_msg_enter_label); } else if (StringUtils.isBlank(host.getHostname())) { errorText = getString(R.string.toast_msg_enter_hostname); }//w w w . ja v a 2 s. c o m // else if (!validHostname && !validIP) { // errorText = getString(R.string.toast_msg_invalid_hostname); // } else if (host.getPorts() == null || host.getPorts().size() == 0) { errorText = getString(R.string.toast_msg_enter_port); } else if (host.getDelay() > MAX_DELAY_VALUE) { errorText = getString(R.string.toast_msg_delay_max_value) + MAX_DELAY_VALUE; } else { for (Port port : host.getPorts()) { if (port.getPort() > MAX_PORT_VALUE) { errorText = getString(R.string.toast_msg_invalid_port) + port.getPort(); break; } } } if (StringUtils.isNotBlank(errorText)) { Toast toast = Toast.makeText(this, errorText, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return false; } return true; }
From source file:fm.smart.r1.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 ww .j av a 2 s. c om*/ } 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 (LoginActivity.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("goal_id", goal_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_goal_result = new AddItemResult( Main.lookup.addItemToGoal(Main.transport, goal_id, item_id, null)); Result result = null; try { result = Main.lookup.createExample(Main.transport, translation, translation_language_code, translation, null, null, null); JSONObject json = new JSONObject(result.http_response); String text = json.getString("text"); String translation_id = json.getString("id"); result = Main.lookup.createExample(Main.transport, example, example_language_code, example_transliteration, translation_id, item_id, goal_id); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } CreateExampleActivity.create_example_result = new CreateExampleResult(result); } 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:org.prx.prp.view.StationInformationView.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.streaminfoview); final int streamID = this.getIntent().getExtras().getInt("STREAM_ID"); mContext = this; IntentFilter f = new IntentFilter(); f.addAction("org.prx.errorInStream"); this.registerReceiver(mIntentReceiver, new IntentFilter(f)); final ImageButton favoriteImageButton = (ImageButton) findViewById(R.id.station_favorite_button); if (StreamManager.isFavorite(streamID)) favoriteImageButton.setImageResource(R.drawable.tab_favorites); else/* www .java 2 s.c om*/ favoriteImageButton.setImageResource(R.drawable.tab_no_favorite); favoriteImageButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (StreamManager.isFavorite(streamID)) { StreamManager.removeFavorite(streamID); favoriteImageButton.setImageResource(R.drawable.tab_no_favorite); } else { StreamManager.addFavorite(streamID); favoriteImageButton.setImageResource(R.drawable.tab_favorites); } } }); stream = StreamManager.findById(streamID); TextView streamNameView = (TextView) findViewById(R.id.stream_name_1); TextView StreamNameViewSecondary = (TextView) findViewById(R.id.stream_name_2); streamNameView.setText(stream.getDisplayName()); StreamNameViewSecondary.setText(stream.getDisplayName()); TextView streamStateView = (TextView) findViewById(R.id.stream_state); streamStateView.setText(stream.getSource().getStatePrimary()); listView = (ListView) findViewById(R.id.stream_schedule_list_2); Thread t1 = new Thread(new Runnable() { public void run() { doUpdate(); } }); t1.start(); Toast msg = Toast.makeText(mContext, "Getting stream schedule...", Toast.LENGTH_LONG); msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2, msg.getYOffset() / 2); msg.show(); }
From source file:com.noshufou.android.su.service.ResultService.java
private void sendNotification(long appId, int callerUid, int allow, long currentTime, String appNotify) { // Check to see if we should notify if ((appNotify == null && !mNotify) || (appNotify != null && appNotify.equals("0")) || allow == -1) { return;/*w ww.jav a2 s . c om*/ } final String notificationMessage = getString( allow == 1 ? R.string.notification_text_allow : R.string.notification_text_deny, Util.getAppName(this, callerUid, false)); if (mNotifyType.equals("toast")) { ensurePrefs(); int lastNotificationUid = mPrefs.getInt(LAST_NOTIFICATION_UID, 0); long lastNotificationTime = mPrefs.getLong(LAST_NOTIFICATION_TIME, 0); final int gravity = Integer.parseInt(mPrefs.getString(Preferences.TOAST_LOCATION, "0")); if (lastNotificationUid != callerUid || lastNotificationTime + (5 * 1000) < currentTime) { mHandler.post(new Runnable() { @Override public void run() { Toast toast = Toast.makeText(getApplicationContext(), notificationMessage, Toast.LENGTH_SHORT); if (gravity > 0) { toast.setGravity(gravity, 0, 0); } toast.show(); } }); Editor editor = mPrefs.edit(); editor.putInt(LAST_NOTIFICATION_UID, callerUid); editor.putLong(LAST_NOTIFICATION_TIME, currentTime); editor.commit(); } } else if (mNotifyType.equals("status")) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(this, HomeActivity.class); // TODO: Include extras to tell HomeActivity what to do PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.stat_su) .setTicker(notificationMessage).setWhen(System.currentTimeMillis()) .setContentTitle(getText(R.string.app_name)).setContentText(notificationMessage) .setContentIntent(contentIntent).setAutoCancel(true).setOnlyAlertOnce(true).getNotification(); nm.notify(callerUid, notification); } }
From source file:tm.veriloft.mapsplayground.MapsActivity.java
public void showCenteredToast(String string) { if (string == null || string.equals("")) string = "null"; Toast toast = Toast.makeText(this.getApplicationContext(), string, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();//from w w w .j a v a2 s . co m }
From source file:edgargtzg.popularmovies.DiscoverMoviesFragment.java
/** * Updates the content of the view based on the selected sort by * option by the User.//w w w.j a v a 2s.c o m * * @param sortById id of the action to sort the movies * (for example: most popular, highest-rated) */ private void updateMovies(String sortById) { if (isNetworkAvailable()) { FetchMoviesTask fetchMoviesTask = new FetchMoviesTask(); fetchMoviesTask.execute(sortById); } else { Toast toast = Toast.makeText(getActivity(), R.string.error_msg_no_network, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } }
From source file:org.silena.main.RegistrationOld.java
private void RenderError(String massage) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_error, (ViewGroup) findViewById(R.id.toast_layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); text.setText(massage);/*from ww w . java2 s. co m*/ Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); return; }
From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.SurveyFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (interaction == null) { getActivity().finish();/*w w w .jav a 2 s . c o m*/ } List<Question> questions = interaction.getQuestions(); answers = new LinkedHashMap<String, Object>(questions.size()); View v = inflater.inflate(R.layout.apptentive_survey, container, false); TextView description = (TextView) v.findViewById(R.id.description); description.setText(interaction.getDescription()); final Button send = (Button) v.findViewById(R.id.send); String sendText = interaction.getSubmitText(); if (!TextUtils.isEmpty(sendText)) { send.setText(sendText); } send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Util.hideSoftKeyboard(getActivity(), view); boolean valid = validateAndUpdateState(); if (valid) { if (interaction.isShowSuccessMessage() && !TextUtils.isEmpty(interaction.getSuccessMessage())) { Toast toast = new Toast(getContext()); toast.setGravity(Gravity.FILL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); View toastView = inflater.inflate(R.layout.apptentive_survey_sent_toast, (LinearLayout) getView().findViewById(R.id.survey_sent_toast_root)); toast.setView(toastView); TextView actionTV = ((TextView) toastView.findViewById(R.id.survey_sent_action_text)); actionTV.setText(interaction.getSuccessMessage()); int actionColor = Util.getThemeColor(getContext(), R.attr.apptentiveSurveySentToastActionColor); if (actionColor != 0) { actionTV.setTextColor(actionColor); ImageView actionIcon = (ImageView) toastView.findViewById(R.id.survey_sent_action_icon); actionIcon.setColorFilter(actionColor); } toast.show(); } getActivity().finish(); EngagementModule.engageInternal(getActivity(), interaction, EVENT_SUBMIT); ApptentiveInternal.getInstance().getApptentiveTaskManager() .addPayload(new SurveyResponse(interaction, answers)); ApptentiveLog.d("Survey Submitted."); callListener(true); } else { Toast toast = new Toast(getContext()); toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); View toastView = inflater.inflate(R.layout.apptentive_survey_invalid_toast, (LinearLayout) getView().findViewById(R.id.survey_invalid_toast_root)); toast.setView(toastView); String validationText = interaction.getValidationError(); if (!TextUtils.isEmpty(validationText)) { ((TextView) toastView.findViewById(R.id.survey_invalid_toast_text)).setText(validationText); } toast.show(); } } }); questionsContainer = (LinearLayout) v.findViewById(R.id.questions); if (savedInstanceState == null) { questionsContainer.removeAllViews(); // Then render all the questions for (int i = 0; i < questions.size(); i++) { Question question = questions.get(i); BaseSurveyQuestionView surveyQuestionView; if (question.getType() == Question.QUESTION_TYPE_SINGLELINE) { surveyQuestionView = TextSurveyQuestionView.newInstance((SinglelineQuestion) question); } else if (question.getType() == Question.QUESTION_TYPE_MULTICHOICE) { surveyQuestionView = MultichoiceSurveyQuestionView.newInstance((MultichoiceQuestion) question); } else if (question.getType() == Question.QUESTION_TYPE_MULTISELECT) { surveyQuestionView = MultiselectSurveyQuestionView.newInstance((MultiselectQuestion) question); } else if (question.getType() == Question.QUESTION_TYPE_RANGE) { surveyQuestionView = RangeSurveyQuestionView.newInstance((RangeQuestion) question); } else { surveyQuestionView = null; } if (surveyQuestionView != null) { surveyQuestionView.setOnSurveyQuestionAnsweredListener(this); getRetainedChildFragmentManager().beginTransaction() .add(R.id.questions, surveyQuestionView, Integer.toString(i)).commit(); } } } else { List<Fragment> fragments = getRetainedChildFragmentManager().getFragments(); for (Fragment fragment : fragments) { BaseSurveyQuestionView questionFragment = (BaseSurveyQuestionView) fragment; questionFragment.setOnSurveyQuestionAnsweredListener(this); } } return v; }
From source file:org.occupycincy.android.OccupyCincyActivity.java
private void setToast(String text) { Context context = getApplicationContext(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.BOTTOM, 0, 0); toast.show();/*from ww w. j a v a2 s . c o m*/ }
From source file:dev.ronlemire.contactclientcloud.MainActivity.java
private boolean isContactLoaded() { boolean loaded = contactLoaded != null; if (loaded == false) { Toast message = Toast.makeText(this, R.string.no_contact_selected, Toast.LENGTH_SHORT); message.setGravity(Gravity.CENTER, message.getXOffset(), message.getYOffset()); message.show();//from w w w. j ava 2s .co m } return loaded; }