Material design
Support Android 12
This commit is contained in:
@@ -2,6 +2,7 @@ package fr.svpro.radiomercure;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DownloadManager;
|
||||
@@ -26,16 +27,22 @@ import android.webkit.URLUtil;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
@@ -57,42 +64,65 @@ public class MainActivity extends AppCompatActivity {
|
||||
versionName = BuildConfig.VERSION_NAME;
|
||||
}
|
||||
|
||||
|
||||
//Navigation
|
||||
private NavigationView navigationView;
|
||||
private DrawerLayout drawerLayout;
|
||||
private Toolbar toolbar;
|
||||
|
||||
@SuppressLint({"SetJavaScriptEnabled", "WrongViewCast", "JavascriptInterface"})
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
getSupportActionBar().hide();
|
||||
|
||||
final SwipeRefreshLayout refreshLayout = findViewById(R.id.refresh_layout);
|
||||
refreshLayout.setColorSchemeColors(Color.BLUE);
|
||||
//menu
|
||||
navigationView = findViewById(R.id.navigation_drawer);
|
||||
|
||||
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
|
||||
// Navigation drawer item click listener
|
||||
switch (item.getItemId()) {
|
||||
case R.id.live:
|
||||
Toast.makeText(MainActivity.this, "Vous écoutez Radio Mercure en direct", Toast.LENGTH_SHORT).show();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
lectureAudio("https://live.radiomercure.fr/on-air/live");
|
||||
} else {
|
||||
Toast.makeText(MainActivity.this, "Votre version d'Android n'est pas compatible", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
break;
|
||||
|
||||
// your action when refresh layout swiped
|
||||
web.clearCache(true);
|
||||
reStart();
|
||||
refreshLayout.setRefreshing(false);
|
||||
case R.id.tel:
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(Uri.parse("tel:" + NUMERO_TEL_RADIO));
|
||||
startActivity(intent);
|
||||
break;
|
||||
|
||||
case R.id.refresh:
|
||||
web.clearCache(true);
|
||||
reStart();
|
||||
break;
|
||||
|
||||
case R.id.exit:
|
||||
System.exit(0);
|
||||
break;
|
||||
}
|
||||
|
||||
drawerLayout.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
//toolbar
|
||||
toolbar = findViewById(R.id.toolBar);
|
||||
drawerLayout = findViewById(R.id.drawer_layout);
|
||||
toolbar.setTitle("Radio Mercure");
|
||||
|
||||
fbtn_live = (FloatingActionButton) findViewById(R.id.fbtn_live);
|
||||
fbtn_live.setOnClickListener(new View.OnClickListener() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Snackbar.make(v, "Vous écoutez Radio Mercure en direct", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
lectureAudio("https://live.radiomercure.fr/on-air/live");
|
||||
fbtn_live.setImageResource(android.R.drawable.ic_media_pause);
|
||||
|
||||
}
|
||||
});
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawerLayout.addDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
|
||||
//------Demande d'autorisation de désactiver l'optimisation de la batterie------//
|
||||
AlertDialog.Builder dialogOptBattery = new AlertDialog.Builder(this);
|
||||
@@ -211,51 +241,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.option,menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
switch (id){
|
||||
case R.id.refresh:
|
||||
web.clearCache(true);
|
||||
reStart();
|
||||
//web.reload();
|
||||
//Toast.makeText(this, "Rechargement...", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
|
||||
case R.id.exit:
|
||||
System.exit(0);
|
||||
return true;
|
||||
|
||||
case R.id.about:
|
||||
|
||||
dialog.show();
|
||||
return true;
|
||||
|
||||
case R.id.tel:
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(Uri.parse("tel:" + NUMERO_TEL_RADIO));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
|
||||
//case R.id.live:
|
||||
//lectureAudio("https://live.radiomercure.fr/on-air/live");
|
||||
//Toast.makeText(this, "Vous écoutez Radio Mercure en direct", Toast.LENGTH_SHORT).show();
|
||||
|
||||
//return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (web.canGoBack()) {
|
||||
|
||||
Reference in New Issue
Block a user