- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 Android 的新手,我有一个 Android 应用程序,我在该应用程序上添加了一个“启动画面”,然后加载了 MainActivity。但是 MainActivity 需要额外的 5-6 秒来加载。
MainActivity 的内容是否有可能加载到启动画面中,并且当启动画面结束时它应该显示 MainActivity 而无需额外的 5-6 秒。
请帮帮我,我已经添加了 MainActivity 和启动画面的代码。如果您编辑我的代码并给我完美的代码,那将是您对我最大的善意。
提前致谢。
主 Activity
public class MainActivity extends AppCompatActivity implements MenuItemCallback, ConfigParser.CallBack
{
private static final int PERMISSION_REQUESTCODE = 123;
//Layout
public Toolbar mToolbar;
private TabLayout tabLayout;
private DisableableViewPager viewPager;
private NavigationView navigationView;
public DrawerLayout drawer;
private ActionBarDrawerToggle toggle;
//Adapters
private TabAdapter adapter;
private static SimpleMenu menu;
//Keep track of the interstitials we show
private int interstitialCount = -1;
private InterstitialAd mInterstitialAd;
//Data to pass to a fragment
public static String FRAGMENT_DATA = "transaction_data";
public static String FRAGMENT_CLASS = "transation_target";
//Permissions Queu
List<NavItem> queueItem;
int queueMenuItemId;
//InstanceState (rotation)
private Bundle savedInstanceState;
private static final String STATE_MENU_INDEX = "MENUITEMINDEX";
private static final String STATE_PAGER_INDEX = "VIEWPAGERPOSITION";
private static final String STATE_ACTIONS = "ACTIONS";
@Override
public void configLoaded( boolean facedException )
{
if ( facedException || menu.getFirstMenuItem() == null ) {
if ( Helper.isOnlineShowDialog( MainActivity.this ) )
Toast.makeText( this, R.string.invalid_configuration, Toast.LENGTH_LONG ).show();
} else {
if ( savedInstanceState == null ) {
menuItemClicked( menu.getFirstMenuItem(), 0, false );
} else {
ArrayList<NavItem> actions = (ArrayList<NavItem>) savedInstanceState.getSerializable( STATE_ACTIONS );
int menuItemId = savedInstanceState.getInt( STATE_MENU_INDEX );
int viewPagerPosition = savedInstanceState.getInt( STATE_PAGER_INDEX );
menuItemClicked( actions, menuItemId, false );
viewPager.setCurrentItem( viewPagerPosition );
}
}
}
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
this.savedInstanceState = savedInstanceState;
//Load the appropriate layout
if ( useTabletMenu() ) {
setContentView( R.layout.activity_main_tablet );
Helper.setStatusBarColor( MainActivity.this,
ContextCompat.getColor( this, R.color.myPrimaryDarkColor ) );
} else {
setContentView( R.layout.activity_main );
}
mToolbar = findViewById( R.id.toolbar );
setSupportActionBar( mToolbar );
if ( !useTabletMenu() )
getSupportActionBar().setDisplayShowHomeEnabled( true );
else {
getSupportActionBar().setDisplayShowHomeEnabled( false );
}
if ( Config.HIDE_TOOLBAR ) {
getSupportActionBar().hide();
}
//Drawer
if ( !useTabletMenu() ) {
drawer = findViewById( R.id.drawer );
toggle = new ActionBarDrawerToggle(
this, drawer, mToolbar, R.string.drawer_open, R.string.drawer_close );
drawer.setDrawerListener( toggle );
toggle.syncState();
}
//Layouts
tabLayout = findViewById( R.id.tabs );
viewPager = findViewById( R.id.viewpager );
//Check if we should open a fragment based on the arguments we have
if ( getIntent().getExtras() != null && getIntent().getExtras().containsKey( FRAGMENT_CLASS ) ) {
try {
Class<? extends Fragment> fragmentClass = (Class<? extends Fragment>) getIntent().getExtras().getSerializable( FRAGMENT_CLASS );
if ( fragmentClass != null ) {
String[] extra = getIntent().getExtras().getStringArray( FRAGMENT_DATA );
HolderActivity.startActivity( this, fragmentClass, extra );
finish();
//Optionally, we can also point intents to holderactivity directly instead of MainAc.
}
} catch ( Exception e ) {
//If we come across any errors, just continue and open the default fragment
Log.printStackTrace( e );
}
}
//Menu items
navigationView = findViewById( R.id.nav_view );
menu = new SimpleMenu( navigationView.getMenu(), this );
if ( Config.USE_HARDCODED_CONFIG ) {
Config.configureMenu( menu, this );
} else if ( !Config.CONFIG_URL.isEmpty() && Config.CONFIG_URL.contains( "http" ) )
new ConfigParser( Config.CONFIG_URL, menu, this, this ).execute();
else
new ConfigParser( "config.json", menu, this, this ).execute();
tabLayout.setupWithViewPager( viewPager );
if ( !useTabletMenu() ) {
drawer.setStatusBarBackgroundColor(
ContextCompat.getColor( this, R.color.myPrimaryDarkColor ) );
}
applyDrawerLocks();
//Ads
Helper.admobLoader( this, findViewById( R.id.adView ) );
if ( getResources().getString( R.string.admob_interstitial_id ).length() > 0
&& Config.INTERSTITIAL_INTERVAL > 0
&& !SettingsFragment.getIsPurchased( this ) ) {
mInterstitialAd = new InterstitialAd( this );
mInterstitialAd.setAdUnitId( getResources().getString( R.string.admob_interstitial_id ) );
AdRequest adRequestInter = new AdRequest.Builder().addTestDevice( AdRequest.DEVICE_ID_EMULATOR ).build();
mInterstitialAd.loadAd( adRequestInter );
mInterstitialAd.setAdListener( new AdListener()
{
@Override
public void onAdClosed()
{
// Load the next interstitial.
mInterstitialAd.loadAd( new AdRequest.Builder().addTestDevice( AdRequest.DEVICE_ID_EMULATOR ).build() );
}
} );
}
Helper.updateAndroidSecurityProvider( this );
viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener()
{
public void onPageScrollStateChanged( int state )
{
}
public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels )
{
}
public void onPageSelected( int position )
{
onTabBecomesActive( position );
}
} );
}
@SuppressLint("NewApi")
@Override
public void onRequestPermissionsResult( int requestCode, String[] permissions, int[] grantResults )
{
switch ( requestCode ) {
case PERMISSION_REQUESTCODE:
boolean allGranted = true;
for ( int grantResult : grantResults ) {
if ( grantResult != PackageManager.PERMISSION_GRANTED ) {
allGranted = false;
}
}
if ( allGranted ) {
//Retry to open the menu item
menuItemClicked( queueItem, queueMenuItemId, false );
} else {
// Permission Denied
Toast.makeText( MainActivity.this, getResources().getString( R.string.permissions_required ), Toast.LENGTH_SHORT )
.show();
}
break;
default:
super.onRequestPermissionsResult( requestCode, permissions, grantResults );
}
}
@Override
public void menuItemClicked( List<NavItem> actions, int menuItemIndex, boolean requiresPurchase )
{
// Checking the drawer should be open on start
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( getBaseContext() );
boolean openOnStart = Config.DRAWER_OPEN_START || prefs.getBoolean( "menuOpenOnStart", false );
if ( drawer != null ) {
boolean firstClick = ( savedInstanceState == null && adapter == null );
if ( openOnStart && !useTabletMenu() && firstClick ) {
drawer.openDrawer( GravityCompat.START );
} else {
//Close the drawer
drawer.closeDrawer( GravityCompat.START );
}
}
//Check if the user is allowed to open item
if ( requiresPurchase && !isPurchased() ) return; //isPurchased will handle this.
if ( !checkPermissionsHandleIfNeeded( actions, menuItemIndex ) )
return; //checkPermissions will handle.
if ( isCustomIntent( actions ) ) return;
//Uncheck all other items, check the current item
for ( MenuItem menuItem : menu.getMenuItems() ) {
if ( menuItem.getItemId() == menuItemIndex ) {
menuItem.setChecked( true );
} else
menuItem.setChecked( false );
}
//Load the new tab
adapter = new TabAdapter( getSupportFragmentManager(), actions, this );
viewPager.setAdapter( adapter );
//Show or hide the tab bar depending on if we need it
if ( actions.size() == 1 ) {
tabLayout.setVisibility( View.GONE );
viewPager.setPagingEnabled( false );
} else {
tabLayout.setVisibility( View.VISIBLE );
viewPager.setPagingEnabled( true );
}
( (CustomAppBarLayout) mToolbar.getParent() ).setExpanded( true, true );
//Show in interstitial
showInterstitial();
onTabBecomesActive( 0 );
}
private void onTabBecomesActive( int position )
{
Fragment fragment = adapter.getItem( position );
//If fragment does not support collapse, or if OS does not support collapse, disable collapsing toolbar
if ( ( fragment instanceof CollapseControllingFragment
&& !( (CollapseControllingFragment) fragment ).supportsCollapse() )
||
( android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ) )
lockAppBar();
else
unlockAppBar();
if ( position != 0 )
showInterstitial();
}
/**
* Show an interstitial ad
*/
public void showInterstitial()
{
if ( interstitialCount == ( Config.INTERSTITIAL_INTERVAL - 1 ) ) {
if ( mInterstitialAd != null && mInterstitialAd.isLoaded() ) {
mInterstitialAd.show();
}
interstitialCount = 0;
} else {
interstitialCount++;
}
}
/**
* Checks if the item is/contains a custom intent, and if that the case it will handle it.
*
* @param items List of NavigationItems
* @return True if the item is a custom intent, in that case
*/
private boolean isCustomIntent( List<NavItem> items )
{
NavItem customIntentItem = null;
for ( NavItem item : items ) {
if ( CustomIntent.class.isAssignableFrom( item.getFragment() ) ) {
customIntentItem = item;
}
}
if ( customIntentItem == null ) return false;
if ( items.size() > 1 )
Log.e( "INFO", "Custom Intent Item must be only child of menu item! Ignorning all other tabs" );
CustomIntent.performIntent( MainActivity.this, customIntentItem.getData() );
return true;
}
/**
* If the item can be opened because it either has been purchased or does not require a purchase to show.
*
* @return true if the app is purchased. False if the app hasn't been purchased, or if iaps are disabled
*/
private boolean isPurchased()
{
String license = getResources().getString( R.string.google_play_license );
// if item does not require purchase, or app has purchased, or license is null/empty (app has no in app purchases)
if ( !SettingsFragment.getIsPurchased( this ) && !license.equals( "" ) ) {
String[] extra = new String[]{ SettingsFragment.SHOW_DIALOG };
HolderActivity.startActivity( this, SettingsFragment.class, extra );
return false;
}
return true;
}
/**
* Checks if the item can be opened because it has sufficient permissions.
*
* @param tabs The tabs to check
* @return true if the item is safe to open
*/
private boolean checkPermissionsHandleIfNeeded( List<NavItem> tabs, int menuItemId )
{
if ( android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M ) return true;
List<String> allPermissions = new ArrayList<>();
for ( NavItem tab : tabs ) {
if ( PermissionsFragment.class.isAssignableFrom( tab.getFragment() ) ) {
try {
for ( String permission : ( (PermissionsFragment) tab.getFragment().newInstance() ).requiredPermissions() ) {
if ( !allPermissions.contains( permission ) )
allPermissions.add( permission );
}
} catch ( Exception e ) {
//Don't really care
}
}
}
if ( allPermissions.size() > 1 ) {
boolean allGranted = true;
for ( String permission : allPermissions ) {
if ( checkSelfPermission( permission ) != PackageManager.PERMISSION_GRANTED )
allGranted = false;
}
if ( !allGranted ) {
requestPermissions( allPermissions.toArray( new String[ 0 ] ), PERMISSION_REQUESTCODE );
queueItem = tabs;
queueMenuItemId = menuItemId;
return false;
}
return true;
}
return true;
}
@Override
public boolean onCreateOptionsMenu( Menu menu )
{
MenuInflater inflater = getMenuInflater();
inflater.inflate( R.menu.settings_menu, menu );
return true;
}
@Override
public boolean onOptionsItemSelected( MenuItem item )
{
// Handle item selection
switch ( item.getItemId() ) {
case R.id.settings:
HolderActivity.startActivity( this, SettingsFragment.class, null );
return true;
case R.id.favorites:
HolderActivity.startActivity( this, FavFragment.class, null );
return true;
default:
return super.onOptionsItemSelected( item );
}
}
@Override
public void onBackPressed()
{
Fragment activeFragment = null;
if ( adapter != null )
activeFragment = adapter.getCurrentFragment();
if ( drawer != null && drawer.isDrawerOpen( GravityCompat.START ) ) {
drawer.closeDrawer( GravityCompat.START );
} else if ( activeFragment instanceof BackPressFragment ) {
boolean handled = ( (BackPressFragment) activeFragment ).handleBackPress();
if ( !handled ) {
super.onBackPressed();
}
} else {
super.onBackPressed();
}
}
@Override
protected void onActivityResult( int requestCode, int resultCode, Intent data )
{
super.onActivityResult( requestCode, resultCode, data );
List<Fragment> fragments = getSupportFragmentManager().getFragments();
if ( fragments != null )
for ( Fragment frag : fragments )
if ( frag != null )
frag.onActivityResult( requestCode, resultCode, data );
}
@Override
public void onConfigurationChanged( Configuration newConfig )
{
super.onConfigurationChanged( newConfig );
if ( adapter != null && !( adapter.getCurrentFragment() instanceof ConfigurationChangeFragment ) ) {
this.recreate();
}
}
@Override
protected void onSaveInstanceState( Bundle outState )
{
super.onSaveInstanceState( outState );
if ( adapter == null ) return;
int menuItemIndex = 0;
for ( MenuItem menuItem : menu.getMenuItems() ) {
if ( menuItem.isChecked() ) {
menuItemIndex = menuItem.getItemId();
break;
}
}
outState.putSerializable( STATE_ACTIONS, ( (ArrayList<NavItem>) adapter.getActions() ) );
outState.putInt( STATE_MENU_INDEX, menuItemIndex );
outState.putInt( STATE_PAGER_INDEX, viewPager.getCurrentItem() );
}
//Check if we should adjust our layouts for tablets
public boolean useTabletMenu()
{
return ( getResources().getBoolean( R.bool.isWideTablet ) && Config.TABLET_LAYOUT );
}
//Apply the appropiate locks to the drawer
public void applyDrawerLocks()
{
if ( drawer == null ) {
if ( Config.HIDE_DRAWER )
navigationView.setVisibility( View.GONE );
return;
}
if ( Config.HIDE_DRAWER ) {
toggle.setDrawerIndicatorEnabled( false );
drawer.setDrawerLockMode( DrawerLayout.LOCK_MODE_LOCKED_CLOSED );
} else {
drawer.setDrawerLockMode( DrawerLayout.LOCK_MODE_UNLOCKED );
}
}
private void lockAppBar()
{
AppBarLayout.LayoutParams params =
(AppBarLayout.LayoutParams) mToolbar.getLayoutParams();
params.setScrollFlags( 0 );
}
private void unlockAppBar()
{
AppBarLayout.LayoutParams params =
(AppBarLayout.LayoutParams) mToolbar.getLayoutParams();
params.setScrollFlags( AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
| AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS );
}
}
启动画面
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
最佳答案
use this code inside the splashActivity
public class SplashScreen extends AppCompatActivity {
private static int SPLASH_TIME_OUT=5000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.AppTheme);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
SplashScreen.this.startActivity(new Intent(SplashScreen.this,MainActivity.class));
SplashScreen.this.finish();
finish();
}
},SPLASH_TIME_OUT);
}
}
关于java - MainActivity 应在启动画面期间加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52116292/
我有一个表,用于测量数据集中两个不同值的分布百分比(我有一个计数,替换为 Percentage )。我只想在仪表板中发布 85% 的值。这样做的步骤是什么? .现在,如果我过滤掉 NO 值, YES
我想平均N通过Type对于 Inst 的值 我的数据设置为: Type, Inst, N A, A1, 4 A, A1, 13 A, A1, 13 A, A2, 4 A, A3, 5 B, B1, 4
当我使用 Node 的 http2 库(仅支持 HTTPS,不支持 HTTP)进行开发时,当我在 Chrome 中打开 localhost 时,我会看到一个警告屏幕: Your connection
我想创建一个具有响应式布局的导航栏菜单。当网站显示在显示器上时,我想播放导航栏。当网站在手机上显示时,我会显示最终显示导航栏的菜单图标。 我该怎么做? 最佳答案 试试这个,在移动设备上,导航栏不仅会显
我聘请了一名程序员为我创建一个 iPhone 应用程序。该应用程序的目的是拍照并将其上传到服务器。我们想制作一个特殊用途的屏幕,以便在上传照片之前查看照片。这个专门开发的屏幕将具有至关重要的缩放功能。
我在 Tableau 上有一个我无法解决的简单问题。 我想显示一个图表,显示随时间变化的度量。我想将用户通过参数选择的一个客户端与未选择的所有其他客户端进行比较。该图将显示具有 2 种不同颜色的两条线
我使用 Python 脚本从 3 个不同的 RDS 执行一系列复杂查询,然后将数据导出到一个 CSV 文件中。我现在正在尝试找到一种方法,每周将使用这些数据的仪表板自动发布到 Tableau 服务器中
我在工作中使用 tableau 来处理各种数据类型,包括敏感的个人数据,这些数据只能以聚合格式共享。我试图找到一种方法来保护私有(private)信息,方法是在单元格值小于 5 时隐藏它。这样,当用户
我最近开始在网站上嵌入 Tableau 可视化效果,并遇到了在浏览器中直接使用 Control + P 打印它们的问题。大多数完全扭曲,如果有的话。我做了一些挖掘,发现这是一个已知问题: http:/
例如,此 URL 包含十几个项目:https://tableautest.domain.uk/t/CustomerSharing/view/projects 在每个项目中都有几个工作簿。每个工作簿中都
我正在研究如何使用 Tableau 连接到 Cloudera Hadoop。我提供服务器和端口详细信息并使用“Impala”进行连接。我能够成功连接,选择默认模式并选择所需的表。 在此之后,当我将维度
我正在尝试将 Tableau 工作表嵌入到我的 ReactJS 应用程序中。我有一个包含报告名称列表的菜单(在 react 中),当单击菜单项时,它会更新包含报告名称的状态。我决定使用 tableau
我有以下问题!我有一个这样的表: Data Source 我想创建一个可以获取 apl_id 的字段(我想这是一个字段),有一些我想要的 service_offered。 上表中的示例。如果我想要只有
我有一个航类延误数据电子表格,我正在处理一个显示每个机场总延误时间的工作表。我想过滤维度“机场”,即根据每个机场的起飞次数创建机场类别,“小型”、“中型”和“大型”,这是通过计算维度“航类号”计算得出
我想创建一个带有过滤器的表格,用于选择和比较事物: 假设我有一个变量 Var,包含值 A、B、C、D、E。我想要一个过滤器,以便用户可以选择 A B C D 之一,同时 E 始终被选中。这样选中的E和
我是一名优秀的程序员,十分优秀!