Android: Style Notification Window

This commit is contained in:
zilmar 2022-08-01 09:15:48 +09:30
parent 63051df71e
commit 629fe54ccb
6 changed files with 159 additions and 20 deletions

View File

@ -1,15 +1,19 @@
package emu.project64.util;
//import emu.project64.game.GameOverlay;
import emu.project64.jni.NativeExports;
import emu.project64.jni.SettingsID;
import emu.project64.Project64Application;
import emu.project64.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.view.ContextThemeWrapper;
/**
* A small class to encapsulate the notification process for Mupen64PlusAE.
@ -37,20 +41,17 @@ public final class Notifier
@Override
public void run()
{
final AlertDialog dialog = new AlertDialog.Builder(finalActivity)
.setTitle("Error")
.setMessage(finalMessage)
.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
// You don't have to do anything here if you just want it dismissed when clicked
synchronized(sDisplayMessager)
{
sDisplayMessager.notify();
};
}
})
final LayoutInflater inflater = (LayoutInflater) finalActivity.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View layout = inflater.inflate( R.layout.dialog_menu, null );
TextView DlgTitle = (TextView)layout.findViewById(R.id.dlg_title);
DlgTitle.setText("Error");
ListView ListOptions = (ListView)layout.findViewById(R.id.list_options);
String[] data = { finalMessage };
NotifierAdapter ad = new NotifierAdapter(finalActivity, sDisplayMessager, data);
ListOptions.setAdapter(ad);
final AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(finalActivity,R.style.Theme_Project64_Dialog_Alert))
.setView( layout)
.setCancelable(false)
.create();
dialog.setCanceledOnTouchOutside(false);

View File

@ -0,0 +1,66 @@
package emu.project64.util;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import emu.project64.R;
public class NotifierAdapter extends BaseAdapter
{
Context con;
String[] data;
Runnable DisplayMessager;
public NotifierAdapter (Context context, Runnable DisplayMessager, String[] data)
{
this.con = context;
this.data = data;
this.DisplayMessager = DisplayMessager;
}
@Override
public int getCount() {
return data.length;
}
@Override
public Object getItem(int position) {
return data[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.notifier_adapter, parent, false);
TextView text = (TextView) view.findViewById(R.id.text);
text.setText(data[position]);
Button button = (Button) view.findViewById(R.id.button);
button.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
synchronized(DisplayMessager)
{
DisplayMessager.notify();
};
}
}
);
return view;
}
}

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="@color/ButtonCenterColor"
android:startColor="@color/ButtonStartColor"
android:endColor="@color/ButtonEndColor"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="@color/buttonBorderColor"
/>
</shape>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text"
android:text=""
android:textSize="24dp"
android:paddingBottom = "20dp"
/>
<Button
style="@style/Theme.Project64.Dialog.Button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:gravity="center"
android:text="OK"
/>
</LinearLayout>

View File

@ -7,6 +7,10 @@
<color name="TabInactive">#000000</color>
<color name="TabActive">#4683ec</color>
<color name="ButtonTextColor">#ffffff</color>
<color name="ButtonCenterColor">#8AADE8</color>
<color name="ButtonStartColor">#C7DCFF</color>
<color name="ButtonEndColor">#1750B3</color>
<color name="buttonBorderColor">#4683ec</color>
<color name="white">#ffffff</color>

View File

@ -101,10 +101,23 @@
<item name="android:textSize">30sp</item>
</style>
<style name="Theme.Project64.Dialog.Button">
<item name="android:textColor">@color/ButtonTextColor</item>
<item name="android:textSize">24sp</item>
<item name="android:clickable">true</item>
<item name="android:layout_width">270dp</item>
<item name="android:layout_height">60dp</item>
<item name="android:background">@drawable/button_shape</item>
<item name="android:shadowColor">#A8A8A8</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">0</item>
<item name="android:shadowRadius">5</item>
</style>
<style name="Theme.Project64.Dialog.Alert" parent="Base.Theme.AppCompat.Dialog.Alert">
<item name="android:windowBackground">#00FF00</item>
<item name="android:windowTitleStyle">@style/Theme.Project64.Dialog.Title</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowTitleStyle">@style/Theme.Project64.Dialog.Title</item>
<item name="android:dividerHorizontal">@null</item>
<item name="android:dividerVertical">@null</item>
<item name="android:windowNoTitle">true</item>