I'm a new MPAndroidChart user.
The examples I have found on-line and the Wiki here all give the setDescription() prototype as:
setDescription(String desc)`
However, mChart.setDescription(""); does not compile for me and AndroidStudio->Go To Declaration tells me the declaration for setDescription defined in Chart.java is :
public void setDescription(Description desc) {
this.mDescription = desc;
}
And the Description constructor in Description.java does not take a String.
How do I set the description (or at least turn it off)? Am I pointing to the wrong libraries?
Here is my app's gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And, the module gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.android.nbmc_hbmc"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile 'pub.devrel:easypermissions:0.2.1'
testCompile 'junit:junit:4.12'
}
And this is my chart code. It compiles and shows the chart but it has the Description Label "Description Label" that I can't change or turn off.
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import java.util.ArrayList;
import java.util.List;
import static com.example.android.nbmc_hbmc.R.id.chart;
public class NbmcEcgGraphActivity extends Activity {
private RelativeLayout mainLayout;
private LineChart mChart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ecggraph);
mainLayout = (RelativeLayout) findViewById(R.id.activity_ecggraph);
// Create new line chart
LineChart mChart = (LineChart) findViewById(chart);
mChart.setDescription(new Description());
mChart.setNoDataText("No Data Yet");
It looks like the wiki is out of date!
The correct syntax in MPAndroidChart 3.0.1 is
mChart.getDescription().setText("Description of my chart");
Reference: javadoc
Related
I'm working on the android application and when I want to connect with firebase. I have an:
error: cannot find symbol class DatabaseReference
Error. My code:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DatabaseReference reference = FirebaseDatabase.getInstance().getreference();
}
}
My build.gradle(Project:android)
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.google.gms:google-services:4.3.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
My build.gradle(Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.ala.marouene"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services
And I already have JSON file in my .app folder.
Add Realtime Database:
implementation "com.google.firebase:firebase-database:19.2.0"
But you'd generally need to use elder versions of Firebase, which still were built against com.android.support libraries - or migrate the whole project to androidx libraries.
Found a problem while trying to make FirebaseListAdapter for my ListView, which I want to populate from Firebase Real-time Database.
Android Studio says Cannot resolve symbol 'FirebaseListAdapter', when im focusing FirebaseListAdapter<Trick> adapter = new FirebaseListAdapter<Trick>(options){}. Same with FirebaseListOptions<Trick> options = new FirebaseListOptions.Builder<Trick>(){}
Made all changes from a dublicated question, including updating build.gradle, but nothing helps
My project's build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My app's build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "cz.zelgadiss.myapplication"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.GwonHyeok:StickySwitch:0.0.15'
implementation 'com.github.medyo:fancybuttons:1.9.1'
}
My code:
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
public class EncyActivity extends AppCompatActivity {
ListView list_View;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ency);
Query query = FirebaseDatabase.getInstance().getReference().child("Tricks");
list_View = (ListView) findViewById(R.id.listview);
FirebaseListOptions<Trick> options = new FirebaseListOptions.Builder<Trick>()
.setLayout(R.layout.trick)
.setQuery(query, Trick.class)
.build();
FirebaseListAdapter<Trick> adapter = new FirebaseListAdapter<Trick>(options) {
#Override
protected void populateView(View v, Object model, int position) {
Trick trick = (Trick) model;
TextView name = v.findViewById(R.id.name);
TextView description = v.findViewById(R.id.description);
name.setText(trick.getName().toString());
description.setText(trick.getDescription().toString());
}
};
list_View.setAdapter(adapter);
}
#Override
protected void onStart(){
super.onStart();
adapter.startListening();
}
#Override
protected void onStop(){
super.onStop();
adapter.stopListening();
}
}
In order to use FirebaseListAdapter you will need to import Firebase UI
https://github.com/firebase/FirebaseUI-Android
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:4.3.2'
// FirebaseUI for Cloud Firestore
implementation 'com.firebaseui:firebase-ui-firestore:4.3.2'
Also check this
https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#using-the-firebaserecycleradapter
So I tried adding a user to a firebase group to be able to send data notification to multiple user on a simple app that show the notification when it receives it.
My problem is that following the firebase documentation I tried adding the following line to my mainactivity.java
FirebaseMessaging.getInstance().subscribeToTopic("weather")
But android studio told me that the .getInstance couldn't be called/"Cannot resolve symbol 'getInstance'é it so I don't know what to do to make it work
edit:
The app build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.shayru.myapplication"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.6'
}
The Project build.gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and if needed this is what the mainactivity does :
package com.shayru.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.firebase.messaging.FirebaseMessaging;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
FirebaseMessaging.getInstance().subscribeToTopic("News");
}
The problem is not with Firebase, rather its with your code. Subscribe to the topic in your onCreate() method, not outside a method.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseMessaging.getInstance().subscribeToTopic("News");
}
I received it in my vritual device before...but after I uninstall and reinstalled my app from my AVD then I didnt get any messages but in firebase console its showing completed status..plz some one help me
This is Main Activity
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton budbtn=(ImageButton)findViewById(R.id.buddies);
budbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent= new Intent(MainActivity.this,BuddiesAct.class);
startActivity(intent);
}
});
ImageButton prim=(ImageButton)findViewById(R.id.primary);
ImageButton senior=(ImageButton)findViewById(R.id.senior);
ImageButton suprsen=(ImageButton)findViewById(R.id.supersenior);
}
}
Project level built gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.zion.kidskount"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
apply plugin: 'com.google.gms.google-services'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'gr.pantrif:easy-android-splash-screen:0.0.1'
compile 'com.google.firebase:firebase-messaging:9.0.0'
testCompile 'junit:junit:4.12'
}
Everytime you reinstall or clear data of your application, your token is generated again.
Log your token everytime onTokenRefresh() is called as described here.
So, get your token and use it to send your push notification :D
I am creating an application class to use Firebase in my complete application. However in the import line error occurs highlighting 'firebase' in red.
I have looked everywhere but cannot make out the problem.
Code:
package com.mobility.mobilityindia;
import android.app.Application;
import com.firebase.client.Firebase; <--- firebase is red here
public class MobilityIndia2 extends Application{
#Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this); <---- Firebase is red here
}
app level gradle.build
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig
{
applicationId "com.mobility.mobilityindia"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
String googleSupportVersion = '26.+'
String googlePlayServicesVersion = '11.0.2'
compile "com.google.firebase:firebase-core:$googlePlayServicesVersion"
compile "com.google.firebase:firebase-auth:$googlePlayServicesVersion"
compile "com.android.support:appcompat-v7:$googleSupportVersion"
compile "com.android.support:support-v4:$googleSupportVersion"
compile "com.google.android.gms:play-services:$googlePlayServicesVersion"
compile "com.android.support:design:$googleSupportVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
apply plugin: 'com.google.gms.google-services'
top level gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
}
}
The code you have is for an old version of the Firebase SDK (1.x or 2.x), while you're importing the latest version.
If you follow the latest documentation or the latest Android codelab, you won't need the Firebase.setAndroidContext() anymore and will get imports that start with com.google.firebase.