List of usage examples for android.view Gravity CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.view Gravity CENTER_VERTICAL.
Click Source Link
From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java
@Override public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true); if (mEntriesCursorAdapter != null) { setListAdapter(mEntriesCursorAdapter); }/*from ww w . ja v a 2 s . c o m*/ mListView = (ListView) rootView.findViewById(android.R.id.list); mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext())); if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) { final TextView header = new TextView(mListView.getContext()); header.setMinimumHeight(UiUtils.dpToPixel(70)); int footerPadding = UiUtils.dpToPixel(10); header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding); header.setText(R.string.tip_sentence); header.setGravity(Gravity.CENTER_VERTICAL); header.setCompoundDrawablePadding(UiUtils.dpToPixel(5)); header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0, R.drawable.ic_action_cancel, 0); header.setClickable(true); header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mListView.removeHeaderView(header); PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false); } }); mListView.addHeaderView(header); } UiUtils.addEmptyFooterView(mListView, 90); mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn); mRefreshListBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mNewEntriesNumber = 0; mListDisplayDate = new Date().getTime(); refreshUI(); if (mCurrentUri != null) { restartLoaders(); } } }); disableSwipe(); return rootView; }
From source file:widgets.Graphical_List.java
@SuppressLint("HandlerLeak") public Graphical_List(tracerengine Trac, Activity context, int id, int dev_id, String name, String type, String address, final String state_key, String url, final String usage, int period, int update, int widgetSize, int session_type, final String parameters, String model_id, int place_id, String place_type, SharedPreferences params) { super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container); this.Tracer = Trac; this.context = context; this.dev_id = dev_id; this.id = id; this.usage = usage; this.address = address; //this.type = type; this.state_key = state_key; this.update = update; this.wname = name; this.url = url; String[] model = model_id.split("\\."); this.type = model[0]; this.place_id = place_id; this.place_type = place_type; this.params = params; packageName = context.getPackageName(); this.myself = this; this.session_type = session_type; this.parameters = parameters; setOnLongClickListener(this); setOnClickListener(this); mytag = "Graphical_List (" + dev_id + ")"; login = params.getString("http_auth_username", null); password = params.getString("http_auth_password", null); //state key//from w ww. j a va 2 s . co m state_key_view = new TextView(context); state_key_view.setText(state_key); state_key_view.setTextColor(Color.parseColor("#333333")); //value value = new TextView(context); value.setTextSize(28); value.setTextColor(Color.BLACK); animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(1000); if (with_list) { //Exploit parameters JSONObject jparam = null; String command; JSONArray commandValues = null; try { jparam = new JSONObject(parameters.replaceAll(""", "\"")); command = jparam.getString("command"); commandValues = jparam.getJSONArray("commandValues"); Tracer.e(mytag, "Json command :" + commandValues); } catch (Exception e) { command = ""; commandValues = null; Tracer.e(mytag, "Json command error " + e.toString()); } if (commandValues != null) { if (commandValues.length() > 0) { if (known_values != null) known_values = null; known_values = new String[commandValues.length()]; for (int i = 0; i < commandValues.length(); i++) { try { known_values[i] = commandValues.getString(i); } catch (Exception e) { known_values[i] = "???"; } } } } //list of choices listeChoices = new ListView(context); listItem = new ArrayList<HashMap<String, String>>(); list_usable_choices = new Vector<String>(); for (int i = 0; i < known_values.length; i++) { list_usable_choices.add(getStringResourceByName(known_values[i])); HashMap<String, String> map = new HashMap<String, String>(); map.put("choice", getStringResourceByName(known_values[i])); map.put("cmd_to_send", known_values[i]); listItem.add(map); } SimpleAdapter adapter_map = new SimpleAdapter(getContext(), listItem, R.layout.item_choice, new String[] { "choice", "cmd_to_send" }, new int[] { R.id.choice, R.id.cmd_to_send }); listeChoices.setAdapter(adapter_map); listeChoices.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if ((position < listItem.size()) && (position > -1)) { //process selected command HashMap<String, String> map = new HashMap<String, String>(); map = listItem.get(position); cmd_requested = map.get("cmd_to_send"); Tracer.d(mytag, "command selected at Position = " + position + " Commande = " + cmd_requested); new CommandeThread().execute(); } } }); listeChoices.setScrollingCacheEnabled(false); //feature panel 2 which will contain list of selectable choices featurePan2 = new LinearLayout(context); featurePan2.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); featurePan2.setGravity(Gravity.CENTER_VERTICAL); featurePan2.setPadding(5, 10, 5, 10); featurePan2.addView(listeChoices); } LL_featurePan.addView(value); handler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == 2) { Toast.makeText(getContext(), "Command Failed", Toast.LENGTH_SHORT).show(); } else if (msg.what == 9999) { //Message from cache engine //state_engine send us a signal to notify value changed if (session == null) return; String loc_Value = session.getValue(); Tracer.d(mytag, "Handler receives a new value <" + loc_Value + ">"); value.setText(getStringResourceByName(loc_Value)); //To have the icon colored as it has no state IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 2)); } else if (msg.what == 9998) { // state_engine send us a signal to notify it'll die ! Tracer.d(mytag, "cache engine disappeared ===> Harakiri !"); session = null; realtime = false; removeView(LL_background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } } }; //End of handler //================================================================================ /* * New mechanism to be notified by widgetupdate engine when our value is changed * */ WidgetUpdate cache_engine = WidgetUpdate.getInstance(); if (cache_engine != null) { session = new Entity_client(dev_id, state_key, mytag, handler, session_type); if (tracerengine.get_engine().subscribe(session)) { realtime = true; //we're connected to engine //each time our value change, the engine will call handler handler.sendEmptyMessage(9999); //Force to consider current value in session } } //================================================================================ //updateTimer(); //Don't use anymore cyclic refresh.... }
From source file:net.etuldan.sparss.fragment.EntriesListFragment.java
@Override public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true); if (mEntriesCursorAdapter != null) { setListAdapter(mEntriesCursorAdapter); }/*from w ww .j a v a 2s . c om*/ mListView = (ListView) rootView.findViewById(android.R.id.list); mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext())); if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) { final TextView header = new TextView(mListView.getContext()); header.setMinimumHeight(UiUtils.dpToPixel(70)); int footerPadding = UiUtils.dpToPixel(10); header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding); header.setText(R.string.tip_sentence); header.setGravity(Gravity.CENTER_VERTICAL); header.setCompoundDrawablePadding(UiUtils.dpToPixel(5)); header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_info_outline, 0, R.drawable.ic_cancel, 0); header.setClickable(true); header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mListView.removeHeaderView(header); PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false); } }); mListView.addHeaderView(header); } UiUtils.addEmptyFooterView(mListView, 90); mHideReadButton = (FloatingActionButton) rootView.findViewById(R.id.hide_read_button); mHideReadButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { UiUtils.displayHideReadButtonAction(mListView.getContext()); return true; } }); UiUtils.updateHideReadButton(mHideReadButton); mSearchView = (SearchView) rootView.findViewById(R.id.searchView); if (savedInstanceState != null) { refreshUI(); // To hide/show the search bar } mSearchView.post(new Runnable() { // Do this AFTER the text has been restored from saveInstanceState @Override public void run() { mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); return false; } @Override public boolean onQueryTextChange(String s) { setData(EntryColumns.SEARCH_URI(s), true); return false; } }); } }); disableSwipe(); return rootView; }
From source file:org.apps8os.logger.android.fragment.LoggerPanelFragment.java
private void initCustomView() { mSwitcherView = null;//from w w w. j a v a2 s.c o m mSwitch = null; mEventCount = null; mSwitcherView = getLayoutInflater().inflate(R.layout.logger_switcher, null); mSwitch = (Switch) mSwitcherView.findViewById(R.id.logger_switcher); mSwitch.setTextOn(getString(R.string.on)); mSwitch.setTextOff(getString(R.string.off)); mSwitch.setOnCheckedChangeListener(this); mSwitch.setChecked(mSwitchCheckState); mEventCount = (TextView) mSwitcherView.findViewById(R.id.text_view_running_event); // if the device is honeycomb, we need to // adjust the UI a little bit. Otherwise, // the switch would look weird. if (AndroidVersionHelper.isHoneycomb()) { final LinearLayout.LayoutParams swLp = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); swLp.setMargins(8, -20, 0, 0); mSwitch.setLayoutParams(swLp); } final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; lp.setMargins(0, 0, 16, 0); final ActionBar actionbar = getSupportActionBar(); if (actionbar != null) { actionbar.setCustomView(mSwitcherView, lp); actionbar.setTitle(R.string.app_name); } }
From source file:cz.babi.android.remoteme.service.ConnectionService.java
/** * If server is unreachable we need to stop service and notice that to user. *//*w w w. j a va 2 s . co m*/ private void closeConnection() { if (Common.DEBUG) Log.d(TAG_CLASS_NAME, "[closeConnection]"); if (clientSocket != null) try { clientSocket.close(); } catch (IOException e) { if (Common.ERROR) Log.e(TAG_CLASS_NAME, "[stopService][Can not close client " + "socket.]"); } ConnectionService.server = null; ConnectionService.clientSocket = null; ConnectionService.in = null; ConnectionService.out = null; ConnectionService.needEncryptedCommunication = false; LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View toastLayout = mInflater.inflate(R.layout.toast_warning, null); TextView text = (TextView) toastLayout.findViewById(R.id.warning_text); text.setText(R.string.connection_service_connection_lost_text); Toast toast = new Toast(this); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(toastLayout); toast.show(); disconnectWithError = true; }
From source file:com.mattprecious.notisync.activity.MainActivity.java
private void configureActionBar() { ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); for (int i = 0; i < adapter.getCount(); i++) { actionBar.addTab(actionBar.newTab().setText(adapter.getPageTitle(i)).setTabListener(new TabListener() { @Override/* www.ja va2 s. c o m*/ public void onTabUnselected(Tab tab, FragmentTransaction ft) { } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { pager.setCurrentItem(tab.getPosition()); } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { } })); } actionBarSwitch = new Switch(this, null, R.attr.switchStyleAb); actionBarSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { startService(); } else { stopService(); } } }); updateSwitch(); final int padding = getResources().getDimensionPixelSize(R.dimen.action_bar_switch_padding); actionBarSwitch.setPadding(0, 0, padding, 0); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(actionBarSwitch, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.RIGHT)); }
From source file:com.tmall.ultraviewpager.sample.PagerActivity.java
@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (ultraViewPager.getIndicator() == null) { ultraViewPager.initIndicator();//from w w w.j a v a 2 s.c om ultraViewPager.getIndicator().setOrientation(gravity_indicator); } if (parent == indicatorStyle) { switch (position) { case 0: ultraViewPager.disableIndicator(); break; case 1: ultraViewPager.getIndicator().setFocusResId(0).setNormalResId(0); ultraViewPager.getIndicator().setFocusColor(Color.GREEN).setNormalColor(Color.WHITE) .setRadius((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); break; case 2: ultraViewPager.getIndicator().setFocusResId(R.mipmap.tm_biz_lifemaster_indicator_selected) .setNormalResId(R.mipmap.tm_biz_lifemaster_indicator_normal); break; case 3: break; } } if (parent == indicatorGravityHor) { switch (position) { case 0: gravity_hor = Gravity.LEFT; break; case 1: gravity_hor = Gravity.RIGHT; break; case 2: gravity_hor = Gravity.CENTER_HORIZONTAL; break; } if (ultraViewPager.getIndicator() != null) { if (gravity_ver != 0) { ultraViewPager.getIndicator().setGravity(gravity_hor | gravity_ver); } else { ultraViewPager.getIndicator().setGravity(gravity_hor); } } } if (parent == indicatorGravityVer) { switch (position) { case 0: gravity_ver = Gravity.TOP; break; case 1: gravity_ver = Gravity.BOTTOM; break; case 2: gravity_ver = Gravity.CENTER_VERTICAL; break; } if (ultraViewPager.getIndicator() != null) { if (gravity_hor != 0) { ultraViewPager.getIndicator().setGravity(gravity_hor | gravity_ver); } else { ultraViewPager.getIndicator().setGravity(gravity_ver); } } } }
From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java
private void resetPredictionsView(LinearLayout predictions, boolean showInitLabel) { predictions.removeAllViews();/*from ww w .j a v a 2 s. com*/ if (showInitLabel) { TextView tv1 = new TextView(this); tv1.setText("Predictions will appear Here"); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.weight = 1.f; params.gravity = Gravity.CENTER_VERTICAL; tv1.setLayoutParams(params); tv1.setTextSize(pixels5); predictions.addView(tv1); } if (saveButton != null) saveButton.setVisibility(View.INVISIBLE); if (loader != null) loader.setVisibility(View.INVISIBLE); }
From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomTabLayout.java
private void setupContainer() { mContainer = new LinearLayoutCompat(getContext()); mContainer.setFocusable(false);// w w w .j a va 2s . c o m LayoutParams layoutParams; if (isTablet) { layoutParams = new LayoutParams(mMaxContainerHeight, LayoutParams.MATCH_PARENT); layoutParams.gravity = Gravity.CENTER_VERTICAL; disableBehavior(); mContainer.setOrientation(LinearLayoutCompat.VERTICAL); mContainer.setGravity(Gravity.TOP | Gravity.CENTER_VERTICAL); addView(mContainer, layoutParams); } else { mContainer.setOrientation(LinearLayoutCompat.HORIZONTAL); mContainer.setPadding(0, 0, (int) getResources().getDimension(R.dimen.bottom_navigation_item_padding_bottom), 0); layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.bottom_navigation_height)); layoutParams.gravity = Gravity.TOP; layoutParams.bottomMargin = !isInEditMode() && Util.isNavigationBarTranslucent(getContext()) && !isLandscape() ? Util.getNavigationBarHeight(getContext()) : 0; mContainer.setOrientation(LinearLayoutCompat.HORIZONTAL); mContainer.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL); addView(mContainer, layoutParams); } }
From source file:xyz.berial.textinputlayout.CollapsingTextHelper.java
private void calculateBaseOffsets() { // We then calculate the collapsed text size, using the same logic mTextPaint.setTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom; break;/*from w ww . j a v a2s.c om*/ case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } mTextPaint.setTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); }