mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Allow for customized Background image #50
This commit is contained in:
committed by
Florian Haar
parent
35521f5dfe
commit
a02574dbbb
@@ -324,6 +324,10 @@
|
||||
android:theme="@style/TextSecure.LightNoActionBar"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".preferences.ChatBackgroundDialogFragment"
|
||||
android:theme="@style/TextSecure.LightTheme"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<service android:enabled="true" android:name="org.thoughtcrime.securesms.service.WebRtcCallService"/>
|
||||
<service android:enabled="true" android:exported="false" android:name=".service.KeyCachingService"/>
|
||||
<service android:enabled="true" android:name=".service.MessageRetrievalService"/>
|
||||
|
||||
@@ -1,98 +1,105 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<org.thoughtcrime.securesms.components.InputAwareLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/layout_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer
|
||||
android:id="@+id/quick_attachment_drawer"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="match_parent" android:layout_width="match_parent">
|
||||
<ImageView
|
||||
android:id="@+id/background_imageview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:scaleType="centerCrop"/>
|
||||
<org.thoughtcrime.securesms.components.InputAwareLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/layout_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout android:id="@+id/conversation_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="?attr/actionBarSize"
|
||||
android:gravity="bottom"
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false">
|
||||
<org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer
|
||||
android:id="@+id/quick_attachment_drawer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ViewStub android:id="@+id/group_share_profile_view_stub"
|
||||
android:layout="@layout/conversation_activity_group_share_profile_stub"
|
||||
android:inflatedId="@+id/group_share_profile_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<LinearLayout android:id="@+id/conversation_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="?attr/actionBarSize"
|
||||
android:gravity="bottom"
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false">
|
||||
|
||||
<ViewStub android:id="@+id/unverified_banner_stub"
|
||||
android:layout="@layout/conversation_activity_unverified_banner_stub"
|
||||
android:inflatedId="@+id/unverified_banner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<ViewStub android:id="@+id/group_share_profile_view_stub"
|
||||
android:layout="@layout/conversation_activity_group_share_profile_stub"
|
||||
android:inflatedId="@+id/group_share_profile_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/reminder_stub"
|
||||
android:layout="@layout/conversation_activity_reminderview_stub"
|
||||
android:inflatedId="@+id/reminder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<ViewStub android:id="@+id/unverified_banner_stub"
|
||||
android:layout="@layout/conversation_activity_unverified_banner_stub"
|
||||
android:inflatedId="@+id/unverified_banner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<FrameLayout android:id="@+id/fragment_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
<ViewStub
|
||||
android:id="@+id/reminder_stub"
|
||||
android:layout="@layout/conversation_activity_reminderview_stub"
|
||||
android:inflatedId="@+id/reminder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/attachment_editor_stub"
|
||||
android:inflatedId="@+id/attachment_editor"
|
||||
android:layout="@layout/conversation_activity_attachment_editor_stub"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<FrameLayout android:id="@+id/fragment_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<include layout="@layout/conversation_input_panel"/>
|
||||
<ViewStub
|
||||
android:id="@+id/attachment_editor_stub"
|
||||
android:inflatedId="@+id/attachment_editor"
|
||||
android:layout="@layout/conversation_activity_attachment_editor_stub"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Button android:id="@+id/register_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:text="@string/conversation_activity__enable_signal_messages"
|
||||
android:visibility="gone"/>
|
||||
<include layout="@layout/conversation_input_panel"/>
|
||||
|
||||
<Button android:id="@+id/unblock_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:text="@string/ConversationActivity_unblock"
|
||||
android:visibility="gone"/>
|
||||
<Button android:id="@+id/register_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:text="@string/conversation_activity__enable_signal_messages"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<Button android:id="@+id/make_default_sms_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:text="@string/conversation_activity__enable_signal_for_sms"
|
||||
android:visibility="gone"/>
|
||||
<Button android:id="@+id/unblock_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:text="@string/ConversationActivity_unblock"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView android:id="@+id/space_left"
|
||||
android:paddingLeft="5dip"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:background="?android:windowBackground"
|
||||
android:text="160/160 (1)" />
|
||||
<Button android:id="@+id/make_default_sms_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:text="@string/conversation_activity__enable_signal_for_sms"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView android:id="@+id/space_left"
|
||||
android:paddingLeft="5dip"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:background="?android:windowBackground"
|
||||
android:text="160/160 (1)" />
|
||||
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/emoji_drawer_stub"
|
||||
android:layout="@layout/conversation_activity_emojidrawer_stub"
|
||||
android:inflatedId="@+id/emoji_drawer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<ViewStub
|
||||
android:id="@+id/emoji_drawer_stub"
|
||||
android:layout="@layout/conversation_activity_emojidrawer_stub"
|
||||
android:inflatedId="@+id/emoji_drawer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
</org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer>
|
||||
</org.thoughtcrime.securesms.components.InputAwareLayout>
|
||||
</LinearLayout>
|
||||
</org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer>
|
||||
</org.thoughtcrime.securesms.components.InputAwareLayout>
|
||||
</RelativeLayout>
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/conversation_container"
|
||||
android:id="@+id/conversation_container"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
android:clipToPadding="false"
|
||||
android:background="@color/white">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="0dp"
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="bottom">
|
||||
<Button
|
||||
android:id="@+id/set_default_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="0.5"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Set default"/>
|
||||
<Button
|
||||
android:id="@+id/from_gallery_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="0.5"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="From gallery"/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
@@ -27,6 +27,7 @@ import android.content.res.Configuration;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
@@ -57,6 +58,7 @@ import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@@ -227,6 +229,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
protected HidingLinearLayout quickAttachmentToggle;
|
||||
private QuickAttachmentDrawer quickAttachmentDrawer;
|
||||
private InputPanel inputPanel;
|
||||
private ImageView imageView;
|
||||
|
||||
private Recipient recipient;
|
||||
private ApplicationDcContext dcContext;
|
||||
@@ -997,6 +1000,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
quickAttachmentDrawer = ViewUtil.findById(this, R.id.quick_attachment_drawer);
|
||||
quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle);
|
||||
inputPanel = ViewUtil.findById(this, R.id.bottom_panel);
|
||||
imageView = ViewUtil.findById(this, R.id.background_imageview);
|
||||
|
||||
ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle);
|
||||
|
||||
@@ -1042,6 +1046,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
quickCameraToggle.setVisibility(View.GONE);
|
||||
quickCameraToggle.setEnabled(false);
|
||||
}
|
||||
|
||||
String backgroundImagePath = TextSecurePreferences.getBackgroundImagePath(this);
|
||||
Drawable image = Drawable.createFromPath(backgroundImagePath);
|
||||
imageView.setImageDrawable(image);
|
||||
}
|
||||
|
||||
protected void initializeActionBar() {
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
@@ -41,10 +40,8 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.OnScrollListener;
|
||||
import android.text.ClipboardManager;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -55,25 +52,22 @@ import android.view.Window;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ViewSwitcher;
|
||||
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcEventCenter;
|
||||
import com.b44t.messenger.DcMsg;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
|
||||
import org.thoughtcrime.securesms.ConversationAdapter.HeaderViewHolder;
|
||||
import org.thoughtcrime.securesms.ConversationAdapter.ItemClickListener;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.connect.DcMsgListLoader;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||
import org.thoughtcrime.securesms.contactshare.SharedContactDetailsActivity;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob;
|
||||
@@ -82,12 +76,10 @@ import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
@@ -124,7 +116,6 @@ public class ConversationFragment extends Fragment
|
||||
private RecyclerView.ItemDecoration lastSeenDecoration;
|
||||
private View scrollToBottomButton;
|
||||
private TextView scrollDateHeader;
|
||||
private FrameLayout frameLayout;
|
||||
|
||||
private ApplicationDcContext dcContext;
|
||||
|
||||
@@ -148,7 +139,6 @@ public class ConversationFragment extends Fragment
|
||||
list = ViewUtil.findById(view, android.R.id.list);
|
||||
scrollToBottomButton = ViewUtil.findById(view, R.id.scroll_to_bottom_button);
|
||||
scrollDateHeader = ViewUtil.findById(view, R.id.scroll_date_header);
|
||||
frameLayout = ViewUtil.findById(view, R.id.conversation_container);
|
||||
|
||||
scrollToBottomButton.setOnClickListener(v -> scrollToBottom());
|
||||
|
||||
@@ -163,10 +153,6 @@ public class ConversationFragment extends Fragment
|
||||
{
|
||||
list.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
|
||||
String backgroundImagePath = TextSecurePreferences.getBackgroundImagePath(getContext());
|
||||
Drawable image = Drawable.createFromPath(backgroundImagePath);
|
||||
frameLayout.setBackground(image);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +1,20 @@
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.ExifInterface;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
@@ -33,15 +22,9 @@ import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
@@ -82,51 +65,6 @@ public class AppearancePreferenceFragment extends ListSummaryPreferenceFragment
|
||||
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener((ApplicationPreferencesActivity) getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (data != null && getContext() != null && resultCode == RESULT_OK && requestCode == ApplicationPreferencesActivity.REQUEST_CODE_SET_BACKGROUND) {
|
||||
Uri imageUri = data.getData();
|
||||
if (imageUri != null) {
|
||||
Thread thread = new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Display display = ServiceUtil.getWindowManager(getContext()).getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
Bitmap scaledBitmap = GlideApp.with(getContext())
|
||||
.asBitmap()
|
||||
.load(imageUri)
|
||||
.centerCrop()
|
||||
.skipMemoryCache(true)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.submit(size.x, size.y)
|
||||
.get();
|
||||
String destination = getContext().getFilesDir().getAbsolutePath() + "background";
|
||||
FileOutputStream outStream = new FileOutputStream(destination);
|
||||
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 85, outStream);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
showBackgroundSaveError();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
showBackgroundSaveError();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
showBackgroundSaveError();
|
||||
}
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void showBackgroundSaveError() {
|
||||
Toast.makeText(getActivity(), R.string.AppearancePreferencesFragment_background_save_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public static CharSequence getSummary(Context context) {
|
||||
String[] languageEntries = context.getResources().getStringArray(R.array.language_entries);
|
||||
String[] languageEntryValues = context.getResources().getStringArray(R.array.language_values);
|
||||
@@ -147,11 +85,8 @@ public class AppearancePreferenceFragment extends ListSummaryPreferenceFragment
|
||||
private class BackgroundClickListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("image/*");
|
||||
getActivity().startActivityForResult(intent, ApplicationPreferencesActivity.REQUEST_CODE_SET_BACKGROUND);
|
||||
|
||||
Intent intent = new Intent(getContext(), ChatBackgroundDialogFragment.class);
|
||||
getActivity().startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Display;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.BaseActionBarActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class ChatBackgroundDialogFragment extends BaseActionBarActivity {
|
||||
|
||||
Button galleryButton;
|
||||
Button defaultButton;
|
||||
FrameLayout layoutContainer;
|
||||
MenuItem acceptMenuItem;
|
||||
|
||||
String tempDestinationPath;
|
||||
Uri imageUri;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.select_chat_background_dialog);
|
||||
|
||||
defaultButton = findViewById(R.id.set_default_button);
|
||||
galleryButton = findViewById(R.id.from_gallery_button);
|
||||
layoutContainer = findViewById(R.id.layout_container);
|
||||
|
||||
defaultButton.setOnClickListener(new DefaultClickListener());
|
||||
galleryButton.setOnClickListener(new GalleryClickListener());
|
||||
|
||||
String backgroundImagePath = TextSecurePreferences.getBackgroundImagePath(this);
|
||||
setLayoutBackgroundImage(backgroundImagePath);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = this.getMenuInflater();
|
||||
menu.clear();
|
||||
inflater.inflate(R.menu.group_create, menu);
|
||||
acceptMenuItem = menu.findItem(R.id.menu_create_group);
|
||||
acceptMenuItem.setEnabled(false);
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.menu_create_group) {
|
||||
// handle confirmation button click here
|
||||
Context context = getApplicationContext();
|
||||
if(imageUri != null){
|
||||
Thread thread = new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
String destination = context.getFilesDir().getAbsolutePath() + "/background";
|
||||
scaleAndSaveImage(context, destination);
|
||||
TextSecurePreferences.setBackgroundImagePath(context, destination);
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
}
|
||||
else {
|
||||
TextSecurePreferences.setBackgroundImagePath(context, "");
|
||||
}
|
||||
finish();
|
||||
return true;
|
||||
} else if (id == android.R.id.home) {
|
||||
// handle close button click here
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void scaleAndSaveImage(Context context, String destinationPath) {
|
||||
try{
|
||||
Display display = ServiceUtil.getWindowManager(context).getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
Bitmap scaledBitmap = GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.load(imageUri)
|
||||
.centerCrop()
|
||||
.skipMemoryCache(true)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.submit(size.x, size.y)
|
||||
.get();
|
||||
FileOutputStream outStream = new FileOutputStream(destinationPath);
|
||||
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 85, outStream);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
showBackgroundSaveError();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
showBackgroundSaveError();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
showBackgroundSaveError();
|
||||
}
|
||||
}
|
||||
|
||||
private void setLayoutBackgroundImage(String backgroundImagePath) {
|
||||
Drawable image = Drawable.createFromPath(backgroundImagePath);
|
||||
layoutContainer.setBackground(image);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
final Context context = getApplicationContext();
|
||||
if (data != null && context != null && resultCode == RESULT_OK && requestCode == ApplicationPreferencesActivity.REQUEST_CODE_SET_BACKGROUND) {
|
||||
imageUri = data.getData();
|
||||
if (imageUri != null) {
|
||||
acceptMenuItem.setEnabled(true);
|
||||
Thread thread = new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
tempDestinationPath = context.getFilesDir().getAbsolutePath() + "/background-temp";
|
||||
scaleAndSaveImage(context, tempDestinationPath);
|
||||
runOnUiThread(() -> {
|
||||
// Stuff that updates the UI
|
||||
setLayoutBackgroundImage(tempDestinationPath);
|
||||
});
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showBackgroundSaveError() {
|
||||
Toast.makeText(this, R.string.AppearancePreferencesFragment_background_save_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void enableMenuItem() {
|
||||
acceptMenuItem.setEnabled(true);
|
||||
}
|
||||
private class DefaultClickListener implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
imageUri = null;
|
||||
tempDestinationPath = "";
|
||||
setLayoutBackgroundImage("");
|
||||
enableMenuItem();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class GalleryClickListener implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("image/*");
|
||||
startActivityForResult(intent, ApplicationPreferencesActivity.REQUEST_CODE_SET_BACKGROUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user