Project

General

Profile

Download (5.71 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / helpers / BaseActivity.java @ a5972f92

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2024 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.helpers;
11

    
12
import android.content.res.Configuration;
13
import android.os.Build;
14
import android.os.Bundle;
15
import android.util.DisplayMetrics;
16
import android.view.View;
17
import android.view.ViewGroup;
18
import android.view.WindowManager;
19
import android.widget.LinearLayout;
20

    
21
import androidx.appcompat.app.AppCompatActivity;
22

    
23
import org.distorted.main.R;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
public class BaseActivity extends AppCompatActivity
28
{
29
    public static final float RATIO_BAR = 0.080f;
30
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
31
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
32
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
33
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
34
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
35

    
36
    private int mCurrentApiVersion;
37
    protected int mScreenWidth, mScreenHeight;
38
    protected int mHeightLowerBar, mHeightUpperBar;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
    @Override
43
    protected void onCreate(Bundle savedState)
44
      {
45
      setTheme(R.style.MaterialThemeNoActionBar);
46
      super.onCreate(savedState);
47
      }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
    protected void getWindowWidth(Configuration conf)
52
      {
53
      int dpi = getResources().getDisplayMetrics().densityDpi;
54
      float conv = ((float) dpi/DisplayMetrics.DENSITY_DEFAULT);
55

    
56
      mScreenWidth = (int) (conf.screenWidthDp*conv + 0.5f);
57
      mScreenHeight= (int) (conf.screenHeightDp*conv + 0.5f);
58
      }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
    protected void computeScreenDimensions()
63
      {
64
      DisplayMetrics displaymetrics = new DisplayMetrics();
65
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
66
      mScreenWidth =displaymetrics.widthPixels;
67
      mScreenHeight=displaymetrics.heightPixels;
68
      }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
    protected void computeLowerBarHeight(float ratio)
73
      {
74
      int barHeight = (int)(mScreenHeight*ratio);
75
      mHeightLowerBar = barHeight;
76

    
77
      LinearLayout layout = findViewById(R.id.lowerBar);
78
      ViewGroup.LayoutParams params = layout.getLayoutParams();
79
      params.height = barHeight;
80
      layout.setLayoutParams(params);
81
      }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
// this does not include possible insets
85

    
86
    protected void computeUpperBarHeight(float ratio)
87
      {
88
      int barHeight = (int)(mScreenHeight*ratio);
89
      mHeightUpperBar = barHeight;
90

    
91
      LinearLayout layout = findViewById(R.id.upperBar);
92
      ViewGroup.LayoutParams params = layout.getLayoutParams();
93
      params.height = barHeight;
94
      layout.setLayoutParams(params);
95
      }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
    protected void hideNavigationBar()
100
      {
101
      mCurrentApiVersion = Build.VERSION.SDK_INT;
102

    
103
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
104
        {
105
        final View decorView = getWindow().getDecorView();
106

    
107
        decorView.setSystemUiVisibility(FLAGS);
108

    
109
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
110
          {
111
          @Override
112
          public void onSystemUiVisibilityChange(int visibility)
113
            {
114
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
115
              {
116
              decorView.setSystemUiVisibility(FLAGS);
117
              }
118
            }
119
          });
120
        }
121
      }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
// do not avoid cutouts
125

    
126
    protected void cutoutHack()
127
      {
128
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
129
        {
130
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
131
        }
132
      }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
    @Override
137
    public void onWindowFocusChanged(boolean hasFocus)
138
      {
139
      super.onWindowFocusChanged(hasFocus);
140

    
141
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
142
        {
143
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
144
        }
145
      }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
    public int getScreenWidthInPixels()
150
      {
151
      return mScreenWidth;
152
      }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
    public int getScreenHeightInPixels()
157
      {
158
      return mScreenHeight;
159
      }
160

    
161
}
(1-1/6)