Example usage for android.widget Toast setGravity

List of usage examples for android.widget Toast setGravity

Introduction

In this page you can find the example usage for android.widget Toast setGravity.

Prototype

public void setGravity(int gravity, int xOffset, int yOffset) 

Source Link

Document

Set the location at which the notification should appear on the screen.

Usage

From source file:io.plaidapp.ui.DribbbleLogin.java

private void showLoggedInUser() {
    Gson gson = new GsonBuilder().setDateFormat(DribbbleService.DATE_FORMAT).create();

    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(DribbbleService.ENDPOINT)
            .setConverter(new GsonConverter(gson))
            .setRequestInterceptor(new AuthInterceptor(dribbblePrefs.getAccessToken())).build();

    DribbbleService dribbbleApi = restAdapter.create((DribbbleService.class));
    dribbbleApi.getAuthenticatedUser(new Callback<User>() {
        @Override//  w ww.  j a  v  a2s . c o  m
        public void success(User user, Response response) {
            dribbblePrefs.setLoggedInUser(user);
            Toast confirmLogin = new Toast(getApplicationContext());
            View v = LayoutInflater.from(DribbbleLogin.this).inflate(R.layout.toast_logged_in_confirmation,
                    null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.name);
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.avatar_url).placeholder(R.drawable.ic_player)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DribbbleLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void failure(RetrofitError error) {
        }
    });
}

From source file:com.indoorsy.frash.easemob.activity.ChatActivity.java

/**
 * ?uri??//from   ww w  .ja v a  2 s.  c  o m
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;
        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, R.string.not_find_image, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(this, R.string.not_find_image, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        sendPicture(file.getAbsolutePath());
    }
}

From source file:org.nla.tarotdroid.lib.ui.TabGameSetActivity.java

/**
 * Starts the whole Facebook post process.
 * /*from   w  ww .  java  2  s.  com*/
 * @param session
 */
private void launchPostProcess(final Session session) {

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toast_layout_root));

    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon_facebook_released);
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(this.getString(R.string.msgFacebookNotificationInProgress));

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();

    Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {

        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (session == Session.getActiveSession()) {
                if (user != null) {
                    int notificationId = FacebookHelper.showNotificationStartProgress(TabGameSetActivity.this);
                    AppContext.getApplication().getNotificationIds()
                            .put(TabGameSetActivity.this.gameSet.getUuid(), notificationId);

                    AppContext.getApplication().setLoggedFacebookUser(user);
                    UpSyncGameSetTask task = new UpSyncGameSetTask(TabGameSetActivity.this, progressDialog);
                    task.setCallback(TabGameSetActivity.this.upSyncCallback);
                    task.execute(TabGameSetActivity.this.gameSet);
                }
            }
            if (response.getError() != null) {
                AuditHelper.auditErrorAsString(ErrorTypes.facebookNewMeRequestFailed,
                        response.getError().toString(), TabGameSetActivity.this);
            }
        }
    });
    request.executeAsync();
}

From source file:eu.faircode.adblocker.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());/*from   w ww . j  a v  a 2s  .c om*/

    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }

    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    swEnabled = (SwitchCompat) findViewById(R.id.swEnabled);
    running = true;

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);

    // Upgrade
    Receiver.upgrade(initialized, this);

    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }

    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);

    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);

    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });

    // Title
    getSupportActionBar().setTitle(null);

    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivQueue.getLeft(),
                    Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    // On/off switch
    swEnabled.setChecked(enabled);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();

            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view)
                                .setCancelable(false)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (running) {
                                            Log.i(TAG, "Start intent=" + prepare);
                                            try {
                                                startActivityForResult(prepare, REQUEST_VPN);
                                            } catch (Throwable ex) {
                                                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                                Util.sendCrashReport(ex, ActivityMain.this);
                                                onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                                prefs.edit().putBoolean("enabled", false).apply();
                                            }
                                        }
                                    }
                                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        dialogVpn = null;
                                    }
                                }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    Util.sendCrashReport(ex, ActivityMain.this);
                    prefs.edit().putBoolean("enabled", false).apply();
                }

            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();

    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivMetered.getLeft(),
                    Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);

    // Disabled warning
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);

    // Application list
    //        RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    //        rvApplication.setHasFixedSize(true);
    //        rvApplication.setLayoutManager(new LinearLayoutManager(this));
    //        adapter = new AdapterRule(this);
    //        rvApplication.setAdapter(adapter);

    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    //        swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    //        swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    //        swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    //        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    //            @Override
    //            public void onRefresh() {
    //                Rule.clearCache(ActivityMain.this);
    //                ServiceSinkhole.reload("pull", ActivityMain.this);
    //                updateApplicationList(null);
    //            }
    //        });

    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);

    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);

    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);

    // First use
    if (!initialized) {
        // Create view
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.first, null, false);
        TextView tvFirst = (TextView) view.findViewById(R.id.tvFirst);
        tvFirst.setMovementMethod(LinkMovementMethod.getInstance());

        // Show dialog
        dialogFirst = new AlertDialog.Builder(this).setView(view).setCancelable(false)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            prefs.edit().putBoolean("initialized", true).apply();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            finish();
                    }
                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        dialogFirst = null;
                    }
                }).create();
        dialogFirst.show();
    }

    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

    // Update IAB SKUs
    try {
        iab = new IAB(new IAB.Delegate() {
            @Override
            public void onReady(IAB iab) {
                try {
                    iab.updatePurchases();

                    if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this))
                        prefs.edit().putBoolean("log", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) {
                        if (!"teal".equals(prefs.getString("theme", "teal")))
                            prefs.edit().putString("theme", "teal").apply();
                    }
                    if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this))
                        prefs.edit().putBoolean("show_stats", false).apply();
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                } finally {
                    iab.unbind();
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    checkExtras(getIntent());
}

From source file:com.concentricsky.android.khanacademy.data.remote.KAAPIAdapter.java

/**
 * Call me from the UI thread, please./*from   w  ww . j  ava 2 s  .c  o m*/
 * 
 * Meant for use by broadcast receivers receiving ACTION_BADGE_EARNED.
 * */
public void toastBadge(Badge badge) {
    BadgeCategory category = badge.getCategory();
    //      Dao<BadgeCategory, Integer> dao = dataService.getHelper().getDao(BadgeCategory.class);
    //      dao.refresh(category);

    Toast toast = new Toast(dataService);
    View content = LayoutInflater.from(dataService).inflate(R.layout.badge, null, false);
    ImageView iconView = (ImageView) content.findViewById(R.id.badge_image);
    TextView pointsView = (TextView) content.findViewById(R.id.badge_points);
    TextView titleView = (TextView) content.findViewById(R.id.badge_title);
    TextView descView = (TextView) content.findViewById(R.id.badge_description);

    iconView.setImageResource(category.getIconResourceId());
    int points = badge.getPoints();
    if (points > 0) {
        pointsView.setText(points + "");
    } else {
        pointsView.setVisibility(View.GONE);
    }
    titleView.setText(badge.getDescription());
    descView.setText(badge.getSafe_extended_description());

    toast.setView(content);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setGravity(Gravity.TOP, 0, 200);
    toast.show();
}

From source file:pandroid.agent.PandroidAgentListener.java

private void contact() {

    Toast toast = Toast.makeText(getApplicationContext(),

            getString(R.string.loading), Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.BOTTOM, 0, 0);
    toast.show();//from ww  w.  j a v a 2s  . c o m

    Date date = new Date();

    putSharedData("PANDROID_DATA", "lastContact", Long.toString(date.getTime() / 1000), "long");
    Boolean xmlBuilt = true;
    String xml = "";

    try {
        xml = new buildXMLTask().execute().get();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        xmlBuilt = false;
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        xmlBuilt = false;
    }

    if (xmlBuilt) {
        //TODO
    } else {
        //TODO
    }

    new contactTask().execute(xml);
    //TODO ensure not a problem
    //updateValues();

}

From source file:io.plaidapp.ui.DesignerNewsLogin.java

private void showLoggedInUser() {
    DesignerNewsService designerNewsService = new RestAdapter.Builder()
            .setEndpoint(DesignerNewsService.ENDPOINT)
            .setRequestInterceptor(new ClientAuthInterceptor(designerNewsPrefs.getAccessToken(),
                    BuildConfig.DESIGNER_NEWS_CLIENT_ID))
            .build().create(DesignerNewsService.class);
    designerNewsService.getAuthedUser(new Callback<UserResponse>() {
        @Override//from  w  w  w . ja va 2s. c  o m
        public void success(UserResponse userResponse, Response response) {
            final User user = userResponse.user;
            designerNewsPrefs.setLoggedInUser(user);
            Toast confirmLogin = new Toast(getApplicationContext());
            View v = LayoutInflater.from(DesignerNewsLogin.this).inflate(R.layout.toast_logged_in_confirmation,
                    null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.display_name);
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.portrait_url)
                    .placeholder(R.drawable.avatar_placeholder)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DesignerNewsLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void failure(RetrofitError error) {
            Log.e(getClass().getCanonicalName(), error.getMessage(), error);
        }
    });
}

From source file:com.example.multi_ndef.Frag_Write.java

private void displayMessage(String message) {

    status = true;/*from  w  w w.j  a v a2  s  .  c o  m*/
    Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0);
    toast.show();
}

From source file:io.plaidapp.ui.DesignerNewsLogin.java

@SuppressLint("InflateParams")
void showLoggedInUser() {
    final Call<User> authedUser = designerNewsPrefs.getApi().getAuthedUser();
    authedUser.enqueue(new Callback<User>() {
        @Override//from w  w w.  j  a va2s  . c  om
        public void onResponse(Call<User> call, Response<User> response) {
            if (!response.isSuccessful())
                return;
            final User user = response.body();
            designerNewsPrefs.setLoggedInUser(user);
            final Toast confirmLogin = new Toast(getApplicationContext());
            final View v = LayoutInflater.from(DesignerNewsLogin.this)
                    .inflate(R.layout.toast_logged_in_confirmation, null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.display_name.toLowerCase());
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.portrait_url)
                    .placeholder(R.drawable.avatar_placeholder)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DesignerNewsLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
            Log.e(getClass().getCanonicalName(), t.getMessage(), t);
        }
    });
}

From source file:com.ccxt.whl.activity.SettingsFragment.java

/**
 * ?uri?/*w  w w  . j  a  va 2  s  . co  m*/
 * 
 * @param selectedImage
 */
private String getpathfromUri(Uri selectedImage) {
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getActivity().getContentResolver().query(selectedImage, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return null;
        }
        return picturePath;
        //sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return null;

        }
        return file.getAbsolutePath();
    }

}