Example usage for com.badlogic.gdx.backends.android AndroidGraphics AndroidGraphics

List of usage examples for com.badlogic.gdx.backends.android AndroidGraphics AndroidGraphics

Introduction

In this page you can find the example usage for com.badlogic.gdx.backends.android AndroidGraphics AndroidGraphics.

Prototype

public AndroidGraphics(AndroidApplicationBase application, AndroidApplicationConfiguration config,
            ResolutionStrategy resolutionStrategy) 

Source Link

Usage

From source file:de.cachebox_test.main.java

License:Open Source License

/**
 * Called when the activity is first created.
 *//*from w w w .  j a  va 2  s . c o m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GL.resetIsInitial();

    if (GlobalCore.RunFromSplash) {
        Log.info(log, "CACHEBOX: " + "main-OnCreate Run from Splash");
    } else {
        Log.info(log, "CACHEBOX: " + "main-OnCreate illegal-Run");
        // run splash
        Intent mainIntent = new Intent().setClass(main.this, de.cachebox_test.splash.class);
        startActivity(mainIntent);
        finish();
        return;
    }

    mainActivity = this;

    if (savedInstanceState != null) {
        // restore ACB after Kill
        Log.debug(log, "restore ACB after Kill");

        GlobalCore.restartAfterKill = true;
        GlobalCore.isTab = savedInstanceState.getBoolean("isTab");
        GlobalCore.useSmallSkin = savedInstanceState.getBoolean("useSmallSkin");
        String workPath = savedInstanceState.getString("WorkPath");

        // Read Config
        Config.Initialize(workPath, workPath + "/cachebox.config");

        // hier muss die Config Db initialisiert werden
        Database.Settings = new AndroidDB(DatabaseType.Settings, this);
        if (!FileIO.createDirectory(Config.mWorkPath + "/User"))
            return;
        Database.Settings.StartUp(Config.mWorkPath + "/User/Config.db3");
        // initialize Database
        Database.Data = new AndroidDB(DatabaseType.CacheBox, this);
        Database.FieldNotes = new AndroidDB(DatabaseType.FieldNotes, this);

        Config.AcceptChanges();

        Resources res = this.getResources();
        DevicesSizes ui = new DevicesSizes();

        ui.Window = new Size(savedInstanceState.getInt("WindowWidth"),
                savedInstanceState.getInt("WindowHeight"));
        ui.Density = res.getDisplayMetrics().density;

        ui.isLandscape = false;

        new UiSizes();

        UI_Size_Base.that.initial(ui);

        Global.Paints.init(this);
        Global.InitIcons(this);

        GlobalCore.restartCache = savedInstanceState.getString("selectedCacheID");
        GlobalCore.restartWaypoint = savedInstanceState.getString("selectedWayPoint");

    } else {
        GlobalCore.restartAfterKill = false;
    }

    ActivityUtils.onActivityCreateSetTheme(this);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (GlobalCore.isTab) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    // initialize receiver for screen switched on/off
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);

    if (mReceiver == null) {
        mReceiver = new ScreenReceiver();
        registerReceiver(mReceiver, filter);
    }

    // N = Config.nightMode.getValue();

    setContentView(GlobalCore.isTab ? R.layout.tab_main : R.layout.main);

    findViewsById();
    initialPlatformConector();

    inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mainActivity.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // create new splash
    splash sp = new splash(0, 0, UI_Size_Base.that.getWindowWidth(), UI_Size_Base.that.getWindowHeight(),
            "Splash");

    // create new mainView
    TabMainView ma = new TabMainView(0, 0, UI_Size_Base.that.getWindowWidth(),
            UI_Size_Base.that.getWindowHeight(), "mainView");

    glListener = new GL(UI_Size_Base.that.getWindowWidth(), UI_Size_Base.that.getWindowHeight(), sp, ma);

    int Time = Config.ScreenLock.getValue();
    counter = new ScreenLockTimer(Time, Time);
    counter.start();

    // add Event Handler
    SelectedCacheEventList.Add(this);
    CacheListChangedEventList.Add(this);
    // GpsStateChangeEventList.Add(this);

    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);

    Config.AcceptChanges();

    AndroidSettings.RunOverLockScreen.addChangedEventListener(new IChanged() {
        @Override
        public void isChanged() {
            setLockScreenProperty();
        }
    });

    // Initial Android TexturePacker
    new Android_Packer();

    initialLocationManager();

    initalMicIcon();

    glListener.onStart();
    if (tabFrame != null)
        tabFrame.setVisibility(View.INVISIBLE);
    if (frame != null)
        frame.setVisibility(View.INVISIBLE);

    InfoDownSlider.invalidate();

    CacheListChangedEvent();

    try {
        this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    } catch (Exception e) {
        // sometimes:
        // ERROR/ActivityThread(15416): Activity de.cachebox_test.main has
        // leaked IntentReceiver
        // de.cachebox_test.main$7@4745a0f0 that was originally registered
        // here.
        // Are you missing a call to unregisterReceiver()?
    }

    downSlider.isInitial = false;

    int sollHeight = (Config.quickButtonShow.getValue() && Config.quickButtonLastShow.getValue())
            ? UiSizes.that.getQuickButtonListHeight()
            : 0;

    setQuickButtonHeight(sollHeight);

    if (isFirstStart) {
        // ask for API key only if Rev-Number changed, like at new
        // installation and API Key is Empty
        if (Config.newInstall.getValue() && Config.GetAccessToken().equals("")) {
            askToGetApiKey();
        } else {
            if (!GlobalCore.restartAfterKill)
                chkGpsIsOn();
        }

        if (Config.newInstall.getValue()) {
            // wait for Copy Asset is closed
            CheckTranslationIsLoaded();
            Timer tim = new Timer();
            TimerTask timTask = new TimerTask() {

                @Override
                public void run() {

                    mainActivity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            String Welcome = "";
                            String LangId = getString(R.string.langId);
                            try {
                                Welcome = Translation.GetTextFile("welcome", LangId);

                                Welcome += Translation.GetTextFile("changelog", LangId);
                            } catch (IOException e1) {
                                e1.printStackTrace();
                            }

                            MessageBox.Show(Welcome, Translation.Get("welcome"), MessageBoxIcon.None);
                        }
                    });

                }
            };

            tim.schedule(timTask, 5000);

        }

        if (input == null) {
            graphics = new AndroidGraphics(this, gdxConfig,
                    gdxConfig.resolutionStrategy == null ? new FillResolutionStrategy()
                            : gdxConfig.resolutionStrategy);

            input = new AndroidInput(this, this.inflater.getContext(), graphics.getView(), gdxConfig);

        }

    }

    if (aktView != null)
        ((View) aktView).setVisibility(View.INVISIBLE);
    if (aktTabView != null)
        ((View) aktTabView).setVisibility(View.INVISIBLE);
    if (InfoDownSlider != null)
        ((View) InfoDownSlider).setVisibility(View.INVISIBLE);
    if (cacheNameView != null)
        ((View) cacheNameView).setVisibility(View.INVISIBLE);

    initialViewGL();
}

From source file:de.cachebox_test.main.java

License:Open Source License

@Override
protected void onPause() {
    Log.info(log, "Main=> onPause");

    stopped = true;//from   www  .j av  a  2s .co  m

    unbindPluginServices();

    if (input == null) {
        graphics = new AndroidGraphics(this, gdxConfig,
                gdxConfig.resolutionStrategy == null ? new FillResolutionStrategy()
                        : gdxConfig.resolutionStrategy);
        input = new AndroidInput(this, this.inflater.getContext(), graphics.getView(), gdxConfig);
    }

    if (isFinishing()) {
        if (mConnection != null) {
            unbindService(mConnection);
            mConnection = null;
        }

    }

    super.onPause();

    Log.debug(log, "Main=> onPause release SuppressPowerSaving");

    try {
        if (this.mWakeLock != null)
            this.mWakeLock.release();
    } catch (Exception e) {
        // dann ebend nicht!
    }
}

From source file:de.cachebox_test.main.java

License:Open Source License

@Override
protected void onResume() {
    viewGL.RenderContinous();//w w w .  j  a va 2s  . c o m
    if (stopped) {
        showWaitToRenderStartet();
        invalidateTextureEventList.Call();
    }

    Log.debug(log, "Main=> onResume");
    if (input == null) {
        Log.debug(log, "Main=> onResume input== null");

        graphics = new AndroidGraphics(this, gdxConfig,
                gdxConfig.resolutionStrategy == null ? new FillResolutionStrategy()
                        : gdxConfig.resolutionStrategy);
        input = new AndroidInput(this, this.inflater.getContext(), graphics.getView(), gdxConfig);
    }

    super.onResume();

    if (counter != null) {
        if (runsWithAkku) {
            counter.start();
        } else {
            counter.cancel();
        }
    }

    if (mSensorManager != null)
        mSensorManager.registerListener(mListener, mSensor, SensorManager.SENSOR_DELAY_UI);
    this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    int sollHeight = (Config.quickButtonShow.getValue() && Config.quickButtonLastShow.getValue())
            ? UiSizes.that.getQuickButtonListHeight()
            : 0;
    ((main) main.mainActivity).setQuickButtonHeight(sollHeight);
    downSlider.isInitial = false;
    InfoDownSlider.invalidate();

    // Ausschalten verhindern
    /*
     * This code together with the one in onDestroy() will make the screen
     * be always on until this Activity gets destroyed.
     */
    if (Config.SuppressPowerSaving.getValue()) {
        Log.debug(log, "Main=> onResume SuppressPowerSaving");
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        int flags = PowerManager.SCREEN_BRIGHT_WAKE_LOCK;
        this.mWakeLock = pm.newWakeLock(flags, "Cachebox");
        this.mWakeLock.acquire();
    }

    Config.SuppressPowerSaving.addChangedEventListener(new IChanged() {

        @Override
        public void isChanged() {
            if (Config.SuppressPowerSaving.getValue()) {
                Log.debug(log, "Main=> onResume SuppressPowerSaving");
                final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                int flags = PowerManager.SCREEN_BRIGHT_WAKE_LOCK;
                main.this.mWakeLock = pm.newWakeLock(flags, "Cachebox");
                main.this.mWakeLock.acquire();

            } else {
                final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                main.this.mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Cachebox non Powersave");
                main.this.mWakeLock.acquire();
            }
        }
    });

    try {
        initialOnTouchListener();
    } catch (Exception e) {
        Log.err(log, "onResume", "initialOnTouchListener", e);
    }

    // Initial PlugIn
    fillPluginList();
    bindPluginServices();

    final Bundle extras = getIntent().getExtras();
    if (!GlobalCore.restartAfterKill || extras != null) {
        ExtSearch_GcCode = extras.getString("GcCode");
        ExtSearch_GpxPath = extras.getString("GpxPath");
        if (ExtSearch_GpxPath != null)
            Log.info(log, "GPX found: " + ExtSearch_GpxPath);

        if (ExtSearch_GcCode != null || ExtSearch_GpxPath != null) {
            mustRunSearch = true;

            // ACB running call search
            if (TabMainView.that.isInitial()) {
                PlatformConnector.FirstShow();
            }
        }

        // delete handled extras
        getIntent().removeExtra("GcCode");
        getIntent().removeExtra("GpxPath");
    }
    GL.that.RestartRender();
}