List of usage examples for android.view Gravity CENTER
int CENTER
To view the source code for android.view Gravity CENTER.
Click Source Link
From source file:com.sdspikes.fireworks.FireworksActivity.java
private TextView makeAttributeTextView(final int rank, final GameState.CardColor color) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); int oneButtonWidth = mDiscardWidthR2 / 10; int marginWidth = oneButtonWidth / 10; params.setMargins(marginWidth, 5, marginWidth, 5); params.width = oneButtonWidth - marginWidth * 2; params.height = params.width;//from w w w. ja v a 2s . c om TextView textView = new TextView(this); textView.setLayoutParams(params); textView.setText(String.valueOf(rank)); if (rank == -1) textView.setText(" "); textView.setGravity(Gravity.CENTER); textView.setBackgroundResource(HandFragment.cardColorToBGColor.get(color)); textView.setTextColor(getResources().getColor(HandFragment.cardColorToTextColor(color))); textView.setVisibility(View.VISIBLE); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "clicked on an attribute button: " + GameState.Card.cardColorToString(color) + " " + rank); List<GameState.Card> hand = mTurnData.state.hands.get(mRecipientPlayer).hand; List<Integer> locations = new ArrayList<Integer>(); String info = ""; if (rank == -1) { info = GameState.Card.cardColorToString(color); for (int i = 0; i < hand.size(); i++) { if (hand.get(i).color == color) locations.add(i); } } else { info = HandFragment.rankToString(rank); for (int i = 0; i < hand.size(); i++) { if (hand.get(i).rank == rank) locations.add(i); } } if (locations.size() == 0) { Toast.makeText(FireworksActivity.this, mIdToName.get(mRecipientPlayer) + " does not have any " + info, Toast.LENGTH_SHORT); } else { int[] positions = new int[locations.size()]; for (int i = 0; i < positions.length; i++) { // Make the positions 1-indexed positions[i] = locations.get(i) + 1; } LogItem item = new InfoLogItem(mMyId, mRecipientPlayer, info, positions); actionLog.add(item.toString()); mTurnData.state.hintsRemaining--; mTurnData.state.currentPlayerId = mTurnData.state.hands .get(mTurnData.state.currentPlayerId).nextPlayerId; togglePlayOptionsVisible(PlayOptions.turnMessage); broadcastGameInfo(item.getJSONObject()); updateAllPlayers(mTurnData.getJSONObject()); mRecipientPlayer = null; } } }); return textView; }
From source file:com.intel.xdk.device.Device.java
public void showRemoteSite(final String strURL, final int closeX_pt, final int closeY_pt, final int closeX_ls, final int closeY_ls, final int closeW, final int closeH, final String closeImage) { if (strURL == null || strURL.length() == 0) return;/*from ww w. j ava2 s. c om*/ remoteCloseXPort = closeX_pt; remoteCloseYPort = closeY_pt; remoteCloseXLand = closeX_ls; remoteCloseYLand = closeY_ls; //hack to adjust image size DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); remoteCloseW = (int) ((float) closeW * dm.density); remoteCloseH = (int) ((float) closeH * dm.density); //Set position, width, height of closeImage according to currentOrientation if (this.getOrientation() == 0 || this.getOrientation() == 180) { //Portrait AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams( remoteCloseW == 0 ? 48 : remoteCloseW, remoteCloseH == 0 ? 48 : remoteCloseH, remoteCloseXPort, remoteCloseYPort); remoteClose.setLayoutParams(params); } else { AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams( remoteCloseW == 0 ? 48 : remoteCloseW, remoteCloseH == 0 ? 48 : remoteCloseH, remoteCloseXLand, remoteCloseYLand); remoteClose.setLayoutParams(params); } activity.runOnUiThread(new Runnable() { public void run() { if (remoteView == null) { remoteView = new WebView(activity); remoteView.setInitialScale(0); remoteView.setVerticalScrollBarEnabled(false); remoteView.setWebViewClient(new WebViewClient()); final WebSettings settings = remoteView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); remoteLayout.addView(remoteView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER)); remoteView.requestFocusFromTouch(); remoteView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) { remoteClose.performClick(); return true; } else { return false; } } }); } // load the url remoteView.loadUrl(strURL); // show the view remoteLayout.setVisibility(View.VISIBLE); // set the flag isShowingRemoteSite = true; // isShowingRemoteSite = true; // get focus remoteView.requestFocus(View.FOCUS_DOWN); remoteClose.bringToFront(); } }); }
From source file:com.devwang.logcabin.LogCabinMainActivity.java
/** * app mcu'S' // w w w . j a va 2s . com */ protected void isSound() { State_Sound = ""; mLogCabinInfo.setSTATE_IR(State_Ir); toastDisplay(getApplicationContext(), "~~~", Gravity.CENTER, R.drawable.icon_sound_wind, Toast.LENGTH_SHORT); vibratorSettings(1);// State_Sound = ""; mLogCabinInfo.setSTATE_SOUND(State_Sound); }
From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java
public void setRadioGroupInLayout(View layout) { RadioGroup radioGroup = (RadioGroup) layout.findViewById(R.id.radiogroup); RadioButton radioButtonTop = (RadioButton) layout.findViewById(R.id.radiobutton_top); RadioButton radioButtonCenter = (RadioButton) layout.findViewById(R.id.radiobutton_center); RadioButton radioButtonButton = (RadioButton) layout.findViewById(R.id.radiobutton_bottom); switch (mToastPosition) { case Gravity.TOP: radioButtonTop.setChecked(true); break;/*from w ww.ja v a 2s . co m*/ case Gravity.CENTER: radioButtonCenter.setChecked(true); break; case Gravity.BOTTOM: radioButtonButton.setChecked(true); break; } radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radiobutton_top: mToastPosition = Gravity.TOP; break; case R.id.radiobutton_center: mToastPosition = Gravity.CENTER; if (mAlertService != null) { mAlertService.setToastPosition(Gravity.CENTER); } break; case R.id.radiobutton_bottom: mToastPosition = Gravity.BOTTOM; break; } if (mAlertService != null && mAlertService.isBoundService()) { mAlertService.setToastPosition(mToastPosition); } } }); }
From source file:cn.kangeqiu.kq.activity.ChatActivity.java
/** * ?uri??/*from w ww .ja v a2s .com*/ * * @param selectedImage */ private void sendPicByUri(Uri selectedImage) { // String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null); String st8 = getResources().getString(R.string.cant_find_pictures); 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, 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??//ww w . j a va 2 s . c o m * * @param selectedImage */ private File Uritofile(Uri selectedImage) { File file = null; 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; } file = new File(picturePath); //sendPicture(picturePath); } else { 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; }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Shows a Toast alert./* w w w . j a va 2 s . c o m*/ * * @param context * @param message * @param centerOnScreen Set to TRUE to center on the screen. */ public static void dialog_showToastAlert(Context context, String message, boolean centerOnScreen) { Toast msg = Toast.makeText(context, message, Toast.LENGTH_SHORT); if (centerOnScreen) { msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2, msg.getYOffset() / 2); } msg.show(); }
From source file:cmu.cconfs.instantMessage.activities.ChatActivity.java
/** * ?uri??/* w w w .j av a 2 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:com.ccxt.whl.activity.SettingsFragment.java
/** * ?uri?/*from w w w .j av a 2 s. c om*/ * * @param selectedImage */ private void sendPicByUri(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; } //copyFile(picturePath,imageUri.getPath()); cropImageUri(selectedImage, 200, 200, USERPIC_REQUEST_CODE_CUT); //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; } //copyFile(selectedImage.getPath(),imageUri.getPath()); cropImageUri(selectedImage, 200, 200, USERPIC_REQUEST_CODE_CUT); //sendPicture(file.getAbsolutePath()); } }
From source file:flex.android.magiccube.activity.ActivityBattleMode.java
public void SaveReplay() { // TODO Auto-generated method stub if (dbHelper == null) { dbHelper = new DBHelper(this); }//w ww .j a va 2s.c om dbHelper.create(TableName, TableContent); ContentValues values = new ContentValues(); values.put("cmdstrbefore", this.GetCmdStrBefore()); values.put("cmdstrafter", this.GetCmdStrAfter()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); String datestr = dateFormat.format(date); values.put("savetime", datestr); values.put("movetimes", this.GetMoveTimes()); dbHelper.insert(TableName, values); Toast toast; if (State == OnStateListener.WIN) { toast = Toast.makeText(getApplicationContext(), "" + datestr, Toast.LENGTH_LONG); } else { toast = Toast.makeText(getApplicationContext(), "" + datestr, Toast.LENGTH_LONG); } toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }