Partially solve issue with RAM. Simplify logo animation code.

This commit is contained in:
Snek 2017-03-17 17:03:38 +03:00
parent afa275ef5e
commit 045c99954a
2 changed files with 18 additions and 41 deletions

View File

@ -6,9 +6,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
@ -20,17 +20,23 @@ import android.widget.TextView;
public class LaunchActivity extends AppCompatActivity {
ImageView connect, cancel, imageViewLogo;
TextView status;
//AnimationDrawable logo;
Boolean isPressed = false;
SharedPreferences sharedPreferences;
MediaPlayer m;
Handler aniHandle = new Handler();
int i = 0;
int id;
int duration = 20;
Runnable aniRunnable = new Runnable() {
public void run() {
imageViewLogo.setImageDrawable((getResources().getDrawable(id)));
animate(imageViewLogo);
if (i < 39) {
i += 1;
String imgName = "logo" + Integer.toString(i);
id = getResources().getIdentifier(imgName, "drawable", getPackageName());
imageViewLogo.setImageDrawable((getResources().getDrawable(id)));
aniHandle.postDelayed(this, duration);
}
}
};
@ -43,15 +49,6 @@ public class LaunchActivity extends AppCompatActivity {
}
}
protected void animate(ImageView view) {
if (i < 39) {
i += 1;
String imgName = "logo" + Integer.toString(i);
id = getResources().getIdentifier(imgName, "drawable", getPackageName());
view.postDelayed(aniRunnable, duration);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -60,14 +57,8 @@ public class LaunchActivity extends AppCompatActivity {
cancel = (ImageView) findViewById(R.id.imageView_cancel);
status = (TextView) findViewById(R.id.textView_call);
imageViewLogo = (ImageView) findViewById(R.id.imageView_logo);
/*
* Reported OOM on 2K+ resolution devices.
* Looks like better to change it to static image for now.
*/
/*logo = (AnimationDrawable) imageViewLogo.getDrawable();
logo.start();*/
aniHandle.post(aniRunnable);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
animate(imageViewLogo);
if (!isAppInstalled(LaunchActivity.this, "com.google.android.googlequicksearchbox")) {
status.setText(R.string.google_app_error);
}
@ -137,9 +128,10 @@ public class LaunchActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
super.onDestroy();
if (m != null)
m.release();
super.onDestroy();
aniHandle.removeCallbacks(aniRunnable);
}
@Override
@ -171,16 +163,4 @@ public class LaunchActivity extends AppCompatActivity {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
}
/* Reported OOM on 2K+ resolution devices */
/*
@Override
protected void onPause() {
//to enable the to collect the animation frames
if (logo != null && logo.isRunning())
logo.stop();
imageViewLogo.setImageResource(R.drawable.logo39);
logo = null;
super.onPause();
}*/
}

View File

@ -132,23 +132,23 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
super.onDestroy();
if (sr != null)
sr.destroy();
if (m != null)
m.release();
super.onDestroy();
}
@Override
protected void onStop() {
isLoop = false;
super.onStop();
isLoop = false;
}
@Override
protected void onPause() {
isLoop = false;
super.onPause();
isLoop = false;
}
@ -472,13 +472,10 @@ public class MainActivity extends AppCompatActivity {
input += data.get(0);
/* TODO: Japanese doesn't split the words. Sigh. */
String[] splitInput = input.split(" ");
/* Really, google? */
if (splitInput[0].equalsIgnoreCase("Асистент")) {
String temp = "";
String[] replace;
temp += data.get(1);
replace = temp.split(" ");
splitInput[0] = replace[0];
splitInput[0] = "Ассистент";
}
/* Switch language within current context for voice recognition */