Main: integrar rediseño + anuncio recompensado para CAMBIAR FRASE (UMP consent, recarga tras uso)
This commit is contained in:
1 parent
37a802705a
commit
4919118fc5
1 file changed
+200
-136
@@ -6,31 +6,33 @@ import android.content.ClipboardManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.text.method.ScrollingMovementMethod;
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import com.marcohc.robotocalendar.RobotoCalendarView.RobotoCalendarListener;
|
|
||||||
import com.marcohc.robotocalendar.RobotoCalendarView;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import java.text.DateFormatSymbols;
|
import androidx.core.content.ContextCompat;
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
import com.google.android.gms.ads.AdRequest;
|
import com.google.android.gms.ads.AdRequest;
|
||||||
import com.google.android.gms.ads.AdView;
|
import com.google.android.gms.ads.FullScreenContentCallback;
|
||||||
|
import com.google.android.gms.ads.LoadAdError;
|
||||||
import com.google.android.gms.ads.MobileAds;
|
import com.google.android.gms.ads.MobileAds;
|
||||||
|
import com.google.android.gms.ads.OnUserEarnedRewardListener;
|
||||||
|
import com.google.android.gms.ads.rewarded.RewardedAd;
|
||||||
|
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
|
||||||
import com.google.android.ump.ConsentInformation;
|
import com.google.android.ump.ConsentInformation;
|
||||||
import com.google.android.ump.ConsentRequestParameters;
|
import com.google.android.ump.ConsentRequestParameters;
|
||||||
import com.google.android.ump.FormError;
|
import com.google.android.ump.FormError;
|
||||||
import com.google.android.ump.UserMessagingPlatform;
|
import com.google.android.ump.UserMessagingPlatform;
|
||||||
|
import com.marcohc.robotocalendar.RobotoCalendarView;
|
||||||
|
|
||||||
|
import java.text.DateFormatSymbols;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity implements RobotoCalendarView.RobotoCalendarListener {
|
||||||
public class MainActivity extends AppCompatActivity implements RobotoCalendarListener {
|
|
||||||
|
|
||||||
private RobotoCalendarView robotoCalendarView;
|
private RobotoCalendarView robotoCalendarView;
|
||||||
DatabaseHelper db;
|
DatabaseHelper db;
|
||||||
@@ -39,49 +41,26 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
|||||||
final Config conf = new Config(this);
|
final Config conf = new Config(this);
|
||||||
|
|
||||||
/* Will use when move month back and forth, because library doesnt show the actual month.. */
|
/* Will use when move month back and forth, because library doesnt show the actual month.. */
|
||||||
Integer calMonth = cal.get(Calendar.MONTH)+1; //From 1 to 12, and not from 0 to 11
|
Integer calMonth = cal.get(Calendar.MONTH) + 1; //From 1 to 12, and not from 0 to 11
|
||||||
Integer calYear = cal.get(Calendar.YEAR);
|
Integer calYear = cal.get(Calendar.YEAR);
|
||||||
|
|
||||||
/* Texts making all activity used, and valued in onCreate */
|
/* Views of the redesign */
|
||||||
TextView txtfraseTitle;
|
TextView txtDate;
|
||||||
TextView txtfraseText;
|
TextView txtSentence;
|
||||||
TextView txtfraseAutor;
|
TextView txtAutor;
|
||||||
/* More objects of view */
|
|
||||||
ImageButton btnFav;
|
ImageButton btnFav;
|
||||||
ImageButton btnShare;
|
ImageButton btnShare;
|
||||||
|
TextView btnChange;
|
||||||
|
|
||||||
|
/* Rewarded ad to change the sentence */
|
||||||
@Override
|
private RewardedAd rewardedAd;
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
MenuInflater inflater = getMenuInflater();
|
|
||||||
inflater.inflate(R.menu.main, menu);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
int id = item.getItemId();
|
|
||||||
if (id == R.id.favorites) {
|
|
||||||
startActivity(new Intent(MainActivity.this, FavsActivity.class));
|
|
||||||
return true;
|
|
||||||
} else if (id == R.id.options) {
|
|
||||||
startActivity(new Intent(MainActivity.this, OptsActivity.class));
|
|
||||||
return true;
|
|
||||||
} else if (id == R.id.about) {
|
|
||||||
startActivity(new Intent(MainActivity.this, AboutOfActivity.class));
|
|
||||||
return true;
|
|
||||||
} else if (id == R.id.exit) {
|
|
||||||
moveTaskToBack(true); /* Returns to "desktop" */
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
/* First of all,before loading, see if its the first time using the app */
|
/* First of all,before loading, see if its the first time using the app */
|
||||||
if (conf.getFirstTime()){
|
if (conf.getFirstTime()) {
|
||||||
new AlertDialog.Builder(MainActivity.this)
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
.setTitle(R.string.welcome_title)
|
.setTitle(R.string.welcome_title)
|
||||||
.setMessage(R.string.welcome_text)
|
.setMessage(R.string.welcome_text)
|
||||||
@@ -96,13 +75,22 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
UiUtils.applySystemBarsInsets(this);
|
|
||||||
|
/* Rediseño: header propio, sin ActionBar; insets con fondo bgCard */
|
||||||
|
if (getSupportActionBar() != null) {
|
||||||
|
getSupportActionBar().hide();
|
||||||
|
}
|
||||||
|
UiUtils.applySystemBarsInsets(this, findViewById(R.id.main_root),
|
||||||
|
ContextCompat.getColor(this, R.color.bgCard), UiUtils.isDarkTheme(this));
|
||||||
|
UiUtils.setupBottomNav(this, UiUtils.NavTab.INICIO);
|
||||||
|
|
||||||
db = new DatabaseHelper(this);
|
db = new DatabaseHelper(this);
|
||||||
txtfraseTitle = findViewById(R.id.txt_frasetitle);
|
txtDate = findViewById(R.id.txt_date);
|
||||||
txtfraseText = findViewById(R.id.txt_frasetext);
|
txtSentence = findViewById(R.id.txt_sentence);
|
||||||
txtfraseAutor = findViewById(R.id.txt_fraseautor);
|
txtAutor = findViewById(R.id.txt_fraseautor);
|
||||||
btnFav = findViewById(R.id.btnFav);
|
btnFav = findViewById(R.id.btnFav);
|
||||||
btnShare = findViewById(R.id.btnShare);
|
btnShare = findViewById(R.id.btnShare);
|
||||||
|
btnChange = findViewById(R.id.btn_change);
|
||||||
|
|
||||||
/* Calendar basic settings */
|
/* Calendar basic settings */
|
||||||
robotoCalendarView = (RobotoCalendarView) findViewById(R.id.calendarPicker);
|
robotoCalendarView = (RobotoCalendarView) findViewById(R.id.calendarPicker);
|
||||||
@@ -110,15 +98,44 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
|||||||
robotoCalendarView.setShortWeekDays(false);
|
robotoCalendarView.setShortWeekDays(false);
|
||||||
robotoCalendarView.showDateTitle(true);
|
robotoCalendarView.showDateTitle(true);
|
||||||
|
|
||||||
/* Admob ads: consentimiento UMP primero, luego init en background y banner */
|
/* Admob ads: consentimiento UMP primero, luego init en background y
|
||||||
|
banner + rewarded (patrón FrasesDeAnime) */
|
||||||
setUpConsentAndAds();
|
setUpConsentAndAds();
|
||||||
|
|
||||||
|
/* Make sentence text scrollable */
|
||||||
|
txtSentence.setMovementMethod(new ScrollingMovementMethod());
|
||||||
|
|
||||||
|
/* Copy sentence on tap (as before) */
|
||||||
|
txtSentence.setOnClickListener(viewIn -> {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
clipboard.setPrimaryClip(ClipData.newPlainText("Sentence",
|
||||||
|
txtSentence.getText() + getString(R.string.sharefrom)));
|
||||||
|
Toast.makeText(getApplicationContext(), R.string.copied, Toast.LENGTH_LONG).show();
|
||||||
|
});
|
||||||
|
|
||||||
/* Register context menu */
|
/* Fav toggle */
|
||||||
registerForContextMenu(txtfraseText);
|
btnFav.setOnClickListener(viewIn -> {
|
||||||
|
if (db.getFav(IDFrase) == 1) {
|
||||||
|
db.delFav(IDFrase);
|
||||||
|
} else {
|
||||||
|
db.addFav(IDFrase);
|
||||||
|
}
|
||||||
|
changeFavImage();
|
||||||
|
});
|
||||||
|
|
||||||
/* Close app on back button */
|
/* Share */
|
||||||
|
btnShare.setOnClickListener(viewIn -> {
|
||||||
|
String sentence = txtSentence.getText().toString();
|
||||||
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
|
intent.setType("text/plain");
|
||||||
|
intent.putExtra(Intent.EXTRA_TEXT, sentence + getString(R.string.sharefrom));
|
||||||
|
startActivity(Intent.createChooser(intent, getString(R.string.share_with)));
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Change sentence: rewarded ad (like FrasesDeAnime) */
|
||||||
|
btnChange.setOnClickListener(viewIn -> onChangeSentenceClick());
|
||||||
|
|
||||||
|
/* Close app on back button: registrado con OnBackPressedDispatcher */
|
||||||
getOnBackPressedDispatcher().addCallback(this, new androidx.activity.OnBackPressedCallback(true) {
|
getOnBackPressedDispatcher().addCallback(this, new androidx.activity.OnBackPressedCallback(true) {
|
||||||
@Override
|
@Override
|
||||||
public void handleOnBackPressed() {
|
public void handleOnBackPressed() {
|
||||||
@@ -127,7 +144,11 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Consentimiento UMP (obligatorio EEA) y tras él, init de AdMob + banner */
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Ads: UMP consent → init background → banner adaptativo + rewarded */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/** Consentimiento UMP (obligatorio EEA) y tras él, init + carga de anuncios */
|
||||||
private void setUpConsentAndAds() {
|
private void setUpConsentAndAds() {
|
||||||
ConsentRequestParameters params = new ConsentRequestParameters.Builder().build();
|
ConsentRequestParameters params = new ConsentRequestParameters.Builder().build();
|
||||||
ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(this);
|
ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(this);
|
||||||
@@ -140,115 +161,160 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
|||||||
formError -> initAdsAfterConsent());
|
formError -> initAdsAfterConsent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** MobileAds.initialize en background y, al completar, banner + rewarded */
|
||||||
private void initAdsAfterConsent() {
|
private void initAdsAfterConsent() {
|
||||||
/* MobileAds.initialize en background: no bloquee el arranque */
|
new Thread(() -> MobileAds.initialize(getApplicationContext(), initializationStatus ->
|
||||||
new Thread(() -> {
|
runOnUiThread(() -> {
|
||||||
MobileAds.initialize(getApplicationContext());
|
UiUtils.loadBannerAd(MainActivity.this,
|
||||||
runOnUiThread(() -> {
|
(android.widget.FrameLayout) findViewById(R.id.adContainer));
|
||||||
AdView mAdView = findViewById(R.id.adView);
|
loadRewardedAd();
|
||||||
AdRequest adRequest = new AdRequest.Builder().build();
|
}))).start();
|
||||||
mAdView.loadAd(adRequest);
|
|
||||||
});
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** Carga el anuncio recompensado con el ID de UNIDAD, no el de app */
|
||||||
public void onResume(){
|
private void loadRewardedAd() {
|
||||||
super.onResume();
|
AdRequest adRequest = new AdRequest.Builder().build();
|
||||||
/* Refresh calendar */
|
RewardedAd.load(this, getString(R.string.rewarded_ad_unit_id), adRequest,
|
||||||
cal = Calendar.getInstance();
|
new RewardedAdLoadCallback() {
|
||||||
calMonth = cal.get(Calendar.MONTH)+1; //From 1 to 12, and not from 0 to 11
|
@Override
|
||||||
calYear = cal.get(Calendar.YEAR);
|
public void onAdFailedToLoad(LoadAdError adError) {
|
||||||
|
rewardedAd = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAdLoaded(RewardedAd ad) {
|
||||||
|
rewardedAd = ad;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//Load today's sentence and set texts
|
/* ------------------------------------------------------------------ */
|
||||||
IDFrase = db.getIDFraseHoy();
|
/* Cambiar frase con anuncio recompensado (patrón FrasesDeAnime) */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
/* Refresh calendar, after load sentences for checks */
|
/**
|
||||||
robotoCalendarView.updateView();
|
* Botón CAMBIAR FRASE: sólo tiene sentido para un día ya desbloqueado
|
||||||
markDates();
|
* (hoy o un pasado accesible). Muestra el rewarded y, con la recompensa,
|
||||||
|
* diálogo para confirmar el cambio.
|
||||||
txtfraseText.setText(db.getFraseFromID(IDFrase));
|
*/
|
||||||
txtfraseAutor.setText(db.getAutorFromID(IDFrase));
|
private void onChangeSentenceClick() {
|
||||||
|
if (IDFrase == null || IDFrase <= 0) {
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
// ListView Item Click Listener
|
.setMessage(R.string.rewarded_no_sentence)
|
||||||
txtfraseText.setOnClickListener(new View.OnClickListener() {
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (rewardedAd == null) {
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setMessage(R.string.rewarded_not_ready)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RewardedAd ad = rewardedAd;
|
||||||
|
rewardedAd = null;
|
||||||
|
/* Recargar tras cerrar: los RewardedAd son de un solo uso */
|
||||||
|
ad.setFullScreenContentCallback(new FullScreenContentCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View viewIn) {
|
public void onAdDismissedFullScreenContent() {
|
||||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
loadRewardedAd();
|
||||||
clipboard.setPrimaryClip(ClipData.newPlainText("Sentence", txtfraseText.getText()+MainActivity.this.getString(R.string.sharefrom)));
|
|
||||||
Toast.makeText(getApplicationContext(), R.string.copied, Toast.LENGTH_LONG ).show();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
changeFavImage(); //Fav image button
|
ad.show(this, rewardItem -> {
|
||||||
|
/* ANUNCIO VISTO: ofrecer el cambio de frase */
|
||||||
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
|
.setTitle(R.string.rewarded_change_title)
|
||||||
|
.setMessage(R.string.rewarded_change_msg)
|
||||||
|
.setPositiveButton(R.string.rewarded_change_ok, (d, w) -> {
|
||||||
|
db.changeDaySentence(selYear, selMonth, selDay);
|
||||||
|
IDFrase = db.getIDFraseDay(selYear, selMonth, selDay);
|
||||||
|
updateSentenceViews();
|
||||||
|
markDates();
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// SetFavListener
|
/* ------------------------------------------------------------------ */
|
||||||
btnFav.setOnClickListener(new View.OnClickListener() {
|
/* Sentence views */
|
||||||
@Override
|
/* ------------------------------------------------------------------ */
|
||||||
public void onClick(View viewIn) {
|
|
||||||
if (db.getFav(IDFrase) == 1){
|
/** Updates the pill date, sentence and author for the selected day */
|
||||||
db.delFav(IDFrase);
|
private void updateSentenceViews() {
|
||||||
}else {
|
txtSentence.setText(db.getFraseFromID(IDFrase));
|
||||||
db.addFav(IDFrase);
|
txtAutor.setText(db.getAutorFromID(IDFrase));
|
||||||
}
|
Calendar today = Calendar.getInstance();
|
||||||
changeFavImage();
|
if (selYear != today.get(Calendar.YEAR)
|
||||||
}
|
|| selMonth != today.get(Calendar.MONTH) + 1
|
||||||
});
|
|| selDay != today.get(Calendar.DAY_OF_MONTH)) {
|
||||||
// ShareListener
|
txtDate.setText(getString(R.string.sentence_of_day, selDay, getMonth(selMonth)));
|
||||||
btnShare.setOnClickListener(new View.OnClickListener() {
|
} else {
|
||||||
@Override
|
txtDate.setText(R.string.txt_todaysentence);
|
||||||
public void onClick(View viewIn) {
|
}
|
||||||
String sentence = txtfraseText.getText().toString();
|
changeFavImage();
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
||||||
intent.setType("text/plain");
|
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, sentence+MainActivity.this.getString(R.string.sharefrom));
|
|
||||||
startActivity(Intent.createChooser(intent, getString(R.string.share_with)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeFavImage() {
|
private void changeFavImage() {
|
||||||
if (db.getFav(IDFrase) == 1){
|
if (db.getFav(IDFrase) == 1) {
|
||||||
btnFav.setBackgroundResource(R.drawable.star_on);
|
btnFav.setBackgroundResource(R.drawable.star_on);
|
||||||
}else {
|
} else {
|
||||||
btnFav.setBackgroundResource(R.drawable.star_off);
|
btnFav.setBackgroundResource(R.drawable.star_off);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
/* Refresh calendar */
|
||||||
|
cal = Calendar.getInstance();
|
||||||
|
calMonth = cal.get(Calendar.MONTH) + 1; //From 1 to 12, and not from 0 to 11
|
||||||
|
calYear = cal.get(Calendar.YEAR);
|
||||||
|
|
||||||
/* Close app on back button: registrado en onCreate con OnBackPressedDispatcher */
|
/* Selected day = today on resume */
|
||||||
|
selYear = cal.get(Calendar.YEAR);
|
||||||
|
selMonth = cal.get(Calendar.MONTH) + 1;
|
||||||
|
selDay = cal.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
|
/* Load today's sentence and set texts */
|
||||||
|
IDFrase = db.getIDFraseHoy();
|
||||||
|
updateSentenceViews();
|
||||||
|
|
||||||
|
/* Refresh calendar after load sentences for checks */
|
||||||
|
robotoCalendarView.updateView();
|
||||||
|
markDates();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Calendar listener */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDayClick(Calendar daySelectedCalendar) {
|
public void onDayClick(Calendar daySelectedCalendar) {
|
||||||
Integer month = daySelectedCalendar.get(Calendar.MONTH);
|
int year = daySelectedCalendar.get(Calendar.YEAR);
|
||||||
Integer day = daySelectedCalendar.get(Calendar.DAY_OF_MONTH);
|
int month = daySelectedCalendar.get(Calendar.MONTH) + 1;
|
||||||
Integer year = daySelectedCalendar.get(Calendar.YEAR);
|
int day = daySelectedCalendar.get(Calendar.DAY_OF_MONTH);
|
||||||
month=month+1; //Now months start with 1 and not 0
|
selYear = year;
|
||||||
/* Load sentence */
|
selMonth = month;
|
||||||
|
selDay = day;
|
||||||
IDFrase = db.getIDFraseDay(year, month, day);
|
IDFrase = db.getIDFraseDay(year, month, day);
|
||||||
String frase = db.getFraseFromID(IDFrase);
|
updateSentenceViews();
|
||||||
txtfraseText.setText(frase); //Change text
|
|
||||||
txtfraseAutor.setText(db.getAutorFromID(IDFrase));
|
|
||||||
/* Set Title before sentence */
|
|
||||||
if (year != cal.get(Calendar.YEAR) || month != (cal.get(Calendar.MONTH)+1) || day != cal.get(Calendar.DAY_OF_MONTH)) {
|
|
||||||
txtfraseTitle.setText(getString(R.string.sentence_of_day, day, getMonth(month))); //Change title
|
|
||||||
}else {
|
|
||||||
txtfraseTitle.setText(R.string.txt_todaysentence); //Change title (today)
|
|
||||||
}
|
|
||||||
changeFavImage(); //For checking fav image
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDayLongClick(Calendar daySelectedCalendar) {
|
public void onDayLongClick(Calendar daySelectedCalendar) {
|
||||||
onDayClick(daySelectedCalendar);
|
onDayClick(daySelectedCalendar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Selected day shown in the sentence card (today on resume) */
|
||||||
|
int selYear;
|
||||||
|
int selMonth;
|
||||||
|
int selDay;
|
||||||
|
|
||||||
/** It returns the month name */
|
/** It returns the month name */
|
||||||
public String getMonth(int month) {
|
public String getMonth(int month) {
|
||||||
String str = new DateFormatSymbols().getMonths()[month-1];
|
String str = new DateFormatSymbols().getMonths()[month - 1];
|
||||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,25 +324,24 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
|||||||
Calendar time = Calendar.getInstance();
|
Calendar time = Calendar.getInstance();
|
||||||
String[] IDDays = db.getAllDaysYet();
|
String[] IDDays = db.getAllDaysYet();
|
||||||
if (IDDays.length != 0) {
|
if (IDDays.length != 0) {
|
||||||
for (int x = 0; x <= IDDays.length - 1; x++) {
|
for (String idDay : IDDays) {
|
||||||
Integer year = Integer.parseInt(IDDays[x].substring(0, 4));
|
Integer year = Integer.parseInt(idDay.substring(0, 4));
|
||||||
Integer month = Integer.parseInt(IDDays[x].substring(4, 6));
|
Integer month = Integer.parseInt(idDay.substring(4, 6));
|
||||||
Integer day = Integer.parseInt(IDDays[x].substring(6, 8));
|
Integer day = Integer.parseInt(idDay.substring(6, 8));
|
||||||
if (year.equals(calYear) && month.equals(calMonth)) {
|
if (year.equals(calYear) && month.equals(calMonth)) {
|
||||||
time.set(Calendar.DAY_OF_MONTH, day);
|
time.set(Calendar.DAY_OF_MONTH, day);
|
||||||
time.set(Calendar.MONTH, month-1);
|
time.set(Calendar.MONTH, month - 1);
|
||||||
robotoCalendarView.markCircleImage1(time);
|
robotoCalendarView.markCircleImage1(time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Overrides for month plus and minus */
|
/* Overrides for month plus and minus */
|
||||||
@Override
|
@Override
|
||||||
public void onRightButtonClick() {
|
public void onRightButtonClick() {
|
||||||
calMonth += 1;
|
calMonth += 1;
|
||||||
if (calMonth > 12){
|
if (calMonth > 12) {
|
||||||
calMonth = 1;
|
calMonth = 1;
|
||||||
calYear += 1;
|
calYear += 1;
|
||||||
}
|
}
|
||||||
@@ -286,11 +351,10 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
|||||||
@Override
|
@Override
|
||||||
public void onLeftButtonClick() {
|
public void onLeftButtonClick() {
|
||||||
calMonth -= 1;
|
calMonth -= 1;
|
||||||
if (calMonth < 1){
|
if (calMonth < 1) {
|
||||||
calMonth = 12;
|
calMonth = 12;
|
||||||
calYear -= 1;
|
calYear -= 1;
|
||||||
}
|
}
|
||||||
markDates();
|
markDates();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user