Convert global Toast to per-activity Snackbar
Assign activity menu icon to activity Snackbar Unify appearance of Snackbar, Fix overlap in log sender See https://stackoverflow.com/a/49583210/461982 for the StackOverflow submission on modifying Snackbar location.
This commit is contained in:
parent
c684629128
commit
f88561614e
|
@ -1,11 +1,17 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.constraint.ConstraintLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -15,7 +21,6 @@ import android.widget.ListView;
|
|||
import android.widget.SlidingDrawer;
|
||||
import android.widget.SlidingDrawer.OnDrawerOpenListener;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.reicast.emulator.config.Config;
|
||||
import com.reicast.emulator.debug.GitAdapter;
|
||||
|
@ -172,9 +177,7 @@ public class AboutFragment extends Fragment {
|
|||
} catch (JSONException e) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
MainActivity.showToastMessage(getActivity(),
|
||||
getActivity().getString(R.string.git_broken),
|
||||
R.drawable.ic_github, Toast.LENGTH_SHORT);
|
||||
showToastMessage(getActivity().getString(R.string.git_broken), Snackbar.LENGTH_SHORT);
|
||||
slidingGithub.close();
|
||||
}
|
||||
});
|
||||
|
@ -182,9 +185,7 @@ public class AboutFragment extends Fragment {
|
|||
} catch (Exception e) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
MainActivity.showToastMessage(getActivity(),
|
||||
getActivity().getString(R.string.git_broken),
|
||||
R.drawable.ic_github, Toast.LENGTH_SHORT);
|
||||
showToastMessage(getActivity().getString(R.string.git_broken), Snackbar.LENGTH_SHORT);
|
||||
slidingGithub.close();
|
||||
}
|
||||
});
|
||||
|
@ -234,4 +235,28 @@ public class AboutFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void showToastMessage(String message, int duration) {
|
||||
ConstraintLayout layout = (ConstraintLayout) getActivity().findViewById(R.id.mainui_layout);
|
||||
Snackbar snackbar = Snackbar.make(layout, message, duration);
|
||||
View snackbarLayout = snackbar.getView();
|
||||
snackbarLayout.setMinimumWidth(ConstraintLayout.LayoutParams.MATCH_PARENT);
|
||||
TextView textView = (TextView) snackbarLayout.findViewById(
|
||||
android.support.design.R.id.snackbar_text);
|
||||
textView.setGravity(Gravity.CENTER_VERTICAL);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
textView.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
|
||||
Drawable drawable;
|
||||
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
||||
drawable = getResources().getDrawable(
|
||||
R.drawable.ic_info_outline, getActivity().getTheme());
|
||||
} else {
|
||||
drawable = VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_info_outline, getActivity().getTheme());
|
||||
}
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||||
textView.setCompoundDrawablePadding(getResources()
|
||||
.getDimensionPixelOffset(R.dimen.snackbar_icon_padding));
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,16 @@ import android.graphics.Typeface;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.constraint.ConstraintLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
@ -22,7 +27,6 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.util.FileUtils;
|
||||
import com.reicast.emulator.config.Config;
|
||||
|
@ -52,7 +56,6 @@ public class FileBrowser extends Fragment {
|
|||
|
||||
private Vibrator vib;
|
||||
private Drawable orig_bg;
|
||||
private Activity parentActivity;
|
||||
private boolean ImgBrowse;
|
||||
private boolean games;
|
||||
private OnItemSelectedListener mCallback;
|
||||
|
@ -151,10 +154,8 @@ public class FileBrowser extends Fragment {
|
|||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
// setContentView(R.layout.activity_main);
|
||||
parentActivity = getActivity();
|
||||
|
||||
vib = (Vibrator) parentActivity
|
||||
.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
/*
|
||||
* OnTouchListener viblist=new OnTouchListener() {
|
||||
|
@ -169,9 +170,7 @@ public class FileBrowser extends Fragment {
|
|||
|
||||
File home = new File(mPrefs.getString(Config.pref_home, home_directory));
|
||||
if (!home.exists() || !home.isDirectory()) {
|
||||
MainActivity.showToastMessage(getActivity(),
|
||||
getActivity().getString(R.string.config_home),
|
||||
R.drawable.ic_notification, Toast.LENGTH_LONG);
|
||||
showToastMessage(getActivity().getString(R.string.config_home), Snackbar.LENGTH_LONG);
|
||||
} else {
|
||||
(new installGraphics()).execute();
|
||||
}
|
||||
|
@ -207,9 +206,9 @@ public class FileBrowser extends Fragment {
|
|||
out.close();
|
||||
} else if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
OutputStream fo = new FileOutputStream(file);
|
||||
InputStream png = parentActivity.getAssets()
|
||||
.open("buttons.png");
|
||||
InputStream png = getActivity().getAssets().open("buttons.png");
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int len = 0;
|
||||
|
@ -241,7 +240,7 @@ public class FileBrowser extends Fragment {
|
|||
File storage = new File(paths[0]);
|
||||
|
||||
// array of valid image file extensions
|
||||
String[] mediaTypes = parentActivity.getResources().getStringArray(array);
|
||||
String[] mediaTypes = getActivity().getResources().getStringArray(array);
|
||||
FilenameFilter[] filter = new FilenameFilter[mediaTypes.length];
|
||||
|
||||
int i = 0;
|
||||
|
@ -275,12 +274,12 @@ public class FileBrowser extends Fragment {
|
|||
@Override
|
||||
protected void onPostExecute(List<File> items) {
|
||||
if (items != null && !items.isEmpty()) {
|
||||
final LinearLayout list = (LinearLayout) parentActivity.findViewById(R.id.game_list);
|
||||
final LinearLayout list = (LinearLayout) getActivity().findViewById(R.id.game_list);
|
||||
if (list != null) {
|
||||
list.removeAllViews();
|
||||
}
|
||||
|
||||
String heading = parentActivity.getString(R.string.games_listing);
|
||||
String heading = getActivity().getString(R.string.games_listing);
|
||||
createListHeader(heading, list, array == R.array.images);
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
createListItem(list, items.get(i), i, array == R.array.images);
|
||||
|
@ -328,7 +327,7 @@ public class FileBrowser extends Fragment {
|
|||
|
||||
private void createListHeader(String header_text, View view, boolean hasBios) {
|
||||
if (hasBios) {
|
||||
final View childview = parentActivity.getLayoutInflater().inflate(
|
||||
final View childview = getActivity().getLayoutInflater().inflate(
|
||||
R.layout.bios_list_item, null, false);
|
||||
|
||||
((TextView) childview.findViewById(R.id.item_name))
|
||||
|
@ -367,7 +366,7 @@ public class FileBrowser extends Fragment {
|
|||
((ViewGroup) view).addView(childview);
|
||||
}
|
||||
|
||||
final View headerView = parentActivity.getLayoutInflater().inflate(
|
||||
final View headerView = getActivity().getLayoutInflater().inflate(
|
||||
R.layout.browser_fragment_header, null, false);
|
||||
((ImageView) headerView.findViewById(R.id.item_icon))
|
||||
.setImageResource(R.drawable.open_folder);
|
||||
|
@ -380,11 +379,11 @@ public class FileBrowser extends Fragment {
|
|||
}
|
||||
|
||||
private void createListItem(LinearLayout list, final File game, final int index, final boolean isGame) {
|
||||
final View childview = parentActivity.getLayoutInflater().inflate(
|
||||
final View childview = getActivity().getLayoutInflater().inflate(
|
||||
R.layout.browser_fragment_item, null, false);
|
||||
|
||||
XMLParser xmlParser = new XMLParser(game, index, mPrefs);
|
||||
xmlParser.setViewParent(parentActivity, childview, mCallback);
|
||||
xmlParser.setViewParent(getActivity(), childview, mCallback);
|
||||
orig_bg = childview.getBackground();
|
||||
|
||||
childview.findViewById(R.id.childview).setOnClickListener(
|
||||
|
@ -400,9 +399,8 @@ public class FileBrowser extends Fragment {
|
|||
home_directory = game.getAbsolutePath().substring(0,
|
||||
game.getAbsolutePath().lastIndexOf(File.separator)).replace("/data", "");
|
||||
if (!DataDirectoryBIOS()) {
|
||||
MainActivity.showToastMessage(getActivity(),
|
||||
getActivity().getString(R.string.config_data, home_directory),
|
||||
R.drawable.ic_notification, Toast.LENGTH_LONG);
|
||||
showToastMessage(getActivity().getString(R.string.config_data, home_directory),
|
||||
Snackbar.LENGTH_LONG);
|
||||
}
|
||||
mPrefs.edit().putString("home_directory", home_directory).apply();
|
||||
mCallback.onFolderSelected(Uri.fromFile(new File(home_directory)));
|
||||
|
@ -430,8 +428,7 @@ public class FileBrowser extends Fragment {
|
|||
}
|
||||
|
||||
void navigate(final File root_sd) {
|
||||
LinearLayout v = (LinearLayout) parentActivity
|
||||
.findViewById(R.id.game_list);
|
||||
LinearLayout v = (LinearLayout) getActivity().findViewById(R.id.game_list);
|
||||
v.removeAllViews();
|
||||
|
||||
ArrayList<File> list = new ArrayList<File>();
|
||||
|
@ -456,7 +453,7 @@ public class FileBrowser extends Fragment {
|
|||
for (final File file : list) {
|
||||
if (file != null && !file.isDirectory() && !file.getAbsolutePath().equals("/data"))
|
||||
continue;
|
||||
final View childview = parentActivity.getLayoutInflater().inflate(
|
||||
final View childview = getActivity().getLayoutInflater().inflate(
|
||||
R.layout.browser_fragment_item, null, false);
|
||||
|
||||
if (file == null) {
|
||||
|
@ -481,7 +478,7 @@ public class FileBrowser extends Fragment {
|
|||
public void onClick(View view) {
|
||||
if (file != null && file.isDirectory()) {
|
||||
navigate(file);
|
||||
ScrollView sv = (ScrollView) parentActivity
|
||||
ScrollView sv = (ScrollView) getActivity()
|
||||
.findViewById(R.id.game_scroller);
|
||||
sv.scrollTo(0, 0);
|
||||
vib.vibrate(50);
|
||||
|
@ -496,9 +493,9 @@ public class FileBrowser extends Fragment {
|
|||
home_directory = heading.replace("/data", "");
|
||||
mPrefs.edit().putString(Config.pref_home, home_directory).apply();
|
||||
if (!DataDirectoryBIOS()) {
|
||||
MainActivity.showToastMessage(getActivity(),
|
||||
getActivity().getString(R.string.config_data, home_directory),
|
||||
R.drawable.ic_notification, Toast.LENGTH_LONG);
|
||||
showToastMessage(getActivity().getString(R.string.config_data, home_directory),
|
||||
Snackbar.LENGTH_LONG
|
||||
);
|
||||
}
|
||||
mCallback.onFolderSelected(Uri.fromFile(new File(home_directory)));
|
||||
JNIdc.config(home_directory);
|
||||
|
@ -549,4 +546,28 @@ public class FileBrowser extends Fragment {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showToastMessage(String message, int duration) {
|
||||
ConstraintLayout layout = (ConstraintLayout) getActivity().findViewById(R.id.mainui_layout);
|
||||
Snackbar snackbar = Snackbar.make(layout, message, duration);
|
||||
View snackbarLayout = snackbar.getView();
|
||||
snackbarLayout.setMinimumWidth(ConstraintLayout.LayoutParams.MATCH_PARENT);
|
||||
TextView textView = (TextView) snackbarLayout.findViewById(
|
||||
android.support.design.R.id.snackbar_text);
|
||||
textView.setGravity(Gravity.CENTER_VERTICAL);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
textView.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
|
||||
Drawable drawable;
|
||||
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
||||
drawable = getResources().getDrawable(
|
||||
R.drawable.ic_subdirectory_arrow_right, getActivity().getTheme());
|
||||
} else {
|
||||
drawable = VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_subdirectory_arrow_right, getActivity().getTheme());
|
||||
}
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||||
textView.setCompoundDrawablePadding(getResources()
|
||||
.getDimensionPixelOffset(R.dimen.snackbar_icon_padding));
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -15,26 +14,23 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.constraint.ConstraintLayout;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnSystemUiVisibilityChangeListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.reicast.emulator.config.Config;
|
||||
import com.reicast.emulator.config.InputFragment;
|
||||
|
@ -244,8 +240,7 @@ public class MainActivity extends AppCompatActivity implements
|
|||
|
||||
public void onGameSelected(Uri uri) {
|
||||
if (Config.readOutput("uname -a").equals(getString(R.string.error_kernel))) {
|
||||
MainActivity.showToastMessage(MainActivity.this, getString(R.string.unsupported),
|
||||
R.drawable.ic_notification, Toast.LENGTH_SHORT);
|
||||
showToastMessage(getString(R.string.unsupported), Snackbar.LENGTH_SHORT);
|
||||
}
|
||||
String msg = null;
|
||||
if (!isBiosExisting(MainActivity.this))
|
||||
|
@ -300,8 +295,8 @@ public class MainActivity extends AppCompatActivity implements
|
|||
builder.setNegativeButton(R.string.gdrive,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Toast.makeText(MainActivity.this,
|
||||
R.string.require_bios, Toast.LENGTH_SHORT).show();
|
||||
showToastMessage(getString(R.string.require_bios),
|
||||
Snackbar.LENGTH_SHORT);
|
||||
}
|
||||
});
|
||||
builder.create();
|
||||
|
@ -586,29 +581,20 @@ public class MainActivity extends AppCompatActivity implements
|
|||
intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
return list.size() > 0;
|
||||
}
|
||||
|
||||
public static void showToastMessage(Context context, String message,
|
||||
int resource, int duration) {
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View layout = inflater.inflate(R.layout.toast_layout, null);
|
||||
|
||||
ImageView image = (ImageView) layout.findViewById(R.id.image);
|
||||
image.setImageResource(resource);
|
||||
|
||||
TextView text = (TextView) layout.findViewById(R.id.text);
|
||||
text.setText(message);
|
||||
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
WindowManager winman = (WindowManager) context
|
||||
.getSystemService(Context.WINDOW_SERVICE);
|
||||
winman.getDefaultDisplay().getMetrics(metrics);
|
||||
|
||||
Toast toast = new Toast(context);
|
||||
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,
|
||||
(int) (72 * metrics.density + 0.5f));
|
||||
toast.setDuration(duration);
|
||||
toast.setView(layout);
|
||||
toast.show();
|
||||
private void showToastMessage(String message, int duration) {
|
||||
ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.mainui_layout);
|
||||
Snackbar snackbar = Snackbar.make(layout, message, duration);
|
||||
View snackbarLayout = snackbar.getView();
|
||||
snackbarLayout.setMinimumWidth(ConstraintLayout.LayoutParams.MATCH_PARENT);
|
||||
TextView textView = (TextView) snackbarLayout.findViewById(
|
||||
android.support.design.R.id.snackbar_text);
|
||||
textView.setGravity(Gravity.CENTER_VERTICAL);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
textView.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_notification, 0, 0, 0);
|
||||
textView.setCompoundDrawablePadding(getResources()
|
||||
.getDimensionPixelOffset(R.dimen.snackbar_icon_padding));
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,19 @@ package com.reicast.emulator.config;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.constraint.ConstraintLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -25,12 +30,11 @@ import android.widget.EditText;
|
|||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.util.FileUtils;
|
||||
import com.reicast.emulator.Emulator;
|
||||
import com.reicast.emulator.FileBrowser;
|
||||
import com.reicast.emulator.GL2JNIActivity;
|
||||
import com.reicast.emulator.R;
|
||||
import com.reicast.emulator.emu.GL2JNIView;
|
||||
import com.reicast.emulator.emu.JNIdc;
|
||||
|
@ -131,8 +135,8 @@ public class OptionsFragment extends Fragment {
|
|||
home_directory = editBrowse.getText().toString();
|
||||
if (home_directory.endsWith("/data")) {
|
||||
home_directory.replace("/data", "");
|
||||
Toast.makeText(getActivity(), R.string.data_folder,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
showToastMessage(getActivity().getString(R.string.data_folder),
|
||||
Snackbar.LENGTH_SHORT);
|
||||
}
|
||||
mPrefs.edit().putString(Config.pref_home, home_directory).apply();
|
||||
JNIdc.config(home_directory);
|
||||
|
@ -650,4 +654,28 @@ public class OptionsFragment extends Fragment {
|
|||
}
|
||||
mPrefs.edit().putString("localized", localized).apply();
|
||||
}
|
||||
|
||||
private void showToastMessage(String message, int duration) {
|
||||
ConstraintLayout layout = (ConstraintLayout) getActivity().findViewById(R.id.mainui_layout);
|
||||
Snackbar snackbar = Snackbar.make(layout, message, duration);
|
||||
View snackbarLayout = snackbar.getView();
|
||||
snackbarLayout.setMinimumWidth(ConstraintLayout.LayoutParams.MATCH_PARENT);
|
||||
TextView textView = (TextView) snackbarLayout.findViewById(
|
||||
android.support.design.R.id.snackbar_text);
|
||||
textView.setGravity(Gravity.CENTER_VERTICAL);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
textView.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
|
||||
Drawable drawable;
|
||||
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
||||
drawable = getResources().getDrawable(
|
||||
R.drawable.ic_settings, getActivity().getTheme());
|
||||
} else {
|
||||
drawable = VectorDrawableCompat.create(getResources(),
|
||||
R.drawable.ic_settings, getActivity().getTheme());
|
||||
}
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||||
textView.setCompoundDrawablePadding(getResources()
|
||||
.getDimensionPixelOffset(R.dimen.snackbar_icon_padding));
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
package com.reicast.emulator.debug;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.support.constraint.ConstraintLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.reicast.emulator.R;
|
||||
|
@ -239,10 +247,13 @@ public class GenerateLogs extends AsyncTask<String, Integer, String> {
|
|||
@Override
|
||||
protected void onPostExecute(final String response) {
|
||||
if (response != null && !response.equals(null)) {
|
||||
Toast.makeText(mContext, mContext.getString(R.string.log_saved),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(mContext, mContext.getString(R.string.platform),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(mContext, mContext.getString(R.string.log_saved),
|
||||
// Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(mContext, mContext.getString(R.string.platform),
|
||||
// Toast.LENGTH_SHORT).show();
|
||||
|
||||
showToastMessage(mContext.getString(R.string.log_saved), Snackbar.LENGTH_SHORT);
|
||||
showToastMessage(mContext.getString(R.string.platform), Snackbar.LENGTH_SHORT);
|
||||
UploadLogs mUploadLogs = new UploadLogs(mContext, currentTime);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
mUploadLogs.executeOnExecutor(
|
||||
|
@ -252,4 +263,34 @@ public class GenerateLogs extends AsyncTask<String, Integer, String> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showToastMessage(String message, int duration) {
|
||||
ConstraintLayout layout = (ConstraintLayout)
|
||||
((Activity) mContext).findViewById(R.id.mainui_layout);
|
||||
Snackbar snackbar = Snackbar.make(layout, message, duration);
|
||||
View snackbarLayout = snackbar.getView();
|
||||
ConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(
|
||||
ConstraintLayout.LayoutParams.MATCH_PARENT,
|
||||
ConstraintLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
lp.setMargins(0, 0, 0, 0);
|
||||
snackbarLayout.setLayoutParams(lp);
|
||||
TextView textView = (TextView) snackbarLayout.findViewById(
|
||||
android.support.design.R.id.snackbar_text);
|
||||
textView.setGravity(Gravity.CENTER_VERTICAL);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
textView.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
|
||||
Drawable drawable;
|
||||
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
||||
drawable = mContext.getResources().getDrawable(
|
||||
R.drawable.ic_send, ((Activity) mContext).getTheme());
|
||||
} else {
|
||||
drawable = VectorDrawableCompat.create(mContext.getResources(),
|
||||
R.drawable.ic_send, ((Activity) mContext).getTheme());
|
||||
}
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||||
textView.setCompoundDrawablePadding(mContext.getResources()
|
||||
.getDimensionPixelOffset(R.dimen.snackbar_icon_padding));
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ import com.android.util.FileUtils;
|
|||
import com.reicast.emulator.Emulator;
|
||||
import com.reicast.emulator.GL2JNIActivity;
|
||||
import com.reicast.emulator.GL2JNINative;
|
||||
import com.reicast.emulator.MainActivity;
|
||||
import com.reicast.emulator.R;
|
||||
import com.reicast.emulator.config.Config;
|
||||
import com.reicast.emulator.emu.OnScreenMenu.FpsPopup;
|
||||
import com.reicast.emulator.periph.VJoy;
|
||||
|
@ -686,7 +684,7 @@ public class GL2JNIView extends GLSurfaceView
|
|||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
Log.d(context.getApplicationContext().getPackageName(), msg);
|
||||
MainActivity.showToastMessage(context, msg, R.drawable.ic_notification, Toast.LENGTH_SHORT);
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<android.support.constraint.ConstraintLayout 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/mainui_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/toast_layout_root"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="#50000000"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginTop="2dip"
|
||||
android:layout_toRightOf="@+id/ImageView01"
|
||||
android:includeFontPadding="false"
|
||||
android:lineSpacingMultiplier="1.0"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="12sp"
|
||||
android:typeface="sans" />
|
||||
|
||||
</LinearLayout>
|
|
@ -13,4 +13,6 @@
|
|||
<dimen name="primary_text_material">16sp</dimen>
|
||||
<dimen name="secondary_text_material">14sp</dimen>
|
||||
|
||||
<dimen name="snackbar_icon_padding">6dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue