Remove bitmap from entry class

This commit is contained in:
RichyHBM 2017-11-26 11:50:44 +00:00
parent 8258b972e1
commit 91db03bc47
10 changed files with 74 additions and 88 deletions

View file

@ -209,10 +209,6 @@ public class MainActivity extends BaseActivity
int digits = Integer.parseInt(digitsInput.getText().toString());
Entry e = new Entry(type, secret, period, digits, label, algorithm, tagsAdapter.getActiveTags());
int size = getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size);
e.setThumbnailImage(EntryThumbnail.getThumbnailGraphic(MainActivity.this, label, size, e.getThumbnail()));
e.updateOTP();
adapter.addEntry(e);
adapter.saveEntries();
@ -459,10 +455,6 @@ public class MainActivity extends BaseActivity
if(result.getContents() != null) {
try {
Entry e = new Entry(result.getContents());
int size = getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size);
e.setThumbnailImage(EntryThumbnail.getThumbnailGraphic(MainActivity.this, e.getLabel(), size, e.getThumbnail()));
e.updateOTP();
adapter.addEntry(e);
adapter.saveEntries();

View file

@ -66,7 +66,6 @@ public class Entry {
private long last_update = 0;
public List<String> tags = new ArrayList<>();
private EntryThumbnail.EntryThumbnails thumbnail = EntryThumbnail.EntryThumbnails.Default;
private Bitmap thumbnailImage;
public Entry(){}
@ -239,10 +238,6 @@ public class Entry {
public void setTags(List<String> tags) { this.tags = tags; }
public Bitmap getThumbnailImage() { return thumbnailImage; }
public void setThumbnailImage(Bitmap thumbnailImage) { this.thumbnailImage = thumbnailImage; }
public EntryThumbnail.EntryThumbnails getThumbnail() { return thumbnail; }
public void setThumbnail( EntryThumbnail.EntryThumbnails value) { thumbnail = value; }

View file

@ -98,10 +98,6 @@ public class DatabaseHelper {
for (int i = 0; i < json.length(); i++) {
Entry entry = new Entry(json.getJSONObject(i));
int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size);
entry.setThumbnailImage(EntryThumbnail.getThumbnailGraphic(context, entry.getLabel(), size, entry.getThumbnail()));
entries.add(entry);
}
} catch (Exception error) {

View file

@ -5,15 +5,9 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PictureDrawable;
import com.larvalabs.svgandroid.SVG;
import com.larvalabs.svgandroid.SVGBuilder;
import org.shadowice.flocke.andotp.R;
import java.io.IOException;
public class EntryThumbnail {
public enum EntryThumbnails {
Default(R.mipmap.ic_launcher_round),
@ -38,9 +32,9 @@ public class EntryThumbnail {
try {
Drawable drawable = context.getResources().getDrawable(thumbnail.getResource());
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Bitmap bitmap = Bitmap.createBitmap(drawable.getMinimumWidth(), drawable.getMinimumHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
drawable.draw(canvas);
return bitmap;
} catch(Exception e) {

View file

@ -37,12 +37,14 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
@ -160,7 +162,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
public void onBindViewHolder(EntryViewHolder entryViewHolder, int i) {
Entry entry = displayedEntries.get(i);
entryViewHolder.updateValues(entry.getLabel(), entry.getCurrentOTP(), entry.getTags(), entry.getThumbnailImage());
entryViewHolder.updateValues(entry.getLabel(), entry.getCurrentOTP(), entry.getTags(), entry.getThumbnail());
if (entry.hasNonDefaultPeriod()) {
entryViewHolder.showCustomPeriod(entry.getPeriod());
@ -261,7 +263,6 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
Entry e = entries.get(realIndex);
e.setLabel(newLabel);
e.setThumbnailImage(EntryThumbnail.getThumbnailGraphic(context, e.getLabel(), size, e.getThumbnail()));
DatabaseHelper.saveDatabase(context, entries);
}
@ -280,42 +281,49 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
int marginSmall = context.getResources().getDimensionPixelSize(R.dimen.activity_margin_small);
int marginMedium = context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium);
ListView list = new ListView(context);
list.setAdapter(new ThumbnailSelectionAdapter(context));
list.setDividerHeight(0);
GridView grid = new GridView(context);
grid.setAdapter(new ThumbnailSelectionAdapter(context));
grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
grid.setColumnWidth(context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size));
grid.setNumColumns(GridView.AUTO_FIT);
grid.setVerticalSpacing(context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium));
grid.setHorizontalSpacing(context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium));
grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
FrameLayout container = new FrameLayout(context);
container.setPaddingRelative(marginMedium, marginSmall, marginMedium, 0);
container.addView(grid);
final AlertDialog alert = builder.setTitle(R.string.menu_popup_change_image)
.setView(container)
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {}
})
.create();
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int realIndex = getRealIndex(pos);
TextView v = (TextView) view.findViewById(R.id.thumbnail_selection_text);
EntryThumbnail.EntryThumbnails thumbnail = EntryThumbnail.EntryThumbnails.Default;
try {
thumbnail = EntryThumbnail.EntryThumbnails.valueOf(v.getText().toString());
thumbnail = EntryThumbnail.EntryThumbnails.values()[position];
} catch (Exception e) {
e.printStackTrace();
}
int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size);
Entry e = entries.get(realIndex);
e.setThumbnailImage(EntryThumbnail.getThumbnailGraphic(context, e.getLabel(), size, thumbnail));
e.setThumbnail(thumbnail);
DatabaseHelper.saveDatabase(context, entries);
notifyItemChanged(pos);
alert.cancel();
}
});
FrameLayout container = new FrameLayout(context);
container.setPaddingRelative(marginMedium, marginSmall, marginMedium, 0);
container.addView(list);
builder.setTitle(R.string.menu_popup_change_image)
.setView(container)
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {}
})
.create()
.show();
alert.show();
}

View file

@ -36,6 +36,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import org.shadowice.flocke.andotp.R;
import org.shadowice.flocke.andotp.Utilities.EntryThumbnail;
import org.shadowice.flocke.andotp.Utilities.Settings;
import org.shadowice.flocke.andotp.Utilities.Tools;
import org.shadowice.flocke.andotp.View.ItemTouchHelper.ItemTouchHelperViewHolder;
@ -106,7 +107,7 @@ public class EntryViewHolder extends RecyclerView.ViewHolder
});
}
public void updateValues(String label, String token, List<String> tags, Bitmap thumbnail) {
public void updateValues(String label, String token, List<String> tags, EntryThumbnail.EntryThumbnails thumbnail) {
Settings settings = new Settings(context);
this.label.setText(label);
@ -128,7 +129,9 @@ public class EntryViewHolder extends RecyclerView.ViewHolder
}
thumbnailImg.setVisibility(settings.getThumbnailVisible() ? View.VISIBLE : View.GONE);
thumbnailImg.setImageBitmap(thumbnail);
int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size);
thumbnailImg.setImageBitmap(EntryThumbnail.getThumbnailGraphic(context, label, size, thumbnail));
}
public void showCustomPeriod(int period) {

View file

@ -6,6 +6,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
@ -14,37 +16,46 @@ import org.shadowice.flocke.andotp.Utilities.EntryThumbnail;
import java.util.ArrayList;
public class ThumbnailSelectionAdapter extends ArrayAdapter<EntryThumbnail.EntryThumbnails> {
public class ThumbnailSelectionAdapter extends BaseAdapter {
private Context context;
public ThumbnailSelectionAdapter(Context context) {
super(context, R.layout.component_thumbnail_selection, new ArrayList<EntryThumbnail.EntryThumbnails>());
ThumbnailSelectionAdapter(Context context) {
this.context = context;
for (EntryThumbnail.EntryThumbnails thumb : EntryThumbnail.EntryThumbnails.values()) {
add(thumb);
}
@Override
public int getCount() {
return EntryThumbnail.EntryThumbnails.values().length;
}
@Override
public Object getItem(int i) {
if(i >= EntryThumbnail.EntryThumbnails.values().length)
return EntryThumbnail.EntryThumbnails.Default;
else
return EntryThumbnail.EntryThumbnails.values()[i];
}
@Override
public long getItemId(int i) {
return EntryThumbnail.EntryThumbnails.values()[i].ordinal();
}
@NonNull
@Override
public View getView(int i, View view, @NonNull ViewGroup viewGroup) {
View newView;
int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size);
ImageView imageView;
if (view == null) {
newView = LayoutInflater.from(context).inflate(R.layout.component_thumbnail_selection , viewGroup, false);
} else{
newView = view;
imageView = new ImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(size, size));
} else {
imageView = (ImageView) view;
}
ImageView imageView = (ImageView) newView.findViewById(R.id.thumbnail_selection_icon);
TextView textView = (TextView) newView.findViewById(R.id.thumbnail_selection_text);
EntryThumbnail.EntryThumbnails thumb = (EntryThumbnail.EntryThumbnails)getItem(i);
EntryThumbnail.EntryThumbnails thumb = getItem(i);
int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size);
imageView.setImageBitmap(EntryThumbnail.getThumbnailGraphic(context, thumb.name(), size, thumb));
textView.setText(thumb.name());
return newView;
return imageView;
}
}

View file

@ -1,4 +1,9 @@
<vector android:height="24dp" android:viewportHeight="250.0"
android:viewportWidth="256.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#161614" android:pathData="M128,0C57.32,0 0,57.31 0,128C0,184.56 36.68,232.54 87.53,249.46C93.93,250.65 96.28,246.68 96.28,243.3C96.28,240.25 96.16,230.17 96.11,219.47C60.5,227.22 52.98,204.37 52.98,204.37C47.16,189.57 38.77,185.64 38.77,185.64C27.16,177.7 39.65,177.86 39.65,177.86C52.5,178.76 59.27,191.05 59.27,191.05C70.68,210.62 89.21,204.96 96.52,201.69C97.66,193.42 100.98,187.77 104.64,184.57C76.21,181.34 46.32,170.36 46.32,121.32C46.32,107.34 51.33,95.92 59.51,86.96C58.18,83.73 53.8,70.72 60.75,53.08C60.75,53.08 71.5,49.64 95.96,66.2C106.17,63.37 117.12,61.95 128,61.9C138.88,61.95 149.84,63.37 160.07,66.2C184.5,49.64 195.23,53.08 195.23,53.08C202.2,70.72 197.82,83.73 196.49,86.96C204.69,95.92 209.66,107.34 209.66,121.32C209.66,170.48 179.72,181.3 151.21,184.47C155.8,188.44 159.9,196.23 159.9,208.18C159.9,225.3 159.75,239.09 159.75,243.3C159.75,246.71 162.05,250.7 168.54,249.44C219.37,232.5 256,184.54 256,128C256,57.31 198.69,0 128,0ZM47.94,182.34C47.66,182.98 46.66,183.17 45.75,182.73C44.82,182.31 44.3,181.45 44.6,180.81C44.87,180.15 45.88,179.97 46.8,180.41C47.73,180.83 48.26,181.7 47.94,182.34ZM54.24,187.96C53.63,188.52 52.43,188.26 51.62,187.37C50.79,186.47 50.63,185.28 51.25,184.71C51.88,184.14 53.03,184.41 53.87,185.3C54.71,186.2 54.87,187.39 54.24,187.96ZM58.56,195.15C57.77,195.69 56.49,195.18 55.7,194.04C54.91,192.9 54.91,191.54 55.71,190.99C56.51,190.44 57.77,190.94 58.58,192.07C59.36,193.22 59.36,194.59 58.56,195.15ZM65.86,203.47C65.16,204.24 63.67,204.04 62.57,202.98C61.45,201.95 61.14,200.48 61.84,199.71C62.55,198.94 64.06,199.15 65.16,200.2C66.27,201.23 66.61,202.71 65.86,203.47ZM75.3,206.28C74.99,207.28 73.55,207.74 72.1,207.31C70.66,206.88 69.71,205.7 70,204.69C70.3,203.68 71.75,203.2 73.21,203.66C74.65,204.1 75.6,205.26 75.3,206.28ZM86.05,207.47C86.08,208.53 84.85,209.4 83.33,209.42C81.8,209.46 80.56,208.6 80.55,207.56C80.55,206.5 81.75,205.63 83.28,205.61C84.8,205.58 86.05,206.42 86.05,207.47ZM96.6,207.07C96.78,208.1 95.73,209.16 94.22,209.44C92.73,209.71 91.35,209.07 91.17,208.05C90.98,207 92.06,205.94 93.54,205.67C95.05,205.4 96.41,206.02 96.6,207.07Z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="139dp"
android:viewportWidth="512.0"
android:viewportHeight="139.0">
<path
android:pathData="M98.7,59.31L55.64,59.31C54.52,59.31 53.62,60.22 53.62,61.33L53.62,82.38C53.62,83.49 54.52,84.39 55.64,84.39L72.43,84.39L72.43,110.55C72.43,110.55 68.66,111.84 58.23,111.84C45.93,111.84 28.74,107.34 28.74,69.55C28.74,31.75 46.64,26.78 63.44,26.78C77.99,26.78 84.25,29.34 88.24,30.57C89.49,30.95 90.65,29.71 90.65,28.6L95.45,8.25C95.45,7.73 95.28,7.11 94.68,6.68C93.06,5.53 83.19,-0 58.23,-0C29.49,-0 0,12.23 0,71.02C0,129.82 33.76,138.58 62.21,138.58C85.76,138.58 100.05,128.51 100.05,128.51C100.64,128.19 100.71,127.36 100.71,126.99L100.71,61.33C100.71,60.22 99.81,59.31 98.7,59.31ZM320.5,7.36C320.5,6.24 319.61,5.34 318.5,5.34L294.25,5.34C293.14,5.34 292.24,6.24 292.24,7.36C292.24,7.36 292.25,54.22 292.25,54.22L254.46,54.22L254.46,7.36C254.46,6.24 253.56,5.34 252.46,5.34L228.21,5.34C227.11,5.34 226.21,6.24 226.21,7.36L226.21,134.23C226.21,135.35 227.11,136.26 228.21,136.26L252.46,136.26C253.56,136.26 254.46,135.35 254.46,134.23L254.46,79.96L292.25,79.96C292.25,79.96 292.18,134.23 292.18,134.23C292.18,135.35 293.08,136.26 294.19,136.26L318.49,136.26C319.61,136.26 320.49,135.35 320.5,134.23L320.5,7.36ZM144.37,24.32C144.37,15.59 137.37,8.54 128.74,8.54C120.11,8.54 113.1,15.59 113.1,24.32C113.1,33.04 120.11,40.12 128.74,40.12C137.37,40.12 144.37,33.04 144.37,24.32ZM142.45,107.53L142.45,48.97C142.45,47.86 141.55,46.95 140.44,46.95L116.27,46.95C115.16,46.95 114.17,48.09 114.17,49.2L114.17,133.11C114.17,135.58 115.71,136.31 117.7,136.31L139.47,136.31C141.86,136.31 142.45,135.14 142.45,133.07L142.45,107.53ZM413.16,46.95L389.1,46.95C388,46.95 387.1,47.86 387.1,48.98L387.1,111.19C387.1,111.19 380.99,115.66 372.31,115.66C363.64,115.66 361.33,111.72 361.33,103.23L361.33,48.98C361.33,47.86 360.44,46.95 359.33,46.95L334.92,46.95C333.81,46.95 332.91,47.86 332.91,48.98L332.91,107.34C332.91,132.57 346.97,138.74 366.32,138.74C382.19,138.74 394.98,129.97 394.98,129.97C394.98,129.97 395.59,134.59 395.87,135.14C396.14,135.69 396.86,136.24 397.64,136.24L413.17,136.17C414.27,136.17 415.18,135.26 415.18,134.14L415.17,48.98C415.17,47.86 414.27,46.95 413.16,46.95ZM468.6,115.71C460.25,115.45 454.59,111.67 454.59,111.67L454.59,71.49C454.59,71.49 460.18,68.07 467.03,67.45C475.69,66.68 484.04,69.29 484.04,89.96C484.04,111.76 480.27,116.06 468.6,115.71ZM478.09,44.22C464.42,44.22 455.13,50.32 455.13,50.32L455.13,7.36C455.13,6.24 454.23,5.34 453.13,5.34L428.81,5.34C427.71,5.34 426.81,6.24 426.81,7.36L426.81,134.23C426.81,135.35 427.71,136.26 428.82,136.26L445.68,136.26C446.44,136.26 447.02,135.87 447.44,135.18C447.86,134.5 448.47,129.33 448.47,129.33C448.47,129.33 458.41,138.76 477.23,138.76C499.33,138.76 512,127.55 512,88.44C512,49.33 491.76,44.22 478.09,44.22ZM212.23,46.73L194.04,46.73C194.04,46.73 194.01,22.71 194.01,22.7C194.01,21.79 193.55,21.34 192.49,21.34L167.71,21.34C166.75,21.34 166.23,21.76 166.23,22.69L166.23,47.52C166.23,47.52 153.81,50.52 152.97,50.76C152.13,51 151.52,51.77 151.52,52.69L151.52,68.3C151.52,69.42 152.41,70.32 153.52,70.32L166.23,70.32L166.23,107.86C166.23,135.74 185.79,138.48 198.98,138.48C205.01,138.48 212.22,136.54 213.42,136.1C214.14,135.84 214.55,135.09 214.55,134.28L214.57,117.12C214.57,116 213.63,115.09 212.56,115.09C211.5,115.09 208.79,115.53 206,115.53C197.07,115.53 194.04,111.37 194.04,105.99C194.04,100.62 194.04,70.32 194.04,70.32L212.23,70.32C213.34,70.32 214.24,69.42 214.24,68.3L214.24,48.75C214.24,47.63 213.34,46.73 212.23,46.73Z"
android:fillColor="#11110F"/>
</vector>

View file

@ -17,7 +17,7 @@
android:id="@+id/thumbnailImg"
android:layout_width="@dimen/card_thumbnail_size"
android:layout_height="@dimen/card_thumbnail_size"
android:layout_marginEnd="@dimen/activity_margin_small"
android:layout_marginEnd="@dimen/activity_margin"
android:src="@mipmap/ic_launcher"/>
<LinearLayout

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:id="@+id/thumbnail_selection_icon"
android:layout_width="@dimen/card_thumbnail_size"
android:layout_height="@dimen/card_thumbnail_size"
android:layout_marginEnd="@dimen/activity_margin_small"/>
<TextView android:id="@+id/thumbnail_selection_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28sp"
android:layout_gravity="center_vertical" />
</LinearLayout>