Java Code Examples for androidx.appcompat.app.AppCompatActivity#obtainStyledAttributes()

The following examples show how to use androidx.appcompat.app.AppCompatActivity#obtainStyledAttributes() . 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: MotionSpecTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void loadFromAttributes() {
  AppCompatActivity context = activityTestRule.getActivity();

  TypedArray attributes =
      context.obtainStyledAttributes(null, R.styleable.Test, 0, R.style.Widget_Test);

  MotionSpec spec1 =
      MotionSpec.createFromAttribute(context, attributes, R.styleable.Test_motionSpec);
  MotionSpec spec2 =
      MotionSpec.createFromResource(context, R.animator.valid_set_of_object_animator_motion_spec);
  assertEquals(spec1, spec2);
}
 
Example 2
Source File: PropertiesDialog.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public final Dialog onCreateDialog(final Bundle savedInstanceState) {
	super.onCreateDialog(savedInstanceState);

	if(alreadyCreated) return getDialog();
	alreadyCreated = true;

	final AppCompatActivity context = (AppCompatActivity)getActivity();

	final TypedArray attr = context.obtainStyledAttributes(new int[] {
			R.attr.rrListHeaderTextCol,
			R.attr.rrListDividerCol,
			R.attr.rrMainTextCol
	});

	rrListHeaderTextCol = attr.getColor(0, 0);
	rrListDividerCol = attr.getColor(1, 0);
	rrCommentBodyCol = attr.getColor(2, 0);

	attr.recycle();

	final AlertDialog.Builder builder = new AlertDialog.Builder(context);

	final LinearLayout items = new LinearLayout(context);
	items.setOrientation(LinearLayout.VERTICAL);

	prepare(context, items);
	builder.setTitle(getTitle(context));

	final ScrollView sv = new ScrollView(context);
	sv.addView(items);
	builder.setView(sv);

	builder.setNeutralButton(R.string.dialog_close, null);

	return builder.create();
}
 
Example 3
Source File: RedditPreparedMessage.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
public RedditPreparedMessage(
		@NonNull final AppCompatActivity activity,
		@NonNull final RedditMessage message,
		final long timestamp) {

	final Context applicationContext = activity.getApplicationContext();

	this.src = message;

	// TODO custom time
	// TODO respect RRTheme

	final int rrCommentHeaderBoldCol;
	final int rrCommentHeaderAuthorCol;

	{
		final TypedArray appearance = activity.obtainStyledAttributes(new int[]{
				R.attr.rrCommentHeaderBoldCol,
				R.attr.rrCommentHeaderAuthorCol,
		});

		rrCommentHeaderBoldCol = appearance.getColor(0, 255);
		rrCommentHeaderAuthorCol = appearance.getColor(1, 255);

		appearance.recycle();
	}

	body = HtmlReader.parse(message.getUnescapedBodyHtml(), activity);

	idAndType = message.name;

	final BetterSSB sb = new BetterSSB();

	if(src.author == null) {
		sb.append("[" + applicationContext.getString(R.string.general_unknown) + "]", BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f);
	} else {
		sb.append(src.author, BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f);
	}

	sb.append("   ", 0);
	sb.append(RRTime.formatDurationFrom(applicationContext, src.created_utc * 1000L), BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderBoldCol, 0, 1f);

	header = sb.get();
}