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: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;/*w ww  .  j  a v  a 2s  . com*/
    }
    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// ww  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.licubeclub.zionhs.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Calendar Cal = Calendar.getInstance();
    AMorPM = Cal.get(Calendar.AM_PM);
    DAYofWEEK = Cal.get(Calendar.DAY_OF_WEEK);
    DAYofMONTH = Cal.get(Calendar.DAY_OF_MONTH);

    Log.d("DAYofMONTH", String.valueOf(Cal.get(Calendar.DAY_OF_MONTH)));

    cManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mobile = cManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    wifi = cManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    setContentView(R.layout.activity_main);

    /*//  www .  j a va  2s.  c o m
    * TODO - ?    (/?/?)
    * */
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    MEAL = (TextView) findViewById(R.id.mealdata);
    SCHEDULE = (TextView) findViewById(R.id.schedata);
    NOTIPARNTS = (TextView) findViewById(R.id.notiparentdata);
    NOTICES = (TextView) findViewById(R.id.notidata);

    View notices = findViewById(R.id.notices);
    View meal = findViewById(R.id.meal);
    View schedule = findViewById(R.id.schedule);
    View notices_parents = findViewById(R.id.notices_parents);

    notices.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent0 = new Intent(MainActivity.this, Notices.class);
            intent0.putExtra("url",
                    "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=58");
            intent0.putExtra("title", getResources().getString(R.string.notices));
            startActivity(intent0);
        }
    });

    meal.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, MealActivity.class);
            startActivity(intent);
        }
    });

    schedule.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, Schedule.class);
            startActivity(intent);
        }
    });

    notices_parents.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, Notices.class);
            intent.putExtra("url",
                    "http://www.zion.hs.kr/main.php?menugrp=110200&master=bbs&act=list&master_sid=59");
            intent.putExtra("title", getResources().getString(R.string.title_activity_notices__parents));
            startActivity(intent);
        }
    });

    //Navigation Drawer
    DrawerArray = new ArrayList<String>();
    DrawerArray.add(getString(R.string.meal));
    DrawerArray.add(getString(R.string.schedule));
    DrawerArray.add(getString(R.string.title_activity_notices__parents));
    DrawerArray.add(getString(R.string.notices));
    DrawerArray.add(getString(R.string.schoolintro));
    DrawerArray.add(getString(R.string.schoolinfo));
    DrawerArray.add(getString(R.string.appsettings_apinfo_title));

    IconArray = new ArrayList<Drawable>();
    IconArray.add(getResources().getDrawable(R.drawable.ic_meal));
    IconArray.add(getResources().getDrawable(R.drawable.ic_event_black_24dp));
    IconArray.add(getResources().getDrawable(R.drawable.ic_insert_drive_file_black_24dp));
    IconArray.add(getResources().getDrawable(R.drawable.ic_speaker_notes_black_24dp));
    IconArray.add(getResources().getDrawable(R.drawable.ic_intro));
    IconArray.add(getResources().getDrawable(R.drawable.ic_school));
    IconArray.add(getResources().getDrawable(R.drawable.ic_info_black_24dp));

    NavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    DrawerList = (ListView) findViewById(R.id.left_drawer);

    Adapter = new DrawerListAdapter(this, DrawerArray, IconArray);
    DrawerList.setAdapter(Adapter);

    //Listen for Navigation Drawer State
    DrawerToggle = new ActionBarDrawerToggle(this, NavigationDrawer, R.string.drawer_open,
            R.string.drawer_close) {
        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            isNavDrawerOpen = false;
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            //                getSupportActionBar().setBackgroundDrawable(Darkblue);
            isNavDrawerOpen = true;
        }

    };
    NavigationDrawer.setDrawerListener(DrawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    //Drawer Item Click action
    DrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                startActivity(new Intent(MainActivity.this, MealActivity.class));
                break;
            case 1:
                startActivity(new Intent(MainActivity.this, Schedule.class));
                break;
            case 2:
                Intent intent = new Intent(MainActivity.this, Notices.class);
                intent.putExtra("url",
                        "http://www.zion.hs.kr/main.php?menugrp=110200&master=bbs&act=list&master_sid=59");
                intent.putExtra("title", getResources().getString(R.string.title_activity_notices__parents));
                startActivity(intent);
                break;
            case 3:
                Intent intent0 = new Intent(MainActivity.this, Notices.class);
                intent0.putExtra("url",
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=58");
                intent0.putExtra("title", getResources().getString(R.string.notices));
                startActivity(intent0);
                break;
            case 4:
                startActivity(new Intent(MainActivity.this, Schoolintro.class));
                break;
            case 5:
                startActivity(new Intent(MainActivity.this, Schoolinfo.class));
                break;
            case 6:
                startActivity(new Intent(MainActivity.this, Appinfo.class));
                break;
            }
        }
    });

    SRL = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    if (mobile.isConnected() || wifi.isConnected()) {
        networkTask();
    } else {

        Toast toast = Toast.makeText(getApplicationContext(),
                getResources().getString(R.string.network_connection_warning), Toast.LENGTH_LONG);
        toast.setGravity(Gravity.BOTTOM, 0, 0);
        toast.show();
    }
    SRL.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            cManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            mobile = cManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
            wifi = cManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            if (mobile.isConnected() || wifi.isConnected()) {
                networkTask();
            } else {

                Toast toast = Toast.makeText(getApplicationContext(),
                        getResources().getString(R.string.network_connection_warning), Toast.LENGTH_LONG);
                toast.setGravity(Gravity.BOTTOM, 0, 0);
                toast.show();
                SRL.setRefreshing(false);
            }
        }
    });

}

From source file:com.amazon.appstream.fireclient.FireClientActivity.java

@Override
public void onErrorMessage(final boolean fatal, final String message) {
    runOnUiThread(new Runnable() {
        @Override/*from   w w  w . ja  va 2  s  .  c o m*/
        public void run() {
            if (mStopped) {
                Log.i(TAG, "Ignoring error during stopped state :" + (fatal ? "fatal" : "non fatal") + ":"
                        + message);
                return; // ignore errors if we're stopped.
            }
            if (fatal) {
                // Tell the app it needs to pause.
                AppStreamInterface.pause(true);
                ErrorDialogFragment dialog = new ErrorDialogFragment();
                dialog.setMessage(message);
                dialog.show(getSupportFragmentManager(), "ErrorDialogFragment");

                // And finally stop AppStream; kill the interfaces to give us a clean slate.
                stopAppStream();
            } else {
                if (mConnectDialog != null) {
                    openConnectDialog(message);
                } else {
                    Toast toast = Toast.makeText(FireClientActivity.this, message, Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.RIGHT | Gravity.BOTTOM, 10, 10);
                    toast.show();
                }
            }
        }
    });
}

From source file:com.vkassin.mtrade.Common.java

public static void login(final Context ctx) {

    // ctx = Common.app_ctx;
    Common.connected = false;/*from ww w  .j  ava  2s . com*/

    if (inLogin)
        return;

    inLogin = true;

    if (Common.mainActivity != null)
        Common.mainActivity.handler.sendMessage(
                Message.obtain(Common.mainActivity.handler, Common.mainActivity.DISMISS_PROGRESS_DIALOG));

    // while(true) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.login_dialog);
    dialog.setTitle(R.string.LoginDialogTitle);
    dialog.setCancelable(false);

    final EditText nametxt = (EditText) dialog.findViewById(R.id.loginnameedit);
    final EditText passtxt = (EditText) dialog.findViewById(R.id.passwordedit);
    final EditText passtxt1 = (EditText) dialog.findViewById(R.id.passwordedit1);
    final EditText passtxt2 = (EditText) dialog.findViewById(R.id.passwordedit2);
    final EditText mailtxt = (EditText) dialog.findViewById(R.id.emailedit2);

    String nam = myaccount.get("name");
    Common.oldName = nam;

    if (nam != null) {

        nametxt.setText(nam);
        passtxt.requestFocus();
    }

    Button customDialog_Register = (Button) dialog.findViewById(R.id.goregister);
    customDialog_Register.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.setTitle(R.string.LoginDialogTitle1);
            final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
            layreg.setVisibility(View.VISIBLE);
            final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
            laylog.setVisibility(View.GONE);
        }

    });

    Button customDialog_Register1 = (Button) dialog.findViewById(R.id.goregister1);
    customDialog_Register1.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            if (mailtxt.getText().length() < 1) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectEmail, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

                return;
            }

            if (passtxt1.getText().length() < 1) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                return;
            }

            if (!passtxt2.getText().toString().equals(passtxt1.getText().toString())) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword1, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                return;
            }

            try {

                Socket sock = new Socket(ip_addr, port_register);

                JSONObject msg = new JSONObject();
                msg.put("objType", Common.MSG_REGISTER);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("user", mailtxt.getText().toString());
                msg.put("passwd", passtxt1.getText().toString());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("sign", sign(mailtxt.getText().toString(), passtxt1.getText().toString()));

                byte[] array = msg.toString().getBytes();
                ByteBuffer buff = ByteBuffer.allocate(array.length + 4);
                buff.putInt(array.length);
                buff.put(array);
                sock.getOutputStream().write(buff.array());

                ByteBuffer buff1 = ByteBuffer.allocate(4);
                buff1.put(readMsg(sock.getInputStream(), 4));
                buff1.position(0);
                int pkgSize = buff1.getInt();
                // Log.i(TAG, "size = "+pkgSize);
                String s = new String(readMsg(sock.getInputStream(), pkgSize));

                sock.close();

                JSONObject jo = new JSONObject(s);

                Log.i(TAG, "register answer = " + jo);

                int t = jo.getInt("status");
                switch (t) {

                case 1:
                    Toast toast = Toast.makeText(mainActivity, R.string.RegisterStatus1, Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast.show();

                    dialog.setTitle(R.string.LoginDialogTitle);
                    final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
                    layreg.setVisibility(View.GONE);
                    final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
                    laylog.setVisibility(View.VISIBLE);

                    nametxt.setText(mailtxt.getText());
                    break;

                case -2:
                    Toast toast1 = Toast.makeText(mainActivity, R.string.RegisterStatus3, Toast.LENGTH_LONG);
                    toast1.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast1.show();
                    break;

                default:
                    Toast toast2 = Toast.makeText(mainActivity, R.string.RegisterStatus2, Toast.LENGTH_LONG);
                    toast2.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast2.show();
                    break;

                }

            } catch (Exception e) {

                e.printStackTrace();
                Log.e(TAG, "Error in registration process!!", e);

                Toast toast = Toast.makeText(mainActivity, R.string.ConnectError, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

            }

        }

    });

    Button customDialog_CancelReg = (Button) dialog.findViewById(R.id.cancelreg);
    customDialog_CancelReg.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.setTitle(R.string.LoginDialogTitle);
            final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
            layreg.setVisibility(View.GONE);
            final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
            laylog.setVisibility(View.VISIBLE);

        }

    });

    Button customDialog_Dismiss = (Button) dialog.findViewById(R.id.gologin);
    customDialog_Dismiss.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.lradio0);
            Common.isSSL = bu0.isChecked();

            inLogin = false;

            JSONObject msg = new JSONObject();
            try {

                msg.put("objType", Common.LOGOUT);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("status", 1);
                mainActivity.writeJSONMsg(msg);
            } catch (Exception e) {
                e.printStackTrace();
                Log.e(TAG, "Error! Cannot create JSON logout object", e);
            }

            myaccount.put("name", nametxt.getText().toString());
            myaccount.put("password", passtxt.getText().toString());

            Log.i(TAG,
                    "myaccount username: " + myaccount.get("name") + " password: " + myaccount.get("password"));

            dialog.dismiss();
            mainActivity.stop();
            // saveAccountDetails();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            loginFromDialog = true;
            //            mainActivity.refresh();

            Common.keypassword(ctx);
        }

    });

    dialog.show();
    // Common.confChanged = false;
    // }//while(true);

}

From source file:lewa.support.v7.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 www  . j a  v a  2s .  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();
    ///LEWA MODIFY BEGIN
    final int height = Injector.getHeight(this);
    final int midy = Injector.measureMidy(this, screenPos[1], height);
    //final int height = getHeight();
    //final int midy = screenPos[1] + height / 2;
    ///LEWA MODIFY END
    int referenceX = screenPos[0] + width / 2;
    if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) {
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        referenceX = screenWidth - referenceX; // mirror
    }
    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 | GravityCompat.END, referenceX, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    return true;
}

From source file:fm.smart.r1.ItemActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ExceptionHandler.register(this);

    // could check here to see if this was suspended for login and go
    // straight to add_item ...

    setContentView(R.layout.item);/*from w  w  w. ja v a 2 s  .  c o m*/

    TextView cue_and_pronunciation = (TextView) findViewById(R.id.cue_and_pronunciation);
    cue_and_pronunciation.setText(item.cue_text); // TODO handle case where
    // item is null?
    TextView cue_part_of_speech = (TextView) findViewById(R.id.cue_part_of_speech);
    if (!TextUtils.equals(item.part_of_speech, "None")) {
        cue_part_of_speech.setText(item.part_of_speech);
    } else {
        cue_part_of_speech.setVisibility(View.INVISIBLE);
    }

    TextView response_and_pronunciation = (TextView) findViewById(R.id.response_and_pronunciation);
    response_and_pronunciation.setText(item.children[0][0]);
    TextView response_part_of_speech = (TextView) findViewById(R.id.response_part_of_speech);
    if (item.type != null && item.type.equals("meaning")) {
        item.type = "Translation";
    }
    response_part_of_speech.setText(item.type);
    response_part_of_speech.setVisibility(View.INVISIBLE);

    ImageView cue_sound = (ImageView) findViewById(R.id.cue_sound);
    try {
        setSound(cue_sound, item.cue_sound_url, this, R.id.cue_sound, (String) item.item_node.getString("id"),
                item.cue_text);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    ImageView response_sound = (ImageView) findViewById(R.id.response_sound);
    try {
        setSound(response_sound, item.response_sound_url, this, R.id.response_sound,
                (String) item.item_node.getString("id"),
                item.response_node.getJSONObject("content").getString("text"));
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    EfficientAdapter adapter = new EfficientAdapter(ItemActivity.this, item.sentence_vector);
    cache = new Cache(adapter);
    setListAdapter(adapter);
    if (adapter.getCount() == 0 && !ItemActivity.shown_toast) {
        Toast t = Toast.makeText(this, "Know a good example? Click the menu button to add one", 250);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
        ItemActivity.shown_toast = true;
    }
    // notify();
}

From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java

public void toastsettext(String string1) {
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_activity,
            (ViewGroup) ((Activity) context).findViewById(R.id.toast_rl));
    TextView txt = (TextView) layout.findViewById(R.id.toast_txt);
    txt.setText(string1);//from ww  w  .  j av  a 2  s .c o  m
    Toast tst = new Toast(context);
    tst.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    tst.setDuration(Toast.LENGTH_SHORT);
    tst.setView(layout);
    tst.show();
}

From source file:com.grass.caishi.cc.activity.AdAddActivity.java

/**
 * ?uri??//from  ww  w . ja v  a  2 s.  c o m
 * 
 * @param selectedImage
 */
private String getPicByUri(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, "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return null;
        }
        return picturePath;
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return null;

        }
        return file.getAbsolutePath();
    }
}

From source file:com.npi.muzeiflickr.ui.activities.SettingsActivity.java

private void populateFooter(View footerView) {
    final View footerButton = footerView.findViewById(R.id.list_footer_button);
    final Spinner footerModeChooser = (Spinner) footerView.findViewById(R.id.mode_chooser);
    final RelativeLayout addItemContainer = (RelativeLayout) footerView.findViewById(R.id.new_item_container);
    final ImageButton footerSearchButton = (ImageButton) footerView.findViewById(R.id.footer_search_button);
    final ProgressBar footerProgress = (ProgressBar) footerView.findViewById(R.id.footer_progress);
    final EditText footerTerm = (EditText) footerView.findViewById(R.id.footer_term);

    footerButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override//from www  .  j  a  v  a  2s  . c  om
        public boolean onLongClick(View v) {
            int[] pos = new int[2];
            footerButton.getLocationInWindow(pos);

            String contentDesc = footerButton.getContentDescription().toString();
            Toast t = Toast.makeText(SettingsActivity.this, contentDesc, Toast.LENGTH_SHORT);
            t.show();
            t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, pos[1] + (footerButton.getHeight() / 2));

            return true;
        }
    });

    footerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addItemContainer.animate().alpha(1F);
            footerButton.animate().alpha(0F);
        }
    });

    //Mode spinner management
    ArrayAdapter<CharSequence> adapter = new SourceSpinnerAdapter(this, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.modes));

    footerModeChooser.setAdapter(adapter);

    footerSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String searchString = footerTerm.getText().toString();
            switch (footerModeChooser.getSelectedItemPosition()) {
            case 0:

                //It's a search

                //Looking for a same existing search
                List<Search> searchs = Search.listAll(Search.class);
                for (Search search : searchs) {
                    if (search.getTitle().equals(searchString)) {
                        Toast.makeText(SettingsActivity.this, getString(R.string.search_exists),
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                footerSearchButton.setVisibility(View.GONE);
                footerProgress.setVisibility(View.VISIBLE);

                getSearch(searchString, new UserInfoListener<Search>() {
                    @Override
                    public void onSuccess(Search search) {
                        mRequestAdapter.add(search);
                        mRequestAdapter.notifyDataSetChanged();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                        footerTerm.setText("");
                        footerModeChooser.setSelection(0);
                        addItemContainer.animate().alpha(0F);
                        footerButton.animate().alpha(1F);
                    }

                    @Override
                    public void onError(String reason) {
                        Toast.makeText(SettingsActivity.this, reason, Toast.LENGTH_LONG).show();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                    }
                });

                break;
            case 1:
                //It's an user

                //Looking for a same existing search
                List<User> users = User.listAll(User.class);
                for (User user : users) {
                    if (user.getTitle().equals(searchString)) {
                        Toast.makeText(SettingsActivity.this, getString(R.string.user_exists),
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                footerSearchButton.setVisibility(View.GONE);
                footerProgress.setVisibility(View.VISIBLE);

                getUserId(searchString, new UserInfoListener<User>() {
                    @Override
                    public void onSuccess(User user) {
                        mRequestAdapter.add(user);
                        mRequestAdapter.notifyDataSetChanged();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                        footerTerm.setText("");
                        footerModeChooser.setSelection(0);
                        addItemContainer.animate().alpha(0F);
                        footerButton.animate().alpha(1F);
                    }

                    @Override
                    public void onError(String reason) {
                        Toast.makeText(SettingsActivity.this, reason, Toast.LENGTH_LONG).show();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                    }
                });
                break;
            case 2:
                //It's a tag

                //Looking for a same existing search
                List<Tag> tags = Tag.listAll(Tag.class);
                for (Tag tag : tags) {
                    if (tag.getTitle().equals(searchString)) {
                        Toast.makeText(SettingsActivity.this, getString(R.string.user_exists),
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                footerSearchButton.setVisibility(View.GONE);
                footerProgress.setVisibility(View.VISIBLE);

                getTag(searchString, new UserInfoListener<Tag>() {
                    @Override
                    public void onSuccess(Tag tag) {
                        mRequestAdapter.add(tag);
                        mRequestAdapter.notifyDataSetChanged();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                        footerTerm.setText("");
                        footerModeChooser.setSelection(0);
                        addItemContainer.animate().alpha(0F);
                        footerButton.animate().alpha(1F);
                    }

                    @Override
                    public void onError(String reason) {
                        Toast.makeText(SettingsActivity.this, reason, Toast.LENGTH_LONG).show();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                    }
                });
                break;

            case 3:
                //It's an user

                //Looking for a same existing search
                List<FGroup> groups = FGroup.listAll(FGroup.class);
                for (FGroup group : groups) {
                    if (group.getTitle().equals(searchString)) {
                        Toast.makeText(SettingsActivity.this, getString(R.string.group_exists),
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                footerSearchButton.setVisibility(View.GONE);
                footerProgress.setVisibility(View.VISIBLE);

                getGroupId(searchString, new UserInfoListener<FGroup>() {
                    @Override
                    public void onSuccess(FGroup group) {
                        mRequestAdapter.add(group);
                        mRequestAdapter.notifyDataSetChanged();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                        footerTerm.setText("");
                        footerModeChooser.setSelection(0);
                        addItemContainer.animate().alpha(0F);
                        footerButton.animate().alpha(1F);
                    }

                    @Override
                    public void onError(String reason) {
                        Toast.makeText(SettingsActivity.this, reason, Toast.LENGTH_LONG).show();
                        footerSearchButton.setVisibility(View.VISIBLE);
                        footerProgress.setVisibility(View.GONE);
                    }
                });
                break;
            }
        }
    });
}