use of android.support.annotation.DrawableRes in project Osmand by osmandapp.
the class CoordinateInputDialogFragment method setupKeyboardItems.
private void setupKeyboardItems(View keyboardView, View.OnClickListener listener, @IdRes int... itemsIds) {
@DrawableRes int itemBg = lightTheme ? R.drawable.keyboard_item_light_bg : R.drawable.keyboard_item_dark_bg;
@DrawableRes int controlItemBg = lightTheme ? R.drawable.keyboard_item_control_light_bg : R.drawable.keyboard_item_control_dark_bg;
ColorStateList clearItemTextColorStateList = AndroidUtils.createColorStateList(getContext(), R.color.keyboard_item_divider_control_color_light, R.color.keyboard_item_divider_control_color_light_pressed);
ColorStateList numberColorStateList = AndroidUtils.createColorStateList(getContext(), R.color.keyboard_item_text_color_light, R.color.keyboard_item_text_color_light_pressed);
@ColorInt int textColorDark = getResolvedColor(R.color.keyboard_item_text_color_dark);
for (@IdRes int id : itemsIds) {
View itemView = keyboardView.findViewById(id);
Object item = getItemObjectById(id);
final boolean controlItem = id == R.id.keyboard_item_next_field || id == R.id.keyboard_item_backspace;
itemView.setBackgroundResource(controlItem ? controlItemBg : itemBg);
itemView.setOnClickListener(listener);
View itemTopSpace = itemView.findViewById(R.id.keyboard_item_top_spacing);
View itemBottomSpace = itemView.findViewById(R.id.keyboard_item_bottom_spacing);
TextView itemTv = (TextView) itemView.findViewById(R.id.keyboard_item_text);
ImageView itemIv = (ImageView) itemView.findViewById(R.id.keyboard_item_image);
if (item instanceof String) {
boolean clearItem = id == R.id.keyboard_item_clear;
if (clearItem) {
TextViewCompat.setAutoSizeTextTypeWithDefaults(itemTv, TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE);
itemTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.default_list_text_size));
} else {
TextViewCompat.setAutoSizeTextTypeWithDefaults(itemTv, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
}
if (lightTheme) {
itemTv.setTextColor(clearItem ? clearItemTextColorStateList : numberColorStateList);
} else {
itemTv.setTextColor(clearItem ? getResolvedColor(R.color.keyboard_item_divider_control_color_dark) : textColorDark);
}
itemTopSpace.setVisibility(View.VISIBLE);
itemTv.setVisibility(View.VISIBLE);
itemTv.setText((String) item);
itemIv.setVisibility(View.GONE);
itemBottomSpace.setVisibility(View.VISIBLE);
} else if (item instanceof Integer) {
itemTopSpace.setVisibility(View.GONE);
itemTv.setVisibility(View.GONE);
itemIv.setVisibility(View.VISIBLE);
itemBottomSpace.setVisibility(View.GONE);
Drawable icon;
if (lightTheme) {
icon = DrawableCompat.wrap(getResources().getDrawable((Integer) item));
DrawableCompat.setTintList(icon, numberColorStateList);
} else {
icon = getColoredIcon((Integer) item, R.color.keyboard_item_divider_control_color_dark);
}
itemIv.setImageDrawable(icon);
}
}
}
use of android.support.annotation.DrawableRes in project buglife-android by Buglife.
the class ScreenshotAnnotatorActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screenshot_annotator);
mAnnotationView = (AnnotationView) findViewById(R.id.annotation_view);
Intent intent = getIntent();
intent.setExtrasClassLoader(FileAttachment.class.getClassLoader());
mAttachment = intent.getParcelableExtra(INTENT_KEY_ATTACHMENT);
intent.setExtrasClassLoader(BugContext.class.getClassLoader());
mBugContext = intent.getParcelableExtra(INTENT_KEY_BUG_CONTEXT);
File file = mAttachment.getFile();
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
mAnnotationView.setImage(bitmap);
mColorPalette = new ColorPalette.Builder(this).build();
// Annotation tools
mAnnotationToolbar = findViewById(R.id.annotation_toolbar);
mAnnotationToolbar.setBackgroundColor(mColorPalette.getColorPrimary());
mArrowTool = (ImageButton) findViewById(R.id.arrow_tool);
mLoupeTool = (ImageButton) findViewById(R.id.loupe_tool);
mBlurTool = (ImageButton) findViewById(R.id.blur_tool);
mArrowTool.setColorFilter(getToolColorFilter());
mLoupeTool.setColorFilter(getToolColorFilter());
mBlurTool.setColorFilter(getToolColorFilter());
mArrowTool.setOnClickListener(mToolClickListener);
mLoupeTool.setOnClickListener(mToolClickListener);
mBlurTool.setOnClickListener(mToolClickListener);
setSelectedTool(Annotation.Type.ARROW);
mAnnotationView.setAnnotation(Annotation.newArrowInstance());
mAnnotationView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
setToolbarsHidden(true);
break;
case MotionEvent.ACTION_UP:
setToolbarsHidden(false);
break;
}
// Must return false in order for event to propagate down
return false;
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
int colorPrimary = mColorPalette.getColorPrimary();
int titleTextColor = mColorPalette.getTextColorPrimary();
@DrawableRes final int homeAsUpIndicatorDrawableId;
@StringRes final int titleStringId;
if (isInitialScreenshotAnnotationActivity()) {
// If this is the initial screenshot activity, show a different title
// along with close + next buttons
homeAsUpIndicatorDrawableId = android.R.drawable.ic_menu_close_clear_cancel;
titleStringId = R.string.report_a_bug;
} else {
// Otherwise, this is a child activity of ReportActivity
homeAsUpIndicatorDrawableId = R.drawable.buglife_abc_ic_ab_back_mtrl_am_alpha;
titleStringId = R.string.screenshot_annotator_activity_label;
}
Drawable homeAsUpIndicator = ActivityUtils.getTintedDrawable(this, homeAsUpIndicatorDrawableId, mColorPalette.getTextColorPrimary());
CharSequence title = ActivityUtils.getTextWithColor(this, titleTextColor, titleStringId);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(homeAsUpIndicator);
actionBar.setBackgroundDrawable(new ColorDrawable(colorPrimary));
actionBar.setTitle(title);
}
ActivityUtils.setStatusBarColor(this, mColorPalette.getColorPrimaryDark());
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// ClientEventReporter.getInstance(Buglife.getContext()).reportClientEvent("presented_reporter", mBugContext.getApiIdentity());
}
}, 2000);
}
use of android.support.annotation.DrawableRes in project apps-android-wikipedia by wikimedia.
the class NotificationPresenter method showNotification.
public static void showNotification(@NonNull Context context, @NonNull Notification n, @NonNull String wikiSiteName) {
String title;
@DrawableRes int icon = R.drawable.ic_wikipedia_w;
@ColorRes int color = R.color.base30;
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
return;
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = notificationManager.getNotificationChannel(CHANNEL_ID);
if (notificationChannel == null) {
int importance = NotificationManager.IMPORTANCE_HIGH;
notificationChannel = new NotificationChannel(CHANNEL_ID, context.getString(R.string.notification_echo_channel_description), importance);
notificationChannel.setLightColor(ContextCompat.getColor(context, R.color.accent50));
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID).setDefaults(NotificationCompat.DEFAULT_ALL).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true);
title = StringUtil.fromHtml(n.getContents() != null ? n.getContents().getHeader() : "").toString();
if (n.getContents() != null && n.getContents().getLinks() != null && n.getContents().getLinks().getPrimary() != null) {
addAction(context, builder, n.getContents().getLinks().getPrimary(), REQUEST_CODE_ACTION);
}
if (n.getContents() != null && n.getContents().getLinks() != null && n.getContents().getLinks().getSecondary() != null && n.getContents().getLinks().getSecondary().size() > 0) {
addAction(context, builder, n.getContents().getLinks().getSecondary().get(0), REQUEST_CODE_ACTION + 1);
}
if (n.getContents() != null && n.getContents().getLinks() != null && n.getContents().getLinks().getSecondary() != null && n.getContents().getLinks().getSecondary().size() > 1) {
addAction(context, builder, n.getContents().getLinks().getSecondary().get(1), REQUEST_CODE_ACTION + 2);
}
Intent activityIntent = NotificationActivity.newIntent(context);
switch(n.type()) {
case Notification.TYPE_EDIT_USER_TALK:
icon = R.drawable.ic_chat_white_24dp;
color = R.color.accent50;
break;
case Notification.TYPE_REVERTED:
icon = R.drawable.ic_rotate_left_white_24dp;
color = R.color.red50;
builder.setPriority(NotificationCompat.PRIORITY_MAX);
break;
case Notification.TYPE_EDIT_THANK:
icon = R.drawable.ic_usertalk_constructive;
color = R.color.green50;
break;
case Notification.TYPE_EDIT_MILESTONE:
icon = R.drawable.ic_mode_edit_white_24dp;
color = R.color.accent50;
break;
default:
break;
}
builder.setContentIntent(PendingIntent.getActivity(context, REQUEST_CODE_ACTIVITY, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT)).setLargeIcon(drawNotificationBitmap(context, color, icon)).setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.drawable.ic_wikipedia_w : R.mipmap.launcher).setColor(ContextCompat.getColor(context, color)).setContentTitle(wikiSiteName).setContentText(title).setStyle(new NotificationCompat.BigTextStyle().bigText(title));
notificationManager.notify((int) n.key(), builder.build());
}
use of android.support.annotation.DrawableRes in project android-gif-drawable by koral--.
the class GifSelectorDrawable method inflate.
@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme) throws XmlPullParserException, IOException {
final XmlResourceParser resourceParser = (XmlResourceParser) parser;
resourceParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
int eventType = resourceParser.getEventType();
do {
if (eventType == XmlPullParser.START_TAG && "item".equals(resourceParser.getName())) {
@DrawableRes final int resourceId = resourceParser.getAttributeResourceValue(NAMESPACE, "drawable", 0);
final boolean state_pressed = resourceParser.getAttributeBooleanValue(NAMESPACE, "state_pressed", false);
final int[] stateSet = state_pressed ? new int[] { android.R.attr.state_pressed } : new int[0];
addState(stateSet, GifDrawable.createFromResource(r, resourceId));
}
eventType = resourceParser.next();
} while (eventType != XmlPullParser.END_DOCUMENT);
}
use of android.support.annotation.DrawableRes in project instructure-android by instructure.
the class ViewUtilsTest method getAssignmentIconOrder.
@Test
public void getAssignmentIconOrder() throws Exception {
/**
* Tests the order that the icons are retrieved.
* Quizzes, Discussion Topics, Assignment icons in that order
*
* To properly test the order we need to test the method 3 times for each icon type
*/
Assignment assignment = new Assignment();
List<String> types = new ArrayList<>();
@DrawableRes int iconRes = 0;
// Add all other submission types
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.NONE));
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ON_PAPER));
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.EXTERNAL_TOOL));
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_UPLOAD));
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_TEXT_ENTRY));
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_URL));
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.MEDIA_RECORDING));
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ATTENDANCE));
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.NOT_GRADED));
assignment.setSubmissionTypes(types);
iconRes = ViewUtils.getAssignmentIcon(assignment);
assertTrue(iconRes == R.drawable.ic_cv_assignments_fill);
// Add the one we want to test
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.DISCUSSION_TOPIC));
assignment.setSubmissionTypes(types);
iconRes = ViewUtils.getAssignmentIcon(assignment);
assertTrue(iconRes == R.drawable.ic_cv_discussions_fill);
// Add the next one we want to test
types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_QUIZ));
assignment.setSubmissionTypes(types);
iconRes = ViewUtils.getAssignmentIcon(assignment);
assertTrue(iconRes == R.drawable.ic_cv_quizzes_fill);
}
Aggregations