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:com.nbplus.vbroadlauncher.fragment.LauncherFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_launcher, container, false);

    mMainViewLayout = (LinearLayout) v.findViewById(R.id.main_view_layout);

    // push agent ??.
    mPushServiceStatus = (ImageView) v.findViewById(R.id.ic_nav_wifi);
    if (((BaseActivity) getActivity()).isPushServiceConnected()) {
        mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_on);
    } else {//from ww w . ja v  a2s .c  om
        mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_off);
    }

    mVillageName = (TextView) v.findViewById(R.id.launcher_village_name);
    mVillageName.setText(LauncherSettings.getInstance(getActivity()).getVillageName());

    mApplicationsView = (LinearLayout) v.findViewById(R.id.ic_nav_apps);
    mApplicationsView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(), ShowApplicationActivity.class);
            startActivity(intent);
            getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
        }
    });
    mServiceTreeMap = (LinearLayout) v.findViewById(R.id.ic_nav_show_map);
    mServiceTreeMap.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!NetworkUtils.isConnected(getActivity())) {
                ((BaseActivity) getActivity()).showNetworkConnectionAlertDialog();
                return;
            }
            Intent intent = new Intent(getActivity(), BroadcastWebViewActivity.class);

            ShortcutData data = new ShortcutData(Constants.SHORTCUT_TYPE_WEB_DOCUMENT_SERVER,
                    R.string.btn_show_map, getActivity().getResources().getString(R.string.addr_show_map),
                    R.drawable.ic_menu_04, R.drawable.ic_menu_shortcut_02_selector, 0, null);

            VBroadcastServer serverInfo = LauncherSettings.getInstance(getActivity()).getServerInformation();
            data.setDomain(serverInfo.getDocServer());

            intent.putExtra(Constants.EXTRA_NAME_SHORTCUT_DATA, data);
            startActivity(intent);
        }
    });
    mOutdoorMode = (LinearLayout) v.findViewById(R.id.ic_nav_outdoor);
    mOutdoorText = (TextView) v.findViewById(R.id.tv_outdoor);
    if (LauncherSettings.getInstance(getActivity()).isOutdoorMode()) {
        mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_on));
        mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_on, 0, 0, 0);
    } else {
        mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_off));
        mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_off, 0, 0, 0);
    }
    mOutdoorMode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast toast;

            boolean mode = false;
            if (LauncherSettings.getInstance(getActivity()).isOutdoorMode()) {
                LauncherSettings.getInstance(getActivity()).setIsOutdoorMode(false);
                mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_off, 0, 0, 0);
                mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_off));

                toast = Toast.makeText(getActivity(), R.string.outdoor_mode_off, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                toast.show();
            } else {
                mode = true;
                LauncherSettings.getInstance(getActivity()).setIsOutdoorMode(true);
                mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_on));
                mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_on, 0, 0, 0);

                toast = Toast.makeText(getActivity(), R.string.outdoor_mode_on, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                toast.show();
            }

            HomeLauncherApplication application = (HomeLauncherApplication) getActivity()
                    .getApplicationContext();
            if (application != null) {
                application.outdoorModeChanged(mode);
            }
        }
    });
    // ?? ?
    mIoTDataSync = (LinearLayout) v.findViewById(R.id.ic_iot_data_sync);
    mIoTDataSyncText = (TextView) v.findViewById(R.id.tv_iot_data_sync);
    mIoTDataSync.setOnClickListener(mIoTSyncClickListener);
    mIoTDataSync.setClickable(true);
    mIoTDataSync.setEnabled(true);

    mTextClock = (TextClock) v.findViewById(R.id.text_clock);
    if (mTextClock != null) {
        mTextClock.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_APP_CALENDAR);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
                } catch (ActivityNotFoundException e) {
                    e.printStackTrace();
                    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
                    alert.setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent i = new Intent(
                                    android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
                            i.addCategory(Intent.CATEGORY_DEFAULT);
                            startActivity(i);
                        }
                    });
                    alert.setMessage(R.string.alert_calendar_not_found);
                    alert.show();
                }
            }
        });
    }
    mWeatherView = (WeatherView) v.findViewById(R.id.weather_view);
    mMainViewLeftPanel = (LinearLayout) v.findViewById(R.id.main_view_left_panel);
    mMainViewRightPanel = (LinearLayout) v.findViewById(R.id.main_view_right_panel);

    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // add main shortcut.
    ArrayList<ShortcutData> mainShortcutDatas = LauncherSettings.getInstance(getActivity())
            .getLauncherMainShortcuts();
    mMainShortcutGridLayout = (GridLayout) v.findViewById(R.id.main_shortcut_grid);
    float dp;// = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_width);
    //        float widthPx = DisplayUtils.pxFromDp(getActivity(), dp);
    //
    //        dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_height);
    //        float heightPx = DisplayUtils.pxFromDp(getActivity(), dp);

    dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_font_size);
    float mainShortcutFontPx = DisplayUtils.pxFromDp(getActivity(), dp);
    for (int i = 0; i < mMainShortcutGridLayout.getColumnCount(); i++) {
        /**
         * right shortcut panel
         */
        ShortcutData data = mainShortcutDatas.get(i);
        FrameLayout btnLayout = (FrameLayout) layoutInflater.inflate(R.layout.launcher_menu_top_item,
                mMainShortcutGridLayout, false);//new Button(getActivity());
        mMainShortcutGridLayout.addView(btnLayout);
        if (data.getPushType() != null && data.getPushType().length > 0) {
            data.setLauncherButton(btnLayout);
            mPushNotifiableShorcuts.add(data);
        }

        btnLayout.setBackgroundResource(data.getIconBackResId());

        //            GridLayout.LayoutParams lp = (GridLayout.LayoutParams)btnLayout.getLayoutParams();
        //            lp.width = (int)widthPx;
        //            lp.height = (int)heightPx;
        //            btnLayout.setLayoutParams(lp);

        TextView label = (TextView) btnLayout.findViewById(R.id.menu_item_label);
        label.setText(data.getName());
        label.setTextSize(TypedValue.COMPLEX_UNIT_PX, mainShortcutFontPx);
        label.setTextColor(getResources().getColor(R.color.white));
        label.setTypeface(null, Typeface.BOLD);
        label.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

        ImageView icon = (ImageView) btnLayout.findViewById(R.id.menu_item_image);
        icon.setImageResource(data.getIconResId());

        btnLayout.setTag(data);
        btnLayout.setOnClickListener(this);
    }

    // add other shortcuts.
    mShorcutGridLayout = (GridLayout) v.findViewById(R.id.shortcut_grid);
    ArrayList<ShortcutData> shortcutDatas = LauncherSettings.getInstance(getActivity()).getLauncherShortcuts();
    int columnNum = mShorcutGridLayout.getColumnCount();
    final int MAX_ROW_NUM = 3;

    int shortcutNum = shortcutDatas.size() > (columnNum * MAX_ROW_NUM) ? (columnNum * MAX_ROW_NUM)
            : shortcutDatas.size();
    dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_shortcut_font_size);
    float btnFontPx = DisplayUtils.pxFromDp(getActivity(), dp);

    for (int i = 0; i < shortcutNum; i++) {
        /**
         * right shortcut panel
         */
        ShortcutData data = shortcutDatas.get(i);
        FrameLayout btnLayout = (FrameLayout) layoutInflater.inflate(R.layout.launcher_menu_item,
                mShorcutGridLayout, false);//new Button(getActivity());
        mShorcutGridLayout.addView(btnLayout);
        if (data.getPushType() != null && data.getPushType().length > 0) {
            data.setLauncherButton(btnLayout);
            mPushNotifiableShorcuts.add(data);
        }

        btnLayout.setBackgroundResource(data.getIconBackResId());

        TextView label = (TextView) btnLayout.findViewById(R.id.menu_item_label);
        label.setText(data.getName());
        label.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnFontPx);
        label.setTextColor(getResources().getColor(R.color.white));
        label.setTypeface(null, Typeface.BOLD);
        label.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

        ImageView icon = (ImageView) btnLayout.findViewById(R.id.menu_item_image);
        icon.setImageResource(data.getIconResId());

        btnLayout.setTag(data);
        btnLayout.setOnClickListener(this);
    }

    setContentViewByOrientation();

    return v;
}

From source file:cn.ucai.yizhesale.activity.ChatActivity.java

/**
 * ?uri??/*from   ww w. ja  v  a  2s . c o  m*/
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    String st8 = getResources().getString(cn.ucai.yizhesale.R.string.cant_find_pictures);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, st8, 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, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        sendPicture(file.getAbsolutePath());
    }

}

From source file:com.devwang.logcabin.LogCabinMainActivity.java

private void toastDisplay(Context context, CharSequence text, int gravity, int ResImgId, int duration) {
    Toast toast = Toast.makeText(context, text, duration);
    if (gravity != 0) {
        switch (gravity) {
        case Gravity.CENTER:
            toast.setGravity(Gravity.CENTER, 0, 0);//  x,y0
            break;
        case Gravity.FILL:
            toast.setGravity(Gravity.FILL, 0, 0);//  x,y0
            break;
        case Gravity.BOTTOM:
            toast.setGravity(Gravity.BOTTOM, 0, 0);
            break;
        default://w  w  w  . j  a v  a2  s .  co m
            break;
        }
    }
    if (ResImgId != 0) {
        LinearLayout toastView = (LinearLayout) toast.getView();
        ImageView imageCodeProject = new ImageView(getApplicationContext());
        imageCodeProject.setImageResource(ResImgId);
        toastView.addView(imageCodeProject, 0);
    }

    toast.show();
}

From source file:com.wemolian.app.wml.ChatActivity.java

/**
 * ?uri??/*  w w  w  .j ava  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, "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        sendPicture(picturePath, false);
    } 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;

        }
        sendPicture(file.getAbsolutePath(), false);
    }

}

From source file:cmu.cconfs.instantMessage.activities.ChatActivity.java

/**
 * ?uri??/* ww  w.  j  a v a2 s  . c om*/
 *
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    String st8 = getResources().getString(R.string.cant_find_pictures);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, st8, 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, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        sendPicture(file.getAbsolutePath());
    }

}

From source file:cn.gen.superwechat.activity.ChatActivity.java

/**
 * ?uri??/* www.j av a2s . c  o  m*/
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    String st8 = getResources().getString(cn.gen.superwechat.R.string.cant_find_pictures);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, st8, 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, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        sendPicture(file.getAbsolutePath());
    }

}

From source file:com.crearo.gpslogger.ui.fragments.display.GpsSimpleViewFragment.java

@Override
public void onClick(View view) {
    Toast toast = new Toast(getActivity());
    switch (view.getId()) {
    case R.id.simpleview_imgSatelliteCount:
        toast = getToast(R.string.txt_satellites);
        break;//  w  w  w.j  a  va2  s .  c  o m
    case R.id.simpleview_imgAccuracy:
        toast = getToast(R.string.txt_accuracy);
        break;

    case R.id.simpleview_imgAltitude:
        toast = getToast(R.string.txt_altitude);
        break;

    case R.id.simpleview_imgDirection:
        toast = getToast(R.string.txt_direction);
        break;

    case R.id.simpleview_imgDuration:
        toast = getToast(R.string.txt_travel_duration);
        break;

    case R.id.simpleview_imgSpeed:
        toast = getToast(R.string.txt_speed);
        break;

    case R.id.simpleview_distance:
        toast = getToast(R.string.txt_travel_distance);
        break;

    case R.id.simpleview_points:
        toast = getToast(R.string.txt_number_of_points);
        break;

    case R.id.simpleview_imgLink:
        toast = getToast(preferenceHelper.getCustomLoggingUrl());
        break;

    }

    int location[] = new int[2];
    view.getLocationOnScreen(location);
    toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0], location[1]);
    toast.show();
}

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

/**
 * ?uri??// w ww  .ja  va2  s .c  om
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {

    //
    //
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    // Cursor cursor = getContentResolver().query(filePath,filePathColumn,
    // null, null, null);
    // cursor.moveToFirst();
    // int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    // String picturePath = cursor.getString(columnIndex);
    // cursor.close();
    // return picturePath;
    //
    //

    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    if (cursor != null) {

        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        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;
        }
        sendPicture(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;

        }
        sendPicture(file.getAbsolutePath());
    }
}

From source file:io.puzzlebox.bloom.ui.BloomFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    View v = inflater.inflate(R.layout.fragment_bloom, container, false);

    //      requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    //      setContentView(R.layout.main);
    //      getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);

    progressBarAttention = (ProgressBar) v.findViewById(R.id.progressBarAttention);
    final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
    ShapeDrawable progressBarAttentionDrawable = new ShapeDrawable(
            new RoundRectShape(roundedCorners, null, null));
    String progressBarAttentionColor = "#FF0000";
    progressBarAttentionDrawable.getPaint().setColor(Color.parseColor(progressBarAttentionColor));
    ClipDrawable progressAttention = new ClipDrawable(progressBarAttentionDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);/* w ww  .  ja  va  2s.  c o  m*/
    progressBarAttention.setProgressDrawable(progressAttention);
    progressBarAttention
            .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    progressBarMeditation = (ProgressBar) v.findViewById(R.id.progressBarMeditation);
    ShapeDrawable progressBarMeditationDrawable = new ShapeDrawable(
            new RoundRectShape(roundedCorners, null, null));
    String progressBarMeditationColor = "#0000FF";
    progressBarMeditationDrawable.getPaint().setColor(Color.parseColor(progressBarMeditationColor));
    ClipDrawable progressMeditation = new ClipDrawable(progressBarMeditationDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarMeditation.setProgressDrawable(progressMeditation);
    progressBarMeditation
            .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    progressBarSignal = (ProgressBar) v.findViewById(R.id.progressBarSignal);
    ShapeDrawable progressBarSignalDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));
    String progressBarSignalColor = "#00FF00";
    progressBarSignalDrawable.getPaint().setColor(Color.parseColor(progressBarSignalColor));
    ClipDrawable progressSignal = new ClipDrawable(progressBarSignalDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarSignal.setProgressDrawable(progressSignal);
    progressBarSignal.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));
    //      progressBarSignal.setProgress(tgSignal);

    progressBarPower = (ProgressBar) v.findViewById(R.id.progressBarPower);
    ShapeDrawable progressBarPowerDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));
    String progressBarPowerColor = "#FFFF00";
    progressBarPowerDrawable.getPaint().setColor(Color.parseColor(progressBarPowerColor));
    ClipDrawable progressPower = new ClipDrawable(progressBarPowerDrawable, Gravity.LEFT,
            ClipDrawable.HORIZONTAL);
    progressBarPower.setProgressDrawable(progressPower);
    progressBarPower.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    //      progressBarRange = (ProgressBar) v.findViewById(R.id.progressBarRange);
    ////      ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
    //      ShapeDrawable progressBarRangeDrawable = new ShapeDrawable();
    ////      String progressBarRangeColor = "#FF00FF";
    //      String progressBarRangeColor = "#990099";
    //      progressBarRangeDrawable.getPaint().setColor(Color.parseColor(progressBarRangeColor));
    //      ClipDrawable progressRange = new ClipDrawable(progressBarRangeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    //      progressBarRange.setProgressDrawable(progressRange);
    //      progressBarRange.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));
    //
    ////      progressBarRange.setMax(128 + 127);
    //      progressBarRange.setMax(bloomRangeMax);

    //      progressBarBloom = (ProgressBar) v.findViewById(R.id.progressBarBloom);
    //      ShapeDrawable progressBarBloomDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
    //      String progressBarBloomColor = "#7F0000";
    //      progressBarBloomDrawable.getPaint().setColor(Color.parseColor(progressBarBloomColor));
    //      ClipDrawable progressBloom = new ClipDrawable(progressBarBloomDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    //      progressBarBloom.setProgressDrawable(progressBloom);
    //      progressBarBloom.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

    seekBarAttention = (SeekBar) v.findViewById(R.id.seekBarAttention);
    seekBarAttention.setOnSeekBarChangeListener(this);
    seekBarMeditation = (SeekBar) v.findViewById(R.id.seekBarMeditation);
    seekBarMeditation.setOnSeekBarChangeListener(this);

    //      imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus);

    servoSeekBar = (SeekBar) v.findViewById(R.id.ServoSeekBar);
    servoSeekBar.setEnabled(false);
    //      servoSeekBar.setMax(180);
    servoSeekBar.setMax(100);
    servoSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 };

            buf[1] = (byte) servoSeekBar.getProgress();

            BloomSingleton.getInstance().characteristicTx.setValue(buf);
            BloomSingleton.getInstance().mBluetoothLeService
                    .writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
        }
    });

    //      rssiValue = (TextView) v.findViewById(R.id.rssiValue);

    connectBloom = (Button) v.findViewById(R.id.connectBloom);

    connectBloom.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                if (!BloomSingleton.getInstance().scanFlag) {
                    scanLeDevice();

                    Timer mTimer = new Timer();
                    mTimer.schedule(new TimerTask() {

                        @Override
                        public void run() {
                            if ((BloomSingleton.getInstance().mDevice != null)
                                    && (BloomSingleton.getInstance().mDevice.getAddress() != null)
                                    && (BloomSingleton.getInstance().mBluetoothLeService != null)) {
                                BloomSingleton
                                        .getInstance().mDeviceAddress = BloomSingleton.getInstance().mDevice
                                                .getAddress();
                                if (BloomSingleton.getInstance().mDeviceAddress != null)
                                    BloomSingleton.getInstance().mBluetoothLeService
                                            .connect(BloomSingleton.getInstance().mDeviceAddress);
                                else {
                                    Toast toast = Toast.makeText(getActivity(),
                                            "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT);
                                    toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM);
                                    toast.show();
                                }
                                BloomSingleton.getInstance().scanFlag = true;
                            } else {
                                getActivity().runOnUiThread(new Runnable() {
                                    public void run() {
                                        Toast toast = Toast.makeText(getActivity(),
                                                "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT);
                                        toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM);
                                        toast.show();
                                    }
                                });
                            }
                        }
                    }, BloomSingleton.getInstance().SCAN_PERIOD);
                }
            } catch (Exception e) {
                Log.e(TAG, "Exception connecting to Bloom: " + e);
                Toast toast = Toast.makeText(getActivity(), "Exception connecting to Puzzlebox Bloom",
                        Toast.LENGTH_SHORT);
                toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM);
                toast.show();
            }

            System.out.println(BloomSingleton.getInstance().connState);
            //            Log.e(TAG, connState);
            //            if (connState == false) {
            if (!BloomSingleton.getInstance().connState
                    && BloomSingleton.getInstance().mDeviceAddress != null) {
                BloomSingleton.getInstance().mBluetoothLeService
                        .connect(BloomSingleton.getInstance().mDeviceAddress);
            } else {
                if (BloomSingleton.getInstance().mBluetoothLeService != null) {
                    setBloomRGBOff();
                    BloomSingleton.getInstance().mBluetoothLeService.disconnect();
                    BloomSingleton.getInstance().mBluetoothLeService.close();
                    setButtonDisable();
                }
            }
        }
    });

    //      Button buttonOpen = (Button) v.findViewById(R.id.buttonOpen);
    //      buttonOpen.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //            byte[] buf = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 };
    //            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //         }
    //      });
    //      buttonOpen.setVisibility(View.GONE);
    //
    //      Button buttonClose = (Button) v.findViewById(R.id.buttonClose);
    //      buttonClose.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //            byte[] buf = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00 };
    //            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //         }
    //      });
    //      buttonClose.setVisibility(View.GONE);

    //      buttonDemo = (Button) v.findViewById(R.id.buttonDemo);
    //      buttonDemo.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //            byte[] buf;
    ////            if (! BloomSingleton.getInstance().demoActive) {
    //            BloomSingleton.getInstance().demoActive = true;
    //
    //            // bloomOpen()
    ////            buf = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x00};
    ////            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    ////            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //
    //            // loopRGB()
    //            buf = new byte[]{(byte) 0x06, (byte) 0x00, (byte) 0x00};
    //            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //
    //            // Set Red to 0
    //            buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0
    //            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //
    //            // bloomClose()
    ////            buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00};
    ////            BloomSingleton.getInstance().characteristicTx.setValue(buf);
    ////            BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //
    //
    ////            } else {
    ////               BloomSingleton.getInstance().demoActive = false;
    //////               buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00};
    //////               BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //////               BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    ////               buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0
    ////               BloomSingleton.getInstance().characteristicTx.setValue(buf);
    ////               BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //////               buf = new byte[]{(byte) 0x0A, (byte) 0x01, (byte) 0x00}; // G = 0
    //////               BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //////               BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    //////               buf = new byte[]{(byte) 0x0A, (byte) 0x02, (byte) 0x00}; // B = 0
    //////               BloomSingleton.getInstance().characteristicTx.setValue(buf);
    //////               BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx);
    ////            }
    //         }
    //      });

    if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show();
        getActivity().finish();
    }

    final BluetoothManager mBluetoothManager = (BluetoothManager) getActivity()
            .getSystemService(Context.BLUETOOTH_SERVICE);
    BloomSingleton.getInstance().mBluetoothAdapter = mBluetoothManager.getAdapter();
    if (BloomSingleton.getInstance().mBluetoothAdapter == null) {
        Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show();
        getActivity().finish();
        return v;
    }

    Intent gattServiceIntent = new Intent(getActivity(), RBLService.class);
    //      bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
    getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE);

    /**
     * Update settings according to default UI
     */

    updateScreenLayout();

    //      updatePowerThresholds();
    //      updatePower();

    if (BloomSingleton.getInstance().connState)
        setButtonEnable();

    return v;

}

From source file:org.csp.everyaware.offline.Map.java

/****************** OTTIENE RIFERIMENTO AI BOTTONI *********************************/

public void getButtonRefs() {
    mZoomControls = (LinearLayout) findViewById(R.id.zoomLinearLayout);
    mZoomControls.setVisibility(View.GONE);

    mTrackLengthBtn = (Button) findViewById(R.id.trackLengthBtn);
    mFollowCamBtn = (Button) findViewById(R.id.followCameraBtn);
    mZoomOutBtn = (Button) findViewById(R.id.zoomOutBtn);
    mZoomInBtn = (Button) findViewById(R.id.zoomInBtn);
    mInsertAnnBtn = (Button) findViewById(R.id.insertAnnBtn);
    mShareBtn = (Button) findViewById(R.id.shareBtn);

    mTrackLengthBtn.setVisibility(View.GONE);
    mInsertAnnBtn.setVisibility(View.GONE);

    mZoomOutBtn.setOnClickListener(new OnClickListener() {
        @Override/*w w w  . j a va  2  s.  c o m*/
        public void onClick(View arg0) {
            // Zoom out
            try {
                mGoogleMap.moveCamera(CameraUpdateFactory.zoomBy(-1f));
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            //read and save actual zoom level
            mZoom = mGoogleMap.getCameraPosition().zoom;
        }
    });

    mZoomInBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // Zoom in
            try {
                mGoogleMap.moveCamera(CameraUpdateFactory.zoomBy(1f));
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            //read and save actual zoom level
            mZoom = mGoogleMap.getCameraPosition().zoom;
        }
    });

    mShareBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            mFacebookManager = FacebookManager.getInstance(Map.this, mFacebookHandler);
            mTwitterManager = TwitterManager.getInstance(Map.this);

            final Dialog dialog = new Dialog(Map.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.share_dialog);
            //dialog.setTitle("Activate login on...");

            getShareButtonsRef(dialog);

            dialog.show();
        }
    });

    mFollowCamBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            //mCameraTrackOn = !mCameraTrackOn;
            setCameraTracking();

            if (mCameraTrackOn) {
                try {
                    if (Utils.lastPhoneLocation != null)
                        mGoogleMap.animateCamera(
                                CameraUpdateFactory.newLatLng(new LatLng(Utils.lastPhoneLocation.getLatitude(),
                                        Utils.lastPhoneLocation.getLongitude())));
                    else if (Utils.lastNetworkLocation != null)
                        mGoogleMap.animateCamera(CameraUpdateFactory
                                .newLatLng(new LatLng(Utils.lastNetworkLocation.getLatitude(),
                                        Utils.lastNetworkLocation.getLongitude())));
                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    mShareBtn.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            Toast toast = Toast.makeText(getApplicationContext(),
                    getResources().getString(R.string.share_btn_text), Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, 250); //250 from top on a 480x800 screen
            toast.show();
            return false;
        }
    });

    //status icons references
    mGpsStatus = (ImageView) findViewById(R.id.gpsStatusIv);
    mInterUplStatus = (ImageView) findViewById(R.id.interUplStatusIv);

    //gps status icon initialization
    mGpsStatus.setBackgroundResource(R.drawable.gps_off);

    //read network type index on which upload data is allowed: 0 - only wifi; 1 - both wifi and mobile
    int networkTypeIndex = Utils.getUploadNetworkTypeIndex(getApplicationContext());

    //1 - is internet connection available? 
    boolean[] connectivity = Utils.haveNetworkConnection(getApplicationContext());

    //if user wants to upload only on wifi networks, connectivity[0] (network connectivity) must be true
    if (networkTypeIndex == 0) {
        if (connectivity[0])
            mConnectivityOn = true;
        else
            mConnectivityOn = false;
    } else //if user wants to upload both on wifi/mobile networks
        mConnectivityOn = connectivity[0] || connectivity[1];

    //network status icon initialization
    if (mConnectivityOn) {
        mInterUplStatus.setBackgroundResource(R.drawable.internet_on);
        Utils.uploadOn = Constants.INTERNET_ON_INT;
    } else {
        mInterUplStatus.setBackgroundResource(R.drawable.internet_off);
        Utils.uploadOn = Constants.INTERNET_OFF_INT;
    }

    //button to get from server black carbon levels around user
    mGetBcLevelsBtn = (Button) findViewById(R.id.getBcLevelsBtn);
    mGetBcLevelsBtn.setVisibility(View.VISIBLE);
    mGetBcLevelsBtn.setOnClickListener(mGetBcLevelsOnClickListener);

    //bcLayout.addView(mGetBcLevelsBtn);
    mSpectrum = (LinearLayout) findViewById(R.id.spectrumLinearLayout);
    mSpectrum.setVisibility(View.VISIBLE);
}