Skip to content

Commit

Permalink
Rename private fields in creation
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Sep 26, 2017
1 parent cf192db commit 9443de8
Showing 1 changed file with 59 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
Expand Down Expand Up @@ -86,31 +85,31 @@ public class MemeCreateActivity extends AppCompatActivity
//## UI Binding
//########################
@BindView(R.id.fab)
FloatingActionButton fab;
FloatingActionButton _fab;

@BindView(R.id.toolbar)
Toolbar toolbar;
Toolbar _toolbar;

@BindView(R.id.memecreate__activity__image)
ImageView imageEditView;
ImageView _imageEditView;

@BindView(R.id.memecreate__activity__edit_caption_bottom)
EditText textEditBottomCaption;
EditText _textEditBottomCaption;

@BindView(R.id.memecreate__activity__edit_caption_top)
EditText textEditTopCaption;
EditText _textEditTopCaption;

//#####################
//## Members
//#####################
private static boolean doubleBackToExitPressedOnce = false;
private Bitmap lastBitmap = null;
private long memeSavetime = -1;
private App app;
private static boolean _doubleBackToExitPressedOnce = false;
private Bitmap _lastBitmap = null;
private long _memeSavetime = -1;
private App _app;
private MemeEditorObject _memeEditorObject;
private boolean bFullscreenImage = true;
private Bundle savedInstanceState = null;
boolean moarControlsContainerVisible = false;
private boolean _bFullscreenImage = true;
private Bundle _savedInstanceState = null;
boolean _moarControlsContainerVisible = false;

//#####################
//## Methods
Expand Down Expand Up @@ -139,10 +138,10 @@ protected void onCreate(Bundle savedInstanceState) {

// Bind Ui
ButterKnife.bind(this);
app = (App) getApplication();
_app = (App) getApplication();

// Set _toolbar
setSupportActionBar(toolbar);
setSupportActionBar(_toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Expand All @@ -151,7 +150,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

public void initMemeSettings(Bundle savedInstanceState) {
MemeData.Font lastUsedFont = getFont(app.settings.getLastUsedFont());
MemeData.Font lastUsedFont = getFont(_app.settings.getLastUsedFont());
Bitmap bitmap = extractBitmapFromIntent(getIntent());
if (savedInstanceState != null && savedInstanceState.containsKey("memeObj")) {
_memeEditorObject = (MemeEditorObject) savedInstanceState.getSerializable("memeObj");
Expand All @@ -163,8 +162,8 @@ public void initMemeSettings(Bundle savedInstanceState) {
}
_memeEditorObject.getImageMain().setDisplayImage(_memeEditorObject.getImageMain().getImage().copy(Bitmap.Config.RGB_565, false));

textEditTopCaption.setText(_memeEditorObject.getCaptionTop().getText());
textEditBottomCaption.setText(_memeEditorObject.getCaptionBottom().getText());
_textEditTopCaption.setText(_memeEditorObject.getCaptionTop().getText());
_textEditBottomCaption.setText(_memeEditorObject.getCaptionBottom().getText());
_memeEditorObject.setChangedListener(this);
_memeEditorObject.notifyChangedListener();
}
Expand All @@ -182,23 +181,23 @@ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
prepareForSaving();
outState.putSerializable("memeObj", _memeEditorObject);
this.savedInstanceState = outState;
this._savedInstanceState = outState;
}

private void prepareForSaving() {
if (_memeEditorObject == null) {
return;
}
_memeEditorObject.setChangedListener(null);
imageEditView.setImageBitmap(null);
if (lastBitmap != null && !lastBitmap.isRecycled())
lastBitmap.recycle();
_imageEditView.setImageBitmap(null);
if (_lastBitmap != null && !_lastBitmap.isRecycled())
_lastBitmap.recycle();
MemeEditorObject.MemeElementImage imageMain = _memeEditorObject.getImageMain();
if (imageMain.getImage() != null && !imageMain.getImage().isRecycled())
imageMain.getImage().recycle();
if (imageMain.getDisplayImage() != null && !imageMain.getDisplayImage().isRecycled())
imageMain.getDisplayImage().recycle();
lastBitmap = null;
_lastBitmap = null;
imageMain.setDisplayImage(null);
imageMain.setImage(null);
_memeEditorObject.getCaptionTop().setFont(null);
Expand All @@ -215,12 +214,12 @@ protected void onDestroy() {
@Override
protected void onResume() {
super.onResume();
if (bFullscreenImage) {
bFullscreenImage = false;
if (_bFullscreenImage) {
_bFullscreenImage = false;
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
if (savedInstanceState != null) {
initMemeSettings(savedInstanceState);
if (_savedInstanceState != null) {
initMemeSettings(_savedInstanceState);
}


Expand Down Expand Up @@ -259,7 +258,7 @@ private Bitmap extractBitmapFromIntent(final Intent intent) {
//Scale big images down to avoid "out of memory"
InputStream inputStream = getAssets().open(imagePath);
BitmapFactory.decodeStream(inputStream, new Rect(0, 0, 0, 0), options);
options.inSampleSize = ContextUtils.get().calculateInSampleSize(options, app.settings.getRenderQualityReal());
options.inSampleSize = ContextUtils.get().calculateInSampleSize(options, _app.settings.getRenderQualityReal());
options.inJustDecodeBounds = false;
inputStream.close();
inputStream = getAssets().open(imagePath);
Expand All @@ -271,7 +270,7 @@ private Bitmap extractBitmapFromIntent(final Intent intent) {
} else {
//Scale big images down to avoid "out of memory"
BitmapFactory.decodeFile(imagePath, options);
options.inSampleSize = ContextUtils.get().calculateInSampleSize(options, app.settings.getRenderQualityReal());
options.inSampleSize = ContextUtils.get().calculateInSampleSize(options, _app.settings.getRenderQualityReal());
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(imagePath, options);
}
Expand All @@ -280,16 +279,16 @@ private Bitmap extractBitmapFromIntent(final Intent intent) {

@Override
public void onBackPressed() {
boolean hasTextInput = !textEditTopCaption.getText().toString().isEmpty() || !textEditBottomCaption.getText().toString().isEmpty();
boolean hasTextInput = !_textEditTopCaption.getText().toString().isEmpty() || !_textEditBottomCaption.getText().toString().isEmpty();

// Close views above
if (moarControlsContainerVisible) {
if (_moarControlsContainerVisible) {
toggleMoarControls(true, false);
return;
}

// Auto save if option checked
if (hasTextInput && app.settings.isAutoSaveMeme()) {
if (hasTextInput && _app.settings.isAutoSaveMeme()) {
if (saveMemeToFilesystem(false)) {
finish();
return;
Expand All @@ -303,27 +302,27 @@ public void onBackPressed() {
}

// Else wait for double back-press
if (doubleBackToExitPressedOnce) {
if (_doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
doubleBackToExitPressedOnce = true;
_doubleBackToExitPressedOnce = true;
Snackbar.make(findViewById(android.R.id.content), R.string.creator__press_back_again_to_exit, Snackbar.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
_doubleBackToExitPressedOnce = false;
}
}, 2000);
}

@OnTouch(R.id.memecreate__activity__image)
public boolean onImageTouched(View view) {
textEditBottomCaption.clearFocus();
textEditTopCaption.clearFocus();
imageEditView.requestFocus();
_textEditBottomCaption.clearFocus();
_textEditTopCaption.clearFocus();
_imageEditView.requestFocus();
ActivityUtils.get(this).hideSoftKeyboard();
if (moarControlsContainerVisible) {
if (_moarControlsContainerVisible) {
toggleMoarControls(true, false);
}
return true;
Expand Down Expand Up @@ -352,7 +351,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.action_share: {
app.shareBitmapToOtherApp(lastBitmap, this);
_app.shareBitmapToOtherApp(_lastBitmap, this);
return true;
}
case R.id.action_save: {
Expand All @@ -369,13 +368,13 @@ private boolean saveMemeToFilesystem(boolean showDialog) {
}

File folder = AssetUpdater.getMemesDir(AppSettings.get());
if (memeSavetime < 0) {
memeSavetime = System.currentTimeMillis();
if (_memeSavetime < 0) {
_memeSavetime = System.currentTimeMillis();
}

String filename = String.format(Locale.getDefault(), "%s_%d.jpg", getString(R.string.app_name), memeSavetime);
String filename = String.format(Locale.getDefault(), "%s_%d.jpg", getString(R.string.app_name), _memeSavetime);
File fullpath = new File(folder, filename);
boolean wasSaved = ContextUtils.get().writeImageToFileJpeg(fullpath, lastBitmap) != null;
boolean wasSaved = ContextUtils.get().writeImageToFileJpeg(fullpath, _lastBitmap) != null;
if (wasSaved && showDialog) {

AlertDialog.Builder dialog = new AlertDialog.Builder(this);
Expand All @@ -384,7 +383,7 @@ private boolean saveMemeToFilesystem(boolean showDialog) {
.setNegativeButton(R.string.creator__keep_editing, null)
.setNeutralButton(R.string.main__share_meme, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
app.shareBitmapToOtherApp(lastBitmap, MemeCreateActivity.this);
_app.shareBitmapToOtherApp(_lastBitmap, MemeCreateActivity.this);
}
})
.setPositiveButton(R.string.main__yes, new DialogInterface.OnClickListener() {
Expand All @@ -411,31 +410,31 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}

public void toggleMoarControls(boolean forceVisibile, boolean visible) {
moarControlsContainerVisible = !moarControlsContainerVisible;
_moarControlsContainerVisible = !_moarControlsContainerVisible;
if (forceVisibile) {
moarControlsContainerVisible = visible;
_moarControlsContainerVisible = visible;
}
textEditBottomCaption.setVisibility(moarControlsContainerVisible ? View.GONE : View.VISIBLE);
textEditTopCaption.setVisibility(moarControlsContainerVisible ? View.GONE : View.VISIBLE);
toolbar.setVisibility(moarControlsContainerVisible ? View.GONE : View.VISIBLE);
_textEditBottomCaption.setVisibility(_moarControlsContainerVisible ? View.GONE : View.VISIBLE);
_textEditTopCaption.setVisibility(_moarControlsContainerVisible ? View.GONE : View.VISIBLE);
_toolbar.setVisibility(_moarControlsContainerVisible ? View.GONE : View.VISIBLE);

// higher weightRatio means the conf is more wide, so below view can be higher
// 100 is the max weight, 55 means the below view is a little more weighted
Bitmap curImg = _memeEditorObject.getImageMain().getDisplayImage();
int weight = (int) (55f * (1 + ((curImg.getWidth() / (float) curImg.getHeight()) / 10f)));
weight = weight > 100 ? 100 : weight;

// Set weights. If moarControlsContainerVisible == false -> Hide them = 0 weight
// Set weights. If _moarControlsContainerVisible == false -> Hide them = 0 weight
View container = findViewById(R.id.memecreate__activity__image_container);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) container.getLayoutParams();
lp.height = 0;
lp.weight = moarControlsContainerVisible ? 100 - weight : 100;
lp.weight = _moarControlsContainerVisible ? 100 - weight : 100;
container.setLayoutParams(lp);
container = findViewById(R.id.memecreate__activity__moar_controls_container);
container.setVisibility(moarControlsContainerVisible ? View.VISIBLE : View.GONE);
container.setVisibility(_moarControlsContainerVisible ? View.VISIBLE : View.GONE);
lp = (LinearLayout.LayoutParams) container.getLayoutParams();
lp.height = 0;
lp.weight = moarControlsContainerVisible ? weight : 0;
lp.weight = _moarControlsContainerVisible ? weight : 0;
container.setLayoutParams(lp);
}

Expand Down Expand Up @@ -509,7 +508,7 @@ public void onNothingSelected(AdapterView<?> parent) {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
_memeEditorObject.getCaptionTop().setFont((MemeData.Font) parent.getSelectedItem());
_memeEditorObject.getCaptionBottom().setFont((MemeData.Font) parent.getSelectedItem());
app.settings.setLastUsedFont(((MemeData.Font) parent.getSelectedItem()).fullPath.getAbsolutePath());
_app.settings.setLastUsedFont(((MemeData.Font) parent.getSelectedItem()).fullPath.getAbsolutePath());
}
});
SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
Expand Down Expand Up @@ -643,12 +642,12 @@ public void onCaptionTopChanged(CharSequence text) {

@Override
public void onMemeEditorObjectChanged(MemeEditorObjectBase memeEditorObject) {
imageEditView.setImageBitmap(null);
if (lastBitmap != null)
lastBitmap.recycle();
_imageEditView.setImageBitmap(null);
if (_lastBitmap != null)
_lastBitmap.recycle();
Bitmap bmp = drawMultilineTextToBitmap(this, (MemeEditorObject) memeEditorObject);
imageEditView.setImageBitmap(bmp);
lastBitmap = bmp;
_imageEditView.setImageBitmap(bmp);
_lastBitmap = bmp;
}

@OnClick(R.id.memecreate__moar_controls__layout)
Expand Down

0 comments on commit 9443de8

Please sign in to comment.