Example usage for android.view Gravity CENTER

List of usage examples for android.view Gravity CENTER

Introduction

In this page you can find the example usage for android.view Gravity CENTER.

Prototype

int CENTER

To view the source code for android.view Gravity CENTER.

Click Source Link

Document

Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.

Usage

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

/**
 * ?uri??//  w ww . j  av  a  2 s  .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:cn.gen.superwechat.activity.ChatActivity.java

/**
 * ?uri??//  w  ww. j av a  2  s. com
 * 
 * @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.ccxt.whl.activity.SettingsFragment.java

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

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

        }
        return file.getAbsolutePath();
    }

}

From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java

private void setAudio(final GalleryItemViewTag tag, final File file) {
    runOnUiThread(new Runnable() {
        @Override/*from   w w  w .j a v  a  2  s. co  m*/
        public void run() {
            setOnClickView(tag, getString(R.string.gallery_tap_to_play), new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!settings.useInternalAudioPlayer()) {
                        openExternal();
                    } else {
                        recycleTag(tag, false);
                        final TextView durationView = new TextView(GalleryActivity.this);
                        durationView.setGravity(Gravity.CENTER);
                        tag.layout.setVisibility(View.VISIBLE);
                        tag.layout.addView(durationView);
                        tag.audioPlayer = new MediaPlayer();
                        tag.audioPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                            @Override
                            public void onPrepared(final MediaPlayer mp) {
                                mp.setLooping(true);

                                durationView.setText(
                                        getSpannedText("00:00 / " + formatMediaPlayerTime(mp.getDuration())));

                                tag.timer = new Timer();
                                tag.timer.schedule(new TimerTask() {
                                    @Override
                                    public void run() {
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                try {
                                                    durationView.setText(getSpannedText(
                                                            formatMediaPlayerTime(mp.getCurrentPosition())
                                                                    + " / "
                                                                    + formatMediaPlayerTime(mp.getDuration())));
                                                } catch (Exception e) {
                                                    Logger.e(TAG, e);
                                                    tag.timer.cancel();
                                                }
                                            }
                                        });
                                    }
                                }, 1000, 1000);

                                mp.start();
                            }
                        });
                        tag.audioPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                            @Override
                            public boolean onError(MediaPlayer mp, int what, int extra) {
                                Logger.e(TAG, "(Audio) Error code: " + what);
                                if (tag.timer != null)
                                    tag.timer.cancel();
                                showError(tag, getString(R.string.gallery_error_play));
                                return true;
                            }
                        });
                        try {
                            tag.audioPlayer.setDataSource(file.getAbsolutePath());
                            tag.audioPlayer.prepareAsync();
                        } catch (Exception e) {
                            Logger.e(TAG, "audio player error", e);
                            if (tag.timer != null)
                                tag.timer.cancel();
                            showError(tag, getString(R.string.gallery_error_play));
                        }
                    }
                }
            });
        }
    });
}

From source file:com.stikyhive.stikyhive.ChattingActivity.java

public void clickSend(View v) {
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            0);//from  ww  w.  ja v  a 2s. co  m
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layoutTalk.setLayoutParams(params);
    layoutTalk.setGravity(Gravity.CENTER);
    flagRecord = false;
    /*txtEditorWatcher = new TextWatcher() {
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }
            
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        //This sets a textview to the current length
        Log.i("Text ", " is changed" + s + "**");
        if (s.toString().substring(0, s.length()).equalsIgnoreCase(" ")) {
            Log.i("Can't ", " space");
        }
        // txtTitleCha.setText(String.valueOf(50 - s.length()) + " characters left");
    }
            
    public void afterTextChanged(Editable s) {
    }
    };*/

    messageServer = edTxtMsg.getText().toString();
    lv.smoothScrollToPosition(adapter.getCount() - 1);
    if (messageServer.equals("")) {
        setShakeAnimation(edTxtMsg);
        Toast.makeText(getApplicationContext(), "Enter your message", Toast.LENGTH_SHORT).show();
    } else {
        // edTxtMsg.addTextChangedListener(txtEditorWatcher);
        calcualteTodayDate();
        Log.i("Time Server ", " * " + timeSendServer);
        flagChatting = true;
        msg = edTxtMsg.getText().toString();
        new regTask().execute("Send message to ");
        adapter.add(new StikyChat("", edTxtMsg.getText().toString(), false, timeSend, "", 0, 0, "", "", "",
                null, ""));
        lv.smoothScrollToPosition(adapter.getCount() - 1);
        edTxtMsg.setText("");
    }

}

From source file:android.support.design.widget.CoordinatorLayout.java

/**
 * Return the given gravity value or the default if the passed value is NO_GRAVITY.
 * This should be used for children that are anchored to another view.
 *//*ww  w. jav a  2 s  .  c  o  m*/
private static int resolveAnchoredChildGravity(int gravity) {
    return gravity == Gravity.NO_GRAVITY ? Gravity.CENTER : gravity;
}

From source file:com.stikyhive.stikyhive.ChattingActivity.java

public void clickPay(View v) {
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            0);//w  ww.  j  a v  a  2  s .c o  m
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layoutTalk.setLayoutParams(params);
    layoutTalk.setGravity(Gravity.CENTER);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    flagPay = true;
    //        Intent intent = new Intent("com.arctech.MAKEOFFER");
    //        intent.putExtra("recipientName", chatRecipient);
    //        intent.putExtra("recipientUrl", chatRecipientUrl);
    //        startActivity(intent);
    flagChatting = false;
    new regTask3().execute("Pay");
}

From source file:com.stikyhive.stikyhive.ChattingActivity.java

public void clickRecord(View v) {
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            calculatePixels(150f));//from w  w w  .ja va2  s  .  c  om
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layoutTalk.setLayoutParams(params);
    layoutTalk.setGravity(Gravity.CENTER);
    hideKeyboard(edTxtMsg);
    flagRecord = true;
    /* LayoutInflater inflator = (LayoutInflater) this
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     View header = inflator.inflate(R.layout.chat_talk, null);
     layoutTalk.addView(header);*/
    /*Intent intent = new Intent("com.arctech.AUDIOACTIVITY");
    startActivity(intent);*/
}

From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java

private void setOnClickView(GalleryItemViewTag tag, String message, View.OnClickListener handler) {
    tag.thumbnailView.setVisibility(View.VISIBLE);
    tag.loadingView.setVisibility(View.GONE);
    TextView v = new TextView(GalleryActivity.this);
    v.setGravity(Gravity.CENTER);
    v.setText(getSpannedText(message));//from ww w.  j av a2s.  c  o m
    tag.layout.setVisibility(View.VISIBLE);
    tag.layout.addView(v);
    v.setOnClickListener(handler);
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void endshiftCode() {
    pdialog = ProgressDialog.show(HomeScreen.this, "Please wait", "Ending shift ...", true);

    //send end shift code
    send_event("93");

    ToastMessage.displayToastFromResource(HomeScreen.this, 5, Gravity.CENTER,
            (ViewGroup) findViewById(R.id.toast_layout_root));

    //if tour module installed then clear out any current tour
    if (GTConstants.isTour) {
        //if tour started but not completed write to the trp file
        //touritemNumber > 0 indicates that at least one tag has been scanned
        if (GTConstants.trpfilename.length() > 1 && touritemNumber >= 0)
            endtrpFile(false);// w  w w  .j  a v  a2 s  .  com
        else
            cleantourInfo();
    }

    //write to dar, transfer file to send directory
    Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.darfileName,
            "End shift;" + GTConstants.currentBatteryPercent + ";" + Utility.getLocalTime() + ";"
                    + Utility.getLocalDate() + "\r\n",
            true);

    //write the event 19 information to the file
    String GM = Utility.getHeaderMessage("$GM") + ",19," + getCellID();
    Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.darfileName,
            GM + "\r\n", true);

    //give time for file write before moving file
    Utility.initializeGeneralTimer(2000);
    do {
        Utility.Sleep(1000);
    } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag());

    //move the dar file to the send file folder 
    File from = new File(GTConstants.dardestinationFolder, GTConstants.darfileName);

    //change the file name to match the $GM time and date
    String parse[] = GM.split(",");
    String newFile = GTConstants.LICENSE_ID.substring(7) + "_" + parse[10] + "_" + parse[2] + ".dar";

    File to = new File(GTConstants.sendfileFolder, newFile);
    from.renameTo(to);

    //write to srp file
    if (GTConstants.srpfileName.length() > 1) {
        Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.srpfileName,
                "End account;" + GTConstants.accountName + ";" + Utility.getLocalTime() + ";"
                        + Utility.getLocalDate() + "\r\n",
                true);

        //write the event 19 information to the file
        GM = Utility.getHeaderMessage("$GM") + ",19," + getCellID();
        Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.srpfileName,
                GM + "\r\n", true);

        //give time for file write before moving file
        Utility.initializeGeneralTimer(2000);
        do {
            Utility.Sleep(100);
        } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag());

        //move the srp file to the send file folder 
        from = new File(GTConstants.dardestinationFolder, GTConstants.srpfileName);

        //change the file name to match the $GM time and date
        String _parse[] = GM.split(",");
        newFile = GTConstants.LICENSE_ID.substring(7) + "_" + _parse[10] + "_" + _parse[2] + "_srp.srp";

        to = new File(GTConstants.sendfileFolder, newFile);
        from.renameTo(to);

        //end account
        GTConstants.srpfileName = " ";
        GTConstants.accountID = "";
        GTConstants.accountName = "";
    }
    //set flag for sending
    Utility.setUploadAvailable();

    //pause the GPS location service after ending a shift
    MainService.pauseLocationListener();

    //wait for end shift string to reach server (or timeout occurs) before dismissing wait dialog
    new CountDownTimer(5000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            if (!GTConstants.sendData) {
                //pdialog.dismiss();
            }
        }

        @Override
        public void onFinish() {
            if (!(pdialog == null)) {
                pdialog.dismiss();

                //set spinner back to start shift
                spinner.setSelection(0);

                //clear the warning text window
                setwarningText("");

                //set the current state
                Utility.setcurrentState(GTConstants.offShift);
                setuserBanner();

                btn_send.setEnabled(true);

                if (Utility.getpostorderAvailable()) {
                    restartsyncTimer = true;
                    showAlert("Sync Update", "Update of sync file required", true);
                }
            }
        }
    }.start();
}