fixed media preview for file types other than images

This commit is contained in:
Daniel Gultsch 2018-09-12 14:37:41 +02:00
parent 0f81ae39b8
commit 00c062a0c8
55 changed files with 94 additions and 84 deletions

View File

@ -842,7 +842,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
case ATTACHMENT_CHOICE_CHOOSE_FILE: case ATTACHMENT_CHOICE_CHOOSE_FILE:
case ATTACHMENT_CHOICE_RECORD_VIDEO: case ATTACHMENT_CHOICE_RECORD_VIDEO:
case ATTACHMENT_CHOICE_RECORD_VOICE: case ATTACHMENT_CHOICE_RECORD_VOICE:
final List<Attachment> fileUris = Attachment.extractAttachments(getActivity(), data, Attachment.Type.FILE); final Attachment.Type type = requestCode == ATTACHMENT_CHOICE_RECORD_VOICE ? Attachment.Type.RECORDING : Attachment.Type.FILE;
final List<Attachment> fileUris = Attachment.extractAttachments(getActivity(), data, type);
mediaPreviewAdapter.addMediaPreviews(fileUris); mediaPreviewAdapter.addMediaPreviews(fileUris);
toggleInputMethod(); toggleInputMethod();
break; break;
@ -850,7 +851,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
double latitude = data.getDoubleExtra("latitude", 0); double latitude = data.getDoubleExtra("latitude", 0);
double longitude = data.getDoubleExtra("longitude", 0); double longitude = data.getDoubleExtra("longitude", 0);
Uri geo = Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude)); Uri geo = Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude));
attachLocationToConversation(conversation, geo); mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), geo, Attachment.Type.LOCATION));
toggleInputMethod();
break; break;
case REQUEST_INVITE_TO_CONVERSATION: case REQUEST_INVITE_TO_CONVERSATION:
XmppActivity.ConferenceInvite invite = XmppActivity.ConferenceInvite.parse(data); XmppActivity.ConferenceInvite invite = XmppActivity.ConferenceInvite.parse(data);
@ -869,7 +871,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final PresenceSelector.OnPresenceSelected callback = () -> { final PresenceSelector.OnPresenceSelected callback = () -> {
for (Iterator<Attachment> i = attachments.iterator(); i.hasNext(); i.remove()) { for (Iterator<Attachment> i = attachments.iterator(); i.hasNext(); i.remove()) {
final Attachment attachment = i.next(); final Attachment attachment = i.next();
if (attachment.getType() == Attachment.Type.IMAGE) { if (attachment.getType() == Attachment.Type.LOCATION) {
attachLocationToConversation(conversation, attachment.getUri());
} else if (attachment.getType() == Attachment.Type.IMAGE) {
Log.d(Config.LOGTAG, "ConversationsActivity.commitAttachments() - attaching image to conversations. CHOOSE_IMAGE"); Log.d(Config.LOGTAG, "ConversationsActivity.commitAttachments() - attaching image to conversations. CHOOSE_IMAGE");
attachImageToConversation(conversation, attachment.getUri()); attachImageToConversation(conversation, attachment.getUri());
} else { } else {

View File

@ -58,11 +58,11 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.ui.interfaces.OnConversationArchived; import eu.siacs.conversations.ui.interfaces.OnConversationArchived;
import eu.siacs.conversations.ui.interfaces.OnConversationSelected; import eu.siacs.conversations.ui.interfaces.OnConversationSelected;
import eu.siacs.conversations.ui.util.Color;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.PendingActionHelper; import eu.siacs.conversations.ui.util.PendingActionHelper;
import eu.siacs.conversations.ui.util.PendingItem; import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.ui.util.ScrollState; import eu.siacs.conversations.ui.util.ScrollState;
import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.utils.ThemeHelper; import eu.siacs.conversations.utils.ThemeHelper;
import static android.support.v7.widget.helper.ItemTouchHelper.LEFT; import static android.support.v7.widget.helper.ItemTouchHelper.LEFT;
@ -99,7 +99,7 @@ public class ConversationsOverviewFragment extends XmppFragment {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
if(actionState != ItemTouchHelper.ACTION_STATE_IDLE){ if(actionState != ItemTouchHelper.ACTION_STATE_IDLE){
Paint paint = new Paint(); Paint paint = new Paint();
paint.setColor(Color.get(activity,R.attr.conversations_overview_background)); paint.setColor(StyledAttributes.getColor(activity,R.attr.conversations_overview_background));
paint.setStyle(Paint.Style.FILL); paint.setStyle(Paint.Style.FILL);
c.drawRect(viewHolder.itemView.getLeft(),viewHolder.itemView.getTop() c.drawRect(viewHolder.itemView.getLeft(),viewHolder.itemView.getTop()
,viewHolder.itemView.getRight(),viewHolder.itemView.getBottom(), paint); ,viewHolder.itemView.getRight(),viewHolder.itemView.getBottom(), paint);

View File

@ -35,7 +35,6 @@ import android.support.v7.widget.Toolbar;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -47,21 +46,18 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivitySearchBinding; import eu.siacs.conversations.databinding.ActivitySearchBinding;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.StubConversation;
import eu.siacs.conversations.services.MessageSearchTask; import eu.siacs.conversations.services.MessageSearchTask;
import eu.siacs.conversations.ui.adapter.MessageAdapter; import eu.siacs.conversations.ui.adapter.MessageAdapter;
import eu.siacs.conversations.ui.interfaces.OnSearchResultsAvailable; import eu.siacs.conversations.ui.interfaces.OnSearchResultsAvailable;
import eu.siacs.conversations.ui.util.ChangeWatcher; import eu.siacs.conversations.ui.util.ChangeWatcher;
import eu.siacs.conversations.ui.util.Color;
import eu.siacs.conversations.ui.util.DateSeparator; import eu.siacs.conversations.ui.util.DateSeparator;
import eu.siacs.conversations.ui.util.Drawable; import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.ui.util.ListViewUtils; import eu.siacs.conversations.ui.util.ListViewUtils;
import eu.siacs.conversations.ui.util.PendingItem; import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.ui.util.ShareUtil; import eu.siacs.conversations.ui.util.ShareUtil;
@ -217,12 +213,12 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
private void changeBackground(boolean hasSearch, boolean hasResults) { private void changeBackground(boolean hasSearch, boolean hasResults) {
if (hasSearch) { if (hasSearch) {
if (hasResults) { if (hasResults) {
binding.searchResults.setBackgroundColor(Color.get(this, R.attr.color_background_secondary)); binding.searchResults.setBackgroundColor(StyledAttributes.getColor(this, R.attr.color_background_secondary));
} else { } else {
binding.searchResults.setBackground(Drawable.get(this, R.attr.activity_background_no_results)); binding.searchResults.setBackground(StyledAttributes.getDrawable(this, R.attr.activity_background_no_results));
} }
} else { } else {
binding.searchResults.setBackground(Drawable.get(this, R.attr.activity_background_search)); binding.searchResults.setBackground(StyledAttributes.getDrawable(this, R.attr.activity_background_search));
} }
} }

View File

@ -38,7 +38,7 @@ import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.ExportLogsService; import eu.siacs.conversations.services.ExportLogsService;
import eu.siacs.conversations.services.MemorizingTrustManager; import eu.siacs.conversations.services.MemorizingTrustManager;
import eu.siacs.conversations.ui.util.Color; import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.TimeframeUtils; import eu.siacs.conversations.utils.TimeframeUtils;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
@ -74,7 +74,7 @@ public class SettingsActivity extends XmppActivity implements
mSettingsFragment.setActivityIntent(getIntent()); mSettingsFragment.setActivityIntent(getIntent());
this.mTheme = findTheme(); this.mTheme = findTheme();
setTheme(this.mTheme); setTheme(this.mTheme);
getWindow().getDecorView().setBackgroundColor(Color.get(this, R.attr.color_background_primary)); getWindow().getDecorView().setBackgroundColor(StyledAttributes.getColor(this, R.attr.color_background_primary));
setSupportActionBar(findViewById(R.id.toolbar)); setSupportActionBar(findViewById(R.id.toolbar));
configureActionBar(getSupportActionBar()); configureActionBar(getSupportActionBar());
} }

View File

@ -25,7 +25,7 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.ManageAccountActivity; import eu.siacs.conversations.ui.ManageAccountActivity;
import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.util.Color; import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
public class AccountAdapter extends ArrayAdapter<Account> { public class AccountAdapter extends ArrayAdapter<Account> {
@ -65,14 +65,14 @@ public class AccountAdapter extends ArrayAdapter<Account> {
statusView.setText(getContext().getString(account.getStatus().getReadableId())); statusView.setText(getContext().getString(account.getStatus().getReadableId()));
switch (account.getStatus()) { switch (account.getStatus()) {
case ONLINE: case ONLINE:
statusView.setTextColor(Color.get(activity, R.attr.TextColorOnline)); statusView.setTextColor(StyledAttributes.getColor(activity, R.attr.TextColorOnline));
break; break;
case DISABLED: case DISABLED:
case CONNECTING: case CONNECTING:
statusView.setTextColor(Color.get(activity, android.R.attr.textColorSecondary)); statusView.setTextColor(StyledAttributes.getColor(activity, android.R.attr.textColorSecondary));
break; break;
default: default:
statusView.setTextColor(Color.get(activity, R.attr.TextColorError)); statusView.setTextColor(StyledAttributes.getColor(activity, R.attr.TextColorError));
break; break;
} }
final SwitchCompat tglAccountState = view.findViewById(R.id.tgl_account_status); final SwitchCompat tglAccountState = view.findViewById(R.id.tgl_account_status);

View File

@ -26,9 +26,8 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.Transferable; import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.ui.ConversationFragment; import eu.siacs.conversations.ui.ConversationFragment;
import eu.siacs.conversations.ui.ConversationsOverviewFragment;
import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.util.Color; import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.ui.widget.UnreadCountCustomView; import eu.siacs.conversations.ui.widget.UnreadCountCustomView;
import eu.siacs.conversations.utils.EmojiWrapper; import eu.siacs.conversations.utils.EmojiWrapper;
import eu.siacs.conversations.utils.IrregularUnicodeDetector; import eu.siacs.conversations.utils.IrregularUnicodeDetector;
@ -93,9 +92,9 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationAdapte
} }
if (conversation == ConversationFragment.getConversation(activity)) { if (conversation == ConversationFragment.getConversation(activity)) {
viewHolder.frame.setBackgroundColor(Color.get(activity,R.attr.color_background_tertiary)); viewHolder.frame.setBackgroundColor(StyledAttributes.getColor(activity,R.attr.color_background_tertiary));
} else { } else {
viewHolder.frame.setBackgroundColor(Color.get(activity,R.attr.color_background_primary)); viewHolder.frame.setBackgroundColor(StyledAttributes.getColor(activity,R.attr.color_background_primary));
} }
Message message = conversation.getLatestMessage(); Message message = conversation.getLatestMessage();

View File

@ -1,17 +1,17 @@
package eu.siacs.conversations.ui.adapter; package eu.siacs.conversations.ui.adapter;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
@ -22,11 +22,10 @@ import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.MediaPreviewBinding; import eu.siacs.conversations.databinding.MediaPreviewBinding;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.ui.ConversationFragment; import eu.siacs.conversations.ui.ConversationFragment;
import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.util.Attachment; import eu.siacs.conversations.ui.util.Attachment;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.ui.util.StyledAttributes;
public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapter.MediaPreviewViewHolder> { public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapter.MediaPreviewViewHolder> {
@ -48,8 +47,29 @@ public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapte
@Override @Override
public void onBindViewHolder(@NonNull MediaPreviewViewHolder holder, int position) { public void onBindViewHolder(@NonNull MediaPreviewViewHolder holder, int position) {
final Context context = conversationFragment.getActivity();
final Attachment attachment = mediaPreviews.get(position); final Attachment attachment = mediaPreviews.get(position);
if (attachment.renderThumbnail()) {
holder.binding.mediaPreview.setImageAlpha(255);
loadPreview(attachment, holder.binding.mediaPreview); loadPreview(attachment, holder.binding.mediaPreview);
} else {
cancelPotentialWork(attachment, holder.binding.mediaPreview);
holder.binding.mediaPreview.setBackgroundColor(StyledAttributes.getColor(context, R.attr.color_background_tertiary));
holder.binding.mediaPreview.setImageAlpha(Math.round(StyledAttributes.getFloat(context, R.attr.icon_alpha) * 255));
final @AttrRes int attr;
if (attachment.getType() == Attachment.Type.LOCATION) {
attr = R.attr.media_preview_location;
} else if (attachment.getType() == Attachment.Type.RECORDING) {
attr = R.attr.media_preview_recording;
} else {
if (attachment.getMime() != null && attachment.getMime().startsWith("audio/")) {
attr = R.attr.media_preview_audio;
} else {
attr = R.attr.media_preview_file;
}
}
holder.binding.mediaPreview.setImageDrawable(StyledAttributes.getDrawable(context, attr));
}
holder.binding.deleteButton.setOnClickListener(v -> { holder.binding.deleteButton.setOnClickListener(v -> {
int pos = mediaPreviews.indexOf(attachment); int pos = mediaPreviews.indexOf(attachment);
mediaPreviews.remove(pos); mediaPreviews.remove(pos);
@ -72,6 +92,7 @@ public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapte
imageView.setImageBitmap(bm); imageView.setImageBitmap(bm);
imageView.setBackgroundColor(0x00000000); imageView.setBackgroundColor(0x00000000);
} else { } else {
imageView.setBackgroundColor(0xff333333);
imageView.setImageDrawable(null); imageView.setImageDrawable(null);
final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
final AsyncDrawable asyncDrawable = new AsyncDrawable(conversationFragment.getActivity().getResources(), null, task); final AsyncDrawable asyncDrawable = new AsyncDrawable(conversationFragment.getActivity().getResources(), null, task);

View File

@ -10,7 +10,7 @@ import android.view.View;
import java.util.List; import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.util.Color; import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.xmpp.forms.Field; import eu.siacs.conversations.xmpp.forms.Field;
public abstract class FormFieldWrapper { public abstract class FormFieldWrapper {
@ -18,9 +18,9 @@ public abstract class FormFieldWrapper {
protected final Context context; protected final Context context;
protected final Field field; protected final Field field;
protected final View view; protected final View view;
protected OnFormFieldValuesEdited onFormFieldValuesEditedListener; OnFormFieldValuesEdited onFormFieldValuesEditedListener;
protected FormFieldWrapper(Context context, Field field) { FormFieldWrapper(Context context, Field field) {
this.context = context; this.context = context;
this.field = field; this.field = field;
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@ -58,7 +58,7 @@ public abstract class FormFieldWrapper {
int start = label.length(); int start = label.length();
int end = label.length() + 2; int end = label.length() + 2;
spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, 0); spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, 0);
spannableString.setSpan(new ForegroundColorSpan(Color.get(context,R.attr.colorAccent)), start, end, 0); spannableString.setSpan(new ForegroundColorSpan(StyledAttributes.getColor(context,R.attr.colorAccent)), start, end, 0);
} }
return spannableString; return spannableString;
} }

View File

@ -42,6 +42,7 @@ import java.util.UUID;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.MimeUtils; import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class Attachment { public class Attachment {
@ -54,7 +55,7 @@ public class Attachment {
} }
public enum Type { public enum Type {
FILE, IMAGE FILE, IMAGE, LOCATION, RECORDING
} }
private final Uri uri; private final Uri uri;
@ -70,7 +71,7 @@ public class Attachment {
} }
public static List<Attachment> of(final Context context, Uri uri, Type type) { public static List<Attachment> of(final Context context, Uri uri, Type type) {
final String mime = MimeUtils.guessMimeTypeFromUri(context, uri); final String mime = type == Type.LOCATION ?null :MimeUtils.guessMimeTypeFromUri(context, uri);
return Collections.singletonList(new Attachment(uri, type, mime)); return Collections.singletonList(new Attachment(uri, type, mime));
} }
@ -100,6 +101,10 @@ public class Attachment {
return uris; return uris;
} }
public boolean renderThumbnail() {
return type == Type.IMAGE || (type == Type.FILE && mime != null && (mime.startsWith("video/") || mime.startsWith("image/")));
}
public Uri getUri() { public Uri getUri() {
return uri; return uri;
} }

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2018, Daniel Gultsch All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package eu.siacs.conversations.ui.util;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.AttrRes;
public class Drawable {
public static android.graphics.drawable.Drawable get(Context context, @AttrRes int id) {
TypedArray typedArray = context.obtainStyledAttributes(new int[]{id});
android.graphics.drawable.Drawable drawable = typedArray.getDrawable(0);
typedArray.recycle();
return drawable;
}
}

View File

@ -29,19 +29,30 @@
package eu.siacs.conversations.ui.util; package eu.siacs.conversations.ui.util;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.support.annotation.AttrRes; import android.support.annotation.AttrRes;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
public class Color { public class StyledAttributes {
public static android.graphics.drawable.Drawable getDrawable(Context context, @AttrRes int id) {
TypedArray typedArray = context.obtainStyledAttributes(new int[]{id});
android.graphics.drawable.Drawable drawable = typedArray.getDrawable(0);
typedArray.recycle();
return drawable;
}
public static @ColorInt int get(Context context, @AttrRes int attr) { public static float getFloat(Context context, @AttrRes int id) {
TypedArray typedArray = context.obtainStyledAttributes(new int[]{id});
float value = typedArray.getFloat(0,0f);
typedArray.recycle();
return value;
}
public static @ColorInt int getColor(Context context, @AttrRes int attr) {
TypedArray typedArray = context.obtainStyledAttributes(new int[]{attr}); TypedArray typedArray = context.obtainStyledAttributes(new int[]{attr});
int color = typedArray.getColor(0,0); int color = typedArray.getColor(0,0);
typedArray.recycle(); typedArray.recycle();
return color; return color;
} }
} }

View File

@ -50,7 +50,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.util.Color; import eu.siacs.conversations.ui.util.StyledAttributes;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public class IrregularUnicodeDetector { public class IrregularUnicodeDetector {
@ -73,7 +73,7 @@ public class IrregularUnicodeDetector {
} }
public static Spannable style(Context context, Jid jid) { public static Spannable style(Context context, Jid jid) {
return style(jid, Color.get(context, R.attr.color_warning)); return style(jid, StyledAttributes.getColor(context, R.attr.color_warning));
} }
private static Spannable style(Jid jid, @ColorInt int color) { private static Spannable style(Jid jid, @ColorInt int color) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 683 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 819 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 869 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -9,6 +9,7 @@
android:layout_height="@dimen/media_preview_size" android:layout_height="@dimen/media_preview_size"
android:background="@color/black54" android:background="@color/black54"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:scaleType="center"
android:layout_margin="12dp"/> android:layout_margin="12dp"/>
<ImageButton <ImageButton
android:id="@+id/delete_button" android:id="@+id/delete_button"

View File

@ -52,6 +52,12 @@
<attr name="icon_alpha" format="float"/> <attr name="icon_alpha" format="float"/>
<attr name="delete_icon_alpha" format="float"/> <attr name="delete_icon_alpha" format="float"/>
<attr name="media_preview_file" format="reference"/>
<attr name="media_preview_recording" format="reference"/>
<attr name="media_preview_audio" format="reference"/>
<attr name="media_preview_location" format="reference"/>
<attr name="icon_add_group" format="reference"/> <attr name="icon_add_group" format="reference"/>
<attr name="icon_add_person" format="reference"/> <attr name="icon_add_person" format="reference"/>
<attr name="icon_cancel" format="reference"/> <attr name="icon_cancel" format="reference"/>

View File

@ -63,6 +63,11 @@
<item name="dialog_horizontal_padding">24dp</item> <item name="dialog_horizontal_padding">24dp</item>
<item name="dialog_vertical_padding">16dp</item> <item name="dialog_vertical_padding">16dp</item>
<item type="reference" name="media_preview_file">@drawable/ic_description_black_48dp</item>
<item type="reference" name="media_preview_recording">@drawable/ic_mic_black_48dp</item>
<item type="reference" name="media_preview_audio">@drawable/ic_headset_black_48dp</item>
<item type="reference" name="media_preview_location">@drawable/ic_room_black_48dp</item>
<item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item> <item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item>
<item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item> <item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item>
<item type="reference" name="icon_cancel">@drawable/ic_cancel_black_24dp</item> <item type="reference" name="icon_cancel">@drawable/ic_cancel_black_24dp</item>
@ -164,6 +169,11 @@
<item name="dialog_horizontal_padding">24dp</item> <item name="dialog_horizontal_padding">24dp</item>
<item name="dialog_vertical_padding">16dp</item> <item name="dialog_vertical_padding">16dp</item>
<item type="reference" name="media_preview_file">@drawable/ic_description_white_48dp</item>
<item type="reference" name="media_preview_recording">@drawable/ic_mic_white_48dp</item>
<item type="reference" name="media_preview_audio">@drawable/ic_headset_white_48dp</item>
<item type="reference" name="media_preview_location">@drawable/ic_room_white_48dp</item>
<item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item> <item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item>
<item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item> <item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item>
<item type="reference" name="icon_cancel">@drawable/ic_cancel_white_24dp</item> <item type="reference" name="icon_cancel">@drawable/ic_cancel_white_24dp</item>