mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 09:02:19 +00:00
committed by
Moxie Marlinspike
parent
a4e18c515c
commit
4185006147
@@ -28,22 +28,17 @@ public class Dialogs {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
||||
dialog.setTitle(title);
|
||||
dialog.setMessage(message);
|
||||
dialog.setIcon(resolveIcon(context, R.attr.dialog_alert_icon));
|
||||
dialog.setPositiveButton(android.R.string.ok, null);
|
||||
dialog.show();
|
||||
}
|
||||
public static void showInfoDialog(Context context, String title, String message) {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
||||
dialog.setTitle(title);
|
||||
dialog.setMessage(message);
|
||||
dialog.setIcon(resolveIcon(context, R.attr.dialog_info_icon));
|
||||
dialog.setIcon(ResUtil.getDrawable(context, R.attr.dialog_alert_icon));
|
||||
dialog.setPositiveButton(android.R.string.ok, null);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public static Drawable resolveIcon(Context c, int iconAttr) {
|
||||
TypedValue out = new TypedValue();
|
||||
c.getTheme().resolveAttribute(iconAttr, out, true);
|
||||
return c.getResources().getDrawable(out.resourceId);
|
||||
public static void showInfoDialog(Context context, String title, String message) {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
||||
dialog.setTitle(title);
|
||||
dialog.setMessage(message);
|
||||
dialog.setIcon(ResUtil.getDrawable(context, R.attr.dialog_info_icon));
|
||||
dialog.setPositiveButton(android.R.string.ok, null);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,16 @@ public class ListenableFutureTask<V> extends FutureTask<V> {
|
||||
super(callable);
|
||||
}
|
||||
|
||||
public ListenableFutureTask(final V result) {
|
||||
super(new Callable<V>() {
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
return result;
|
||||
}
|
||||
});
|
||||
this.run();
|
||||
}
|
||||
|
||||
public synchronized void addListener(FutureTaskListener<V> listener) {
|
||||
if (this.isDone()) {
|
||||
callback(listener);
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -50,6 +51,22 @@ public class MediaUtil {
|
||||
return data;
|
||||
}
|
||||
|
||||
public static Bitmap getOrGenerateThumbnail(Context context, MasterSecret masterSecret, PduPart part)
|
||||
throws IOException, BitmapDecodingException
|
||||
{
|
||||
if (part.getDataUri() != null && part.getId() > -1) {
|
||||
return BitmapFactory.decodeStream(DatabaseFactory.getPartDatabase(context)
|
||||
.getThumbnailStream(masterSecret, part.getId()));
|
||||
} else if (part.getDataUri() != null) {
|
||||
Log.w(TAG, "generating thumbnail for new part");
|
||||
Bitmap bitmap = MediaUtil.generateThumbnail(context, masterSecret, part.getDataUri(), Util.toIsoString(part.getContentType())).getBitmap();
|
||||
part.setThumbnail(bitmap);
|
||||
return bitmap;
|
||||
} else {
|
||||
throw new FileNotFoundException("no data location specified");
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getPartData(Context context, MasterSecret masterSecret, PduPart part)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
@@ -18,14 +18,27 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.AttrRes;
|
||||
import android.util.TypedValue;
|
||||
|
||||
public class ThemeUtil {
|
||||
public static Drawable resolveIcon(Context c, int iconAttr)
|
||||
{
|
||||
TypedValue out = new TypedValue();
|
||||
c.getTheme().resolveAttribute(iconAttr, out, true);
|
||||
return c.getResources().getDrawable(out.resourceId);
|
||||
public class ResUtil {
|
||||
|
||||
public static int getColor(Context context, @AttrRes int attr) {
|
||||
final TypedArray styledAttributes = context.obtainStyledAttributes(new int[]{attr});
|
||||
final int result = styledAttributes.getColor(0, -1);
|
||||
styledAttributes.recycle();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int getDrawableRes(Context c, @AttrRes int attr) {
|
||||
final TypedValue out = new TypedValue();
|
||||
c.getTheme().resolveAttribute(attr, out, true);
|
||||
return out.resourceId;
|
||||
}
|
||||
|
||||
public static Drawable getDrawable(Context c, @AttrRes int attr) {
|
||||
return c.getResources().getDrawable(getDrawableRes(c, attr));
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTa
|
||||
public static void showWarningDialog(Context context, OnClickListener onAcceptListener) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(R.string.ConversationFragment_save_to_sd_card);
|
||||
builder.setIcon(Dialogs.resolveIcon(context, R.attr.dialog_alert_icon));
|
||||
builder.setIcon(ResUtil.getDrawable(context, R.attr.dialog_alert_icon));
|
||||
builder.setCancelable(true);
|
||||
builder.setMessage(R.string.ConversationFragment_this_media_has_been_stored_in_an_encrypted_database_warning);
|
||||
builder.setPositiveButton(R.string.yes, onAcceptListener);
|
||||
|
||||
41
src/org/thoughtcrime/securesms/util/ViewUtil.java
Normal file
41
src/org/thoughtcrime/securesms/util/ViewUtil.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.view.View;
|
||||
|
||||
public class ViewUtil {
|
||||
public static void setBackgroundSavingPadding(View v, Drawable drawable) {
|
||||
final int paddingBottom = v.getPaddingBottom();
|
||||
final int paddingLeft = v.getPaddingLeft();
|
||||
final int paddingRight = v.getPaddingRight();
|
||||
final int paddingTop = v.getPaddingTop();
|
||||
v.setBackgroundDrawable(drawable);
|
||||
v.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
||||
}
|
||||
|
||||
public static void setBackgroundSavingPadding(View v, @DrawableRes int resId) {
|
||||
final int paddingBottom = v.getPaddingBottom();
|
||||
final int paddingLeft = v.getPaddingLeft();
|
||||
final int paddingRight = v.getPaddingRight();
|
||||
final int paddingTop = v.getPaddingTop();
|
||||
v.setBackgroundResource(resId);
|
||||
v.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user