List of usage examples for android.widget TextView setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.example.sam.savemeapp.StatisticsFragment.java
/** * Sets up the initial legend with the contained categories shown * in the pie chart and bullet points with the corresponding colors. */// ww w. ja va 2s . c o m public void setUpPiechart() { pieChart.getDescription().setEnabled(false); Legend pieL = pieChart.getLegend(); Log.d("stats", Float.toString(pieL.getEntries().length)); startLegend = pieL; LegendEntry[] legends = pieL.getEntries(); pieL.setEnabled(false); mLegend.removeAllViews(); //The default legend consist of TextViews and ImageViews which contains a bullet point. //The legends are contained inside of a horizontal LinearLayout which is contained in a vertical LinearLayout. for (int t = 0; t < legends.length - 1; t++) { LegendEntry x = legends[t]; LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams.setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } designPiechart(); pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { private int color; @Override public void onValueSelected(Entry e, Highlight h) { //it creates new legends with the information of the subcategories when a // category in the pi chart is clicked ArrayList<LegendEntry> list = new ArrayList<>(); mLegend.removeAllViews(); if (e.getData().equals(Color.parseColor("#00a0ae"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Food & Beverage")) { color = x.formColor; } } list.add(new LegendEntry("Food & Beverage: " + u.categories.get("Food & Beverage").get("Food & Beverage") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Restaurant & Caf: " + u.categories.get("Food & Beverage").get("Restaurant & Caf") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Supermarket: " + u.categories.get("Food & Beverage").get("Supermarket") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); //This category legends consist of the main category in this case "Food & Beverage" in the top of the legend //and the sub categories bellow. The name is also shown together with the amount spend in that category. for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#be3127"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Transportation")) { color = x.formColor; } } list.add(new LegendEntry("Transportation: " + u.categories.get("Transportation").get("Transportation") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Public transport: " + u.categories.get("Transportation").get("Public transport") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Taxi & Uber: " + u.categories.get("Transportation").get("Taxi & Uber") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Petrol: " + u.categories.get("Transportation").get("Petrol") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Maintenance: " + u.categories.get("Transportation").get("Maintenance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#7dc725"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Shopping")) { color = x.formColor; } } list.add(new LegendEntry( "Shopping: " + u.categories.get("Shopping").get("Shopping") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Clothing: " + u.categories.get("Shopping").get("Clothing") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electronics: " + u.categories.get("Shopping").get("Electronics") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Books: " + u.categories.get("Shopping").get("Books") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gifts: " + u.categories.get("Shopping").get("Gifts") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Other: " + u.categories.get("Shopping").get("Other") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#e88300"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Entertainment")) { color = x.formColor; } } list.add(new LegendEntry( "Entertainment: " + u.categories.get("Entertainment").get("Entertainment") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Going out: " + u.categories.get("Entertainment").get("Going out") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Sports: " + u.categories.get("Entertainment").get("Sports") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#dc006d"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Health")) { color = x.formColor; } } list.add(new LegendEntry("Health: " + u.categories.get("Health").get("Health") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Doctor: " + u.categories.get("Health").get("Doctor") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Pharmacy: " + u.categories.get("Health").get("Pharmacy") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#1562a4"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Bills")) { color = x.formColor; } } list.add(new LegendEntry("Bills: " + u.categories.get("Bills").get("Bills") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Water: " + u.categories.get("Bills").get("Water") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electricity: " + u.categories.get("Bills").get("Electricity") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gas: " + u.categories.get("Bills").get("Gas") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Rent: " + u.categories.get("Bills").get("Rent") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Phone: " + u.categories.get("Bills").get("Phone") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add( new LegendEntry("Insurance: " + u.categories.get("Bills").get("Insurance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("TV: " + u.categories.get("Bills").get("TV") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Internet: " + u.categories.get("Bills").get("Internet") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } } @Override public void onNothingSelected() { //Sets up the default legend when nothing is selected pieChart = (PieChart) v.findViewById(R.id.piechart); pieChart.setUsePercentValues(true); LegendEntry[] legends = startLegend.getEntries(); startLegend.setEnabled(false); mLegend.removeAllViews(); for (LegendEntry x : legends) { LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams .setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } } }); }
From source file:gr.ellak.ma.emergencyroad.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}./*from w w w . j av a 2 s .co m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setTextColor(Color.WHITE); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); textView.setLayoutParams( new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); return textView; }
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 www . j a va 2 s. co m 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.tonyjs.hashtagram.ui.widget.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}./*from w ww .j ava 2s . c om*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTextColor(Color.WHITE); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style // textView.setAllCaps(true); } ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); textView.setLayoutParams(params); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:mediachooser.activity.HomeFragmentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(getRLayoutId("activity_home_media_chooser")); maxImages = getIntent().getIntExtra(MultiImageChooserActivity.MAX_IMAGES_KEY, MultiImageChooserActivity.NOLIMIT); desiredWidth = getIntent().getIntExtra(MultiImageChooserActivity.WIDTH_KEY, 0); desiredHeight = getIntent().getIntExtra(MultiImageChooserActivity.HEIGHT_KEY, 0); quality = getIntent().getIntExtra(MultiImageChooserActivity.QUALITY_KEY, 0); thumbSize = getIntent().getIntExtra(MultiImageChooserActivity.THUMB_SIZE_KEY, 0); maxImageCount = maxImages;//from w w w.j av a 2 s . c o m headerBarTitle = (TextView) findViewById(getRIntId("titleTextViewFromMediaChooserHeaderBar")); headerBarCamera = (ImageView) findViewById(getRIntId("cameraImageViewFromMediaChooserHeaderBar")); headerBarBack = (ImageView) findViewById(getRIntId("backArrowImageViewFromMediaChooserHeaderView")); headerBarDone = (TextView) findViewById(getRIntId("doneTextViewViewFromMediaChooserHeaderView")); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); leftLinearContainer = (LinearLayout) findViewById(getRIntId("leftLinearContainer")); mTabHost.setup(this, getSupportFragmentManager(), getRIntId("realTabcontent")); leftLinearContainer.setOnClickListener(clickListener); headerBarCamera.setOnClickListener(clickListener); headerBarDone.setOnClickListener(clickListener); if (!MediaChooserConstants.showCameraVideo) { headerBarCamera.setVisibility(View.GONE); } if (getIntent() != null && (getIntent().getBooleanExtra("isFromBucket", false))) { if (getIntent().getBooleanExtra("image", false)) { headerBarTitle.setText(getResources().getString(getRStringId("image"))); setHeaderBarCameraBackground(getResources().getDrawable(getRDrawableId("selector_camera_button"))); headerBarCamera.setTag(getResources().getString(getRStringId("image"))); Bundle bundle = new Bundle(); bundle.putString("name", getIntent().getStringExtra("name")); mTabHost.addTab( mTabHost.newTabSpec("tab1") .setIndicator(getResources().getString(getRStringId("images_tab")) + " "), ImageFragment.class, bundle); } else { // headerBarTitle.setText(getResources().getString(R.string.video)); // setHeaderBarCameraBackground(getResources().getDrawable(R.drawable.selector_video_button)); // headerBarCamera.setTag(getResources().getString(R.string.video)); // // Bundle bundle = new Bundle(); // bundle.putString("name", getIntent().getStringExtra("name")); // mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(getResources().getString(R.string.videos_tab) + " "), VideoFragment.class, bundle); } } else { // if(MediaChooserConstants.showVideo){ // mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(getResources().getString(R.string.videos_tab) + " "), VideoFragment.class, null); // } if (MediaChooserConstants.showImage) { headerBarTitle.setText(getResources().getString(getRStringId("image"))); setHeaderBarCameraBackground(getResources().getDrawable(getRDrawableId("selector_camera_button"))); headerBarCamera.setTag(getResources().getString(getRStringId("image"))); mTabHost.addTab( mTabHost.newTabSpec("tab1") .setIndicator(getResources().getString(getRStringId("images_tab")) + " "), ImageFragment.class, null); } // if(MediaChooserConstants.showVideo){ // headerBarTitle.setText(getResources().getString(R.string.video)); // setHeaderBarCameraBackground(getResources().getDrawable(R.drawable.selector_video_button)); // headerBarCamera.setTag(getResources().getString(R.string.video)); // } } for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { TextView textView = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams(); params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.width = RelativeLayout.LayoutParams.WRAP_CONTENT; textView.setLayoutParams(params); } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams(); params.gravity = Gravity.CENTER; textView.setLayoutParams(params); } textView.setTextColor(getResources().getColor(getRColorId("tabs_title_color"))); textView.setTextSize(convertDipToPixels(10)); } if ((mTabHost.getTabWidget().getChildAt(0) != null)) { ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); } if ((mTabHost.getTabWidget().getChildAt(1) != null)) { ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(getRColorId("headerbar_selected_tab_color"))); } mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); ImageFragment imageFragment = (ImageFragment) fragmentManager.findFragmentByTag("tab1"); // VideoFragment videoFragment = (VideoFragment) fragmentManager.findFragmentByTag("tab2"); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (tabId.equalsIgnoreCase("tab1")) { headerBarTitle.setText(getResources().getString(getRStringId("image"))); setHeaderBarCameraBackground( getResources().getDrawable(getRDrawableId("selector_camera_button"))); headerBarCamera.setTag(getResources().getString(getRStringId("image"))); if (imageFragment != null) { // if(videoFragment != null){ // fragmentTransaction.hide(videoFragment); // } fragmentTransaction.show(imageFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(getRColorId("headerbar_selected_tab_color"))); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); } else { // headerBarTitle.setText(getResources().getString(R.string.video)); // setHeaderBarCameraBackground(getResources().getDrawable(R.drawable.selector_video_button)); // headerBarCamera.setTag(getResources().getString(R.string.video)); // // if(videoFragment != null){ // // if(imageFragment != null){ // fragmentTransaction.hide(imageFragment); // } // // fragmentTransaction.show(videoFragment); // if(videoFragment.getAdapter() != null){ // videoFragment.getAdapter().notifyDataSetChanged(); // } // } // ((TextView)(mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))).setTextColor(Color.WHITE); // ((TextView)(mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))).setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); } fragmentTransaction.commit(); } }); mTabHost.getTabWidget().getChildAt(0).setVisibility(View.GONE); // RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) headerBarCamera.getLayoutParams(); // params.height = convertDipToPixels(40); // params.width = convertDipToPixels(40); // headerBarCamera.setLayoutParams(params); // headerBarCamera.setScaleType(ScaleType.CENTER_INSIDE); // headerBarCamera.setPadding(convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15)); }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
public static AlertDialog getaddtextdialog(String title, final int itemnumber, Context ctx) { AlertDialog.Builder getaddtext = new AlertDialog.Builder(ctx); final LinearLayout linearlayout = new LinearLayout(ctx); linearlayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); linearlayout.setOrientation(LinearLayout.VERTICAL); final EditText nameet = new EditText(ctx); nameet.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final TextView fontname = new TextView(ctx); fontname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final TextView colorname = new TextView(ctx); colorname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final Spinner fontsizespinner = new Spinner(ctx); fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final Spinner colorspinner = new Spinner(ctx); fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); List<String> fontsizelist = new ArrayList<String>(); for (int t = 1; t < 200; t++) { fontsizelist.add(u.s(t));// w w w.j ava 2 s. c o m } ArrayAdapter<String> fontsizearrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview, fontsizelist); fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview); List<String> colorlist = new ArrayList<String>(); { colorlist.add("RED"); colorlist.add("BLACK"); colorlist.add("BLUE"); colorlist.add("GREEN"); colorlist.add("WHITE"); colorlist.add("GRAY"); } ArrayAdapter<String> colorlistarrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview, colorlist); fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview); colorspinner.setAdapter(colorlistarrayadapter); fontsizespinner.setAdapter(fontsizearrayadapter); fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, "25")); fontname.setText("Select Font Size"); fontname.setTextSize(20f); colorname.setText("Select Color"); colorname.setTextSize(20f); linearlayout.addView(nameet); linearlayout.addView(fontname); linearlayout.addView(fontsizespinner); linearlayout.addView(colorname); linearlayout.addView(colorspinner); if (!(itemnumber == view.i)) { nameet.setText(view.ITEMstring[itemnumber]); fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, u.s(view.ITEMfontsize[itemnumber]))); colorspinner.setSelection(getIndexofSpinner(colorspinner, u.s(view.ITEMfontcolor[itemnumber]))); } getaddtext.setView(linearlayout); getaddtext.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); getaddtext.setTitle(title); getaddtext.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub String string = nameet.getText().toString(); float fontsize = fontsizespinner.getSelectedItemPosition() + 1; //ITEMelcnumber[itemselectednumber]=u.i(string); int colpos = colorspinner.getSelectedItemPosition(); int[] col = new int[] { Color.RED, Color.BLACK, Color.BLUE, Color.GREEN, Color.WHITE, Color.GRAY }; int color = col[colpos]; Log.d("addtext", u.s((int) fontsize) + colpos + color); view.ITEMstring[itemnumber] = string; view.ITEMfontsize[itemnumber] = (int) fontsize; view.ITEMfontcolor[itemnumber] = color; view.itemname = string; view.fontsize = (int) fontsize; view.color = color; view.invalidate(); dialog.dismiss(); FloorPlanActivity.writeonedbitem(itemnumber); } }); return getaddtext.create(); }
From source file:dev.journey.uitoolkit.view.FlexibleTabLayout.java
private TextView getDefaultTextView() { TextView textView = new TextView(getContext()); textView.setMaxLines(2);/*w w w. ja v a2 s. c o m*/ textView.setEllipsize(TextUtils.TruncateAt.END); textView.setGravity(Gravity.CENTER); LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textView.setLayoutParams(layoutParams); return textView; }
From source file:com.cybrosys.scientific.EventListener.java
@SuppressWarnings("deprecation") public void showHistory() { shPref = ScientificActivity.ctx.getSharedPreferences("myHistpref", 0); int inSize = shPref.getInt("HistIndex", 0); System.out.println("" + inSize); String[] str = new String[inSize]; for (int inI = 0; inI < inSize; inI++) { str[inI] = shPref.getString("hist" + inI, ""); System.out.println(str[inI]); }/*from w ww .j a v a 2s . c o m*/ LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); vwLayout = inflater.inflate(R.layout.pop_history, (ViewGroup) ((Activity) ctx).findViewById(R.id.popup_element)); popmW1 = new PopupWindow(vwLayout, PalmCalcActivity.inDispwidth, PalmCalcActivity.inDispheight, true); popmW1.setBackgroundDrawable(new BitmapDrawable()); popmW1.setOutsideTouchable(true); popmW1.showAtLocation(vwLayout, Gravity.CENTER, 0, 0); tblltTable = (TableLayout) vwLayout.findViewById(R.id.tablelay); ImageButton btnCancel = (ImageButton) vwLayout.findViewById(R.id.butcancelmain); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { popmW1.dismiss(); } }); txtvHistory = new TextView[inSize]; btnHistory = new Button[inSize]; tblrRowL = new TableRow[inSize]; TableRow.LayoutParams buttonParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f); TableRow.LayoutParams textParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT, .1f); int inJ = 0, inL = inSize - 1; for (int inI = 0; inI < inSize; inI++) { if (!str[inI].equalsIgnoreCase("")) { btnHistory[inJ] = new Button(ctx); txtvHistory[inJ] = new TextView(ctx); txtvHistory[inJ].setText("" + (inJ + 1)); txtvHistory[inJ].setGravity(Gravity.CENTER); txtvHistory[inJ].setTextColor(ScientificActivity.ctx.getResources().getColor(R.color.HistColor)); txtvHistory[inJ].setLayoutParams(textParams); btnHistory[inJ].setText(str[inL]); btnHistory[inJ].setTextColor(Color.WHITE); btnHistory[inJ].setGravity(Gravity.LEFT); btnHistory[inJ].setLayoutParams(buttonParams); btnHistory[inJ].setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.button_effect)); tblrRowL[inJ] = new TableRow(ctx); tblrRowL[inJ].addView(txtvHistory[inJ]); tblrRowL[inJ].addView(btnHistory[inJ]); tblltTable.addView(tblrRowL[inJ]); final int inK = inJ; btnHistory[inK].setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // etxt.setText(btns[inK].getText().toString()); mHandler.insert(btnHistory[inK].getText().toString()); popmW1.dismiss(); } }); inJ++; inL--; } } if (inSize == 0) { TextView txtvHistory = new TextView(ctx); txtvHistory.setLayoutParams(textParams); txtvHistory.setGravity(Gravity.CENTER); txtvHistory.setTextColor(Color.WHITE); txtvHistory.setText("History Empty"); TableRow tblrRowL = new TableRow(ctx); tblrRowL.addView(txtvHistory); tblltTable.addView(tblrRowL); } }
From source file:com.b44t.ui.Components.PasscodeView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = AndroidUtilities.displaySize.y - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight); LayoutParams layoutParams;/*ww w.j ava 2 s . c o m*/ if (!AndroidUtilities.isTablet() && getContext().getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams(); layoutParams.width = UserConfig.passcodeType == 0 ? width / 2 : width; layoutParams.height = AndroidUtilities.dp(140); layoutParams.topMargin = (height - AndroidUtilities.dp(140)) / 2; passwordFrameLayout.setLayoutParams(layoutParams); layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams(); layoutParams.height = height; layoutParams.leftMargin = width / 2; layoutParams.topMargin = height - layoutParams.height; layoutParams.width = width / 2; numbersFrameLayout.setLayoutParams(layoutParams); } else { int top = 0; int left = 0; if (AndroidUtilities.isTablet()) { if (width > AndroidUtilities.dp(498)) { left = (width - AndroidUtilities.dp(498)) / 2; width = AndroidUtilities.dp(498); } if (height > AndroidUtilities.dp(528)) { top = (height - AndroidUtilities.dp(528)) / 2; height = AndroidUtilities.dp(528); } } layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams(); layoutParams.height = height / 3; layoutParams.width = width; layoutParams.topMargin = top; layoutParams.leftMargin = left; passwordFrameLayout.setTag(top); passwordFrameLayout.setLayoutParams(layoutParams); layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams(); layoutParams.height = height / 3 * 2; layoutParams.leftMargin = left; layoutParams.topMargin = height - layoutParams.height + top; layoutParams.width = width; numbersFrameLayout.setLayoutParams(layoutParams); } int sizeBetweenNumbersX = (layoutParams.width - AndroidUtilities.dp(50) * 3) / 4; int sizeBetweenNumbersY = (layoutParams.height - AndroidUtilities.dp(50) * 4) / 5; for (int a = 0; a < 11; a++) { LayoutParams layoutParams1; int num; if (a == 0) { num = 10; } else if (a == 10) { num = 11; } else { num = a - 1; } int row = num / 3; int col = num % 3; int top; if (a < 10) { TextView textView = numberTextViews.get(a); TextView textView1 = lettersTextViews.get(a); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams1 = (LayoutParams) textView1.getLayoutParams(); top = layoutParams1.topMargin = layoutParams.topMargin = sizeBetweenNumbersY + (sizeBetweenNumbersY + AndroidUtilities.dp(50)) * row; layoutParams1.leftMargin = layoutParams.leftMargin = sizeBetweenNumbersX + (sizeBetweenNumbersX + AndroidUtilities.dp(50)) * col; layoutParams1.topMargin += AndroidUtilities.dp(40); textView.setLayoutParams(layoutParams); textView1.setLayoutParams(layoutParams1); } else { layoutParams = (LayoutParams) eraseView.getLayoutParams(); top = layoutParams.topMargin = sizeBetweenNumbersY + (sizeBetweenNumbersY + AndroidUtilities.dp(50)) * row + AndroidUtilities.dp(8); layoutParams.leftMargin = sizeBetweenNumbersX + (sizeBetweenNumbersX + AndroidUtilities.dp(50)) * col; top -= AndroidUtilities.dp(8); eraseView.setLayoutParams(layoutParams); } FrameLayout frameLayout = numberFrameLayouts.get(a); layoutParams1 = (LayoutParams) frameLayout.getLayoutParams(); layoutParams1.topMargin = top - AndroidUtilities.dp(17); layoutParams1.leftMargin = layoutParams.leftMargin - AndroidUtilities.dp(25); frameLayout.setLayoutParams(layoutParams1); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
From source file:com.hybris.mobile.lib.ui.view.Alert.java
/** * Set the icon on the alert//w w w . j a v a 2 s . c o m * * @param context application-specific resources * @param configuration describes all device configuration information * @param mainView ViewGroup resources * @param textView alert message to be viewed message to be displayedView */ @SuppressLint("NewApi") private static void setIcon(Activity context, Configuration configuration, ViewGroup mainView, TextView textView) { ImageView imageView = (ImageView) mainView.findViewById(R.id.alert_view_icon); // Reset the current icon if (imageView != null) { mainView.removeView(imageView); } // On the textview as well textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); textView.setCompoundDrawablePadding(0); if (configuration.getIconResId() != -1) { imageView = new ImageView(context); imageView.setId(R.id.alert_view_icon); imageView.setImageResource(configuration.getIconResId()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(layoutParams); switch (configuration.getIconPosition()) { case LEFT_TEXT: textView.setCompoundDrawablesWithIntrinsicBounds(configuration.getIconResId(), 0, 0, 0); textView.setCompoundDrawablePadding(10); break; case RIGHT_TEXT: textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, configuration.getIconResId(), 0); textView.setCompoundDrawablePadding(10); break; case LEFT: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START); } layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layoutParams.setMargins(25, 0, 0, 0); mainView.addView(imageView); // We redefine the layout params otherwise the image is not well aligned textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); break; case RIGHT: default: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END); } layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); layoutParams.setMargins(0, 0, 25, 0); mainView.addView(imageView); // We redefine the layout params otherwise the image is not well aligned textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); break; } } }