Permalink
Browse files

front: Refactor dialog popup utilities into a separate class.

Can be used in other activities, and helps declutter GalleryActivity.
  • Loading branch information...
littleguy77 committed May 7, 2015
1 parent 4114294 commit 349a17acbba8c4209858ae7604ccc9c5dcc3bf38
@@ -30,6 +30,7 @@
import org.mupen64plusae.v3.alpha.R;
import paulscode.android.mupen64plusae.dialog.ChangeLog;
import paulscode.android.mupen64plusae.dialog.Popups;
import paulscode.android.mupen64plusae.dialog.Prompt;
import paulscode.android.mupen64plusae.dialog.Prompt.PromptConfirmListener;
import paulscode.android.mupen64plusae.dialog.ScanRomsDialog;
@@ -43,10 +44,8 @@
import paulscode.android.mupen64plusae.task.CacheRomInfoTask.CacheRomInfoListener;
import paulscode.android.mupen64plusae.task.ComputeMd5Task;
import paulscode.android.mupen64plusae.task.ComputeMd5Task.ComputeMd5Listener;
import paulscode.android.mupen64plusae.util.DeviceUtil;
import paulscode.android.mupen64plusae.util.Notifier;
import paulscode.android.mupen64plusae.util.RomHeader;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.AlertDialog.Builder;
import android.content.Context;
@@ -143,7 +142,7 @@ protected void onCreate( Bundle savedInstanceState )
if( lastVer != currVer )
{
// First run after install/update, greet user with changelog, then help dialog
popupFaq();
Popups.showFaq( this );
ChangeLog log = new ChangeLog( getAssets() );
if( log.show( this, lastVer + 1, currVer ) )
{
@@ -422,29 +421,28 @@ public boolean onOptionsItemSelected( MenuItem item )
ActivityHelper.startManageControllerProfilesActivity( this );
return true;
case R.id.menuItem_faq:
popupFaq();
Popups.showFaq( this );
return true;
case R.id.menuItem_helpForum:
ActivityHelper.launchUri( GalleryActivity.this, R.string.uri_forum );
ActivityHelper.launchUri( this, R.string.uri_forum );
return true;
case R.id.menuItem_controllerDiagnostics:
ActivityHelper.startDiagnosticActivity( this );
return true;
case R.id.menuItem_reportBug:
ActivityHelper.launchUri( GalleryActivity.this, R.string.uri_bugReport );
ActivityHelper.launchUri( this, R.string.uri_bugReport );
return true;
case R.id.menuItem_appVersion:
popupAppVersion();
Popups.showAppVersion( this );
return true;
case R.id.menuItem_changelog:
new ChangeLog( getAssets() )
.show( GalleryActivity.this, 0, mAppData.appVersionCode );
new ChangeLog( getAssets() ).show( this, 0, mAppData.appVersionCode );
return true;
case R.id.menuItem_logcat:
popupLogcat();
Popups.showLogcat( this );
return true;
case R.id.menuItem_hardwareInfo:
popupHardwareInfo();
Popups.showHardwareInfo( this );
return true;
case R.id.menuItem_credits:
ActivityHelper.launchUri( GalleryActivity.this, R.string.uri_credits );
@@ -726,55 +724,6 @@ public int getSpanSize( int position )
mGridView.setLayoutManager( layoutManager );
}
private void popupFaq()
{
CharSequence title = getText( R.string.menuItem_faq );
CharSequence message = getText( R.string.popup_faq );
new Builder( this ).setTitle( title ).setMessage( message ).create().show();
}
private void popupLogcat()
{
String title = getString( R.string.menuItem_logcat );
String message = DeviceUtil.getLogCat();
popupShareableText( title, message );
}
private void popupHardwareInfo()
{
String title = getString( R.string.menuItem_hardwareInfo );
String axisInfo = DeviceUtil.getAxisInfo();
String peripheralInfo = DeviceUtil.getPeripheralInfo();
String cpuInfo = DeviceUtil.getCpuInfo();
String message = axisInfo + peripheralInfo + cpuInfo;
popupShareableText( title, message );
}
private void popupShareableText( String title, final String message )
{
// Set up click handler to share text with a user-selected app (email, clipboard, etc.)
DialogInterface.OnClickListener shareHandler = new DialogInterface.OnClickListener()
{
@SuppressLint( "InlinedApi" )
@Override
public void onClick( DialogInterface dialog, int which )
{
ActivityHelper.launchPlainText( GalleryActivity.this, message, getText( R.string.actionShare_title ) );
}
};
new Builder( this ).setTitle( title ).setMessage( message.toString() )
.setNeutralButton( R.string.actionShare_title, shareHandler ).create().show();
}
private void popupAppVersion()
{
String title = getString( R.string.menuItem_appVersion );
String message = getString( R.string.popup_version, mAppData.appVersion,
mAppData.appVersionCode );
new Builder( this ).setTitle( title ).setMessage( message ).create().show();
}
@Override
protected void onResume()
{
@@ -0,0 +1,85 @@
/**
* Mupen64PlusAE, an N64 emulator for the Android platform
*
* Copyright (C) 2013 Paul Lamb
*
* This file is part of Mupen64PlusAE.
*
* Mupen64PlusAE is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Mupen64PlusAE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Mupen64PlusAE. If
* not, see <http://www.gnu.org/licenses/>.
*
* Authors: littleguy77
*/
package paulscode.android.mupen64plusae.dialog;
import org.mupen64plusae.v3.alpha.R;
import paulscode.android.mupen64plusae.ActivityHelper;
import paulscode.android.mupen64plusae.persistent.AppData;
import paulscode.android.mupen64plusae.util.DeviceUtil;
import android.annotation.SuppressLint;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
public class Popups
{
public static void showFaq( Context context )
{
CharSequence title = context.getText( R.string.menuItem_faq );
CharSequence message = context.getText( R.string.popup_faq );
new Builder( context ).setTitle( title ).setMessage( message ).create().show();
}
public static void showLogcat( Context context )
{
String title = context.getString( R.string.menuItem_logcat );
String message = DeviceUtil.getLogCat();
showShareableText( context, title, message );
}
public static void showHardwareInfo( Context context )
{
String title = context.getString( R.string.menuItem_hardwareInfo );
String axisInfo = DeviceUtil.getAxisInfo();
String peripheralInfo = DeviceUtil.getPeripheralInfo();
String cpuInfo = DeviceUtil.getCpuInfo();
String message = axisInfo + peripheralInfo + cpuInfo;
showShareableText( context, title, message );
}
public static void showShareableText( final Context context, String title, final String message )
{
// Set up click handler to share text with a user-selected app (email, clipboard, etc.)
DialogInterface.OnClickListener shareHandler = new DialogInterface.OnClickListener()
{
@SuppressLint( "InlinedApi" )
@Override
public void onClick( DialogInterface dialog, int which )
{
ActivityHelper.launchPlainText( context, message,
context.getText( R.string.actionShare_title ) );
}
};
new Builder( context ).setTitle( title ).setMessage( message.toString() )
.setNeutralButton( R.string.actionShare_title, shareHandler ).create().show();
}
public static void showAppVersion( Context context )
{
AppData appData = new AppData( context );
String title = context.getString( R.string.menuItem_appVersion );
String message = context.getString( R.string.popup_version, appData.appVersion,
appData.appVersionCode );
new Builder( context ).setTitle( title ).setMessage( message ).create().show();
}
}

0 comments on commit 349a17a

Please sign in to comment.