Created
March 15, 2019 19:52
-
-
Save PauloCeami/6a2bf2fc334aabd8a5da41785cc28ac2 to your computer and use it in GitHub Desktop.
Context is not working in activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.captresources.app.receitasefaz.pauloceami.activityes; | |
import android.annotation.SuppressLint; | |
import android.content.res.Configuration; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import br.com.captresources.app.receitasefaz.pauloceami.R; | |
import mehdi.sakout.aboutpage.Element; | |
import android.support.v7.app.AppCompatDelegate; | |
import android.view.Gravity; | |
import android.view.View; | |
import android.widget.Toast; | |
import java.util.Calendar; | |
public class AboutPage extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
simulateDayNight(/* DAY */ 0); | |
Element adsElement = new Element(); | |
adsElement.setTitle("Advertise with us"); | |
View aboutPage = new AboutPage(this) | |
.isRTL(false) | |
.setImage(R.drawable.icon) | |
.addItem(new Element().setTitle("Version 6.2")) | |
.addItem(adsElement) | |
.addGroup("Connect with us") | |
.addEmail("[email protected]") | |
.addWebsite("http://medyo.github.io/") | |
.addFacebook("the.medy") | |
.addTwitter("medyo80") | |
.addYoutube("UCdPQtdWIsg7_pi4mrRu46vA") | |
.addPlayStore("com.ideashower.readitlater.pro") | |
.addInstagram("medyo80") | |
.addGitHub("medyo") | |
.addItem(getCopyRightsElement()) | |
.create(); | |
setContentView(aboutPage); | |
} | |
Element getCopyRightsElement() { | |
Element copyRightsElement = new Element(); | |
@SuppressLint({"StringFormatInvalid", "LocalSuppress"}) final String copyrights = String.format(getString(R.string.copy_right), Calendar.getInstance().get(Calendar.YEAR)); | |
copyRightsElement.setTitle(copyrights); | |
copyRightsElement.setIconDrawable(R.drawable.icon); | |
copyRightsElement.setIconTint(mehdi.sakout.aboutpage.R.color.about_item_icon_color); | |
copyRightsElement.setIconNightTint(android.R.color.white); | |
copyRightsElement.setGravity(Gravity.CENTER); | |
copyRightsElement.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(AboutPage.this, copyrights, Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
return copyRightsElement; | |
} | |
void simulateDayNight(int currentSetting) { | |
final int DAY = 0; | |
final int NIGHT = 1; | |
final int FOLLOW_SYSTEM = 3; | |
int currentNightMode = getResources().getConfiguration().uiMode | |
& Configuration.UI_MODE_NIGHT_MASK; | |
if (currentSetting == DAY && currentNightMode != Configuration.UI_MODE_NIGHT_NO) { | |
AppCompatDelegate.setDefaultNightMode( | |
AppCompatDelegate.MODE_NIGHT_NO); | |
} else if (currentSetting == NIGHT && currentNightMode != Configuration.UI_MODE_NIGHT_YES) { | |
AppCompatDelegate.setDefaultNightMode( | |
AppCompatDelegate.MODE_NIGHT_YES); | |
} else if (currentSetting == FOLLOW_SYSTEM) { | |
AppCompatDelegate.setDefaultNightMode( | |
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment