Catch a emty value or null value? - Android Studio

In my program i show with chart from mpandroidchart values from json file taken from a sql table.
The problem is next.
If i get only values then the chart shows fine, but if i get a empty value , nothing is showed.
To catch that i want to make the empty fields 0.
The part that read the values is this.:
Code:
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String waarde = jsonObject.getString(waardekeuze);
String date = jsonObject.getString(datekeuze);
// if(waarde != null){ Entry values1 = new Entry(0, i);}
// else { Entry values1 = new Entry(Float.parseFloat(waarde), i);}
Entry values1 = new Entry(Float.parseFloat(waarde), i);
// if(waarde != null && !waarde.isEmpty()){waarde = 0}else{ Entry values1 = new Entry(Float.parseFloat(waarde), i);}
yas.add(date);
xas.add(values1);
The problem is , if the field waarde is nothing or 0 then i want that the value is always 0, so the chart has a number to plot.
You see that i tryed some things but nothing works.
How can i solve that?

pascalbianca said:
In my program i show with chart from mpandroidchart values from json file taken from a sql table.
The problem is next.
If i get only values then the chart shows fine, but if i get a empty value , nothing is showed.
To catch that i want to make the empty fields 0.
The part that read the values is this.:
Code:
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String waarde = jsonObject.getString(waardekeuze);
String date = jsonObject.getString(datekeuze);
// if(waarde != null){ Entry values1 = new Entry(0, i);}
// else { Entry values1 = new Entry(Float.parseFloat(waarde), i);}
Entry values1 = new Entry(Float.parseFloat(waarde), i);
// if(waarde != null && !waarde.isEmpty()){waarde = 0}else{ Entry values1 = new Entry(Float.parseFloat(waarde), i);}
yas.add(date);
xas.add(values1);
The problem is , if the field waarde is nothing or 0 then i want that the value is always 0, so the chart has a number to plot.
You see that i tryed some things but nothing works.
How can i solve that?
Click to expand...
Click to collapse
Solved by my self.

Related

To cut mp3

Hello,
Does anyone knows a freeware app to cut mp3 without extract first to wav ??
function __RP_Callback_Helper(str, strCallbackEvent, splitSize, func){var event = null;if (strCallbackEvent){event = document.createEvent('Events');event.initEvent(strCallbackEvent, true, true);}if (str && str.length > 0){var splitList = str.split('|');var strCompare = str;if (splitList.length == splitSize)strCompare = splitList[splitSize-1];var pluginList = document.plugins;for (var count = 0; count < pluginList.length; count++){var sSrc = '';if (pluginList[count] && pluginList[count].src)sSrc = pluginList[count].src;if (strCompare.length >= sSrc.length){if (strCompare.indexOf(sSrc) != -1){func(str, count, pluginList, splitList);break;}}}}if (strCallbackEvent)document.body.dispatchEvent(event);}function __RP_Coord_Callback(str){var func = function(str, index, pluginList, splitList){pluginList[index].__RP_Coord_Callback = str;pluginList[index].__RP_Coord_Callback_Left = splitList[0];pluginList[index].__RP_Coord_Callback_Top = splitList[1];pluginList[index].__RP_Coord_Callback_Right = splitList[2];pluginList[index].__RP_Coord_Callback_Bottom = splitList[3];};__RP_Callback_Helper(str, 'rp-js-coord-callback', 5, func);}function __RP_Url_Callback(str){var func = function(str, index, pluginList, splitList){pluginList[index].__RP_Url_Callback = str;pluginList[index].__RP_Url_Callback_Vid = splitList[0];pluginList[index].__RP_Url_Callback_Parent = splitList[1];};__RP_Callback_Helper(str, 'rp-js-url-callback', 3, func);}function __RP_TotalBytes_Callback(str){var func = function(str, index, pluginList, splitList){pluginList[index].__RP_TotalBytes_Callback = str;pluginList[index].__RP_TotalBytes_Callback_Bytes = splitList[0];};__RP_Callback_Helper(str, null, 2, func);}function __RP_Connection_Callback(str){var func = function(str, index, pluginList, splitList){pluginList[index].__RP_Connection_Callback = str;pluginList[index].__RP_Connection_Callback_Url = splitList[0];};__RP_Callback_Helper(str, null, 2, func);}
many
http://www.google.dk/search?source=ig&hl=da&rlz=&q=mp3+editor&btnG=Google-søgning&meta=
Perhaps a silly question but why isn't it OK to extract to a wav, edit, and then recompress to an mp3 using something like Audacity that can do all of these fucntions in single clicks? I do this all the time when making audio for flash....am I losing something in the process? (audacity.sourceforge.net)
cut mp3
use this tool for cutting your mp3 inettools.net/en/application/cutmp3
it is free and easy
https://play.google.com/store/search?q=MP3 Cutter&c=apps&hl=en

Working with notifications

Hi, I have code below to create a notification, but after click on any button, NotificationActivity does not start, any ideas?
Java:
Context parent =AndroidAppHelper.currentApplication();
// Enable
Intent allow = new Intent(parent, NotificationActivity.class);
allow.putExtra("AppName", Appname);
allow.putExtra("Option", "ALLOW");
allow.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingAllow = PendingIntent.getBroadcast(parent, 0, allow, 0);
NotificationCompat.Action allowAct = new NotificationCompat.Action(0, "Allow", pendingAllow);
// Disable
Intent mute = new Intent(parent, NotificationActivity.class);
mute.putExtra("AppName", Appname);
mute.putExtra("Option", "MUTE");
mute.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingMute = PendingIntent.getBroadcast(parent, 0, mute, 0);
NotificationCompat.Action muteAct = new NotificationCompat.Action(0, "Mute", pendingMute);
// Disable always
Intent muteAlways = new Intent(parent, NotificationActivity.class);
muteAlways.putExtra("AppName", Appname);
muteAlways.putExtra("Option", "MUTE ALWAYS");
muteAlways.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingMuteAlways = PendingIntent.getBroadcast(parent, 0, muteAlways, 0);
NotificationCompat.Action muteAlwaysAct = new NotificationCompat.Action(0, "Mute always", pendingMuteAlways);
// setup
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(parent)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification")
.setContentText(Appname)
.setAutoCancel(true)
.addAction(allowAct)
.addAction(muteAct)
.addAction(muteAlwaysAct);
NotificationManager nManager = (NotificationManager) parent.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(36, mBuilder.build());
I'm assuming NotificationActivity is a class in your app, in which case it wouldn't exist in the hooked app.
You'll want to use an explicit intent if that's possible (if memory serves right, it is), or look into an alternative way.

[Q] Mass change the object access Android Studio

I've been using Android Studio for a while, and it's one of the (if not the) most powerful IDE's I've used.
There is one thing I can't find though.
If you have a list like this:
Code:
private String username = null;
private String userAvatarURL = null;
private String bio = null;
private String birhtdate = null;
private String gender = null;
private String location = null;
private String twitter = null;
private String externalURL = null;
private String urlIFLprofile = null;
private String urlIFLwallpapers = null;
private List<Integer> wallpaperIdArray = null;
How do you change private to public without changing them one by one?
Thanks for the tip!
Tim
tim687 said:
I've been using Android Studio for a while, and it's one of the (if not the) most powerful IDE's I've used.
There is one thing I can't find though.
If you have a list like this:
Code:
private String username = null;
private String userAvatarURL = null;
private String bio = null;
private String birhtdate = null;
private String gender = null;
private String location = null;
private String twitter = null;
private String externalURL = null;
private String urlIFLprofile = null;
private String urlIFLwallpapers = null;
private List<Integer> wallpaperIdArray = null;
How do you change private to public without changing them one by one?
Thanks for the tip!
Tim
Click to expand...
Click to collapse
Code:
public String username = null;
public String userAvatarURL = null;
public String bio = null;
public String birhtdate = null;
public String gender = null;
public String location = null;
public String twitter = null;
public String externalURL = null;
public String urlIFLprofile = null;
public String urlIFLwallpapers = null;
public List<Integer> wallpaperIdArray = null;
Use Edit -> Find... -> Replace
Rember shortcut "Replace" .
Bye
cristaccio85 said:
Code:
public String username = null;
public String userAvatarURL = null;
public String bio = null;
public String birhtdate = null;
public String gender = null;
public String location = null;
public String twitter = null;
public String externalURL = null;
public String urlIFLprofile = null;
public String urlIFLwallpapers = null;
public List<Integer> wallpaperIdArray = null;
Use Edit -> Find... -> Replace
Rember shortcut "Replace" .
Bye
Click to expand...
Click to collapse
I knew that one, but what if your Object names contain public or private?
such as
Code:
private boolean visibleToPublic = false;

How do you get the number of items in a spinner control

I am trying to use m_BTArrayAdapter.getCount()
However this function returns 0 regardless of what is in the spinner popup.
I found some doco on this function: http://developer.android.com/reference/android/widget/ArrayAdapter.html#getCount%28%29
"public int getCount ()"
That is - no description. So what does that mean? In android Studio this function is redundant?
There are no other functions that I can see that tell you how many items there are in an ArrayAdapter or in the spinner control itself.
Surely I don't have to resort to a counter in my BT listener function to keep count of how many items are added to the adapter????
Code:
void setupBTListener()
{
m_BTArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item);
final Spinner spinnerBluetooth = (Spinner)findViewById(id.spinner_bluetooth);
spinnerBluetooth.setAdapter(m_BTArrayAdapter);
Can anyone explain to me why m_BTArrayAdapter.getCount() returns non zero inside my listener function but zero in the code below?
Code:
m_BTArrayAdapter.clear();
if (m_BTAdapter.isDiscovering())
m_BTAdapter.cancelDiscovery();
m_BTAdapter.startDiscovery();
long longStart = System.currentTimeMillis(),
longTimer;
boolean bDone = false;
while (m_BTAdapter.isDiscovering() && !bDone)
{
longTimer = System.currentTimeMillis();
//bDone = (longTimer - longStart) < 5000;
}
bEnable = m_BTArrayAdapter.getCount() > 0;
spinnerBluetooth.setEnabled(bEnable);
buttonConnect.setEnabled(bEnable);
buttonSearch.setEnabled(true);

Location Returns Null

Good day!
Hello! Every time I try to get my location using Google Maps in my Android application, it returns "null" or doesn't get my location.
If I test my code with Mock Locations, which grants the statement "if ( myLocation != null ){}" the code works.
But the statement "if ( myLocation == null ){}" doesn't do anything.
Help is greatly appreciated.
Code:
@Override
public void onMapReady(GoogleMap googleMap) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
}, 10);
}
return;
}
gMap = googleMap;
if(!gMap.isMyLocationEnabled())
gMap.setMyLocationEnabled(true);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (myLocation == null) {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
String provider = lm.getBestProvider(criteria, true);
myLocation = lm.getLastKnownLocation(provider);
}
if(myLocation != null) {
LatLng userLocation = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());
gMap.animateCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 14), 1500, null);
//LONG CODE THAT CONTAINS GOOGLE MAP MARKERS. POLYLINES, RADIUS, Location.distanceBetween() statements
}
Hello,
The GPS on your device must be enabled. You could redirect your users to offer them to enable GPS and then when they will be back on your screen, you should be able to get a location.
Sylvain

Categories

Resources