Example usage for android.widget Toast show

List of usage examples for android.widget Toast show

Introduction

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

Prototype

public void show() 

Source Link

Document

Show the view for the specified duration.

Usage

From source file:nl.sogeti.android.gpstracker.actions.ShareTrack.java

/**
 * POST a (GPX) file to the 0.6 API of the OpenStreetMap.org website publishing 
 * this track to the public.//from w  w w  .  j  av  a 2  s.co m
 * 
 * @param fileUri
 * @param contentType
 */
private void sendToOsm(Uri fileUri, Uri trackUri, String contentType) {
    String username = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.OSM_USERNAME, "");
    String password = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.OSM_PASSWORD, "");
    String visibility = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.OSM_VISIBILITY,
            "trackable");
    File gpxFile = new File(fileUri.getEncodedPath());
    String hostname = getString(R.string.osm_post_host);
    Integer port = new Integer(getString(R.string.osm_post_port));
    HttpHost targetHost = new HttpHost(hostname, port, "http");

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = null;
    String responseText = "";
    int statusCode = 0;
    Cursor metaData = null;
    String sources = null;
    try {
        metaData = this.getContentResolver().query(Uri.withAppendedPath(trackUri, "metadata"),
                new String[] { MetaData.VALUE }, MetaData.KEY + " = ? ",
                new String[] { Constants.DATASOURCES_KEY }, null);
        if (metaData.moveToFirst()) {
            sources = metaData.getString(0);
        }
        if (sources != null && sources.contains(LoggerMap.GOOGLE_PROVIDER)) {
            throw new IOException("Unable to upload track with materials derived from Google Maps.");
        }

        // The POST to the create node
        HttpPost method = new HttpPost(getString(R.string.osm_post_context));

        // Preemptive basic auth on the first request 
        method.addHeader(
                new BasicScheme().authenticate(new UsernamePasswordCredentials(username, password), method));

        // Build the multipart body with the upload data
        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        entity.addPart("file", new FileBody(gpxFile));
        entity.addPart("description", new StringBody(queryForTrackName()));
        entity.addPart("tags", new StringBody(queryForNotes()));
        entity.addPart("visibility", new StringBody(visibility));
        method.setEntity(entity);

        // Execute the POST to OpenStreetMap
        response = httpclient.execute(targetHost, method);

        // Read the response
        statusCode = response.getStatusLine().getStatusCode();
        InputStream stream = response.getEntity().getContent();
        responseText = convertStreamToString(stream);
    } catch (IOException e) {
        Log.e(TAG, "Failed to upload to " + targetHost.getHostName() + "Response: " + responseText, e);
        responseText = getString(R.string.osm_failed) + e.getLocalizedMessage();
        Toast toast = Toast.makeText(this, responseText, Toast.LENGTH_LONG);
        toast.show();
    } catch (AuthenticationException e) {
        Log.e(TAG, "Failed to upload to " + targetHost.getHostName() + "Response: " + responseText, e);
        responseText = getString(R.string.osm_failed) + e.getLocalizedMessage();
        Toast toast = Toast.makeText(this, responseText, Toast.LENGTH_LONG);
        toast.show();
    } finally {
        if (metaData != null) {
            metaData.close();
        }
    }

    if (statusCode == 200) {
        Log.i(TAG, responseText);
        CharSequence text = getString(R.string.osm_success) + responseText;
        Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG);
        toast.show();
    } else {
        Log.e(TAG, "Failed to upload to error code " + statusCode + " " + responseText);
        CharSequence text = getString(R.string.osm_failed) + responseText;
        Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG);
        toast.show();
    }
}

From source file:at.fhooe.mcm.saap.facebook.HelloFacebookSampleActivity.java

private void showPickerFragment(PickerFragment<?> fragment) {
    fragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override/* w  w  w. jav  a2 s  . c om*/
        public void onError(PickerFragment<?> pickerFragment, FacebookException error) {
            String text = getString(R.string.exception, error.getMessage());
            Toast toast = Toast.makeText(HelloFacebookSampleActivity.this, text, Toast.LENGTH_SHORT);
            toast.show();
        }
    });

    FragmentManager fm = getSupportFragmentManager();
    fm.beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit();

    controlsContainer.setVisibility(View.GONE);

    // We want the fragment fully created so we can use it immediately.
    fm.executePendingTransactions();

    fragment.loadData(true);
}

From source file:at.alladin.rmbt.android.map.RMBTMapFragment.java

private void showInfoToast() {
    final Map<String, String> currentMapOptionTitles = ((RMBTMainActivity) getActivity())
            .getCurrentMapOptionTitles();
    String infoString = "";
    for (final String s : currentMapOptionTitles.values()) {
        if (infoString.length() > 0)
            infoString += "\n";

        infoString += s;/*from   w  w w  . j ava 2  s  .  c  o  m*/
    }
    if (infoString.length() > 0) {
        final Toast toast = Toast.makeText(getActivity(), infoString, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.BOTTOM, 0, 0);
        toast.show();
    }
}

From source file:com.spydiko.rotationmanager.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings: // Refresh button
        //            if(AppSpecificOrientation.LOG) Log.d(TAG, "action_settings");
        packageManager = getPackageManager();
        UpdateData updateData = new UpdateData();
        this.adapter = new InteractiveArrayAdapter(this, activities, (AppSpecificOrientation) getApplication());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            updateData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
        else/*from w w  w .j  a  v a 2 s. c o  m*/
            updateData.execute((Void[]) null);
        //            if(AppSpecificOrientation.LOG) Log.d(TAG, "execute");
        lv.setAdapter(adapter);
        break;
    case R.id.itemToggleService: // Play - Stop Service
        //                if(AppSpecificOrientation.LOG) Log.d(TAG, "entered");
        if (AppSpecificOrientation.isServiceRunning()) {
            item.setTitle(R.string.titleServiceStop);
            //               item.setIcon(android.R.drawable.ic_media_play);
            stopService(new Intent(this, NewOrieService.class));
            AppSpecificOrientation.setServiceRunning(false);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "if");
            //               if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            item.setIcon(R.drawable.ic_off_button_rotation_manager);
        } else {
            item.setTitle(R.string.titleServiceStart);
            //               item.setIcon(android.R.drawable.ic_media_pause);
            startService(new Intent(this, NewOrieService.class));
            Toast toast = Toast.makeText(this, getString(R.string.notification_text), Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
            toast.show();
            //               if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            item.setIcon(R.drawable.ic_on_button_rotation_manager);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "else");
        }
        break;

    case R.id.setOnBoot: // Set broadcast receiver on or off
        if (AppSpecificOrientation.getBoot()) {
            item.setChecked(false);
            AppSpecificOrientation.setBoot(false);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_off);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false");
        } else {
            item.setChecked(true);
            AppSpecificOrientation.setBoot(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_on);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true");
        }

        break;
    case R.id.howTo: // Open How To Activity
        startActivityForResult((new Intent(this, HowToActivity.class)), 1);
        break;
    case R.id.about: // Open About Activity
        startActivityForResult((new Intent(this, AboutActivity.class)), 1);
        break;
    case R.id.donate:
        startActivity(new Intent(this, DonateActivity.class));
        break;
    case R.id.permNotification:
        if (AppSpecificOrientation.isPermNotification()) {
            item.setChecked(false);
            AppSpecificOrientation.setPermNotification(false);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_off);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false");
            if (AppSpecificOrientation.isServiceRunning())
                startService(new Intent(this, NewOrieService.class));
        } else {
            item.setChecked(true);
            AppSpecificOrientation.setPermNotification(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_on);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true");
            if (AppSpecificOrientation.isServiceRunning())
                startService(new Intent(this, NewOrieService.class));
        }

        break;
    case R.id.license:
        startActivity(new Intent(this, License.class));
        break;
    case android.R.id.home:
        menu.toggle();
        return true;
    }
    return true;
}

From source file:com.sam_chordas.android.stockhawk.ui.MyStocksActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    setContentView(R.layout.activity_my_stocks);
    // The intent service is for executing immediate pulls from the Yahoo API
    // GCMTaskService can only schedule tasks, they cannot execute immediately
    mServiceIntent = new Intent(this, StockIntentService.class);
    if (savedInstanceState == null) {
        // Run the initialize task service so that some stocks appear upon an empty database
        mServiceIntent.putExtra("tag", "init");
        if (Utils.isNetworkAvailable(mContext)) {
            startService(mServiceIntent);
        } else {//from   w  ww  .j av a 2 s  .  c o  m
            networkToast();
        }
    }
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    getLoaderManager().initLoader(CURSOR_LOADER_ID, null, this);

    mCursorAdapter = new QuoteCursorAdapter(this, null);
    recyclerView.addOnItemTouchListener(
            new RecyclerViewItemClickListener(this, new RecyclerViewItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    // CursorAdapter returns a cursor at the correct position for getItem(), or null
                    // if it cannot seek to that position.
                    Intent intent = new Intent(getApplicationContext(), LineGraphActivity.class);
                    intent.putExtra(STOCK_ITEM, mCursorAdapter.getItemSymbol(position));
                    startActivity(intent);
                }
            }));
    recyclerView.setAdapter(mCursorAdapter);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.attachToRecyclerView(recyclerView);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Utils.isNetworkAvailable(mContext)) {
                new MaterialDialog.Builder(mContext).title(R.string.symbol_search)
                        .content(R.string.content_test).inputType(InputType.TYPE_CLASS_TEXT)
                        .input(R.string.input_hint, R.string.input_prefill, new MaterialDialog.InputCallback() {
                            @Override
                            public void onInput(MaterialDialog dialog, CharSequence input) {
                                // On FAB click, receive user input. Make sure the stock doesn't already exist
                                // in the DB and proceed accordingly
                                Cursor c = getContentResolver().query(QuoteProvider.Quotes.CONTENT_URI,
                                        new String[] { QuoteColumns.SYMBOL }, QuoteColumns.SYMBOL + "= ?",
                                        new String[] { input.toString() }, null);
                                if (c.getCount() != 0) {
                                    Toast toast = Toast.makeText(MyStocksActivity.this,
                                            "This stock is already saved!", Toast.LENGTH_LONG);
                                    toast.setGravity(Gravity.CENTER, Gravity.CENTER, 0);
                                    toast.show();
                                    return;
                                } else {
                                    // Add the stock to DB
                                    mServiceIntent.putExtra("tag", "add");
                                    mServiceIntent.putExtra("symbol", input.toString());
                                    startService(mServiceIntent);

                                }
                            }
                        }).show();
            } else {
                networkToast();
            }

        }
    });

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mCursorAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);

    mTitle = getTitle();
    if (Utils.isNetworkAvailable(mContext)) {
        long period = 30L;
        long flex = 10L;
        String periodicTag = "periodic";

        // create a periodic task to pull stocks once every hour after the app has been opened. This
        // is so Widget data stays up to date.
        PeriodicTask periodicTask = new PeriodicTask.Builder().setService(StockTaskService.class)
                .setPeriod(period).setFlex(flex).setTag(periodicTag)
                .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED).setRequiresCharging(false).build();
        // Schedule task with tag "periodic." This ensure that only the stocks present in the DB
        // are updated.
        GcmNetworkManager.getInstance(this).schedule(periodicTask);
    }

    if (!Utils.isNetworkAvailable(getApplicationContext())) {
        networkToast();
    }
}

From source file:fi.mikuz.boarder.gui.DropboxMenu.java

public void download(final ArrayList<String> boards, boolean cleanUnusedFiles) {

    int currentBoardIndex = 1;
    int numberOfBoards = boards.size();

    DropboxCache dropboxCache = new DropboxCache();
    DropboxCacheUtils.load(dropboxCache);

    if (numberOfBoards > 0) {
        try {//  w  ww  .  j  a  v  a 2  s.c  o  m
            for (String boardName : boards) {

                if (cleanUnusedFiles) {
                    // Clean unnecessary local files
                    try {
                        checkUnusedLocal(new File(SoundboardMenu.mSbDir, boardName), dropboxCache);
                    } catch (NullPointerException npe) {
                        Log.w(SoundboardMenu.TAG, "Failed to delete unused local files", npe);
                    } catch (IOException e) {
                        Log.w(SoundboardMenu.TAG, "Failed to delete unused local files", e);
                    }
                }

                // Download necessary files
                List<Entry> fileEntrys = mApi.metadata("/" + boardName, 0, null, true, null).contents;
                downloadBoard(fileEntrys, currentBoardIndex, numberOfBoards, dropboxCache);
                currentBoardIndex++;
            }
        } catch (DropboxException e) {
            Log.e(TAG, "Failed to download", e);
        } catch (FileNotFoundException e) {
            Log.e(TAG, "Failed to download", e);
        }
    } else {
        Toast error = Toast.makeText(DropboxMenu.this, "Please select boards", Toast.LENGTH_LONG);
        error.show();
    }

    DropboxCacheUtils.save(dropboxCache);
    mWaitDialog.dismiss();
}

From source file:fi.mikuz.boarder.gui.DropboxMenu.java

public void upload(final ArrayList<String> boards, boolean cleanUnusedFiles) {

    int currentBoardIndex = 1;
    int numberOfBoards = boards.size();

    DropboxCache dropboxCache = new DropboxCache();
    DropboxCacheUtils.load(dropboxCache);

    if (numberOfBoards > 0) {
        try {//from  w w  w. ja v a 2  s . c  o  m
            for (String boardName : boards) {

                try {
                    Entry dbBoardDir = mApi.metadata("/" + boardName, 0, null, false, null);
                    if (!dbBoardDir.isDeleted && !dbBoardDir.isDir) {
                        mApi.delete("/" + boardName);
                        mApi.createFolder("/" + boardName);
                    }
                } catch (DropboxException e2) {
                    Log.v(TAG, "Creating new board directory /" + boardName + " in Dropbox");
                    mApi.createFolder("/" + boardName);
                }

                if (cleanUnusedFiles) {
                    // Check for unnecessary files in Dropbox
                    checkUnusedDropbox(mApi.metadata("/" + boardName, 0, null, true, null), dropboxCache);
                }

                // Upload necessary files
                uploadBoard(new File(SoundboardMenu.mSbDir, boardName), currentBoardIndex, numberOfBoards,
                        dropboxCache);
                currentBoardIndex++;
            }
        } catch (DropboxException e) {
            Log.e(TAG, "Failed to upload", e);
        }
    } else {
        Toast error = Toast.makeText(DropboxMenu.this, "Please select boards", Toast.LENGTH_LONG);
        error.show();
    }

    DropboxCacheUtils.save(dropboxCache);
    mWaitDialog.dismiss();
}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

@Override
public void start() {
    Toast t = Toast.makeText(PlayerActivity.this, "1", Toast.LENGTH_SHORT);
    t.show();
    player.getPlayerControl().start();//from   w  ww  .jav a2  s. c  om
}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

@Override
public void pause() {
    Toast t = Toast.makeText(PlayerActivity.this, "2", Toast.LENGTH_SHORT);
    t.show();
    player.getPlayerControl().pause();/* w ww  . j av  a  2s .c o  m*/
}