PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 25 → WM Sports - Códigos Fontes - Versão 23
WM Sports - Códigos Fontes - Versão 23
Débuté par BOLLER, 13 fév. 2018 22:30 - Aucune réponse
Membre enregistré
3 655 messages
Popularité : +175 (223 votes)
Posté le 13 février 2018 - 22:30
Prezados,

Abaixo os codigos do projeto WM Sports do Windev Mobile versão 23







Fontes

http://repository.windev.com/resource.awp…

http://repository.windev.com/resource.awp…

http://repository.windev.com/resource.awp…


Documentação em PDF

http://repository.windev.com/resource.awp…


COL_ANDROID

// Résumé : Renvoie vrai si le téléphone est en économie d'erngie
// Syntaxe :
//[ <Résultat> = ] EconomieEnergieActive ()
//
// Paramètres :
// Aucun
// Valeur de retour :
// booléen : // Aucune
//
// Exemple :
// Indiquez ici un exemple d'utilisation.
//
Procedure EconomieEnergieActive() : boolean

bRes is boolean


IF SysAndroidVersion(sysVersionApiLevel) >= 21 THEN
bRes = JAVA_isPowerSaveMode()
END

RESULT bRes




//--------------------------------------------------------------------------------------


import android.view.View;
import android.os.Build;
import android.view.Window;

// Résumé : Supprime l'ombre de l'action bar
PUBLIC static void JAVA_ActionBarSupprimeOmbre(){

IF (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View actionbar;

// Récupération de l'action bar
Window window = getActiviteEnCours().getWindow();
View v = window.getDecorView();
int resId = getContexteApplication().getResources().getIdentifier("action_bar_container", "id", "android");
actionbar = v.findViewById(resId);

// Changement de l'élévation pour supprimer m'ombre
IF (actionbar != Null){
actionbar.setElevation(0);
}

}
}


//-------------------------------------------------------------------------------------


import android.content.Intent;
import android.provider.Settings;


// Ouvre les paramètres du téléphone pour activer le GPS
PUBLIC static void JAVA_ActiveGPS(){
try {
getActiviteEnCours().startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
} catch(EXCEPTION e) {
Log.e("WM Sports", e.toString());
}
}


//-------------------------------------------------------------------------------------

// Résumé : Appelle la procédure JAVA pour activer le GPS
//
Procedure JAVA_ActiveGPSWL()

<Compile IF ConfigurationType=Android>
JAVA_ActiveGPS()
<END>


//--------------------------------------------------------------------------------------



PUBLIC static boolean JAVA_ArreteFocusAudio(){
try{
IF (mAudioManager == Null){
RETURN False;
}
ELSE{
mAudioManager.abandonAudioFocus(afChangeListener);
RETURN True;
}
} catch(EXCEPTION e) {
RETURN False;
}

}


//-------------------------------------------------------------------------------------


import android.graphics.Color;
import android.graphics.PorterDuff;
import java.lang.Exception;
import android.widget.Switch;
import android.content.res.ColorStateList;
import android.view.ViewGroup;
import android.view.View;

PUBLIC static boolean JAVA_ChangeCouleurInterrupteur(string sNomChamp,string sCouleur){
try{
SWITCH monswitch;
int[][] states;
int[] colorsThumb;
int[] colorsTrack;
ColorStateList myListThumb;
ColorStateList myListTrack;


// Etats des interrupteurs
states = new int[][] { new int[] { android.R.attr.state_checked }, new int[] { -android.R.attr.state_checked } };

// Couleurs
colorsThumb = new int[] { Color.parseColor(sCouleur), Color.parseColor("#E8E8E8") };
colorsTrack = new int[] { Color.parseColor(sCouleur), Color.parseColor("#000000") };

myListThumb = new ColorStateList(states, colorsThumb);
myListTrack = new ColorStateList(states, colorsTrack);

// Récupération des interrupteurs
ViewGroup viewGroup = (ViewGroup) getView(sNomChamp);

IF (viewGroup == Null){
RETURN False;
}


///////////////////////////////////////////
// Boucle sur tous les interrupteurs
for (int i = 0; i < viewGroup.getChildCount(); i++) {

// Récupération du fils
View child = viewGroup.getChildAt(i);

try{
// Cast en switch
monswitch = (SWITCH) child;


// Changement de la couleur
monswitch.setThumbTintList(myListThumb);
monswitch.setTrackTintList(myListTrack);

}
catch(EXCEPTION e) {
Log.e("WM Sports",e.toString());
RETURN False;
}
}



RETURN True;
}
catch(EXCEPTION e) {
Log.e("WM Sports",e.toString());
RETURN False;
}

}

//-------------------------------------------------------------------------------------


import android.media.AudioManager;
import android.content.Context;

PUBLIC static boolean JAVA_DemandeFocusAudio(){
try{
IF (mAudioManager == Null){
mAudioManager = (AudioManager) getContexteApplication().getSystemService(Context.AUDIO_SERVICE);
}

IF (mAudioManager == Null){
RETURN False;
}

// Request audio focus for playback
int RESULT = mAudioManager.requestAudioFocus(afChangeListener,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);

IF (RESULT == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
RETURN True;
}
ELSE{
RETURN False;
}
} catch(EXCEPTION e) {
RETURN False;
}
}

static AudioManager.OnAudioFocusChangeListener afChangeListener =
new AudioManager.OnAudioFocusChangeListener() {
PUBLIC void onAudioFocusChange(int focusChange) {
IF (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
// Pause playback
} ELSE IF (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
// Resume playback
} ELSE IF (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
//mAudioManager.unregisterMediaButtonEventReceiver(RemoteControlReceiver);
mAudioManager.abandonAudioFocus(afChangeListener);
// Stop playback
}
}
};


PUBLIC static AudioManager mAudioManager;

//------------------------------------------------------------------------------------


import android.os.PowerManager;
import android.os.Build;

PUBLIC static boolean JAVA_isPowerSaveMode(){

PowerManager powerManager = (PowerManager) getActiviteEnCours().getSystemService(Context.POWER_SERVICE);

IF (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && powerManager.isPowerSaveMode()) {
// Animations are disabled in power save mode, so just show a toast instead.
RETURN True;
}

RETURN False;
}


//--------------------------------------------------------------------------------------


import android.view.View;
import android.os.Build;

// Résumé : PAsse les icônes de la barre de statut en sombre
PUBLIC static void JAVA_StatusBarChangeCouleurIcone(){

IF (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Récupération de la barre de statut
View statusbar = getActiviteEnCours().getWindow().getDecorView();

// Passage en barre claire
statusbar.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}


//------------------------------------------------------------------------------------

// Donne la rotation de l'image
import android.media.ExifInterface;
import java.lang.Exception;
import android.graphics.*;
import android.util.Log;
import java.io.FileOutputStream;

PUBLIC static boolean JAVA_TraitePhotoExif(string sPhoto, string sPhotoDestination){
int nRotation = 0;
boolean res = False;

try{
ExifInterface m_exif = new ExifInterface(sPhoto);
nRotation = (int)exifOrientationToDegrees(m_exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL));

// BITMAP
BitmapFactory.Options bounds = new BitmapFactory.Options();
// Réduit la taille
//bounds.inSampleSize = 2;
Bitmap sourceBitmap = BitmapFactory.decodeFile(sPhoto,bounds);

IF (sourceBitmap == Null){
RETURN False;
}

// Rotation
Matrix matrix = new Matrix();
IF (nRotation > 0) {
matrix.preRotate(nRotation);
}

int width = sourceBitmap.getWidth();
int height = sourceBitmap.getHeight();

// Création du nouveau bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, width, height, matrix, True);

IF (resizedBitmap == Null){
RETURN False;
}

// Sauvegarde
FileOutputStream out = new FileOutputStream(sPhotoDestination);
res = resizedBitmap.compress(Bitmap.CompressFormat.JPEG , 100, out);
sourceBitmap.recycle();
resizedBitmap.recycle();

resizedBitmap = Null;
sourceBitmap = Null;

RETURN res;
}
catch(EXCEPTION e) {
Log.e("WM Sports",e.toString());
RETURN False;
}

}

PUBLIC static float exifOrientationToDegrees(int exifOrientation) {
IF (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
RETURN 90;
} ELSE IF (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
RETURN 180;
} ELSE IF (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
RETURN 270;
}
RETURN 0;
}


//-------------------------------------------------------------------------------------

// Résumé : Lit un texte en baissant le volume de la musique si besoin
// Syntaxe :
//SyntheseVocaleLitTexteFocus (<sTExte> est chaîne)
//
// Paramètres :
// sTExte (chaîne ANSI) : Texte à lire
// Procédure automatique :
// La procédure est exécutée manuellement, lors d'un appel dans le code
// Elle s'exécutera dans un thread (sans avoir besoin d'appeler la fonction ThreadExecute), sans utilisation de HFSQL
//
// Traitement automatique des erreurs : exécuter le bloc de code CAS ERREUR
//
// Traitement automatique des exceptions : exécuter le bloc de code CAS EXCEPTION:
//

Procedure SyntheseVocaleLitTexteFocus(sTExte is string)

////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Lecture des données
<Compile IF ConfigurationType=Android>
bResFocus is boolean
bResFocus = JAVA_DemandeFocusAudio()
<END>

// Lecture
SpeechSynthesisReadText(sTExte,True)

<Compile IF ConfigurationType=Android>
IF bResFocus THEN JAVA_ArreteFocusAudio()
<END>

CASE ERROR:
JAVA_ArreteFocusAudio()
CASE EXCEPTION:
JAVA_ArreteFocusAudio()


//-------------------------------------------------------------------------------------


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Message modifié, 13 février 2018 - 22:31