Fancy toast, Forgiving BIOS directory selection

This commit is contained in:
TwistedUmbrella 2014-10-24 22:44:10 -04:00
parent 157c837ec0
commit 49a44b3cb0
4 changed files with 135 additions and 7 deletions

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
====================================================================
Copyright (c) 2012-2013 LoungeKatt Entertainment. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. All advertising materials mentioning features or use of this
code must be open-source and display the following disclaimer:
"This product includes software developed by LoungeKatt" unless
otherwise displayed by published public repository entries.
4. The names "LoungeKatt" and "StarKissed" must not be used to
endorse or promote products derived from this software without
prior written permission. For written permission, please contact
admin@loungekatt.com.
5. Products derived from this software may not be called "StarKissed"
nor may "StarKissed" appear in their names without prior written
permission of LoungeKatt Entertainment.
6. Redistributions of any form whatsoever without public source
must retain the following acknowledgment:
"This product includes source code developed by LoungeKatt"
THIS SOFTWARE IS PROVIDED BY LoungeKatt ``AS IS'' AND ANY
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
==================================================================== -->
<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="wrap_content"
android:layout_centerVertical="true"
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="18sp"
android:typeface="sans" />
</LinearLayout>

View File

@ -7,6 +7,7 @@
<string name="games_path">Storage Path (location of *.gdi, *.chd or *.cdi images)</string>
<string name="game_path">Default Game Storage</string>
<string name="config_home">Please configure a home directory.</string>
<string name="config_data">Please move BIOS to %1$s/data/</string>
<string name="config_game">Please configure a game directory.</string>
<string name="unsupported">Unsupported kernel version!</string>
<string name="locate">Locate</string>

View File

@ -189,8 +189,9 @@ public class FileBrowser extends Fragment {
File home = new File(mPrefs.getString(Config.pref_home, home_directory));
if (!home.exists() || !home.isDirectory()) {
Toast.makeText(getActivity(), R.string.config_home,
Toast.LENGTH_LONG).show();
MainActivity.showToastMessage(getActivity(),
getActivity().getString(R.string.config_home),
Toast.LENGTH_LONG);
}
if (!ImgBrowse && !games) {
@ -401,6 +402,11 @@ public class FileBrowser extends Fragment {
.fromFile(game) : Uri.EMPTY);
home_directory = game.getAbsolutePath().substring(0,
game.getAbsolutePath().lastIndexOf(File.separator));
if (!DataDirectoryBIOS()) {
MainActivity.showToastMessage(getActivity(),
getActivity().getString(R.string.config_data, home_directory),
Toast.LENGTH_LONG);
}
mPrefs.edit().putString("home_directory",
home_directory.replace("/data", "")).commit();
JNIdc.config(home_directory.replace("/data", ""));
@ -498,11 +504,10 @@ public class FileBrowser extends Fragment {
mPrefs.edit()
.putString(Config.pref_home,
heading).commit();
File data_directory = new File(heading,
"data");
if (!data_directory.exists()
|| !data_directory.isDirectory()) {
data_directory.mkdirs();
if (!DataDirectoryBIOS()) {
MainActivity.showToastMessage(getActivity(),
getActivity().getString(R.string.config_data, home_directory),
Toast.LENGTH_LONG);
}
JNIdc.config(heading);
}
@ -529,4 +534,18 @@ public class FileBrowser extends Fragment {
}
v.invalidate();
}
private boolean DataDirectoryBIOS() {
File data_directory = new File(home_directory, "data");
if (!data_directory.exists() || !data_directory.isDirectory()) {
data_directory.mkdirs();
File bios = new File(home_directory, "dc_boot.bin");
boolean success = bios.renameTo(new File(home_directory + "/data", "dc_boot.bin"));
File flash = new File(home_directory, "dc_flash.bin");
success = flash.renameTo(new File(home_directory + "/data", "dc_flash.bin"));
return success;
} else {
return true;
}
}
}

View File

@ -20,14 +20,18 @@ import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnSystemUiVisibilityChangeListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@ -635,4 +639,29 @@ public class MainActivity extends SlidingFragmentActivity implements
intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
public static void showToastMessage(Context context, String message,
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(R.drawable.ic_launcher);
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);
final float scale = context.getResources().getDisplayMetrics().density;
int toastPixels = (int) ((metrics.widthPixels * scale + 0.5f) / 18);
Toast toast = new Toast(context);
toast.setGravity(Gravity.BOTTOM, 0, toastPixels);
toast.setDuration(duration);
toast.setView(layout);
toast.show();
}
}