|
| 1 | +package com.xxmassdeveloper.mpchartexample.fragments |
| 2 | + |
| 3 | +import android.content.Intent |
| 4 | +import android.net.Uri |
| 5 | +import android.os.Bundle |
| 6 | +import android.view.* |
| 7 | +import android.widget.FrameLayout |
| 8 | +import android.widget.Toast |
| 9 | +import androidx.coordinatorlayout.widget.CoordinatorLayout |
| 10 | +import androidx.fragment.app.Fragment |
| 11 | +import androidx.fragment.app.FragmentManager |
| 12 | +import androidx.fragment.app.FragmentPagerAdapter |
| 13 | +import androidx.viewpager.widget.ViewPager |
| 14 | +import com.google.android.material.snackbar.Snackbar |
| 15 | +import com.xxmassdeveloper.mpchartexample.R |
| 16 | +import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase |
| 17 | + |
| 18 | +/** |
| 19 | + * Demonstrates how to keep your charts straight forward, simple and beautiful with the MPAndroidChart library. |
| 20 | + */ |
| 21 | +class SimpleChartDemo : DemoBase() { |
| 22 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 23 | + super.onCreate(savedInstanceState) |
| 24 | + window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) |
| 25 | + setContentView(R.layout.activity_awesomedesign) |
| 26 | + val pager = findViewById<ViewPager>(R.id.pager) |
| 27 | + pager.offscreenPageLimit = 3 |
| 28 | + pager.adapter = PageAdapter(supportFragmentManager) |
| 29 | + |
| 30 | + showSnackbar("Swipe left and right for more awesome design examples!") |
| 31 | + } |
| 32 | + |
| 33 | + private inner class PageAdapter(fm: FragmentManager?) : FragmentPagerAdapter(fm!!) { |
| 34 | + override fun getItem(pos: Int): Fragment { |
| 35 | + var f: Fragment? = null |
| 36 | + when (pos) { |
| 37 | + 0 -> f = SineCosineFragment.newInstance() |
| 38 | + 1 -> f = ComplexityFragment.newInstance() |
| 39 | + 2 -> f = BarChartFrag.newInstance() |
| 40 | + 3 -> f = ScatterChartFrag.newInstance() |
| 41 | + 4 -> f = PieChartFrag.newInstance() |
| 42 | + } |
| 43 | + return f!! |
| 44 | + } |
| 45 | + |
| 46 | + override fun getCount(): Int { |
| 47 | + return 5 |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + override fun onCreateOptionsMenu(menu: Menu): Boolean { |
| 52 | + menuInflater.inflate(R.menu.only_github, menu) |
| 53 | + return true |
| 54 | + } |
| 55 | + |
| 56 | + override fun onOptionsItemSelected(item: MenuItem): Boolean { |
| 57 | + when (item.itemId) { |
| 58 | + R.id.viewGithub -> { |
| 59 | + val i = Intent(Intent.ACTION_VIEW) |
| 60 | + i.data = Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/SimpleChartDemo.java") |
| 61 | + startActivity(i) |
| 62 | + } |
| 63 | + } |
| 64 | + return true |
| 65 | + } |
| 66 | + |
| 67 | + /* Intentionally left empty */ |
| 68 | + public override fun saveToGallery() = Unit |
| 69 | + |
| 70 | + private fun showSnackbar(text: String) { |
| 71 | + val viewPos : View = findViewById(android.R.id.content) |
| 72 | + val snackbar = Snackbar.make(viewPos, text, Snackbar.LENGTH_LONG) |
| 73 | + val view = snackbar.view |
| 74 | + when (val params = view.layoutParams) { |
| 75 | + is CoordinatorLayout.LayoutParams -> { |
| 76 | + val paramsC = view.layoutParams as CoordinatorLayout.LayoutParams |
| 77 | + paramsC.gravity = Gravity.CENTER_VERTICAL |
| 78 | + view.layoutParams = paramsC |
| 79 | + snackbar.show() |
| 80 | + } |
| 81 | + is FrameLayout.LayoutParams -> { |
| 82 | + val paramsC = view.layoutParams as FrameLayout.LayoutParams |
| 83 | + paramsC.gravity = Gravity.BOTTOM |
| 84 | + view.layoutParams = paramsC |
| 85 | + snackbar.show() |
| 86 | + } |
| 87 | + else -> { |
| 88 | + Toast.makeText(this, text + " " + params.javaClass.simpleName, Toast.LENGTH_SHORT).show() |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments