Custom emoji picker
This commit is contained in:
parent
eb15a19413
commit
d76783d291
|
@ -47,6 +47,7 @@ import android.text.InputFilter;
|
|||
import android.text.InputType;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -63,6 +64,7 @@ import android.widget.CheckBox;
|
|||
import android.widget.CompoundButton;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.GridView;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
@ -120,8 +122,10 @@ import fr.gouv.etalab.mastodon.client.Entities.Mention;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.StoredStatus;
|
||||
import fr.gouv.etalab.mastodon.drawers.CustomEmojiAdapter;
|
||||
import fr.gouv.etalab.mastodon.drawers.EmojisSearchAdapter;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
|
||||
import fr.gouv.etalab.mastodon.sqlite.CustomEmojiDAO;
|
||||
import fr.gouv.etalab.mastodon.translation.Translate;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Version;
|
||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
|
@ -188,6 +192,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
private Account accountReply;
|
||||
private View popup_trans;
|
||||
private AlertDialog dialogTrans;
|
||||
private AlertDialog alertDialogEmoji;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -862,6 +867,41 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
}
|
||||
});
|
||||
picker.show(getSupportFragmentManager(), "COUNTRY_PICKER");
|
||||
return true;
|
||||
case R.id.action_emoji:
|
||||
final List<Emojis> emojis = new CustomEmojiDAO(getApplicationContext(), db).getAllEmojis();
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
int paddingPixel = 15;
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
int paddingDp = (int)(paddingPixel * density);
|
||||
builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setTitle(R.string.insert_emoji);
|
||||
if( emojis != null && emojis.size() > 0) {
|
||||
GridView gridView = new GridView(TootActivity.this);
|
||||
gridView.setAdapter(new CustomEmojiAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, emojis));
|
||||
gridView.setNumColumns(5);
|
||||
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
toot_content.getText().insert(toot_content.getSelectionStart(), " :" + emojis.get(position).getShortcode()+": ");
|
||||
alertDialogEmoji.dismiss();
|
||||
}
|
||||
});
|
||||
gridView.setPadding(paddingDp,paddingDp,paddingDp,paddingDp);
|
||||
builder.setView(gridView);
|
||||
}else{
|
||||
TextView textView = new TextView(TootActivity.this);
|
||||
textView.setText(getString(R.string.no_emoji));
|
||||
textView.setPadding(paddingDp,paddingDp,paddingDp,paddingDp);
|
||||
builder.setView(textView);
|
||||
}
|
||||
alertDialogEmoji = builder.show();
|
||||
|
||||
|
||||
return true;
|
||||
case R.id.action_microphone:
|
||||
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
||||
|
@ -1059,6 +1099,16 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
if( itemViewReply != null)
|
||||
itemViewReply.setVisible(false);
|
||||
}
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION, null);
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
Version minVersion = new Version("2.0");
|
||||
MenuItem itemEmoji = menu.findItem(R.id.action_emoji);
|
||||
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||
itemEmoji.setVisible(true);
|
||||
}else{
|
||||
itemEmoji.setVisible(false);
|
||||
}
|
||||
if( accountReply != null){
|
||||
MenuItem itemRestore = menu.findItem(R.id.action_restore);
|
||||
if( itemRestore != null)
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
package fr.gouv.etalab.mastodon.drawers;
|
||||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Mastalab 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 Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 03/11/2017.
|
||||
* Adapter to display custom emojis
|
||||
*/
|
||||
public class CustomEmojiAdapter extends ArrayAdapter {
|
||||
|
||||
|
||||
private Context context;
|
||||
private List<Emojis> emojis;
|
||||
private CustomEmojiAdapter customEmojiAdapter;
|
||||
|
||||
public CustomEmojiAdapter(@NonNull Context context, int resource, List<Emojis> emojis) {
|
||||
super(context, resource, resource);
|
||||
this.context = context;
|
||||
this.emojis = emojis;
|
||||
customEmojiAdapter = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return emojis.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Emojis getItem(int position) {
|
||||
return emojis.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
|
||||
final ImageView imageView;
|
||||
Emojis emoji = emojis.get(position);
|
||||
if (convertView == null) {
|
||||
imageView = new ImageView(context);
|
||||
float density = context.getResources().getDisplayMetrics().density;
|
||||
imageView.setLayoutParams(new GridView.LayoutParams((int)(30*density), (int)(30*density)));
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
imageView.setPadding((int)(2*density), (int)(5*density), (int)(2*density), (int)(5*density));
|
||||
} else {
|
||||
imageView = (ImageView) convertView;
|
||||
}
|
||||
ImageLoader imageLoader = ImageLoader.getInstance();
|
||||
File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name));
|
||||
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context)
|
||||
.imageDownloader(new PatchBaseImageDownloader(context))
|
||||
.threadPoolSize(5)
|
||||
.threadPriority(Thread.MIN_PRIORITY + 3)
|
||||
.denyCacheImageMultipleSizesInMemory()
|
||||
.diskCache(new UnlimitedDiskCache(cacheDir))
|
||||
.build();
|
||||
DisplayImageOptions optionNew = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
if( !imageLoader.isInited())
|
||||
imageLoader.init(configImg);
|
||||
imageLoader.loadImage(emoji.getUrl(), optionNew, new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
super.onLoadingComplete(imageUri, view, loadedImage);
|
||||
BitmapDrawable icon = new BitmapDrawable(context.getResources(), loadedImage);
|
||||
imageView.setImageDrawable(icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
}
|
||||
});
|
||||
return imageView;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM15.5,11c0.83,0 1.5,-0.67 1.5,-1.5S16.33,8 15.5,8 14,8.67 14,9.5s0.67,1.5 1.5,1.5zM8.5,11c0.83,0 1.5,-0.67 1.5,-1.5S9.33,8 8.5,8 7,8.67 7,9.5 7.67,11 8.5,11zM12,17.5c2.33,0 4.31,-1.46 5.11,-3.5L6.89,14c0.8,2.04 2.78,3.5 5.11,3.5z"/>
|
||||
</vector>
|
|
@ -6,6 +6,11 @@
|
|||
android:title="@string/show_reply"
|
||||
android:icon="@drawable/ic_visibility"
|
||||
app:showAsAction="always" />
|
||||
<item
|
||||
android:id="@+id/action_emoji"
|
||||
android:title="@string/insert_emoji"
|
||||
android:icon="@drawable/ic_insert_emoticon"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_microphone"
|
||||
android:title="@string/microphone"
|
||||
|
|
|
@ -430,4 +430,6 @@
|
|||
<string name="translate">Translate</string>
|
||||
<string name="please_wait">Please, wait few seconds before making this action.</string>
|
||||
<string name="disclaimer_full">Das Profil wird möglicherweise unvollständig wiedergegeben.</string>
|
||||
<string name="insert_emoji">Emoji einfügen</string>
|
||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||
</resources>
|
||||
|
|
|
@ -437,4 +437,6 @@
|
|||
<string name="translate">Traduire</string>
|
||||
<string name="please_wait">Veuillez patienter quelques secondes avant de faire cette action.</string>
|
||||
<string name="disclaimer_full">Les données ci-dessous peuvent ne pas refléter ce profil dans sa totalité.</string>
|
||||
<string name="insert_emoji">Insérer un émoji</string>
|
||||
<string name="no_emoji">L\'application n\'a pas encore collecté d\'emojis personnalisés</string>
|
||||
</resources>
|
|
@ -434,4 +434,6 @@
|
|||
<string name="translate">Translate</string>
|
||||
<string name="please_wait">Please, wait few seconds before making this action.</string>
|
||||
<string name="disclaimer_full">De informatie hieronder kan mogelijk een incompleet beeld geven van dit gebruikersprofiel.</string>
|
||||
<string name="insert_emoji">Emoji toevoegen</string>
|
||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||
</resources>
|
||||
|
|
|
@ -436,4 +436,6 @@
|
|||
<string name="translate">Translate</string>
|
||||
<string name="please_wait">Please, wait few seconds before making this action.</string>
|
||||
<string name="disclaimer_full">Information below may reflect the user\'s profile incompletely.</string>
|
||||
<string name="insert_emoji">Inserir Emoji</string>
|
||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||
</resources>
|
||||
|
|
|
@ -94,6 +94,8 @@
|
|||
<string name="failed">Failed!</string>
|
||||
<string name="scheduled_toots">Scheduled toots</string>
|
||||
<string name="disclaimer_full">Information below may reflect the user\'s profile incompletely.</string>
|
||||
<string name="insert_emoji">Insert emoji</string>
|
||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||
<!-- Status -->
|
||||
<string name="no_status">No toot to display</string>
|
||||
<string name="fav_added">The toot was added to favourites</string>
|
||||
|
|
Loading…
Reference in New Issue