Skip to content

Commit

Permalink
Move layout generation to its own class (0.6.0.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriDellal committed Oct 13, 2018
1 parent 78de747 commit 6f5710e
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 94 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="36"
android:versionName="0.6.0" package="ru.henridellal.emerald"
android:versionCode="37"
android:versionName="0.6.0.1" package="ru.henridellal.emerald"
>

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>
Expand Down
96 changes: 4 additions & 92 deletions app/src/main/java/ru/henridellal/emerald/Apps.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,24 @@
//import android.util.Log;
import android.view.GestureDetector;
import android.view.inputmethod.InputMethodManager;
import android.view.LayoutInflater;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class Apps extends Activity
{
private GestureDetector gestureDetector;
private CategoryManager categories;
private ArrayList<BaseData> curCatData;
private RelativeLayout mainLayout;
private GridView grid;
private Dock dock;
public SharedPreferences options;
Expand Down Expand Up @@ -802,90 +796,6 @@ protected void onNewIntent(Intent i) {
super.onNewIntent(i);
}

private void layoutInit() {
mainLayout = new RelativeLayout(this);
LayoutInflater layoutInflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LinearLayout dockBar = (LinearLayout) layoutInflater.inflate(R.layout.dock_bar, mainLayout, false);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(dockBar.getLayoutParams());
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
dockBar.setLayoutParams(layoutParams);
dockBar.setBackgroundColor(options.getInt(Keys.DOCK_BACKGROUND, 0x22000000));
mainLayout.addView(dockBar);

FrameLayout mainBar = (FrameLayout) layoutInflater.inflate(R.layout.main_bar, mainLayout, false);
grid = (GridView) layoutInflater.inflate(R.layout.apps_grid, mainLayout, false);
boolean kitkatNoImmersiveMode = (Build.VERSION.SDK_INT == 19 && !options.getBoolean(Keys.FULLSCREEN, false));
if (options.getBoolean(Keys.BOTTOM_MAIN_BAR, true)) {
layoutParams = new RelativeLayout.LayoutParams(mainBar.getLayoutParams());
layoutParams.addRule(RelativeLayout.ABOVE, R.id.dock_bar);
mainBar.setLayoutParams(layoutParams);
mainLayout.addView(mainBar);

if (kitkatNoImmersiveMode) {
View fakeStatusBar = layoutInflater.inflate(R.layout.kitkat_status_bar, mainLayout, false);
fakeStatusBar.setBackgroundColor(options.getInt(Keys.STATUS_BAR_BACKGROUND, 0x22000000));
layoutParams = new RelativeLayout.LayoutParams(fakeStatusBar.getLayoutParams());
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
fakeStatusBar.setLayoutParams(layoutParams);
mainLayout.addView(fakeStatusBar);
}
layoutParams = new RelativeLayout.LayoutParams(grid.getLayoutParams());
if (kitkatNoImmersiveMode) {
layoutParams.addRule(RelativeLayout.BELOW, R.id.kitkat_status_bar);
} else {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
}
layoutParams.addRule(RelativeLayout.ABOVE, R.id.main_bar);
grid.setLayoutParams(layoutParams);
mainLayout.addView(grid);
} else {
if (!kitkatNoImmersiveMode) {
layoutParams = new RelativeLayout.LayoutParams(mainBar.getLayoutParams());
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
} else {
View fakeStatusBar = layoutInflater.inflate(R.layout.kitkat_status_bar, mainLayout, false);
fakeStatusBar.setBackgroundColor(options.getInt(Keys.STATUS_BAR_BACKGROUND, 0x22000000));
layoutParams = new RelativeLayout.LayoutParams(fakeStatusBar.getLayoutParams());
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
mainLayout.addView(fakeStatusBar);

layoutParams = new RelativeLayout.LayoutParams(mainBar.getLayoutParams());
layoutParams.addRule(RelativeLayout.BELOW, R.id.kitkat_status_bar);
}

mainBar.setLayoutParams(layoutParams);
mainLayout.addView(mainBar);

layoutParams = new RelativeLayout.LayoutParams(grid.getLayoutParams());
layoutParams.addRule(RelativeLayout.ABOVE, R.id.dock_bar);
layoutParams.addRule(RelativeLayout.BELOW, R.id.main_bar);
grid.setLayoutParams(layoutParams);
mainLayout.addView(grid);
}
if (options.getBoolean(Keys.HIDE_MAIN_BAR, false)) {
mainBar.setVisibility(View.GONE);
}
mainBar.setBackgroundColor(options.getInt(Keys.BAR_BACKGROUND, 0x22000000));
grid.setBackgroundColor(options.getInt(Keys.APPS_WINDOW_BACKGROUND, 0));
if (options.getBoolean(Keys.STACK_FROM_BOTTOM, false)) {
grid.setStackFromBottom(true);
}
if (options.getBoolean(Keys.TILE, true)) {
grid.setNumColumns(GridView.AUTO_FIT);
}
adapter = new CustomAdapter(this);
grid.setAdapter(adapter);

if (options.getBoolean(Keys.SCROLLBAR, false)) {
grid.setFastScrollEnabled(true);
grid.setFastScrollAlwaysVisible(true);
grid.setScrollBarStyle(AbsListView.SCROLLBARS_INSIDE_INSET);
grid.setSmoothScrollbarEnabled(true);
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
//Log.v(APP_TAG, "onCreate");
Expand All @@ -906,7 +816,6 @@ protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= 11) {
Themer.applyTheme(this, options);
}
layoutInit();
if (options.getBoolean(Keys.SHOW_TUTORIAL, true)) {
startActivity(new Intent(this, TutorialActivity.class));
}
Expand All @@ -924,7 +833,10 @@ protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= 21) {
Themer.setWindowDecorations(this, options);
}
setContentView(mainLayout);
setContentView(MainLayout.get(this, options));
grid = (GridView) findViewById(R.id.appsGrid);
adapter = new CustomAdapter(this);
grid.setAdapter(adapter);
options.edit().putBoolean(Keys.MESSAGE_SHOWN, true).commit();
if (options.getBoolean(Keys.ICON_PACK_CHANGED, false)) {
loadAppsFromSystem(true);
Expand Down
112 changes: 112 additions & 0 deletions app/src/main/java/ru/henridellal/emerald/MainLayout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package ru.henridellal.emerald;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class MainLayout {

public static RelativeLayout get(Context context, SharedPreferences options) {
RelativeLayout mainLayout = new RelativeLayout(context);
LayoutInflater layoutInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

addDockBar(mainLayout, layoutInflater, options);

boolean kitkatNoImmersiveMode = (Build.VERSION.SDK_INT == 19 && !options.getBoolean(Keys.FULLSCREEN, false));
FrameLayout mainBar = (FrameLayout) layoutInflater.inflate(R.layout.main_bar, mainLayout, false);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(mainBar.getLayoutParams());

GridView grid = (GridView) layoutInflater.inflate(R.layout.apps_grid, mainLayout, false);
initAppsGrid(grid, options);

if (options.getBoolean(Keys.BOTTOM_MAIN_BAR, true)) {
layoutParams.addRule(RelativeLayout.ABOVE, R.id.dock_bar);
mainBar.setLayoutParams(layoutParams);
mainLayout.addView(mainBar);

if (kitkatNoImmersiveMode) {
mainLayout.addView(getFakeStatusBar(mainLayout, layoutInflater, options));
}
layoutParams = new RelativeLayout.LayoutParams(grid.getLayoutParams());
if (kitkatNoImmersiveMode) {
layoutParams.addRule(RelativeLayout.BELOW, R.id.kitkat_status_bar);
} else {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
}
layoutParams.addRule(RelativeLayout.ABOVE, R.id.main_bar);
grid.setLayoutParams(layoutParams);
mainLayout.addView(grid);
} else {
if (!kitkatNoImmersiveMode) {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
} else {
mainLayout.addView(getFakeStatusBar(mainLayout, layoutInflater, options));
layoutParams.addRule(RelativeLayout.BELOW, R.id.kitkat_status_bar);
}

mainBar.setLayoutParams(layoutParams);
mainLayout.addView(mainBar);

layoutParams = new RelativeLayout.LayoutParams(grid.getLayoutParams());
layoutParams.addRule(RelativeLayout.ABOVE, R.id.dock_bar);
layoutParams.addRule(RelativeLayout.BELOW, R.id.main_bar);
grid.setLayoutParams(layoutParams);
mainLayout.addView(grid);
}
if (options.getBoolean(Keys.HIDE_MAIN_BAR, false)) {
mainBar.setVisibility(View.GONE);
}
mainBar.setBackgroundColor(options.getInt(Keys.BAR_BACKGROUND, 0x22000000));

return mainLayout;
}

private static void initAppsGrid(GridView grid, SharedPreferences options) {
grid.setBackgroundColor(options.getInt(Keys.APPS_WINDOW_BACKGROUND, 0));
if (options.getBoolean(Keys.STACK_FROM_BOTTOM, false)) {
grid.setStackFromBottom(true);
}
if (options.getBoolean(Keys.TILE, true)) {
grid.setNumColumns(GridView.AUTO_FIT);
}

if (options.getBoolean(Keys.SCROLLBAR, false)) {
setFastScroll(grid);
}
}

private static void addDockBar(RelativeLayout mainLayout, LayoutInflater inflater, SharedPreferences options) {
LinearLayout dockBar = (LinearLayout) inflater.inflate(R.layout.dock_bar, mainLayout, false);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(dockBar.getLayoutParams());
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
dockBar.setLayoutParams(layoutParams);
dockBar.setBackgroundColor(options.getInt(Keys.DOCK_BACKGROUND, 0x22000000));
mainLayout.addView(dockBar);
}

private static View getFakeStatusBar(RelativeLayout mainLayout, LayoutInflater inflater, SharedPreferences options) {
View fakeStatusBar = inflater.inflate(R.layout.kitkat_status_bar, mainLayout, false);
fakeStatusBar.setBackgroundColor(options.getInt(Keys.STATUS_BAR_BACKGROUND, 0x22000000));
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(fakeStatusBar.getLayoutParams());
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
fakeStatusBar.setLayoutParams(layoutParams);
return fakeStatusBar;
}

private static void setFastScroll(GridView grid) {
grid.setFastScrollEnabled(true);
grid.setFastScrollAlwaysVisible(true);
grid.setScrollBarStyle(AbsListView.SCROLLBARS_INSIDE_INSET);
grid.setSmoothScrollbarEnabled(true);
}

}

0 comments on commit 6f5710e

Please sign in to comment.