Java Code Examples for android.widget.RadioGroup#getChildCount()

The following examples show how to use android.widget.RadioGroup#getChildCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleNoValuesExtractor.java    From AndroidRipper with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Detect Name of the Widget
 * 
 * @param v
 *            Widget
 * @return
 */
private String detectName(View v) {
	String name = "";
	if (v instanceof TextView) {
		TextView t = (TextView) v;
		name = (t.getText() != null) ? t.getText().toString() : "";
		if (v instanceof EditText) {
			CharSequence hint = ((EditText) v).getHint();
			name = (hint == null) ? "" : hint.toString();
		}
	} else if (v instanceof RadioGroup) {
		RadioGroup g = (RadioGroup) v;
		int max = g.getChildCount();
		String text = "";
		for (int i = 0; i < max; i++) {
			View c = g.getChildAt(i);
			text = detectName(c);
			if (!text.equals("")) {
				name = text;
				break;
			}
		}
	}
	return name;
}
 
Example 2
Source File: SimpleExtractor.java    From AndroidRipper with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Detect Name of the Widget
 * 
 * @param v
 *            Widget
 * @return
 */
protected String detectName(View v) {
	String name = "";
	if (v instanceof TextView) {
		TextView t = (TextView) v;
		name = (t.getText() != null) ? t.getText().toString() : "";
		if (v instanceof EditText) {
			CharSequence hint = ((EditText) v).getHint();
			name = (hint == null) ? "" : hint.toString();
		}
	} else if (v instanceof RadioGroup) {
		RadioGroup g = (RadioGroup) v;
		int max = g.getChildCount();
		String text = "";
		for (int i = 0; i < max; i++) {
			View c = g.getChildAt(i);
			text = detectName(c);
			if (!text.equals("")) {
				name = text;
				break;
			}
		}
	}
	return name;
}
 
Example 3
Source File: ReflectionExtractor.java    From AndroidRipper with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Detect Name of the Widget
 * 
 * @param v
 *            Widget
 * @return
 */
protected String detectName(View v) {
	String name = "";
	if (v instanceof TextView) {
		TextView t = (TextView) v;
		name = (t.getText() != null) ? t.getText().toString() : "";
		if (v instanceof EditText) {
			CharSequence hint = ((EditText) v).getHint();
			name = (hint == null) ? "" : hint.toString();
		}
	} else if (v instanceof RadioGroup) {
		RadioGroup g = (RadioGroup) v;
		int max = g.getChildCount();
		String text = "";
		for (int i = 0; i < max; i++) {
			View c = g.getChildAt(i);
			text = detectName(c);
			if (!text.equals("")) {
				name = text;
				break;
			}
		}
	}
	return name;
}
 
Example 4
Source File: SearchActivity.java    From Car-Pooling with MIT License 6 votes vote down vote up
/**
 * This method is used to select ride that are available to specific destination in the form of radio buttons
 */
private void displayConfirmation(){

    RadioGroup radioGroup= (RadioGroup) findViewById(R.id.RadioButtonGroup);
    if(radioGroup.getChildCount()>0) {
        RadioButton radioButton = (RadioButton) findViewById(radioGroup.getCheckedRadioButtonId());
        String selectedtext = radioButton.getText().toString();
        Toast.makeText(SearchActivity.this, selectedtext, Toast.LENGTH_SHORT).show();

        //Toast.makeText(SearchActivity.this, text[5], Toast.LENGTH_SHORT).show();
        Intent myIntent = new Intent(this, RideConfirmation.class);
        myIntent.putExtra("RideDetails",selectedtext);
        myIntent.putExtra("PickupLocation",address);
        startActivityForResult(myIntent, 0);
        finish();

    }
    else
    {
        Toast.makeText(SearchActivity.this, "No Rides available to book.. Please try again", Toast.LENGTH_SHORT).show();
    }

}
 
Example 5
Source File: ZhiHuAdapter.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
    for (int i = 0; i < radioGroup.getChildCount(); i++) {
        if (radioGroup.getChildAt(i).getId() == checkId) {
            //  即将要展示的Fragment
            Fragment target = mFragmentList.get(i);
            Fragment currentFragment = getCurrentFragment();
            currentFragment.onPause();

            FragmentTransaction fragmentTransaction = getFragmentTransaction();
            if (target.isAdded()) {
                target.onResume();
                fragmentTransaction.show(target).hide(currentFragment);

            } else {
                fragmentTransaction.add(mContentId, target).show(target).hide(currentFragment);
            }
            fragmentTransaction.commit();
            currentTab = i;

            if (mFragmentToogleListener != null) {
                mFragmentToogleListener.onToogleChange(target, currentTab);
            }

        }
    }

}
 
Example 6
Source File: MainDiscoveryFragment.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
private void setTabsBackground(@NonNull RadioGroup options) {
    final int childCount = options.getChildCount();
    for (int i = 0; i < childCount; i++) {
        if (i == 0) {
            options.getChildAt(i).setBackgroundResource(R.drawable.edx_segmented_control_left_background);
        } else if (i == childCount - 1) {
            options.getChildAt(i).setBackgroundResource(R.drawable.edx_segmented_control_right_background);
        } else {
            options.getChildAt(i).setBackgroundResource(R.drawable.edx_segmented_control_middle_background);
        }
    }
}
 
Example 7
Source File: MainActivity.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
private void init() {
    mFm = getSupportFragmentManager();
    mNavigationBar = (RadioGroup) findViewById(R.id.navigation);

    int size = (int) getResources().getDimension(R.dimen.navigation_top_icon_size);
    for (int i = 0, count = mNavigationBar.getChildCount(); i < count; i++) {
        RadioButton rb = (RadioButton) mNavigationBar.getChildAt(i);
        Drawable topIcon = getResources().getDrawable(R.drawable.selector_navigation_bg);
        topIcon.setBounds(0, 0, size, size);
        rb.setCompoundDrawables(null, topIcon, null, null);
        rb.setId(i);
    }
    mNavigationBar.setOnCheckedChangeListener(this);
    ((RadioButton) mNavigationBar.getChildAt(0)).setChecked(true);
}
 
Example 8
Source File: CustomDrawableDemo.java    From support with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_drawable_layout);
    final int color = 0xff35b558;
    int strokeWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2f, getResources().getDisplayMetrics());
    int corner = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5f, getResources().getDisplayMetrics());


    SegmentDrawable drawable1 = new SegmentDrawable(SegmentDrawable.Style.LEFT_EDGE);
    drawable1.setStrokeWidth(strokeWidth);
    drawable1.setColor(color);
    drawable1.setCornerRadius(corner);
    findViewById(R.id.label).setBackgroundDrawable(drawable1);

    SegmentDrawable drawable2 = new SegmentDrawable(SegmentDrawable.Style.MIDDLE);
    drawable2.setStrokeWidth(strokeWidth);
    drawable2.setColor(color);
    drawable2.setCornerRadius(corner);

    findViewById(R.id.label2).setBackgroundDrawable(drawable2);

    SegmentDrawable drawable3 = new SegmentDrawable(SegmentDrawable.Style.RIGHT_EDGE);
    drawable3.setStrokeWidth(strokeWidth);
    drawable3.setColor(color);
    drawable3.setCornerRadius(corner);

    findViewById(R.id.label3).setBackgroundDrawable(drawable3);

    RadioGroup group = (RadioGroup) findViewById(R.id.container);
    int count = group.getChildCount();

    for (int i = 0; i < count; i++) {
        RadioButton child = (RadioButton) group.getChildAt(i);

        SegmentDrawable drawable;
        if (i == 0) {
            drawable = new SegmentDrawable(SegmentDrawable.Style.LEFT_EDGE);
            child.setChecked(true);
        } else if (i == count - 1) {
            drawable = new SegmentDrawable(SegmentDrawable.Style.RIGHT_EDGE);
        } else {
            drawable = new SegmentDrawable(SegmentDrawable.Style.MIDDLE);
        }
        drawable.setColor(color);
        drawable.setStrokeWidth(strokeWidth);
        drawable.setCornerRadius(corner);

        child.setButtonDrawable(null);
        child.setBackgroundDrawable(drawable.newStateListDrawable());
    }
}
 
Example 9
Source File: AppViewActivity.java    From smartcard-reader with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_app_view);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    // persistent data in shared prefs
    SharedPreferences ss = getSharedPreferences("prefs", Context.MODE_PRIVATE);
    mEditor = ss.edit();

    mSelectedAppPos = ss.getInt("selected_app_pos", 0);

    Gson gson = new Gson();
    String json = ss.getString("groups", null);
    if (json == null) {
        mUserGroups = new LinkedHashSet<>();
    } else {
        Type collectionType = new TypeToken<LinkedHashSet<String>>() {
        }.getType();
        mUserGroups = gson.fromJson(json, collectionType);
    }

    // alphabetize, case insensitive
    mSortedAllGroups = new ArrayList<>(mUserGroups);
    mSortedAllGroups.addAll(Arrays.asList(DEFAULT_GROUPS));
    Collections.sort(mSortedAllGroups, String.CASE_INSENSITIVE_ORDER);

    // when deleting an app results in an empty group, we remove the group;
    // we may need to adjust group position indices for batch select and app
    // browse activities, which apply to the sorted list of groups
    mSelectedGrpPos = ss.getInt("selected_grp_pos", 0);
    mSelectedGrpName = mSortedAllGroups.get(mSelectedGrpPos);
    mExpandedGrpPos = ss.getInt("expanded_grp_pos", -1);
    mExpandedGrpName = (mExpandedGrpPos == -1) ? "" : mSortedAllGroups.get(mExpandedGrpPos);

    Intent intent = getIntent();
    mAppPos = intent.getIntExtra(EXTRA_APP_POS, 0);

    mName = (EditText) findViewById(R.id.app_name);
    mAid = (EditText) findViewById(R.id.app_aid);
    mType = (RadioGroup) findViewById(R.id.radio_grp_type);
    mNote = (TextView) findViewById(R.id.note);
    mGroups = (TextView) findViewById(R.id.group_list);

    // view only
    mName.setFocusable(false);
    mAid.setFocusable(false);
    for (int i = 0; i < mType.getChildCount(); i++) {
        mType.getChildAt(i).setClickable(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window w = getWindow();
        w.setFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
                WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
                        WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        w.setStatusBarColor(getResources().getColor(R.color.primary_dark));
    }
}
 
Example 10
Source File: SketchPropertiesFragment.java    From APDE with GNU General Public License v2.0 4 votes vote down vote up
public void rebuildIconChange() {
	//Original image
	final ImageView bigIcon = changeIconLayout.findViewById(R.id.big_icon);
	//Image after cropping and scaling
	final ImageView smallIcon = changeIconLayout.findViewById(R.id.small_icon);
	
	//Alt text for the big icon
	final TextView bigIconAltText = changeIconLayout.findViewById(R.id.big_icon_alt_text);
	
	//Scale format radio group
	final RadioGroup scaleFormat = changeIconLayout.findViewById(R.id.format_scale);
	
	Bitmap bitmap = loadBitmap();
	
	if (bitmap != null) {
		int w = bitmap.getWidth();
		int h = bitmap.getHeight();
		
		int dim = changeIconLayout.getWidth();
		
		if (w > dim || h > dim) {
			//Resize the bitmap to fit the dialog
			
			if (Math.min(w, h) == w) {
				int scaleW = Math.round(w / (((float) h) / dim));
				
				bigIcon.setImageBitmap(Bitmap.createScaledBitmap(bitmap, scaleW, dim, false));
			} else {
				int scaleH = Math.round(h / (((float) w) / dim));
				
				bigIcon.setImageBitmap(Bitmap.createScaledBitmap(bitmap, dim, scaleH, false));
			}
		} else {
			bigIcon.setImageBitmap(bitmap);
		}
		
		int iconSize = Math.round(36 * getResources().getDisplayMetrics().density);
		
		smallIcon.setImageBitmap(formatIcon(bitmap, iconSize, getScaleFormat(scaleFormat)));
		
		bigIcon.setVisibility(View.VISIBLE);
		bigIconAltText.setVisibility(View.GONE);
		
		changeIconOK.setEnabled(true);
		for (int i = 0; i < scaleFormat.getChildCount(); i++) {
			((RadioButton) scaleFormat.getChildAt(i)).setEnabled(true);
		}
		
		return;
	}
	
	//If we were unable to load the image...
	
	bigIcon.setImageBitmap(null);
	
	//Load the old icon for the current sketch
	
	File sketchFolder = getGlobalState().getSketchLocation();
	String[] iconTitles = com.calsignlabs.apde.build.Build.ICON_LIST;
	
	String iconPath = "";
	
	for (String iconTitle : iconTitles) {
		File icon = new File(sketchFolder, iconTitle);
		
		if (icon.exists()) {
			iconPath = icon.getAbsolutePath();
			break;
		}
	}
	
	if (!iconPath.equals("")) {
		Bitmap oldIcon = BitmapFactory.decodeFile(iconPath);
		
		if (oldIcon != null) {
			smallIcon.setImageBitmap(oldIcon);
		} else {
			//Uh-oh, some error occurred...
		}
	} else {
		smallIcon.setImageDrawable(getResources().getDrawable(R.drawable.default_icon));
	}
	
	bigIcon.setVisibility(View.GONE);
	bigIconAltText.setVisibility(View.VISIBLE);
	
	changeIconOK.setEnabled(false);
	for (int i = 0; i < scaleFormat.getChildCount(); i ++) {
		((RadioButton) scaleFormat.getChildAt(i)).setEnabled(false);
	}
}