Untitled
unknown
java
3 years ago
3.3 kB
6
Indexable
/* Copyright (C) Alexandre Silva "Kelpy" - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Alexandre Silva <alexandresilva.coding@gmail.com>, 10 2022
*/
package com.mrkelpy.isle.elements;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageButton;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mrkelpy.isle.R;
import com.mrkelpy.isle.elements.abstraction.AbstractConstraintLayout;
import com.mrkelpy.isle.utils.AppState;
import com.mrkelpy.isle.utils.DrawableUtils;
/**
* This class implements a main constraint where all the app elements will be contained in, allowing for full,
* free control over any element interactions during the app lifecycle.
*/
public class MainAppConstraintLayout extends AbstractConstraintLayout {
/**
* The current application state, can be enabled or disabled. <br>
* If it isn't determined, it'll be off by default.
*/
private final AppState state = this.determineAppState();
/**
* The logoButton that controls the current app state. This is the most important element
* of the app, and is controlled by the main app constraint.
*/
private ImageButton logoButton;
public MainAppConstraintLayout(@NonNull Context context) {
super(context);
this.init(context);
}
public MainAppConstraintLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.init(context);
}
public MainAppConstraintLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.init(context);
}
/**
* Since there is more than one constructor in the class, this method
* performs every necessary actions that are common to all constructors. <br>
* Loads up the logo button and adds the elements from the StateConstraintLayout matching the app state.
* @param context The application context.
*/
private void init(Context context) {
this.logoButton = this.loadLogoButton(context);
}
/**
* Loads up the logo button accordingly to the current app state. <br>
* If the app is activated, the button should display the logo, and be located well above the
* screen center. <br>
* If not, it should display the turn-on picture, and be located slightly above the center.
* @param context The application context.
*/
private ImageButton loadLogoButton(Context context) {
ImageButton button = (ImageButton) this.findViewById(R.id.logo_button);
Drawable icon = DrawableUtils.get(context, this.state == AppState.ON ? "icon.isle" : "icon.off");
button.setImageDrawable(icon);
return button;
}
/**
* Determines the app's state based on saved file settings, so it can boot back up
* and stay active even in the case of a device restart.
*/
private AppState determineAppState() {
return AppState.OFF;
}
}
Editor is loading...