Search in sources :

Example 16 with Color

use of android.graphics.Color in project mapbox-plugins-android by mapbox.

the class FillActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_annotation);
    mapView = findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
        findViewById(R.id.fabStyles).setOnClickListener(v -> mapboxMap.setStyle(Utils.INSTANCE.getNextStyle()));
        mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2));
        fillManager = new FillManager(mapView, mapboxMap, style);
        fillManager.addClickListener(fill -> {
            Toast.makeText(FillActivity.this, String.format("Fill clicked %s with title: %s", fill.getId(), getTitleFromFill(fill)), Toast.LENGTH_SHORT).show();
            return false;
        });
        fillManager.addLongClickListener(fill -> {
            Toast.makeText(FillActivity.this, String.format("Fill long clicked %s with title: %s", fill.getId(), getTitleFromFill(fill)), Toast.LENGTH_SHORT).show();
            return false;
        });
        // create a fixed fill
        List<LatLng> innerLatLngs = new ArrayList<>();
        innerLatLngs.add(new LatLng(-35.317366, -74.179687));
        innerLatLngs.add(new LatLng(-35.317366, -30.761718));
        innerLatLngs.add(new LatLng(4.740675, -30.761718));
        innerLatLngs.add(new LatLng(4.740675, -74.179687));
        innerLatLngs.add(new LatLng(-35.317366, -74.179687));
        List<List<LatLng>> latLngs = new ArrayList<>();
        latLngs.add(innerLatLngs);
        FillOptions fillOptions = new FillOptions().withLatLngs(latLngs).withData(new JsonPrimitive("Foobar")).withFillColor(ColorUtils.colorToRgbaString(Color.RED));
        fillManager.create(fillOptions);
        // random add fills across the globe
        List<FillOptions> fillOptionsList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            int color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
            fillOptionsList.add(new FillOptions().withLatLngs(createRandomLatLngs()).withFillColor(ColorUtils.colorToRgbaString(color)));
        }
        fillManager.create(fillOptionsList);
        try {
            fillManager.create(FeatureCollection.fromJson(Utils.INSTANCE.loadStringFromAssets(this, "annotations.json")));
        } catch (IOException e) {
            throw new RuntimeException("Unable to parse annotations.json");
        }
    }));
}
Also used : Bundle(android.os.Bundle) ColorUtils(com.mapbox.mapboxsdk.utils.ColorUtils) FeatureCollection(com.mapbox.geojson.FeatureCollection) MapView(com.mapbox.mapboxsdk.maps.MapView) R(com.mapbox.mapboxsdk.plugins.testapp.R) IOException(java.io.IOException) Random(java.util.Random) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) FillOptions(com.mapbox.mapboxsdk.plugins.annotation.FillOptions) Utils(com.mapbox.mapboxsdk.plugins.testapp.Utils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Color(android.graphics.Color) JsonElement(com.google.gson.JsonElement) CameraUpdateFactory(com.mapbox.mapboxsdk.camera.CameraUpdateFactory) List(java.util.List) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Toast(android.widget.Toast) Style(com.mapbox.mapboxsdk.maps.Style) Menu(android.view.Menu) FillManager(com.mapbox.mapboxsdk.plugins.annotation.FillManager) JsonPrimitive(com.google.gson.JsonPrimitive) Fill(com.mapbox.mapboxsdk.plugins.annotation.Fill) JsonPrimitive(com.google.gson.JsonPrimitive) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) IOException(java.io.IOException) FillManager(com.mapbox.mapboxsdk.plugins.annotation.FillManager) FillOptions(com.mapbox.mapboxsdk.plugins.annotation.FillOptions)

Example 17 with Color

use of android.graphics.Color in project Phonograph by kabouzeid.

the class ChangelogDialog method onCreateDialog.

@SuppressLint("InflateParams")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final View customView;
    try {
        customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_web_view, null);
    } catch (InflateException e) {
        e.printStackTrace();
        return new MaterialDialog.Builder(getActivity()).title(android.R.string.dialog_alert_title).content("This device doesn't support web view, which is necessary to view the change log. It is missing a system component.").positiveText(android.R.string.ok).build();
    }
    MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.changelog).customView(customView, false).positiveText(android.R.string.ok).showListener(dialog1 -> {
        if (getActivity() != null)
            setChangelogRead(getActivity());
    }).build();
    final WebView webView = customView.findViewById(R.id.web_view);
    try {
        // Load from phonograph-changelog.html in the assets folder
        StringBuilder buf = new StringBuilder();
        InputStream json = getActivity().getAssets().open("phonograph-changelog.html");
        BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8"));
        String str;
        while ((str = in.readLine()) != null) buf.append(str);
        in.close();
        // Inject color values for WebView body background and links
        final String backgroundColor = colorToCSS(ATHUtil.resolveColor(getActivity(), R.attr.md_background_color, Color.parseColor(ThemeSingleton.get().darkTheme ? "#424242" : "#ffffff")));
        final String contentColor = colorToCSS(Color.parseColor(ThemeSingleton.get().darkTheme ? "#ffffff" : "#000000"));
        final String changeLog = buf.toString().replace("{style-placeholder}", String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor)).replace("{link-color}", colorToCSS(ThemeSingleton.get().positiveColor.getDefaultColor())).replace("{link-color-active}", colorToCSS(ColorUtil.lightenColor(ThemeSingleton.get().positiveColor.getDefaultColor())));
        webView.loadData(changeLog, "text/html", "UTF-8");
    } catch (Throwable e) {
        webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
    }
    return dialog;
}
Also used : Context(android.content.Context) ATHUtil(com.kabouzeid.appthemehelper.util.ATHUtil) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) LayoutInflater(android.view.LayoutInflater) PreferenceUtil(com.kabouzeid.gramophone.util.PreferenceUtil) Dialog(android.app.Dialog) PackageInfo(android.content.pm.PackageInfo) InputStreamReader(java.io.InputStreamReader) Color(android.graphics.Color) ThemeSingleton(com.afollestad.materialdialogs.internal.ThemeSingleton) SuppressLint(android.annotation.SuppressLint) InflateException(android.view.InflateException) ColorUtil(com.kabouzeid.appthemehelper.util.ColorUtil) View(android.view.View) BufferedReader(java.io.BufferedReader) WebView(android.webkit.WebView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Log(android.util.Log) R(com.kabouzeid.gramophone.R) DialogFragment(androidx.fragment.app.DialogFragment) InputStream(java.io.InputStream) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) InflateException(android.view.InflateException) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) NonNull(androidx.annotation.NonNull) SuppressLint(android.annotation.SuppressLint)

Aggregations

Color (android.graphics.Color)17 View (android.view.View)16 TextView (android.widget.TextView)14 List (java.util.List)12 Context (android.content.Context)11 Bundle (android.os.Bundle)11 LayoutInflater (android.view.LayoutInflater)11 ArrayList (java.util.ArrayList)10 Toast (android.widget.Toast)9 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)9 Intent (android.content.Intent)8 ViewGroup (android.view.ViewGroup)8 Drawable (android.graphics.drawable.Drawable)7 ImageView (android.widget.ImageView)7 Activity (android.app.Activity)6 Log (android.util.Log)6 SharedPreferences (android.content.SharedPreferences)5 AsyncTask (android.os.AsyncTask)5 MenuItem (android.view.MenuItem)5 Resources (android.content.res.Resources)4